Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2422 flags for 1.21 #2432

Merged
merged 9 commits into from
Jul 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ private void checkClickedBlock(Event e, Player player, Block block)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;

import com.google.common.base.Enums;

import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

Expand Down Expand Up @@ -101,6 +103,10 @@ public void onPlayerInteract(final PlayerInteractEvent e)
{
return;
}
if (Enums.getIfPresent(Material.class, "TRIAL_SPAWNER").isPresent() && m.equals(Material.TRIAL_SPAWNER)) {
this.checkIsland(e, p, l, Flags.BREAK_SPAWNERS);
return;
}
switch (m)
{
case CAKE -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS);
Expand Down Expand Up @@ -182,7 +188,7 @@ private boolean notAllowed(EntityDamageByEntityEvent e, Player player, Location
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onProjectileHitBreakBlock(ProjectileHitEvent e) {
// We want to make sure this is an actual projectile (arrow or trident)
if (!(e.getEntity() instanceof AbstractArrow)) {
if (!(e.getEntity() instanceof Projectile)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Protects islands from visitors blowing things up
* @author tastybento
*/
public class TNTListener extends FlagListener {
public class ExplosionListener extends FlagListener {
/**
* Contains {@link EntityType}s that generates an explosion.
* @since 1.5.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package world.bentobox.bentobox.listeners.flags.protection;

import java.util.Map;

import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;

Expand Down Expand Up @@ -55,24 +61,43 @@ public void onPlayerInteract(PlayerInteractEvent e)
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(EntityInteractEvent e)
{
if (!(e.getEntity() instanceof Projectile p))
if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player)
{
return;
checkBlocks(e, player, e.getBlock());
}
}

if (p.getShooter() instanceof Player player)
{
if (Tag.WOODEN_BUTTONS.isTagged(e.getBlock().getType()))
{
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.BUTTON);
return;
}
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, Material.DECORATED_POT, Flags.BREAK_BLOCKS);
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);
if (result && MAT_TO_FLAG.containsKey(block.getType())) {
result = this.checkIsland(e, player, block.getLocation(), MAT_TO_FLAG.get(block.getType()));

}

if (Tag.PRESSURE_PLATES.isTagged(e.getBlock().getType()))
{
// Pressure plates
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.PRESSURE_PLATE);
return result;
}

/**
* Protects buttons and plates, etc. from being activated by projectiles that explode
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileExplode(EntityExplodeEvent e) {
if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player) {
for (Block b : e.blockList()) {
if (!this.checkBlocks(e, player, b)) {
e.blockList().clear();
}
}
}
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package world.bentobox.bentobox.listeners.flags.worldsettings;

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
Expand All @@ -21,8 +20,8 @@ public class SpawnerSpawnEggsListener extends FlagListener {
public void onSpawnerChange(final PlayerInteractEvent e) {
User user = User.getInstance(e.getPlayer());
// Checking if the clicked block is a spawner and the item in hand is a mob egg
if (e.getClickedBlock() != null && e.getClickedBlock().getType().equals(Material.SPAWNER)
&& e.getItem() != null && e.getItem().getType().toString().endsWith("_SPAWN_EGG")
if (e.getClickedBlock() != null && e.getClickedBlock().getType().name().endsWith("_SPAWNER")
&& e.getItem() != null && e.getItem().getType().name().endsWith("_SPAWN_EGG")
&& getIWM().inWorld(e.getClickedBlock().getWorld())
&& !(user.hasPermission(getIWM().getPermissionPrefix(e.getClickedBlock().getWorld()) + "mod.bypass." + Flags.SPAWNER_SPAWN_EGGS.getID() + ".everywhere")
|| user.hasPermission(getIWM().getPermissionPrefix(e.getClickedBlock().getWorld()) + "mod.bypassprotect"))
Expand Down
32 changes: 25 additions & 7 deletions src/main/java/world/bentobox/bentobox/lists/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand All @@ -38,7 +39,7 @@
import world.bentobox.bentobox.listeners.flags.protection.SculkSensorListener;
import world.bentobox.bentobox.listeners.flags.protection.SculkShriekerListener;
import world.bentobox.bentobox.listeners.flags.protection.ShearingListener;
import world.bentobox.bentobox.listeners.flags.protection.TNTListener;
import world.bentobox.bentobox.listeners.flags.protection.ExplosionListener;
import world.bentobox.bentobox.listeners.flags.protection.TeleportationListener;
import world.bentobox.bentobox.listeners.flags.protection.ThrowingListener;
import world.bentobox.bentobox.listeners.flags.settings.DecayListener;
Expand Down Expand Up @@ -266,9 +267,9 @@ private Flags() {}
* Prevents players from priming TNT.
* @since 1.5.0
*
* @see TNTListener
* @see ExplosionListener
*/
public static final Flag TNT_PRIMING = new Flag.Builder("TNT_PRIMING", Material.TNT).listener(new TNTListener()).build();
public static final Flag TNT_PRIMING = new Flag.Builder("TNT_PRIMING", Material.TNT).listener(new ExplosionListener()).build();

/**
* Prevents players from extinguishing fires.
Expand Down Expand Up @@ -461,23 +462,23 @@ private Flags() {}
/**
* If {@code false}, prevents TNT from breaking blocks and damaging nearby entities.
* @since 1.5.0
* @see TNTListener
* @see ExplosionListener
*/
public static final Flag TNT_DAMAGE = new Flag.Builder("TNT_DAMAGE", Material.TNT).type(Type.SETTING)
.mode(Flag.Mode.ADVANCED).build();

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

/**
* If {@code false}, prevents TNT from breaking blocks and damaging nearby entities outside of island boundaries.
* @since 1.15.3
* @see TNTListener
* @see ExplosionListener
*/
public static final Flag WORLD_TNT_DAMAGE = new Flag.Builder("WORLD_TNT_DAMAGE", Material.TNT)
.type(Type.WORLD_SETTING)
Expand All @@ -486,7 +487,7 @@ private Flags() {}
/**
* If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities outside of island boundaries.
* @since 1.19.1
* @see TNTListener
* @see ExplosionListener
*/
public static final Flag WORLD_BLOCK_EXPLODE_DAMAGE = new Flag.Builder("WORLD_BLOCK_EXPLODE_DAMAGE", Material.TNT_MINECART)
.type(Type.WORLD_SETTING)
Expand Down Expand Up @@ -687,6 +688,23 @@ private 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class IslandCache {
* Map of all islands with island uniqueId as key
*/
@NonNull
private final Map<@NonNull String, @NonNull Island> islandsById;
private final Map<@NonNull String, Island> islandsById;
/**
* Every player who is associated with an island is in this map. Key is player
* UUID, value is a set of islands
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading