Prevent snowballs from being dropped and moved to other inventories

This commit is contained in:
Sam 2017-12-29 18:16:43 +00:00 committed by Alexander Meech
parent 6c32247663
commit 9bd7cb18b2
2 changed files with 31 additions and 19 deletions

View File

@ -358,7 +358,10 @@ public class UtilInv
return;
//Inform
UtilPlayer.message(event.getWhoClicked(), F.main("Inventory", "You cannot hotbar swap " + F.item(name) + "."));
if (inform)
{
UtilPlayer.message(event.getWhoClicked(), F.main("Inventory", "You cannot hotbar swap " + F.item(name) + "."));
}
event.setCancelled(true);
}
//Other
@ -373,7 +376,10 @@ public class UtilInv
if (!IsItem(event.getCurrentItem(), name, type, data))
return;
//Inform
UtilPlayer.message(event.getWhoClicked(), F.main("Inventory", "You cannot move " + F.item(name) + "."));
if (inform)
{
UtilPlayer.message(event.getWhoClicked(), F.main("Inventory", "You cannot move " + F.item(name) + "."));
}
event.setCancelled(true);
}
}

View File

@ -6,7 +6,8 @@ import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilInv;
@ -39,7 +40,7 @@ public class PerkSlowSnowball extends Perk
for (Player player : Manager.GetGame().GetPlayers(true))
{
if (UtilPlayer.isSpectator(player) || !hasPerk(player) || UtilInv.contains(player, Material.SNOW_BALL, (byte) 0, MAX) || !Recharge.Instance.use(player, "Snowball Give", 6000, false, false))
if (UtilPlayer.isSpectator(player) || !hasPerk(player) || UtilInv.contains(player, SNOW_BALL.getType(), SNOW_BALL.getData().getData(), MAX) || !Recharge.Instance.use(player, "Snowball Give", 6000, false, false))
{
continue;
}
@ -48,20 +49,6 @@ public class PerkSlowSnowball extends Perk
}
}
@EventHandler
public void playerInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (itemStack == null || itemStack.getType() != Material.SNOW_BALL || !hasPerk(player))
{
return;
}
UtilInv.remove(player, Material.SNOW_BALL, (byte) 0, UtilInv.getAmount(player, Material.SNOW_BALL) - MAX);
}
@EventHandler(priority = EventPriority.HIGH)
public void snowballDamage(CustomDamageEvent event)
{
@ -79,7 +66,26 @@ public class PerkSlowSnowball extends Perk
return;
}
Manager.GetCondition().Factory().Slow(GetName(), damagee, damager, 2, 1, false, true, false, false);
Manager.GetCondition().Factory().Slow(GetName(), damagee, damager, 3, 1, false, true, false, false);
event.AddMod(damager.getName(), "Snowball", 1, true);
}
@EventHandler
public void disallowMovement(InventoryClickEvent event)
{
UtilInv.DisallowMovementOf(event, null, SNOW_BALL.getType(), SNOW_BALL.getData().getData(), false);
}
@EventHandler
public void disallowDrop(PlayerDropItemEvent event)
{
Player player = event.getPlayer();
if (!hasPerk(player) || event.getItemDrop().getItemStack().getType() != SNOW_BALL.getType())
{
return;
}
event.setCancelled(true);
}
}