mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-29 12:37:37 +01:00
Added creeper listener. Fixed bugs with listener reg.
This commit is contained in:
parent
4f5b6a25b6
commit
d8f783999b
@ -0,0 +1,57 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
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.api.localization.TextVariables;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
/**
|
||||
* Listens for creepers hsssssssh!
|
||||
* For the {@link us.tastybento.bskyblock.lists.Flags#CREEPER_DAMAGE}
|
||||
* and {@link us.tastybento.bskyblock.lists.Flags#CREEPER_GRIEFING} flags.
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class CreeperListener extends AbstractFlagListener {
|
||||
|
||||
/**
|
||||
* Prevent damage from explosion
|
||||
* @param e - event
|
||||
*/
|
||||
@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)) {
|
||||
return;
|
||||
}
|
||||
// If creeper damage is not allowed in world, remove it
|
||||
if (!Flags.CREEPER_DAMAGE.isSetForWorld(e.getLocation().getWorld())) {
|
||||
// If any were removed, then prevent damage too
|
||||
e.blockList().clear();
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// Check for griefing
|
||||
Creeper creeper = (Creeper)e.getEntity();
|
||||
if (!Flags.CREEPER_GRIEFING.isSetForWorld(e.getLocation().getWorld()) && creeper.getTarget() instanceof Player) {
|
||||
Player target = (Player)creeper.getTarget();
|
||||
if (!getIslands().locationIsOnIsland(target, e.getLocation())) {
|
||||
User user = User.getInstance(target);
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.CREEPER_GRIEFING.getHintReference()));
|
||||
e.setCancelled(true);
|
||||
e.blockList().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ 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.CleanSuperFlatListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.CreeperListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.EggListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.EnderChestListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.EnterExitListener;
|
||||
@ -191,10 +192,16 @@ public class Flags {
|
||||
|
||||
public static final Flag CHEST_DAMAGE = new FlagBuilder().id("CHEST_DAMAGE").icon(Material.TRAPPED_CHEST).type(Type.WORLD_SETTING)
|
||||
.allowedByDefault(false).build();
|
||||
public static final Flag CREEPER_DAMAGE = new FlagBuilder().id("CREEPER_DAMAGE").icon(Material.GREEN_SHULKER_BOX).type(Type.WORLD_SETTING)
|
||||
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();
|
||||
/**
|
||||
* Prevents creeper griefing. This is where a visitor will trigger a creeper to blow up an island.
|
||||
*/
|
||||
public static final Flag CREEPER_GRIEFING = new FlagBuilder().id("CREEPER_GRIEFING").icon(Material.FIREWORK).type(Type.WORLD_SETTING)
|
||||
.allowedByDefault(false).build();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class FlagsManager {
|
||||
* Register any unregistered listeners - called after the plugin is fully loaded
|
||||
*/
|
||||
public void registerListeners() {
|
||||
registeredListeners.entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).forEach(this::registerListener);
|
||||
registeredListeners.entrySet().stream().filter(e -> !e.getValue()).map(Map.Entry::getKey).forEach(this::registerListener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user