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

View File

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

View File

@ -55,7 +55,7 @@ public class IslandCreateCommand extends CompositeCommand {
.reason(Reason.CREATE) .reason(Reason.CREATE)
.build(); .build();
} catch (IOException e) { } 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"); user.sendMessage("commands.island.create.unable-create-island");
e.printStackTrace(); e.printStackTrace();
} }

View File

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

View File

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

View File

@ -37,7 +37,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
public boolean execute(User user, List<String> args) { public boolean execute(User user, List<String> args) {
UUID playerUUID = user.getUniqueId(); UUID playerUUID = user.getUniqueId();
if (DEBUG) 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. // Fire event so add-ons can run commands, etc.
IslandBaseEvent event = TeamEvent.builder() IslandBaseEvent event = TeamEvent.builder()
.island(getIslands() .island(getIslands()
@ -45,7 +45,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.INFO) .reason(TeamReason.INFO)
.involvedPlayer(playerUUID) .involvedPlayer(playerUUID)
.build(); .build();
bsb.getServer().getPluginManager().callEvent(event); getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
UUID teamLeaderUUID = getTeamLeader(user); UUID teamLeaderUUID = getTeamLeader(user);
Set<UUID> teamMembers = getMembers(user); Set<UUID> teamMembers = getMembers(user);
@ -61,7 +61,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize."); String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1])); maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
} }

View File

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

View File

@ -47,7 +47,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
if (args.isEmpty() || args.size() > 1) { if (args.isEmpty() || args.size() > 1) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far // Invite label with no name, i.e., /island invite - tells the player who has invited them so far
if (inviteList.containsKey(playerUUID)) { 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()); user.sendMessage("invite.nameHasInvitedYou", "[name]", inviter.getName());
} else { } else {
user.sendMessage("help.island.invite"); user.sendMessage("help.island.invite");
@ -96,7 +96,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize."); String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1])); maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
} }
@ -119,7 +119,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.INVITE) .reason(TeamReason.INVITE)
.involvedPlayer(invitedPlayerUUID) .involvedPlayer(invitedPlayerUUID)
.build(); .build();
bsb.getServer().getPluginManager().callEvent(event); getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
// Put the invited player (key) onto the list with inviter (value) // 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! // 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) .reason(TeamReason.REJECT)
.involvedPlayer(playerUUID) .involvedPlayer(playerUUID)
.build(); .build();
bsb.getServer().getPluginManager().callEvent(event); getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
// Remove this player from the global invite list // 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) { public boolean execute(User user, List<String> args) {
UUID playerUUID = user.getUniqueId(); UUID playerUUID = user.getUniqueId();
// Can use if in a team // Can use if in a team
boolean inTeam = bsb.getPlayers().inTeam(playerUUID); boolean inTeam = getPlugin().getPlayers().inTeam(playerUUID);
UUID teamLeaderUUID = bsb.getIslands().getTeamLeader(playerUUID); UUID teamLeaderUUID = getPlugin().getIslands().getTeamLeader(playerUUID);
if (!(inTeam && teamLeaderUUID.equals(playerUUID))) { if (!(inTeam && teamLeaderUUID.equals(playerUUID))) {
return true; 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)); UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) { if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player"); 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"); user.sendMessage("commands.island.team.setowner.errors.cant-transfer-to-yourself");
return true; 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"); user.sendMessage("commands.island.team.setowner.errors.target-is-not-member");
return true; return true;
} }
@ -64,7 +64,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
.reason(TeamReason.MAKELEADER) .reason(TeamReason.MAKELEADER)
.involvedPlayer(targetUUID) .involvedPlayer(targetUUID)
.build(); .build();
bsb.getServer().getPluginManager().callEvent(event); getPlugin().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
// target is the new leader // target is the new leader
@ -81,7 +81,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
// Check for zero protection range // Check for zero protection range
Island islandByOwner = getIslands().getIsland(targetUUID); Island islandByOwner = getIslands().getIsland(targetUUID);
if (islandByOwner.getProtectionRange() == 0) { 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); islandByOwner.setProtectionRange(range);
} }
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) { for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
@ -93,7 +93,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range."); String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
hasARangePerm = true; hasARangePerm = true;
@ -115,7 +115,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
if (range != islandByOwner.getProtectionRange()) { if (range != islandByOwner.getProtectionRange()) {
user.sendMessage("commands.admin.setrange.range-updated", "[number]", String.valueOf(range)); user.sendMessage("commands.admin.setrange.range-updated", "[number]", String.valueOf(range));
target.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 " "Makeleader: Island protection range changed from " + islandByOwner.getProtectionRange() + " to "
+ range + " for " + user.getName() + " due to permission."); + 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) { public Optional<List<String>> tabComplete(final User user, final String alias, final LinkedList<String> args) {
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();
String lastArg = (!args.isEmpty() ? args.getLast() : ""); String lastArg = (!args.isEmpty() ? args.getLast() : "");
for (UUID member : bsb.getIslands().getMembers(user.getUniqueId())) { for (UUID member : getPlugin().getIslands().getMembers(user.getUniqueId())) {
options.add(bsb.getServer().getOfflinePlayer(member).getName()); options.add(getPlugin().getServer().getOfflinePlayer(member).getName());
} }
return Optional.of(Util.tabLimit(options, lastArg)); return Optional.of(Util.tabLimit(options, lastArg));
} }

View File

@ -359,4 +359,21 @@ public class IslandCache {
public int size() { public int size() {
return islandsByLocation.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;
}
} }