Fills in protections.

Shulker box done. Pots done. Pufferfish are considered Monsters, not
animals because they can hurt visitors. Other fish protected. Bonemeal
prevented (place blocks). Name tags done.

https://github.com/BentoBoxWorld/bentobox/issues/336
This commit is contained in:
tastybento 2018-11-10 21:03:04 -08:00
parent c2e9490bb0
commit 2ca00969e7
4 changed files with 33 additions and 7 deletions

View File

@ -31,10 +31,17 @@ public class BlockInteractionListener extends FlagListener {
// Now check for in-hand items // Now check for in-hand items
if (e.getItem() != null) { if (e.getItem() != null) {
if (e.getItem().getType().name().contains("BOAT")) {
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
return;
}
switch (e.getItem().getType()) { switch (e.getItem().getType()) {
case ENDER_PEARL: case ENDER_PEARL:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ENDER_PEARL); checkIsland(e, e.getClickedBlock().getLocation(), Flags.ENDER_PEARL);
break; break;
case BONE_MEAL:
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
break;
case BAT_SPAWN_EGG: case BAT_SPAWN_EGG:
case BLAZE_SPAWN_EGG: case BLAZE_SPAWN_EGG:
case CAVE_SPIDER_SPAWN_EGG: case CAVE_SPIDER_SPAWN_EGG:
@ -102,6 +109,11 @@ public class BlockInteractionListener extends FlagListener {
* @param type - material type of clicked block * @param type - material type of clicked block
*/ */
private void checkClickedBlock(Event e, Location loc, Material type) { private void checkClickedBlock(Event e, Location loc, Material type) {
// Handle pots
if (type.name().startsWith("POTTED")) {
checkIsland(e, loc, Flags.CHEST);
return;
}
switch (type) { switch (type) {
case ANVIL: case ANVIL:
checkIsland(e, loc, Flags.ANVIL); checkIsland(e, loc, Flags.ANVIL);
@ -150,6 +162,8 @@ public class BlockInteractionListener extends FlagListener {
case LIGHT_GRAY_SHULKER_BOX: case LIGHT_GRAY_SHULKER_BOX:
case WHITE_SHULKER_BOX: case WHITE_SHULKER_BOX:
case YELLOW_SHULKER_BOX: case YELLOW_SHULKER_BOX:
case SHULKER_BOX:
case FLOWER_POT:
case DISPENSER: case DISPENSER:
case DROPPER: case DROPPER:
case HOPPER: case HOPPER:

View File

@ -20,7 +20,10 @@ public class ChestDamageListener extends FlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) { public void onExplosion(final EntityExplodeEvent e) {
if (getIWM().inWorld(e.getLocation()) && !Flags.CHEST_DAMAGE.isSetForWorld(e.getLocation().getWorld())) { if (getIWM().inWorld(e.getLocation()) && !Flags.CHEST_DAMAGE.isSetForWorld(e.getLocation().getWorld())) {
e.blockList().removeIf(b -> b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)); e.blockList().removeIf(b -> b.getType().equals(Material.CHEST)
|| b.getType().equals(Material.TRAPPED_CHEST)
|| b.getType().name().contains("SHULKER_BOX")
);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags; package world.bentobox.bentobox.listeners.flags;
import org.bukkit.Material;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -37,5 +38,9 @@ public class EntityInteractListener extends FlagListener {
if (e.getRightClicked().getType().equals(EntityType.VILLAGER)) { if (e.getRightClicked().getType().equals(EntityType.VILLAGER)) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.TRADING); checkIsland(e, e.getRightClicked().getLocation(), Flags.TRADING);
} }
// Name tags
if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NAME_TAG)) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS);
}
} }
} }

View File

@ -6,12 +6,14 @@ import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Fish;
import org.bukkit.entity.IronGolem; import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Parrot; import org.bukkit.entity.Parrot;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.entity.PufferFish;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.entity.Snowman; import org.bukkit.entity.Snowman;
import org.bukkit.entity.Squid; import org.bukkit.entity.Squid;
@ -27,8 +29,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
@ -49,11 +51,13 @@ public class HurtingListener extends FlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageByEntityEvent e) { public void onEntityDamage(final EntityDamageByEntityEvent e) {
// Mobs being hurt // Mobs being hurt
if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman) { if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman
|| (e.getEntity() instanceof Fish && !(e.getEntity() instanceof PufferFish))) {
respond(e, e.getDamager(), Flags.HURT_ANIMALS); respond(e, e.getDamager(), Flags.HURT_ANIMALS);
} else if (e.getEntity() instanceof Villager) { } else if (e.getEntity() instanceof Villager) {
respond(e, e.getDamager(), Flags.HURT_VILLAGERS); respond(e, e.getDamager(), Flags.HURT_VILLAGERS);
} else if (e.getEntity() instanceof Monster || e.getEntity() instanceof Squid || e.getEntity() instanceof Slime) { } else if (e.getEntity() instanceof Monster || e.getEntity() instanceof Squid
|| e.getEntity() instanceof Slime || e.getEntity() instanceof PufferFish) {
respond(e, e.getDamager(), Flags.HURT_MONSTERS); respond(e, e.getDamager(), Flags.HURT_MONSTERS);
} }
} }