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.
This commit is contained in:
Amaury Carrade 2015-07-10 15:07:12 +02:00
parent 0a79eee89b
commit 07bc9cf4a5
2 changed files with 61 additions and 4 deletions

View File

@ -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++;

View File

@ -144,6 +144,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)
{
for(int i = 0, c = inventory.getSize(); i < c; i++)