From 62e1fb3688dae02d102156b8f7f7f38814bb9a74 Mon Sep 17 00:00:00 2001 From: Thanos paravantis Date: Sat, 9 Jan 2016 17:01:57 +0200 Subject: [PATCH] Prevent players from stacking others with a menu inventory opened. --- .../mineplex/hub/modules/StackerManager.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java index 420a01dea..3fcf8a8b2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java @@ -1,5 +1,6 @@ package mineplex.hub.modules; +import java.util.ArrayList; import java.util.HashSet; import org.bukkit.Bukkit; @@ -7,6 +8,7 @@ import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; import org.bukkit.entity.Horse; @@ -16,6 +18,8 @@ import org.bukkit.entity.Wither; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import mineplex.core.MiniPlugin; @@ -123,24 +127,45 @@ public class StackerManager extends MiniPlugin implements IThrown if (stackee instanceof Player) { + Player stackeePlayer = (Player) stackee; + if (!Manager.hasPlayerStackingEnabled(stacker)) { UtilPlayer.message(stacker, F.main("Stacker", "You have player stacking disabled.")); return; } - if (!Manager.hasPlayerStackingEnabled(((Player)stackee))) + if (!Manager.hasPlayerStackingEnabled((stackeePlayer))) { UtilPlayer.message(stacker, F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " has player stacking disabled.")); return; } - if (Manager.GetTreasure().isOpening((Player) stackee)) + if (Manager.GetTreasure().isOpening(stackeePlayer)) { UtilPlayer.message(stacker, F.main("Stacker", F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " is opening a chest!"))); return; } - } + + Inventory top = stackeePlayer.getOpenInventory().getTopInventory(); + + if (!(top instanceof CraftInventoryCrafting) && hasItems(top)) + { + String message = F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " cannot be stacked right now."); + + if (top.getHolder() != null) + { + if (top.getHolder().equals(stackeePlayer)) + { + UtilPlayer.message(stacker, message); + return; + } + } + + UtilPlayer.message(stacker, message); + return; + } + } if (stackee instanceof LivingEntity) { @@ -284,6 +309,17 @@ public class StackerManager extends MiniPlugin implements IThrown //Portal Delay Manager.SetPortalDelay(target); } + + private boolean hasItems(Inventory inventory) + { + for (ItemStack item : inventory.getContents()) + { + if (item != null) + return true; + } + + return false; + } @Override public void Idle(ProjectileUser data)