From 3811b01e81b0722d4ddbf8e7da50cbea95b97a29 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 10 Nov 2021 18:31:38 +0000 Subject: [PATCH] Delomboked Utils --- .../java/com/willfp/eco/util/ArrowUtils.java | 11 +-- .../java/com/willfp/eco/util/BlockUtils.java | 34 ++++---- .../java/com/willfp/eco/util/ClassUtils.java | 10 ++- .../com/willfp/eco/util/DurabilityUtils.java | 35 ++++---- .../com/willfp/eco/util/LightningUtils.java | 18 +++-- .../java/com/willfp/eco/util/ListUtils.java | 8 +- .../java/com/willfp/eco/util/MenuUtils.java | 10 ++- .../willfp/eco/util/NamespacedKeyUtils.java | 14 ++-- .../java/com/willfp/eco/util/NumberUtils.java | 40 +++++----- .../java/com/willfp/eco/util/PlayerUtils.java | 16 ++-- .../java/com/willfp/eco/util/PotionUtils.java | 10 ++- .../java/com/willfp/eco/util/ServerUtils.java | 14 ++-- .../java/com/willfp/eco/util/SkullUtils.java | 20 ++--- .../java/com/willfp/eco/util/StringUtils.java | 79 +++++++++---------- .../java/com/willfp/eco/util/TeamUtils.java | 12 +-- .../com/willfp/eco/util/TelekinesisUtils.java | 10 ++- .../java/com/willfp/eco/util/VectorUtils.java | 18 +++-- 17 files changed, 193 insertions(+), 166 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/util/ArrowUtils.java b/eco-api/src/main/java/com/willfp/eco/util/ArrowUtils.java index c11f902e..95b050e5 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/ArrowUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/ArrowUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.entity.Arrow; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.MetadataValue; @@ -12,9 +11,7 @@ import java.util.List; /** * Utilities / API methods for arrows. */ -@UtilityClass -public class ArrowUtils { - +public final class ArrowUtils { /** * Get the bow from an arrow. * @@ -22,7 +19,7 @@ public class ArrowUtils { * @return The bow, or null if no bow. */ @Nullable - public ItemStack getBow(@NotNull final Arrow arrow) { + public static ItemStack getBow(@NotNull final Arrow arrow) { List values = arrow.getMetadata("shot-from"); if (values.isEmpty()) { @@ -35,4 +32,8 @@ public class ArrowUtils { return (ItemStack) values.get(0).value(); } + + private ArrowUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/BlockUtils.java b/eco-api/src/main/java/com/willfp/eco/util/BlockUtils.java index 32584f1c..24d9081f 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/BlockUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/BlockUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.apache.commons.lang.Validate; import org.bukkit.Chunk; import org.bukkit.Location; @@ -21,22 +20,21 @@ import java.util.function.BiConsumer; /** * Utilities / API methods for blocks. */ -@UtilityClass -public class BlockUtils { +public final class BlockUtils { /** * If the meta set function has been set. */ - private boolean initialized = false; + private static boolean initialized = false; /** * The block break function. */ - private BiConsumer blockBreakConsumer = null; + private static BiConsumer blockBreakConsumer = null; - private Set getNearbyBlocks(@NotNull final Block start, - @NotNull final List allowedMaterials, - @NotNull final Set blocks, - final int limit) { + private static Set getNearbyBlocks(@NotNull final Block start, + @NotNull final List allowedMaterials, + @NotNull final Set blocks, + final int limit) { for (BlockFace face : BlockFace.values()) { Block block = start.getRelative(face); if (blocks.contains(block)) { @@ -66,9 +64,9 @@ public class BlockUtils { * @return A set of all {@link Block}s. */ @NotNull - public Set getVein(@NotNull final Block start, - @NotNull final List allowedMaterials, - final int limit) { + public static Set getVein(@NotNull final Block start, + @NotNull final List allowedMaterials, + final int limit) { return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit); } @@ -78,8 +76,8 @@ public class BlockUtils { * @param player The player to break the block as. * @param block The block to break. */ - public void breakBlock(@NotNull final Player player, - @NotNull final Block block) { + public static void breakBlock(@NotNull final Player player, + @NotNull final Block block) { Validate.isTrue(initialized, "Must be initialized!"); Validate.notNull(blockBreakConsumer, "Must be initialized!"); @@ -100,7 +98,7 @@ public class BlockUtils { * @param block The block. * @return If placed by a player. */ - public boolean isPlayerPlaced(@NotNull final Block block) { + public static boolean isPlayerPlaced(@NotNull final Block block) { Chunk chunk = block.getChunk(); return chunk.getPersistentDataContainer().has( @@ -115,11 +113,15 @@ public class BlockUtils { * @param function The function. */ @ApiStatus.Internal - public void initialize(@NotNull final BiConsumer function) { + public static void initialize(@NotNull final BiConsumer function) { Validate.isTrue(!initialized, "Already initialized!"); blockBreakConsumer = function; initialized = true; } + + private BlockUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/ClassUtils.java b/eco-api/src/main/java/com/willfp/eco/util/ClassUtils.java index 268150b7..dccab799 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/ClassUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/ClassUtils.java @@ -1,13 +1,11 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; /** * Utilities / API methods for classes. */ -@UtilityClass -public class ClassUtils { +public final class ClassUtils { /** * Get if a class exists. * @@ -15,7 +13,7 @@ public class ClassUtils { * @return If the class exists. * @see Class#forName(String) */ - public boolean exists(@NotNull final String className) { + public static boolean exists(@NotNull final String className) { try { Class.forName(className); return true; @@ -23,4 +21,8 @@ public class ClassUtils { return false; } } + + private ClassUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/DurabilityUtils.java b/eco-api/src/main/java/com/willfp/eco/util/DurabilityUtils.java index 3e0c712e..28a30a18 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/DurabilityUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/DurabilityUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; @@ -11,14 +10,16 @@ import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; /** * Utilities / API methods for item durability. */ -@UtilityClass -public class DurabilityUtils { +public final class DurabilityUtils { + private DurabilityUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } + /** * Damage an item in a player's inventory. * The slot of a held item can be obtained with {@link PlayerInventory#getHeldItemSlot()}. @@ -29,10 +30,10 @@ public class DurabilityUtils { * @param damage The amount of damage to deal. * @param slot The slot in the inventory of the item. */ - public void damageItem(@NotNull final Player player, - @NotNull final ItemStack item, - final int damage, - final int slot) { + public static void damageItem(@NotNull final Player player, + @NotNull final ItemStack item, + final int damage, + final int slot) { if (item.getItemMeta() == null) { return; } @@ -60,13 +61,13 @@ public class DurabilityUtils { if (meta.getDamage() >= item.getType().getMaxDurability()) { meta.setDamage(item.getType().getMaxDurability()); - item.setItemMeta((ItemMeta) meta); + item.setItemMeta(meta); PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item); Bukkit.getPluginManager().callEvent(event); player.getInventory().clear(slot); player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1); } else { - item.setItemMeta((ItemMeta) meta); + item.setItemMeta(meta); } } } @@ -78,9 +79,9 @@ public class DurabilityUtils { * @param damage The amount of damage to deal. * @param player The player. */ - public void damageItemNoBreak(@NotNull final ItemStack item, - final int damage, - @NotNull final Player player) { + public static void damageItemNoBreak(@NotNull final ItemStack item, + final int damage, + @NotNull final Player player) { if (item.getItemMeta() == null) { return; } @@ -104,7 +105,7 @@ public class DurabilityUtils { if (meta.getDamage() >= item.getType().getMaxDurability()) { meta.setDamage(item.getType().getMaxDurability() - 1); } - item.setItemMeta((ItemMeta) meta); + item.setItemMeta(meta); } } @@ -114,8 +115,8 @@ public class DurabilityUtils { * @param item The item to damage. * @param repair The amount of damage to heal. */ - public void repairItem(@NotNull final ItemStack item, - final int repair) { + public static void repairItem(@NotNull final ItemStack item, + final int repair) { if (item.getItemMeta() == null) { return; } @@ -130,7 +131,7 @@ public class DurabilityUtils { if (meta.getDamage() < 0) { meta.setDamage(0); } - item.setItemMeta((ItemMeta) meta); + item.setItemMeta(meta); } } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/LightningUtils.java b/eco-api/src/main/java/com/willfp/eco/util/LightningUtils.java index 3f63392f..3e621906 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/LightningUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/LightningUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; @@ -9,8 +8,7 @@ import org.jetbrains.annotations.NotNull; /** * Utilities / API methods for lightning. */ -@UtilityClass -public class LightningUtils { +public final class LightningUtils { /** * Strike lightning on player without fire. @@ -19,9 +17,9 @@ public class LightningUtils { * @param damage The damage to deal. * @param silent If the lightning sound should be played locally */ - public void strike(@NotNull final LivingEntity victim, - final double damage, - final boolean silent) { + public static void strike(@NotNull final LivingEntity victim, + final double damage, + final boolean silent) { Location loc = victim.getLocation(); if (silent) { @@ -40,8 +38,12 @@ public class LightningUtils { * @param victim The entity to smite. * @param damage The damage to deal. */ - public void strike(@NotNull final LivingEntity victim, - final double damage) { + public static void strike(@NotNull final LivingEntity victim, + final double damage) { strike(victim, damage, false); } + + private LightningUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/ListUtils.java b/eco-api/src/main/java/com/willfp/eco/util/ListUtils.java index 4ab07036..586d5955 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/ListUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/ListUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,8 +11,7 @@ import java.util.Map; /** * Utilities / API methods for lists. */ -@UtilityClass -public class ListUtils { +public final class ListUtils { /** * Initialize 2D list of a given size. * @@ -57,4 +55,8 @@ public class ListUtils { return frequencyMap; } + + private ListUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java b/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java index e50d913e..39857c88 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java @@ -1,14 +1,12 @@ package com.willfp.eco.util; import com.willfp.eco.core.tuples.Pair; -import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; /** * Utilities / API methods for menus. */ -@UtilityClass -public class MenuUtils { +public final class MenuUtils { /** * Convert 0-53 slot to row and column pair. * @@ -16,9 +14,13 @@ public class MenuUtils { * @return The pair of row and columns. */ @NotNull - public Pair convertSlotToRowColumn(final int slot) { + public static Pair convertSlotToRowColumn(final int slot) { int row = Math.floorDiv(slot, 9); int column = slot - row * 9; return new Pair<>(row + 1, column + 1); } + + private MenuUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java b/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java index d23b9fbe..e514b87a 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; @@ -9,8 +8,7 @@ import java.util.Objects; /** * Utilities / API methods for {@link NamespacedKey}s. */ -@UtilityClass -public class NamespacedKeyUtils { +public final class NamespacedKeyUtils { /** * Create a NamespacedKey for eco. * @@ -18,7 +16,7 @@ public class NamespacedKeyUtils { * @return The key. */ @NotNull - public NamespacedKey createEcoKey(@NotNull final String string) { + public static NamespacedKey createEcoKey(@NotNull final String string) { return Objects.requireNonNull(NamespacedKey.fromString("eco:" + string)); } @@ -30,8 +28,12 @@ public class NamespacedKeyUtils { * @return The key. */ @NotNull - public NamespacedKey create(@NotNull final String namespace, - @NotNull final String key) { + public static NamespacedKey create(@NotNull final String namespace, + @NotNull final String key) { return Objects.requireNonNull(NamespacedKey.fromString(namespace + ":" + key)); } + + private NamespacedKeyUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java b/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java index 3634ff09..0b1879b0 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; import java.text.DecimalFormat; @@ -11,8 +10,7 @@ import java.util.concurrent.ThreadLocalRandom; /** * Utilities / API methods for numbers. */ -@UtilityClass -public class NumberUtils { +public final class NumberUtils { /** * Sin lookup table. */ @@ -72,8 +70,8 @@ public class NumberUtils { * @param bias The bias between -1 and 1, where higher values bias input values to lower output values. * @return The biased output. */ - public double bias(final double input, - final double bias) { + public static double bias(final double input, + final double bias) { double k = Math.pow(1 - bias, 3); return (input * k) / (input * k - input + 1); @@ -86,8 +84,8 @@ public class NumberUtils { * @param limit The maximum. * @return The new value. */ - public int equalIfOver(final int toChange, - final int limit) { + public static int equalIfOver(final int toChange, + final int limit) { return Math.min(toChange, limit); } @@ -98,8 +96,8 @@ public class NumberUtils { * @param limit The maximum. * @return The new value. */ - public double equalIfOver(final double toChange, - final double limit) { + public static double equalIfOver(final double toChange, + final double limit) { return Math.min(toChange, limit); } @@ -110,7 +108,7 @@ public class NumberUtils { * @return The number, converted to a roman numeral. */ @NotNull - public String toNumeral(final int number) { + public static String toNumeral(final int number) { if (number >= 1 && number <= 4096) { int l = NUMERALS.floorKey(number); if (number == l) { @@ -147,8 +145,8 @@ public class NumberUtils { * @param max Maximum. * @return Random integer. */ - public int randInt(final int min, - final int max) { + public static int randInt(final int min, + final int max) { return ThreadLocalRandom.current().nextInt(min, max + 1); } @@ -159,8 +157,8 @@ public class NumberUtils { * @param max Maximum. * @return Random double. */ - public double randFloat(final double min, - final double max) { + public static double randFloat(final double min, + final double max) { return ThreadLocalRandom.current().nextDouble(min, max); } @@ -172,9 +170,9 @@ public class NumberUtils { * @param peak Peak. * @return Random double. */ - public double triangularDistribution(final double minimum, - final double maximum, - final double peak) { + public static double triangularDistribution(final double minimum, + final double maximum, + final double peak) { double f = (peak - minimum) / (maximum - minimum); double rand = Math.random(); if (rand < f) { @@ -190,7 +188,7 @@ public class NumberUtils { * @param toLog The number. * @return The result. */ - public int log2(final int toLog) { + public static int log2(final int toLog) { return (int) (Math.log(toLog) / Math.log(2)); } @@ -201,10 +199,14 @@ public class NumberUtils { * @return Formatted. */ @NotNull - public String format(final double toFormat) { + public static String format(final double toFormat) { DecimalFormat df = new DecimalFormat("0.00"); String formatted = df.format(toFormat); return formatted.endsWith("00") ? String.valueOf((int) toFormat) : formatted; } + + private NumberUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java b/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java index aee27f4b..42f8bb21 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java @@ -5,7 +5,6 @@ import com.willfp.eco.core.Prerequisite; import com.willfp.eco.core.data.PlayerProfile; import com.willfp.eco.core.data.keys.PersistentDataKey; import com.willfp.eco.core.data.keys.PersistentDataKeyType; -import lombok.experimental.UtilityClass; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.OfflinePlayer; @@ -16,8 +15,7 @@ import org.jetbrains.annotations.NotNull; /** * Utilities / API methods for players. */ -@UtilityClass -public class PlayerUtils { +public final class PlayerUtils { /** * The data key for saved player names. */ @@ -34,7 +32,7 @@ public class PlayerUtils { * @return The audience. */ @NotNull - public Audience getAudience(@NotNull final Player player) { + public static Audience getAudience(@NotNull final Player player) { BukkitAudiences adventure = Eco.getHandler().getAdventure(); if (Prerequisite.HAS_PAPER.isMet()) { @@ -59,7 +57,7 @@ public class PlayerUtils { * @return The audience. */ @NotNull - public Audience getAudience(@NotNull final CommandSender sender) { + public static Audience getAudience(@NotNull final CommandSender sender) { BukkitAudiences adventure = Eco.getHandler().getAdventure(); if (Prerequisite.HAS_PAPER.isMet()) { @@ -83,7 +81,7 @@ public class PlayerUtils { * @param player The player. * @return The player name. */ - public String getSavedDisplayName(@NotNull final OfflinePlayer player) { + public static String getSavedDisplayName(@NotNull final OfflinePlayer player) { PlayerProfile profile = PlayerProfile.load(player); if (player instanceof Player onlinePlayer) { @@ -108,8 +106,12 @@ public class PlayerUtils { * * @param player The player. */ - public void updateSavedDisplayName(@NotNull final Player player) { + public static void updateSavedDisplayName(@NotNull final Player player) { PlayerProfile profile = PlayerProfile.load(player); profile.write(PLAYER_NAME_KEY, player.getDisplayName()); } + + private PlayerUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/PotionUtils.java b/eco-api/src/main/java/com/willfp/eco/util/PotionUtils.java index 7c144df1..adfd9c10 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/PotionUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/PotionUtils.java @@ -1,21 +1,19 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.potion.PotionData; import org.jetbrains.annotations.NotNull; /** * Utilities / API methods for potions. */ -@UtilityClass -public class PotionUtils { +public final class PotionUtils { /** * Get the duration (in ticks) for potion data. * * @param data The data. * @return The duration. */ - public int getDuration(@NotNull final PotionData data) { + public static int getDuration(@NotNull final PotionData data) { if (data.isExtended()) { return switch (data.getType()) { case INSTANT_DAMAGE, INSTANT_HEAL: yield 0; @@ -44,4 +42,8 @@ public class PotionUtils { default: yield 3600; }; } + + private PotionUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java b/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java index 7414192b..74659ab5 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.apache.commons.lang.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -10,19 +9,18 @@ import java.util.function.Supplier; /** * Utilities / API methods for the server. */ -@UtilityClass -public class ServerUtils { +public final class ServerUtils { /** * The TPS supplier. */ - private Supplier tpsSupplier = null; + private static Supplier tpsSupplier = null; /** * Get the current server TPS. * * @return The TPS. */ - public double getTps() { + public static double getTps() { Validate.notNull(tpsSupplier, "Not initialized!"); double tps = tpsSupplier.get(); @@ -40,9 +38,13 @@ public class ServerUtils { * @param function The function. */ @ApiStatus.Internal - public void initialize(@NotNull final Supplier function) { + public static void initialize(@NotNull final Supplier function) { Validate.isTrue(tpsSupplier == null, "Already initialized!"); tpsSupplier = function; } + + private ServerUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java b/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java index 7d32a8a3..84d08ec7 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.apache.commons.lang.Validate; import org.bukkit.inventory.meta.SkullMeta; import org.jetbrains.annotations.ApiStatus; @@ -13,22 +12,21 @@ import java.util.function.Function; /** * Utilities / API methods for player heads. */ -@UtilityClass -public class SkullUtils { +public final class SkullUtils { /** * If the meta set function has been set. */ - private boolean initialized = false; + private static boolean initialized = false; /** * The meta set function. */ - private BiConsumer metaSetConsumer = null; + private static BiConsumer metaSetConsumer = null; /** * The meta get function. */ - private Function metaGetConsumer = null; + private static Function metaGetConsumer = null; /** * Set the texture of a skull from base64. @@ -36,7 +34,7 @@ public class SkullUtils { * @param meta The meta to modify. * @param base64 The base64 texture. */ - public void setSkullTexture(@NotNull final SkullMeta meta, + public static void setSkullTexture(@NotNull final SkullMeta meta, @NotNull final String base64) { Validate.isTrue(initialized, "Must be initialized!"); Validate.notNull(metaSetConsumer, "Must be initialized!"); @@ -51,7 +49,7 @@ public class SkullUtils { * @return The texture, potentially null. */ @Nullable - public String getSkullTexture(@NotNull final SkullMeta meta) { + public static String getSkullTexture(@NotNull final SkullMeta meta) { Validate.isTrue(initialized, "Must be initialized!"); Validate.notNull(metaGetConsumer, "Must be initialized!"); @@ -65,7 +63,7 @@ public class SkullUtils { * @param function2 Get function. */ @ApiStatus.Internal - public void initialize(@NotNull final BiConsumer function, + public static void initialize(@NotNull final BiConsumer function, @NotNull final Function function2) { Validate.isTrue(!initialized, "Already initialized!"); @@ -73,4 +71,8 @@ public class SkullUtils { metaGetConsumer = function2; initialized = true; } + + private SkullUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java b/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java index a302d3ed..12c4d181 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java @@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.willfp.eco.core.Prerequisite; import com.willfp.eco.core.integrations.placeholder.PlaceholderManager; -import lombok.experimental.UtilityClass; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -16,7 +15,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.Color; +import java.awt.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -25,18 +24,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import static net.md_5.bungee.api.ChatColor.BOLD; -import static net.md_5.bungee.api.ChatColor.COLOR_CHAR; -import static net.md_5.bungee.api.ChatColor.ITALIC; -import static net.md_5.bungee.api.ChatColor.MAGIC; -import static net.md_5.bungee.api.ChatColor.STRIKETHROUGH; -import static net.md_5.bungee.api.ChatColor.UNDERLINE; +import static net.md_5.bungee.api.ChatColor.*; /** * Utilities / API methods for strings. */ -@UtilityClass -public class StringUtils { +public final class StringUtils { /** * Regexes for gradients. */ @@ -93,7 +86,7 @@ public class StringUtils { * @return The message, formatted. */ @NotNull - public List formatList(@NotNull final List list) { + public static List formatList(@NotNull final List list) { return formatList(list, (Player) null); } @@ -107,8 +100,8 @@ public class StringUtils { * @return The message, format. */ @NotNull - public List formatList(@NotNull final List list, - @Nullable final Player player) { + public static List formatList(@NotNull final List list, + @Nullable final Player player) { return formatList(list, player, FormatOption.WITH_PLACEHOLDERS); } @@ -122,8 +115,8 @@ public class StringUtils { * @return The message, formatted. */ @NotNull - public List formatList(@NotNull final List list, - @NotNull final FormatOption option) { + public static List formatList(@NotNull final List list, + @NotNull final FormatOption option) { return formatList(list, null, option); } @@ -138,9 +131,9 @@ public class StringUtils { * @return The message, format. */ @NotNull - public List formatList(@NotNull final List list, - @Nullable final Player player, - @NotNull final FormatOption option) { + public static List formatList(@NotNull final List list, + @Nullable final Player player, + @NotNull final FormatOption option) { List translated = new ArrayList<>(); for (String string : list) { translated.add(format(string, player, option)); @@ -159,7 +152,7 @@ public class StringUtils { * @see StringUtils#format(String, Player) */ @NotNull - public String format(@NotNull final String message) { + public static String format(@NotNull final String message) { return format(message, (Player) null); } @@ -173,8 +166,8 @@ public class StringUtils { * @return The message, formatted. */ @NotNull - public String format(@NotNull final String message, - @Nullable final Player player) { + public static String format(@NotNull final String message, + @Nullable final Player player) { return format(message, player, FormatOption.WITH_PLACEHOLDERS); } @@ -189,8 +182,8 @@ public class StringUtils { * @see StringUtils#format(String, Player) */ @NotNull - public String format(@NotNull final String message, - @NotNull final FormatOption option) { + public static String format(@NotNull final String message, + @NotNull final FormatOption option) { return format(message, null, option); } @@ -204,7 +197,7 @@ public class StringUtils { * @see StringUtils#format(String, Player) */ @NotNull - public Component formatToComponent(@NotNull final String message) { + public static Component formatToComponent(@NotNull final String message) { return formatToComponent(message, (Player) null); } @@ -218,8 +211,8 @@ public class StringUtils { * @return The message, formatted. */ @NotNull - public Component formatToComponent(@NotNull final String message, - @Nullable final Player player) { + public static Component formatToComponent(@NotNull final String message, + @Nullable final Player player) { return formatToComponent(message, player, FormatOption.WITH_PLACEHOLDERS); } @@ -234,8 +227,8 @@ public class StringUtils { * @see StringUtils#format(String, Player) */ @NotNull - public Component formatToComponent(@NotNull final String message, - @NotNull final FormatOption option) { + public static Component formatToComponent(@NotNull final String message, + @NotNull final FormatOption option) { return formatToComponent(message, null, option); } @@ -250,9 +243,9 @@ public class StringUtils { * @return The message, formatted, as a component. */ @NotNull - public Component formatToComponent(@NotNull final String message, - @Nullable final Player player, - @NotNull final FormatOption option) { + public static Component formatToComponent(@NotNull final String message, + @Nullable final Player player, + @NotNull final FormatOption option) { return toComponent(format(message, player, option)); } @@ -267,9 +260,9 @@ public class StringUtils { * @return The message, formatted. */ @NotNull - public String format(@NotNull final String message, - @Nullable final Player player, - @NotNull final FormatOption option) { + public static String format(@NotNull final String message, + @Nullable final Player player, + @NotNull final FormatOption option) { String processedMessage = message; if (option == FormatOption.WITH_PLACEHOLDERS) { processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player); @@ -379,7 +372,7 @@ public class StringUtils { * @return The object stringified. */ @NotNull - public String internalToString(@Nullable final Object object) { + public static String internalToString(@Nullable final Object object) { if (object == null) { return "null"; } @@ -405,8 +398,8 @@ public class StringUtils { * @return The string with the prefix removed. */ @NotNull - public String removePrefix(@NotNull final String string, - @NotNull final String prefix) { + public static String removePrefix(@NotNull final String string, + @NotNull final String prefix) { if (string.startsWith(prefix)) { return string.substring(prefix.length()); } @@ -420,7 +413,7 @@ public class StringUtils { * @return The JSON String. */ @NotNull - public String legacyToJson(@Nullable final String legacy) { + public static String legacyToJson(@Nullable final String legacy) { String processed = legacy; if (legacy == null) { processed = ""; @@ -439,7 +432,7 @@ public class StringUtils { * @return The legacy string. */ @NotNull - public String jsonToLegacy(@NotNull final String json) { + public static String jsonToLegacy(@NotNull final String json) { return LEGACY_COMPONENT_SERIALIZER.serialize( GsonComponentSerializer.gson().deserialize(json) ); @@ -452,7 +445,7 @@ public class StringUtils { * @return The component. */ @NotNull - public Component toComponent(@Nullable final String legacy) { + public static Component toComponent(@Nullable final String legacy) { String processed = legacy; if (legacy == null) { processed = ""; @@ -468,7 +461,7 @@ public class StringUtils { * @return The legacy text. */ @NotNull - public String toLegacy(@NotNull final Component component) { + public static String toLegacy(@NotNull final Component component) { return LEGACY_COMPONENT_SERIALIZER.serialize(component); } @@ -486,4 +479,8 @@ public class StringUtils { */ WITHOUT_PLACEHOLDERS } + + private StringUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java b/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java index 6ba754ab..0500fb34 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java @@ -3,7 +3,6 @@ package com.willfp.eco.util; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.willfp.eco.core.Prerequisite; -import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -18,8 +17,7 @@ import java.util.stream.Collectors; /** * Utilities / API methods for teams. */ -@UtilityClass -public class TeamUtils { +public final class TeamUtils { /** * Ore ChatColors. */ @@ -44,7 +42,7 @@ public class TeamUtils { * @return The team. */ @NotNull - public Team fromChatColor(@NotNull final ChatColor color) { + public static Team fromChatColor(@NotNull final ChatColor color) { if (CHAT_COLOR_TEAMS.containsKey(color)) { return CHAT_COLOR_TEAMS.get(color); } @@ -72,7 +70,7 @@ public class TeamUtils { * @return The team. */ @NotNull - public Team getMaterialColorTeam(@NotNull final Material material) { + public static Team getMaterialColorTeam(@NotNull final Material material) { return fromChatColor(MATERIAL_COLORS.getOrDefault(material, ChatColor.WHITE)); } @@ -102,4 +100,8 @@ public class TeamUtils { MATERIAL_COLORS.put(Material.DEEPSLATE_EMERALD_ORE, ChatColor.GREEN); } } + + private TeamUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/TelekinesisUtils.java b/eco-api/src/main/java/com/willfp/eco/util/TelekinesisUtils.java index e4661bae..ed76f7fa 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/TelekinesisUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/TelekinesisUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -14,7 +13,6 @@ import java.util.function.Function; * Telekinesis means that all drops and xp go straight to a player's inventory * rather than dropping on the ground. */ -@UtilityClass public final class TelekinesisUtils { /** * Set of tests that return if the player is telekinetic. @@ -26,7 +24,7 @@ public final class TelekinesisUtils { * * @param test The test to register, where the boolean output is if the player is telekinetic. */ - public void registerTest(@NotNull final Function test) { + public static void registerTest(@NotNull final Function test) { TESTS.add(test); } @@ -38,7 +36,7 @@ public final class TelekinesisUtils { * @param player The player to test. * @return If the player is telekinetic. */ - public boolean testPlayer(@NotNull final Player player) { + public static boolean testPlayer(@NotNull final Player player) { for (Function test : TESTS) { if (test.apply(player)) { return true; @@ -47,4 +45,8 @@ public final class TelekinesisUtils { return false; } + + private TelekinesisUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/util/VectorUtils.java b/eco-api/src/main/java/com/willfp/eco/util/VectorUtils.java index 0c273edb..19ac3c78 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/VectorUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/VectorUtils.java @@ -1,6 +1,5 @@ package com.willfp.eco.util; -import lombok.experimental.UtilityClass; import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; @@ -13,8 +12,7 @@ import java.util.Map; /** * Utilities / API methods for vectors. */ -@UtilityClass -public class VectorUtils { +public final class VectorUtils { /** * Cached circles to prevent many sqrt calls. */ @@ -26,7 +24,7 @@ public class VectorUtils { * @param vector The vector to check. * @return If the vector is finite. */ - public boolean isFinite(@NotNull final Vector vector) { + public static boolean isFinite(@NotNull final Vector vector) { try { NumberConversions.checkFinite(vector.getX(), "x not finite"); NumberConversions.checkFinite(vector.getY(), "y not finite"); @@ -45,7 +43,7 @@ public class VectorUtils { * @return The vector, simplified. */ @NotNull - public Vector simplifyVector(@NotNull final Vector vec) { + public static Vector simplifyVector(@NotNull final Vector vec) { double x = Math.abs(vec.getX()); double y = Math.abs(vec.getY()); double z = Math.abs(vec.getZ()); @@ -78,7 +76,7 @@ public class VectorUtils { * @return An array of {@link Vector}s. */ @NotNull - public Vector[] getCircle(final int radius) { + public static Vector[] getCircle(final int radius) { Vector[] cached = CIRCLE_CACHE.get(radius); if (cached != null) { return cached; @@ -115,7 +113,7 @@ public class VectorUtils { * @return An array of {@link Vector}s. */ @NotNull - public Vector[] getSquare(final int radius) { + public static Vector[] getSquare(final int radius) { List vectors = new ArrayList<>(); int xoffset = -radius; @@ -140,7 +138,7 @@ public class VectorUtils { * @return An array of {@link Vector}s. */ @NotNull - public Vector[] getCube(final int radius) { + public static Vector[] getCube(final int radius) { List vectors = new ArrayList<>(); for (int y = -radius; y <= radius; y++) { @@ -153,4 +151,8 @@ public class VectorUtils { return vectors.toArray(new Vector[0]); } + + private VectorUtils() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + } }