Merge pull request #2449 from BentoBoxWorld/develop

Release 2.4.2
This commit is contained in:
tastybento 2024-07-27 16:27:44 -07:00 committed by GitHub
commit 037e66f6f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 440 additions and 53 deletions

View File

@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. --> <!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number> <build.number>-LOCAL</build.number>
<!-- This allows to change between versions. --> <!-- This allows to change between versions. -->
<build.version>2.4.1</build.version> <build.version>2.4.2</build.version>
<sonar.organization>bentobox-world</sonar.organization> <sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url> <sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars> <server.jars>${project.basedir}/lib</server.jars>

View File

@ -219,7 +219,8 @@ public class IslandTeamInviteGUI {
return true; return true;
} }
if (clickType.equals(ClickType.LEFT)) { if (clickType.equals(ClickType.LEFT)) {
user.closeInventory(); // Close inventory after one tick to allow the no pickup click return to occur
Bukkit.getScheduler().runTask(plugin, () -> user.closeInventory());
if (itic.canExecute(user, itic.getLabel(), List.of(player.getName()))) { if (itic.canExecute(user, itic.getLabel(), List.of(player.getName()))) {
plugin.log("Invite sent to: " + player.getName() + " by " + user.getName() + " to join island in " plugin.log("Invite sent to: " + player.getName() + " by " + user.getName() + " to join island in "
+ itc.getWorld().getName()); + itc.getWorld().getName());
@ -229,7 +230,8 @@ public class IslandTeamInviteGUI {
+ itc.getWorld().getName()); + itc.getWorld().getName());
} }
} else if (clickType.equals(ClickType.RIGHT)) { } else if (clickType.equals(ClickType.RIGHT)) {
user.closeInventory(); // Close inventory after one tick to allow the no pickup click return to occur
Bukkit.getScheduler().runTask(plugin, () -> user.closeInventory());
if (this.itc.getCoopCommand().canExecute(user, itic.getLabel(), List.of(player.getName()))) { if (this.itc.getCoopCommand().canExecute(user, itic.getLabel(), List.of(player.getName()))) {
plugin.log("Coop: " + player.getName() + " cooped " + user.getName() + " to island in " plugin.log("Coop: " + player.getName() + " cooped " + user.getName() + " to island in "
+ itc.getWorld().getName()); + itc.getWorld().getName());
@ -240,15 +242,15 @@ public class IslandTeamInviteGUI {
+ itc.getWorld().getName()); + itc.getWorld().getName());
} }
} else if (clickType.equals(ClickType.SHIFT_LEFT)) { } else if (clickType.equals(ClickType.SHIFT_LEFT)) {
user.closeInventory(); // Close inventory after one tick to allow the no pickup click return to occur
Bukkit.getScheduler().runTask(plugin, () -> user.closeInventory());
if (this.itc.getTrustCommand().canExecute(user, itic.getLabel(), List.of(player.getName()))) { if (this.itc.getTrustCommand().canExecute(user, itic.getLabel(), List.of(player.getName()))) {
plugin.log("Trust: " + player.getName() + " trusted " + user.getName() + " to island in " plugin.log("Trust: " + player.getName() + " trusted " + user.getName() + " to island in "
+ itc.getWorld().getName()); + itc.getWorld().getName());
this.itc.getTrustCommand().execute(user, itic.getLabel(), List.of(player.getName())); this.itc.getTrustCommand().execute(user, itic.getLabel(), List.of(player.getName()));
} else { } else {
plugin.log("Trust failed: " + player.getName() + "'s trust failed for " + user.getName() plugin.log("Trust failed: " + player.getName() + "'s trust failed for " + user.getName()
+ " for island in " + " for island in " + itc.getWorld().getName());
+ itc.getWorld().getName());
} }
} }
return true; return true;

View File

@ -9,6 +9,8 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -29,7 +31,9 @@ import world.bentobox.bentobox.database.json.adapters.LocationTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.MaterialTypeAdapter; import world.bentobox.bentobox.database.json.adapters.MaterialTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.PairTypeAdapter; import world.bentobox.bentobox.database.json.adapters.PairTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.PotionEffectTypeAdapter; import world.bentobox.bentobox.database.json.adapters.PotionEffectTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.ProfessionTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.VectorTypeAdapter; import world.bentobox.bentobox.database.json.adapters.VectorTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.VillagerTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.WorldTypeAdapter; import world.bentobox.bentobox.database.json.adapters.WorldTypeAdapter;
import world.bentobox.bentobox.util.Pair; import world.bentobox.bentobox.util.Pair;
@ -78,6 +82,10 @@ public class BentoboxTypeAdapterFactory implements TypeAdapterFactory {
return (TypeAdapter<T>) new WorldTypeAdapter(); return (TypeAdapter<T>) new WorldTypeAdapter();
} else if (Vector.class.isAssignableFrom(rawType)) { } else if (Vector.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new VectorTypeAdapter(); return (TypeAdapter<T>) new VectorTypeAdapter();
} else if (Profession.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new ProfessionTypeAdapter();
} else if (Villager.Type.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new VillagerTypeAdapter();
} else if (Pair.class.isAssignableFrom(rawType)) { } else if (Pair.class.isAssignableFrom(rawType)) {
// Add Pair handling here with type safety // Add Pair handling here with type safety
Type pairType = type.getType(); Type pairType = type.getType();

View File

@ -0,0 +1,34 @@
package world.bentobox.bentobox.database.json.adapters;
import java.io.IOException;
import org.bukkit.entity.Villager.Profession;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
public class ProfessionTypeAdapter extends TypeAdapter<Profession> {
@Override
public void write(JsonWriter out, Profession profession) throws IOException {
out.value(profession.name());
}
@Override
public Profession read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
String id = reader.nextString();
try {
return Profession.valueOf(id);
} catch (Exception e) {
// Do nothing
}
return Profession.NONE;
}
}

View File

@ -0,0 +1,34 @@
package world.bentobox.bentobox.database.json.adapters;
import java.io.IOException;
import org.bukkit.entity.Villager;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
public class VillagerTypeAdapter extends TypeAdapter<Villager.Type> {
@Override
public void write(JsonWriter out, Villager.Type type) throws IOException {
out.value(type.name());
}
@Override
public Villager.Type read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
String id = reader.nextString();
try {
return Villager.Type.valueOf(id);
} catch (Exception e) {
// Do nothing
}
return Villager.Type.PLAINS;
}
}

View File

@ -501,7 +501,7 @@ public class Island implements DataObject, MetaDataAble {
/** /**
* Get the maximum protected Z block coordinate based on the island location. It * Get the maximum protected Z block coordinate based on the island location. It
* will never be more than {@link #getMinZ()} * will never be more than {@link #getMaxZ()}
* *
* @return the maxProtectedZ * @return the maxProtectedZ
* @since 1.5.2 * @since 1.5.2

View File

@ -363,16 +363,23 @@ public class LangUtilsHook extends Hook {
* @param user The user's language will be used for translation. * @param user The user's language will be used for translation.
* @return Return the translation result. * @return Return the translation result.
*/ */
@SuppressWarnings("deprecation")
public static String getPotionBaseEffectName(PotionType potionType, User user) { public static String getPotionBaseEffectName(PotionType potionType, User user) {
if (hooked) { if (hooked) {
return LanguageHelper.getPotionBaseEffectName(potionType, getUserLocale(user)); return LanguageHelper.getPotionBaseEffectName(potionType, getUserLocale(user));
} }
try {
List<PotionEffect> effects = potionType.getPotionEffects(); List<PotionEffect> effects = potionType.getPotionEffects();
if (effects.isEmpty()) { if (effects.isEmpty()) {
return "No Effects"; return "No Effects";
} }
return effects.stream().map(effect -> Util.prettifyText(effect.getType().getKey().getKey())) return effects.stream().map(effect -> Util.prettifyText(effect.getType().getKey().getKey()))
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));
} catch (Exception e) {
// Older versions of Spigot pre-1.20.4 don't have getPotionEffects()
return Util.prettifyText(potionType.getEffectType().getKey().getKey());
}
} }
/** /**

View File

@ -26,7 +26,7 @@ public class PanelListenerManager implements Listener {
private static final HashMap<UUID, Panel> openPanels = new HashMap<>(); private static final HashMap<UUID, Panel> openPanels = new HashMap<>();
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
InventoryView view = event.getView(); InventoryView view = event.getView();

View File

@ -39,7 +39,7 @@ public class SeedWorldMakerListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent e) { public void onChunkLoad(ChunkLoadEvent e) {
if (!ready || !e.getChunk().isGenerated()) { if (!ready) {
return; return;
} }
World world = e.getWorld(); World world = e.getWorld();
@ -47,7 +47,7 @@ public class SeedWorldMakerListener implements Listener {
World seed = Bukkit.getWorld(world.getName() + "/bentobox"); World seed = Bukkit.getWorld(world.getName() + "/bentobox");
int x = e.getChunk().getX(); int x = e.getChunk().getX();
int z = e.getChunk().getZ(); int z = e.getChunk().getZ();
if (seed != null && !seed.getChunkAt(x, z, false).isGenerated()) { if (seed != null) {
Util.getChunkAtAsync(seed, x, z, true); Util.getChunkAtAsync(seed, x, z, true);
} }
}); });

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

@ -21,6 +21,8 @@ import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent; import org.bukkit.event.vehicle.VehicleDamageEvent;
import com.google.common.base.Enums;
import world.bentobox.bentobox.api.flags.FlagListener; import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
@ -101,6 +103,10 @@ public class BreakBlocksListener extends FlagListener {
{ {
return; 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) switch (m)
{ {
case CAKE -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS); case CAKE -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS);
@ -182,7 +188,7 @@ public class BreakBlocksListener extends FlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onProjectileHitBreakBlock(ProjectileHitEvent e) { public void onProjectileHitBreakBlock(ProjectileHitEvent e) {
// We want to make sure this is an actual projectile (arrow or trident) // We want to make sure this is an actual projectile (arrow or trident)
if (!(e.getEntity() instanceof AbstractArrow)) { if (!(e.getEntity() instanceof Projectile)) {
return; return;
} }

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) {
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

@ -27,7 +27,7 @@ import world.bentobox.bentobox.lists.Flags;
* Protects islands from visitors blowing things up * Protects islands from visitors blowing things up
* @author tastybento * @author tastybento
*/ */
public class TNTListener extends FlagListener { public class ExplosionListener extends FlagListener {
/** /**
* Contains {@link EntityType}s that generates an explosion. * Contains {@link EntityType}s that generates an explosion.
* @since 1.5.0 * @since 1.5.0

View File

@ -1,15 +1,23 @@
package world.bentobox.bentobox.listeners.flags.protection; package world.bentobox.bentobox.listeners.flags.protection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.FlagListener; import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
@ -55,24 +63,47 @@ public class PhysicalInteractionListener extends FlagListener
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(EntityInteractEvent e) 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) 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,
if (Tag.WOODEN_BUTTONS.isTagged(e.getBlock().getType())) Flags.PRESSURE_PLATE, Tag.FENCE_GATES, Flags.GATE, Tag.DOORS, Flags.DOOR, Tag.CANDLE_CAKES,
{ Flags.CANDLES, Tag.CANDLES, Flags.CANDLES);
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.BUTTON); Map<Material, Flag> MAT_TO_FLAG = Map.of(Material.LEVER, Flags.LEVER, Material.TRIPWIRE, Flags.REDSTONE,
return; 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())) return result;
{ }
// Pressure plates
this.checkIsland(e, player, e.getBlock().getLocation(), Flags.PRESSURE_PLATE); /**
* 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) {
List<Block> blocksToRemove = new ArrayList<>();
for (Block b : e.blockList()) {
if (!this.checkBlocks(e, player, b)) {
blocksToRemove.add(b);
} }
} }
e.blockList().removeAll(blocksToRemove);
} }
}
} }

View File

@ -1,6 +1,5 @@
package world.bentobox.bentobox.listeners.flags.worldsettings; package world.bentobox.bentobox.listeners.flags.worldsettings;
import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -21,8 +20,8 @@ public class SpawnerSpawnEggsListener extends FlagListener {
public void onSpawnerChange(final PlayerInteractEvent e) { public void onSpawnerChange(final PlayerInteractEvent e) {
User user = User.getInstance(e.getPlayer()); User user = User.getInstance(e.getPlayer());
// Checking if the clicked block is a spawner and the item in hand is a mob egg // 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) if (e.getClickedBlock() != null && e.getClickedBlock().getType().name().endsWith("_SPAWNER")
&& e.getItem() != null && e.getItem().getType().toString().endsWith("_SPAWN_EGG") && e.getItem() != null && e.getItem().getType().name().endsWith("_SPAWN_EGG")
&& getIWM().inWorld(e.getClickedBlock().getWorld()) && 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.bypass." + Flags.SPAWNER_SPAWN_EGGS.getID() + ".everywhere")
|| user.hasPermission(getIWM().getPermissionPrefix(e.getClickedBlock().getWorld()) + "mod.bypassprotect")) || user.hasPermission(getIWM().getPermissionPrefix(e.getClickedBlock().getWorld()) + "mod.bypassprotect"))

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;
@ -38,7 +39,7 @@ import world.bentobox.bentobox.listeners.flags.protection.PortalListener;
import world.bentobox.bentobox.listeners.flags.protection.SculkSensorListener; import world.bentobox.bentobox.listeners.flags.protection.SculkSensorListener;
import world.bentobox.bentobox.listeners.flags.protection.SculkShriekerListener; import world.bentobox.bentobox.listeners.flags.protection.SculkShriekerListener;
import world.bentobox.bentobox.listeners.flags.protection.ShearingListener; 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.TeleportationListener;
import world.bentobox.bentobox.listeners.flags.protection.ThrowingListener; import world.bentobox.bentobox.listeners.flags.protection.ThrowingListener;
import world.bentobox.bentobox.listeners.flags.settings.DecayListener; import world.bentobox.bentobox.listeners.flags.settings.DecayListener;
@ -266,9 +267,9 @@ public final class Flags {
* Prevents players from priming TNT. * Prevents players from priming TNT.
* @since 1.5.0 * @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. * Prevents players from extinguishing fires.
@ -461,7 +462,7 @@ public final class Flags {
/** /**
* If {@code false}, prevents TNT from breaking blocks and damaging nearby entities. * If {@code false}, prevents TNT from breaking blocks and damaging nearby entities.
* @since 1.5.0 * @since 1.5.0
* @see TNTListener * @see ExplosionListener
*/ */
public static final Flag TNT_DAMAGE = new Flag.Builder("TNT_DAMAGE", Material.TNT).type(Type.SETTING) public static final Flag TNT_DAMAGE = new Flag.Builder("TNT_DAMAGE", Material.TNT).type(Type.SETTING)
.mode(Flag.Mode.ADVANCED).build(); .mode(Flag.Mode.ADVANCED).build();
@ -469,7 +470,7 @@ public final class Flags {
/** /**
* If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities. * If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities.
* @since 1.19.1 * @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) public static final Flag BLOCK_EXPLODE_DAMAGE = new Flag.Builder("BLOCK_EXPLODE_DAMAGE", Material.TNT_MINECART).type(Type.SETTING)
.mode(Flag.Mode.ADVANCED).build(); .mode(Flag.Mode.ADVANCED).build();
@ -477,7 +478,7 @@ public final class Flags {
/** /**
* If {@code false}, prevents TNT from breaking blocks and damaging nearby entities outside of island boundaries. * If {@code false}, prevents TNT from breaking blocks and damaging nearby entities outside of island boundaries.
* @since 1.15.3 * @since 1.15.3
* @see TNTListener * @see ExplosionListener
*/ */
public static final Flag WORLD_TNT_DAMAGE = new Flag.Builder("WORLD_TNT_DAMAGE", Material.TNT) public static final Flag WORLD_TNT_DAMAGE = new Flag.Builder("WORLD_TNT_DAMAGE", Material.TNT)
.type(Type.WORLD_SETTING) .type(Type.WORLD_SETTING)
@ -486,7 +487,7 @@ public final class Flags {
/** /**
* If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities outside of island boundaries. * If {@code false}, prevents Block Explode from breaking blocks and damaging nearby entities outside of island boundaries.
* @since 1.19.1 * @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) public static final Flag WORLD_BLOCK_EXPLODE_DAMAGE = new Flag.Builder("WORLD_BLOCK_EXPLODE_DAMAGE", Material.TNT_MINECART)
.type(Type.WORLD_SETTING) .type(Type.WORLD_SETTING)
@ -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

@ -125,6 +125,22 @@ public enum GameModePlaceholder {
*/ */
ISLAND_MEMBERS_LIST("island_members_list", (addon, user, island) -> island == null ? "" : island.getMemberSet(RanksManager.MEMBER_RANK).stream() ISLAND_MEMBERS_LIST("island_members_list", (addon, user, island) -> island == null ? "" : island.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(addon.getPlayers()::getName).collect(Collectors.joining(","))), .map(addon.getPlayers()::getName).collect(Collectors.joining(","))),
/**
* Returns a comma separated list of player names that are at least TRUSTED on this island.
* @since 2.4.2
*/
ISLAND_TRUSTED_LIST("island_trusted_list",
(addon, user, island) -> island == null ? ""
: island.getMemberSet(RanksManager.TRUSTED_RANK, false).stream().map(addon.getPlayers()::getName)
.collect(Collectors.joining(","))),
/**
* Returns a comma separated list of player names that are at least COOP on this island.
* @since 2.4.2
*/
ISLAND_COOP_LIST("island_coop_list",
(addon, user, island) -> island == null ? ""
: island.getMemberSet(RanksManager.COOP_RANK, false).stream().map(addon.getPlayers()::getName)
.collect(Collectors.joining(","))),
/** /**
* Returns the amount of players that are TRUSTED on this island. * Returns the amount of players that are TRUSTED on this island.
* @since 1.5.0 * @since 1.5.0
@ -244,6 +260,20 @@ public enum GameModePlaceholder {
VISITED_ISLAND_MEMBERS_LIST("visited_island_members_list", (addon, user, island) -> VISITED_ISLAND_MEMBERS_LIST("visited_island_members_list", (addon, user, island) ->
getVisitedIsland(addon, user).map(value -> value.getMemberSet(RanksManager.MEMBER_RANK).stream() getVisitedIsland(addon, user).map(value -> value.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(addon.getPlayers()::getName).collect(Collectors.joining(","))).orElse("")), .map(addon.getPlayers()::getName).collect(Collectors.joining(","))).orElse("")),
/**
* Returns a comma separated list of player names that are at TRUSTED on the island the player is standing on.
* @since 2.4.2
*/
VISITED_ISLAND_TRUSTED_LIST("visited_island_trusted_list", (addon, user,
island) -> getVisitedIsland(addon, user).map(value -> value.getMemberSet(RanksManager.TRUSTED_RANK, false)
.stream().map(addon.getPlayers()::getName).collect(Collectors.joining(","))).orElse("")),
/**
* Returns a comma separated list of player names that are COOP on the island the player is standing on.
* @since 2.4.2
*/
VISITED_ISLAND_COOP_LIST("visited_island_coop_list", (addon, user,
island) -> getVisitedIsland(addon, user).map(value -> value.getMemberSet(RanksManager.COOP_RANK, false)
.stream().map(addon.getPlayers()::getName).collect(Collectors.joining(","))).orElse("")),
/** /**
* Returns the amount of players that are at least MEMBER on the island the player is standing on. * Returns the amount of players that are at least MEMBER on the island the player is standing on.
* @since 1.5.2 * @since 1.5.2

View File

@ -108,7 +108,9 @@ public class BlueprintClipboardManager {
bp = gson.fromJson(fr, Blueprint.class); bp = gson.fromJson(fr, Blueprint.class);
} catch (Exception e) { } catch (Exception e) {
plugin.logError("Blueprint has JSON error: " + zipFile.getName()); plugin.logError("Blueprint has JSON error: " + zipFile.getName());
plugin.logStacktrace(e);
throw new IOException("Blueprint has JSON error: " + zipFile.getName()); throw new IOException("Blueprint has JSON error: " + zipFile.getName());
} }
Files.delete(file.toPath()); Files.delete(file.toPath());
// Bedrock check and set // Bedrock check and set

View File

@ -84,9 +84,11 @@ public class PlayersManager {
Objects.requireNonNull(playerUUID, "Player UUID must not be null"); Objects.requireNonNull(playerUUID, "Player UUID must not be null");
// If the player exists in the database, load it; otherwise, create and save a new player // If the player exists in the database, load it; otherwise, create and save a new player
Players player = loadPlayer(playerUUID); if (handler.objectExists(playerUUID.toString())) {
if (player != null) { Players p = loadPlayer(playerUUID);
return player; if (p != null) {
return p;
}
} }
Players newPlayer = new Players(plugin, playerUUID); Players newPlayer = new Players(plugin, playerUUID);
handler.saveObjectAsync(newPlayer); handler.saveObjectAsync(newPlayer);

View File

@ -38,7 +38,7 @@ public class IslandCache {
* Map of all islands with island uniqueId as key * Map of all islands with island uniqueId as key
*/ */
@NonNull @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 * Every player who is associated with an island is in this map. Key is player
* UUID, value is a set of islands * UUID, value is a set of islands

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

View File

@ -0,0 +1,110 @@
package world.bentobox.bentobox.listeners.flags.protection;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, Flags.class, Util.class, Bukkit.class })
public class CandleListenerTest extends AbstractCommonSetup {
private CandleListener l;
@Mock
private Block block;
/**
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Island manager
// Default is that everything is allowed
when(island.isAllowed(any(), any())).thenReturn(true);
when(block.getLocation()).thenReturn(location);
// Tags
when(Tag.CANDLES.isTagged(any(Material.class))).thenReturn(true);
when(Tag.CANDLE_CAKES.isTagged(any(Material.class))).thenReturn(true);
// Listener
l = new CandleListener();
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.CandleListener#onCandleInteract(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnCandleInteract() {
// Block
when(block.getType()).thenReturn(Material.CANDLE);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, null, block, BlockFace.UP);
l.onCandleInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.CandleListener#onCandleInteract(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnCandleCakeInteract() {
// Block
when(block.getType()).thenReturn(Material.CANDLE_CAKE);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, null, block, BlockFace.UP);
l.onCandleInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.CandleListener#onCandleInteract(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnCandleInteractFail() {
when(island.isAllowed(any(), any())).thenReturn(false);
// Block
when(block.getType()).thenReturn(Material.CANDLE);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, null, block, BlockFace.UP);
l.onCandleInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(), eq("protection.protected"));
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.CandleListener#onCandleInteract(org.bukkit.event.player.PlayerInteractEvent)}.
*/
@Test
public void testOnCandleCakeInteractFail() {
when(island.isAllowed(any(), any())).thenReturn(false);
// Block
when(block.getType()).thenReturn(Material.CANDLE_CAKE);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, null, block, BlockFace.UP);
l.onCandleInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(), eq("protection.protected"));
}
}

View File

@ -7,10 +7,13 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -25,6 +28,7 @@ import org.bukkit.entity.Slime;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
import org.bukkit.event.Event.Result; import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -228,4 +232,61 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
assertTrue(p.name() +" failed", e.isCancelled()); assertTrue(p.name() +" failed", e.isCancelled());
}); });
} }
/**
* Test method for {@link PhysicalInteractionListener#onProjectileExplode(org.bukkit.event.entity.EntityExplodeEvent)}.
*/
@Test
public void testOnProjectileExplodeNotProjectile() {
Entity entity = mock(Entity.class);
List<Block> blocks = new ArrayList<>();
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onProjectileExplode(e);
assertFalse(e.isCancelled());
}
/**
* Test method for {@link PhysicalInteractionListener#onProjectileExplode(org.bukkit.event.entity.EntityExplodeEvent)}.
*/
@Test
public void testOnProjectileExplodeProjectileNoPlayer() {
Projectile entity = mock(Projectile.class);
ProjectileSource source = mock(Creeper.class);
when(entity.getShooter()).thenReturn(source);
List<Block> blocks = new ArrayList<>();
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onProjectileExplode(e);
assertFalse(e.isCancelled());
}
/**
* Test method for {@link PhysicalInteractionListener#onProjectileExplode(org.bukkit.event.entity.EntityExplodeEvent)}.
*/
@Test
public void testOnProjectileExplodeProjectilePlayer() {
Projectile entity = mock(Projectile.class);
when(entity.getShooter()).thenReturn(mockPlayer);
List<Block> blocks = new ArrayList<>();
Block block1 = mock(Block.class);
Block block2 = mock(Block.class);
when(block1.getLocation()).thenReturn(location);
when(block2.getLocation()).thenReturn(location);
blocks.add(block1);
blocks.add(block2);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
PhysicalInteractionListener i = new PhysicalInteractionListener();
// Test with wooden button
when(block1.getType()).thenReturn(Material.OAK_BUTTON);
when(Tag.WOODEN_BUTTONS.isTagged(Material.OAK_BUTTON)).thenReturn(true);
// Test with pressure plate
when(block2.getType()).thenReturn(Material.STONE_PRESSURE_PLATE);
when(Tag.PRESSURE_PLATES.isTagged(Material.STONE_PRESSURE_PLATE)).thenReturn(true);
i.onProjectileExplode(e);
verify(notifier, times(2)).notify(any(), eq("protection.protected"));
}
} }

View File

@ -58,7 +58,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
private Entity entity; private Entity entity;
// Class under test // Class under test
private TNTListener listener; private ExplosionListener listener;
@Override @Override
@Before @Before
@ -85,7 +85,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Util // Util
when(Util.findFirstMatchingEnum(any(), anyString())).thenCallRealMethod(); when(Util.findFirstMatchingEnum(any(), anyString())).thenCallRealMethod();
listener = new TNTListener(); listener = new ExplosionListener();
listener.setPlugin(plugin); listener.setPlugin(plugin);
} }

View File

@ -46,7 +46,7 @@ public class FlagsManagerTest {
/** /**
* Update this value if the number of registered listeners changes * Update this value if the number of registered listeners changes
*/ */
private static final int NUMBER_OF_LISTENERS = 54; private static final int NUMBER_OF_LISTENERS = 55;
@Mock @Mock
private BentoBox plugin; private BentoBox plugin;
@Mock @Mock