diff --git a/build.gradle.kts b/build.gradle.kts index 4e95df2..64489f6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,8 +33,6 @@ tasks.runServer { tasks.shadowJar { isEnableRelocation = isRelease() relocationPrefix = project.group.toString() - - relocate("net.kyori.adventure", "$relocationPrefix.net.kyori.adventure") } fun isRelease(): Boolean { diff --git a/plugin/core/build.gradle.kts b/plugin/core/build.gradle.kts index 907766f..d38db88 100644 --- a/plugin/core/build.gradle.kts +++ b/plugin/core/build.gradle.kts @@ -5,13 +5,12 @@ plugins { dependencies { compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT") - compileOnly("com.mojang:brigadier:1.0.18") compileOnly("com.comphenix.protocol:ProtocolLib:4.8.0") implementation(project(":plugin:utils")) implementation("io.github.mr-empee:lightwire:0.0.3") - implementation("io.github.mr-empee:colonel:0.0.4") + implementation("io.github.mr-empee.command-forge:bukkit:0.0.1-SNAPSHOT") implementation("io.github.mr-empee:easy-gui:0.0.3") implementation("io.github.mr-empee:item-builder:0.0.2") diff --git a/plugin/core/src/main/java/core/MysticalBarriers.java b/plugin/core/src/main/java/core/MysticalBarriers.java index bf97fc5..fdb1d39 100644 --- a/plugin/core/src/main/java/core/MysticalBarriers.java +++ b/plugin/core/src/main/java/core/MysticalBarriers.java @@ -17,29 +17,29 @@ public class MysticalBarriers extends JavaPlugin { - public static final String COMMAND = "mb"; - private final LightWire iocContainer = LightWire.of(getClass().getPackage()); + private static LightWire IOC; @Override public void onEnable() { EasyGUI.init(this); - iocContainer.addComponent(this); - iocContainer.addComponent(new BukkitSyncedExecutor(this)); - iocContainer.addComponent(new BukkitAsyncExecutor(this)); + IOC = LightWire.of(getClass().getPackage()); + IOC.addComponent(this); + IOC.addComponent(new BukkitSyncedExecutor(this)); + IOC.addComponent(new BukkitAsyncExecutor(this)); - iocContainer.load(); + IOC.load(); } public void reload() { - for (IReloadable reloadable : iocContainer.getInstances(IReloadable.class)) { + for (IReloadable reloadable : IOC.getInstances(IReloadable.class)) { reloadable.reload(); } } @Override public void onDisable() { - for (Closeable closeable : iocContainer.getInstances(Closeable.class)) { + for (Closeable closeable : IOC.getInstances(Closeable.class)) { try { closeable.close(); } catch (Exception e) { @@ -55,4 +55,8 @@ public boolean isDevelop() { return getDescription().getVersion().endsWith("-SNAPSHOT"); } + public static T getInstance(Class clazz) { + return IOC.getInstances(clazz).get(0); + } + } diff --git a/plugin/core/src/main/java/core/configs/client/resources/PluginConfig.java b/plugin/core/src/main/java/core/configs/client/resources/PluginConfig.java index 907a0f4..4b66d0b 100644 --- a/plugin/core/src/main/java/core/configs/client/resources/PluginConfig.java +++ b/plugin/core/src/main/java/core/configs/client/resources/PluginConfig.java @@ -18,11 +18,28 @@ public class PluginConfig extends ResourceConfig { public PluginConfig(MysticalBarriers plugin) { - super(plugin, "configs/config.yml", plugin.isDevelop(), List.of()); + super(plugin, "configs/config.yml", plugin.isDevelop(), List.of( + fromV2ToV3() + )); Messenger.setPrefix(getPrefix()); } + private static Migrator fromV2ToV3() { + return (currentVersion, config) -> { + if (currentVersion > 2) { + return currentVersion; + } + + String prefix = config.getString("messages.prefix"); + Component prefixComponent = LegacyComponentSerializer.legacy('&').deserialize(prefix); + + config.set("messages.prefix", MiniMessage.miniMessage().serialize(prefixComponent)); + + return 3; + }; + } + public boolean blockChorusTp() { return getConfig().getBoolean("block-chorus-teleportation"); } diff --git a/plugin/core/src/main/java/core/configs/server/CommandsConfig.java b/plugin/core/src/main/java/core/configs/server/CommandsConfig.java index d0e7d58..d8f297f 100644 --- a/plugin/core/src/main/java/core/configs/server/CommandsConfig.java +++ b/plugin/core/src/main/java/core/configs/server/CommandsConfig.java @@ -1,51 +1,82 @@ package core.configs.server; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.empee.colonel.BrigadierCommand; -import io.github.empee.colonel.BrigadierManager; +import com.github.empee.commands.CommandContext; +import com.github.empee.commands.CommandManager; +import com.github.empee.commands.CommandNode; +import com.github.empee.commands.exceptions.ArgumentException; +import com.github.empee.commands.exceptions.CommandException; +import com.github.empee.commands.spigot.BukkitInjector; +import core.configs.client.resources.MessagesConfig; +import core.controllers.commands.ICommand; import io.github.empee.lightwire.annotations.LightWired; -import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; -import core.configs.client.resources.MessagesConfig; -import core.exceptions.PluginException; import utils.Messenger; import java.util.List; +import java.util.Map; +import java.util.logging.Logger; @LightWired -public class CommandsConfig extends BrigadierManager { - private final MessagesConfig messages; - - public CommandsConfig( - JavaPlugin plugin, MessagesConfig messages, - List> commands - ) { - super(plugin, new CommandDispatcher<>()); - - this.messages = messages; - commands.forEach(c -> { - var registeredLabel = register(c.get()); - Messenger.log("The command '{}' has been registered", registeredLabel); - }); +public class CommandsConfig { + + CommandManager commandManager = new CommandManager<>(CommandSender.class); + + private final JavaPlugin plugin; + private final MessagesConfig messagesConfig; + private final List commands; + + public CommandsConfig(JavaPlugin plugin, MessagesConfig messagesConfig, List commands) { + this.messagesConfig = messagesConfig; + this.plugin = plugin; + this.commands = commands; + + registerExceptionHandler(); + registerCommands(); } - @Override - @SneakyThrows - protected void handleException(CommandSender source, Exception e) { - if (e instanceof PluginException) { - Messenger.log(source, messages.get(((PluginException) e).getId(), ((PluginException) e).getArguments())); - } else if (e instanceof CommandSyntaxException) { - Messenger.log(source, e.getMessage()); - } else { - Messenger.log(source, messages.get("errors.internal_error")); - Messenger.log("Error while executing command", e); + private void registerCommands() { + BukkitInjector injector = new BukkitInjector(plugin, commandManager); + + for (ICommand command : commands) { + CommandNode cmd = command.get(); + + commandManager.register(cmd); + injector.inject(command.get()); + } + } + + private void registerExceptionHandler() { + commandManager.setExceptionHandler(this::handleCommandException); + } + + public void handleCommandException(CommandContext context, CommandException exception) { + if (exception.getType() == CommandException.Type.ARG_PARSING_ERROR) { + handleCommandArgumentException(context, (ArgumentException) exception); + return; } + + if (exception.getType() == CommandException.Type.EXECUTION_ERROR) { + Messenger.error("Error while executing command '/{}'", exception.getCause(), context.getReader().getText()); + } + + Messenger.log(context.getSource(), messagesConfig.get("commands.errors." + exception.getType())); } - @Override - protected CommandSender getSource(CommandSender source) { - return source; + private void handleCommandArgumentException(CommandContext context, ArgumentException exception) { + String message; + + if (exception.getCauseID() == null) { + message = messagesConfig.get("commands.errors.arg_parsing_error.unk"); + Messenger.error("Error while parsing argument '{}' of command '/{}'", exception.getCause(), exception.getInput(), context.getReader().getText()); + } else { + var placeholders = Map.of("input", (Object) exception.getInput()); + message = messagesConfig.get("commands.errors.arg_parsing_error." + exception.getCauseID(), placeholders); + } + + Messenger.log(context.getSource(), message); } + } diff --git a/plugin/core/src/main/java/core/controllers/commands/BarriersCommand.java b/plugin/core/src/main/java/core/controllers/commands/BarriersCommand.java index 94c98e3..acf2fda 100644 --- a/plugin/core/src/main/java/core/controllers/commands/BarriersCommand.java +++ b/plugin/core/src/main/java/core/controllers/commands/BarriersCommand.java @@ -1,68 +1,72 @@ package core.controllers.commands; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import core.controllers.commands.arguments.BarrierArgumentType; -import core.controllers.guis.BarrierEditGUI; -import io.github.empee.colonel.BrigadierCommand; -import io.github.empee.lightwire.annotations.LightWired; -import lombok.RequiredArgsConstructor; -import org.bukkit.command.CommandSender; +import com.github.empee.commands.CommandNode; +import com.github.empee.commands.arguments.StringArgument; import core.MysticalBarriers; +import core.controllers.commands.arguments.BarrierArgument; +import core.controllers.guis.BarrierEditGUI; import core.controllers.guis.BarrierListGUI; import core.controllers.guis.PluginGUI; -import core.model.Barrier; -import core.registries.Permissions; import core.items.RegionSelectorWand; +import core.registries.Permissions; import core.services.BarriersService; +import io.github.empee.lightwire.annotations.LightWired; +import lombok.RequiredArgsConstructor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import utils.Messenger; @LightWired @RequiredArgsConstructor -public class BarriersCommand extends BrigadierCommand { +public class BarriersCommand implements ICommand { private final MysticalBarriers plugin; private final RegionSelectorWand selectionWand; private final BarriersService barriersService; - @Override - public LiteralArgumentBuilder get() { - return literal(MysticalBarriers.COMMAND) - .requires(s -> s.hasPermission(Permissions.ADMIN)) - .then(wand()) - .then(create()) - .then(modify()) - .then(list()) - .then(reload()); + public CommandNode get() { + return CommandNode.of("mysticalbarriers", CommandSender.class) + .withPermission(s -> s.hasPermission(Permissions.ADMIN)) + .withAliases("mb") + .withChild(wand()) + .withChild(create()) + .withChild(modify()) + .withChild(list()) + .withChild(reload()); } - public ArgumentBuilder wand() { - return node(literal("wand")) - .executes(c -> { - var player = player(c); + public CommandNode wand() { + return CommandNode.of("wand", Player.class) + .withExecutor(c -> { + Player player = c.getSource(); + player.getInventory().addItem(selectionWand.get()); Messenger.log(player, "&aSelection wand given"); - }).build(); + }); } - public ArgumentBuilder modify() { - return node(literal("edit"), arg("barrier", BarrierArgumentType.barrier(barriersService))) - .executes(c -> PluginGUI.get(BarrierEditGUI.class).open(player(c), c.getArgument("barrier", Barrier.class))) - .build(); + public CommandNode modify() { + return CommandNode.of("edit", Player.class) + .withArgs(BarrierArgument.of("barrier")) + .withExecutor(c -> { + PluginGUI.get(BarrierEditGUI.class).open(c.getSource(), c.get("barrier")); + }); } - public ArgumentBuilder list() { - return node(literal("list")) - .executes(c -> PluginGUI.get(BarrierListGUI.class).open(player(c))) - .build(); + public CommandNode list() { + return CommandNode.of("list", Player.class) + .withExecutor(c -> { + PluginGUI.get(BarrierListGUI.class).open(c.getSource()); + }); } - public ArgumentBuilder create() { - return node(literal("create"), arg("id", StringArgumentType.string())) - .executes(c -> { - var player = player(c); - var id = c.getArgument("id", String.class); + public CommandNode create() { + return CommandNode.of("create", Player.class) + .withArgs(StringArgument.of("id")) + .withExecutor(c -> { + Player player = c.getSource(); + String id = c.get("id"); + if (barriersService.findById(id).isPresent()) { Messenger.log(player, "&cA barrier with that id already exists"); return; @@ -78,13 +82,16 @@ public LiteralArgumentBuilder get() { selectionWand.invalidate(player.getUniqueId()); Messenger.log(player, "&aBarrier created"); - }).build(); + }); } - public ArgumentBuilder reload() { - return node(literal("reload")) - .executes(c -> plugin.reload()) - .build(); + public CommandNode reload() { + return CommandNode.of("reload", CommandSender.class) + .withExecutor(c -> { + plugin.reload(); + + Messenger.log(c.getSource(), "&aThe plugin has been reloaded"); + }); } } diff --git a/plugin/core/src/main/java/core/controllers/commands/ICommand.java b/plugin/core/src/main/java/core/controllers/commands/ICommand.java new file mode 100644 index 0000000..0524d81 --- /dev/null +++ b/plugin/core/src/main/java/core/controllers/commands/ICommand.java @@ -0,0 +1,10 @@ +package core.controllers.commands; + +import com.github.empee.commands.CommandNode; +import org.bukkit.command.CommandSender; + +public interface ICommand { + + CommandNode get(); + +} diff --git a/plugin/core/src/main/java/core/controllers/commands/arguments/BarrierArgument.java b/plugin/core/src/main/java/core/controllers/commands/arguments/BarrierArgument.java new file mode 100644 index 0000000..8971ae7 --- /dev/null +++ b/plugin/core/src/main/java/core/controllers/commands/arguments/BarrierArgument.java @@ -0,0 +1,60 @@ +package core.controllers.commands.arguments; + +import com.github.empee.commands.CommandContext; +import com.github.empee.commands.arguments.Argument; +import com.github.empee.commands.exceptions.ArgumentException; +import com.github.empee.commands.suggestions.CommandSuggestion; +import core.MysticalBarriers; +import core.model.Barrier; +import core.services.BarriersService; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Getter +@RequiredArgsConstructor(staticName = "of") +public class BarrierArgument implements Argument { + + public static final String ERROR_NOT_FOUND = "barrier_not_found"; + + private final String id; + private final BarriersService barriersService = MysticalBarriers.getInstance(BarriersService.class); + + private Function, ?> executor; + private final Function, List> suggestions = suggestionProvider(); + + private @NotNull Function, List> suggestionProvider() { + return ctx -> barriersService.findAll().stream() + .map(b -> CommandSuggestion.of(b.getId(), null)) + .collect(Collectors.toList()); + } + + public String getParser() { + return "brigadier:string"; + } + + @Override + public @NotNull Barrier parse(CommandContext context, String input) { + return barriersService.findById(input).orElseThrow( + () -> ArgumentException.parsing(this, input, ERROR_NOT_FOUND) + ); + } + + public BarrierArgument withExecutor(Function, ?> executor) { + this.executor = executor; + return this; + } + + public BarrierArgument withExecutor(Consumer> executor) { + return withExecutor((ctx) -> { + executor.accept(ctx); + return null; + }); + } + +} diff --git a/plugin/core/src/main/java/core/controllers/commands/arguments/BarrierArgumentType.java b/plugin/core/src/main/java/core/controllers/commands/arguments/BarrierArgumentType.java deleted file mode 100644 index 5c0a6e4..0000000 --- a/plugin/core/src/main/java/core/controllers/commands/arguments/BarrierArgumentType.java +++ /dev/null @@ -1,41 +0,0 @@ -package core.controllers.commands.arguments; - -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import core.exceptions.PluginException; -import core.model.Barrier; -import core.services.BarriersService; -import io.github.empee.colonel.arguments.CustomArgumentType; -import lombok.RequiredArgsConstructor; - -import java.util.concurrent.CompletableFuture; - -@RequiredArgsConstructor(staticName = "barrier") -public class BarrierArgumentType implements CustomArgumentType { - - private final BarriersService barriersService; - - public Barrier parse(StringReader reader) throws CommandSyntaxException { - return barriersService.findById(reader.readString()).orElseThrow( - () -> PluginException.of("barrier_not_found") - ); - } - - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - barriersService.findAll().forEach( - b -> builder.suggest(b.getId()) - ); - - return builder.buildFuture(); - } - - @Override - public ArgumentType getNmsType() { - return StringArgumentType.string(); - } -} diff --git a/plugin/core/src/main/java/core/handlers/BarrierSpawningHandler.java b/plugin/core/src/main/java/core/handlers/BarrierSpawningHandler.java index 66354d7..4070d57 100644 --- a/plugin/core/src/main/java/core/handlers/BarrierSpawningHandler.java +++ b/plugin/core/src/main/java/core/handlers/BarrierSpawningHandler.java @@ -13,6 +13,7 @@ import core.model.Barrier; import core.packets.MultiBlockPacket; import core.services.BarriersService; +import utils.LocationUtils; import utils.regions.CubicRegion; import java.util.HashMap; @@ -28,11 +29,11 @@ public class BarrierSpawningHandler implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - if(event.getFrom().toBlockLocation().toVector().equals(event.getTo().toBlockLocation().toVector())) { + if(event.getFrom().toVector().equals(event.getTo().toVector())) { return; } - refreshBarriers(event.getTo().toBlockLocation(), event.getPlayer()); + refreshBarriers(LocationUtils.toBlockLocation(event.getTo()), event.getPlayer()); } @EventHandler diff --git a/plugin/core/src/main/java/core/items/RegionSelectorWand.java b/plugin/core/src/main/java/core/items/RegionSelectorWand.java index 45ec3b1..6cbf1c0 100644 --- a/plugin/core/src/main/java/core/items/RegionSelectorWand.java +++ b/plugin/core/src/main/java/core/items/RegionSelectorWand.java @@ -15,6 +15,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import utils.LocationUtils; import utils.Messenger; import utils.TextUtils; import utils.regions.CubicRegion; @@ -65,7 +66,7 @@ public void onClick(PlayerInteractEvent event) { return; } - var location = event.getClickedBlock().getLocation().toBlockLocation(); + var location = LocationUtils.toBlockLocation(event.getClickedBlock().getLocation()); select(player, location); Messenger.log(player, "&aSelected point at &e{} {} {}", location.getX(), location.getY(), location.getZ()); diff --git a/plugin/core/src/main/resources/configs/config.yml b/plugin/core/src/main/resources/configs/config.yml index 2007004..daaf387 100644 --- a/plugin/core/src/main/resources/configs/config.yml +++ b/plugin/core/src/main/resources/configs/config.yml @@ -3,7 +3,7 @@ version: 2 lang: "en" messages: - prefix: "&f&l(&6&l!&f&l) &r " + prefix: "&f&l(&6&l!&f&l) &r" # Prevent chorus fruit teleportation within 8 blocks of a barrier block-chorus-teleportation: true diff --git a/plugin/core/src/main/resources/messages/generic.yml b/plugin/core/src/main/resources/messages/generic.yml index dc4ef25..93c3f0d 100644 --- a/plugin/core/src/main/resources/messages/generic.yml +++ b/plugin/core/src/main/resources/messages/generic.yml @@ -1,5 +1,21 @@ -version: 2 +version: 3 -errors: - internal_error: "&cAn internal error occurred (╯°□°)╯︵ ┻━┻" - barrier_not_found: "&cBarrier not found" \ No newline at end of file +commands: + errors: + execution_error: "&cUnkown error while executing the command" + command_unk: "&cUnknown command" + illegal_sender: "&cSender type not allowed" + missing_permission: "&cNot enough permission" + not_executable: "&cNot a full command" + syntax_error: "&cUnable to parse the command" + arg_not_found: "&cThe command is missing an argument" + arg_parsing_error: + unk: "&cUnknown error while parsing argument" + uuid_syntax_error: "&cThe uuid '&e{input}&c' isn't valid" + player_not_online: "&cThe player '&e{input}&c' isn't online" + int_not_valid: "&cThe value '&e{input}&c' isn't an integer" + double_not_valid: "&cThe value '&e{input}&c' isn't a double" + number_too_high: "&cThe number '&e{input}&c' is too high" + number_too_low: "&cThe number '&e{input}&c' is too low" + enum_not_found: "&cThe value '&e{input}&c' isn't valid" + barrier_not_found: "&cThe barrier '&e{input}&c' doesn't exists" diff --git a/plugin/utils/build.gradle.kts b/plugin/utils/build.gradle.kts index 57bf160..b271112 100644 --- a/plugin/utils/build.gradle.kts +++ b/plugin/utils/build.gradle.kts @@ -7,10 +7,6 @@ dependencies { compileOnly("org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT") compileOnly("org.slf4j:slf4j-api:2.0.12") - implementation("net.kyori:adventure-platform-bukkit:4.3.3") - implementation("net.kyori:adventure-text-minimessage:4.17.0") - implementation("net.kyori:adventure-text-serializer-legacy:4.17.0") - api("net.kyori:adventure-platform-bukkit:4.3.3") api("net.kyori:adventure-text-minimessage:4.17.0") api("net.kyori:adventure-text-serializer-legacy:4.17.0") diff --git a/plugin/utils/src/main/java/utils/LocationUtils.java b/plugin/utils/src/main/java/utils/LocationUtils.java new file mode 100644 index 0000000..0329b67 --- /dev/null +++ b/plugin/utils/src/main/java/utils/LocationUtils.java @@ -0,0 +1,17 @@ +package utils; + +import lombok.experimental.UtilityClass; +import org.bukkit.Location; + +@UtilityClass +public class LocationUtils { + + public Location toBlockLocation(Location location) { + Location blockLoc = location.clone(); + blockLoc.setX(blockLoc.getBlockX()); + blockLoc.setY(blockLoc.getBlockY()); + blockLoc.setZ(blockLoc.getBlockZ()); + return blockLoc; + } + +} diff --git a/plugin/utils/src/main/java/utils/Messenger.java b/plugin/utils/src/main/java/utils/Messenger.java index f18b5cb..4bc1bc7 100644 --- a/plugin/utils/src/main/java/utils/Messenger.java +++ b/plugin/utils/src/main/java/utils/Messenger.java @@ -19,8 +19,6 @@ public class Messenger { private final JavaPlugin plugin = JavaPlugin.getProvidingPlugin(Messenger.class); private final Logger consoleLogger = LoggerFactory.getLogger(plugin.getName()); - private final BukkitAudiences audience = BukkitAudiences.create(plugin); - @Getter @Setter private String prefix = ""; @@ -31,7 +29,7 @@ public void log(CommandSender sender, String msg, Object... obj) { msg = msg.replaceFirst("\\{}", o.toString()); } - audience.sender(sender).sendMessage(TextUtils.toComponent(msg)); + sender.sendMessage(TextUtils.colorize(msg)); } public void log(String msg, Object... obj) { diff --git a/plugin/utils/src/main/java/utils/TextUtils.java b/plugin/utils/src/main/java/utils/TextUtils.java index c63fb2d..b784569 100644 --- a/plugin/utils/src/main/java/utils/TextUtils.java +++ b/plugin/utils/src/main/java/utils/TextUtils.java @@ -4,6 +4,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.md_5.bungee.api.ChatColor; import java.util.Collections; import java.util.Map; @@ -15,18 +16,8 @@ @UtilityClass public class TextUtils { - private final LegacyComponentSerializer legacySerializer = LegacyComponentSerializer.legacy('&'); - private final MiniMessage miniMessage = MiniMessage.miniMessage(); - public String colorize(String text) { - return legacySerializer.serialize(toComponent(text)); - } - - public Component toComponent(String input) { - Component component = legacySerializer.deserialize(input); - input = miniMessage.serialize(component); - - return miniMessage.deserialize(input); + return ChatColor.translateAlternateColorCodes('&', text); } public String[] formatted(String text) { @@ -39,37 +30,9 @@ public String[] formatted(String text, Map placeholders) { } text = colorize(text); - if (text.endsWith("\n")) { - text += " "; - } - text = text.replace("\t", " "); return text.split("\n"); } - public String[] centered(String text) { - if (!text.startsWith("\n")) { - text = "\n" + text; - } - - if (!text.endsWith("\n")) { - text += "\n"; - } - - return formatted(text); - } - - public String[] centered(String text, Map placeholders) { - if (!text.startsWith("\n")) { - text = "\n" + text; - } - - if (!text.endsWith("\n")) { - text += "\n"; - } - - return formatted(text, placeholders); - } - } diff --git a/settings.gradle.kts b/settings.gradle.kts index 30cdeef..bcd2f38 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,6 +9,7 @@ dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { + mavenLocal() mavenCentral() maven("https://repo.dmulloy2.net/repository/public/")