private boolean isSpecial(ItemStack stack) {
if (stack.getItemMeta() == null) return false;
return stack.getItemMeta().getDisplayName().equals("special");
}
@EventHandler
public void onLaunch(PlayerLaunchProjectileEvent e) {
if (e.getItemStack().getType() == Material.SNOWBALL && isSpecial(e.getItemStack())) {
e.getProjectile().setMetadata("special_snowball", new FixedMetadataValue(this, true));
if (e.getPlayer().getGameMode() != GameMode.CREATIVE)
e.setShouldConsume(false);
}
}
@EventHandler
public void onHit(ProjectileHitEvent e) {
if (e.getEntity() instanceof Snowball && e.getEntity().getShooter() instanceof Player) {
if (e.getHitEntity() != null && e.getHitEntity() instanceof Player) {
if (e.getHitEntity() == e.getEntity().getShooter()) return;
if (!e.getEntity().hasMetadata("special_snowball")) return;
((Player) e.getHitEntity()).kickPlayer("Your reason");
}
}
}