- Switch messages.yml to minimessage

This commit is contained in:
Taah 2022-02-24 23:09:55 -08:00
parent b6f4ddbb4c
commit bd21e5d2ba
40 changed files with 161 additions and 110 deletions

View File

@ -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'

View File

@ -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;
}

View File

@ -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"));
}
}

View File

@ -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"));
}
}

View File

@ -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"));
}
}

View File

@ -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"));
}
}

View File

@ -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));

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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."));

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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");
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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());

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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()));
}
}

View File

@ -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);
});
}
}

View File

@ -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

View File

@ -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()));
}
}
}

View File

@ -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)
{

View File

@ -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);

View File

@ -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

View File

@ -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("<e>", 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("<v>", String.valueOf(object));
}
return f;
}
public static ChatColor getChatColorFromConfig(Config config, ChatColor def, String path)

View File

@ -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 <r> - this will reset the color of the message to the base color defined above.
# Broadcast color <b> - this will make the color of the message the broadcast color defined above.
# Error color <e> - 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<v>.\n&cReason: &6<v>\n&cEnd date: &6<v>\n&cBanned by: &6<v>"
banMessage: "<red>You have been banned! You may appeal at <gold><v>.\n<red>Reason: <gold><v>\n<red>End date: <gold><v>\n<red>Banned by: <gold><v>"
test: "this is a test message!"
# 1. The command sender's username
variableTest: "variable test with <v>!"
@ -32,33 +29,33 @@ worldNotFound: "World not found!"
# 1. The world you have been teleported to
playerWorldTeleport: "You have been teleported to <v>."
# 1. The sender who opped everyone
oppedAllPlayers: "<b><v> - Opped all players on the server"
oppedAllPlayers: "<aqua><v> - Opped all players on the server"
# 1. The sender who de-opped everyone
deoppedAllPlayers: "<b><v> - De-opped all players on the server"
deoppedAllPlayers: "<aqua><v> - De-opped all players on the server"
# 1. The person who is opping
# 2. The person who has been opped
oppedPlayer: "<b><v> - Opped <v>"
oppedPlayer: "<aqua><v> - Opped <v>"
# 1. The person who is freezing
# 2. The person who has been frozen
frozePlayer: "<b><v> - Froze <v>"
frozePlayer: "<aqua><v> - Froze <v>"
# 1. The person who is unfreezing
# 2. The person who has been unfrozen
unfrozePlayer: "<b><v> - Unfroze <v>"
noPermission: "<e>You cannot use this command!"
unfrozePlayer: "<aqua><v> - Unfroze <v>"
noPermission: "<red>You cannot use this command!"
# 1. The rank required to use the command
noPermissionRank: "<e>You must be at least <v> to use this command!"
noPermissionRank: "<red>You must be at least <v> to use this command!"
# 1. The permission node required to use the command
noPermissionNode: "<e>You must have the permission: <v> to use this command!"
noPermissionInGame: "<e>You must be in console to use this command!"
noPermissionConsole: "<e>You must be in-game to use this command!"
noPermissionNode: "<red>You must have the permission: <v> to use this command!"
noPermissionInGame: "<red>You must be in console to use this command!"
noPermissionConsole: "<red>You must be in-game to use this command!"
# 1. The username of the name history
nameHistoryTitle: "Name History of <v>"
# 1. A username of the found user
# 2. When the user changed to that username
nameHistoryBody: " - <v> (<v>)"
# 1. The username that failed
nameHistoryFail: "<e>Something went wrong while trying to retrieve name history of <v>! Try again later!"
nameHistoryDoesntExist: "<e>Couldn't find this user! Please check if your spelling was correct and this player exists"
nameHistoryFail: "<red>Something went wrong while trying to retrieve name history of <v>! Try again later!"
nameHistoryDoesntExist: "<red>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 <v>."
# 1. The player's name
@ -69,38 +66,38 @@ setOtherPlayerGameModeTo: "You set <v>'s gamemode to <v>."
playerSetOtherGameMode: "<v> set your gamemode to <v>."
# 1. The command sender
# 2. The gamemode
setEveryoneGameMode: "<b><v> - Changing everyone's gamemode to <v>"
setEveryoneGameMode: "<aqua><v> - Changing everyone's gamemode to <v>"
consoleMustDefinePlayer: "You must define a player since you are running this command from console."
# 1. The command sender
# 2. The player
newAdminAdded: "<b><v> - Adding <v> to the admin list"
newAdminAdded: "<aqua><v> - Adding <v> to the admin list"
# 1. The command sender
# 2. The player
adminRemoved: "<e><v> - Removing <v> from the admin list"
adminRemoved: "<red><v> - Removing <v> from the admin list"
# 1. The command sender
# 2. The player
adminSetRank: "<b><v> - Setting <v>'s rank to <v>"
adminSetRank: "<aqua><v> - Setting <v>'s rank to <v>"
# The world name
teleportedToWorld: "<b>You have been teleported to the <v>."
higherRankThanYou: "<e>This player is an admin and a higher rank than you."
playerNotAdmin: "<e>That player is not an admin."
playerIsAdmin: "<e>That player is already an admin."
rankNotFound: "<e>The rank you entered was not found."
rankMustBeHigherThanAdmin: "<e>The rank you entered must be higher than Admin."
consoleOnly: "<e>This command can only be executed by the console."
teleportedToWorld: "<aqua>You have been teleported to the <v>."
higherRankThanYou: "<red>This player is an admin and a higher rank than you."
playerNotAdmin: "<red>That player is not an admin."
playerIsAdmin: "<red>That player is already an admin."
rankNotFound: "<red>The rank you entered was not found."
rankMustBeHigherThanAdmin: "<red>The rank you entered must be higher than Admin."
consoleOnly: "<red>This command can only be executed by the console."
# 1. Rank
yourRank: "<b>Your rank is: <v>"
yourRank: "<aqua>Your rank is: <v>"
# 1. Player name
# 2. Rank
otherRank: "<b><v>'s rank is: <v>"
otherRank: "<aqua><v>'s rank is: <v>"
# 1. The command sender
# 2. The player
banningPlayer: "<e><v> - Banning <v>"
banningPlayer: "<red><v> - Banning <v>"
# 1. The command sender
# 2. The player
unbanningPlayer: "<b><v> - Unbanning <v>"
playerNotBanned: "<e>That player is not banned!"
teleportedToWorldSpawn: "<b>Teleporting to the local spawn"
unbanningPlayer: "<aqua><v> - Unbanning <v>"
playerNotBanned: "<red>That player is not banned!"
teleportedToWorldSpawn: "<aqua>Teleporting to the local spawn"
toggleCommandSpy: "CommandSpy has been "
enabled: "enabled"
disabled: "disabled"