use of org.bukkit.entity.Creeper in project acidisland by tastybento.
the class IslandGuard method onBreakHanging.
/**
* Prevents the breakage of hanging items
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW)
public void onBreakHanging(final HangingBreakByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info(e.getRemover().toString());
}
if (inWorld(e.getEntity())) {
if ((e.getRemover() instanceof Creeper) && !Settings.allowCreeperDamage) {
e.setCancelled(true);
return;
}
// Check if creeper griefing is allowed
if ((e.getRemover() instanceof Creeper) && !Settings.allowCreeperGriefing) {
// Find out who the creeper was targeting
Creeper creeper = (Creeper) e.getRemover();
if (creeper.getTarget() instanceof Player) {
Player target = (Player) creeper.getTarget();
// Check if the target is on their own island or not
if (!plugin.getGrid().locationIsOnIsland(target, e.getEntity().getLocation())) {
// They are a visitor tsk tsk
e.setCancelled(true);
return;
}
}
// Check if this creeper was lit by a visitor
if (litCreeper.contains(creeper.getUniqueId())) {
if (DEBUG) {
plugin.getLogger().info("DBEUG: preventing creeper from damaging");
}
e.setCancelled(true);
return;
}
}
if (e.getRemover() instanceof Player) {
Player p = (Player) e.getRemover();
// This permission bypasses protection
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
if (actionAllowed(p, e.getEntity().getLocation(), SettingsFlag.BREAK_BLOCKS)) {
return;
}
// Not allowed
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
}
use of org.bukkit.entity.Creeper in project acidisland by tastybento.
the class IslandGuard method onExplosion.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) {
if (DEBUG) {
// Commented out due to Ender dragon spam in Paper Spigot
// plugin.getLogger().info(e.getEventName());
// plugin.getLogger().info("Entity exploding is " + e.getEntity());
}
if (!inWorld(e.getLocation())) {
return;
}
// Find out what is exploding
Entity expl = e.getEntity();
if (expl == null) {
// Note player can still die from beds exploding in the nether.
if (!Settings.allowTNTDamage) {
// plugin.getLogger().info("TNT block damage prevented");
e.blockList().clear();
} else {
if (!Settings.allowChestDamage) {
List<Block> toberemoved = new ArrayList<Block>();
// Save the chest blocks in a list
for (Block b : e.blockList()) {
switch(b.getType()) {
case CHEST:
case ENDER_CHEST:
case STORAGE_MINECART:
case TRAPPED_CHEST:
toberemoved.add(b);
break;
default:
break;
}
}
// Now delete them
for (Block b : toberemoved) {
e.blockList().remove(b);
}
}
}
return;
}
// prevent at spawn
if (plugin.getGrid().isAtSpawn(e.getLocation())) {
e.setCancelled(true);
}
// Find out what is exploding
EntityType exploding = e.getEntityType();
if (exploding == null) {
return;
}
switch(exploding) {
case CREEPER:
if (!Settings.allowCreeperDamage) {
// plugin.getLogger().info("Creeper block damage prevented");
e.blockList().clear();
} else {
// Check if creeper griefing is allowed
if (!Settings.allowCreeperGriefing) {
// Find out who the creeper was targeting
Creeper creeper = (Creeper) e.getEntity();
if (creeper.getTarget() instanceof Player) {
Player target = (Player) creeper.getTarget();
// Check if the target is on their own island or not
if (!plugin.getGrid().locationIsOnIsland(target, e.getLocation())) {
// They are a visitor tsk tsk
// Stop the blocks from being damaged, but allow hurt still
e.blockList().clear();
}
}
// Check if this creeper was lit by a visitor
if (litCreeper.contains(creeper.getUniqueId())) {
if (DEBUG) {
plugin.getLogger().info("DBEUG: preventing creeper from damaging");
}
litCreeper.remove(creeper.getUniqueId());
e.setCancelled(true);
return;
}
}
if (!Settings.allowChestDamage) {
List<Block> toberemoved = new ArrayList<Block>();
// Save the chest blocks in a list
for (Block b : e.blockList()) {
switch(b.getType()) {
case CHEST:
case ENDER_CHEST:
case STORAGE_MINECART:
case TRAPPED_CHEST:
toberemoved.add(b);
break;
default:
break;
}
}
// Now delete them
for (Block b : toberemoved) {
e.blockList().remove(b);
}
}
}
break;
case PRIMED_TNT:
case MINECART_TNT:
if (!Settings.allowTNTDamage) {
// plugin.getLogger().info("TNT block damage prevented");
e.blockList().clear();
} else {
if (!Settings.allowChestDamage) {
List<Block> toberemoved = new ArrayList<Block>();
// Save the chest blocks in a list
for (Block b : e.blockList()) {
switch(b.getType()) {
case CHEST:
case ENDER_CHEST:
case STORAGE_MINECART:
case TRAPPED_CHEST:
toberemoved.add(b);
break;
default:
break;
}
}
// Now delete them
for (Block b : toberemoved) {
e.blockList().remove(b);
}
}
}
break;
default:
break;
}
}
use of org.bukkit.entity.Creeper in project acidisland by tastybento.
the class IslandGuard method onEntityDamage.
/**
* This method protects players from PVP if it is not allowed and from
* arrows fired by other players
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageByEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info("DEBUG: Damager = " + e.getDamager().toString());
plugin.getLogger().info("DEBUG: Entitytype = " + e.getEntityType());
plugin.getLogger().info("DEBUG: Entity = " + e.getEntity());
}
// Check world
if (!inWorld(e.getEntity())) {
return;
}
// Get the island where the damage is occurring
Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
boolean inNether = false;
if (e.getEntity().getWorld().equals(ASkyBlock.getNetherWorld())) {
inNether = true;
}
// Stop TNT damage if it is disallowed
if (!Settings.allowTNTDamage && (e.getDamager().getType().equals(EntityType.PRIMED_TNT) || e.getDamager().getType().equals(EntityType.FIREWORK))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: cancelling TNT or firework damage");
e.setCancelled(true);
return;
}
// Check for creeper damage at spawn
if (island != null && island.isSpawn() && e.getDamager().getType().equals(EntityType.CREEPER) && island.getIgsFlag(SettingsFlag.CREEPER_PAIN)) {
return;
}
// Stop Creeper damager if it is disallowed
if (!Settings.allowCreeperDamage && e.getDamager().getType().equals(EntityType.CREEPER) && !(e.getEntity() instanceof Player)) {
e.setCancelled(true);
return;
}
// Stop Creeper griefing if it is disallowed
if (!Settings.allowCreeperGriefing && e.getDamager().getType().equals(EntityType.CREEPER)) {
// Now we have to check what the target was
Creeper creeper = (Creeper) e.getDamager();
// plugin.getLogger().info("DEBUG: entity being damaged is " + e.getEntity());
if (creeper.getTarget() instanceof Player) {
// plugin.getLogger().info("DEBUG: target is a player");
Player target = (Player) creeper.getTarget();
// Check if the target is on their own island or not
if (!plugin.getGrid().locationIsOnIsland(target, e.getEntity().getLocation())) {
// They are a visitor tsk tsk
// plugin.getLogger().info("DEBUG: player is a visitor");
e.setCancelled(true);
return;
}
}
// Check if this creeper was lit by a visitor
if (litCreeper.contains(creeper.getUniqueId())) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: preventing creeeper from damaging");
}
e.setCancelled(true);
return;
}
}
// Ops can do anything
if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager();
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
}
// Get the real attacker
boolean flamingArrow = false;
boolean projectile = false;
Player attacker = null;
if (e.getDamager() instanceof Player) {
attacker = (Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Projectile damage");
projectile = true;
// Find out who fired the arrow
Projectile p = (Projectile) e.getDamager();
if (DEBUG)
plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString());
if (p.getShooter() instanceof Player) {
attacker = (Player) p.getShooter();
if (p.getFireTicks() > 0) {
flamingArrow = true;
}
// Check if this is a flaming arrow
if (DEBUG)
plugin.getLogger().info("DEBUG: fire ticks = " + p.getFireTicks() + " max = " + p.getMaxFireTicks());
}
}
if (attacker == null) {
// Not a player
return;
}
// Self damage
if (e.getEntity() instanceof Player && attacker.equals((Player) e.getEntity())) {
if (DEBUG)
plugin.getLogger().info("Self damage!");
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Another player");
// Check to see if it's an item frame
if (e.getEntity() instanceof ItemFrame || e.getEntityType().toString().endsWith("STAND")) {
if (island != null && (island.getIgsFlag(SettingsFlag.BREAK_BLOCKS) || island.getMembers().contains(attacker.getUniqueId()))) {
return;
}
// Else not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
// Monsters being hurt
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) {
// Normal island check
if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
// Members always allowed
return;
}
if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) {
// Check for visitors setting creepers alight using flint steel
if (!Settings.allowCreeperGriefing && e.getEntity() instanceof Creeper) {
for (ItemStack holding : Util.getPlayerInHandItems(attacker)) {
if (holding.getType().equals(Material.FLINT_AND_STEEL)) {
// Save this creeper for later when any damage caused by its explosion will be nullified
litCreeper.add(e.getEntity().getUniqueId());
if (DEBUG) {
plugin.getLogger().info("DEBUG: adding to lit creeper set");
}
}
}
}
return;
}
// Not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
// Mobs being hurt
if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman || e.getEntity() instanceof Villager) {
if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
return;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
// Else not allowed
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
// Establish whether PVP is allowed or not.
boolean pvp = false;
if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
if (DEBUG)
plugin.getLogger().info("DEBUG: PVP allowed");
pvp = true;
}
// Players being hurt PvP
if (e.getEntity() instanceof Player) {
if (pvp) {
return;
} else {
Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
if (flamingArrow)
e.getEntity().setFireTicks(0);
if (projectile)
e.getDamager().remove();
e.setCancelled(true);
return;
}
}
}
Aggregations