Clans: Fix map inventory moving

This commit is contained in:
libraryaddict 2015-07-21 07:37:08 +12:00
parent 3dcf489ea6
commit cd55eba2be

View File

@ -28,11 +28,11 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility; import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.WorldEventManager;
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.server.v1_7_R4.PersistentCollection;
import net.minecraft.util.com.google.common.base.Objects;
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;
@ -57,7 +57,9 @@ 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;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.map.MapRenderer; import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView; import org.bukkit.map.MapView;
@ -471,21 +473,32 @@ public class ItemMapManager extends MiniPlugin
} }
@EventHandler @EventHandler
public void mapMoveInventories(InventoryClickEvent event) public void preventMapMoveInventories(InventoryClickEvent event)
{ {
ItemStack item = event.getCurrentItem(); Inventory inv = event.getClickedInventory();
if (inv == null)
return;
// Yeah, the loop looks a little weird..
for (ItemStack item : new ItemStack[]
{
event.getCurrentItem(), event.getCursor()
})
{
if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId if (item == null || item.getType() != Material.MAP || item.getDurability() < _mapId
|| item.getDurability() > _mapId + 100) || item.getDurability() > _mapId + 100)
return; continue;
if (event.getClickedInventory() == null || event.getClickedInventory().getHolder() instanceof Player) if (inv.getHolder() instanceof Player ? !event.isShiftClick() : Objects.equal(event.getCurrentItem(), item))
return; continue;
event.setCancelled(true); event.setCancelled(true);
UtilPlayer.message(event.getWhoClicked(), UtilPlayer.message(event.getWhoClicked(),
F.main("Inventory", "You cannot move " + F.item("Clans Map") + " between inventories.")); F.main("Inventory", "You cannot move " + F.item("Clans Map") + " between inventories."));
return;
}
} }
@EventHandler @EventHandler