Skip to content

Commit

Permalink
Fixes item frame protection by flag. Also affects armor stands
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 7, 2019
1 parent 21e75c6 commit d3e35a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags.protection;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
Expand Down Expand Up @@ -108,14 +109,25 @@ public void onEntityDamage(EntityDamageByEntityEvent e) {
}
// Get the attacker
if (e.getDamager() instanceof Player) {
checkIsland(e, (Player)e.getDamager(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
// Check the break blocks flag
notAllowed(e, (Player)e.getDamager(), e.getEntity().getLocation());
} else if (e.getDamager() instanceof Projectile) {
// Find out who fired the arrow
Projectile p = (Projectile) e.getDamager();
if (p.getShooter() instanceof Player && !checkIsland(e, (Player)p.getShooter(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS)) {
if (p.getShooter() instanceof Player && notAllowed(e, (Player)p.getShooter(), e.getEntity().getLocation())) {
e.getEntity().setFireTicks(0);
p.setFireTicks(0);
}
}
}

private boolean notAllowed(EntityDamageByEntityEvent e, Player player, Location location) {
if (!checkIsland(e, player, location, Flags.BREAK_BLOCKS)) return true;
if (e.getEntity() instanceof ItemFrame) {
return !checkIsland(e, player, location, Flags.ITEM_FRAME);
} else if (e.getEntity() instanceof ArmorStand) {
return !checkIsland(e, player, location, Flags.ARMOR_STAND);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void onBlockPlace(final BlockPlaceEvent e) {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerHitItemFrame(PlayerInteractEntityEvent e) {
if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) {
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS);
if (!checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS)) return;
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.ITEM_FRAME);
}
}

Expand Down

1 comment on commit d3e35a9

@Poslovitch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flags descriptions should be updated to clearly state the change.

Please sign in to comment.