mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 20:25:16 +01:00
Added CANDLES and BELL_RINGING flags and protections
This commit is contained in:
parent
3d00191b90
commit
16592c595b
@ -100,9 +100,11 @@ public class BlockInteractionListener extends FlagListener
|
||||
switch (type)
|
||||
{
|
||||
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 BEEHIVE, BEE_NEST -> this.checkIsland(e, player, loc, Flags.HIVE);
|
||||
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 TRAPPED_CHEST -> this.checkIsland(e, player, loc, Flags.TRAPPED_CHEST);
|
||||
case FLOWER_POT -> this.checkIsland(e, player, loc, Flags.FLOWER_POT);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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,
|
||||
Tag.PRESSURE_PLATES, Flags.PRESSURE_PLATE, Tag.FENCE_GATES, Flags.GATE, Tag.DOORS, Flags.DOOR);
|
||||
private boolean checkBlocks(Event e, Player player, Block block) {
|
||||
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) {
|
||||
TAG_TO_FLAG.entrySet().stream().filter(entry -> entry.getKey().isTagged(block.getType())).findFirst()
|
||||
.ifPresent(entry -> this.checkIsland(e, player, block.getLocation(), entry.getValue()));
|
||||
if (result && MAT_TO_FLAG.containsKey(block.getType())) {
|
||||
result = this.checkIsland(e, player, block.getLocation(), MAT_TO_FLAG.get(block.getType()));
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
@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) {
|
||||
for (Block b : e.blockList()) {
|
||||
this.checkBlocks(e, player, b);
|
||||
/*
|
||||
* TODO:
|
||||
* Add protection for candles
|
||||
*
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.BreedingListener;
|
||||
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.EggListener;
|
||||
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();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Deprecated Flags are ignored.
|
||||
|
@ -912,6 +912,10 @@ protection:
|
||||
description: Toggle interaction
|
||||
name: Beacons
|
||||
hint: Beacon use disabled
|
||||
BELL_RINGING:
|
||||
description: Toggle interaction
|
||||
name: Allow bell ringing
|
||||
hint: Bell ringing disabled
|
||||
BED:
|
||||
description: Toggle interaction
|
||||
name: Beds
|
||||
@ -960,6 +964,10 @@ protection:
|
||||
description: Toggle button use
|
||||
name: Buttons
|
||||
hint: Button use disabled
|
||||
CANDLES:
|
||||
description: Toggle candle interaction
|
||||
name: Candles
|
||||
hint: Candle interaction disabled
|
||||
CAKE:
|
||||
description: Toggle cake interaction
|
||||
name: Cakes
|
||||
|
Loading…
Reference in New Issue
Block a user