diff --git a/src/de/steamwar/misslewars/listener/ArenaListener.java b/src/de/steamwar/misslewars/listener/ArenaListener.java index 57e2c7a..4d7a7ec 100644 --- a/src/de/steamwar/misslewars/listener/ArenaListener.java +++ b/src/de/steamwar/misslewars/listener/ArenaListener.java @@ -21,12 +21,15 @@ package de.steamwar.misslewars.listener; import de.steamwar.misslewars.Config; import de.steamwar.misslewars.FightState; +import de.steamwar.misslewars.MWTeam; import de.steamwar.misslewars.MissileWars; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerDropItemEvent; @@ -34,6 +37,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPickupArrowEvent; import java.util.EnumSet; +import java.util.Map; import java.util.Objects; public class ArenaListener extends BasicListener { @@ -69,12 +73,7 @@ public class ArenaListener extends BasicListener { e.setCancelled(true); } - @EventHandler - public void onItemDrop(PlayerDropItemEvent e){ - e.setCancelled(true); - } - - @EventHandler + @EventHandler public void onHunger(FoodLevelChangeEvent e){ e.setCancelled(true); } diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java index 5c611a7..71f12cb 100644 --- a/src/de/steamwar/misslewars/listener/ItemListener.java +++ b/src/de/steamwar/misslewars/listener/ItemListener.java @@ -20,23 +20,41 @@ package de.steamwar.misslewars.listener; import de.steamwar.misslewars.FightState; +import de.steamwar.misslewars.MWTeam; +import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.items.SpecialItem; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityPickupItemEvent; +import org.bukkit.event.entity.ItemDespawnEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; public class ItemListener extends BasicListener { + private Set RED_ITEMS = new HashSet<>(); + private Set BLUE_ITEMS = new HashSet<>(); + public ItemListener() { super(EnumSet.of(FightState.FIGHTING)); } + @Override + public void enable() { + super.enable(); + RED_ITEMS.clear(); + BLUE_ITEMS.clear(); + } + @EventHandler public void onItemClick(PlayerInteractEvent e) { ItemStack item = e.getItem(); @@ -64,4 +82,38 @@ public class ItemListener extends BasicListener { SpecialItem.handleHit(e); } + @EventHandler + public void onItemDrop(PlayerDropItemEvent e){ + MWTeam mwTeam = MissileWars.getTeam(e.getPlayer()); + if (mwTeam == null) { + e.setCancelled(true); + return; + } + if (mwTeam == MissileWars.getRedTeam()) { + RED_ITEMS.add(e.getItemDrop().getEntityId()); + } else { + BLUE_ITEMS.add(e.getItemDrop().getEntityId()); + } + } + + @EventHandler + public void onEntityPickupItem(EntityPickupItemEvent e) { + Player player = (Player) e.getEntity(); + MWTeam mwTeam = MissileWars.getTeam(player); + if (mwTeam == null) { + e.setCancelled(true); + return; + } + if (mwTeam == MissileWars.getRedTeam() && !RED_ITEMS.contains(e.getItem().getEntityId())) { + e.setCancelled(true); + } else if (!BLUE_ITEMS.contains(e.getItem().getEntityId())) { + e.setCancelled(true); + } + } + + @EventHandler + public void onItemDespawn(ItemDespawnEvent event) { + RED_ITEMS.remove(event.getEntity().getEntityId()); + BLUE_ITEMS.remove(event.getEntity().getEntityId()); + } }