Fixes item frame protection by flag. Also affects armor stands

https://github.com/BentoBoxWorld/BentoBox/issues/1023
This commit is contained in:
tastybento 2019-11-06 17:43:30 -08:00
parent 21e75c645e
commit d3e35a9ecb
2 changed files with 16 additions and 3 deletions

View File

@ -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;
@ -108,14 +109,25 @@ public class BreakBlocksListener extends FlagListener {
}
// 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;
}
}

View File

@ -39,7 +39,8 @@ public class PlaceBlocksListener extends FlagListener {
@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);
}
}