This commit is contained in:
tastybento 2024-05-01 18:01:54 -07:00 committed by GitHub
commit 3811d4fa96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
40 changed files with 329 additions and 194 deletions

10
pom.xml
View File

@ -73,7 +73,7 @@
<postgresql.version>42.2.18</postgresql.version>
<hikaricp.version>5.0.1</hikaricp.version>
<!-- More visible way to change dependency versions -->
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.5-R0.1-SNAPSHOT</spigot.version>
<!-- Might differ from the last Spigot release for short periods
of time -->
<paper.version>1.20.4-R0.1-SNAPSHOT</paper.version>
@ -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.3.0</build.version>
<build.version>2.4.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
@ -230,6 +230,12 @@
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc....</groupId>
<artifactId>spigot</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc.</groupId>
<artifactId>spigot</artifactId>

View File

@ -12,7 +12,6 @@ import world.bentobox.bentobox.api.commands.admin.resets.AdminResetsCommand;
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamAddCommand;
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamCommand;
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamDisbandCommand;
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamFixCommand;
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamKickCommand;
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamSetownerCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
@ -63,7 +62,6 @@ public abstract class DefaultAdminCommand extends CompositeCommand {
new AdminTeamKickCommand(this);
new AdminTeamDisbandCommand(this);
new AdminTeamSetownerCommand(this);
new AdminTeamFixCommand(this);
// Blueprints
new AdminBlueprintCommand(this);
// Register/unregister islands

View File

@ -12,6 +12,7 @@ import org.bukkit.Particle;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.commands.admin.range.AdminRangeDisplayCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.BlueprintClipboard;
import world.bentobox.bentobox.managers.BlueprintsManager;
@ -23,7 +24,6 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
// Map containing selection cuboid display tasks
private Map<User, Integer> displayClipboards;
private static final Particle PARTICLE = Particle.REDSTONE;
private static final Particle.DustOptions PARTICLE_DUST_OPTIONS = new Particle.DustOptions(Color.RED, 1.0F);
public AdminBlueprintCommand(CompositeCommand parent) {
@ -99,26 +99,38 @@ public class AdminBlueprintCommand extends ConfirmableCommand {
// Drawing x-axes
for (int x = minX; x <= maxX; x++) {
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, minY + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, maxY + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, minY + 0.5, maxZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, maxY + 0.5, maxZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, minY + 0.5,
minZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, maxY + 0.5,
minZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, minY + 0.5,
maxZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, x + 0.5, maxY + 0.5,
maxZ + 0.5);
}
// Drawing y-axes
for (int y = minY; y <= maxY; y++) {
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, y + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, y + 0.5, minZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, y + 0.5, maxZ + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, y + 0.5, maxZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, y + 0.5,
minZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, y + 0.5,
minZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, y + 0.5,
maxZ + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, y + 0.5,
maxZ + 0.5);
}
// Drawing z-axes
for (int z = minZ; z <= maxZ; z++) {
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, minY + 0.5, z + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, minY + 0.5, z + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, maxY + 0.5, z + 0.5);
user.spawnParticle(PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, maxY + 0.5, z + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, minY + 0.5,
z + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, minY + 0.5,
z + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, minX + 0.5, maxY + 0.5,
z + 0.5);
user.spawnParticle(AdminRangeDisplayCommand.PARTICLE, PARTICLE_DUST_OPTIONS, maxX + 0.5, maxY + 0.5,
z + 0.5);
}
}

View File

@ -13,6 +13,7 @@ import org.bukkit.Particle;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
/**
* @author Poslovitch
@ -23,6 +24,9 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
private static final String DISPLAY = "display";
private static final String SHOW = "show";
private static final String HIDE = "hide";
public static final Particle PARTICLE = Util.findFirstMatchingEnum(Particle.class, "REDSTONE", "DUST");
private static final Particle PARTICLE2 = Util.findFirstMatchingEnum(Particle.class, "VILLAGER_HAPPY",
"HAPPY_VILLAGER");
// Map of users to which ranges must be displayed
private final Map<User, Integer> displayRanges = new HashMap<>();
@ -76,11 +80,11 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
// Draw the default protected area if island protected zone is different
if (island.getProtectionRange() != getPlugin().getIWM().getIslandProtectionRange(getWorld())) {
drawZone(user, Particle.VILLAGER_HAPPY, null, island, getPlugin().getIWM().getIslandProtectionRange(getWorld()));
drawZone(user, PARTICLE2, null, island, getPlugin().getIWM().getIslandProtectionRange(getWorld()));
}
// Draw the island area
drawZone(user, Particle.REDSTONE, new Particle.DustOptions(Color.GRAY, 1.0F), island, island.getRange());
drawZone(user, PARTICLE, new Particle.DustOptions(Color.GRAY, 1.0F), island, island.getRange());
});
}, 20, 30));
}

View File

@ -1,35 +0,0 @@
package world.bentobox.bentobox.api.commands.admin.team;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
public class AdminTeamFixCommand extends CompositeCommand {
public AdminTeamFixCommand(CompositeCommand parent) {
super(parent, "fix");
}
@Override
public void setup() {
setPermission("mod.team.fix");
setDescription("commands.admin.team.fix.description");
}
@Override
public boolean canExecute(User user, String label, List<String> args) {
// If args are not right, show help
if (!args.isEmpty()) {
showHelp(this, user);
return false;
}
return true;
}
@Override
public boolean execute(User user, String label, List<String> args) {
getIslands().checkTeams(user, getWorld());
return true;
}
}

View File

@ -48,7 +48,6 @@ public class PanelItem {
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
icon.setItemMeta(meta);
}
@ -89,7 +88,6 @@ public class PanelItem {
this.name = name;
if (meta != null) {
meta.setDisplayName(name);
meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils
icon.setItemMeta(meta);
}
}
@ -135,9 +133,9 @@ public class PanelItem {
}
if (meta != null) {
if (glow) {
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow);
meta.addEnchant(Enchantment.POWER, 0, glow);
} else {
meta.removeEnchant(Enchantment.ARROW_DAMAGE);
meta.removeEnchant(Enchantment.POWER);
}
icon.setItemMeta(meta);

View File

@ -14,6 +14,7 @@ import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@ -33,6 +34,8 @@ import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import com.google.common.base.Enums;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.events.OfflineMessageEvent;
@ -62,19 +65,18 @@ public class User implements MetaDataAble {
private static final Map<Particle, Class<?>> VALIDATION_CHECK;
static {
Map<Particle, Class<?>> v = new EnumMap<>(Particle.class);
v.put(Particle.REDSTONE, Particle.DustOptions.class);
v.put(Particle.ITEM_CRACK, ItemStack.class);
v.put(Particle.BLOCK_CRACK, BlockData.class);
v.put(Particle.BLOCK_DUST, BlockData.class);
v.put(Particle.DUST, Particle.DustOptions.class);
v.put(Particle.ITEM, ItemStack.class);
v.put(Particle.ITEM_COBWEB, ItemStack.class);
v.put(Particle.FALLING_DUST, BlockData.class);
v.put(Particle.BLOCK, BlockData.class);
v.put(Particle.BLOCK_MARKER, BlockData.class);
v.put(Particle.DUST_COLOR_TRANSITION, DustTransition.class);
v.put(Particle.DUST_PILLAR, BlockData.class);
v.put(Particle.VIBRATION, Vibration.class);
v.put(Particle.SCULK_CHARGE, Float.class);
v.put(Particle.SHRIEK, Integer.class);
v.put(Particle.LEGACY_BLOCK_CRACK, BlockData.class);
v.put(Particle.LEGACY_BLOCK_DUST, BlockData.class);
v.put(Particle.LEGACY_FALLING_DUST, BlockData.class);
v.put(Particle.ENTITY_EFFECT, Color.class);
VALIDATION_CHECK = Collections.unmodifiableMap(v);
}
@ -730,7 +732,7 @@ public class User implements MetaDataAble {
// Check if this particle is beyond the viewing distance of the server
if (this.player != null && this.player.getLocation().toVector().distanceSquared(new Vector(x, y,
z)) < (Bukkit.getServer().getViewDistance() * 256 * Bukkit.getServer().getViewDistance())) {
if (particle.equals(Particle.REDSTONE)) {
if (particle.equals(Particle.DUST)) {
player.spawnParticle(particle, x, y, z, 1, 0, 0, 0, 1, dustOptions);
} else if (dustOptions != null) {
player.spawnParticle(particle, x, y, z, 1, dustOptions);

View File

@ -1,8 +1,10 @@
package world.bentobox.bentobox.hooks;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.bukkit.DyeColor;
import org.bukkit.Material;
@ -264,29 +266,57 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getPotionName(potionType, getUserLocale(user));
}
return generalPotionName(potionType);
}
private static String generalPotionName(PotionType potionType) {
return switch (potionType) {
case UNCRAFTABLE -> "Uncraftable Potion";
case WATER -> "Water Bottle";
case MUNDANE -> "Mundane Potion";
case THICK -> "Thick Potion";
case AWKWARD -> "Awkward Potion";
case NIGHT_VISION -> "Potion of Night Vision";
case INVISIBILITY -> "Potion of Invisibility";
case JUMP -> "Potion of Leaping";
case FIRE_RESISTANCE -> "Potion of Fire Resistance";
case SPEED -> "Potion of Swiftness";
case SLOWNESS -> "Potion of Slowness";
case WATER_BREATHING -> "Potion of Water Breathing";
case INSTANT_HEAL -> "Potion of Healing";
case INSTANT_DAMAGE -> "Potion of Harming";
case POISON -> "Potion of Poison";
case REGEN -> "Potion of Regeneration";
case STRENGTH -> "Potion of Strength";
case WEAKNESS -> "Potion of Weakness";
case LUCK -> "Potion of Luck";
case TURTLE_MASTER -> "Potion of the Turtle Master";
case SLOW_FALLING -> "Potion of Slow Falling";
default -> "Unknown Potion";
case HARMING -> "Potion of Harming";
case HEALING -> "Potion of Healing";
case INFESTED -> "Infested Potion";
case LEAPING -> "Potion of Leaping";
case LONG_FIRE_RESISTANCE -> "Potion of Long Fire Resistance";
case LONG_INVISIBILITY -> "Potion of Long Invisibility";
case LONG_NIGHT_VISION -> "Potion of Long Night Vision";
case LONG_POISON -> "Potion of Long Poison";
case LONG_REGENERATION -> "Potion of Long Regeneration";
case LONG_SLOWNESS -> "Potion of Long Slowness";
case LONG_SLOW_FALLING -> "Potion of Long Slow Falling";
case LONG_STRENGTH -> "Potion of Long Strength";
case LONG_SWIFTNESS -> "Potion of Long Swiftness";
case LONG_TURTLE_MASTER -> "Potion of Long Turtle Master";
case LONG_WATER_BREATHING -> "Potion of Long Water Breathing";
case LONG_WEAKNESS -> "Potion of Long Weakness";
case OOZING -> "Potion of Oozing";
case REGENERATION -> "Potion of Regeneration";
case STRONG_HARMING -> "Potion of Strong Harming";
case STRONG_HEALING -> "Potion of Strong Healing";
case STRONG_LEAPING -> "Potion of Strong Leaping";
case STRONG_POISON -> "Potion of Strong Poison";
case STRONG_REGENERATION -> "Potion of Strong Regeneration";
case STRONG_SLOWNESS -> "Potion of Strong Slowness";
case STRONG_STRENGTH -> "Potion of Strong Strength";
case STRONG_SWIFTNESS -> "Potion of Swiftness";
case STRONG_TURTLE_MASTER -> "Potion of Strong Turtle Master";
case SWIFTNESS -> "Potion of Swiftness";
case WEAVING -> "Potion of Weaving";
case WIND_CHARGED -> "Potion of Wind Charged";
default -> "Potion (Unknown)";
};
}
@ -302,30 +332,7 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getSplashPotionName(potionType, getUserLocale(user));
}
return switch (potionType) {
case UNCRAFTABLE -> "Splash Uncraftable Potion";
case WATER -> "Splash Water Bottle";
case MUNDANE -> "Mundane Splash Potion";
case THICK -> "Thick Splash Potion";
case AWKWARD -> "Awkward Splash Potion";
case NIGHT_VISION -> "Splash Potion of Night Vision";
case INVISIBILITY -> "Splash Potion of Invisibility";
case JUMP -> "Splash Potion of Leaping";
case FIRE_RESISTANCE -> "Splash Potion of Fire Resistance";
case SPEED -> "Splash Potion of Swiftness";
case SLOWNESS -> "Splash Potion of Slowness";
case WATER_BREATHING -> "Splash Potion of Water Breathing";
case INSTANT_HEAL -> "Splash Potion of Healing";
case INSTANT_DAMAGE -> "Splash Potion of Harming";
case POISON -> "Splash Potion of Poison";
case REGEN -> "Splash Potion of Regeneration";
case STRENGTH -> "Splash Potion of Strength";
case WEAKNESS -> "Splash Potion of Weakness";
case LUCK -> "Splash Potion of Luck";
case TURTLE_MASTER -> "Splash Potion of the Turtle Master";
case SLOW_FALLING -> "Splash Potion of Slow Falling";
default -> "Unknown Splash Potion";
};
return "Splash" + generalPotionName(potionType);
}
/**
@ -339,30 +346,7 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getLingeringPotionName(potionType, getUserLocale(user));
}
return switch (potionType) {
case UNCRAFTABLE -> "Lingering Uncraftable Potion";
case WATER -> "Lingering Water Bottle";
case MUNDANE -> "Mundane Lingering Potion";
case THICK -> "Thick Lingering Potion";
case AWKWARD -> "Awkward Lingering Potion";
case NIGHT_VISION -> "Lingering Potion of Night Vision";
case INVISIBILITY -> "Lingering Potion of Invisibility";
case JUMP -> "Lingering Potion of Leaping";
case FIRE_RESISTANCE -> "Lingering Potion of Fire Resistance";
case SPEED -> "Lingering Potion of Swiftness";
case SLOWNESS -> "Lingering Potion of Slowness";
case WATER_BREATHING -> "Lingering Potion of Water Breathing";
case INSTANT_HEAL -> "Lingering Potion of Healing";
case INSTANT_DAMAGE -> "Lingering Potion of Harming";
case POISON -> "Lingering Potion of Poison";
case REGEN -> "Lingering Potion of Regeneration";
case STRENGTH -> "Lingering Potion of Strength";
case WEAKNESS -> "Lingering Potion of Weakness";
case LUCK -> "Lingering Potion of Luck";
case TURTLE_MASTER -> "Lingering Potion of the Turtle Master";
case SLOW_FALLING -> "Lingering Potion of Slow Falling";
default -> "Unknown Lingering Potion";
};
return "Lingering" + generalPotionName(potionType);
}
/**
@ -376,28 +360,7 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getTippedArrowName(potionType, getUserLocale(user));
}
return switch (potionType) {
case UNCRAFTABLE -> "Uncraftable Tipped Arrow";
case WATER -> "Arrow of Splashing";
case MUNDANE, THICK, AWKWARD -> "Tipped Arrow";
case NIGHT_VISION -> "Arrow of Night Vision";
case INVISIBILITY -> "Arrow of Invisibility";
case JUMP -> "Arrow of Leaping";
case FIRE_RESISTANCE -> "Arrow of Fire Resistance";
case SPEED -> "Arrow of Swiftness";
case SLOWNESS -> "Arrow of Slowness";
case WATER_BREATHING -> "Arrow of Water Breathing";
case INSTANT_HEAL -> "Arrow of Healing";
case INSTANT_DAMAGE -> "Arrow of Harming";
case POISON -> "Arrow of Poison";
case REGEN -> "Arrow of Regeneration";
case STRENGTH -> "Arrow of Strength";
case WEAKNESS -> "Arrow of Weakness";
case LUCK -> "Arrow of Luck";
case TURTLE_MASTER -> "Arrow of the Turtle Master";
case SLOW_FALLING -> "Arrow of Slow Falling";
default -> "Unknown Arrow";
};
return generalPotionName(potionType).replaceAll("Potion", "Arrow");
}
/**
@ -413,11 +376,12 @@ public class LangUtilsHook extends Hook {
if (hooked) {
return LanguageHelper.getPotionBaseEffectName(potionType, getUserLocale(user));
}
PotionEffectType effectType = potionType.getEffectType();
if (effectType == null) {
List<PotionEffect> effects = potionType.getPotionEffects();
if (effects.isEmpty()) {
return "No Effects";
}
return Util.prettifyText(effectType.getName());
return effects.stream().map(effect -> Util.prettifyText(effect.getType().getKey().getKey()))
.collect(Collectors.joining(", "));
}
/**
@ -430,7 +394,7 @@ public class LangUtilsHook extends Hook {
public static String getPotionEffectName(PotionEffectType effectType, User user) {
return hooked
? LanguageHelper.getPotionEffectName(effectType, getUserLocale(user))
: Util.prettifyText(effectType.getName());
: Util.prettifyText(effectType.getKey().getKey());
}
/**

View File

@ -17,6 +17,7 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import com.google.common.base.Enums;
import com.google.common.base.Optional;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
@ -28,7 +29,6 @@ import world.bentobox.bentobox.lists.Flags;
*
*/
public class BreedingListener extends FlagListener {
/**
* A list of items that cause breeding if a player has them in their hand and they click an animal
* This list may need to be extended with future versions of Minecraft.
@ -41,7 +41,10 @@ public class BreedingListener extends FlagListener {
bi.put(EntityType.HORSE, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
bi.put(EntityType.DONKEY, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
bi.put(EntityType.COW, Collections.singletonList(Material.WHEAT));
bi.put(EntityType.MUSHROOM_COW, Collections.singletonList(Material.WHEAT));
Optional<EntityType> mc = Enums.getIfPresent(EntityType.class, "MUSHROOM_COW");
if (mc.isPresent()) {
bi.put(mc.get(), Collections.singletonList(Material.WHEAT));
}
bi.put(EntityType.SHEEP, Collections.singletonList(Material.WHEAT));
bi.put(EntityType.PIG, Arrays.asList(Material.CARROT, Material.POTATO, Material.BEETROOT));
bi.put(EntityType.CHICKEN, Arrays.asList(Material.WHEAT_SEEDS, Material.PUMPKIN_SEEDS, Material.MELON_SEEDS, Material.BEETROOT_SEEDS));

View File

@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerUnleashEntityEvent;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
/**
* @author tastybento
@ -42,7 +43,8 @@ public class LeashListener extends FlagListener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerLeashHitch(final HangingPlaceEvent e) {
if (e.getEntity().getType().equals(EntityType.LEASH_HITCH)) {
EntityType LEASH_HITCH = Util.findFirstMatchingEnum(EntityType.class, "LEASH_HITCH", "LEASH_KNOT");
if (e.getEntity().getType().equals(LEASH_HITCH)) {
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.LEASH);
}
}

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners.flags.protection;
import java.io.IOException;
import java.util.List;
import org.bukkit.Location;
@ -17,21 +18,38 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import com.google.common.base.Enums;
import com.google.common.base.Optional;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.util.Util;
/**
* Protects islands from visitors blowing things up
* @author tastybento
*/
public class TNTListener extends FlagListener {
/**
* Contains {@link EntityType}s that generates an explosion.
* @since 1.5.0
*/
private static final List<EntityType> TNT_TYPES = List.of(EntityType.PRIMED_TNT, EntityType.MINECART_TNT);
private static final List<EntityType> TNT_TYPES = List.of(
findFirstMatchingEnum(EntityType.class, "PRIMED_TNT", "TNT"),
findFirstMatchingEnum(EntityType.class, "MINECART_TNT", "TNT_MINECART"));
private static <T extends Enum<T>> T findFirstMatchingEnum(Class<T> enumClass, String... values) {
if (enumClass == null || values == null) {
return null;
}
for (String value : values) {
Optional<T> enumConstant = Enums.getIfPresent(enumClass, value.toUpperCase());
if (enumConstant.isPresent()) {
return enumConstant.get();
}
}
return null; // Return null if no match is found
}
/**
* Contains {@link Material}s that can be used to prime a TNT.
* @since 1.5.0

View File

@ -0,0 +1,52 @@
package world.bentobox.bentobox.nms.v1_20_R4;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData;
import net.minecraft.core.BlockPosition;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.chunk.Chunk;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.nms.PasteHandler;
import world.bentobox.bentobox.util.DefaultPasteUtil;
import world.bentobox.bentobox.util.Util;
public class PasteHandlerImpl implements PasteHandler {
protected static final IBlockData AIR = ((CraftBlockData) AIR_BLOCKDATA).getState();
/**
* Set the block to the location
*
* @param island - island
* @param location - location
* @param bpBlock - blueprint block
*/
@Override
public CompletableFuture<Void> setBlock(Island island, Location location, BlueprintBlock bpBlock) {
return Util.getChunkAtAsync(location).thenRun(() -> {
Block block = location.getBlock();
// Set the block data - default is AIR
BlockData bd = DefaultPasteUtil.createBlockData(bpBlock);
CraftBlockData craft = (CraftBlockData) bd;
net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4);
BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
// Setting the block to air before setting to another state prevents some console errors
nmsChunk.a(bp, AIR, false);
nmsChunk.a(bp, craft.getState(), false);
block.setBlockData(bd, false);
DefaultPasteUtil.setBlockState(island, block, bpBlock);
// Set biome
if (bpBlock.getBiome() != null) {
block.setBiome(bpBlock.getBiome());
}
});
}
}

View File

@ -0,0 +1,26 @@
package world.bentobox.bentobox.nms.v1_20_R4;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData;
import net.minecraft.core.BlockPosition;
import net.minecraft.world.level.World;
import net.minecraft.world.level.chunk.Chunk;
import world.bentobox.bentobox.nms.CopyWorldRegenerator;
public class WorldRegeneratorImpl extends CopyWorldRegenerator {
@Override
public void setBlockInNativeChunk(org.bukkit.Chunk chunk, int x, int y, int z, BlockData blockData,
boolean applyPhysics) {
CraftBlockData craft = (CraftBlockData) blockData;
World nmsWorld = ((CraftWorld) chunk.getWorld()).getHandle();
Chunk nmsChunk = nmsWorld.d(chunk.getX(), chunk.getZ());
BlockPosition bp = new BlockPosition((chunk.getX() << 4) + x, y, (chunk.getZ() << 4) + z);
// Setting the block to air before setting to another state prevents some console errors
nmsChunk.a(bp, PasteHandlerImpl.AIR, applyPhysics);
nmsChunk.a(bp, craft.getState(), applyPhysics);
}
}

View File

@ -261,7 +261,8 @@ public class ItemParser {
boolean isUpgraded = !part[2].isEmpty() && !part[2].equalsIgnoreCase("1");
boolean isExtended = part[3].equalsIgnoreCase("EXTENDED");
PotionData data = new PotionData(type, isExtended, isUpgraded);
potionMeta.setBasePotionData(data);
// TODO: Set extended and u[graded settings.
potionMeta.setBasePotionType(type);
result.setItemMeta(potionMeta);
result.setAmount(Integer.parseInt(part[5]));
return result;
@ -285,7 +286,7 @@ public class ItemParser {
private static ItemStack parsePotion(String[] part) {
if (part.length == 6) {
BentoBox.getInstance().logWarning("The old potion parsing detected for " + part[0] +
". Please update your configs, as SPIGOT changed potion types.");
". Please update your configs, as SPIGOT changed potion types.");
return parsePotionOld(part);
}
@ -314,7 +315,7 @@ public class ItemParser {
if (result.getItemMeta() instanceof PotionMeta meta) {
PotionType potionType = Enums.getIfPresent(PotionType.class, part[1].toUpperCase(Locale.ENGLISH)).
or(PotionType.WATER);
or(PotionType.WATER);
meta.setBasePotionType(potionType);
result.setItemMeta(meta);
}
@ -340,7 +341,17 @@ public class ItemParser {
BannerMeta meta = (BannerMeta) result.getItemMeta();
if (meta != null) {
for (int i = 2; i < part.length; i += 2) {
meta.addPattern(new Pattern(DyeColor.valueOf(part[i + 1]), PatternType.valueOf(part[i])));
PatternType pt = Enums.getIfPresent(PatternType.class, part[i]).orNull();
if (pt == null) {
// Try to convert old to new
if (part[i].trim().equals("STRIPE_SMALL")) {
pt = PatternType.SMALL_STRIPES;
}
}
DyeColor dc = Enums.getIfPresent(DyeColor.class, part[i + 1]).orNull();
if (pt != null && dc != null) {
meta.addPattern(new Pattern(dc, pt));
}
}
result.setItemMeta(meta);
}

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.util;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -42,6 +43,9 @@ import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import com.google.common.base.Enums;
import com.google.common.base.Optional;
import io.papermc.lib.PaperLib;
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
import world.bentobox.bentobox.BentoBox;
@ -801,4 +805,30 @@ public class Util {
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
toLowerCase();
}
/**
* Attempts to find the first matching enum constant from an array of possible string representations.
* This method sequentially checks each string against the enum constants of the specified enum class
* by normalizing the string values to uppercase before comparison, enhancing the likelihood of a match
* if the enum constants are defined in uppercase.
*
* @param enumClass the Class object of the enum type to be checked against
* @param values an array of string values which are potential matches for the enum constants
* @param <T> the type parameter of the enum
* @return the first matching enum constant if a match is found; otherwise, returns null
* @throws IOException
* @throws NullPointerException if either {@code enumClass} or {@code values} are null
*/
public static <T extends Enum<T>> T findFirstMatchingEnum(Class<T> enumClass, String... values) {
if (enumClass == null || values == null) {
return null;
}
for (String value : values) {
Optional<T> enumConstant = Enums.getIfPresent(enumClass, value.toUpperCase());
if (enumConstant.isPresent()) {
return enumConstant.get();
}
}
return null; // Return null if no match is found
}
}

View File

@ -231,7 +231,15 @@ public class ServerCompatibility {
/**
* @since 2.0.0
*/
V1_20_4(Compatibility.COMPATIBLE);
V1_20_4(Compatibility.COMPATIBLE),
/**
* @since 2.4.0
*/
V1_20_5(Compatibility.COMPATIBLE),
/**
* @since 2.4.0
*/
V1_20_6(Compatibility.COMPATIBLE);
private final Compatibility compatibility;

View File

@ -36,6 +36,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@ -93,6 +95,10 @@ public class TestBentoBox extends AbstractCommonSetup {
when(ownerOfIsland.getUniqueId()).thenReturn(uuid);
when(visitorToIsland.getUniqueId()).thenReturn(VISITOR_UUID);
// Util
PowerMockito.mockStatic(Util.class);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
island.setOwner(uuid);
island.setProtectionRange(100);
HashMap<UUID, Integer> members = new HashMap<>();

View File

@ -155,6 +155,7 @@ public class AdminSettingsCommandTest extends RanksManagerBeforeClassTest {
PowerMockito.mockStatic(Util.class);
when(Util.getUUID(anyString())).thenReturn(uuid);
when(Util.tabLimit(any(), any())).thenCallRealMethod();
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Settings
Settings settings = new Settings();

View File

@ -160,6 +160,7 @@ public class IslandGoCommandTest {
when(iwm.getAddon(any())).thenReturn(Optional.empty());
PowerMockito.mockStatic(Util.class);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Locales
LocalesManager lm = mock(LocalesManager.class);

View File

@ -215,6 +215,7 @@ public class CycleClickTest {
// Util
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Event
when(Bukkit.getPluginManager()).thenReturn(pim);

View File

@ -92,6 +92,7 @@ public class IslandToggleClickTest {
when(user.getUniqueId()).thenReturn(uuid);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(mock(World.class));
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
FlagsManager fm = mock(FlagsManager.class);
when(flag.isSetForWorld(any())).thenReturn(false);

View File

@ -55,7 +55,7 @@ public class BentoBoxLocaleTest {
Locale locale = Locale.US;
YamlConfiguration config = new YamlConfiguration();
config.set("meta.banner", "WHITE_BANNER:1:STRIPE_SMALL:RED:SQUARE_TOP_RIGHT:CYAN:SQUARE_TOP_RIGHT:BLUE");
config.set("meta.banner", "WHITE_BANNER:1:SMALL_STRIPES:RED:SQUARE_TOP_RIGHT:CYAN:SQUARE_TOP_RIGHT:BLUE");
List<String> authors = new ArrayList<>();
authors.add("tastybento");
authors.add("tastybento2");

View File

@ -842,9 +842,10 @@ public class UserTest {
User.clearUsers();
User p = User.getInstance(player);
try {
p.spawnParticle(Particle.REDSTONE, 4, 0.0d, 0.0d, 0.0d);
p.spawnParticle(Particle.DUST, 4, 0.0d, 0.0d, 0.0d);
} catch (Exception e) {
assertEquals("A non-null DustOptions must be provided when using Particle.REDSTONE as particle.", e.getMessage());
assertEquals("A non-null DustOptions must be provided when using Particle.DUST as particle.",
e.getMessage());
}
}
@ -878,8 +879,8 @@ public class UserTest {
User p = User.getInstance(player);
DustOptions dust = mock(DustOptions.class);
p.spawnParticle(Particle.REDSTONE, dust, 0.0d, 0.0d, 0.0d);
verify(player).spawnParticle(Particle.REDSTONE, 0.0d, 0.0d, 0.0d, 1, 0, 0, 0, 1, dust);
p.spawnParticle(Particle.DUST, dust, 0.0d, 0.0d, 0.0d);
verify(player).spawnParticle(Particle.DUST, 0.0d, 0.0d, 0.0d, 1, 0, 0, 0, 1, dust);
}
@ -896,8 +897,8 @@ public class UserTest {
User p = User.getInstance(player);
DustOptions dust = mock(DustOptions.class);
p.spawnParticle(Particle.REDSTONE, dust, 0.0d, 0.0d, 0.0d);
verify(player).spawnParticle(Particle.REDSTONE, 0.0d, 0.0d, 0.0d, 1, 0, 0, 0, 1, dust);
p.spawnParticle(Particle.DUST, dust, 0.0d, 0.0d, 0.0d);
verify(player).spawnParticle(Particle.DUST, 0.0d, 0.0d, 0.0d, 1, 0, 0, 0, 1, dust);
}
@ -914,8 +915,8 @@ public class UserTest {
User p = User.getInstance(player);
DustOptions dust = mock(DustOptions.class);
p.spawnParticle(Particle.REDSTONE, dust, 0, 0, 0);
verify(player).spawnParticle(Particle.REDSTONE, 0.0d, 0.0d, 0.0d, 1, 0, 0, 0, 1, dust);
p.spawnParticle(Particle.DUST, dust, 0, 0, 0);
verify(player).spawnParticle(Particle.DUST, 0.0d, 0.0d, 0.0d, 1, 0, 0, 0, 1, dust);
}

View File

@ -134,6 +134,7 @@ public class StandardSpawnProtectionListenerTest {
// Util translate color codes (used in user translate methods)
when(Util.translateColorCodes(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Set up class
ssp = new StandardSpawnProtectionListener(plugin);

View File

@ -169,6 +169,8 @@ public abstract class AbstractCommonSetup {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(mock(World.class));
// Util
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Util translate color codes (used in user translate methods)
when(Util.translateColorCodes(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));

View File

@ -76,7 +76,9 @@ public class GeoMobLimitTabTest {
// IWM
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getAddon(any())).thenReturn(Optional.of(gma));
// Make list of the first 4 creatures on the list - it's alphabetical and follows the list of Living Entities
list = new ArrayList<>();
list.add("ARMADILLO");
list.add("AXOLOTL");
list.add("BAT");
list.add("COW");
@ -102,24 +104,27 @@ public class GeoMobLimitTabTest {
@Test
public void testOnClick() {
GeoMobLimitTab tab = new GeoMobLimitTab(user, EntityLimitTabType.GEO_LIMIT, world);
// AXOLOTL, BAT, and COW in list
// ARMADILLO, AXOLOTL, BAT, and COW in list
assertEquals(4, list.size());
assertEquals("COW", list.get(3));
assertEquals("BAT", list.get(2));
assertEquals("AXOLOTL", list.get(1));
assertEquals("ARMADILLO", list.get(0));
// Click on ARMADILLO
tab.onClick(panel, user, ClickType.LEFT, 10);
list.forEach(System.out::println);
assertEquals(3, list.size());
assertEquals("COW", list.get(2));
assertEquals("BAT", list.get(1));
assertEquals("AXOLOTL", list.get(0));
// Click on AXOLOTL
// Click on ARMADILLO again to have it added to the end of the list
tab.onClick(panel, user, ClickType.LEFT, 10);
list.forEach(System.out::println);
assertEquals(2, list.size());
assertEquals("COW", list.get(1));
assertEquals("BAT", list.get(0));
// Click on AXOLOTL again to have it added
tab.onClick(panel, user, ClickType.LEFT, 10);
assertEquals(3, list.size());
assertEquals("BAT", list.get(0));
assertEquals("COW", list.get(1));
assertEquals("AXOLOTL", list.get(2));
assertEquals(4, list.size());
assertEquals("COW", list.get(2));
assertEquals("BAT", list.get(1));
assertEquals("AXOLOTL", list.get(0));
assertEquals("ARMADILLO", list.get(3));
verify(gma, times(2)).saveWorldSettings();
}
@ -165,7 +170,8 @@ public class GeoMobLimitTabTest {
List<@Nullable PanelItem> items = tab.getPanelItems();
assertFalse(items.isEmpty());
items.forEach(i -> {
if (i.getName().equals("Axolotl") || i.getName().equals("Cow") || i.getName().equals("Bat")) {
if (i.getName().equals("Armadillo") || i.getName().equals("Axolotl") || i.getName().equals("Cow")
|| i.getName().equals("Bat")) {
assertEquals("Name : " + i.getName(), Material.RED_SHULKER_BOX, i.getItem().getType());
} else {
assertEquals("Name : " + i.getName(), Material.GREEN_SHULKER_BOX, i.getItem().getType());
@ -182,7 +188,8 @@ public class GeoMobLimitTabTest {
List<@Nullable PanelItem> items = tab.getPanelItems();
assertFalse(items.isEmpty());
items.forEach(i -> {
if (i.getName().equals("Axolotl") || i.getName().equals("Cow") || i.getName().equals("Bat")) {
if (i.getName().equals("Armadillo") || i.getName().equals("Axolotl") || i.getName().equals("Cow")
|| i.getName().equals("Bat")) {
assertEquals("Name : " + i.getName(), Material.GREEN_SHULKER_BOX, i.getItem().getType());
} else {
assertEquals("Name : " + i.getName(), Material.RED_SHULKER_BOX, i.getItem().getType());

View File

@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@ -77,10 +78,13 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(block.getWorld()).thenReturn(world);
// Entity
when(entity.getType()).thenReturn(EntityType.PRIMED_TNT);
when(entity.getType()).thenReturn(EntityType.TNT);
when(entity.getWorld()).thenReturn(world);
when(entity.getLocation()).thenReturn(location);
// Util
when(Util.findFirstMatchingEnum(any(), anyString())).thenCallRealMethod();
listener = new TNTListener();
listener.setPlugin(plugin);

View File

@ -231,6 +231,7 @@ public class PVPListenerTest {
// Util translate color codes (used in user translate methods)
when(Util.translateColorCodes(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
}

View File

@ -185,7 +185,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
public void testOnExplosionChestDamageNotAllowed() {
Flags.CHEST_DAMAGE.setSetting(world, false);
Entity entity = mock(Entity.class);
when(entity.getType()).thenReturn(EntityType.PRIMED_TNT);
when(entity.getType()).thenReturn(EntityType.TNT);
List<Block> list = new ArrayList<>();
Block chest = mock(Block.class);
when(chest.getType()).thenReturn(Material.CHEST);
@ -217,7 +217,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
public void testOnExplosionChestDamageAllowed() {
Flags.CHEST_DAMAGE.setSetting(world, true);
Entity entity = mock(Entity.class);
when(entity.getType()).thenReturn(EntityType.PRIMED_TNT);
when(entity.getType()).thenReturn(EntityType.TNT);
List<Block> list = new ArrayList<>();
Block chest = mock(Block.class);
when(chest.getType()).thenReturn(Material.CHEST);

View File

@ -82,6 +82,7 @@ public class CleanSuperFlatListenerTest {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Regenerator
when(Util.getRegenerator()).thenReturn(regenerator);

View File

@ -102,6 +102,11 @@ public class EnterExitListenerTest {
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
// Util
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
@ -189,9 +194,6 @@ public class EnterExitListenerTest {
// Listener
listener = new EnterExitListener();
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(any())).thenReturn(ws);

View File

@ -137,6 +137,7 @@ public class InvincibleVisitorsListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(mock(World.class));
when(Util.prettifyText(anyString())).thenCallRealMethod();
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Util translate color codes (used in user translate methods)
when(Util.translateColorCodes(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
FlagsManager fm = mock(FlagsManager.class);

View File

@ -103,6 +103,7 @@ public class IslandRespawnListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// World Settings
WorldSettings ws = mock(WorldSettings.class);

View File

@ -66,6 +66,11 @@ public class OfflineGrowthListenerTest {
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Util
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Owner
UUID uuid = UUID.randomUUID();
@ -92,9 +97,6 @@ public class OfflineGrowthListenerTest {
when(block.getLocation()).thenReturn(inside);
when(block.getType()).thenReturn(Material.KELP);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
// World Settings
when(iwm.inWorld(any(World.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm);

View File

@ -94,6 +94,7 @@ public class OfflineRedstoneListenerTest {
// Util
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// World Settings
when(iwm.inWorld(any(World.class))).thenReturn(true);

View File

@ -94,6 +94,7 @@ public class PistonPushListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// World Settings
IslandWorldManager iwm = mock(IslandWorldManager.class);

View File

@ -97,6 +97,7 @@ public class RemoveMobsListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// World Settings
IslandWorldManager iwm = mock(IslandWorldManager.class);

View File

@ -87,6 +87,9 @@ public class FlagsManagerTest {
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
//PowerMockito.mockStatic(Flags.class);
// Util
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
}
@After

View File

@ -238,6 +238,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
// Worlds translate to world
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.findFirstMatchingEnum(any(), any())).thenCallRealMethod();
// Island
when(island.getOwner()).thenReturn(uuid);

View File

@ -209,7 +209,6 @@ public class IslandCreationPanelTest {
verify(inv).setItem(eq(0), any());
verify(inv).setItem(eq(1), any());
verify(meta).setDisplayName(eq("test"));
verify(meta).setLocalizedName(eq("test"));
verify(meta).setLore(eq(List.of("A description", "", "panels.tips.click-to-choose")));
}
@ -224,15 +223,12 @@ public class IslandCreationPanelTest {
verify(inv).setItem(eq(0), any());
verify(inv).setItem(eq(1), any());
verify(meta).setDisplayName(eq("test"));
verify(meta).setLocalizedName(eq("test"));
verify(meta).setLore(eq(List.of("A description", "", "panels.tips.click-to-choose")));
verify(inv).setItem(eq(0), any());
verify(meta).setDisplayName(eq("test2"));
verify(meta).setLocalizedName(eq("test2"));
verify(meta).setLore(eq(List.of("A description 2", "", "panels.tips.click-to-choose")));
verify(inv).setItem(eq(1), any());
verify(meta).setDisplayName(eq("test3"));
verify(meta).setLocalizedName(eq("test3"));
verify(meta).setLore(eq(List.of("A description 3", "", "panels.tips.click-to-choose")));
}