From 50de5817e926c41026558e08f7f56984a7c0960b Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Mon, 10 Aug 2020 23:39:36 -0400 Subject: [PATCH] default guild ranks it works!!!!!!!!!!!!!! --- .../me/totalfreedom/tfguilds/TFGuilds.java | 2 +- .../command/DeleteRankSubcommand.java | 7 +++ .../tfguilds/command/GuildCommand.java | 5 +- .../tfguilds/command/HelpSubcommand.java | 1 + .../command/SetDefaultRankSubcommand.java | 63 +++++++++++++++++++ .../me/totalfreedom/tfguilds/guild/Guild.java | 29 ++++++++- 6 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java index 80dd168..a8bc827 100644 --- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java +++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java @@ -60,4 +60,4 @@ public final class TFGuilds extends JavaPlugin manager.registerEvents(new ChatListener(), this); manager.registerEvents(new JoinListener(), this); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java index a01f19f..b1f0e93 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java @@ -48,6 +48,13 @@ public class DeleteRankSubcommand extends Common implements CommandExecutor } guild.removeRank(rank); + + if (guild.hasDefaultRank() && rank.equals(guild.getDefaultRank())) + { + guild.setDefaultRank(null); + guild.save(); + } + sender.sendMessage(tl(PREFIX + "Deleted the rank named %s%" + rank + "%p% in your guild.")); guild.save(); return true; diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java index d32ebc4..3d744fc 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java @@ -66,6 +66,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete return new HomeSubcommand().onCommand(sender, command, label, args); case "roster": return new RosterSubcommand().onCommand(sender, command, label, args); + case "setdefaultrank": + return new SetDefaultRankSubcommand().onCommand(sender, command, label, args); } return false; } @@ -81,7 +83,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete return Arrays.asList("addmod", "chat", "createrank", "create", "deleterank", "disband", "help", "home", "info", "invite", "join", "kick", "leave", "list", "motd", "removemod", "rename", - "roster", "setowner", "setrank", "setstate", "tag", "tp"); + "roster", "setowner", "setrank", "setstate", "tag", "tp", "setdefaultrank"); } else if (args.length == 2) { @@ -116,6 +118,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete } case "deleterank": + case "setdefaultrank": { if (guild.getOwner().equals(sender.getName())) { diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java index 14f722f..ab77cbd 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java @@ -33,6 +33,7 @@ public class HelpSubcommand extends Common implements CommandExecutor sender.sendMessage(tl("%s% - %p%chat [message]")); sender.sendMessage(tl("%s% - %p%roster [guild | player]")); sender.sendMessage(tl("%s% - %p%setstate ")); + sender.sendMessage(tl("%s% - %p%setdefaultrank ")); return true; } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java new file mode 100644 index 0000000..cb6acda --- /dev/null +++ b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java @@ -0,0 +1,63 @@ +package me.totalfreedom.tfguilds.command; + +import me.totalfreedom.tfguilds.Common; +import me.totalfreedom.tfguilds.guild.Guild; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +public class SetDefaultRankSubcommand extends Common implements CommandExecutor +{ + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) + { + if (sender instanceof ConsoleCommandSender) + { + sender.sendMessage(NO_PERMS); + return true; + } + + if (args.length == 0) + { + return false; + } + + Player player = (Player)sender; + Guild guild = Guild.getGuild(player); + if (guild == null) + { + sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); + return true; + } + + if (!guild.getOwner().equals(player.getName())) + { + sender.sendMessage(ChatColor.RED + "You do not have permissions to manage ranks in your guild!"); + return true; + } + + String rank = StringUtils.join(args, " ", 1, args.length); + if (rank.equalsIgnoreCase("members") || rank.equalsIgnoreCase("member") || rank.equalsIgnoreCase("none")) + { + guild.setDefaultRank(null); + guild.save(); + sender.sendMessage(tl(PREFIX + "Removed the default guild rank.")); + return true; + } + + if (!guild.hasRank(rank)) + { + sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!"); + return true; + } + + guild.setDefaultRank(rank); + guild.save(); + sender.sendMessage(tl(PREFIX + "Set " + rank + " as the default rank for your guild.")); + return true; + } +} diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java index c8152cb..f3836b5 100644 --- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java +++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java @@ -59,6 +59,10 @@ public class Guild @Setter private Location home; + @Getter + @Setter + private String defaultRank; + @Getter private final long creation; @@ -72,7 +76,8 @@ public class Guild List ranks, String motd, Location home, - long creation) + long creation, + String defaultrank) { this.identifier = identifier; this.name = name; @@ -85,6 +90,7 @@ public class Guild this.motd = motd; this.home = home; this.creation = creation; + this.defaultRank = defaultrank; } public void save() @@ -102,11 +108,17 @@ public class Guild plugin.guilds.set(identifier + ".motd", motd); plugin.guilds.set(identifier + ".home", home); plugin.guilds.set(identifier + ".creation", creation); + plugin.guilds.set(identifier + ".defaultrank", defaultRank); plugin.guilds.save(); } public void addMember(String name) { + if (hasDefaultRank()) + { + getRank(defaultRank).getMembers().add(name); + } + members.add(name); } @@ -119,6 +131,10 @@ public class Guild } members.remove(name); + for (GuildRank gr : getRanks()) + { + getRank(gr.getName()).getMembers().remove(name); + } moderators.remove(name); } @@ -211,6 +227,11 @@ public class Guild return home != null; } + public boolean hasDefaultRank() + { + return defaultRank != null; + } + public void broadcast(String message) { for (Player player : Bukkit.getOnlinePlayers()) @@ -359,7 +380,8 @@ public class Guild new ArrayList<>(), null, null, - System.currentTimeMillis()); + System.currentTimeMillis(), + null); guild.save(); GLog.info(owner.getName() + " has created guild " + name); return guild; @@ -393,7 +415,8 @@ public class Guild ranks, plugin.guilds.getString(identifier + ".motd"), plugin.guilds.getLocation(identifier + ".home"), - plugin.guilds.getLong(identifier + ".creation")); + plugin.guilds.getLong(identifier + ".creation"), + plugin.guilds.getString(identifier + ".defaultrank")); } public static Guild getGuild(Player player)