Added CANDLES and BELL_RINGING flags and protections

This commit is contained in:
tastybento 2024-07-14 16:02:00 -07:00
parent 3d00191b90
commit 16592c595b
5 changed files with 81 additions and 6 deletions

View File

@ -100,9 +100,11 @@ public class BlockInteractionListener extends FlagListener
switch (type) switch (type)
{ {
case BEACON -> this.checkIsland(e, player, loc, Flags.BEACON); case BEACON -> this.checkIsland(e, player, loc, Flags.BEACON);
case BELL -> this.checkIsland(e, player, loc, Flags.BELL_RINGING);
case BREWING_STAND -> this.checkIsland(e, player, loc, Flags.BREWING); case BREWING_STAND -> this.checkIsland(e, player, loc, Flags.BREWING);
case BEEHIVE, BEE_NEST -> this.checkIsland(e, player, loc, Flags.HIVE); case BEEHIVE, BEE_NEST -> this.checkIsland(e, player, loc, Flags.HIVE);
case BARREL -> this.checkIsland(e, player, loc, Flags.BARREL); case BARREL -> this.checkIsland(e, player, loc, Flags.BARREL);
case CANDLE -> this.checkIsland(e, player, loc, Flags.CANDLES);
case CHEST, CHEST_MINECART -> this.checkIsland(e, player, loc, Flags.CHEST); case CHEST, CHEST_MINECART -> this.checkIsland(e, player, loc, Flags.CHEST);
case TRAPPED_CHEST -> this.checkIsland(e, player, loc, Flags.TRAPPED_CHEST); case TRAPPED_CHEST -> this.checkIsland(e, player, loc, Flags.TRAPPED_CHEST);
case FLOWER_POT -> this.checkIsland(e, player, loc, Flags.FLOWER_POT); case FLOWER_POT -> this.checkIsland(e, player, loc, Flags.FLOWER_POT);

View File

@ -0,0 +1,33 @@
package world.bentobox.bentobox.listeners.flags.protection;
import org.bukkit.Tag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
/**
* Protects candles
* @author tastybento
* @since 2.4.2
*/
public class CandleListener extends FlagListener {
/**
* Prevent dying signs.
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCandleInteract(final PlayerInteractEvent e) {
if (e.getClickedBlock() == null || e.getItem() == null) {
return;
}
if (Tag.CANDLES.isTagged(e.getClickedBlock().getType())
|| Tag.CANDLE_CAKES.isTagged(e.getClickedBlock().getType())) {
this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.CANDLES);
}
}
}

View File

@ -67,16 +67,25 @@ public class PhysicalInteractionListener extends FlagListener
} }
} }
private static final Map<Tag<Material>, Flag> TAG_TO_FLAG = Map.of(Tag.WOODEN_BUTTONS, Flags.BUTTON, private boolean checkBlocks(Event e, Player player, Block block) {
Tag.PRESSURE_PLATES, Flags.PRESSURE_PLATE, Tag.FENCE_GATES, Flags.GATE, Tag.DOORS, Flags.DOOR); Map<Tag<Material>, Flag> TAG_TO_FLAG = Map.of(Tag.WOODEN_BUTTONS, Flags.BUTTON, Tag.PRESSURE_PLATES,
Flags.PRESSURE_PLATE, Tag.FENCE_GATES, Flags.GATE, Tag.DOORS, Flags.DOOR, Tag.CANDLE_CAKES,
Flags.CANDLES, Tag.CANDLES, Flags.CANDLES);
Map<Material, Flag> MAT_TO_FLAG = Map.of(Material.LEVER, Flags.LEVER, Material.TRIPWIRE, Flags.REDSTONE,
Material.TARGET, Flags.REDSTONE);
boolean result = TAG_TO_FLAG.entrySet().stream().filter(entry -> entry.getKey().isTagged(block.getType()))
.findFirst().map(entry -> this.checkIsland(e, player, block.getLocation(), entry.getValue()))
.orElse(true);
private void checkBlocks(Event e, Player player, Block block) { if (result && MAT_TO_FLAG.containsKey(block.getType())) {
TAG_TO_FLAG.entrySet().stream().filter(entry -> entry.getKey().isTagged(block.getType())).findFirst() result = this.checkIsland(e, player, block.getLocation(), MAT_TO_FLAG.get(block.getType()));
.ifPresent(entry -> this.checkIsland(e, player, block.getLocation(), entry.getValue())); }
return result;
} }
/** /**
* Protects buttons and plates from being activated by projectiles that explode * Protects buttons and plates, etc. from being activated by projectiles that explode
* @param e - event * @param e - event
*/ */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@ -84,6 +93,11 @@ public class PhysicalInteractionListener extends FlagListener
if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player) { if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player) {
for (Block b : e.blockList()) { for (Block b : e.blockList()) {
this.checkBlocks(e, player, b); this.checkBlocks(e, player, b);
/*
* TODO:
* Add protection for candles
*
*/
} }
} }
} }

View File

@ -19,6 +19,7 @@ import world.bentobox.bentobox.listeners.flags.protection.BlockInteractionListen
import world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener; import world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener;
import world.bentobox.bentobox.listeners.flags.protection.BreedingListener; import world.bentobox.bentobox.listeners.flags.protection.BreedingListener;
import world.bentobox.bentobox.listeners.flags.protection.BucketListener; import world.bentobox.bentobox.listeners.flags.protection.BucketListener;
import world.bentobox.bentobox.listeners.flags.protection.CandleListener;
import world.bentobox.bentobox.listeners.flags.protection.DyeListener; import world.bentobox.bentobox.listeners.flags.protection.DyeListener;
import world.bentobox.bentobox.listeners.flags.protection.EggListener; import world.bentobox.bentobox.listeners.flags.protection.EggListener;
import world.bentobox.bentobox.listeners.flags.protection.ElytraListener; import world.bentobox.bentobox.listeners.flags.protection.ElytraListener;
@ -687,6 +688,23 @@ public final class Flags {
*/ */
public static final Flag SIGN_EDITING = new Flag.Builder("SIGN_EDITING", Material.DARK_OAK_SIGN).mode(Flag.Mode.BASIC).type(Type.PROTECTION).build(); public static final Flag SIGN_EDITING = new Flag.Builder("SIGN_EDITING", Material.DARK_OAK_SIGN).mode(Flag.Mode.BASIC).type(Type.PROTECTION).build();
/**
* Bell ringing protection
* Listeners are {@link BlockInteractionListener} and {@link PhysicalInteractionListener}
* @since 2.4.2
*/
public static final Flag BELL_RINGING = new Flag.Builder("BELL_RINGING", Material.BELL).mode(Flag.Mode.EXPERT)
.type(Type.PROTECTION).build();
/**
* Candle protection
* Listener is {@link CandleListener}
* @since 2.4.2
*/
public static final Flag CANDLES = new Flag.Builder("CANDLES", Material.CANDLE).mode(Flag.Mode.EXPERT)
.listener(new CandleListener())
.type(Type.PROTECTION).build();
/** /**
* Provides a list of all the Flag instances contained in this class using reflection. * Provides a list of all the Flag instances contained in this class using reflection.
* Deprecated Flags are ignored. * Deprecated Flags are ignored.

View File

@ -912,6 +912,10 @@ protection:
description: Toggle interaction description: Toggle interaction
name: Beacons name: Beacons
hint: Beacon use disabled hint: Beacon use disabled
BELL_RINGING:
description: Toggle interaction
name: Allow bell ringing
hint: Bell ringing disabled
BED: BED:
description: Toggle interaction description: Toggle interaction
name: Beds name: Beds
@ -960,6 +964,10 @@ protection:
description: Toggle button use description: Toggle button use
name: Buttons name: Buttons
hint: Button use disabled hint: Button use disabled
CANDLES:
description: Toggle candle interaction
name: Candles
hint: Candle interaction disabled
CAKE: CAKE:
description: Toggle cake interaction description: Toggle cake interaction
name: Cakes name: Cakes