Maps: 100 deaths before maps freeze, sends a warning message when switching servers from clans

This commit is contained in:
libraryaddict 2015-07-13 21:21:17 +12:00
parent a9e68ff777
commit 66bef4ac00
5 changed files with 467 additions and 383 deletions

View File

@ -86,6 +86,9 @@ public class PartyManager extends MiniPlugin
@EventHandler @EventHandler
public void serverTransfer(ServerTransferEvent event) public void serverTransfer(ServerTransferEvent event)
{ {
if (event.isDraggedByParty())
return;
Party party = _partyLeaderMap.get(event.getPlayer().getName()); Party party = _partyLeaderMap.get(event.getPlayer().getName());
if (party != null) if (party != null)
@ -100,7 +103,7 @@ public class PartyManager extends MiniPlugin
{ {
if (player != event.getPlayer()) if (player != event.getPlayer())
{ {
_portal.sendPlayerToServer(player, event.getServer(), false); _portal.sendPlayerToServer(player, event.getServer(), true);
} }
} }
} }

View File

@ -78,19 +78,16 @@ public class Portal extends MiniPlugin
public void sendPlayerToServer(Player player, String serverName) public void sendPlayerToServer(Player player, String serverName)
{ {
sendPlayerToServer(player, serverName, true); sendPlayerToServer(player, serverName, false);
} }
public void sendPlayerToServer(final Player player, final String serverName, boolean callEvent) public void sendPlayerToServer(final Player player, final String serverName, boolean draggedByParty)
{ {
if (_connectingPlayers.contains(player.getName())) if (_connectingPlayers.contains(player.getName()))
return; return;
if (callEvent) ServerTransferEvent event = new ServerTransferEvent(player, serverName, draggedByParty);
{
ServerTransferEvent event = new ServerTransferEvent(player, serverName);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
}
final boolean override = serverName.equalsIgnoreCase("Lobby"); final boolean override = serverName.equalsIgnoreCase("Lobby");
final Rank playerRank = _clientManager.Get(player).GetRank(); final Rank playerRank = _clientManager.Get(player).GetRank();

View File

@ -10,11 +10,18 @@ public class ServerTransferEvent extends Event
private static final HandlerList _handlers = new HandlerList(); private static final HandlerList _handlers = new HandlerList();
private Player _player; private Player _player;
private String _server; private String _server;
private boolean _draggedByParty;
public ServerTransferEvent(Player player, String server) public ServerTransferEvent(Player player, String server, boolean draggedByParty)
{ {
_player = player; _player = player;
_server = server; _server = server;
_draggedByParty = draggedByParty;
}
public boolean isDraggedByParty()
{
return _draggedByParty;
} }
public HandlerList getHandlers() public HandlerList getHandlers()

View File

@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -20,6 +21,8 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.portal.ServerTransferEvent;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
@ -27,6 +30,7 @@ import mineplex.game.clans.clans.ClansUtility;
import net.minecraft.server.v1_7_R4.Block; import net.minecraft.server.v1_7_R4.Block;
import net.minecraft.server.v1_7_R4.Blocks; import net.minecraft.server.v1_7_R4.Blocks;
import net.minecraft.server.v1_7_R4.MaterialMapColor; import net.minecraft.server.v1_7_R4.MaterialMapColor;
import net.minecraft.server.v1_7_R4.PersistentCollection;
import net.minecraft.util.com.google.common.collect.HashMultiset; import net.minecraft.util.com.google.common.collect.HashMultiset;
import net.minecraft.util.com.google.common.collect.Iterables; import net.minecraft.util.com.google.common.collect.Iterables;
import net.minecraft.util.com.google.common.collect.Multisets; import net.minecraft.util.com.google.common.collect.Multisets;
@ -38,11 +42,15 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.CraftChunk; import org.bukkit.craftbukkit.v1_7_R4.CraftChunk;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -143,11 +151,27 @@ public class ItemMapManager extends MiniPlugin
_world = Bukkit.getWorld("world"); _world = Bukkit.getWorld("world");
MapView view = null;
try try
{ {
File file = new File("world/clans_map_id"); File file = new File("world/clans_map_id");
File foundFile = null;
for (File f : new File("world/data").listFiles())
{
if (f.getName().startsWith("map_"))
{
foundFile = f;
break;
}
}
if (foundFile == null)
{
PersistentCollection collection = ((CraftWorld) _world).getHandle().worldMaps;
Field f = collection.getClass().getDeclaredField("d");
f.setAccessible(true);
((HashMap) f.get(collection)).put("map", (short) 0);
}
if (file.exists()) if (file.exists())
{ {
@ -155,35 +179,37 @@ public class ItemMapManager extends MiniPlugin
_mapId = Short.parseShort(br.readLine()); _mapId = Short.parseShort(br.readLine());
br.close(); br.close();
File file1 = new File("world/data/map_" + _mapId); if (foundFile == null)
if (!file1.exists())
{
boolean copied = false;
for (File f : file1.getParentFile().listFiles())
{
if (f.getName().contains("map_"))
{
FileUtils.copyFile(f, file1);
copied = true;
}
}
if (!copied)
{ {
_mapId = -1; _mapId = -1;
file.delete(); file.delete();
} }
else
{
for (int i = _mapId; i <= _mapId + 100; i++)
{
File file1 = new File("world/data/map_" + i + ".dat");
if (!file1.exists())
{
FileUtils.copyFile(foundFile, file1);
} }
view = Bukkit.getMap(_mapId); setupRenderer(Bukkit.getMap((short) i));
}
}
} }
if (_mapId < 0) if (_mapId < 0)
{ {
view = Bukkit.createMap(_world); MapView view = Bukkit.createMap(_world);
_mapId = view.getId(); _mapId = view.getId();
setupRenderer(view);
for (int i = 0; i < 100; i++)
{
setupRenderer(Bukkit.createMap(_world));// Ensures the following 100 maps are unused
}
file.createNewFile(); file.createNewFile();
@ -197,61 +223,32 @@ public class ItemMapManager extends MiniPlugin
ex.printStackTrace(); ex.printStackTrace();
} }
rebuildScan();
}
private void setupRenderer(MapView view)
{
for (MapRenderer renderer : view.getRenderers()) for (MapRenderer renderer : view.getRenderers())
{ {
view.removeRenderer(renderer); view.removeRenderer(renderer);
} }
view.addRenderer(new ItemMapRenderer(this)); view.addRenderer(new ItemMapRenderer(this));
rebuildScan();
} }
@EventHandler @EventHandler
public void dropItem(ItemSpawnEvent event) public void preventMapInItemFrame(PlayerInteractEntityEvent event)
{
ItemStack item = event.getEntity().getItemStack();
if (item != null && item.getType() == Material.MAP && item.getDurability() == _mapId)
{
event.getEntity().remove();
}
}
@EventHandler
public void recenterMap(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{ {
if (!(event.getRightClicked() instanceof ItemFrame))
return; return;
}
for (Player player : Bukkit.getOnlinePlayers()) ItemStack item = event.getPlayer().getItemInHand();
{
MapInfo info = getMap(player);
if (info.getScale() >= 3) if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
{ || item.getDurability() > _mapId + 100)
continue; return;
}
Location l = player.getLocation(); event.setCancelled(true);
int zoom = getZoom(info.getScale());
double mapX = (l.getX() - info.getX()) / zoom;
double mapZ = (l.getZ() - info.getZ()) / zoom;
if (Math.abs(mapX) > 22 || Math.abs(mapZ) > 22)
{
int newX = calcMapCenter(zoom, l.getBlockX());
int newZ = calcMapCenter(zoom, l.getBlockZ());
if (Math.abs(mapX) > 22 ? newX != info.getX() : newZ != info.getZ())
{
info.setInfo(newX, newZ);
}
}
}
} }
/** /**
@ -382,6 +379,368 @@ public class ItemMapManager extends MiniPlugin
} }
} }
private void drawWorldScale(int scale, int startingX, int startingZ)
{
Byte[][] first = _map.get(0);
Byte[][] second = _map.get(scale);
int zoom = getZoom(scale);
for (int x = startingX; x < startingX + _blocksScan; x += zoom)
{
for (int z = startingZ; z < startingZ + _blocksScan; z += zoom)
{
HashMultiset<Byte> hashmultiset = HashMultiset.create();
for (int addX = 0; addX < zoom; addX++)
{
for (int addZ = 0; addZ < zoom; addZ++)
{
int pX = x + addX + _halfMapSize;
int pZ = z + addZ + _halfMapSize;
if (pX >= first.length || pZ >= first.length)
{
continue;
}
Byte b = first[pX][pZ];
hashmultiset.add(b);
}
}
Byte color = Iterables.getFirst(Multisets.copyHighestCountFirst(hashmultiset), (byte) 0);
second[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color;
}
}
}
@EventHandler
public void dropItem(ItemSpawnEvent event)
{
ItemStack item = event.getEntity().getItemStack();
if (item != null && item.getType() == Material.MAP && item.getDurability() >= _mapId
&& item.getDurability() <= _mapId + 100)
{
event.getEntity().remove();
}
}
public ClansUtility getClansUtility()
{
return _clansUtility;
}
private double getDistance(double x1, double z1, double x2, double z2)
{
x1 = (x1 - x2);
z1 = (z1 - z2);
return (x1 * x1) + (z1 * z1);
}
private double getDistance(Entry<Integer, Integer> entry, double x1, double z1)
{
return getDistance(x1, z1, entry.getKey() + (_blocksScan / 2), entry.getValue() + (_blocksScan / 2));
}
public Byte[][] getMap(int scale)
{
return _map.get(scale);
}
public MapInfo getMap(Player player)
{
return _mapInfo.get(player.getName());
}
public int getMapSize()
{
return _halfMapSize;
}
public int getZoom(int scale)
{
return _scale.get(scale);
}
@EventHandler
public void mapMoveInventories(InventoryClickEvent event)
{
ItemStack item = event.getCurrentItem();
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
return;
if (event.getClickedInventory() == null || event.getClickedInventory().getHolder() instanceof Player)
return;
event.setCancelled(true);
UtilPlayer.message(event.getWhoClicked(),
F.main("Inventory", "You cannot move " + F.item("Clans Map") + " between inventories."));
}
@EventHandler
public void onDeath(PlayerDeathEvent event)
{
MapInfo info = getMap(event.getEntity());
info.setMap(Math.min(_mapId + 100, info.getMap() + 1));
}
@EventHandler
public void onHotbarMove(PlayerItemHeldEvent event)
{
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItem(event.getNewSlot());
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
return;
showZoom(player, getMap(player));
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (event.getAction() == Action.PHYSICAL)
return;
ItemStack item = event.getItem();
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100)
return;
Player player = event.getPlayer();
MapInfo info = getMap(player);
boolean zoomIn = event.getAction().name().contains("LEFT");
if (!_scale.containsKey(info.getScale() + (zoomIn ? -1 : 1)))
{
return;
}
if (!info.canZoom())
{
long remainingTime = (info.getZoomCooldown() + 2500) - System.currentTimeMillis();
UtilPlayer.message(
player,
F.main("Recharge",
"You cannot use " + F.skill("Map Zoom") + " for "
+ F.time(UtilTime.convertString((remainingTime), 1, TimeUnit.FIT)) + "."));
return;
}
info.addZoom();
if (zoomIn)
{
int newScale = info.getScale() - 1;
Location loc = player.getLocation();
int zoom = getZoom(newScale);
info.setInfo(newScale, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ()));
}
else
{
int newScale = info.getScale() + 1;
Location loc = player.getLocation();
int zoom = getZoom(newScale);
info.setInfo(newScale, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ()));
}
showZoom(player, info);
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
MapInfo info = new MapInfo(_mapId);
Player player = event.getPlayer();
Location loc = player.getLocation();
int zoom = getZoom(1);
info.setInfo(1, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ()));
_mapInfo.put(player.getName(), info);
if (UtilInv.getItems(player).isEmpty())
{
setMap(player);
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
_mapInfo.remove(event.getPlayer().getName());
}
@EventHandler
public void onServerTransfer(ServerTransferEvent event)
{
Player p = event.getPlayer();
p.sendMessage(C.cDRed + C.Bold + "WARNING!");
p.sendMessage(C.cYellow + "There's a bug where switching servers will freeze the Clans Map!");
p.sendMessage(C.cYellow + "If you want to play on Clans again, rejoin the Mineplex server!");
}
private void rebuildScan()
{
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan)
{
for (int z = -_halfMapSize - 16; z < _halfMapSize; z += (z < -_halfMapSize ? 16 : _blocksScan))
{
_scanList.add(new HashMap.SimpleEntry(x, z));
}
}
if (!_loadWorld)
{
Iterator<Entry<Integer, Integer>> itel = _scanList.iterator();
while (itel.hasNext())
{
Entry<Integer, Integer> entry = itel.next();
boolean removeEntry = true;
for (Player player : UtilServer.getPlayers())
{
if (Math.sqrt(getDistance(entry, player.getLocation().getX(), player.getLocation().getZ())) < 200)
{
removeEntry = false;
break;
}
}
if (removeEntry)
{
itel.remove();
}
}
}
Collections.sort(_scanList, _comparator);
}
@EventHandler
public void recenterMap(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
for (Player player : Bukkit.getOnlinePlayers())
{
MapInfo info = getMap(player);
if (info.getScale() >= 3)
{
continue;
}
Location l = player.getLocation();
int zoom = getZoom(info.getScale());
double mapX = (l.getX() - info.getX()) / zoom;
double mapZ = (l.getZ() - info.getZ()) / zoom;
if (Math.abs(mapX) > 22 || Math.abs(mapZ) > 22)
{
int newX = calcMapCenter(zoom, l.getBlockX());
int newZ = calcMapCenter(zoom, l.getBlockZ());
if (Math.abs(mapX) > 22 ? newX != info.getX() : newZ != info.getZ())
{
info.setInfo(newX, newZ);
}
}
}
}
@EventHandler
public void renderMap(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
if (_scanList.isEmpty())
{
if (_loadWorld)
{
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan)
{
for (int z = -_halfMapSize; z < _halfMapSize; z += _blocksScan)
{
drawWorldScale(3, x, z);
colorWorldHeight(3, x, z);
}
}
System.out.print("Finished first map scan and render");
}
_loadWorld = false;
if (UtilServer.getPlayers().length == 0)
return;
rebuildScan();
}
else if (_scanList.size() % 20 == 0)
{
Collections.sort(_scanList, _comparator);
}
Entry<Integer, Integer> entry = _scanList.remove(0);
int startingX = entry.getKey();
int startingZ = entry.getValue();
boolean outsideMap = startingZ < -_halfMapSize;
scanWorldMap(startingX, startingZ, !outsideMap);
if (outsideMap)
{
return;
}
for (int scale = 1; scale < _scale.size(); scale++)
{
if (scale == 3 && _loadWorld)
continue;
if (!outsideMap)
{
drawWorldScale(scale, startingX, startingZ);
}
colorWorldHeight(scale, startingX, startingZ);
}
colorWorldHeight(0, startingX, startingZ);
}
public void scanWorldMap(int startingX, int startingZ, boolean setColors) public void scanWorldMap(int startingX, int startingZ, boolean setColors)
{ {
Byte[][] map = _map.get(0); Byte[][] map = _map.get(0);
@ -470,142 +829,31 @@ public class ItemMapManager extends MiniPlugin
} }
} }
private void drawWorldScale(int scale, int startingX, int startingZ) public void setMap(Player player)
{ {
Byte[][] first = _map.get(0); for (ItemStack item : UtilInv.getItems(player))
Byte[][] second = _map.get(scale);
int zoom = getZoom(scale);
for (int x = startingX; x < startingX + _blocksScan; x += zoom)
{ {
for (int z = startingZ; z < startingZ + _blocksScan; z += zoom) if (item.getType() == Material.MAP && (item.getDurability() >= _mapId && item.getDurability() <= _mapId + 100))
{
HashMultiset<Byte> hashmultiset = HashMultiset.create();
for (int addX = 0; addX < zoom; addX++)
{
for (int addZ = 0; addZ < zoom; addZ++)
{
int pX = x + addX + _halfMapSize;
int pZ = z + addZ + _halfMapSize;
if (pX >= first.length || pZ >= first.length)
{
continue;
}
Byte b = first[pX][pZ];
hashmultiset.add(b);
}
}
Byte color = Iterables.getFirst(Multisets.copyHighestCountFirst(hashmultiset), (byte) 0);
second[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color;
}
}
}
public ClansUtility getClansUtility()
{
return _clansUtility;
}
private double getDistance(double x1, double z1, double x2, double z2)
{
x1 = (x1 - x2);
z1 = (z1 - z2);
return (x1 * x1) + (z1 * z1);
}
private double getDistance(Entry<Integer, Integer> entry, double x1, double z1)
{
return getDistance(x1, z1, entry.getKey() + (_blocksScan / 2), entry.getValue() + (_blocksScan / 2));
}
public Byte[][] getMap(int scale)
{
return _map.get(scale);
}
public MapInfo getMap(Player player)
{
return _mapInfo.get(player.getName());
}
public short getMapId()
{
return _mapId;
}
public int getMapSize()
{
return _halfMapSize;
}
public int getZoom(int scale)
{
return _scale.get(scale);
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (event.getAction() == Action.PHYSICAL)
return;
ItemStack item = event.getItem();
if (item == null || item.getType() != Material.MAP || item.getDurability() != _mapId)
return;
Player player = event.getPlayer();
MapInfo info = _mapInfo.get(player.getName());
boolean zoomIn = event.getAction().name().contains("LEFT");
if (!_scale.containsKey(info.getScale() + (zoomIn ? -1 : 1)))
{ {
return; return;
} }
if (!info.canZoom())
{
long remainingTime = (info.getZoomCooldown() + 2500) - System.currentTimeMillis();
UtilPlayer.message(
player,
F.main("Recharge",
"You cannot use " + F.skill("Map Zoom") + " for "
+ F.time(UtilTime.convertString((remainingTime), 1, TimeUnit.FIT)) + "."));
return;
} }
info.addZoom(); ItemStack item = new ItemBuilder(Material.MAP, 1, (short) getMap(player).getMap()).setTitle("Clans Map").build();
if (zoomIn) int slot = player.getInventory().firstEmpty();
if (slot >= 0)
{ {
int newScale = info.getScale() - 1; ItemStack mapSlot = player.getInventory().getItem(8);
Location loc = player.getLocation();
int zoom = getZoom(newScale); if (mapSlot == null || mapSlot.getType() == Material.AIR)
info.setInfo(newScale, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ()));
}
else
{ {
int newScale = info.getScale() + 1; slot = 8;
Location loc = player.getLocation();
int zoom = getZoom(newScale);
info.setInfo(newScale, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ()));
} }
showZoom(player, info); player.getInventory().setItem(slot, item);
}
} }
private void showZoom(Player player, MapInfo info) private void showZoom(Player player, MapInfo info)
@ -651,191 +899,4 @@ public class ItemMapManager extends MiniPlugin
UtilTextBottom.display(progressBar, player); UtilTextBottom.display(progressBar, player);
} }
@EventHandler
public void onHotbarMove(PlayerItemHeldEvent event)
{
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItem(event.getNewSlot());
if (item == null || item.getType() != Material.MAP || item.getDurability() != _mapId)
return;
showZoom(player, getMap(player));
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
MapInfo info = new MapInfo();
Player player = event.getPlayer();
Location loc = player.getLocation();
int zoom = getZoom(1);
info.setInfo(1, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ()));
_mapInfo.put(player.getName(), info);
if (UtilInv.getItems(player).isEmpty())
{
setMap(player);
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
_mapInfo.remove(event.getPlayer().getName());
}
private void rebuildScan()
{
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan)
{
for (int z = -_halfMapSize - 16; z < _halfMapSize; z += (z < -_halfMapSize ? 16 : _blocksScan))
{
_scanList.add(new HashMap.SimpleEntry(x, z));
}
}
if (!_loadWorld)
{
Iterator<Entry<Integer, Integer>> itel = _scanList.iterator();
while (itel.hasNext())
{
Entry<Integer, Integer> entry = itel.next();
boolean removeEntry = true;
for (Player player : UtilServer.getPlayers())
{
if (Math.sqrt(getDistance(entry, player.getLocation().getX(), player.getLocation().getZ())) < 200)
{
removeEntry = false;
break;
}
}
if (removeEntry)
{
itel.remove();
}
}
}
Collections.sort(_scanList, _comparator);
}
@EventHandler
public void renderMap(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
if (_scanList.isEmpty())
{
if (_loadWorld)
{
for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan)
{
for (int z = -_halfMapSize; z < _halfMapSize; z += _blocksScan)
{
drawWorldScale(3, x, z);
colorWorldHeight(3, x, z);
}
}
System.out.print("Finished first map scan and render");
}
_loadWorld = false;
if (UtilServer.getPlayers().length == 0)
return;
rebuildScan();
}
else if (_scanList.size() % 20 == 0)
{
Collections.sort(_scanList, _comparator);
}
Entry<Integer, Integer> entry = _scanList.remove(0);
int startingX = entry.getKey();
int startingZ = entry.getValue();
boolean outsideMap = startingZ < -_halfMapSize;
scanWorldMap(startingX, startingZ, !outsideMap);
if (outsideMap)
{
return;
}
for (int scale = 1; scale < _scale.size(); scale++)
{
if (scale == 3 && _loadWorld)
continue;
if (!outsideMap)
{
drawWorldScale(scale, startingX, startingZ);
}
colorWorldHeight(scale, startingX, startingZ);
}
colorWorldHeight(0, startingX, startingZ);
}
@EventHandler
public void mapMoveInventories(InventoryClickEvent event)
{
ItemStack item = event.getCurrentItem();
if (item == null || item.getType() != Material.MAP || item.getDurability() != _mapId)
return;
if (event.getClickedInventory() == null || event.getClickedInventory().getHolder() instanceof Player)
return;
event.setCancelled(true);
UtilPlayer.message(event.getWhoClicked(),
F.main("Inventory", "You cannot move " + F.item("Clans Map") + " between inventories."));
}
public void setMap(Player player)
{
for (ItemStack item : UtilInv.getItems(player))
{
if (item.getType() == Material.MAP && item.getDurability() == _mapId)
{
return;
}
}
ItemStack item = new ItemStack(Material.MAP, 1, _mapId);
int slot = player.getInventory().firstEmpty();
if (slot >= 0)
{
ItemStack mapSlot = player.getInventory().getItem(8);
if (mapSlot == null || mapSlot.getType() == Material.AIR)
{
slot = 8;
}
player.getInventory().setItem(slot, item);
}
}
} }

View File

@ -13,6 +13,22 @@ public class MapInfo
private long _lastRendered; private long _lastRendered;
private boolean _sendMap; private boolean _sendMap;
private ArrayList<Long> _lastZooms = new ArrayList<Long>(); private ArrayList<Long> _lastZooms = new ArrayList<Long>();
private int _mapId;
public MapInfo(int newId)
{
_mapId = newId;
}
public int getMap()
{
return _mapId;
}
public void setMap(int newId)
{
_mapId = newId;
}
public boolean canZoom() public boolean canZoom()
{ {