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