diff --git a/build.gradle b/build.gradle index 0311973..9918f29 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,11 @@ repositories { maven { url = uri('https://repo.maven.apache.org/maven2/') } + + maven { + name = "sonatype-oss-snapshots" + url = uri("https://oss.sonatype.org/content/repositories/snapshots/") + } mavenCentral() } @@ -33,6 +38,10 @@ dependencies { compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT' implementation 'org.bstats:bstats-base:3.0.0' implementation 'org.bstats:bstats-bukkit:3.0.0' + implementation("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT") { + exclude group: "net.kyori", module: "adventure-api" + exclude group: "org.jetbrains", module: "annotations" + } } group = 'dev.plex' diff --git a/src/main/java/dev/plex/command/PlexCommand.java b/src/main/java/dev/plex/command/PlexCommand.java index 2dbaac1..795f664 100644 --- a/src/main/java/dev/plex/command/PlexCommand.java +++ b/src/main/java/dev/plex/command/PlexCommand.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.UUID; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -108,7 +109,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player) { - sender.sendMessage(tl("noPermissionInGame")); + sender.sendMessage(messageComponent("noPermissionInGame")); return true; } @@ -116,7 +117,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { if (sender instanceof ConsoleCommandSender) { - send(sender, tl("noPermissionConsole")); + send(sender, messageComponent("noPermissionConsole")); return true; } } @@ -129,7 +130,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { if (!plexPlayer.getRankFromString().isAtLeast(getLevel())) { - send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage()))); + send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage()))); return true; } } @@ -137,7 +138,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { if (!player.hasPermission(perms.permission())) { - send(sender, tl("noPermissionNode", perms.permission())); + send(sender, messageComponent("noPermissionNode", perms.permission())); return true; } } @@ -160,7 +161,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC | ConsoleOnlyException | ConsoleMustDefinePlayerException | PlayerNotBannedException ex) { - send(sender, ex.getMessage()); + send(sender, MiniMessage.miniMessage().deserialize(ex.getMessage())); } return true; } @@ -262,14 +263,14 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC { if (!plexPlayer.getRankFromString().isAtLeast(rank)) { - throw new CommandFailException(PlexUtils.tl("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage()))); + throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage()))); } } else if (plugin.getSystem().equalsIgnoreCase("permissions")) { if (!player.hasPermission(permission)) { - throw new CommandFailException(PlexUtils.tl("noPermissionNode", permission)); + throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission)); } } return true; @@ -419,9 +420,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC * @param objects Any objects to replace in order * @return A kyori component */ - protected Component tl(String s, Object... objects) + protected Component messageComponent(String s, Object... objects) { - return componentFromString(PlexUtils.tl(s, objects)); + return PlexUtils.messageComponent(s, objects); } /** @@ -482,7 +483,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC World world = Bukkit.getWorld(name); if (world == null) { - throw new CommandFailException(PlexUtils.tl("worldNotFound")); + throw new CommandFailException(PlexUtils.messageString("worldNotFound")); } return world; } diff --git a/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java b/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java index 00ffc15..32ca55a 100644 --- a/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java +++ b/src/main/java/dev/plex/command/exception/ConsoleMustDefinePlayerException.java @@ -1,11 +1,11 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.tl; +import static dev.plex.util.PlexUtils.messageString; public class ConsoleMustDefinePlayerException extends RuntimeException { public ConsoleMustDefinePlayerException() { - super(tl("consoleMustDefinePlayer")); + super(messageString("consoleMustDefinePlayer")); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java b/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java index 0cf2a73..09a5439 100644 --- a/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java +++ b/src/main/java/dev/plex/command/exception/ConsoleOnlyException.java @@ -1,11 +1,11 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.tl; +import static dev.plex.util.PlexUtils.messageString; public class ConsoleOnlyException extends RuntimeException { public ConsoleOnlyException() { - super(tl("consoleOnly")); + super(messageString("consoleOnly")); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java b/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java index d8af974..0558baa 100644 --- a/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java +++ b/src/main/java/dev/plex/command/exception/PlayerNotBannedException.java @@ -1,11 +1,11 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.tl; +import static dev.plex.util.PlexUtils.messageString; public class PlayerNotBannedException extends RuntimeException { public PlayerNotBannedException() { - super(tl("playerNotBanned")); + super(messageString("playerNotBanned")); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java b/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java index 17e8a6c..efb8f91 100644 --- a/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java +++ b/src/main/java/dev/plex/command/exception/PlayerNotFoundException.java @@ -1,11 +1,11 @@ package dev.plex.command.exception; -import static dev.plex.util.PlexUtils.tl; +import static dev.plex.util.PlexUtils.messageString; public class PlayerNotFoundException extends RuntimeException { public PlayerNotFoundException() { - super(tl("playerNotFound")); + super(messageString("playerNotFound")); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/AdminCMD.java b/src/main/java/dev/plex/command/impl/AdminCMD.java index a202225..60c3c33 100644 --- a/src/main/java/dev/plex/command/impl/AdminCMD.java +++ b/src/main/java/dev/plex/command/impl/AdminCMD.java @@ -61,7 +61,7 @@ public class AdminCMD extends PlexCommand if (isAdmin(plexPlayer)) { - return tl("playerIsAdmin"); + return messageComponent("playerIsAdmin"); } Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer)); @@ -89,7 +89,7 @@ public class AdminCMD extends PlexCommand if (!isAdmin(plexPlayer)) { - return tl("playerNotAdmin"); + return messageComponent("playerNotAdmin"); } Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer)); @@ -117,21 +117,21 @@ public class AdminCMD extends PlexCommand if (!rankExists(args[2])) { - return tl("rankNotFound"); + return messageComponent("rankNotFound"); } Rank rank = Rank.valueOf(args[2].toUpperCase()); if (!rank.isAtLeast(Rank.ADMIN)) { - return tl("rankMustBeHigherThanAdmin"); + return messageComponent("rankMustBeHigherThanAdmin"); } PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); if (!isAdmin(plexPlayer)) { - return tl("playerNotAdmin"); + return messageComponent("playerNotAdmin"); } Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank)); diff --git a/src/main/java/dev/plex/command/impl/AdminworldCMD.java b/src/main/java/dev/plex/command/impl/AdminworldCMD.java index 279e6ee..df1d004 100644 --- a/src/main/java/dev/plex/command/impl/AdminworldCMD.java +++ b/src/main/java/dev/plex/command/impl/AdminworldCMD.java @@ -25,7 +25,7 @@ public class AdminworldCMD extends PlexCommand { Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0); playerSender.teleportAsync(loc); - return tl("teleportedToWorld", "adminworld"); + return messageComponent("teleportedToWorld", "adminworld"); } return null; } diff --git a/src/main/java/dev/plex/command/impl/AdventureCMD.java b/src/main/java/dev/plex/command/impl/AdventureCMD.java index 9ac616a..92e2dd4 100644 --- a/src/main/java/dev/plex/command/impl/AdventureCMD.java +++ b/src/main/java/dev/plex/command/impl/AdventureCMD.java @@ -29,7 +29,7 @@ public class AdventureCMD extends PlexCommand { if (isConsole(sender)) { - throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer")); + throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); } Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE)); return null; @@ -42,9 +42,9 @@ public class AdventureCMD extends PlexCommand for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) { targetPlayer.setGameMode(GameMode.ADVENTURE); - tl("gameModeSetTo", "adventure"); + messageComponent("gameModeSetTo", "adventure"); } - PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "adventure")); + PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "adventure")); return null; } diff --git a/src/main/java/dev/plex/command/impl/BanCMD.java b/src/main/java/dev/plex/command/impl/BanCMD.java index be0f8ac..9b217b2 100644 --- a/src/main/java/dev/plex/command/impl/BanCMD.java +++ b/src/main/java/dev/plex/command/impl/BanCMD.java @@ -56,7 +56,7 @@ public class BanCMD extends PlexCommand PlexPlayer plexPlayer1 = getPlexPlayer(playerSender); if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString())) { - return tl("higherRankThanYou"); + return messageComponent("higherRankThanYou"); } } } @@ -79,7 +79,7 @@ public class BanCMD extends PlexCommand punishment.setCustomTime(false); punishment.setActive(true); plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment); - PlexUtils.broadcast(tl("banningPlayer", sender.getName(), plexPlayer.getName())); + PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName())); if (player != null) { player.kick(componentFromString("&cYou've been banned.")); diff --git a/src/main/java/dev/plex/command/impl/CreativeCMD.java b/src/main/java/dev/plex/command/impl/CreativeCMD.java index 0a19010..3f2c819 100644 --- a/src/main/java/dev/plex/command/impl/CreativeCMD.java +++ b/src/main/java/dev/plex/command/impl/CreativeCMD.java @@ -29,7 +29,7 @@ public class CreativeCMD extends PlexCommand { if (isConsole(sender)) { - throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer")); + throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); } if (!(playerSender == null)) { @@ -45,9 +45,9 @@ public class CreativeCMD extends PlexCommand for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) { targetPlayer.setGameMode(GameMode.CREATIVE); - tl("gameModeSetTo", "creative"); + messageComponent("gameModeSetTo", "creative"); } - PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "creative")); + PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "creative")); return null; } diff --git a/src/main/java/dev/plex/command/impl/DeopAllCMD.java b/src/main/java/dev/plex/command/impl/DeopAllCMD.java index 7b49879..62e5a6e 100644 --- a/src/main/java/dev/plex/command/impl/DeopAllCMD.java +++ b/src/main/java/dev/plex/command/impl/DeopAllCMD.java @@ -23,7 +23,7 @@ public class DeopAllCMD extends PlexCommand { player.setOp(false); } - PlexUtils.broadcast(tl("deoppedAllPlayers", sender.getName())); + PlexUtils.broadcast(messageComponent("deoppedAllPlayers", sender.getName())); return null; } diff --git a/src/main/java/dev/plex/command/impl/DeopCMD.java b/src/main/java/dev/plex/command/impl/DeopCMD.java index 0e2e822..58f5224 100644 --- a/src/main/java/dev/plex/command/impl/DeopCMD.java +++ b/src/main/java/dev/plex/command/impl/DeopCMD.java @@ -26,7 +26,7 @@ public class DeopCMD extends PlexCommand } Player player = getNonNullPlayer(args[0]); player.setOp(false); - PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName())); + PlexUtils.broadcast(messageComponent("oppedPlayer", sender.getName(), player.getName())); return null; } diff --git a/src/main/java/dev/plex/command/impl/FlatlandsCMD.java b/src/main/java/dev/plex/command/impl/FlatlandsCMD.java index bca1204..e80a734 100644 --- a/src/main/java/dev/plex/command/impl/FlatlandsCMD.java +++ b/src/main/java/dev/plex/command/impl/FlatlandsCMD.java @@ -25,7 +25,7 @@ public class FlatlandsCMD extends PlexCommand { Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0); playerSender.teleportAsync(loc); - return tl("teleportedToWorld", "flatlands"); + return messageComponent("teleportedToWorld", "flatlands"); } return null; } diff --git a/src/main/java/dev/plex/command/impl/FreezeCMD.java b/src/main/java/dev/plex/command/impl/FreezeCMD.java index 0bf06f2..dc9e119 100644 --- a/src/main/java/dev/plex/command/impl/FreezeCMD.java +++ b/src/main/java/dev/plex/command/impl/FreezeCMD.java @@ -41,7 +41,7 @@ public class FreezeCMD extends PlexCommand punishment.setReason(""); plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment); - PlexUtils.broadcast(tl("frozePlayer", sender.getName(), player.getName())); + PlexUtils.broadcast(messageComponent("frozePlayer", sender.getName(), player.getName())); return null; } diff --git a/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java b/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java index 4fc0639..e805f99 100644 --- a/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java +++ b/src/main/java/dev/plex/command/impl/LocalSpawnCMD.java @@ -19,6 +19,6 @@ public class LocalSpawnCMD extends PlexCommand protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation()); - return tl("teleportedToWorldSpawn"); + return messageComponent("teleportedToWorldSpawn"); } } \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java b/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java index 49720dd..ce6d3cd 100644 --- a/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java +++ b/src/main/java/dev/plex/command/impl/MasterbuilderworldCMD.java @@ -26,7 +26,7 @@ public class MasterbuilderworldCMD extends PlexCommand { Location loc = new Location(Bukkit.getWorld("masterbuilderworld"), 0, 50, 0); playerSender.teleportAsync(loc); - return tl("teleportedToWorld", "Master Builder World"); + return messageComponent("teleportedToWorld", "Master Builder World"); } return null; } diff --git a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java index 1abdec1..6d3d008 100644 --- a/src/main/java/dev/plex/command/impl/NameHistoryCMD.java +++ b/src/main/java/dev/plex/command/impl/NameHistoryCMD.java @@ -39,7 +39,7 @@ public class NameHistoryCMD extends PlexCommand AshconInfo info = MojangUtils.getInfo(username); if (info == null) { - return tl("nameHistoryDoesntExist"); + return messageComponent("nameHistoryDoesntExist"); } PlexLog.debug("NameHistory UUID: " + info.getUuid()); PlexLog.debug("NameHistory Size: " + info.getUsernameHistories().length); diff --git a/src/main/java/dev/plex/command/impl/OpAllCMD.java b/src/main/java/dev/plex/command/impl/OpAllCMD.java index 4e07831..c09e568 100644 --- a/src/main/java/dev/plex/command/impl/OpAllCMD.java +++ b/src/main/java/dev/plex/command/impl/OpAllCMD.java @@ -23,7 +23,7 @@ public class OpAllCMD extends PlexCommand { player.setOp(true); } - PlexUtils.broadcast(tl("oppedAllPlayers", sender.getName())); + PlexUtils.broadcast(messageComponent("oppedAllPlayers", sender.getName())); return null; } diff --git a/src/main/java/dev/plex/command/impl/OpCMD.java b/src/main/java/dev/plex/command/impl/OpCMD.java index 9580d2b..eb75eae 100644 --- a/src/main/java/dev/plex/command/impl/OpCMD.java +++ b/src/main/java/dev/plex/command/impl/OpCMD.java @@ -26,7 +26,7 @@ public class OpCMD extends PlexCommand } Player player = getNonNullPlayer(args[0]); player.setOp(true); - PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName())); + PlexUtils.broadcast(messageComponent("oppedPlayer", sender.getName(), player.getName())); return null; } diff --git a/src/main/java/dev/plex/command/impl/RankCMD.java b/src/main/java/dev/plex/command/impl/RankCMD.java index eaa3069..c78aa0c 100644 --- a/src/main/java/dev/plex/command/impl/RankCMD.java +++ b/src/main/java/dev/plex/command/impl/RankCMD.java @@ -23,14 +23,14 @@ public class RankCMD extends PlexCommand if (!(playerSender == null)) { Rank rank = getPlexPlayer(playerSender).getRankFromString(); - return tl("yourRank", rank.getReadable()); + return messageComponent("yourRank", rank.getReadable()); } } else { Player player = getNonNullPlayer(args[0]); Rank rank = getPlexPlayer(player).getRankFromString(); - return tl("otherRank", player.getName(), rank.getReadable()); + return messageComponent("otherRank", player.getName(), rank.getReadable()); } return null; } diff --git a/src/main/java/dev/plex/command/impl/SpectatorCMD.java b/src/main/java/dev/plex/command/impl/SpectatorCMD.java index 00304e3..8a1d76e 100644 --- a/src/main/java/dev/plex/command/impl/SpectatorCMD.java +++ b/src/main/java/dev/plex/command/impl/SpectatorCMD.java @@ -29,7 +29,7 @@ public class SpectatorCMD extends PlexCommand { if (isConsole(sender)) { - throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer")); + throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); } Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SPECTATOR)); return null; @@ -42,9 +42,9 @@ public class SpectatorCMD extends PlexCommand for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) { targetPlayer.setGameMode(GameMode.SPECTATOR); - tl("gameModeSetTo", "spectator"); + messageComponent("gameModeSetTo", "spectator"); } - PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "spectator")); + PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "spectator")); return null; } diff --git a/src/main/java/dev/plex/command/impl/SurvivalCMD.java b/src/main/java/dev/plex/command/impl/SurvivalCMD.java index d0b15e5..5191c52 100644 --- a/src/main/java/dev/plex/command/impl/SurvivalCMD.java +++ b/src/main/java/dev/plex/command/impl/SurvivalCMD.java @@ -29,7 +29,7 @@ public class SurvivalCMD extends PlexCommand { if (isConsole(sender)) { - throw new CommandFailException(PlexUtils.tl("consoleMustDefinePlayer")); + throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer")); } Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL)); } @@ -41,9 +41,9 @@ public class SurvivalCMD extends PlexCommand for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers()) { targetPlayer.setGameMode(GameMode.SURVIVAL); - send(targetPlayer, tl("gameModeSetTo", "survival")); + send(targetPlayer, messageComponent("gameModeSetTo", "survival")); } - PlexUtils.broadcast(tl("setEveryoneGameMode", sender.getName(), "survival")); + PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "survival")); return null; } diff --git a/src/main/java/dev/plex/command/impl/TagCMD.java b/src/main/java/dev/plex/command/impl/TagCMD.java index df1c09d..6e0bbdf 100644 --- a/src/main/java/dev/plex/command/impl/TagCMD.java +++ b/src/main/java/dev/plex/command/impl/TagCMD.java @@ -38,7 +38,7 @@ public class TagCMD extends PlexCommand { if (sender instanceof ConsoleCommandSender) { - return tl("noPermissionConsole"); + return messageComponent("noPermissionConsole"); } PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); if (args.length < 2) @@ -60,7 +60,7 @@ public class TagCMD extends PlexCommand { if (sender instanceof ConsoleCommandSender) { - return tl("noPermissionConsole"); + return messageComponent("noPermissionConsole"); } PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); diff --git a/src/main/java/dev/plex/command/impl/UnbanCMD.java b/src/main/java/dev/plex/command/impl/UnbanCMD.java index 930be21..dba93de 100644 --- a/src/main/java/dev/plex/command/impl/UnbanCMD.java +++ b/src/main/java/dev/plex/command/impl/UnbanCMD.java @@ -47,7 +47,7 @@ public class UnbanCMD extends PlexCommand } plugin.getPunishmentManager().unban(targetUUID); - PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), plexPlayer.getName())); + PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), plexPlayer.getName())); } return null; } diff --git a/src/main/java/dev/plex/command/impl/UnfreezeCMD.java b/src/main/java/dev/plex/command/impl/UnfreezeCMD.java index 7b86e96..727b8e3 100644 --- a/src/main/java/dev/plex/command/impl/UnfreezeCMD.java +++ b/src/main/java/dev/plex/command/impl/UnfreezeCMD.java @@ -31,10 +31,10 @@ public class UnfreezeCMD extends PlexCommand PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); if (!punishedPlayer.isFrozen()) { - throw new CommandFailException(PlexUtils.tl("playerNotFrozen")); + throw new CommandFailException(PlexUtils.messageString("playerNotFrozen")); } punishedPlayer.setFrozen(false); - return tl("unfrozePlayer", sender.getName(), player.getName()); + return messageComponent("unfrozePlayer", sender.getName(), player.getName()); } @Override diff --git a/src/main/java/dev/plex/command/impl/WorldCMD.java b/src/main/java/dev/plex/command/impl/WorldCMD.java index f62231f..82f1c37 100644 --- a/src/main/java/dev/plex/command/impl/WorldCMD.java +++ b/src/main/java/dev/plex/command/impl/WorldCMD.java @@ -30,7 +30,7 @@ public class WorldCMD extends PlexCommand } World world = getNonNullWorld(args[0]); playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0)); - return tl("playerWorldTeleport", world.getName()); + return messageComponent("playerWorldTeleport", world.getName()); } @Override diff --git a/src/main/java/dev/plex/event/AdminAddEvent.java b/src/main/java/dev/plex/event/AdminAddEvent.java index b82b03f..a3887f9 100644 --- a/src/main/java/dev/plex/event/AdminAddEvent.java +++ b/src/main/java/dev/plex/event/AdminAddEvent.java @@ -2,6 +2,7 @@ package dev.plex.event; import dev.plex.player.PlexPlayer; import lombok.Data; +import lombok.EqualsAndHashCode; import org.bukkit.command.CommandSender; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -9,6 +10,7 @@ import org.bukkit.event.HandlerList; /** * Event that is ran when a player is added to the admin list */ +@EqualsAndHashCode(callSuper = true) @Data public class AdminAddEvent extends Event { diff --git a/src/main/java/dev/plex/event/AdminRemoveEvent.java b/src/main/java/dev/plex/event/AdminRemoveEvent.java index aea6882..9f2c6ac 100644 --- a/src/main/java/dev/plex/event/AdminRemoveEvent.java +++ b/src/main/java/dev/plex/event/AdminRemoveEvent.java @@ -2,6 +2,7 @@ package dev.plex.event; import dev.plex.player.PlexPlayer; import lombok.Data; +import lombok.EqualsAndHashCode; import org.bukkit.command.CommandSender; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -9,6 +10,7 @@ import org.bukkit.event.HandlerList; /** * Event that is ran when a player is removed from the admin list */ +@EqualsAndHashCode(callSuper = true) @Data public class AdminRemoveEvent extends Event { diff --git a/src/main/java/dev/plex/event/AdminSetRankEvent.java b/src/main/java/dev/plex/event/AdminSetRankEvent.java index f7fb75d..0769030 100644 --- a/src/main/java/dev/plex/event/AdminSetRankEvent.java +++ b/src/main/java/dev/plex/event/AdminSetRankEvent.java @@ -3,6 +3,7 @@ package dev.plex.event; import dev.plex.player.PlexPlayer; import dev.plex.rank.enums.Rank; import lombok.Data; +import lombok.EqualsAndHashCode; import org.bukkit.command.CommandSender; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -10,6 +11,7 @@ import org.bukkit.event.HandlerList; /** * Event that is ran when an admin's rank is set */ +@EqualsAndHashCode(callSuper = true) @Data public class AdminSetRankEvent extends Event { diff --git a/src/main/java/dev/plex/event/GameModeUpdateEvent.java b/src/main/java/dev/plex/event/GameModeUpdateEvent.java index e893bf0..133b8e6 100644 --- a/src/main/java/dev/plex/event/GameModeUpdateEvent.java +++ b/src/main/java/dev/plex/event/GameModeUpdateEvent.java @@ -1,6 +1,7 @@ package dev.plex.event; import lombok.Data; +import lombok.EqualsAndHashCode; import org.bukkit.GameMode; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -8,6 +9,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; +@EqualsAndHashCode(callSuper = true) @Data public class GameModeUpdateEvent extends Event { diff --git a/src/main/java/dev/plex/listener/impl/AdminListener.java b/src/main/java/dev/plex/listener/impl/AdminListener.java index 5de3dbc..582f500 100644 --- a/src/main/java/dev/plex/listener/impl/AdminListener.java +++ b/src/main/java/dev/plex/listener/impl/AdminListener.java @@ -9,7 +9,9 @@ import dev.plex.player.PlexPlayer; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import org.bukkit.event.EventHandler; -import static dev.plex.util.PlexUtils.tl; + +import static dev.plex.util.PlexUtils.messageComponent; +import static dev.plex.util.PlexUtils.messageString; public class AdminListener extends PlexListener { @@ -20,7 +22,7 @@ public class AdminListener extends PlexListener PlexPlayer target = event.getPlexPlayer(); target.setRank(Rank.ADMIN.name()); DataUtils.update(target); - PlexUtils.broadcast(tl("newAdminAdded", userSender, target.getName())); + PlexUtils.broadcast(messageComponent("newAdminAdded", userSender, target.getName())); } @EventHandler @@ -30,7 +32,7 @@ public class AdminListener extends PlexListener PlexPlayer target = event.getPlexPlayer(); target.setRank(""); DataUtils.update(target); - PlexUtils.broadcast(tl("adminRemoved", userSender, target.getName())); + PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName())); } @EventHandler @@ -41,6 +43,6 @@ public class AdminListener extends PlexListener Rank newRank = event.getRank(); target.setRank(newRank.name().toLowerCase()); DataUtils.update(target); - PlexUtils.broadcast(tl("adminSetRank", userSender, target.getName(), newRank.getReadable())); + PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable())); } } diff --git a/src/main/java/dev/plex/listener/impl/BanListener.java b/src/main/java/dev/plex/listener/impl/BanListener.java index 9014b12..5ece38a 100644 --- a/src/main/java/dev/plex/listener/impl/BanListener.java +++ b/src/main/java/dev/plex/listener/impl/BanListener.java @@ -7,6 +7,8 @@ import dev.plex.punishment.PunishmentType; import dev.plex.util.MojangUtils; import dev.plex.util.PlexUtils; import java.time.format.DateTimeFormatter; + +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.event.EventHandler; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; @@ -24,10 +26,10 @@ public class BanListener extends PlexListener PunishedPlayer player = PlayerCache.getPunishedPlayer(event.getUniqueId()); player.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive()).findFirst().ifPresent(punishment -> { - String banMessage = PlexUtils.tl("banMessage", banUrl, punishment.getReason(), + Component banMessage = PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), DATE_FORMAT.format(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername()); event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, - LegacyComponentSerializer.legacyAmpersand().deserialize(banMessage)); + banMessage); }); } } diff --git a/src/main/java/dev/plex/listener/impl/ChatListener.java b/src/main/java/dev/plex/listener/impl/ChatListener.java index b4de95e..94a2944 100644 --- a/src/main/java/dev/plex/listener/impl/ChatListener.java +++ b/src/main/java/dev/plex/listener/impl/ChatListener.java @@ -31,6 +31,9 @@ public class ChatListener extends PlexListener { renderer.hasPrefix = true; renderer.prefix = prefix; + } else { + renderer.hasPrefix = false; + renderer.prefix = null; } event.renderer(renderer); } @@ -44,18 +47,18 @@ public class ChatListener extends PlexListener PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN)) { - player.sendMessage(PlexUtils.tl("adminChatFormat", sender.getName(), message)); + player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message)); } } else if (plugin.getSystem().equalsIgnoreCase("permissions")) { if (player.hasPermission("plex.adminchat")) { - player.sendMessage(PlexUtils.tl("adminChatFormat", sender.getName(), message)); + player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message)); } } } - Bukkit.getLogger().info(PlexUtils.tl("adminChatFormat", sender.getName(), message)); + plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message)); } public static class PlexChatRenderer implements ChatRenderer diff --git a/src/main/java/dev/plex/listener/impl/GameModeListener.java b/src/main/java/dev/plex/listener/impl/GameModeListener.java index fae8f2a..b8a92d7 100644 --- a/src/main/java/dev/plex/listener/impl/GameModeListener.java +++ b/src/main/java/dev/plex/listener/impl/GameModeListener.java @@ -17,13 +17,13 @@ public class GameModeListener extends PlexListener if (userSender.getName().equals(target.getName())) { target.setGameMode(event.getGameMode()); - userSender.sendMessage(PlexUtils.tl("gameModeSetTo", event.getGameMode().toString().toLowerCase())); + userSender.sendMessage(PlexUtils.messageComponent("gameModeSetTo", event.getGameMode().toString().toLowerCase())); } else { - target.sendMessage(PlexUtils.tl("playerSetOtherGameMode", userSender.getName(), event.getGameMode().toString().toLowerCase())); + target.sendMessage(PlexUtils.messageComponent("playerSetOtherGameMode", userSender.getName(), event.getGameMode().toString().toLowerCase())); target.setGameMode(event.getGameMode()); - userSender.sendMessage(PlexUtils.tl("setOtherPlayerGameModeTo", target.getName(), event.getGameMode().toString().toLowerCase())); + userSender.sendMessage(PlexUtils.messageComponent("setOtherPlayerGameModeTo", target.getName(), event.getGameMode().toString().toLowerCase())); } } } diff --git a/src/main/java/dev/plex/menu/PunishedPlayerMenu.java b/src/main/java/dev/plex/menu/PunishedPlayerMenu.java index 249f22b..a74665a 100644 --- a/src/main/java/dev/plex/menu/PunishedPlayerMenu.java +++ b/src/main/java/dev/plex/menu/PunishedPlayerMenu.java @@ -6,7 +6,11 @@ import dev.plex.player.PunishedPlayer; import dev.plex.punishment.Punishment; import dev.plex.util.menu.AbstractMenu; import java.util.Arrays; +import java.util.Collections; import java.util.List; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -34,17 +38,17 @@ public class PunishedPlayerMenu extends AbstractMenu Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1)); ItemStack nextPage = new ItemStack(Material.FEATHER); ItemMeta meta = nextPage.getItemMeta(); - meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page"); + meta.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE)); nextPage.setItemMeta(meta); ItemStack previousPage = new ItemStack(Material.FEATHER); ItemMeta meta2 = previousPage.getItemMeta(); - meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page"); + meta2.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE)); previousPage.setItemMeta(meta2); ItemStack back = new ItemStack(Material.BARRIER); ItemMeta meta3 = back.getItemMeta(); - meta3.setDisplayName(ChatColor.RED + "Return"); + meta3.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE)); back.setItemMeta(meta3); inventory.setItem(50, nextPage); @@ -81,8 +85,8 @@ public class PunishedPlayerMenu extends AbstractMenu ItemStack item = new ItemStack(Material.NETHER_STAR); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(ChatColor.RED + punishment.getType().name().toUpperCase()); - meta.setLore(Arrays.asList(ChatColor.YELLOW + "Reason: \n" + ChatColor.GRAY + punishment.getReason())); + meta.displayName(Component.text(punishment.getType().name().toUpperCase()).color(NamedTextColor.RED)); + meta.lore(Collections.singletonList(Component.text("Reason: ").color(NamedTextColor.YELLOW).append(Component.newline()).append(Component.text(punishment.getReason()).color(NamedTextColor.GRAY)))); item.setItemMeta(meta); inv.setItem(currentItemIndex, item); @@ -109,10 +113,12 @@ public class PunishedPlayerMenu extends AbstractMenu return; } ItemStack item = event.getCurrentItem(); + if (!item.hasItemMeta()) return; + if (!item.getItemMeta().hasDisplayName()) return; event.setCancelled(true); if (item.getType() == Material.FEATHER) { - if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page")) + if (item.getItemMeta().displayName().equals(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE))) { if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) { @@ -124,7 +130,7 @@ public class PunishedPlayerMenu extends AbstractMenu } openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1); } - else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page")) + else if (item.getItemMeta().displayName().equals(Component.text("Previous Page").color(NamedTextColor.LIGHT_PURPLE))) { if (getCurrentInventoryIndex(inv) - 1 < 0) { diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index 3881523..6e82a61 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -225,7 +225,7 @@ public class PunishmentManager extends PlexBase return; } player.setFrozen(false); - Bukkit.broadcastMessage(PlexUtils.tl("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName())); + Bukkit.broadcast(PlexUtils.messageComponent("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName())); Bukkit.getLogger().info("Unfroze"); } }.runTaskLater(Plex.get(), 20 * seconds); diff --git a/src/main/java/dev/plex/services/impl/GameRuleService.java b/src/main/java/dev/plex/services/impl/GameRuleService.java index d627d40..725dd50 100644 --- a/src/main/java/dev/plex/services/impl/GameRuleService.java +++ b/src/main/java/dev/plex/services/impl/GameRuleService.java @@ -37,6 +37,7 @@ public class GameRuleService extends AbstractService world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false); world.setGameRule(GameRule.SHOW_DEATH_MESSAGES, false); world.setGameRule(GameRule.SEND_COMMAND_FEEDBACK, false); + world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); } @Override diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index 88f451a..a4202b4 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -20,7 +20,9 @@ import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -116,8 +118,9 @@ public class PlexUtils extends PlexBase return ChatColor.translateAlternateColorCodes('&', string); } + /*@Deprecated(forRemoval = true) // if you think the name of this method is dumb feel free to change it i just thought it'd be cool - public static String tl(String s, Object... objects) + public static String messageComponent(String s, Object... objects) { if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor")) { @@ -140,6 +143,25 @@ public class PlexUtils extends PlexBase f = f.replaceAll("", error.toString()); f = color(f); return base + f; + }*/ + + public static Component messageComponent(String entry, Object... objects) + { + return MiniMessage.miniMessage().parse(messageString(entry, objects)); + } + + public static String messageString(String entry, Object... objects) + { + String f = plugin.messages.getString(entry); + if (f == null) + { + throw new NullPointerException(); + } + for (Object object : objects) + { + f = f.replaceFirst("", String.valueOf(object)); + } + return f; } public static ChatColor getChatColorFromConfig(Config config, ChatColor def, String path) diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index cdc4dfb..57353d7 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -1,4 +1,5 @@ # Plex Messages File +# Reference https://docs.adventure.kyori.net/minimessage/format.html # Messages in here will be placed in for certain commands, actions, etc. # Warning: not all commands have customizable messages @@ -15,15 +16,11 @@ errorColor: "c" # you are unable to change the order the variables are used due to it being a code-side functionality. # if you are wishing to change these messages it's recommended you use the same amount of variables as stated in the documentation, however it's not required. -# Reset color - this will reset the color of the message to the base color defined above. -# Broadcast color - this will make the color of the message the broadcast color defined above. -# Error color - this will make the color of the message the error color defined above. - # 1. Appeal URL # 2. Reason # 3. Expiry # 4. Punisher -banMessage: "&cYou have been banned! You may appeal at &6.\n&cReason: &6\n&cEnd date: &6\n&cBanned by: &6" +banMessage: "You have been banned! You may appeal at .\nReason: \nEnd date: \nBanned by: " test: "this is a test message!" # 1. The command sender's username variableTest: "variable test with !" @@ -32,33 +29,33 @@ worldNotFound: "World not found!" # 1. The world you have been teleported to playerWorldTeleport: "You have been teleported to ." # 1. The sender who opped everyone -oppedAllPlayers: " - Opped all players on the server" +oppedAllPlayers: " - Opped all players on the server" # 1. The sender who de-opped everyone -deoppedAllPlayers: " - De-opped all players on the server" +deoppedAllPlayers: " - De-opped all players on the server" # 1. The person who is opping # 2. The person who has been opped -oppedPlayer: " - Opped " +oppedPlayer: " - Opped " # 1. The person who is freezing # 2. The person who has been frozen -frozePlayer: " - Froze " +frozePlayer: " - Froze " # 1. The person who is unfreezing # 2. The person who has been unfrozen -unfrozePlayer: " - Unfroze " -noPermission: "You cannot use this command!" +unfrozePlayer: " - Unfroze " +noPermission: "You cannot use this command!" # 1. The rank required to use the command -noPermissionRank: "You must be at least to use this command!" +noPermissionRank: "You must be at least to use this command!" # 1. The permission node required to use the command -noPermissionNode: "You must have the permission: to use this command!" -noPermissionInGame: "You must be in console to use this command!" -noPermissionConsole: "You must be in-game to use this command!" +noPermissionNode: "You must have the permission: to use this command!" +noPermissionInGame: "You must be in console to use this command!" +noPermissionConsole: "You must be in-game to use this command!" # 1. The username of the name history nameHistoryTitle: "Name History of " # 1. A username of the found user # 2. When the user changed to that username nameHistoryBody: " - ()" # 1. The username that failed -nameHistoryFail: "Something went wrong while trying to retrieve name history of ! Try again later!" -nameHistoryDoesntExist: "Couldn't find this user! Please check if your spelling was correct and this player exists" +nameHistoryFail: "Something went wrong while trying to retrieve name history of ! Try again later!" +nameHistoryDoesntExist: "Couldn't find this user! Please check if your spelling was correct and this player exists" # 1. The gamemode gameModeSetTo: "Your gamemode has been set to ." # 1. The player's name @@ -69,38 +66,38 @@ setOtherPlayerGameModeTo: "You set 's gamemode to ." playerSetOtherGameMode: " set your gamemode to ." # 1. The command sender # 2. The gamemode -setEveryoneGameMode: " - Changing everyone's gamemode to " +setEveryoneGameMode: " - Changing everyone's gamemode to " consoleMustDefinePlayer: "You must define a player since you are running this command from console." # 1. The command sender # 2. The player -newAdminAdded: " - Adding to the admin list" +newAdminAdded: " - Adding to the admin list" # 1. The command sender # 2. The player -adminRemoved: " - Removing from the admin list" +adminRemoved: " - Removing from the admin list" # 1. The command sender # 2. The player -adminSetRank: " - Setting 's rank to " +adminSetRank: " - Setting 's rank to " # The world name -teleportedToWorld: "You have been teleported to the ." -higherRankThanYou: "This player is an admin and a higher rank than you." -playerNotAdmin: "That player is not an admin." -playerIsAdmin: "That player is already an admin." -rankNotFound: "The rank you entered was not found." -rankMustBeHigherThanAdmin: "The rank you entered must be higher than Admin." -consoleOnly: "This command can only be executed by the console." +teleportedToWorld: "You have been teleported to the ." +higherRankThanYou: "This player is an admin and a higher rank than you." +playerNotAdmin: "That player is not an admin." +playerIsAdmin: "That player is already an admin." +rankNotFound: "The rank you entered was not found." +rankMustBeHigherThanAdmin: "The rank you entered must be higher than Admin." +consoleOnly: "This command can only be executed by the console." # 1. Rank -yourRank: "Your rank is: " +yourRank: "Your rank is: " # 1. Player name # 2. Rank -otherRank: "'s rank is: " +otherRank: "'s rank is: " # 1. The command sender # 2. The player -banningPlayer: " - Banning " +banningPlayer: " - Banning " # 1. The command sender # 2. The player -unbanningPlayer: " - Unbanning " -playerNotBanned: "That player is not banned!" -teleportedToWorldSpawn: "Teleporting to the local spawn" +unbanningPlayer: " - Unbanning " +playerNotBanned: "That player is not banned!" +teleportedToWorldSpawn: "Teleporting to the local spawn" toggleCommandSpy: "CommandSpy has been " enabled: "enabled" disabled: "disabled"