Added common variables to AbstractCommand for player, team
This commit is contained in:
parent
47d93c8660
commit
a8606a2b00
|
@ -4,11 +4,16 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,15 +24,24 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||
private Map<String, ArgumentHandler> argumentsMap;
|
||||
private Map<String, String> aliasesMap;
|
||||
public String label;
|
||||
public boolean isPlayer;
|
||||
public boolean inTeam;
|
||||
public UUID playerUUID;
|
||||
public UUID teamLeaderUUID;
|
||||
public Set<UUID> teamMembers;
|
||||
public Player player;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final boolean help;
|
||||
private BSkyBlock plugin;
|
||||
|
||||
private static final int MAX_PER_PAGE = 7;
|
||||
|
||||
protected AbstractCommand(String name, boolean help) {
|
||||
protected AbstractCommand(String name, boolean help, BSkyBlock plugin) {
|
||||
this.name = name;
|
||||
this.help = help;
|
||||
this.plugin = plugin;
|
||||
// These are not initialized elsewhere, so need to be done so. Initialize with size 1 to save memory
|
||||
this.aliasesMap = new HashMap<String,String>(1);
|
||||
this.argumentsMap = new HashMap<String, ArgumentHandler>(1);
|
||||
|
@ -105,6 +119,18 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
this.label = label;
|
||||
if (this.canUse(sender)) {
|
||||
// Check if the command sender is a player or not
|
||||
if (sender instanceof Player) {
|
||||
isPlayer = true;
|
||||
player = (Player)sender;
|
||||
playerUUID = player.getUniqueId();
|
||||
}
|
||||
// Check if the player is in a team or not and if so, grab the team leader's UUID
|
||||
if (plugin.getPlayers().inTeam(playerUUID)) {
|
||||
inTeam = true;
|
||||
teamLeaderUUID = plugin.getIslands().getTeamLeader(playerUUID);
|
||||
teamMembers = plugin.getIslands().getMembers(teamLeaderUUID);
|
||||
}
|
||||
if(args.length >= 1) {
|
||||
ArgumentHandler handler = getHandler(args[0]); // Store the handler to save some calculations
|
||||
if (handler != null && handler.canUse(sender)) {
|
||||
|
|
|
@ -12,7 +12,7 @@ public class AdminCommand extends AbstractCommand {
|
|||
BSkyBlock plugin;
|
||||
|
||||
public AdminCommand(BSkyBlock plugin) {
|
||||
super(Settings.ADMINCOMMAND, true);
|
||||
super(Settings.ADMINCOMMAND, true, plugin);
|
||||
plugin.getCommand(Settings.ADMINCOMMAND).setExecutor(this);
|
||||
plugin.getCommand(Settings.ADMINCOMMAND).setTabCompleter(this);
|
||||
this.plugin = plugin;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package us.tastybento.bskyblock.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
|
@ -37,7 +35,7 @@ public class IslandCommand extends AbstractCommand {
|
|||
|
||||
|
||||
public IslandCommand(BSkyBlock plugin) {
|
||||
super(Settings.ISLANDCOMMAND, true);
|
||||
super(Settings.ISLANDCOMMAND, true, plugin);
|
||||
plugin.getCommand(Settings.ISLANDCOMMAND).setExecutor(this);
|
||||
plugin.getCommand(Settings.ISLANDCOMMAND).setTabCompleter(this);
|
||||
this.plugin = plugin;
|
||||
|
@ -516,12 +514,8 @@ public class IslandCommand extends AbstractCommand {
|
|||
@Override
|
||||
public String[] getHelp(CommandSender sender){
|
||||
plugin.getLogger().info("DEBUG: executing team help");
|
||||
Player player = (Player)sender;
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (plugin.getPlayers().inTeam(playerUUID)) {
|
||||
UUID teamLeader = plugin.getIslands().getTeamLeader(playerUUID);
|
||||
Set<UUID> teamMembers = plugin.getIslands().getMembers(teamLeader);
|
||||
if (teamLeader.equals(playerUUID)) {
|
||||
if (inTeam) {
|
||||
if (teamLeaderUUID.equals(playerUUID)) {
|
||||
int maxSize = Settings.maxTeamSize;
|
||||
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
|
||||
|
@ -554,7 +548,7 @@ public class IslandCommand extends AbstractCommand {
|
|||
}
|
||||
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(sender).get("team.listingMembers") + ":");
|
||||
// Display members in the list
|
||||
for (UUID m : plugin.getIslands().getMembers(teamLeader)) {
|
||||
for (UUID m : teamMembers) {
|
||||
Util.sendMessage(player, ChatColor.WHITE + plugin.getPlayers().getName(m));
|
||||
}
|
||||
} else {
|
||||
|
@ -569,8 +563,8 @@ public class IslandCommand extends AbstractCommand {
|
|||
|
||||
@Override
|
||||
public boolean canUse(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
if (VaultHelper.hasPerm((Player)sender, Settings.PERMPREFIX + "team.create")) {
|
||||
if (isPlayer) {
|
||||
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team.create")) {
|
||||
plugin.getLogger().info("DEBUG: has perm");
|
||||
return true;
|
||||
}
|
||||
|
@ -582,8 +576,6 @@ public class IslandCommand extends AbstractCommand {
|
|||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
plugin.getLogger().info("DEBUG: executing invite");
|
||||
Player player = (Player)sender;
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (args.length == 0) {
|
||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
||||
//TODO
|
||||
|
@ -617,11 +609,9 @@ public class IslandCommand extends AbstractCommand {
|
|||
}
|
||||
// If the player already has a team then check that they are
|
||||
// the leader, etc
|
||||
if (plugin.getPlayers().inTeam(player.getUniqueId())) {
|
||||
UUID teamLeader = plugin.getIslands().getTeamLeader(playerUUID);
|
||||
Set<UUID> teamMembers = plugin.getIslands().getMembers(teamLeader);
|
||||
if (inTeam) {
|
||||
// Leader?
|
||||
if (teamLeader.equals(player.getUniqueId())) {
|
||||
if (teamLeaderUUID.equals(player.getUniqueId())) {
|
||||
// Invited player is free and not in a team
|
||||
if (!plugin.getPlayers().inTeam(invitedPlayerUUID)) {
|
||||
// Player has space in their team
|
||||
|
|
Loading…
Reference in New Issue