From f474ce99fdce6bdeef5d2db434e6a33df13755c2 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Tue, 4 Apr 2023 17:42:05 -0500 Subject: [PATCH 1/4] Added inheritance to the groups when created by TFM. --- .../totalfreedommod/rank/DisplayableGroup.java | 11 ++++++++++- .../totalfreedommod/rank/GroupProvider.java | 10 +++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java index 73c56960..7f393128 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java @@ -6,6 +6,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; import net.luckperms.api.model.data.DataType; import net.luckperms.api.model.group.Group; +import net.luckperms.api.node.types.InheritanceNode; import net.luckperms.api.node.types.PrefixNode; import net.luckperms.api.node.types.WeightNode; import net.md_5.bungee.api.ChatColor; @@ -40,6 +41,7 @@ public class DisplayableGroup implements Displayable private final boolean hasDefaultLoginMessage; public DisplayableGroup(String group, + String inheritance, Component plural, Component tag, int weight, @@ -59,7 +61,14 @@ public class DisplayableGroup implements Displayable cfg.thenAcceptAsync(g -> { WeightNode weightNode = WeightNode.builder(weight).build(); - PrefixNode prefixNode = PrefixNode.builder().prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE))).priority(1).build(); + PrefixNode prefixNode = PrefixNode.builder() + .prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE))) + .priority(1) + .build(); + if (inheritance != null) { + InheritanceNode inheritanceNode = InheritanceNode.builder(inheritance).build(); + g.getData(DataType.NORMAL).add(inheritanceNode); + } g.getData(DataType.NORMAL).add(prefixNode); g.getData(DataType.NORMAL).add(weightNode); }).join(); // Block until the group is created and loaded. diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java index e87839c5..a1d025c3 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java @@ -15,11 +15,11 @@ public interface GroupProvider Component OPEN = Component.text("[", NamedTextColor.DARK_GRAY); Component CLOSE = Component.text("]", NamedTextColor.DARK_GRAY); - GroupProvider NON_OP = () -> new DisplayableGroup("non_op", Component.text("Non-Ops"), Component.empty(), 0, NamedTextColor.WHITE, null, false, false); - GroupProvider OP = () -> new DisplayableGroup("op", Component.text("Operators"), Component.text("Op"), 1, NamedTextColor.GREEN, null, false, false); - GroupProvider MASTER_BUILDER = () -> new DisplayableGroup("builder", Component.text("Master Builders"), Component.text("MB"), 2, NamedTextColor.DARK_AQUA, ChatColor.DARK_AQUA, true, true); - GroupProvider ADMIN = () -> new DisplayableGroup("admin", Component.text("Administrators"), Component.text("Admin"), 3, NamedTextColor.DARK_GREEN, ChatColor.DARK_GREEN, true, true); - GroupProvider SENIOR_ADMIN = () -> new DisplayableGroup("senior", Component.text("Senior Administrators"), Component.text("SrA"), 4, NamedTextColor.GOLD, ChatColor.GOLD, true, true); + GroupProvider NON_OP = () -> new DisplayableGroup("non_op", null,Component.text("Non-Ops"), Component.empty(), 0, NamedTextColor.WHITE, null, false, false); + GroupProvider OP = () -> new DisplayableGroup("op", "non_op", Component.text("Operators"), Component.text("Op"), 1, NamedTextColor.GREEN, null, false, false); + GroupProvider MASTER_BUILDER = () -> new DisplayableGroup("builder", "op", Component.text("Master Builders"), Component.text("MB"), 2, NamedTextColor.DARK_AQUA, ChatColor.DARK_AQUA, true, true); + GroupProvider ADMIN = () -> new DisplayableGroup("admin", "builder", Component.text("Administrators"), Component.text("Admin"), 3, NamedTextColor.DARK_GREEN, ChatColor.DARK_GREEN, true, true); + GroupProvider SENIOR_ADMIN = () -> new DisplayableGroup("senior", "admin", Component.text("Senior Administrators"), Component.text("SrA"), 4, NamedTextColor.GOLD, ChatColor.GOLD, true, true); static User getUser(Player player) { From 773805101be826b0cf35c394474a8fa534423081 Mon Sep 17 00:00:00 2001 From: Video Date: Tue, 4 Apr 2023 20:25:17 -0600 Subject: [PATCH 2/4] Convert tags automatically when loading them in to avoid errors --- .../totalfreedom/totalfreedommod/player/PlayerData.java | 9 ++++++++- .../java/me/totalfreedom/totalfreedommod/util/FUtil.java | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java index 2872a2f8..08e648ce 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java @@ -53,7 +53,14 @@ public class PlayerData ips.addAll(FUtil.stringToList(resultSet.getString("ips"))); notes.clear(); notes.addAll(FUtil.stringToList(resultSet.getString("notes"))); - tag = FUtil.miniMessage(resultSet.getString("tag")); + String tempTag = resultSet.getString("tag"); + //-- + if (!Strings.isNullOrEmpty(tempTag) && FUtil.containsChatColor(tempTag)) + { + tempTag = FUtil.miniMessage(FUtil.colorizeAsComponentSection(tempTag)); + } + //-- + tag = FUtil.miniMessage(tempTag); discordID = resultSet.getString("discord_id"); masterBuilder = resultSet.getBoolean("master_builder"); rideMode = RideMode.valueOf(resultSet.getString("ride_mode").toUpperCase()); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 12c40e64..7aa8f2b8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -83,6 +83,7 @@ public class FUtil private static final PlainTextComponentSerializer STEAMROLLER = PlainTextComponentSerializer.plainText(); public static final LegacyComponentSerializer LEGACY_AMPERSAND = LegacyComponentSerializer.legacyAmpersand(); + public static final LegacyComponentSerializer LEGACY_SECTION = LegacyComponentSerializer.legacySection(); public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(TagResolver.resolver( StandardTags.color(), StandardTags.rainbow(), @@ -490,6 +491,11 @@ public class FUtil return LEGACY_AMPERSAND.deserialize(string); } + public static Component colorizeAsComponentSection(String string) + { + return LEGACY_SECTION.deserialize(string); + } + public static Component miniMessage(String string, TagResolver... placeholders) { return MINI_MESSAGE.deserialize(string, placeholders); From 5422ad6ac7dae8dde3c740afc126ac735d13d0e2 Mon Sep 17 00:00:00 2001 From: Video Date: Tue, 4 Apr 2023 20:40:26 -0600 Subject: [PATCH 3/4] Fucking shit --- .../main/java/me/totalfreedom/totalfreedommod/util/FUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 7aa8f2b8..94a78b16 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -105,7 +105,7 @@ public class FUtil ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE); - private static final Pattern CHATCOLOR_PATTERN = Pattern.compile(".*(?i)(&((#[a-f0-9]{3,6})|([0-9a-fklmnor]))).*"); + private static final Pattern CHATCOLOR_PATTERN = Pattern.compile(".*(?i)(([ยง&])((#[a-f0-9]{3,6})|([0-9a-fklmnor]))).*"); private static final SplittableRandom RANDOM = new SplittableRandom(); public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; private static final List regxList = Arrays.asList("y", "mo", "w", "d", "h", "m", "s"); From 51c807d318e85fd4d4fe2b311e8c1a2a5c71a3c2 Mon Sep 17 00:00:00 2001 From: Video Date: Wed, 5 Apr 2023 10:54:39 -0600 Subject: [PATCH 4/4] Bugfixes, begin working on LP tracks --- .../bridge/LuckPermsBridge.java | 33 +++++++++++++++++++ .../totalfreedommod/rank/GroupProvider.java | 5 +-- .../totalfreedommod/rank/RankManager.java | 3 ++ .../java/me/totalfreedom/discord/TFD4J.java | 2 ++ .../main/java/me/totalfreedom/shop/Shop.java | 2 +- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java index c75e4fe4..2fadc3f1 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java @@ -1,6 +1,9 @@ package me.totalfreedom.totalfreedommod.bridge; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.rank.GroupProvider; import net.luckperms.api.LuckPerms; +import net.luckperms.api.track.TrackManager; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; @@ -20,10 +23,40 @@ public class LuckPermsBridge if (provider == null) throw new UnknownDependencyException("LuckPerms must be present!"); this.luckPerms = provider.getProvider(); + + setupTracks(); } public LuckPerms getAPI() { return luckPerms; } + + public void setupTracks() + { + TrackManager trackManager = getAPI().getTrackManager(); + + if (!trackManager.isLoaded("fakeOp")) + { + trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) -> { + track.appendGroup(GroupProvider.NON_OP.getGroup().getLuckPermsGroup()); + track.appendGroup(GroupProvider.OP.getGroup().getLuckPermsGroup()); + }); + } + + if (!trackManager.isLoaded("admin")) + { + trackManager.createAndLoadTrack("admin").whenComplete((track, exception) -> { + track.appendGroup(GroupProvider.ADMIN.getGroup().getLuckPermsGroup()); + track.appendGroup(GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup()); + }); + } + + if (!trackManager.isLoaded("builder")) + { + trackManager.createAndLoadTrack("builder").whenComplete((track, exception) -> { + track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup()); + }); + } + } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java index a1d025c3..172dc14b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/GroupProvider.java @@ -4,6 +4,7 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.luckperms.api.model.user.User; +import net.luckperms.api.track.TrackManager; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -15,8 +16,8 @@ public interface GroupProvider Component OPEN = Component.text("[", NamedTextColor.DARK_GRAY); Component CLOSE = Component.text("]", NamedTextColor.DARK_GRAY); - GroupProvider NON_OP = () -> new DisplayableGroup("non_op", null,Component.text("Non-Ops"), Component.empty(), 0, NamedTextColor.WHITE, null, false, false); - GroupProvider OP = () -> new DisplayableGroup("op", "non_op", Component.text("Operators"), Component.text("Op"), 1, NamedTextColor.GREEN, null, false, false); + GroupProvider NON_OP = () -> new DisplayableGroup("default", null, Component.text("Non-Ops"), Component.empty(), 0, NamedTextColor.WHITE, null, false, false); + GroupProvider OP = () -> new DisplayableGroup("op", "default", Component.text("Operators"), Component.text("Op"), 1, NamedTextColor.GREEN, null, false, false); GroupProvider MASTER_BUILDER = () -> new DisplayableGroup("builder", "op", Component.text("Master Builders"), Component.text("MB"), 2, NamedTextColor.DARK_AQUA, ChatColor.DARK_AQUA, true, true); GroupProvider ADMIN = () -> new DisplayableGroup("admin", "builder", Component.text("Administrators"), Component.text("Admin"), 3, NamedTextColor.DARK_GREEN, ChatColor.DARK_GREEN, true, true); GroupProvider SENIOR_ADMIN = () -> new DisplayableGroup("senior", "admin", Component.text("Senior Administrators"), Component.text("SrA"), 4, NamedTextColor.GOLD, ChatColor.GOLD, true, true); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index 6cdc1155..355751f8 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -1,6 +1,7 @@ package me.totalfreedom.totalfreedommod.rank; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; @@ -9,6 +10,8 @@ import me.totalfreedom.totalfreedommod.util.FUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.luckperms.api.context.ContextSetFactory; +import net.luckperms.api.track.TrackManager; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; diff --git a/discord/src/main/java/me/totalfreedom/discord/TFD4J.java b/discord/src/main/java/me/totalfreedom/discord/TFD4J.java index 899d1b18..08376d0b 100644 --- a/discord/src/main/java/me/totalfreedom/discord/TFD4J.java +++ b/discord/src/main/java/me/totalfreedom/discord/TFD4J.java @@ -12,6 +12,7 @@ import me.totalfreedom.discord.react.ReactiveBukkitScheduler; import me.totalfreedom.totalfreedommod.api.Context; import me.totalfreedom.totalfreedommod.api.TFD4JCommons; import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.StringUtil; import org.slf4j.Logger; @@ -49,6 +50,7 @@ public class TFD4J extends JavaPlugin slf4j().info(string); this.bn = new BukkitNative(this); + Bukkit.getPluginManager().registerEvents(this.bn, this); slf4j().info("Bukkit Native listener successfully registered! Registering the Discord4J Listeners..."); this.mc = new MinecraftListener(this); diff --git a/shop/src/main/java/me/totalfreedom/shop/Shop.java b/shop/src/main/java/me/totalfreedom/shop/Shop.java index a853eb64..7c447924 100644 --- a/shop/src/main/java/me/totalfreedom/shop/Shop.java +++ b/shop/src/main/java/me/totalfreedom/shop/Shop.java @@ -434,7 +434,7 @@ public class Shop extends FreedomService implements ShoppeCommons @EventHandler public void onPlayerChat(AsyncChatEvent event) { - String message = event.message().toString(); + String message = FUtil.steamroll(event.message()); Player player = event.getPlayer(); if (ConfigEntry.SHOP_ENABLED.getBoolean() && ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean()