Skip to content

Commit

Permalink
Added /guilds admin addplayer | removeplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
bramhaag committed Jan 12, 2017
1 parent 21c27ee commit 77fad4a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
48 changes: 47 additions & 1 deletion src/main/java/me/bramhaag/guilds/commands/CommandAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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[] { "<remove | info> <guild name>" }, 2, 2);
super("admin", "Admin command for managing guilds", "guilds.commands.admin", true, null, new String[] { "<remove | info> <guild name>, or <addplayer | removeplayer> <guild name> <player name>" }, 2, 3);
}

@Override
Expand Down Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/bramhaag/guilds/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit 77fad4a

Please sign in to comment.