Skip to content

Commit f515ae2

Browse files
authored
Merge pull request #2432 from BentoBoxWorld/2422_flags_for_1.21
2422 flags for 1.21
2 parents 18cd62d + 7251517 commit f515ae2

File tree

13 files changed

+291
-29
lines changed

13 files changed

+291
-29
lines changed

src/main/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ private void checkClickedBlock(Event e, Player player, Block block)
100100
switch (type)
101101
{
102102
case BEACON -> this.checkIsland(e, player, loc, Flags.BEACON);
103+
case BELL -> this.checkIsland(e, player, loc, Flags.BELL_RINGING);
103104
case BREWING_STAND -> this.checkIsland(e, player, loc, Flags.BREWING);
104105
case BEEHIVE, BEE_NEST -> this.checkIsland(e, player, loc, Flags.HIVE);
105106
case BARREL -> this.checkIsland(e, player, loc, Flags.BARREL);
107+
case CANDLE -> this.checkIsland(e, player, loc, Flags.CANDLES);
106108
case CHEST, CHEST_MINECART -> this.checkIsland(e, player, loc, Flags.CHEST);
107109
case TRAPPED_CHEST -> this.checkIsland(e, player, loc, Flags.TRAPPED_CHEST);
108110
case FLOWER_POT -> this.checkIsland(e, player, loc, Flags.FLOWER_POT);

src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.bukkit.event.player.PlayerInteractEvent;
2222
import org.bukkit.event.vehicle.VehicleDamageEvent;
2323

24+
import com.google.common.base.Enums;
25+
2426
import world.bentobox.bentobox.api.flags.FlagListener;
2527
import world.bentobox.bentobox.lists.Flags;
2628

@@ -101,6 +103,10 @@ public void onPlayerInteract(final PlayerInteractEvent e)
101103
{
102104
return;
103105
}
106+
if (Enums.getIfPresent(Material.class, "TRIAL_SPAWNER").isPresent() && m.equals(Material.TRIAL_SPAWNER)) {
107+
this.checkIsland(e, p, l, Flags.BREAK_SPAWNERS);
108+
return;
109+
}
104110
switch (m)
105111
{
106112
case CAKE -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS);
@@ -182,7 +188,7 @@ private boolean notAllowed(EntityDamageByEntityEvent e, Player player, Location
182188
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
183189
public void onProjectileHitBreakBlock(ProjectileHitEvent e) {
184190
// We want to make sure this is an actual projectile (arrow or trident)
185-
if (!(e.getEntity() instanceof AbstractArrow)) {
191+
if (!(e.getEntity() instanceof Projectile)) {
186192
return;
187193
}
188194

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package world.bentobox.bentobox.listeners.flags.protection;
2+
3+
import org.bukkit.Tag;
4+
import org.bukkit.event.EventHandler;
5+
import org.bukkit.event.EventPriority;
6+
import org.bukkit.event.player.PlayerInteractEvent;
7+
8+
import world.bentobox.bentobox.api.flags.FlagListener;
9+
import world.bentobox.bentobox.lists.Flags;
10+
11+
/**
12+
* Protects candles
13+
* @author tastybento
14+
* @since 2.4.2
15+
*/
16+
public class CandleListener extends FlagListener {
17+
18+
/**
19+
* Prevent dying signs.
20+
* @param e - event
21+
*/
22+
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
23+
public void onCandleInteract(final PlayerInteractEvent e) {
24+
if (e.getClickedBlock() == null) {
25+
return;
26+
}
27+
28+
if (Tag.CANDLES.isTagged(e.getClickedBlock().getType())
29+
|| Tag.CANDLE_CAKES.isTagged(e.getClickedBlock().getType())) {
30+
this.checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.CANDLES);
31+
}
32+
}
33+
}

src/main/java/world/bentobox/bentobox/listeners/flags/protection/TNTListener.java renamed to src/main/java/world/bentobox/bentobox/listeners/flags/protection/ExplosionListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Protects islands from visitors blowing things up
2828
* @author tastybento
2929
*/
30-
public class TNTListener extends FlagListener {
30+
public class ExplosionListener extends FlagListener {
3131
/**
3232
* Contains {@link EntityType}s that generates an explosion.
3333
* @since 1.5.0

src/main/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListener.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package world.bentobox.bentobox.listeners.flags.protection;
22

3+
import java.util.Map;
4+
35
import org.bukkit.Material;
46
import org.bukkit.Tag;
7+
import org.bukkit.block.Block;
58
import org.bukkit.entity.Player;
69
import org.bukkit.entity.Projectile;
10+
import org.bukkit.event.Event;
711
import org.bukkit.event.EventHandler;
812
import org.bukkit.event.EventPriority;
913
import org.bukkit.event.block.Action;
14+
import org.bukkit.event.entity.EntityExplodeEvent;
1015
import org.bukkit.event.entity.EntityInteractEvent;
1116
import org.bukkit.event.player.PlayerInteractEvent;
1217

18+
import world.bentobox.bentobox.api.flags.Flag;
1319
import world.bentobox.bentobox.api.flags.FlagListener;
1420
import world.bentobox.bentobox.lists.Flags;
1521

@@ -55,24 +61,43 @@ public void onPlayerInteract(PlayerInteractEvent e)
5561
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
5662
public void onProjectileHit(EntityInteractEvent e)
5763
{
58-
if (!(e.getEntity() instanceof Projectile p))
64+
if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player)
5965
{
60-
return;
66+
checkBlocks(e, player, e.getBlock());
6167
}
68+
}
6269

63-
if (p.getShooter() instanceof Player player)
64-
{
65-
if (Tag.WOODEN_BUTTONS.isTagged(e.getBlock().getType()))
66-
{
67-
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.BUTTON);
68-
return;
69-
}
70+
private boolean checkBlocks(Event e, Player player, Block block) {
71+
Map<Tag<Material>, Flag> TAG_TO_FLAG = Map.of(Tag.WOODEN_BUTTONS, Flags.BUTTON, Tag.PRESSURE_PLATES,
72+
Flags.PRESSURE_PLATE, Tag.FENCE_GATES, Flags.GATE, Tag.DOORS, Flags.DOOR, Tag.CANDLE_CAKES,
73+
Flags.CANDLES, Tag.CANDLES, Flags.CANDLES);
74+
Map<Material, Flag> MAT_TO_FLAG = Map.of(Material.LEVER, Flags.LEVER, Material.TRIPWIRE, Flags.REDSTONE,
75+
Material.TARGET, Flags.REDSTONE, Material.DECORATED_POT, Flags.BREAK_BLOCKS);
76+
boolean result = TAG_TO_FLAG.entrySet().stream().filter(entry -> entry.getKey().isTagged(block.getType()))
77+
.findFirst().map(entry -> this.checkIsland(e, player, block.getLocation(), entry.getValue()))
78+
.orElse(true);
79+
if (result && MAT_TO_FLAG.containsKey(block.getType())) {
80+
result = this.checkIsland(e, player, block.getLocation(), MAT_TO_FLAG.get(block.getType()));
81+
82+
}
7083

71-
if (Tag.PRESSURE_PLATES.isTagged(e.getBlock().getType()))
72-
{
73-
// Pressure plates
74-
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.PRESSURE_PLATE);
84+
return result;
85+
}
86+
87+
/**
88+
* Protects buttons and plates, etc. from being activated by projectiles that explode
89+
* @param e - event
90+
*/
91+
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
92+
public void onProjectileExplode(EntityExplodeEvent e) {
93+
if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player) {
94+
for (Block b : e.blockList()) {
95+
if (!this.checkBlocks(e, player, b)) {
96+
e.blockList().clear();
97+
}
7598
}
7699
}
77100
}
101+
102+
78103
}

src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/SpawnerSpawnEggsListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package world.bentobox.bentobox.listeners.flags.worldsettings;
22

3-
import org.bukkit.Material;
43
import org.bukkit.event.EventHandler;
54
import org.bukkit.event.EventPriority;
65
import org.bukkit.event.player.PlayerInteractEvent;
@@ -21,8 +20,8 @@ public class SpawnerSpawnEggsListener extends FlagListener {
2120
public void onSpawnerChange(final PlayerInteractEvent e) {
2221
User user = User.getInstance(e.getPlayer());
2322
// Checking if the clicked block is a spawner and the item in hand is a mob egg
24-
if (e.getClickedBlock() != null && e.getClickedBlock().getType().equals(Material.SPAWNER)
25-
&& e.getItem() != null && e.getItem().getType().toString().endsWith("_SPAWN_EGG")
23+
if (e.getClickedBlock() != null && e.getClickedBlock().getType().name().endsWith("_SPAWNER")
24+
&& e.getItem() != null && e.getItem().getType().name().endsWith("_SPAWN_EGG")
2625
&& getIWM().inWorld(e.getClickedBlock().getWorld())
2726
&& !(user.hasPermission(getIWM().getPermissionPrefix(e.getClickedBlock().getWorld()) + "mod.bypass." + Flags.SPAWNER_SPAWN_EGGS.getID() + ".everywhere")
2827
|| user.hasPermission(getIWM().getPermissionPrefix(e.getClickedBlock().getWorld()) + "mod.bypassprotect"))

src/main/java/world/bentobox/bentobox/lists/Flags.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener;
2020
import world.bentobox.bentobox.listeners.flags.protection.BreedingListener;
2121
import world.bentobox.bentobox.listeners.flags.protection.BucketListener;
22+
import world.bentobox.bentobox.listeners.flags.protection.CandleListener;
2223
import world.bentobox.bentobox.listeners.flags.protection.DyeListener;
2324
import world.bentobox.bentobox.listeners.flags.protection.EggListener;
2425
import world.bentobox.bentobox.listeners.flags.protection.ElytraListener;
@@ -38,7 +39,7 @@
3839
import world.bentobox.bentobox.listeners.flags.protection.SculkSensorListener;
3940
import world.bentobox.bentobox.listeners.flags.protection.SculkShriekerListener;
4041
import world.bentobox.bentobox.listeners.flags.protection.ShearingListener;
41-
import world.bentobox.bentobox.listeners.flags.protection.TNTListener;
42+
import world.bentobox.bentobox.listeners.flags.protection.ExplosionListener;
4243
import world.bentobox.bentobox.listeners.flags.protection.TeleportationListener;
4344
import world.bentobox.bentobox.listeners.flags.protection.ThrowingListener;
4445
import world.bentobox.bentobox.listeners.flags.settings.DecayListener;
@@ -266,9 +267,9 @@ private Flags() {}
266267
* Prevents players from priming TNT.
267268
* @since 1.5.0
268269
*
269-
* @see TNTListener
270+
* @see ExplosionListener
270271
*/
271-
public static final Flag TNT_PRIMING = new Flag.Builder("TNT_PRIMING", Material.TNT).listener(new TNTListener()).build();
272+
public static final Flag TNT_PRIMING = new Flag.Builder("TNT_PRIMING", Material.TNT).listener(new ExplosionListener()).build();
272273

273274
/**
274275
* Prevents players from extinguishing fires.
@@ -461,23 +462,23 @@ private Flags() {}
461462
/**
462463
* If {@code false}, prevents TNT from breaking blocks and damaging nearby entities.
463464
* @since 1.5.0
464-
* @see TNTListener
465+
* @see ExplosionListener
465466
*/
466467
public static final Flag TNT_DAMAGE = new Flag.Builder("TNT_DAMAGE", Material.TNT).type(Type.SETTING)
467468
.mode(Flag.Mode.ADVANCED).build();
468469

469470
/**
470471
* If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities.
471472
* @since 1.19.1
472-
* @see TNTListener
473+
* @see ExplosionListener
473474
*/
474475
public static final Flag BLOCK_EXPLODE_DAMAGE = new Flag.Builder("BLOCK_EXPLODE_DAMAGE", Material.TNT_MINECART).type(Type.SETTING)
475476
.mode(Flag.Mode.ADVANCED).build();
476477

477478
/**
478479
* If {@code false}, prevents TNT from breaking blocks and damaging nearby entities outside of island boundaries.
479480
* @since 1.15.3
480-
* @see TNTListener
481+
* @see ExplosionListener
481482
*/
482483
public static final Flag WORLD_TNT_DAMAGE = new Flag.Builder("WORLD_TNT_DAMAGE", Material.TNT)
483484
.type(Type.WORLD_SETTING)
@@ -486,7 +487,7 @@ private Flags() {}
486487
/**
487488
* If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities outside of island boundaries.
488489
* @since 1.19.1
489-
* @see TNTListener
490+
* @see ExplosionListener
490491
*/
491492
public static final Flag WORLD_BLOCK_EXPLODE_DAMAGE = new Flag.Builder("WORLD_BLOCK_EXPLODE_DAMAGE", Material.TNT_MINECART)
492493
.type(Type.WORLD_SETTING)
@@ -687,6 +688,23 @@ private Flags() {}
687688
*/
688689
public static final Flag SIGN_EDITING = new Flag.Builder("SIGN_EDITING", Material.DARK_OAK_SIGN).mode(Flag.Mode.BASIC).type(Type.PROTECTION).build();
689690

691+
/**
692+
* Bell ringing protection
693+
* Listeners are {@link BlockInteractionListener} and {@link PhysicalInteractionListener}
694+
* @since 2.4.2
695+
*/
696+
public static final Flag BELL_RINGING = new Flag.Builder("BELL_RINGING", Material.BELL).mode(Flag.Mode.EXPERT)
697+
.type(Type.PROTECTION).build();
698+
699+
/**
700+
* Candle protection
701+
* Listener is {@link CandleListener}
702+
* @since 2.4.2
703+
*/
704+
public static final Flag CANDLES = new Flag.Builder("CANDLES", Material.CANDLE).mode(Flag.Mode.EXPERT)
705+
.listener(new CandleListener())
706+
.type(Type.PROTECTION).build();
707+
690708
/**
691709
* Provides a list of all the Flag instances contained in this class using reflection.
692710
* Deprecated Flags are ignored.

src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class IslandCache {
3838
* Map of all islands with island uniqueId as key
3939
*/
4040
@NonNull
41-
private final Map<@NonNull String, @NonNull Island> islandsById;
41+
private final Map<@NonNull String, Island> islandsById;
4242
/**
4343
* Every player who is associated with an island is in this map. Key is player
4444
* UUID, value is a set of islands

src/main/resources/locales/en-US.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ protection:
912912
description: Toggle interaction
913913
name: Beacons
914914
hint: Beacon use disabled
915+
BELL_RINGING:
916+
description: Toggle interaction
917+
name: Allow bell ringing
918+
hint: Bell ringing disabled
915919
BED:
916920
description: Toggle interaction
917921
name: Beds
@@ -960,6 +964,10 @@ protection:
960964
description: Toggle button use
961965
name: Buttons
962966
hint: Button use disabled
967+
CANDLES:
968+
description: Toggle candle interaction
969+
name: Candles
970+
hint: Candle interaction disabled
963971
CAKE:
964972
description: Toggle cake interaction
965973
name: Cakes

0 commit comments

Comments
 (0)