From 77fad4a42a2dea5cb51eb35de904b0c884bf2a7d Mon Sep 17 00:00:00 2001 From: Bram Hagens Date: Thu, 12 Jan 2017 19:48:27 +0100 Subject: [PATCH] Added /guilds admin addplayer | removeplayer --- .../guilds/commands/CommandAdmin.java | 48 ++++++++++++++++++- .../me/bramhaag/guilds/message/Message.java | 2 +- src/main/resources/config.yml | 9 ++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/bramhaag/guilds/commands/CommandAdmin.java b/src/main/java/me/bramhaag/guilds/commands/CommandAdmin.java index 23c3179..e97aa9e 100644 --- a/src/main/java/me/bramhaag/guilds/commands/CommandAdmin.java +++ b/src/main/java/me/bramhaag/guilds/commands/CommandAdmin.java @@ -3,18 +3,20 @@ import me.bramhaag.guilds.Main; import me.bramhaag.guilds.commands.base.CommandBase; import me.bramhaag.guilds.guild.Guild; +import me.bramhaag.guilds.guild.GuildMember; import me.bramhaag.guilds.guild.GuildRole; import me.bramhaag.guilds.message.Message; import me.bramhaag.guilds.util.ConfirmAction; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.logging.Level; public class CommandAdmin extends CommandBase { public CommandAdmin() { - super("admin", "Admin command for managing guilds", "guilds.commands.admin", true, null, new String[] { " " }, 2, 2); + super("admin", "Admin command for managing guilds", "guilds.commands.admin", true, null, new String[] { " , or " }, 2, 3); } @Override @@ -57,6 +59,50 @@ public void decline() { } }); } + else if(args[0].equalsIgnoreCase("addplayer")) { + if(args.length != 3) { + Message.sendMessage(sender, Message.COMMAND_ERROR_ARGS); + return; + } + + Player player = Bukkit.getPlayer(args[2]); + if(player == null || !player.isOnline()) { + Message.sendMessage(sender, Message.COMMAND_ERROR_PLAYER_NOT_FOUND); + return; + } + + if(Guild.getGuild(player.getUniqueId()) != null) { + Message.sendMessage(sender, Message.COMMAND_ADMIN_PLAYER_ALREADY_IN_GUILD); + return; + } + + guild.addMember(player.getUniqueId(), GuildRole.getLowestRole()); + + Message.sendMessage(player, Message.COMMAND_ACCEPT_SUCCESSFUL); + Message.sendMessage(sender, Message.COMMAND_ADMIN_ADDED_PLAYER); + } + else if(args[0].equalsIgnoreCase("removeplayer")) { + if(args.length != 3) { + Message.sendMessage(sender, Message.COMMAND_ERROR_ARGS); + return; + } + + Player player = Bukkit.getPlayer(args[2]); + if(player == null || !player.isOnline()) { + Message.sendMessage(sender, Message.COMMAND_ERROR_PLAYER_NOT_FOUND); + return; + } + + if(Guild.getGuild(player.getUniqueId()) == null) { + Message.sendMessage(sender, Message.COMMAND_ADMIN_PLAYER_NOT_IN_GUILD); + return; + } + + guild.removeMember(player.getUniqueId()); + + Message.sendMessage(player, Message.COMMAND_LEAVE_SUCCESSFUL); + Message.sendMessage(sender, Message.COMMAND_ADMIN_REMOVED_PLAYER); + } else if(args[0].equalsIgnoreCase("info")) { Message.sendMessage(sender, Message.COMMAND_INFO_HEADER.replace("{guild}", guild.getName())); Message.sendMessage(sender, Message.COMMAND_INFO_NAME.replace("{guild}", guild.getName(), "{prefix}", guild.getPrefix())); diff --git a/src/main/java/me/bramhaag/guilds/message/Message.java b/src/main/java/me/bramhaag/guilds/message/Message.java index 504f3a6..7c43197 100644 --- a/src/main/java/me/bramhaag/guilds/message/Message.java +++ b/src/main/java/me/bramhaag/guilds/message/Message.java @@ -94,7 +94,7 @@ public enum Message { COMMAND_UPDATE_FOUND, COMMAND_UPDATE_NOT_FOUND, - EVENT_JOIN_PENDING_INVITES; + EVENT_JOIN_PENDING_INVITES, COMMAND_ADMIN_PLAYER_ALREADY_IN_GUILD, COMMAND_ADMIN_ADDED_PLAYER, COMMAND_ADMIN_PLAYER_NOT_IN_GUILD, COMMAND_ADMIN_REMOVED_PLAYER; public static void sendMessage(CommandSender sender, Message message) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.PREFIX + Main.getInstance().getConfig().getString(getPath(message)))); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c9115a2..d34ca51 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -184,6 +184,15 @@ messages: update: found: "&aFound an update! Go to {url} to download it!" not-found: "&cNo update found!" + admin: + delete-successful: "&cGuild removed successfully!" + delete-error: "&cSomething went wrong while removing this guild!" + delete-warning: "&cType /guilds confirm to remove this guild, type /guilds cancel to cancel." + delete-cancelled: "&cGuild deletion cancelled!" + player-already-in-guild: "&cThis player is already in a guild!" + added-player: "&aAdded player to guild" + player-not-in-guild: "&cPlayer is not in this guild!" + removed-player: "&aRemoved player from guild!" event: join: pending-invites: "&aYou have {number} pending invite(s) from the guild(s): &e{guilds}" \ No newline at end of file