mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-01-05 23:37:43 +01:00
Various fixes and improvements on map GUIs.
* NEW: MapItemManager: new methods to create corresponding map items. * BUG: MapDetailGui: Picking up a part now gives the player the actual map instead of the display item. * BUG: ImageRendererExecutor: The worker's name is now the correct one. * BUG: Picking up a map or putting it in the hand from an inventory now correctly initializes the map.
This commit is contained in:
parent
234a81b335
commit
e942aabeda
@ -81,7 +81,7 @@ public final class ImageOnMap extends ZPlugin
|
||||
}
|
||||
catch(IOException ex)
|
||||
{
|
||||
PluginLogger.error("FATAL : " + ex.getMessage(), null);
|
||||
PluginLogger.error("FATAL : " + ex.getMessage());
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package fr.moribus.imageonmap.gui;
|
||||
import fr.moribus.imageonmap.map.ImageMap;
|
||||
import fr.moribus.imageonmap.map.PosterMap;
|
||||
import fr.moribus.imageonmap.map.SingleMap;
|
||||
import fr.moribus.imageonmap.ui.MapItemManager;
|
||||
import fr.zcraft.zlib.components.gui.ExplorerGui;
|
||||
import fr.zcraft.zlib.components.gui.Gui;
|
||||
import fr.zcraft.zlib.components.gui.GuiAction;
|
||||
@ -36,7 +37,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
public class MapDetailGui extends ExplorerGui<Void>
|
||||
public class MapDetailGui extends ExplorerGui
|
||||
{
|
||||
private final ImageMap map;
|
||||
|
||||
@ -66,6 +67,21 @@ public class MapDetailGui extends ExplorerGui<Void>
|
||||
part.setItemMeta(meta);
|
||||
return part;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getPickedUpItem(int x, int y)
|
||||
{
|
||||
if(map instanceof SingleMap)
|
||||
{
|
||||
return MapItemManager.createMapItem((SingleMap)map);
|
||||
}
|
||||
else if(map instanceof PosterMap)
|
||||
{
|
||||
return MapItemManager.createMapItem((PosterMap)map, x, y);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Unsupported map type : " + map.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getEmptyViewItem()
|
||||
|
@ -35,7 +35,7 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
|
||||
@WorkerAttributes (name = "Image IO", queriesMainThread = true)
|
||||
@WorkerAttributes (name = "Image Renderer", queriesMainThread = true)
|
||||
public class ImageRendererExecutor extends Worker
|
||||
{
|
||||
static public void Test(WorkerCallback callback)
|
||||
|
@ -28,7 +28,9 @@ import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
@ -73,6 +75,26 @@ public class MapInitEvent implements Listener
|
||||
initMap(item);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickup(PlayerPickupItemEvent event)
|
||||
{
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
initMap(item);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInventoryPlace(InventoryClickEvent event)
|
||||
{
|
||||
switch(event.getAction())
|
||||
{
|
||||
case PLACE_ALL:
|
||||
case PLACE_ONE:
|
||||
case PLACE_SOME:
|
||||
case SWAP_WITH_CURSOR:
|
||||
initMap(event.getCursor());
|
||||
}
|
||||
}
|
||||
|
||||
static protected void initMap(ItemStack item)
|
||||
{
|
||||
if (item != null && item.getType() == Material.MAP)
|
||||
|
@ -59,7 +59,7 @@ public class MapItemManager implements Listener
|
||||
|
||||
static public boolean give(Player player, SingleMap map)
|
||||
{
|
||||
return give(player, createMapItem(map.getMapsIDs()[0], map.getName()));
|
||||
return give(player, createMapItem(map));
|
||||
}
|
||||
|
||||
static public boolean give(Player player, PosterMap map)
|
||||
@ -115,6 +115,27 @@ public class MapItemManager implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
static public ItemStack createMapItem(SingleMap map)
|
||||
{
|
||||
return createMapItem(map.getMapsIDs()[0], map.getName());
|
||||
}
|
||||
|
||||
static public ItemStack createMapItem(PosterMap map, int x, int y)
|
||||
{
|
||||
String mapName;
|
||||
if(map.hasColumnData())
|
||||
{
|
||||
mapName = map.getName() +
|
||||
" (row " + x +
|
||||
", column " + y + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
mapName = map.getName();
|
||||
}
|
||||
return createMapItem(map.getMapIdAt(x, y), mapName);
|
||||
}
|
||||
|
||||
static public ItemStack createMapItem(short mapID, String text)
|
||||
{
|
||||
ItemStack itemMap = new ItemStack(Material.MAP, 1, mapID);
|
||||
|
Loading…
Reference in New Issue
Block a user