Switched to a getter for getPlugin() in CompositeCommand

Made internal variable protected.
This commit is contained in:
Tastybento 2017-12-26 08:40:28 -08:00
parent 97722b56d5
commit 239cf50709
11 changed files with 52 additions and 35 deletions

View File

@ -46,8 +46,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* The permission required to execute this command
*/
private String permission = "";
public BSkyBlock bsb = BSkyBlock.getPlugin();
/**
* Map of sub commands
*/
@ -56,6 +54,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* The usage string for this command. It is the commands followed by a locale reference.
*/
private String usage;
private BSkyBlock bsb;
/**
* Sub-command constructor
@ -221,7 +220,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
@Override
public BSkyBlock getPlugin() {
return bsb;
this.bsb = BSkyBlock.getPlugin();
return this.bsb;
}
/**

View File

@ -44,7 +44,7 @@ public class IslandCommand extends CompositeCommand {
@Override
public boolean execute(User user, List<String> args) {
user.sendLegacyMessage("You successfully did /is !");
if (!bsb.getIslands().hasIsland(user.getUniqueId())) {
if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) {
return this.getSubCommand("create").execute(user, args);
}
// Currently, just go home

View File

@ -55,7 +55,7 @@ public class IslandCreateCommand extends CompositeCommand {
.reason(Reason.CREATE)
.build();
} catch (IOException e) {
bsb.getLogger().severe("Could not create island for player.");
getPlugin().getLogger().severe("Could not create island for player.");
user.sendMessage("commands.island.create.unable-create-island");
e.printStackTrace();
}

View File

@ -34,7 +34,7 @@ public class IslandResetCommand extends CompositeCommand {
user.sendMessage("general.errors.not-leader");
return false;
}
if (bsb.getPlayers().inTeam(user.getUniqueId())) {
if (getPlugin().getPlayers().inTeam(user.getUniqueId())) {
user.sendMessage("commands.island.reset.must-remove-members");
return true;
}
@ -43,14 +43,14 @@ public class IslandResetCommand extends CompositeCommand {
// Get the player's old island
Island oldIsland = getIslands().getIsland(player.getUniqueId());
if (DEBUG)
bsb.getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ());
getPlugin().getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ());
// Remove them from this island (it still exists and will be deleted later)
getIslands().removePlayer(player.getUniqueId());
if (DEBUG)
bsb.getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner());
getPlugin().getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner());
// Create new island and then delete the old one
if (DEBUG)
bsb.getLogger().info("DEBUG: making new island ");
getPlugin().getLogger().info("DEBUG: making new island ");
try {
NewIsland.builder()
.player(player)
@ -58,7 +58,7 @@ public class IslandResetCommand extends CompositeCommand {
.oldIsland(oldIsland)
.build();
} catch (IOException e) {
bsb.getLogger().severe("Could not create island for player.");
getPlugin().getLogger().severe("Could not create island for player.");
user.sendMessage("commands.island.create.unable-create-island");
e.printStackTrace();
}

View File

@ -21,17 +21,17 @@ public class IslandSethomeCommand extends CompositeCommand {
public boolean execute(User user, List<String> args) {
UUID playerUUID = user.getUniqueId();
// Check island
if (bsb.getIslands().getIsland(user.getUniqueId()) == null) {
if (getPlugin().getIslands().getIsland(user.getUniqueId()) == null) {
user.sendMessage("general.errors.no-island");
return true;
}
if (!bsb.getIslands().playerIsOnIsland(user.getPlayer())) {
if (!getPlugin().getIslands().playerIsOnIsland(user.getPlayer())) {
user.sendMessage("commands.island.sethome.must-be-on-your-island");
return true;
}
if (args.isEmpty()) {
// island sethome
bsb.getPlayers().setHomeLocation(playerUUID, user.getLocation());
getPlugin().getPlayers().setHomeLocation(playerUUID, user.getLocation());
user.sendMessage("commands.island.sethome.home-set");
} else {
// Dynamic home sizes with permissions
@ -44,7 +44,7 @@ public class IslandSethomeCommand extends CompositeCommand {
if (number < 1 || number > maxHomes) {
user.sendMessage("commands.island.sethome.num-homes", "[max]", String.valueOf(maxHomes));
} else {
bsb.getPlayers().setHomeLocation(playerUUID, user.getLocation(), number);
getPlugin().getPlayers().setHomeLocation(playerUUID, user.getLocation(), number);
user.sendMessage("commands.island.sethome.home-set");
}
} catch (Exception e) {

View File

@ -37,7 +37,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
public boolean execute(User user, List<String> args) {
UUID playerUUID = user.getUniqueId();
if (DEBUG)
bsb.getLogger().info("DEBUG: executing team command for " + playerUUID);
getPlugin().getLogger().info("DEBUG: executing team command for " + playerUUID);
// Fire event so add-ons can run commands, etc.
IslandBaseEvent event = TeamEvent.builder()
.island(getIslands()
@ -45,7 +45,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.INFO)
.involvedPlayer(playerUUID)
.build();
bsb.getServer().getPluginManager().callEvent(event);
getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
UUID teamLeaderUUID = getTeamLeader(user);
Set<UUID> teamMembers = getMembers(user);
@ -61,7 +61,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
bsb.getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
}

View File

@ -49,7 +49,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
return true;
}
if (DEBUG)
bsb.getLogger().info("DEBUG: Invite is valid");
getPlugin().getLogger().info("DEBUG: Invite is valid");
// Fire event so add-ons can run commands, etc.
IslandBaseEvent event = TeamEvent.builder()
.island(getIslands()
@ -57,11 +57,11 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.JOIN)
.involvedPlayer(playerUUID)
.build();
bsb.getServer().getPluginManager().callEvent(event);
getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
// Remove the invite
if (DEBUG)
bsb.getLogger().info("DEBUG: Removing player from invite list");
getPlugin().getLogger().info("DEBUG: Removing player from invite list");
inviteList.remove(playerUUID);
// Put player into Spectator mode
user.setGameMode(GameMode.SPECTATOR);
@ -98,7 +98,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
}
getIslands().save(false);
if (DEBUG)
bsb.getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMembers().toString());
getPlugin().getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMembers().toString());
return true;
}

View File

@ -47,7 +47,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
if (args.isEmpty() || args.size() > 1) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
if (inviteList.containsKey(playerUUID)) {
OfflinePlayer inviter = bsb.getServer().getOfflinePlayer(inviteList.get(playerUUID));
OfflinePlayer inviter = getPlugin().getServer().getOfflinePlayer(inviteList.get(playerUUID));
user.sendMessage("invite.nameHasInvitedYou", "[name]", inviter.getName());
} else {
user.sendMessage("help.island.invite");
@ -96,7 +96,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
bsb.getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
}
@ -119,7 +119,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.INVITE)
.involvedPlayer(invitedPlayerUUID)
.build();
bsb.getServer().getPluginManager().callEvent(event);
getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
// Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite!

View File

@ -30,7 +30,7 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.REJECT)
.involvedPlayer(playerUUID)
.build();
bsb.getServer().getPluginManager().callEvent(event);
getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
// Remove this player from the global invite list

View File

@ -30,12 +30,12 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
public boolean execute(User user, List<String> args) {
UUID playerUUID = user.getUniqueId();
// Can use if in a team
boolean inTeam = bsb.getPlayers().inTeam(playerUUID);
UUID teamLeaderUUID = bsb.getIslands().getTeamLeader(playerUUID);
boolean inTeam = getPlugin().getPlayers().inTeam(playerUUID);
UUID teamLeaderUUID = getPlugin().getIslands().getTeamLeader(playerUUID);
if (!(inTeam && teamLeaderUUID.equals(playerUUID))) {
return true;
}
bsb.getLogger().info("DEBUG: arg[0] = " + args.get(0));
getPlugin().getLogger().info("DEBUG: arg[0] = " + args.get(0));
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player");
@ -53,7 +53,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
return true;
}
if (!bsb.getIslands().getMembers(playerUUID).contains(targetUUID)) {
if (!getPlugin().getIslands().getMembers(playerUUID).contains(targetUUID)) {
user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
return true;
}
@ -64,7 +64,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.MAKELEADER)
.involvedPlayer(targetUUID)
.build();
bsb.getServer().getPluginManager().callEvent(event);
getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
// target is the new leader
@ -81,7 +81,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
// Check for zero protection range
Island islandByOwner = getIslands().getIsland(targetUUID);
if (islandByOwner.getProtectionRange() == 0) {
bsb.getLogger().warning("Player " + user.getName() + "'s island had a protection range of 0. Setting to default " + range);
getPlugin().getLogger().warning("Player " + user.getName() + "'s island had a protection range of 0. Setting to default " + range);
islandByOwner.setProtectionRange(range);
}
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
@ -93,7 +93,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
bsb.getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
getPlugin().getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
hasARangePerm = true;
@ -115,7 +115,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
if (range != islandByOwner.getProtectionRange()) {
user.sendMessage("commands.admin.setrange.range-updated", "[number]", String.valueOf(range));
target.sendMessage("commands.admin.setrange.range-updated", "[number]", String.valueOf(range));
bsb.getLogger().info(
getPlugin().getLogger().info(
"Makeleader: Island protection range changed from " + islandByOwner.getProtectionRange() + " to "
+ range + " for " + user.getName() + " due to permission.");
}
@ -130,8 +130,8 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
public Optional<List<String>> tabComplete(final User user, final String alias, final LinkedList<String> args) {
List<String> options = new ArrayList<>();
String lastArg = (!args.isEmpty() ? args.getLast() : "");
for (UUID member : bsb.getIslands().getMembers(user.getUniqueId())) {
options.add(bsb.getServer().getOfflinePlayer(member).getName());
for (UUID member : getPlugin().getIslands().getMembers(user.getUniqueId())) {
options.add(getPlugin().getServer().getOfflinePlayer(member).getName());
}
return Optional.of(Util.tabLimit(options, lastArg));
}

View File

@ -359,4 +359,21 @@ public class IslandCache {
public int size() {
return islandsByLocation.size();
}
/**
* Get if the cache contains this island
* @param island or uuid of owner
* @return true if it is in the cache
*/
public boolean contains(Object o) {
if (o instanceof UUID) {
return islandsByUUID.containsKey(o);
}
if (o instanceof Island) {
Island is = (Island)o;
if (is.getOwner() != null && islandsByUUID.containsKey(is.getOwner()));
return true;
}
return false;
}
}