From 07bc9cf4a523fcb0c0f379b148ae426de06aaef6 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Fri, 10 Jul 2015 15:07:12 +0200 Subject: [PATCH] You can now destroy from your inventory a map, or all maps from a poster, by putting a map in the map list GUI. * NEW: Remove a whole map (poster or single) from the inventory by putting a piece in the map list GUI. --- .../imageonmap/gui/list/MapListGui.java | 22 +++++++++- .../fr/moribus/imageonmap/map/MapManager.java | 43 ++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/moribus/imageonmap/gui/list/MapListGui.java b/src/main/java/fr/moribus/imageonmap/gui/list/MapListGui.java index ad9e177..0217072 100644 --- a/src/main/java/fr/moribus/imageonmap/gui/list/MapListGui.java +++ b/src/main/java/fr/moribus/imageonmap/gui/list/MapListGui.java @@ -134,8 +134,8 @@ public class MapListGui extends AbstractGui { } @Override - public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { - + public void onClick(Player player, ItemStack stack, String action, ClickType clickType) + { switch (action) { case "back": @@ -188,6 +188,24 @@ public class MapListGui extends AbstractGui { } + @Override + public void onItemDeposit(Player player, ItemStack stack, ClickType clickType, InventoryClickEvent ev) { + ev.setCancelled(true); + + if (stack.getType() == Material.MAP && MapManager.managesMap(stack)) + { + ImageMap map = MapManager.getMap(stack); + + if (map != null) + { + MapManager.clear(player.getInventory(), map); + + // Deprecated? Yes. Alternatives? No, as usual... + ev.setCursor(new ItemStack(Material.AIR)); + } + } + } + private void nextPage(Player player) { if(currentPage < lastPage) currentPage++; diff --git a/src/main/java/fr/moribus/imageonmap/map/MapManager.java b/src/main/java/fr/moribus/imageonmap/map/MapManager.java index 0ecf22d..7d237cf 100644 --- a/src/main/java/fr/moribus/imageonmap/map/MapManager.java +++ b/src/main/java/fr/moribus/imageonmap/map/MapManager.java @@ -61,7 +61,7 @@ abstract public class MapManager } return false; } - + static public boolean managesMap(ItemStack item) { synchronized(playerMaps) @@ -73,7 +73,7 @@ abstract public class MapManager } return false; } - + static public ImageMap createMap(UUID playerUUID, short mapID) throws MapManagerException { ImageMap newMap = new SingleMap(playerUUID, mapID); @@ -143,6 +143,45 @@ abstract public class MapManager { return getPlayerMapStore(playerUUID).getMap(mapId); } + + /** + * Returns the {@link ImageMap} this map belongs to. + * + * @param mapId The ID of the Minecraft map. + * @return The {@link ImageMap}. + */ + static public ImageMap getMap(short mapId) + { + synchronized(playerMaps) + { + for(PlayerMapStore mapStore : playerMaps) + { + if(mapStore.managesMap(mapId)) + { + for(ImageMap map : mapStore.getMapList()) + { + if(map.managesMap(mapId)) + { + return map; + } + } + } + } + } + + return null; + } + + /** + * Returns the {@link ImageMap} this map belongs to. + * + * @param item The map, as an {@link ItemStack}. + * @return The {@link ImageMap}. + */ + static public ImageMap getMap(ItemStack item) + { + return getMap(item.getDurability()); + } static public void clear(Inventory inventory) {