Prevent players from stacking others with a menu inventory opened.
This commit is contained in:
parent
ba3e7cb197
commit
62e1fb3688
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user