From cb818c00560c51c9d3c46e27df7cb3f6cab768bf Mon Sep 17 00:00:00 2001 From: Video Date: Wed, 5 Apr 2023 13:59:01 -0600 Subject: [PATCH 1/3] Removes the WorldGuardBridge It was unused after Paul rewrote the rainbow trail. --- .../totalfreedommod/TotalFreedomMod.java | 2 - .../bridge/WorldGuardBridge.java | 48 ------------------- 2 files changed, 50 deletions(-) delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index f9071f98..136c6c46 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -105,7 +105,6 @@ public class TotalFreedomMod extends JavaPlugin public LibsDisguisesBridge ldb; public CoreProtectBridge cpb; public WorldEditBridge web; - public WorldGuardBridge wgb; public LuckPermsBridge lpb; public static TotalFreedomMod getPlugin() @@ -327,7 +326,6 @@ public class TotalFreedomMod extends JavaPlugin esb = new EssentialsBridge(); ldb = new LibsDisguisesBridge(); web = new WorldEditBridge(); - wgb = new WorldGuardBridge(); lpb = new LuckPermsBridge(); } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java deleted file mode 100644 index e7632719..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java +++ /dev/null @@ -1,48 +0,0 @@ -package me.totalfreedom.totalfreedommod.bridge; - -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.regions.RegionContainer; - -import com.sk89q.worldguard.protection.regions.RegionQuery; -import me.totalfreedom.totalfreedommod.FreedomService; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public class WorldGuardBridge extends FreedomService -{ - @Override - public void onStart() - { - } - - @Override - public void onStop() - { - } - - public boolean canEditCurrentWorld(Player player) - { - // If WorldGuard integration is enabled, do a check with it. - if (isEnabled()) - { - LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); - - RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); - RegionQuery query = container.createQuery(); - - return query.testBuild(localPlayer.getLocation(), localPlayer); - } - - // If the plugin isn't present, return true. - return true; - } - - public boolean isEnabled() - { - Plugin plugin = server.getPluginManager().getPlugin("WorldGuard"); - - return plugin != null && plugin.isEnabled(); - } -} \ No newline at end of file From d1569cb3c0dcb89b459bf8f23a33c3bdc7071f89 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Wed, 5 Apr 2023 15:59:20 -0500 Subject: [PATCH 2/3] Luck Perms is actually based but also not based --- .../bridge/LuckPermsBridge.java | 15 ++-- .../command/Command_adventure.java | 60 ---------------- .../command/Command_clearinventory.java | 72 ------------------- .../command/Command_creative.java | 58 --------------- .../command/Command_nickmm.java | 40 +++++++++++ .../command/Command_spectator.java | 42 ----------- .../command/Command_survival.java | 59 --------------- .../rank/DisplayableGroup.java | 17 +++-- .../totalfreedommod/rank/RankManager.java | 11 +-- .../totalfreedommod/util/Interpolation.java | 52 ++++++++++++++ 10 files changed, 110 insertions(+), 316 deletions(-) delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adventure.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java create mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_survival.java 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 2fadc3f1..1103d373 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/bridge/LuckPermsBridge.java @@ -1,16 +1,12 @@ 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; import org.bukkit.plugin.UnknownDependencyException; -import java.util.concurrent.Executor; - public class LuckPermsBridge { private final LuckPerms luckPerms; @@ -38,7 +34,8 @@ public class LuckPermsBridge if (!trackManager.isLoaded("fakeOp")) { - trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) -> { + trackManager.createAndLoadTrack("fakeOp").whenComplete((track, exception) -> + { track.appendGroup(GroupProvider.NON_OP.getGroup().getLuckPermsGroup()); track.appendGroup(GroupProvider.OP.getGroup().getLuckPermsGroup()); }); @@ -46,7 +43,8 @@ public class LuckPermsBridge if (!trackManager.isLoaded("admin")) { - trackManager.createAndLoadTrack("admin").whenComplete((track, exception) -> { + trackManager.createAndLoadTrack("admin").whenComplete((track, exception) -> + { track.appendGroup(GroupProvider.ADMIN.getGroup().getLuckPermsGroup()); track.appendGroup(GroupProvider.SENIOR_ADMIN.getGroup().getLuckPermsGroup()); }); @@ -54,9 +52,8 @@ public class LuckPermsBridge if (!trackManager.isLoaded("builder")) { - trackManager.createAndLoadTrack("builder").whenComplete((track, exception) -> { - track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup()); - }); + trackManager.createAndLoadTrack("builder").whenComplete((track, exception) -> + track.appendGroup(GroupProvider.MASTER_BUILDER.getGroup().getLuckPermsGroup())); } } } diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adventure.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adventure.java deleted file mode 100644 index 06d286b6..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adventure.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(permission = "adventure", source = SourceType.BOTH) -@CommandParameters(description = "Quickly change your own gamemode to adventure, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/ <[partialname] | -a>", aliases = "gma") -public class Command_adventure extends FreedomCommand -{ - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length == 0) - { - if (isConsole()) - { - msgNew("When used from the console, you must define a target player."); - return true; - } - - playerSender.setGameMode(GameMode.ADVENTURE); - msgNew("Your gamemode has been set to adventure."); - return true; - } - - checkPermission("tfm.adventure.other"); - - if (args[0].equals("-a")) - { - FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to adventure", false); - - server.getOnlinePlayers().forEach(player -> - { - player.setGameMode(GameMode.ADVENTURE); - msgNew("Your gamemode has been set to adventure."); - }); - - return true; - } - - Player player = getPlayer(args[0]); - - if (player == null) - { - msg(PLAYER_NOT_FOUND); - return true; - } - - msgNew("Setting to game mode adventure.", Placeholder.unparsed("player", player.getName())); - player.setGameMode(GameMode.ADVENTURE); - msgNew(player, " set your game mode to adventure.", Placeholder.unparsed("sender", sender.getName())); - - return true; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java deleted file mode 100644 index 4c03f368..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java +++ /dev/null @@ -1,72 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Collections; -import java.util.List; - -@CommandPermissions(permission = "clearinventory", source = SourceType.BOTH) -@CommandParameters(description = "Clear your inventory.", usage = "/ [player]", aliases = "ci,clear") -public class Command_clearinventory extends FreedomCommand -{ - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length < 1) - { - if (senderIsConsole) - { - return false; - } - - playerSender.getInventory().clear(); - msgNew("Your inventory has been cleared."); - } else - { - if (plugin.al.isAdmin(sender)) - { - if (args[0].equals("-a")) - { - FUtil.adminAction(sender.getName(), "Clearing everyone's inventory", true); - server.getOnlinePlayers().forEach(player -> player.getInventory().clear()); - msgNew("Successfully cleared everyone's inventory."); - } else - { - Player player = getPlayer(args[0]); - - if (player == null) - { - msg(PLAYER_NOT_FOUND); - return true; - } - - player.getInventory().clear(); - msgNew("Successfully cleared 's inventory.", Placeholder.unparsed("player", player.getName())); - msgNew(player, " has cleared your inventory.", Placeholder.unparsed("sender", sender.getName())); - } - } else - { - return noPerms(); - } - } - - return true; - } - - @Override - public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) - { - if (args.length == 1 && plugin.al.isAdmin(sender)) - { - List players = FUtil.getPlayerList(); - players.add("-a"); - return players; - } - - return Collections.emptyList(); - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java deleted file mode 100644 index 7862b06b..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_creative.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(permission = "creative", source = SourceType.BOTH) -@CommandParameters(description = "Quickly change your own gamemode to creative, define someone's username to change theirs, or change everyone's gamemode on the server.", usage = "/ <-a | [partialname]>", aliases = "gmc") -public class Command_creative extends FreedomCommand -{ - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length == 0) - { - if (isConsole()) - { - msgNew("When used from the console, you must define a target player."); - return true; - } - - playerSender.setGameMode(GameMode.CREATIVE); - msgNew("Your gamemode has been set to creative."); - return true; - } - - checkPermission("tfm.creative.other"); - - if (args[0].equals("-a")) - { - FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to creative", false); - - server.getOnlinePlayers().forEach(player -> - { - player.setGameMode(GameMode.CREATIVE); - msgNew(player, "Your gamemode has been set to creative."); - }); - - return true; - } - - Player player = getPlayer(args[0]); - - if (player == null) - { - msg(PLAYER_NOT_FOUND); - return true; - } - - msgNew("Setting to gamemode creative.", Placeholder.unparsed("player", player.getName())); - msgNew(player, " set your gamemode to creative.", Placeholder.unparsed("sender", sender.getName())); - player.setGameMode(GameMode.CREATIVE); - return true; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java new file mode 100644 index 00000000..6fcc6a7a --- /dev/null +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java @@ -0,0 +1,40 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.util.FUtil; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(permission = "nickmm", source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Essentials Interface Command - Colorify your nickname.", usage = "/") +public class Command_nickmm extends FreedomCommand +{ + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (!server.getPluginManager().isPluginEnabled("Essentials")) + { + msg("Essentials is not enabled on this server."); + return true; + } + + if (args[0].isEmpty()) { + return false; + } + + if (args[0].matches(ChatColor.COLOR_CHAR + "[0-9a-fkm-o]")) + { + msgNew("That nickname contains invalid characters."); + return true; + } + + Component parsed = FUtil.miniMessage(args[0], Placeholder.unparsed("", sender.getName())); + plugin.esb.setNickname(sender.getName(), FUtil.miniMessage(parsed)); + msgNew("Your nickname is now: " + FUtil.miniMessage(parsed)); + + return false; + } +} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java deleted file mode 100644 index a15109b7..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectator.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(permission = "spectate", source = SourceType.BOTH) -@CommandParameters(description = "Quickly change your own gamemode to spectator, or define someone's username to change theirs.", usage = "/ <[partialname]>", aliases = "gmsp") -public class Command_spectator extends FreedomCommand -{ - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length == 0) - { - if (isConsole()) - { - msgNew("When used from the console, you must define a target player."); - return true; - } - - playerSender.setGameMode(GameMode.SPECTATOR); - msgNew("Your gamemode has been set to spectator."); - return true; - } - - Player player = getPlayer(args[0]); - - if (player == null) - { - msg(PLAYER_NOT_FOUND); - return true; - } - - msgNew("Setting to gamemode spectator", Placeholder.unparsed("player", player.getName())); - player.setGameMode(GameMode.SPECTATOR); - msgNew(player, " set your gamemode to spectator.", Placeholder.unparsed("sender", sender.getName())); - return true; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_survival.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_survival.java deleted file mode 100644 index 77082540..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_survival.java +++ /dev/null @@ -1,59 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(permission = "survival", source = SourceType.BOTH) -@CommandParameters(description = "Quickly change your own gamemode to survival, or define someone's username to change theirs.", usage = "/ <[partialname] | -a>", aliases = "gms") -public class Command_survival extends FreedomCommand -{ - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length == 0) - { - if (isConsole()) - { - msgNew("When used from the console, you must define a target player."); - return true; - } - - playerSender.setGameMode(GameMode.SURVIVAL); - msgNew("Your gamemode has been set to survival."); - return true; - } - - checkPermission("tfm.survival.other"); - - if (args[0].equals("-a")) - { - FUtil.adminAction(sender.getName(), "Changing everyone's gamemode to survival", false); - - server.getOnlinePlayers().forEach(player -> - { - player.setGameMode(GameMode.SURVIVAL); - msgNew(player, "Your gamemode has been set to survival."); - }); - - return true; - } - - Player player = getPlayer(args[0]); - - if (player == null) - { - msg(PLAYER_NOT_FOUND); - return true; - } - - msgNew("Setting to gamemode survival", Placeholder.unparsed("player", player.getName())); - player.setGameMode(GameMode.SURVIVAL); - msgNew(player, " set your gamemode to survival.", Placeholder.unparsed("sender", sender.getName())); - return true; - } -} 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 7f393128..621b6669 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/DisplayableGroup.java @@ -9,9 +9,7 @@ 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; import org.apache.commons.lang.StringUtils; -import org.bukkit.util.FileUtil; import org.jetbrains.annotations.NotNull; import java.util.Locale; @@ -52,20 +50,23 @@ public class DisplayableGroup implements Displayable { Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group); - if (matched == null) { + if (matched == null) + { CompletableFuture cfg = TotalFreedomMod.getPlugin() .lpb .getAPI() .getGroupManager() .createAndLoadGroup(group); - cfg.thenAcceptAsync(g -> { + 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(); - if (inheritance != null) { + if (inheritance != null) + { InheritanceNode inheritanceNode = InheritanceNode.builder(inheritance).build(); g.getData(DataType.NORMAL).add(inheritanceNode); } @@ -75,7 +76,8 @@ public class DisplayableGroup implements Displayable matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group); - if (matched == null) throw new IllegalArgumentException("Group " + group + " does not exist and could not be created."); + if (matched == null) + throw new IllegalArgumentException("Group " + group + " does not exist and could not be created."); } this.group = matched; @@ -103,7 +105,8 @@ public class DisplayableGroup implements Displayable return weight; } - public Group getLuckPermsGroup() { + public Group getLuckPermsGroup() + { return this.group; } 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 355751f8..5118aae4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -1,7 +1,6 @@ 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,11 +8,7 @@ import me.totalfreedom.totalfreedommod.player.PlayerData; 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; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -174,8 +169,7 @@ public class RankManager extends FreedomService if (plugin.al.isAdmin(player) || data.isMasterBuilder() || FUtil.isDeveloper(player)) { player.playerListName(Component.text(player.getName()).color(display.getColor())); - } - else + } else { fPlayer.setTag(null); player.setPlayerListName(null); @@ -230,8 +224,7 @@ public class RankManager extends FreedomService if (playerData.hasLoginMessage()) { message = playerData.getLoginMessage(); - } - else + } else { if (display.hasDefaultLoginMessage()) { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/Interpolation.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/Interpolation.java index 4b3fafbf..c85bd997 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/Interpolation.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/Interpolation.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.util; import me.totalfreedom.totalfreedommod.api.Interpolator; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; import org.bukkit.Color; import java.util.LinkedHashSet; @@ -55,4 +57,54 @@ public class Interpolation } return gradient; } + + public LinkedHashSet rgbGradient(int length, Color from, Color to, Interpolator interpolator) + { + final double[] r = interpolator.interpolate(from.getRed(), to.getRed(), length); + final double[] g = interpolator.interpolate(from.getGreen(), to.getGreen(), length); + final double[] b = interpolator.interpolate(from.getBlue(), to.getBlue(), length); + + final LinkedHashSet gradient = new LinkedHashSet<>(); + + for (int i = 0; i < length; i++) + { + final Color color = Color.fromRGB((int) r[i], (int) g[i], (int) b[i]); + gradient.add(color); + } + return gradient; + } + + public LinkedHashSet componentRGBGradient(int length, TextColor from, TextColor to, Interpolator interpolator) + { + final double[] r = interpolator.interpolate(from.red(), to.red(), length); + final double[] g = interpolator.interpolate(from.green(), to.green(), length); + final double[] b = interpolator.interpolate(from.blue(), to.blue(), length); + + final LinkedHashSet gradient = new LinkedHashSet<>(); + + for (int i = 0; i < length; i++) + { + final TextColor color = TextColor.color((int) r[i], (int) g[i], (int) b[i]); + gradient.add(color); + } + return gradient; + } + + public LinkedHashSet rainbowComponent(int length) + { + LinkedHashSet base = new LinkedHashSet<>(); + LinkedHashSet redToOrange = componentRGBGradient(length, NamedTextColor.RED, NamedTextColor.GOLD, this::linear); + LinkedHashSet orangeToYellow = componentRGBGradient(length, NamedTextColor.GOLD, NamedTextColor.YELLOW, this::linear); + LinkedHashSet yellowToGreen = componentRGBGradient(length, NamedTextColor.YELLOW, NamedTextColor.GREEN, this::linear); + LinkedHashSet greenToBlue = componentRGBGradient(length, NamedTextColor.GREEN, NamedTextColor.BLUE, this::linear); + LinkedHashSet blueToPurple = componentRGBGradient(length, NamedTextColor.BLUE, NamedTextColor.LIGHT_PURPLE, this::linear); + LinkedHashSet purpleToRed = componentRGBGradient(length, TextColor.color(75, 0, 130), TextColor.color(255, 0, 0), this::linear); + base.addAll(redToOrange); + base.addAll(orangeToYellow); + base.addAll(yellowToGreen); + base.addAll(greenToBlue); + base.addAll(blueToPurple); + base.addAll(purpleToRed); + return base; + } } From b29a176fa9a854634b0349845c817e38504cfa90 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Wed, 5 Apr 2023 16:38:31 -0500 Subject: [PATCH 3/3] minor fixing --- .../command/Command_nickgradient.java | 97 ------------------- .../command/Command_nickmm.java | 6 +- .../command/Command_nickrainbow.java | 64 ------------ .../totalfreedommod/rank/Title.java | 1 - .../totalfreedommod/util/FUtil.java | 1 + .../discord/listener/AdminChatListener.java | 58 +++++------ .../discord/util/SnowflakeEntry.java | 15 +++ 7 files changed, 51 insertions(+), 191 deletions(-) delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java deleted file mode 100644 index 833dc13b..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickgradient.java +++ /dev/null @@ -1,97 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.api.Interpolator; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.apache.commons.lang3.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.List; - -@CommandPermissions(permission = "nickgradient", source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/ ", aliases = "nickgr") -public class Command_nickgradient extends FreedomCommand -{ - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (!server.getPluginManager().isPluginEnabled("Essentials")) - { - msg("Essentials is not enabled on this server."); - return true; - } - - if (args.length != 3) - { - return false; - } - - String nick = args[2].trim(); - - if (nick.length() < 3 || nick.length() > 30) - { - msg("Your nickname must be between 3 and 30 characters long."); - return true; - } - - for (Player player : Bukkit.getOnlinePlayers()) - { - if (player == playerSender) - { - continue; - } - if (player.getName().equalsIgnoreCase(nick) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nick)) - { - msg("That nickname is already in use."); - return true; - } - } - - String from = "", to = ""; - java.awt.Color awt1, awt2; - try - { - if (args[0].equalsIgnoreCase("random") || - args[0].equalsIgnoreCase("r")) - { - awt1 = FUtil.getRandomAWTColor(); - from = " (From: " + FUtil.getHexStringOfAWTColor(awt1) + ")"; - } else - { - awt1 = java.awt.Color.decode(args[0]); - } - if (args[1].equalsIgnoreCase("random") || - args[1].equalsIgnoreCase("r")) - { - awt2 = FUtil.getRandomAWTColor(); - to = " (To: " + FUtil.getHexStringOfAWTColor(awt2) + ")"; - } else - { - awt2 = java.awt.Color.decode(args[1]); - } - } catch (NumberFormatException ex) - { - msg("Invalid hex values."); - return true; - } - Color c1 = FUtil.fromAWT(awt1); - Color c2 = FUtil.fromAWT(awt2); - List gradient = FUtil.createColorGradient(c1, c2, nick.length()); - String[] splitNick = nick.split(""); - for (int i = 0; i < splitNick.length; i++) - { - splitNick[i] = net.md_5.bungee.api.ChatColor.of(FUtil.toAWT(gradient.get(i))) + splitNick[i]; - } - nick = StringUtils.join(splitNick, ""); - final String outputNick = FUtil.colorize(nick); - - plugin.esb.setNickname(sender.getName(), outputNick); - - msg("Your nickname is now: '" + outputNick + ChatColor.GRAY + "'" + from + to); - return true; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java index 6fcc6a7a..0d69b9ec 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickmm.java @@ -9,7 +9,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(permission = "nickmm", source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Essentials Interface Command - Colorify your nickname.", usage = "/") +@CommandParameters(description = """ + Essentials Interface Command - Colorify your nickname. + For Example: /nickmm will color your name red. + You can also use tags like and . + For example: /nickmm """, usage = "/ ") public class Command_nickmm extends FreedomCommand { @Override diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java deleted file mode 100644 index ade5ffe9..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_nickrainbow.java +++ /dev/null @@ -1,64 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.util.FUtil; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandPermissions(permission = "nickrainbow", source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/ ") -public class Command_nickrainbow extends FreedomCommand -{ - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (!server.getPluginManager().isPluginEnabled("Essentials")) - { - msgNew("Essentials is not enabled on this server."); - return true; - } - - if (args.length != 1) - { - return false; - } - - final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim())); - - if (!nickPlain.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$")) - { - msgNew("That nickname contains invalid characters."); - return true; - } - - if (nickPlain.length() < 3 || nickPlain.length() > 30) - { - msgNew("Your nickname must be between 3 and 30 characters long."); - return true; - } - - for (Player player : Bukkit.getOnlinePlayers()) - { - if (player == playerSender) - { - continue; - } - if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain)) - { - msgNew("That nickname is already in use."); - return true; - } - } - - final String newNick = FUtil.rainbowify(ChatColor.stripColor(FUtil.colorize(nickPlain))); - - plugin.esb.setNickname(sender.getName(), newNick); - - msgNew("Your nickname is now: ", Placeholder.component("new", FUtil.colorizeAsComponent(newNick))); - - return true; - } -} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java index a7ddef65..9bfd2a8b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java @@ -6,7 +6,6 @@ import net.kyori.adventure.text.format.TextColor; public enum Title implements Displayable { - MASTER_BUILDER(Component.text("a"), Component.text("Master Builder"), Component.text("Master Builders"), 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 94a78b16..eadb880b 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -88,6 +88,7 @@ public class FUtil StandardTags.color(), StandardTags.rainbow(), StandardTags.gradient(), + StandardTags.newline(), StandardTags.decorations(TextDecoration.ITALIC), StandardTags.decorations(TextDecoration.BOLD), StandardTags.decorations(TextDecoration.STRIKETHROUGH), diff --git a/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java b/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java index a0e8b46d..052577ea 100644 --- a/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java +++ b/discord/src/main/java/me/totalfreedom/discord/listener/AdminChatListener.java @@ -129,33 +129,35 @@ public class AdminChatListener // Server Owner if (server == null) throw new IllegalStateException(); - return member.getRoles().map(role -> - { - if (role.getId().equals(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake())) - { - return Title.OWNER; - } else if (role.getId().equals(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake())) - { - return Title.DEVELOPER; - } else if (role.getId().equals(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake())) - { - return Title.EXECUTIVE; - } else if (role.getId().equals(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake())) - { - return Title.ASST_EXEC; - } else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake())) - { - return GroupProvider.SENIOR_ADMIN.getGroup(); - } else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake())) - { - return GroupProvider.ADMIN.getGroup(); - } else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake())) - { - return GroupProvider.MASTER_BUILDER.getGroup(); - } else - { - return null; - } - }).blockFirst(); + return member.getRoles() + .filter(role -> SnowflakeEntry.acceptableRoleIDs().contains(role.getId())) + .map(role -> + { + if (role.getId().equals(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake())) + { + return Title.OWNER; + } else if (role.getId().equals(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake())) + { + return Title.DEVELOPER; + } else if (role.getId().equals(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake())) + { + return Title.EXECUTIVE; + } else if (role.getId().equals(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake())) + { + return Title.ASST_EXEC; + } else if (role.getId().equals(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake())) + { + return GroupProvider.SENIOR_ADMIN.getGroup(); + } else if (role.getId().equals(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake())) + { + return GroupProvider.ADMIN.getGroup(); + } else if (role.getId().equals(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake())) + { + return GroupProvider.MASTER_BUILDER.getGroup(); + } else + { + return GroupProvider.OP.getGroup(); // This should only be reached when a user doesn't + } + }).blockFirst(); } } diff --git a/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java b/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java index d064ad5a..ef990776 100644 --- a/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java +++ b/discord/src/main/java/me/totalfreedom/discord/util/SnowflakeEntry.java @@ -3,6 +3,9 @@ package me.totalfreedom.discord.util; import discord4j.common.util.Snowflake; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import java.util.HashSet; +import java.util.Set; + public enum SnowflakeEntry { ADMIN_CHAT_CHANNEL_ID(ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID), @@ -32,4 +35,16 @@ public enum SnowflakeEntry { return Snowflake.of(entry.getString()); } + + public static Set acceptableRoleIDs() { + Set acceptableRoleIDs = new HashSet<>(); + acceptableRoleIDs.add(SnowflakeEntry.OWNER_ROLE_ID.getSnowflake()); + acceptableRoleIDs.add(SnowflakeEntry.DEVELOPER_ROLE_ID.getSnowflake()); + acceptableRoleIDs.add(SnowflakeEntry.EXECUTIVE_ROLE_ID.getSnowflake()); + acceptableRoleIDs.add(SnowflakeEntry.ASSISTANT_EXECUTIVE_ROLE_ID.getSnowflake()); + acceptableRoleIDs.add(SnowflakeEntry.SENIOR_ADMIN_ROLE_ID.getSnowflake()); + acceptableRoleIDs.add(SnowflakeEntry.ADMIN_ROLE_ID.getSnowflake()); + acceptableRoleIDs.add(SnowflakeEntry.MASTERBUILDER_ROLE_ID.getSnowflake()); + return acceptableRoleIDs; + } }