From da6471941e309e165ccc76595eee644c9edcaa8f Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Sat, 8 Aug 2020 14:19:40 -0400 Subject: [PATCH] add %rank% for guild tags --- pom.xml | 2 +- .../command/CreateRankSubcommand.java | 14 ++++++ .../tfguilds/command/GuildCommand.java | 44 ++++++++++++++++++- .../tfguilds/command/TFGuildsCommand.java | 3 +- .../tfguilds/command/TagSubcommand.java | 2 +- .../me/totalfreedom/tfguilds/guild/Guild.java | 7 ++- .../tfguilds/listener/ChatListener.java | 33 +++++++++++++- 7 files changed, 94 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index f34fd0a..801966c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.totalfreedom TFGuilds - 0.2.7 + 0.2.9 jar TFGuilds diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java index 31468c5..9d6519c 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java @@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command; import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.guild.Guild; +import me.totalfreedom.tfguilds.util.GUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -41,6 +42,19 @@ public class CreateRankSubcommand extends Common implements CommandExecutor } String rank = StringUtils.join(args, " ", 1, args.length); + + for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS) + { + if (rank.equalsIgnoreCase(blacklisted)) + { + if (!plugin.bridge.isAdmin(player)) + { + player.sendMessage(ChatColor.RED + "You may not use that name."); + return true; + } + } + } + if (guild.hasRank(rank)) { sender.sendMessage(ChatColor.RED + "A rank of that name already exists in the guild!"); diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java index a84706c..ae9b27b 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java @@ -88,26 +88,66 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete switch (args[0]) { case "home": + { return Arrays.asList("set"); + } + case "info": case "join": case "roster": + { return Guild.getGuildList(); + } + case "motd": case "tag": + { return Arrays.asList("set", "clear"); + } + case "setstate": + { return Arrays.asList("OPEN", "INVITE", "CLOSED"); + } + case "invite": + { return GUtil.getPlayerList(); + } + case "deleterank": - return guild.getRankNames(); + { + if (guild.getOwner().equals(sender.getName())) + { + return guild.getRankNames(); + } + } + case "tp": + { + return guild.getMembers(); + } + + case "disband": + { + if (!plugin.bridge.isAdmin(sender)) + { + return Collections.emptyList(); + } + + return Guild.getGuildList(); + } + case "removemod": case "addmod": case "setowner": case "kick": - return guild.getMembers(); + { + if (guild.getOwner().equals(sender.getName())) + { + return guild.getMembers(); + } + } } } return Collections.emptyList(); diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java index 188682e..d73c737 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java @@ -1,5 +1,6 @@ package me.totalfreedom.tfguilds.command; +import java.util.UUID; import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.util.GLog; import org.bukkit.Bukkit; @@ -8,8 +9,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import java.util.UUID; - public class TFGuildsCommand extends Common implements CommandExecutor { @Override diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java index bdde8b7..fe49087 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java @@ -69,7 +69,7 @@ public class TagSubcommand extends Common implements CommandExecutor guild.setTag(tag); guild.save(); - sender.sendMessage(tl("%p%Your guild tag has been changed to be \"" + GUtil.colorize(tag) + "%p%\".")); + sender.sendMessage(tl("%p%Your guild tag has been changed to be \"" + GUtil.colorize(tag).replace("%rank%", ChatColor.GOLD +"Guild Owner") + "%p%\".")); return true; } return false; diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java index a9d2437..ff46903 100644 --- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java +++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java @@ -1,5 +1,8 @@ package me.totalfreedom.tfguilds.guild; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import lombok.Getter; import lombok.Setter; import me.totalfreedom.tfguilds.TFGuilds; @@ -15,10 +18,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - public class Guild { private static TFGuilds plugin = TFGuilds.getPlugin(); diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java index d166b0e..0ba00bd 100644 --- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java +++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java @@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.listener; import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.guild.Guild; +import me.totalfreedom.tfguilds.guild.GuildRank; import me.totalfreedom.tfguilds.util.GUtil; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -22,6 +23,36 @@ public class ChatListener implements Listener return; } + GuildRank rank = null; + for (GuildRank r : guild.getRanks()) + { + if (r.getMembers().contains(player.getName())) + { + rank = r; + } + } + + String display; + if (rank == null) + { + if (guild.getOwner().equals(player.getName())) + { + display = "Guild Owner"; + } + else if (guild.hasModerator(player.getName())) + { + display = "Guild Moderator"; + } + else + { + display = "Guild Member"; + } + } + else + { + display = rank.getName(); + } + if (Common.IN_GUILD_CHAT.contains(player)) { guild.chat(player.getName(), e.getMessage()); @@ -31,7 +62,7 @@ public class ChatListener implements Listener if (guild.hasTag()) { - e.setFormat(GUtil.colorize(guild.getTag()) + ChatColor.RESET + " " + e.getFormat()); + e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat()); } } } \ No newline at end of file