From 3166680e94906a11b915baa8f490bc69cb81da1f Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Tue, 23 Jun 2020 20:37:02 -0400 Subject: [PATCH] guild commands only for admins --- pom.xml | 2 +- .../me/totalfreedom/tfguilds/TFGuilds.java | 1 + .../tfguilds/command/GuildAdminCommand.java | 84 +++++++++++++++++++ .../me/totalfreedom/tfguilds/util/GUtil.java | 7 ++ src/main/resources/plugin.yml | 5 +- 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/GuildAdminCommand.java diff --git a/pom.xml b/pom.xml index 6482e03..aa7d915 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.totalfreedom TFGuilds - 0.1.2 + 0.1.3 jar TFGuilds diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java index 38efc64..3933d73 100644 --- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java +++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java @@ -47,6 +47,7 @@ public final class TFGuilds extends JavaPlugin this.getCommand("leaveguild").setExecutor(new LeaveGuildCommand()); this.getCommand("guildkick").setExecutor(new GuildKickCommand()); this.getCommand("guildinfo").setExecutor(new GuildInfoCommand()); + this.getCommand("guildadmin").setExecutor(new GuildAdminCommand()); } private void enableListeners() diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildAdminCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildAdminCommand.java new file mode 100644 index 0000000..8781cc2 --- /dev/null +++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildAdminCommand.java @@ -0,0 +1,84 @@ +package me.totalfreedom.tfguilds.command; + +import me.totalfreedom.tfguilds.util.GBase; +import me.totalfreedom.tfguilds.util.GLog; +import me.totalfreedom.tfguilds.util.GUtil; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +public class GuildAdminCommand extends GBase implements CommandExecutor +{ + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) + { + Player player = (Player) sender; + if (!plugin.tfmb.isAdmin(player)) + { + player.sendMessage(ChatColor.RED + "No permission."); + return true; + } + + if (args.length != 2) + { + return false; + } + + String guild = GUtil.getGuild(args[1]); + if (guild == null) + { + player.sendMessage(ChatColor.RED + "Guild not found."); + return true; + } + + if (args[0].equalsIgnoreCase("cleartag")) + { + GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r "), guild); + player.sendMessage(ChatColor.GREEN + "Successfully cleared tag for guild " + guild); + return true; + } + + if (args[0].equalsIgnoreCase("disbandguild")) + { + GUtil.deleteGuild(guild); + Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded")); + player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + "."); + GLog.info(player.getName() + " deleted guild " + guild); + return true; + } + + if (args[0].equalsIgnoreCase("join")) + { + if (GUtil.isConsole(sender)) + { + sender.sendMessage(ChatColor.RED + "You are not allowed to run this command."); + return true; + } + + if (GUtil.isGuildMember(player, GUtil.getGuild(player))) + { + player.sendMessage(ChatColor.RED + "You are already in a guild."); + return true; + } + + List players = plugin.guilds.getStringList("guilds." + guild + ".members"); + players.add(player.getName()); + plugin.guilds.set("guilds." + guild + ".members", players); + plugin.guilds.save(); + player.sendMessage(ChatColor.GREEN + "You have successfully joined " + guild); + for (Player p : Bukkit.getOnlinePlayers()) + { + if (GUtil.isGuildMember(p, guild)) + { + p.sendMessage(ChatColor.GREEN + player.getName() + " has joined the guild"); + } + } + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java index 97b0523..3a27a4d 100644 --- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java +++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java @@ -51,6 +51,13 @@ public class GUtil plugin.guilds.save(); } + public static void deleteGuild(String guildName) + { + GLog.info("Removing guilds.yml data for " + guildName); + plugin.guilds.set("guilds." + guildName, null); + plugin.guilds.save(); + } + public static void invitePlayer(Player player, String guild, int seconds) { if (seconds > 0) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5aa28b1..c153279 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -43,4 +43,7 @@ commands: usage: / guildinfo: description: Gives you information about any guild - usage: / \ No newline at end of file + usage: / + guildadmin: + description: Guild commands only for admins + usage: / \ No newline at end of file