From 9c0d28e64bb9470bf601c3d1ac4fe4df62b1413a Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 17 Jul 2021 19:24:29 +0200 Subject: [PATCH] Updated to CommonPatterns --- .../slimefun4/api/SlimefunBranch.java | 4 ++-- .../slimefun4/api/items/SlimefunItemStack.java | 4 ++-- .../slimefun4/api/player/PlayerProfile.java | 6 +++--- .../slimefun4/api/player/StatusEffect.java | 6 +++--- .../core/commands/subcommands/BackpackCommand.java | 6 +++--- .../core/commands/subcommands/GiveCommand.java | 4 ++-- .../core/guide/options/ContributorsMenu.java | 4 ++-- .../slimefun4/core/networks/cargo/CargoNet.java | 4 ++-- .../slimefun4/core/services/MetricsService.java | 4 ++-- .../items/androids/ProgrammableAndroid.java | 10 +++++----- .../items/autocrafters/VanillaAutoCrafter.java | 4 ++-- .../items/multiblocks/AbstractCraftingTable.java | 4 ++-- .../thebusybiscuit/slimefun4/utils/ChatUtils.java | 3 ++- .../thebusybiscuit/slimefun4/utils/HeadTexture.java | 3 ++- .../thebusybiscuit/slimefun4/utils/NumberUtils.java | 7 ++++--- .../slimefun4/utils/PatternUtils.java | 13 +------------ .../slimefun4/utils/SlimefunUtils.java | 3 ++- .../slimefun4/utils/tags/TagParser.java | 5 +++-- .../me/mrCookieSlime/Slimefun/api/BlockStorage.java | 6 +++--- .../core/commands/TestBackpackCommand.java | 6 +++--- 20 files changed, 50 insertions(+), 56 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java index f30737353..f755717da 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; import org.apache.commons.lang.Validate; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; +import io.github.bakedlibs.dough.common.CommonPatterns; /** * This enum represents the branch this Slimefun build is on. @@ -50,7 +50,7 @@ public enum SlimefunBranch { this.name = name; this.official = official; - if (!PatternUtils.ASCII.matcher(name).matches()) { + if (!CommonPatterns.ASCII.matcher(name).matches()) { throw new IllegalStateException("The SlimefunBranch enum contains ILLEGAL CHARACTERS. DO NOT TRANSLATE THIS FILE."); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java index 84087c5b5..024972196 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java @@ -23,6 +23,7 @@ import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.items.ItemMetaSnapshot; import io.github.bakedlibs.dough.skins.PlayerHead; import io.github.bakedlibs.dough.skins.PlayerSkin; @@ -31,7 +32,6 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.PrematureCodeException; import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; /** * The {@link SlimefunItemStack} functions as the base for any @@ -297,7 +297,7 @@ public class SlimefunItemStack extends ItemStack { if (texture.startsWith("ey")) { return texture; - } else if (PatternUtils.HEXADECIMAL.matcher(texture).matches()) { + } else if (CommonPatterns.HEXADECIMAL.matcher(texture).matches()) { String value = "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}"; return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8)); } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 1aee22a63..49e374851 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -31,6 +31,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.config.Config; import io.github.thebusybiscuit.slimefun4.api.events.AsyncProfileLoadEvent; import io.github.thebusybiscuit.slimefun4.api.gps.Waypoint; @@ -42,7 +43,6 @@ import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; /** * A class that can store a Player's {@link Research} progress for caching purposes. @@ -439,9 +439,9 @@ public class PlayerProfile { for (String line : item.getItemMeta().getLore()) { if (line.startsWith(ChatColors.color("&7ID: ")) && line.indexOf('#') != -1) { - String[] splitLine = PatternUtils.HASH.split(line); + String[] splitLine = CommonPatterns.HASH.split(line); - if (PatternUtils.NUMERIC.matcher(splitLine[1]).matches()) { + if (CommonPatterns.NUMERIC.matcher(splitLine[1]).matches()) { id = OptionalInt.of(Integer.parseInt(splitLine[1])); uuid = splitLine[0].replace(ChatColors.color("&7ID: "), ""); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java index 1ca43eda7..a66daf5fb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/StatusEffect.java @@ -10,8 +10,8 @@ import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; /** * A very simple API that is meant for adding/getting/clearing custom status effects @@ -97,7 +97,7 @@ public class StatusEffect implements Keyed { Optional optional = PersistentDataAPI.getOptionalString(p, getKey()); if (optional.isPresent()) { - String[] data = PatternUtils.SEMICOLON.split(optional.get()); + String[] data = CommonPatterns.SEMICOLON.split(optional.get()); long timestamp = Long.parseLong(data[1]); if (timestamp == 0 || timestamp >= System.currentTimeMillis()) { @@ -123,7 +123,7 @@ public class StatusEffect implements Keyed { Optional optional = PersistentDataAPI.getOptionalString(p, getKey()); if (optional.isPresent()) { - String[] data = PatternUtils.SEMICOLON.split(optional.get()); + String[] data = CommonPatterns.SEMICOLON.split(optional.get()); return OptionalInt.of(Integer.parseInt(data[0])); } else { return OptionalInt.empty(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java index 25ed2b225..29aaca740 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/BackpackCommand.java @@ -8,13 +8,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.RestoredBackpack; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; /** * This command that allows for backpack retrieval in the event they are lost. @@ -47,7 +47,7 @@ class BackpackCommand extends SubCommand { return; } - if (!PatternUtils.NUMERIC.matcher(args[2]).matches()) { + if (!CommonPatterns.NUMERIC.matcher(args[2]).matches()) { Slimefun.getLocalization().sendMessage(sender, "commands.backpack.invalid-id"); return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index 71b3c9e26..5d56959e8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.common.PlayerList; import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -17,7 +18,6 @@ import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; class GiveCommand extends SubCommand { @@ -83,7 +83,7 @@ class GiveCommand extends SubCommand { int amount = 1; if (args.length == 4) { - if (PatternUtils.NUMERIC.matcher(args[3]).matches()) { + if (CommonPatterns.NUMERIC.matcher(args[3]).matches()) { amount = Integer.parseInt(args[3]); } else { return 0; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/ContributorsMenu.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/ContributorsMenu.java index 41fba995a..951a9e064 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/ContributorsMenu.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/ContributorsMenu.java @@ -12,12 +12,12 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.core.services.github.Contributor; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; @@ -99,7 +99,7 @@ final class ContributorsMenu { String info = entry.getKey(); if (!info.startsWith("&")) { - String[] segments = PatternUtils.COMMA.split(info); + String[] segments = CommonPatterns.COMMA.split(info); info = Slimefun.getLocalization().getMessage(p, "guide.credits.roles." + segments[0]); if (segments.length == 2) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index f1ad41fda..29b87c18b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -16,11 +16,11 @@ import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.api.network.Network; import io.github.thebusybiscuit.slimefun4.api.network.NetworkComponent; import io.github.thebusybiscuit.slimefun4.core.attributes.HologramOwner; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import me.mrCookieSlime.Slimefun.api.BlockStorage; @@ -261,7 +261,7 @@ public class CargoNet extends AbstractItemNetwork implements HologramOwner { if (frequency == null) { return 0; - } else if (!PatternUtils.NUMERIC.matcher(frequency).matches()) { + } else if (!CommonPatterns.NUMERIC.matcher(frequency).matches()) { Slimefun.logger().log(Level.SEVERE, () -> "Failed to parse a Cargo Node Frequency (" + node.getWorld().getName() + " - " + node.getBlockX() + ',' + node.getBlockY() + ',' + node.getBlockZ() + "): " + frequency); return 0; } else { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java index 472292473..eda60a559 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java @@ -15,8 +15,8 @@ import javax.annotation.Nullable; import org.bukkit.plugin.Plugin; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import kong.unirest.GetRequest; import kong.unirest.HttpResponse; @@ -168,7 +168,7 @@ public class MetricsService { * @return if there is an update available. */ public boolean checkForUpdate(@Nullable String currentVersion) { - if (currentVersion == null || !PatternUtils.NUMERIC.matcher(currentVersion).matches()) { + if (currentVersion == null || !CommonPatterns.NUMERIC.matcher(currentVersion).matches()) { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java index 602a570b6..6cbf718df 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java @@ -33,6 +33,7 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.bakedlibs.dough.chat.ChatInput; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.bakedlibs.dough.items.ItemUtils; import io.github.bakedlibs.dough.skins.PlayerHead; @@ -49,7 +50,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.papermc.lib.PaperLib; @@ -255,7 +255,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock, return false; }); - String[] script = PatternUtils.DASH.split(sourceCode); + String[] script = CommonPatterns.DASH.split(sourceCode); for (int i = 1; i < script.length; i++) { int index = i; @@ -499,7 +499,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock, String script = BlockStorage.getLocationInfo(b.getLocation()).getString("script"); // Fixes #2937 if (script != null) { - if (PatternUtils.DASH.split(script).length <= MAX_SCRIPT_LENGTH) { + if (CommonPatterns.DASH.split(script).length <= MAX_SCRIPT_LENGTH) { openScript(pl, b, getScript(b.getLocation())); } else { pl.closeInventory(); @@ -594,7 +594,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock, Validate.notNull(script, "No script given"); Validate.isTrue(script.startsWith(Instruction.START.name() + '-'), "A script must begin with a 'START' token."); Validate.isTrue(script.endsWith('-' + Instruction.REPEAT.name()), "A script must end with a 'REPEAT' token."); - Validate.isTrue(PatternUtils.DASH.split(script).length <= MAX_SCRIPT_LENGTH, "Scripts may not have more than " + MAX_SCRIPT_LENGTH + " segments"); + Validate.isTrue(CommonPatterns.DASH.split(script).length <= MAX_SCRIPT_LENGTH, "Scripts may not have more than " + MAX_SCRIPT_LENGTH + " segments"); BlockStorage.addBlockInfo(l, "script", script); } @@ -694,7 +694,7 @@ public class ProgrammableAndroid extends SlimefunItem implements InventoryBlock, consumeFuel(b, menu); } else { String code = data.getString("script"); - String[] script = PatternUtils.DASH.split(code == null ? DEFAULT_SCRIPT : code); + String[] script = CommonPatterns.DASH.split(code == null ? DEFAULT_SCRIPT : code); String indexData = data.getString("index"); int index = (indexData == null ? 0 : Integer.parseInt(indexData)) + 1; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java index 6e6516bd8..b2272f780 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java @@ -24,6 +24,7 @@ import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -33,7 +34,6 @@ import io.github.thebusybiscuit.slimefun4.core.services.MinecraftRecipeService; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.papermc.lib.PaperLib; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; @@ -67,7 +67,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter { String value = container.get(recipeStorageKey, PersistentDataType.STRING); if (value != null) { - String[] values = PatternUtils.COLON.split(value); + String[] values = CommonPatterns.COLON.split(value); /* * Normally this constructor should not be used. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractCraftingTable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractCraftingTable.java index f074d13f6..4fe693a93 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractCraftingTable.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/AbstractCraftingTable.java @@ -17,6 +17,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.items.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -26,7 +27,6 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; /** @@ -119,7 +119,7 @@ abstract class AbstractCraftingTable extends MultiBlockMachine { for (String line : backpack.getItemMeta().getLore()) { if (line.startsWith(ChatColors.color("&7ID: ")) && line.contains("#")) { String id = line.replace(ChatColors.color("&7ID: "), ""); - String[] idSplit = PatternUtils.HASH.split(id); + String[] idSplit = CommonPatterns.HASH.split(id); PlayerProfile.fromUUID(UUID.fromString(idSplit[0]), profile -> { Optional optional = profile.getBackpack(Integer.parseInt(idSplit[1])); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java index 04592dc7b..e3d7aac4b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import io.github.bakedlibs.dough.chat.ChatInput; import io.github.bakedlibs.dough.common.ChatColors; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; /** @@ -67,7 +68,7 @@ public final class ChatUtils { */ public static @Nonnull String humanize(@Nonnull String string) { StringBuilder builder = new StringBuilder(); - String[] segments = PatternUtils.UNDERSCORE.split(string.toLowerCase(Locale.ROOT)); + String[] segments = CommonPatterns.UNDERSCORE.split(string.toLowerCase(Locale.ROOT)); builder.append(Character.toUpperCase(segments[0].charAt(0))).append(segments[0].substring(1)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java index 4501c982c..a4caf1477 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java @@ -8,6 +8,7 @@ import javax.annotation.Nonnull; import org.apache.commons.lang.Validate; import org.bukkit.inventory.ItemStack; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.skins.PlayerSkin; /** @@ -127,7 +128,7 @@ public enum HeadTexture { HeadTexture(@Nonnull String texture) { Validate.notNull(texture, "Texture cannot be null"); - Validate.isTrue(PatternUtils.HEXADECIMAL.matcher(texture).matches(), "Textures must be in hexadecimal."); + Validate.isTrue(CommonPatterns.HEXADECIMAL.matcher(texture).matches(), "Textures must be in hexadecimal."); this.texture = texture; this.uuid = UUID.nameUUIDFromBytes(texture.getBytes(StandardCharsets.UTF_8)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java index 40478aabe..274361710 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java @@ -14,6 +14,7 @@ import javax.annotation.Nullable; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; /** @@ -196,7 +197,7 @@ public final class NumberUtils { * @return The resulting {@link Integer} */ public static int getInt(@Nonnull String str, int defaultValue) { - if (PatternUtils.NUMERIC.matcher(str).matches()) { + if (CommonPatterns.NUMERIC.matcher(str).matches()) { return Integer.parseInt(str); } else { return defaultValue; @@ -209,7 +210,7 @@ public final class NumberUtils { } String number = roundDecimalNumber(nanoseconds / 1000000.0); - String[] parts = PatternUtils.NUMBER_SEPARATOR.split(number); + String[] parts = CommonPatterns.NUMBER_SEPARATOR.split(number); if (parts.length == 1) { return parts[0] + "ms"; @@ -273,7 +274,7 @@ public final class NumberUtils { javaVer = javaVer.substring(0, javaVer.indexOf('.')); } - if (PatternUtils.NUMERIC.matcher(javaVer).matches()) { + if (CommonPatterns.NUMERIC.matcher(javaVer).matches()) { return Integer.parseInt(javaVer); } else { Slimefun.logger().log(Level.SEVERE, "Error: Cannot identify Java version - {0}", javaVer); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java index 955424037..354aa17f5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/PatternUtils.java @@ -2,7 +2,7 @@ package io.github.thebusybiscuit.slimefun4.utils; import java.util.regex.Pattern; -import net.md_5.bungee.api.ChatColor; +import org.bukkit.ChatColor; /** * This class is created for common-use patterns used in things such as {@link String#split(String)}.
@@ -18,18 +18,7 @@ public final class PatternUtils { private PatternUtils() {} - public static final Pattern COLON = Pattern.compile(":"); - public static final Pattern SEMICOLON = Pattern.compile(";"); - public static final Pattern HASH = Pattern.compile("#"); - public static final Pattern COMMA = Pattern.compile(","); public static final Pattern SLASH_SEPARATOR = Pattern.compile(" / "); - public static final Pattern DASH = Pattern.compile("-"); - public static final Pattern UNDERSCORE = Pattern.compile("_"); - public static final Pattern ASCII = Pattern.compile("[A-Za-z \"_]+"); - public static final Pattern HEXADECIMAL = Pattern.compile("[A-Fa-f0-9]+"); - public static final Pattern NUMERIC = Pattern.compile("[0-9]+"); - - public static final Pattern NUMBER_SEPARATOR = Pattern.compile("[,.]"); public static final Pattern MINECRAFT_MATERIAL = Pattern.compile("minecraft:[a-z_]+"); public static final Pattern MINECRAFT_TAG = Pattern.compile("#minecraft:[a-z_]+"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index d2a213bba..df34c43b2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -25,6 +25,7 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.bakedlibs.dough.items.ItemMetaSnapshot; import io.github.bakedlibs.dough.skins.PlayerHead; import io.github.bakedlibs.dough.skins.PlayerSkin; @@ -222,7 +223,7 @@ public final class SlimefunUtils { String base64 = texture; - if (PatternUtils.HEXADECIMAL.matcher(texture).matches()) { + if (CommonPatterns.HEXADECIMAL.matcher(texture).matches()) { base64 = Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}").getBytes(StandardCharsets.UTF_8)); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java index 66d0207a8..41d951452 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java @@ -28,6 +28,7 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; @@ -145,7 +146,7 @@ public class TagParser implements Keyed { } } else if (PatternUtils.MINECRAFT_TAG.matcher(value).matches()) { // Get the actual Key portion and match it to item and block tags. - String keyValue = PatternUtils.COLON.split(value)[1]; + String keyValue = CommonPatterns.COLON.split(value)[1]; NamespacedKey namespacedKey = NamespacedKey.minecraft(keyValue); Tag itemsTag = Bukkit.getTag(Tag.REGISTRY_ITEMS, namespacedKey, Material.class); Tag blocksTag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, namespacedKey, Material.class); @@ -162,7 +163,7 @@ public class TagParser implements Keyed { } } else if (PatternUtils.SLIMEFUN_TAG.matcher(value).matches()) { // Get a SlimefunTag enum value for the given key - String keyValue = PatternUtils.COLON.split(value)[1].toUpperCase(Locale.ROOT); + String keyValue = CommonPatterns.COLON.split(value)[1].toUpperCase(Locale.ROOT); SlimefunTag tag = SlimefunTag.getTag(keyValue); if (tag != null) { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java index b2f175c4f..6fb2357cf 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -34,10 +34,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.stream.JsonWriter; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; @@ -91,7 +91,7 @@ public class BlockStorage { private static Location deserializeLocation(String l) { try { - String[] components = PatternUtils.SEMICOLON.split(l); + String[] components = CommonPatterns.SEMICOLON.split(l); if (components.length != 4) { return null; } @@ -229,7 +229,7 @@ public class BlockStorage { for (String key : cfg.getKeys(false)) { try { - if (world.getName().equals(PatternUtils.SEMICOLON.split(key)[0])) { + if (world.getName().equals(CommonPatterns.SEMICOLON.split(key)[0])) { BlockInfoConfig data = new BlockInfoConfig(parseJSON(cfg.getString(key))); Slimefun.getRegistry().getChunks().put(key, data); } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/core/commands/TestBackpackCommand.java b/src/test/java/io/github/thebusybiscuit/slimefun4/core/commands/TestBackpackCommand.java index 2a857a0c5..9b876fc82 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/core/commands/TestBackpackCommand.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/core/commands/TestBackpackCommand.java @@ -13,12 +13,12 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.test.TestUtilities; -import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import be.seeseemelk.mockbukkit.MockBukkit; @@ -76,7 +76,7 @@ class TestBackpackCommand { server.execute("slimefun", player, "backpack", player.getName(), id).assertSucceeded(); - if (PatternUtils.NUMERIC.matcher(id).matches()) { + if (CommonPatterns.NUMERIC.matcher(id).matches()) { Assertions.assertFalse(hasBackpack(player, Integer.parseInt(id))); } }