Skip to content

Commit

Permalink
Merge pull request #2449 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 2.4.2
  • Loading branch information
tastybento authored Jul 27, 2024
2 parents 950aff3 + 86945bd commit 037e66f
Show file tree
Hide file tree
Showing 25 changed files with 436 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- 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.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ private boolean clickHandler(User user, ClickType clickType, Player player, @Non
return true;
}
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()))) {
plugin.log("Invite sent to: " + player.getName() + " by " + user.getName() + " to join island in "
+ itc.getWorld().getName());
Expand All @@ -229,7 +230,8 @@ private boolean clickHandler(User user, ClickType clickType, Player player, @Non
+ itc.getWorld().getName());
}
} 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()))) {
plugin.log("Coop: " + player.getName() + " cooped " + user.getName() + " to island in "
+ itc.getWorld().getName());
Expand All @@ -240,15 +242,15 @@ private boolean clickHandler(User user, ClickType clickType, Player player, @Non
+ itc.getWorld().getName());
}
} 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()))) {
plugin.log("Trust: " + player.getName() + " trusted " + user.getName() + " to island in "
+ itc.getWorld().getName());
this.itc.getTrustCommand().execute(user, itic.getLabel(), List.of(player.getName()));
} else {
plugin.log("Trust failed: " + player.getName() + "'s trust failed for " + user.getName()
+ " for island in "
+ itc.getWorld().getName());
+ " for island in " + itc.getWorld().getName());
}
}
return true;
Expand All @@ -272,8 +274,8 @@ public String getPromptText(@NonNull ConversationContext context) {
public Prompt acceptInput(@NonNull ConversationContext context, String input) {
if (itic.canExecute(user, itic.getLabel(), List.of(input))
&& itic.execute(user, itic.getLabel(), List.of(input))) {
return Prompt.END_OF_CONVERSATION;
}
return Prompt.END_OF_CONVERSATION;
}
// Set the search item to what was entered
searchName = input;
// Return to the GUI but give a second for the error to show
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.bukkit.World;
import org.bukkit.block.Biome;
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.potion.PotionEffectType;
import org.bukkit.util.Vector;
Expand All @@ -29,7 +31,9 @@
import world.bentobox.bentobox.database.json.adapters.MaterialTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.PairTypeAdapter;
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.VillagerTypeAdapter;
import world.bentobox.bentobox.database.json.adapters.WorldTypeAdapter;
import world.bentobox.bentobox.util.Pair;

Expand Down Expand Up @@ -78,6 +82,10 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
return (TypeAdapter<T>) new WorldTypeAdapter();
} else if (Vector.class.isAssignableFrom(rawType)) {
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)) {
// Add Pair handling here with type safety
Type pairType = type.getType();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
}
Original file line number Diff line number Diff line change
@@ -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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public int getMinProtectedZ() {

/**
* 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
* @since 1.5.2
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,23 @@ public static String getTippedArrowName(PotionType potionType, User user) {
* @param user The user's language will be used for translation.
* @return Return the translation result.
*/
@SuppressWarnings("deprecation")
public static String getPotionBaseEffectName(PotionType potionType, User user) {
if (hooked) {
return LanguageHelper.getPotionBaseEffectName(potionType, getUserLocale(user));
}
List<PotionEffect> effects = potionType.getPotionEffects();
if (effects.isEmpty()) {
return "No Effects";
try {
List<PotionEffect> effects = potionType.getPotionEffects();

if (effects.isEmpty()) {
return "No Effects";
}
return effects.stream().map(effect -> Util.prettifyText(effect.getType().getKey().getKey()))
.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());
}
return effects.stream().map(effect -> Util.prettifyText(effect.getType().getKey().getKey()))
.collect(Collectors.joining(", "));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PanelListenerManager implements Listener {

private static final HashMap<UUID, Panel> openPanels = new HashMap<>();

@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent event) {
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
InventoryView view = event.getView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public void onBentoBoxReady(BentoBoxReadyEvent e) {

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent e) {
if (!ready || !e.getChunk().isGenerated()) {
if (!ready) {
return;
}
World world = e.getWorld();
plugin.getIWM().getAddon(world).filter(GameModeAddon::isUsesNewChunkGeneration).ifPresent(gma -> {
World seed = Bukkit.getWorld(world.getName() + "/bentobox");
int x = e.getChunk().getX();
int z = e.getChunk().getZ();
if (seed != null && !seed.getChunkAt(x, z, false).isGenerated()) {
if (seed != null) {
Util.getChunkAtAsync(seed, x, z, true);
}
});
Expand Down
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,23 @@
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.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 +63,47 @@ 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()));

}

return result;
}

if (Tag.PRESSURE_PLATES.isTagged(e.getBlock().getType()))
{
// 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);
}
}


}
Loading

0 comments on commit 037e66f

Please sign in to comment.