Maps and other various fixes

This commit is contained in:
Shaun Bennett 2016-04-02 15:43:03 +11:00
parent 5739b1b87b
commit d161d83d12
14 changed files with 238 additions and 119 deletions

View File

@ -110,7 +110,7 @@ public class Clans extends JavaPlugin
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
new ClansBanManager(this, _clientManager, _donationManager);
// new ClansBanManager(this, _clientManager, _donationManager);
PacketHandler packetHandler = new PacketHandler(this);
Punish punish = new Punish(this, webServerAddress, _clientManager);

View File

@ -818,7 +818,21 @@ public class ClansDataAccessLayer
@Override
public void run()
{
_repository.clanExists(clanName, callback);
_repository.clanExists(clanName, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
runSync(new Runnable()
{
@Override
public void run()
{
if (callback != null) callback.run(data);
}
});
}
});
}
});
}

View File

@ -34,6 +34,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.map.MapRenderer;
@ -624,6 +625,22 @@ public class ItemMapManager extends MiniPlugin
// }
}
@EventHandler
public void onWorldChange(PlayerTeleportEvent event)
{
if (event.getFrom().getWorld() != event.getTo().getWorld() && event.getTo().getWorld().equals("world"))
{
runSyncLater(new Runnable()
{
@Override
public void run()
{
setMap(event.getPlayer());
}
}, 20);
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
@ -871,7 +888,9 @@ public class ItemMapManager extends MiniPlugin
public void setMap(Player player)
{
UtilServer.CallEvent(new PlayerGetMapEvent(player));
PlayerGetMapEvent event = UtilServer.CallEvent(new PlayerGetMapEvent(player));
if (event.isCancelled())
return;
for (ItemStack item : UtilInv.getItems(player))
{

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.clans.map;
import java.awt.Color;
import java.util.List;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
@ -8,6 +9,7 @@ import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.tutorial.TutorialManager;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.TutorialType;
import mineplex.game.clans.tutorial.map.TutorialMapManager;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
@ -42,92 +44,19 @@ public class ItemMapRenderer extends MapRenderer
@Override
public void render(MapView mapView, MapCanvas canvas, Player player)
{
if (_tutorial.inTutorial(player))
{
renderTutorialMap(mapView, canvas, player);
}
else
{
// if (_tutorial.inTutorial(player))
// {
// renderTutorialMap(mapView, canvas, player);
// }
// else
// {
renderNormalMap(mapView, canvas, player);
}
// }
}
private void renderTutorialMap(MapView mapView, MapCanvas canvas, Player player)
{
TutorialMapManager tutorialMap = ((ClansMainTutorial) _tutorial.getTutorial(TutorialType.MAIN)).getMapManager();
int zoom = tutorialMap.getScale();
Byte[][] map = tutorialMap.getMap(zoom);
int centerX = 0;
int centerZ = 0;
// We have this cooldown to squeeze out every single bit of performance from the server.
if (Recharge.Instance.use(player, "Draw Map", 4000, false, false))
{
for (int mapX = 0; mapX < 128; mapX++)
{
for (int mapZ = 0; mapZ < 128; mapZ++)
{
int blockX = centerX + (mapX - 64);
int blockZ = centerZ + (mapZ - 64);
int pixelX = blockX + (map.length / 2);
int pixelZ = blockZ + (map.length / 2);
Byte color;
if (!(pixelX < 0 || pixelZ < 0 || pixelX >= map.length || pixelZ >= map.length)
&& map[pixelX][pixelZ] != null)
{
color = map[pixelX][pixelZ];
blockX *= zoom;
blockZ *= zoom;
}
else
{
color = (byte) 0;
}
/* TODO Figure out if you want to colorize this pixel
{
color = MapPalette.matchColor(r, g, b);
}*/
canvas.setPixel(mapX, mapZ, color);
}
}
player.sendMap(mapView);
}
MapCursorCollection cursors = canvas.getCursors();
while (cursors.size() > 0)
{
cursors.removeCursor(cursors.getCursor(0));
}
Location l = player.getLocation().clone();
l.setX((((int)l.getX()) % 1000) + (l.getX() - ((int) l.getX())));
l.setZ((((int)l.getZ()) % 1000) + (l.getZ() - ((int) l.getZ())));
double mapX = (l.getX() - tutorialMap.getX()) / zoom;
double mapZ = (l.getZ() - tutorialMap.getZ()) / zoom;
if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64)
{
byte b0 = (byte) (int) Math.min(127, (double) (mapX * 2.0F) + 0.5D);
byte b1 = (byte) (int) Math.max(-127, (double) (mapZ * 2.0F) + 0.5D);
byte rotation = (byte) (int) ((l.getYaw() * 16D) / 360D);
MapCursor cursor = new MapCursor(b0, b1, (byte) (rotation & 0xF), MapCursor.Type.WHITE_POINTER.getValue(), true);
cursors.addCursor(cursor);
}
}
@ -292,7 +221,6 @@ public class ItemMapRenderer extends MapRenderer
}
//Inside
else
{

View File

@ -24,6 +24,7 @@ public class TutorialWorldManager extends MiniPlugin
private final World _tutorialWorld;
private final Schematic _schematic;
private Stack<TutorialRegion> _regionStack;
private TutorialRegion _centerRegion;
public TutorialWorldManager(JavaPlugin plugin, String worldName, String schematicName) throws IOException
{
@ -56,15 +57,17 @@ public class TutorialWorldManager extends MiniPlugin
_regionStack = new Stack<>();
// Populate the stack with 100 available tutorial regions
for (int x = 0; x < 2; x++)
for (int x = 0; x < 4; x++)
{
for (int z = 0; z < 2; z++)
for (int z = 0; z < 4; z++)
{
long time = System.currentTimeMillis();
double xLoc = (x) * 1000; // 1000x1000 regions
double zLoc = (z) * 1000;
double xLoc = (x) * 1200; // 1000x1000 regions
double zLoc = (z) * 1200;
_regionStack.add(new TutorialRegion(_schematic, new Location(_tutorialWorld, xLoc, 30, zLoc)));
TutorialRegion region = new TutorialRegion(_schematic, new Location(_tutorialWorld, xLoc, 30, zLoc));
if (x == 0 && z == 0) _centerRegion = region;
_regionStack.add(region);
System.out.println("Finished Generating Region: " + ((x * 10) + z) + ". Took " + (System.currentTimeMillis() - time) + " ms");
}
}
@ -94,4 +97,9 @@ public class TutorialWorldManager extends MiniPlugin
{
return _tutorialWorld;
}
public TutorialRegion getCenterRegion()
{
return _centerRegion;
}
}

View File

@ -41,6 +41,8 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.tutorial.TutorialManager;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockPosition;
@ -51,6 +53,7 @@ import net.minecraft.server.v1_8_R3.PersistentCollection;
public class TutorialMapManager extends MiniPlugin
{
private ClansMainTutorial _tutorial;
private int _blocksScan = 16;
private Comparator<Entry<Integer, Integer>> _comparator;
private int _halfMapSize = 64;
@ -63,8 +66,10 @@ public class TutorialMapManager extends MiniPlugin
private int _centerX;
private int _centerZ;
private int _scale = 1;
private int _minX;
private int _minZ;
public TutorialMapManager(JavaPlugin plugin, World world, int minX, int minZ, int maxX, int maxZ)
public TutorialMapManager(JavaPlugin plugin, ClansMainTutorial tutorial, World world, int minX, int minZ, int maxX, int maxZ)
{
super("TutorialMapManager", plugin);
@ -72,6 +77,9 @@ public class TutorialMapManager extends MiniPlugin
_centerZ = minZ + ((maxZ - minZ) / 2);
_centerX = (int) (Math.round(_centerX / 16D) * 16);
_centerZ = (int) (Math.round(_centerZ / 16D) * 16);
_tutorial = tutorial;
_minX = minX;
_minZ = minZ;
_heightMap = new int[(_halfMapSize * 2) + 16][];
@ -187,7 +195,7 @@ public class TutorialMapManager extends MiniPlugin
view.removeRenderer(renderer);
}
view.addRenderer(new TutorialMapRenderer(this));
view.addRenderer(new TutorialMapRenderer(_tutorial, _minX, _minZ));
}
public int getScale()

View File

@ -1,33 +1,45 @@
package mineplex.game.clans.tutorial.map;
import java.awt.*;
import java.util.List;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.tutorial.TutorialManager;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.TutorialType;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapCursor;
import org.bukkit.map.MapCursorCollection;
import org.bukkit.map.MapPalette;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
public class TutorialMapRenderer extends MapRenderer
{
private TutorialMapManager _manager;
private ClansMainTutorial _tutorial;
private int _minX;
private int _minZ;
public TutorialMapRenderer(TutorialMapManager itemMapManager)
public TutorialMapRenderer(ClansMainTutorial tutorialManager, int minX, int minZ)
{
super(true);
_manager = itemMapManager;
_tutorial = tutorialManager;
_minX = minX;
_minZ = minZ;
}
@Override
public void render(MapView mapView, MapCanvas canvas, Player player)
{
int zoom = _manager.getScale();
TutorialMapManager tutorialMap = _tutorial.getMapManager();
int zoom = tutorialMap.getScale();
Byte[][] map = _manager.getMap(zoom);
Byte[][] map = tutorialMap.getMap(zoom);
int centerX = 0;
int centerZ = 0;
@ -35,6 +47,13 @@ public class TutorialMapRenderer extends MapRenderer
// We have this cooldown to squeeze out every single bit of performance from the server.
if (Recharge.Instance.use(player, "Draw Map", 4000, false, false))
{
TutorialRegion region = _tutorial.getWorldManager().getCenterRegion();
MinMaxArea shops = getArea(region, ClansMainTutorial.Bounds.SHOPS);
MinMaxArea fields = getArea(region, ClansMainTutorial.Bounds.FIELDS);
MinMaxArea spawn = getArea(region, ClansMainTutorial.Bounds.SPAWN);
MinMaxArea claim = getArea(region, ClansMainTutorial.Bounds.LAND_CLAIM);
MinMaxArea enemy = getArea(region, ClansMainTutorial.Bounds.ENEMY_LAND);
for (int mapX = 0; mapX < 128; mapX++)
{
for (int mapZ = 0; mapZ < 128; mapZ++)
@ -45,19 +64,28 @@ public class TutorialMapRenderer extends MapRenderer
int pixelX = blockX + (map.length / 2);
int pixelZ = blockZ + (map.length / 2);
Byte color;
int xRegion = mapX + _minX - 6;
int zRegion = mapZ + _minZ;
Byte color = 0;
if (!(pixelX < 0 || pixelZ < 0 || pixelX >= map.length || pixelZ >= map.length)
&& map[pixelX][pixelZ] != null)
{
color = map[pixelX][pixelZ];
if (!((color <= -113 || color >= 0) && color <= 127))
color = (byte) 0;
blockX *= zoom;
blockZ *= zoom;
}
else
{
color = (byte) 0;
color = attemptDraw(false, color, Color.WHITE, new Color(50, 150, 255), xRegion, zRegion, shops, mapX, mapZ);
color = attemptDraw(false, color, Color.WHITE, new Color(255, 120, 0), xRegion, zRegion, fields, mapX, mapZ);
color = attemptDraw(false, color, Color.WHITE, new Color(0, 255, 100), xRegion, zRegion, spawn, mapX, mapZ);
color = attemptDraw(true, color, Color.CYAN, null, xRegion, zRegion, claim, mapX, mapZ);
color = attemptDraw(true, color, Color.RED, null, xRegion, zRegion, enemy, mapX, mapZ);
}
/* TODO Figure out if you want to colorize this pixel
@ -84,8 +112,8 @@ public class TutorialMapRenderer extends MapRenderer
l.setX((((int)l.getX()) % 1000) + (l.getX() - ((int) l.getX())));
l.setZ((((int)l.getZ()) % 1000) + (l.getZ() - ((int) l.getZ())));
double mapX = (l.getX() - _manager.getX()) / zoom;
double mapZ = (l.getZ() - _manager.getZ()) / zoom;
double mapX = (l.getX() - tutorialMap.getX()) / zoom;
double mapZ = (l.getZ() - tutorialMap.getZ()) / zoom;
if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64)
{
@ -99,4 +127,86 @@ public class TutorialMapRenderer extends MapRenderer
cursors.addCursor(cursor);
}
}
private byte attemptDraw(boolean colorAll, byte color, Color color1, Color color2, int xRegion, int zRegion, MinMaxArea area, int mapX, int mapZ)
{
if (xRegion >= area.MinX && xRegion <= area.MaxX && zRegion >= area.MinZ && zRegion <= area.MaxZ)
{
if (xRegion == area.MinX || xRegion == area.MaxX || zRegion == area.MinZ || zRegion == area.MaxZ)
{
// Outer Ring
Color cColor = MapPalette.getColor(color);
double clans = colorAll ? 1 : 0.8;// 0.65;
//Use clanColor2 no matter what for admins
Color drawColor = color1;
if (color2 != null)
{
drawColor = color2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
}
else
{
// Inside
Color cColor = MapPalette.getColor(color);
double clans = 0.065;
//Stripes
boolean checker = (mapX + (mapZ % 4)) % 4 == 0;
Color drawColor = color1;
// if (colorAll)
// {
// clans = 0.8;
// }
if (checker && color2 != null && !colorAll)
{
drawColor = color2;
clans = 1;
}
double base = 1 - clans;
if (clans != 1 && (color == 0 || color == 1 || color == 2 || color == 3))
return color;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
}
}
return color;
}
private MinMaxArea getArea(TutorialRegion region, ClansMainTutorial.Bounds bounds)
{
MinMaxArea area = new MinMaxArea();
List<Location> shopLocations = region.getLocationMap().getGoldLocations(bounds.getDataLocColor());
area.MinX = Math.min(shopLocations.get(0).getBlockX(), shopLocations.get(1).getBlockX());
area.MaxX = Math.max(shopLocations.get(0).getBlockX(), shopLocations.get(1).getBlockX());
area.MinZ = Math.min(shopLocations.get(0).getBlockZ(), shopLocations.get(1).getBlockZ());
area.MaxZ = Math.max(shopLocations.get(0).getBlockZ(), shopLocations.get(1).getBlockZ());
return area;
}
private class MinMaxArea
{
public int MinX;
public int MaxX;
public int MinZ;
public int MaxZ;
}
}

View File

@ -269,7 +269,7 @@ public abstract class Objective<Plugin extends Tutorial, Data extends ObjectiveD
private void showStartMessage(Player player)
{
UtilTextMiddle.display(C.cAqua + "Tutorial", getName(player), 20, 60, 20, player);
UtilTextMiddle.display(C.cAqua + "Next Tutorial", getName(player), 20, 60, 20, player);
}
private void showFinishMessage(Player player)

View File

@ -168,6 +168,10 @@ public abstract class ObjectiveGoal <T extends Objective> implements Listener
if (getExtraDescription(player) != null)
{
for (int i = 0; i < 5; i++)
{
UtilPlayer.message(player, "");
}
// Display extra information for the first time.
UtilPlayer.message(player, C.cGold + C.Strike + "---------------------------------------------");
UtilPlayer.message(player, C.cGray + " " + getExtraDescription(player));

View File

@ -11,7 +11,7 @@ import net.md_5.bungee.api.ChatColor;
public abstract class OrderedObjective<Plugin extends Tutorial> extends Objective<Plugin, OrderedObjectiveData>
{
private List<ObjectiveGoal> _goals;
private List<ObjectiveGoal<?>> _goals;
public OrderedObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description, String extraDescription)
{
@ -94,7 +94,7 @@ public abstract class OrderedObjective<Plugin extends Tutorial> extends Objectiv
}
@Override
protected List<ObjectiveGoal> getGoals()
protected List<ObjectiveGoal<?>> getGoals()
{
return _goals;
}

View File

@ -37,7 +37,7 @@ public abstract class SingleObjective<Plugin extends Tutorial> extends Objective
}
@Override
protected List<ObjectiveGoal> getGoals()
protected List<ObjectiveGoal<?>> getGoals()
{
return null;
}

View File

@ -11,7 +11,7 @@ import net.md_5.bungee.api.ChatColor;
public abstract class UnorderedObjective<Plugin extends Tutorial> extends Objective<Plugin, UnorderedObjectiveData>
{
private List<ObjectiveGoal> _goals;
private List<ObjectiveGoal<?>> _goals;
public UnorderedObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description, String extraDescription)
{
@ -87,7 +87,7 @@ public abstract class UnorderedObjective<Plugin extends Tutorial> extends Object
}
@Override
protected List<ObjectiveGoal> getGoals()
protected List<ObjectiveGoal<?>> getGoals()
{
return _goals;
}

View File

@ -4,6 +4,8 @@ import java.io.IOException;
import java.util.List;
import java.util.UUID;
import mineplex.core.common.util.C;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.gui.events.ClansButtonClickEvent;
import org.bukkit.DyeColor;
import org.bukkit.GameMode;
@ -70,7 +72,7 @@ public class ClansMainTutorial extends Tutorial
e.printStackTrace();
}
_mapManager = new TutorialMapManager(plugin, getWorldManager().getTutorialWorld(), -10, 0, 117, 127);
_mapManager = new TutorialMapManager(plugin, this, getWorldManager().getTutorialWorld(), -10, 0, 117, 127);
// _repository = new TutorialRepository(ClansManager.getInstance().getClientManager());
@ -90,6 +92,7 @@ public class ClansMainTutorial extends Tutorial
getMessage().removePlayer(player);
player.teleport(Spawn.getNorthSpawn());
UtilInv.Clear(player);
ClansManager.getInstance().getItemMapManager().setMap(player);
ClansManager.getInstance().getPvpTimer().unpause(player);
@ -130,6 +133,27 @@ public class ClansMainTutorial extends Tutorial
player.getInventory().clear();
ClansManager.getInstance().getPvpTimer().pause(player);
// Spawn Holograms
addHologram(player,
getPoint(region, ClansMainTutorial.Point.SPAWN).add(0, 1.5, -6),
C.cGoldB + "Welcome to the Clans Tutorial!",
" ",
"This will teach you the basics of Clans.",
"It will take about 5 minutes to complete.",
"You must complete it before playing Clans.",
" ",
"Walk forward to begin!");
addHologram(player,
getPoint(region, ClansMainTutorial.Point.SPAWN).add(0, 1.5, -23),
"Jump Off!");
ClanInfo clan = ClansManager.getInstance().getClan(player);
if (clan != null)
{
ClansManager.getInstance().getClanDataAccess().delete(clan, null);
}
}
@Override

View File

@ -42,11 +42,15 @@ public class GetMapGoal extends ObjectiveGoal<AttackEnemyObjective>
@EventHandler
public void onGetMap(PlayerGetMapEvent event)
{
if (!contains(event.getPlayer()))
if (getObjective().getPlugin().isInTutorial(event.getPlayer()))
{
return;
}
event.setCancelled(true);
getObjective().getPlugin().getMapManager().setMap(event.getPlayer());
if (contains(event.getPlayer()))
{
finish(event.getPlayer());
}
}
}
}