diff --git a/src/main/java/net/flectone/chat/builder/MessageBuilder.java b/src/main/java/net/flectone/chat/builder/MessageBuilder.java index 1ce26be5..06525788 100644 --- a/src/main/java/net/flectone/chat/builder/MessageBuilder.java +++ b/src/main/java/net/flectone/chat/builder/MessageBuilder.java @@ -29,7 +29,6 @@ public class MessageBuilder { private final List messages = new ArrayList<>(); - private final ComponentBuilder componentBuilder = new ComponentBuilder(); private final ItemStack itemStack; private final Player sender; @@ -212,9 +211,4 @@ private BaseComponent[] createItemComponent(@NotNull ItemStack itemStack, @NotNu .append(color) .create(); } - - @NotNull - public BaseComponent[] create() { - return componentBuilder.create(); - } } diff --git a/src/main/java/net/flectone/chat/component/FComponent.java b/src/main/java/net/flectone/chat/component/FComponent.java index aec10489..a2bc2bce 100644 --- a/src/main/java/net/flectone/chat/component/FComponent.java +++ b/src/main/java/net/flectone/chat/component/FComponent.java @@ -33,10 +33,6 @@ public FComponent() { this(new TextComponent()); } - public FComponent(@NotNull FComponent fComponent) { - this(fComponent.get()); - } - @NotNull public BaseComponent get() { return component; diff --git a/src/main/java/net/flectone/chat/database/sqlite/Database.java b/src/main/java/net/flectone/chat/database/sqlite/Database.java index b021dcd6..6c9e98b8 100644 --- a/src/main/java/net/flectone/chat/database/sqlite/Database.java +++ b/src/main/java/net/flectone/chat/database/sqlite/Database.java @@ -185,39 +185,6 @@ public void fromDatabase(FPlayer fPlayer) { }); } - @Nullable - public FPlayer getPlayer(@Nullable String name) throws SQLException { - if (name == null) return null; - - PreparedStatement playerStatement = connection.prepareStatement("SELECT `uuid`, `ip` FROM `players` WHERE `name` = ?"); - playerStatement.setString(1, name); - ResultSet playerResult = playerStatement.executeQuery(); - - if (!playerResult.next()) return null; - - String uuid = playerResult.getString("uuid"); - String ip = playerResult.getString("ip"); - - return new FPlayer(name, uuid, ip); - } - - @Nullable - public FPlayer getPlayer(@Nullable UUID uuid) throws SQLException { - if (uuid == null) return null; - String uuidString = uuid.toString(); - - PreparedStatement playerStatement = connection.prepareStatement("SELECT `name`, `ip` FROM `players` WHERE `uuid` = ?"); - playerStatement.setString(1, uuidString); - ResultSet playerResult = playerStatement.executeQuery(); - - if (!playerResult.next()) return null; - - String name = playerResult.getString("name"); - String ip = playerResult.getString("ip"); - - return new FPlayer(name, uuidString, ip); - } - public void getMute(FPlayer fPlayer) { try { String uuid = fPlayer.getUuid().toString(); diff --git a/src/main/java/net/flectone/chat/database/sqlite/SQLHandler.java b/src/main/java/net/flectone/chat/database/sqlite/SQLHandler.java index 2c6281a4..ba8a0e53 100644 --- a/src/main/java/net/flectone/chat/database/sqlite/SQLHandler.java +++ b/src/main/java/net/flectone/chat/database/sqlite/SQLHandler.java @@ -73,9 +73,4 @@ public void disconnect() { public void onDisconnect() { } - - public boolean isConnected() { - return connection != null; - } - } \ No newline at end of file diff --git a/src/main/java/net/flectone/chat/manager/FActionManager.java b/src/main/java/net/flectone/chat/manager/FActionManager.java index 48dbe9bd..f401404e 100644 --- a/src/main/java/net/flectone/chat/manager/FActionManager.java +++ b/src/main/java/net/flectone/chat/manager/FActionManager.java @@ -2,7 +2,6 @@ import net.flectone.chat.FlectoneChat; import net.flectone.chat.module.FCommand; -import net.flectone.chat.module.FInfo; import net.flectone.chat.module.FListener; import net.flectone.chat.module.FTicker; import net.flectone.chat.util.CommandsUtil; @@ -16,7 +15,6 @@ public class FActionManager { private final List F_LISTENER_LIST = new ArrayList<>(); private final List F_TICKER_LIST = new ArrayList<>(); - private final List F_INFO_LIST = new ArrayList<>(); private final List F_COMMAND_LIST = new ArrayList<>(); public FActionManager() {} @@ -33,13 +31,9 @@ public void add(FTicker fTicker) { F_TICKER_LIST.add(fTicker); } - public void add(FInfo fInfo) { - F_INFO_LIST.add(fInfo); - } public void clearAll() { clearCommands(); - clearInfos(); clearListeners(); clearTickers(); } @@ -48,11 +42,7 @@ public void clearCommands() { F_COMMAND_LIST.forEach(fCommand -> CommandsUtil.unregisterCommand(fCommand.getCommand())); } - - public void clearInfos() { - F_INFO_LIST.clear(); - } - + public void clearListeners() { HandlerList.unregisterAll(FlectoneChat.getPlugin()); F_LISTENER_LIST.clear(); diff --git a/src/main/java/net/flectone/chat/model/advancement/FAdvancement.java b/src/main/java/net/flectone/chat/model/advancement/FAdvancement.java index 82de42ab..bb27615b 100644 --- a/src/main/java/net/flectone/chat/model/advancement/FAdvancement.java +++ b/src/main/java/net/flectone/chat/model/advancement/FAdvancement.java @@ -2,11 +2,9 @@ import net.flectone.chat.util.NMSUtil; import org.bukkit.advancement.Advancement; -import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -import java.lang.reflect.Field; import java.util.Arrays; // Thanks, @CroaBeast, for these methods @@ -14,18 +12,15 @@ public class FAdvancement { private static final String COMP_CLASS = "IChatBaseComponent"; - private final Advancement adv; private String toChat = null; private String hidden = null; private Type type = Type.UNKNOWN; - private ItemStack item = null; private String translateKey; private String translateDesc; private String title; public FAdvancement(@NotNull Advancement adv) { - this.adv = adv; Class craftClass = NMSUtil.getBukkitClass("advancement.CraftAdvancement"); if (craftClass == null) return; @@ -40,32 +35,12 @@ public FAdvancement(@NotNull Advancement adv) { translateKey = String.valueOf(NMSUtil.getObject(NMSUtil.getObject(rawTitle, "b"), "a")); translateDesc = String.valueOf(NMSUtil.getObject(NMSUtil.getObject(rawDesc, "b"), "a")); - Field itemField = null; - try { - itemField = display.getClass().getDeclaredField("c"); - } catch (Exception e) { - e.printStackTrace(); - } - - Object nmsItemStack = null; - if (itemField != null) { - try { - itemField.setAccessible(true); - nmsItemStack = itemField.get(display); - itemField.setAccessible(false); - } catch (Exception e) { - e.printStackTrace(); - } - } - String typeName = NMSUtil.checkValue(NMSUtil.getObject(display, "e"), "PROGRESS"); this.type = Type.getType(typeName); toChat = NMSUtil.checkValue(NMSUtil.getObject(display, "i")); hidden = NMSUtil.checkValue(NMSUtil.getObject(display, "j")); - item = NMSUtil.getBukkitItem(nmsItemStack); - Class chatClass = NMSUtil.getVersion() >= 17 ? NMSUtil.getNMSClass("net.minecraft.network.chat", COMP_CLASS, false) : NMSUtil.getNMSClass(null, COMP_CLASS, true); @@ -99,11 +74,6 @@ public String getTranslateDesc() { return translateDesc; } - @NotNull - public Advancement getBukkit() { - return adv; - } - @NotNull public Type getType() { return type; @@ -117,11 +87,6 @@ public boolean isHidden() { return getBool(hidden); } - @Nullable - public ItemStack getItem() { - return item; - } - public enum Type { UNKNOWN, TASK, diff --git a/src/main/java/net/flectone/chat/model/damager/PlayerDamager.java b/src/main/java/net/flectone/chat/model/damager/PlayerDamager.java index 84a9b14b..a575ef55 100644 --- a/src/main/java/net/flectone/chat/model/damager/PlayerDamager.java +++ b/src/main/java/net/flectone/chat/model/damager/PlayerDamager.java @@ -16,7 +16,6 @@ public class PlayerDamager { @Getter private Entity killer; private String killerItemName; - private String killerItemAsJson; private Entity finalEntityDamager; private Material finalBlockDamager; private String damagerTranslateName; @@ -41,7 +40,6 @@ public ItemStack getKillerItem() { public void setKillerItem(@NotNull ItemStack itemStack) { this.killerItem = itemStack; this.killerItemName = NMSUtil.getMinecraftName(itemStack); - this.killerItemAsJson = NMSUtil.getItemAsJson(itemStack); } @Nullable diff --git a/src/main/java/net/flectone/chat/model/player/FPlayer.java b/src/main/java/net/flectone/chat/model/player/FPlayer.java index 1dea8f98..411dc3ad 100644 --- a/src/main/java/net/flectone/chat/model/player/FPlayer.java +++ b/src/main/java/net/flectone/chat/model/player/FPlayer.java @@ -99,13 +99,6 @@ public FPlayer(@NotNull OfflinePlayer offlinePlayer) { this.minecraftName = offlinePlayer.getName() != null ? offlinePlayer.getName() : "Unknown"; } - public FPlayer(@NotNull String uuid, @NotNull String name, @NotNull String ip) { - this(); - this.uuid = UUID.fromString(uuid); - this.minecraftName = name; - this.ip = ip; - } - public void init() { playerManager.add(this); diff --git a/src/main/java/net/flectone/chat/model/player/Moderation.java b/src/main/java/net/flectone/chat/model/player/Moderation.java index 6aa246d4..0bf5cf56 100644 --- a/src/main/java/net/flectone/chat/model/player/Moderation.java +++ b/src/main/java/net/flectone/chat/model/player/Moderation.java @@ -3,7 +3,6 @@ import lombok.Getter; import net.flectone.chat.util.TimeUtil; import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -52,11 +51,6 @@ private String getName(@NotNull String uuid) { return name != null ? name : "Unknown"; } - @NotNull - public OfflinePlayer getPlayer() { - return Bukkit.getOfflinePlayer(UUID.fromString(playerUUID)); - } - public int getRemainingTime() { return this.time - TimeUtil.getCurrentTime(); } diff --git a/src/main/java/net/flectone/chat/module/FCommand.java b/src/main/java/net/flectone/chat/module/FCommand.java index 03b2ec1c..ebd28193 100644 --- a/src/main/java/net/flectone/chat/module/FCommand.java +++ b/src/main/java/net/flectone/chat/module/FCommand.java @@ -118,13 +118,6 @@ public void sendMessage(@NotNull CommandSender commandSender, @NotNull String st commandSender.sendMessage(message); } - public void sendMessage(@NotNull Player player, @NotNull String string) { - String message = locale.getVaultString(player, string); - message = MessageUtil.formatAll(null, message); - - player.sendMessage(message); - } - public void sendGlobalMessage(@Nullable Player player, @Nullable ItemStack itemStack, @NotNull String format, @NotNull String message, boolean isClickable) { diff --git a/src/main/java/net/flectone/chat/module/FInfo.java b/src/main/java/net/flectone/chat/module/FInfo.java deleted file mode 100644 index f4085668..00000000 --- a/src/main/java/net/flectone/chat/module/FInfo.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.flectone.chat.module; - -import lombok.Getter; - -@Getter -public abstract class FInfo implements FAction { - - private final FModule module; - - public FInfo(FModule module) { - this.module = module; - } -} \ No newline at end of file diff --git a/src/main/java/net/flectone/chat/module/commands/CommandBanlist.java b/src/main/java/net/flectone/chat/module/commands/CommandBanlist.java index 1fb660ac..2cb5efbd 100644 --- a/src/main/java/net/flectone/chat/module/commands/CommandBanlist.java +++ b/src/main/java/net/flectone/chat/module/commands/CommandBanlist.java @@ -119,6 +119,18 @@ public void asyncOnCommand(@NotNull CommandSender commandSender, @NotNull Comman pageLine = MessageUtil.formatAll(cmdSettings.getSender(), pageLine); + FComponentBuilder fComponentBuilder = getfComponentBuilder(pageLine, page, cmdSettings); + + componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); + commandSender.spigot().sendMessage(componentBuilder.create()); + + if (!cmdSettings.isConsole()) { + cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); + } + } + + @NotNull + private FComponentBuilder getfComponentBuilder(String pageLine, int page, CmdSettings cmdSettings) { FComponentBuilder fComponentBuilder = new FComponentBuilder(pageLine); AtomicInteger prevNumber = new AtomicInteger(page); @@ -144,13 +156,7 @@ public void asyncOnCommand(@NotNull CommandSender commandSender, @NotNull Comman nextBuilder.append(fComponent.get(), ComponentBuilder.FormatRetention.NONE); }); - - componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); - commandSender.spigot().sendMessage(componentBuilder.create()); - - if (!cmdSettings.isConsole()) { - cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); - } + return fComponentBuilder; } @Override diff --git a/src/main/java/net/flectone/chat/module/commands/CommandIgnorelist.java b/src/main/java/net/flectone/chat/module/commands/CommandIgnorelist.java index f4810066..27fb2017 100644 --- a/src/main/java/net/flectone/chat/module/commands/CommandIgnorelist.java +++ b/src/main/java/net/flectone/chat/module/commands/CommandIgnorelist.java @@ -116,6 +116,19 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command pageLine = MessageUtil.formatAll(cmdSettings.getSender(), pageLine); + FComponentBuilder fComponentBuilder = getfComponentBuilder(pageLine, page, cmdSettings); + + componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); + + commandSender.spigot().sendMessage(componentBuilder.create()); + + cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); + + return true; + } + + @NotNull + private FComponentBuilder getfComponentBuilder(String pageLine, int page, CmdSettings cmdSettings) { FComponentBuilder fComponentBuilder = new FComponentBuilder(pageLine); AtomicInteger prevNumber = new AtomicInteger(page); @@ -141,14 +154,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command nextBuilder.append(fComponent.get(), ComponentBuilder.FormatRetention.NONE); }); - - componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); - - commandSender.spigot().sendMessage(componentBuilder.create()); - - cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); - - return true; + return fComponentBuilder; } @Override diff --git a/src/main/java/net/flectone/chat/module/commands/CommandMutelist.java b/src/main/java/net/flectone/chat/module/commands/CommandMutelist.java index 1d9e1037..0e248cfc 100644 --- a/src/main/java/net/flectone/chat/module/commands/CommandMutelist.java +++ b/src/main/java/net/flectone/chat/module/commands/CommandMutelist.java @@ -115,6 +115,19 @@ public void asyncOnCommand(@NotNull CommandSender commandSender, @NotNull Comman pageLine = MessageUtil.formatAll(cmdSettings.getSender(), pageLine); + FComponentBuilder fComponentBuilder = getfComponentBuilder(pageLine, page, cmdSettings); + + componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); + + commandSender.spigot().sendMessage(componentBuilder.create()); + + if (!cmdSettings.isConsole()) { + cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); + } + } + + @NotNull + private FComponentBuilder getfComponentBuilder(String pageLine, int page, CmdSettings cmdSettings) { FComponentBuilder fComponentBuilder = new FComponentBuilder(pageLine); AtomicInteger prevNumber = new AtomicInteger(page); @@ -140,14 +153,7 @@ public void asyncOnCommand(@NotNull CommandSender commandSender, @NotNull Comman nextBuilder.append(fComponent.get(), ComponentBuilder.FormatRetention.NONE); }); - - componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); - - commandSender.spigot().sendMessage(componentBuilder.create()); - - if (!cmdSettings.isConsole()) { - cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); - } + return fComponentBuilder; } @Override diff --git a/src/main/java/net/flectone/chat/module/commands/CommandWarnlist.java b/src/main/java/net/flectone/chat/module/commands/CommandWarnlist.java index 4091cb06..c295710f 100644 --- a/src/main/java/net/flectone/chat/module/commands/CommandWarnlist.java +++ b/src/main/java/net/flectone/chat/module/commands/CommandWarnlist.java @@ -115,6 +115,19 @@ public void asyncOnCommand(@NotNull CommandSender commandSender, @NotNull Comman pageLine = MessageUtil.formatAll(cmdSettings.getSender(), pageLine); + FComponentBuilder fComponentBuilder = getfComponentBuilder(pageLine, page, cmdSettings); + + componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); + + commandSender.spigot().sendMessage(componentBuilder.create()); + + if (!cmdSettings.isConsole()) { + cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); + } + } + + @NotNull + private FComponentBuilder getfComponentBuilder(String pageLine, int page, CmdSettings cmdSettings) { FComponentBuilder fComponentBuilder = new FComponentBuilder(pageLine); AtomicInteger prevNumber = new AtomicInteger(page); @@ -140,14 +153,7 @@ public void asyncOnCommand(@NotNull CommandSender commandSender, @NotNull Comman nextBuilder.append(fComponent.get(), ComponentBuilder.FormatRetention.NONE); }); - - componentBuilder.append(fComponentBuilder.build(cmdSettings.getSender(), cmdSettings.getSender())); - - commandSender.spigot().sendMessage(componentBuilder.create()); - - if (!cmdSettings.isConsole()) { - cmdSettings.getFPlayer().playSound(cmdSettings.getSender(), cmdSettings.getSender(), this.toString()); - } + return fComponentBuilder; } @Override diff --git a/src/main/java/net/flectone/chat/module/player/hover/HoverModule.java b/src/main/java/net/flectone/chat/module/player/hover/HoverModule.java index ac218d08..85357900 100644 --- a/src/main/java/net/flectone/chat/module/player/hover/HoverModule.java +++ b/src/main/java/net/flectone/chat/module/player/hover/HoverModule.java @@ -38,10 +38,10 @@ public Pair> get(@NotNull Player player) { public enum CommandType { - SUGGEST("suggest"), - RUN("run"); + SUGGEST(), + RUN(); - CommandType(String name) {} + CommandType() {} public static CommandType fromString(String string) { if (string.equalsIgnoreCase("run")) return RUN; diff --git a/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java b/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java index 9403b06d..8cca7a3d 100644 --- a/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java +++ b/src/main/java/net/flectone/chat/module/playerMessage/formatting/FormattingModule.java @@ -64,39 +64,7 @@ public void replace(@Nullable Player player, @NotNull String message, @NotNull S HashMap formattingMap = load(player); - List> sortedPairs = new ArrayList<>(); - Map patternIndexes = new HashMap<>(); - - int charIndex = 0; - while (charIndex < message.length()) { - if (message.startsWith("\\", charIndex)) { - charIndex += 2; - continue; - } - - String matchedPattern = null; - for (String pattern : patterns) { - if (!formattingMap.containsValue(pattern)) continue; - - if (message.startsWith(pattern, charIndex)) { - matchedPattern = pattern; - break; - } - } - - if (matchedPattern != null) { - if (patternIndexes.containsKey(matchedPattern)) { - sortedPairs.add(new Pair<>(matchedPattern, patternIndexes.get(matchedPattern))); - sortedPairs.add(new Pair<>(matchedPattern, charIndex)); - patternIndexes.remove(matchedPattern); - } else { - patternIndexes.put(matchedPattern, charIndex); - } - charIndex += matchedPattern.length(); - } else { - charIndex++; - } - } + List> sortedPairs = getPairs(message, formattingMap); sortedPairs.sort(Comparator.comparingInt(Pair::right)); @@ -146,6 +114,44 @@ public void replace(@Nullable Player player, @NotNull String message, @NotNull S } + @NotNull + private List> getPairs(@NotNull String message, HashMap formattingMap) { + List> sortedPairs = new ArrayList<>(); + Map patternIndexes = new HashMap<>(); + + int charIndex = 0; + while (charIndex < message.length()) { + if (message.startsWith("\\", charIndex)) { + charIndex += 2; + continue; + } + + String matchedPattern = null; + for (String pattern : patterns) { + if (!formattingMap.containsValue(pattern)) continue; + + if (message.startsWith(pattern, charIndex)) { + matchedPattern = pattern; + break; + } + } + + if (matchedPattern != null) { + if (patternIndexes.containsKey(matchedPattern)) { + sortedPairs.add(new Pair<>(matchedPattern, patternIndexes.get(matchedPattern))); + sortedPairs.add(new Pair<>(matchedPattern, charIndex)); + patternIndexes.remove(matchedPattern); + } else { + patternIndexes.put(matchedPattern, charIndex); + } + charIndex += matchedPattern.length(); + } else { + charIndex++; + } + } + return sortedPairs; + } + private void splitStringToWordParams(@Nullable Player sender, @NotNull String command, @NotNull TextParameters textParameters, @NotNull List messages, @Nullable ItemStack itemStack, @NotNull HashMap formattingMap, diff --git a/src/main/java/net/flectone/chat/module/serverMessage/advancement/AdvancementModule.java b/src/main/java/net/flectone/chat/module/serverMessage/advancement/AdvancementModule.java index 32997c03..f6aca4c8 100644 --- a/src/main/java/net/flectone/chat/module/serverMessage/advancement/AdvancementModule.java +++ b/src/main/java/net/flectone/chat/module/serverMessage/advancement/AdvancementModule.java @@ -92,11 +92,7 @@ public void sendMessage(@NotNull Player sender, @Nullable Player player, @NotNul FComponent advancementComponent = new FLocaleComponent(fAdvancement.getTranslateKey()); String hover = locale.getVaultString(sender, this + "." + fAdvancement.getType() + ".hover"); - FComponentBuilder hoverComponentBuilder = new FComponentBuilder(hover); - hoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> - hoverBuilder.append(new FColorComponent(new FLocaleComponent(fAdvancement.getTranslateKey()), hoverColor).get())); - hoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> - hoverBuilder.append(new FColorComponent(new FLocaleComponent(fAdvancement.getTranslateDesc()), hoverColor).get())); + FComponentBuilder hoverComponentBuilder = getfComponentBuilder(fAdvancement, hover); advancementComponent.addHoverText(hoverComponentBuilder.build(sender, player)); @@ -109,4 +105,14 @@ public void sendMessage(@NotNull Player sender, @Nullable Player player, @NotNul FPlayer.sendToConsole(fComponentBuilder.build(sender, null)); } } + + @NotNull + private FComponentBuilder getfComponentBuilder(@NotNull FAdvancement fAdvancement, String hover) { + FComponentBuilder hoverComponentBuilder = new FComponentBuilder(hover); + hoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> + hoverBuilder.append(new FColorComponent(new FLocaleComponent(fAdvancement.getTranslateKey()), hoverColor).get())); + hoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> + hoverBuilder.append(new FColorComponent(new FLocaleComponent(fAdvancement.getTranslateDesc()), hoverColor).get())); + return hoverComponentBuilder; + } } diff --git a/src/main/java/net/flectone/chat/module/serverMessage/death/DeathModule.java b/src/main/java/net/flectone/chat/module/serverMessage/death/DeathModule.java index 8ba8bab4..283dc1d3 100644 --- a/src/main/java/net/flectone/chat/module/serverMessage/death/DeathModule.java +++ b/src/main/java/net/flectone/chat/module/serverMessage/death/DeathModule.java @@ -28,6 +28,8 @@ public DeathModule(FModule module, String name) { public void init() { if (!isEnabled()) return; register(); + + actionManager.add(new DeathListener(this)); } public void sendAll(@NotNull Player sender, @NotNull PlayerDamager playerDamager, @NotNull String message) { @@ -123,17 +125,23 @@ public void createEntityComponent(@NotNull Player sender, @Nullable Player playe formatHoverMessage = MessageUtil.formatAll(sender, player, formatHoverMessage); - FComponentBuilder entityHoverComponentBuilder = new FComponentBuilder(formatHoverMessage); - - entityHoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> - hoverBuilder.append(new FColorComponent(new FLocaleComponent(NMSUtil.getMinecraftName(entity)), hoverColor).get())); - - entityHoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> - hoverBuilder.append(new FColorComponent(new FLocaleComponent(NMSUtil.getMinecraftType(entity)), hoverColor).get())); + FComponentBuilder entityHoverComponentBuilder = getfComponentBuilder(entity, formatHoverMessage); fLocaleComponent.addHoverText(entityHoverComponentBuilder.build(sender, player)); } componentBuilder.append(new FColorComponent(fLocaleComponent, color).get()); } + + @NotNull + private static FComponentBuilder getfComponentBuilder(@NotNull Entity entity, String formatHoverMessage) { + FComponentBuilder entityHoverComponentBuilder = new FComponentBuilder(formatHoverMessage); + + entityHoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> + hoverBuilder.append(new FColorComponent(new FLocaleComponent(NMSUtil.getMinecraftName(entity)), hoverColor).get())); + + entityHoverComponentBuilder.replace("", (hoverBuilder, hoverColor) -> + hoverBuilder.append(new FColorComponent(new FLocaleComponent(NMSUtil.getMinecraftType(entity)), hoverColor).get())); + return entityHoverComponentBuilder; + } } diff --git a/src/main/java/net/flectone/chat/util/NMSUtil.java b/src/main/java/net/flectone/chat/util/NMSUtil.java index 64cb4c45..96e1c31f 100644 --- a/src/main/java/net/flectone/chat/util/NMSUtil.java +++ b/src/main/java/net/flectone/chat/util/NMSUtil.java @@ -95,44 +95,6 @@ public static String getMinecraftName(Entity entity) { return getMinecraftType(entity); } - /** - * @return 0 if the item has never been repaired or -1 if it is no longer repairable. - */ - public static int getXPForRepair(ItemStack is) { - try { - Object nmsStack = asNMSCopy(is); - - if (version >= 1.18) { - int cost = (int) is.getItemMeta().serialize().getOrDefault("repair-cost", 0); - boolean repairable = cost <= 40; - return repairable ? cost : -1; - } - - boolean hasTag = (boolean) nmsStack.getClass().getMethod("hasTag").invoke(nmsStack); - - if (!hasTag) - return 0; - - Object tag = nmsStack.getClass().getMethod("getTag").invoke(nmsStack); - - boolean hasKey = (boolean) tag.getClass().getMethod("hasKey", String.class).invoke(tag, "RepairCost"); - - if (!hasKey) - return 0; - - int cost = (int) tag.getClass().getMethod("getInt", String.class).invoke(tag, "RepairCost"); - - boolean repairable = cost <= 40; - - if (repairable) - return cost; - else - return -1; - } catch (Exception ex) { - return 0; - } - } - public static String getItemAsJson(ItemStack is) { String itemJson;