Added chest damage listener

Also fixed a bug with creeper listener to only apply to island worlds.

Made TNT flag an island settings. Woohoo!
This commit is contained in:
tastybento 2018-07-19 19:55:32 -07:00
parent c61b87628f
commit f8da453a29
3 changed files with 34 additions and 6 deletions

View File

@ -0,0 +1,29 @@
/**
*
*/
package us.tastybento.bskyblock.listeners.flags;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityExplodeEvent;
import us.tastybento.bskyblock.api.flags.AbstractFlagListener;
import us.tastybento.bskyblock.lists.Flags;
/**
* @author tastybento
*
*/
public class ChestDamageListener extends AbstractFlagListener {
/**
* Prevent chest damage from explosion
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) {
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));
}
}
}

View File

@ -3,7 +3,6 @@
*/
package us.tastybento.bskyblock.listeners.flags;
import org.bukkit.Bukkit;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -31,8 +30,7 @@ public class CreeperListener extends AbstractFlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) {
Bukkit.getLogger().info(e.getEventName());
if (e.getEntity() == null || !e.getEntityType().equals(EntityType.CREEPER)) {
if (e.getEntity() == null || !e.getEntityType().equals(EntityType.CREEPER) || !getIWM().inWorld(e.getLocation())) {
return;
}
// If creeper damage is not allowed in world, remove it

View File

@ -14,6 +14,7 @@ import us.tastybento.bskyblock.listeners.flags.BlockInteractionListener;
import us.tastybento.bskyblock.listeners.flags.BreakBlocksListener;
import us.tastybento.bskyblock.listeners.flags.BreedingListener;
import us.tastybento.bskyblock.listeners.flags.BucketListener;
import us.tastybento.bskyblock.listeners.flags.ChestDamageListener;
import us.tastybento.bskyblock.listeners.flags.CleanSuperFlatListener;
import us.tastybento.bskyblock.listeners.flags.CreeperListener;
import us.tastybento.bskyblock.listeners.flags.EggListener;
@ -155,7 +156,7 @@ public class Flags {
.listener(new MobSpawnListener()).build();
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(Type.SETTING).build();
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).allowedByDefault(true).type(Type.SETTING).build();
public static final Flag TNT = new FlagBuilder().id("TNT").icon(Material.TNT).listener(new TNTListener()).allowedByDefault(false).type(Type.SETTING).build();
/*
* World Settings - they apply to every island in the game worlds.
*/
@ -191,7 +192,7 @@ public class Flags {
.listener(new CleanSuperFlatListener()).allowedByDefault(false).build();
public static final Flag CHEST_DAMAGE = new FlagBuilder().id("CHEST_DAMAGE").icon(Material.TRAPPED_CHEST).type(Type.WORLD_SETTING)
.allowedByDefault(false).build();
.listener(new ChestDamageListener()).allowedByDefault(false).build();
public static final Flag CREEPER_DAMAGE = new FlagBuilder().id("CREEPER_DAMAGE").listener(new CreeperListener()).icon(Material.GREEN_SHULKER_BOX).type(Type.WORLD_SETTING)
.allowedByDefault(true).build();
/**
@ -202,7 +203,7 @@ public class Flags {
/**
* Globally allows or disallows TNT explosion damage/pain.
*/
public static final Flag TNT = new FlagBuilder().id("TNT").icon(Material.TNT).listener(new TNTListener()).allowedByDefault(false).type(Type.WORLD_SETTING).build();
/**