* BUG: Maps are correctly updated if there are map objects already loaded when the plugin is enabled.

This commit is contained in:
Prokopyl 2015-03-31 20:04:56 +02:00
parent 6c95e8a95e
commit b192214609
2 changed files with 28 additions and 9 deletions

View File

@ -85,6 +85,7 @@ public final class ImageOnMap extends JavaPlugin
MapManager.init(); MapManager.init();
Commands.init(this); Commands.init(this);
getServer().getPluginManager().registerEvents(new MapInitEvent(), this); getServer().getPluginManager().registerEvents(new MapInitEvent(), this);
MapInitEvent.init();
} }
@Override @Override

View File

@ -22,8 +22,10 @@ import fr.moribus.imageonmap.ImageOnMap;
import java.io.File; import java.io.File;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerItemHeldEvent;
@ -33,6 +35,21 @@ import org.bukkit.map.MapView;
public class MapInitEvent implements Listener public class MapInitEvent implements Listener
{ {
static public void init()
{
for(World world : Bukkit.getWorlds())
{
for(ItemFrame frame : world.getEntitiesByClass(ItemFrame.class))
{
initMap(frame.getItem());
}
}
for(Player player : Bukkit.getOnlinePlayers())
{
initMap(player.getItemInHand());
}
}
@EventHandler @EventHandler
public void onChunkLoad(ChunkLoadEvent event) public void onChunkLoad(ChunkLoadEvent event)
@ -41,12 +58,7 @@ public class MapInitEvent implements Listener
{ {
if (entity instanceof ItemFrame) if (entity instanceof ItemFrame)
{ {
ItemStack item = ((ItemFrame)entity).getItem(); initMap(((ItemFrame)entity).getItem());
if (item.getType() == Material.MAP)
{
MapView map = Bukkit.getMap(item.getDurability());
if(!Renderer.isHandled(map)) initMap(map);
}
} }
} }
} }
@ -55,16 +67,22 @@ public class MapInitEvent implements Listener
public void onPlayerInv(PlayerItemHeldEvent event) public void onPlayerInv(PlayerItemHeldEvent event)
{ {
ItemStack item = event.getPlayer().getInventory().getItem(event.getNewSlot()); ItemStack item = event.getPlayer().getInventory().getItem(event.getNewSlot());
initMap(item);
}
static protected void initMap(ItemStack item)
{
if (item != null && item.getType() == Material.MAP) if (item != null && item.getType() == Material.MAP)
{ {
MapView map = Bukkit.getMap(item.getDurability()); MapView map = Bukkit.getMap(item.getDurability());
if (!Renderer.isHandled(map)) initMap(map); initMap(map);
} }
} }
protected void initMap(MapView map) static protected void initMap(MapView map)
{ {
if(Renderer.isHandled(map)) return;
File imageFile = ImageOnMap.getPlugin().getImageFile(map.getId()); File imageFile = ImageOnMap.getPlugin().getImageFile(map.getId());
if(imageFile.isFile()) if(imageFile.isFile())
{ {