Fix compatibility for 1.20.6
This commit is contained in:
parent
6949432cb6
commit
63cc0a01d9
|
@ -3,7 +3,6 @@ package world.bentobox.bentobox.api.commands.admin.range;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
@ -11,11 +10,10 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
|
|
||||||
import com.google.common.base.Enums;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
|
@ -26,10 +24,9 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
|
||||||
private static final String DISPLAY = "display";
|
private static final String DISPLAY = "display";
|
||||||
private static final String SHOW = "show";
|
private static final String SHOW = "show";
|
||||||
private static final String HIDE = "hide";
|
private static final String HIDE = "hide";
|
||||||
public static final Particle PARTICLE = Enums.getIfPresent(Particle.class, "RESTONE").toJavaUtil()
|
public static final Particle PARTICLE = Util.findFirstMatchingEnum(Particle.class, "REDSTONE", "DUST");
|
||||||
.orElse(Enums.getIfPresent(Particle.class, "DUST").orNull());
|
private static final Particle PARTICLE2 = Util.findFirstMatchingEnum(Particle.class, "VILLAGER_HAPPY",
|
||||||
private static final Particle PARTICLE2 = Enums.getIfPresent(Particle.class, "VILLAGER_HAPPY").toJavaUtil()
|
"HAPPY_VILLAGER");
|
||||||
.orElse(Enums.getIfPresent(Particle.class, "HAPPY_VILLAGER").orNull());
|
|
||||||
|
|
||||||
// Map of users to which ranges must be displayed
|
// Map of users to which ranges must be displayed
|
||||||
private final Map<User, Integer> displayRanges = new HashMap<>();
|
private final Map<User, Integer> displayRanges = new HashMap<>();
|
||||||
|
|
|
@ -20,6 +20,7 @@ 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;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles breeding protection
|
* Handles breeding protection
|
||||||
|
@ -40,12 +41,8 @@ public class BreedingListener extends FlagListener {
|
||||||
bi.put(EntityType.HORSE, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
|
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.DONKEY, Arrays.asList(Material.GOLDEN_APPLE, Material.GOLDEN_CARROT));
|
||||||
bi.put(EntityType.COW, Collections.singletonList(Material.WHEAT));
|
bi.put(EntityType.COW, Collections.singletonList(Material.WHEAT));
|
||||||
if (Enums.getIfPresent(EntityType.class, "MUSHROOM_COW").isPresent()) {
|
bi.put(Util.findFirstMatchingEnum(EntityType.class, "MUSHROOM_COW", "MOOSHROOM"),
|
||||||
bi.put(Enums.getIfPresent(EntityType.class, "MUSHROOM_COW").get(),
|
Collections.singletonList(Material.WHEAT));
|
||||||
Collections.singletonList(Material.WHEAT));
|
|
||||||
} else {
|
|
||||||
bi.put(EntityType.MOOSHROOM, Collections.singletonList(Material.WHEAT));
|
|
||||||
}
|
|
||||||
bi.put(EntityType.SHEEP, 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.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));
|
bi.put(EntityType.CHICKEN, Arrays.asList(Material.WHEAT_SEEDS, Material.PUMPKIN_SEEDS, Material.MELON_SEEDS, Material.BEETROOT_SEEDS));
|
||||||
|
|
|
@ -7,10 +7,9 @@ import org.bukkit.event.entity.PlayerLeashEntityEvent;
|
||||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerUnleashEntityEvent;
|
import org.bukkit.event.player.PlayerUnleashEntityEvent;
|
||||||
|
|
||||||
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;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
|
@ -44,9 +43,8 @@ public class LeashListener extends FlagListener {
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onPlayerLeashHitch(final HangingPlaceEvent e) {
|
public void onPlayerLeashHitch(final HangingPlaceEvent e) {
|
||||||
EntityType LEASH_HITCH = Enums.getIfPresent(EntityType.class, "LEASH_HITCH")
|
EntityType LEASH_HITCH = Util.findFirstMatchingEnum(EntityType.class, "LEASH_HITCH", "LEASH_KNOT");
|
||||||
.or(Enums.getIfPresent(EntityType.class, "LEASH_KNOT").orNull());
|
if (e.getEntity().getType().equals(LEASH_HITCH)) {
|
||||||
if (LEASH_HITCH != null && e.getEntity().getType().equals(LEASH_HITCH)) {
|
|
||||||
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.LEASH);
|
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.LEASH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,9 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
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;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protects islands from visitors blowing things up
|
* Protects islands from visitors blowing things up
|
||||||
|
@ -28,9 +27,9 @@ import world.bentobox.bentobox.lists.Flags;
|
||||||
*/
|
*/
|
||||||
public class TNTListener extends FlagListener {
|
public class TNTListener extends FlagListener {
|
||||||
|
|
||||||
private static final EntityType PRIMED_TNT = Enums.getIfPresent(EntityType.class, "PRIMED_TNT").or(EntityType.TNT);
|
private static final EntityType PRIMED_TNT = Util.findFirstMatchingEnum(EntityType.class, "PRIMED_TNT", "TNT");
|
||||||
private static final EntityType MINECART_TNT = Enums.getIfPresent(EntityType.class, "PMINECART_TNT)")
|
private static final EntityType MINECART_TNT = Util.findFirstMatchingEnum(EntityType.class, "MINECART_TNT",
|
||||||
.or(EntityType.TNT_MINECART);
|
"TNT_MINECART");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains {@link EntityType}s that generates an explosion.
|
* Contains {@link EntityType}s that generates an explosion.
|
||||||
|
|
|
@ -42,6 +42,9 @@ import org.bukkit.util.Vector;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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.PaperLib;
|
||||||
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
|
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
@ -801,4 +804,26 @@ public class Util {
|
||||||
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
|
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
|
||||||
toLowerCase();
|
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 NullPointerException if either {@code enumClass} or {@code values} are null
|
||||||
|
*/
|
||||||
|
public static <T extends Enum<T>> T findFirstMatchingEnum(Class<T> enumClass, String... values) {
|
||||||
|
for (String value : values) {
|
||||||
|
Optional<T> enumConstant = Enums.getIfPresent(enumClass, value.toUpperCase());
|
||||||
|
if (enumConstant.isPresent()) {
|
||||||
|
return enumConstant.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // Return null or throw an exception if no match is found
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,15 @@ public class ServerCompatibility {
|
||||||
/**
|
/**
|
||||||
* @since 2.0.0
|
* @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;
|
private final Compatibility compatibility;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue