Removed AbstractIslandTeamCommand

This was using static data structure that would not work well when other
addons use the command.
This commit is contained in:
tastybento 2018-05-26 11:43:22 -07:00
parent 35b715ff80
commit 6d17d48bde
41 changed files with 155 additions and 159 deletions

View File

@ -68,6 +68,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* The command chain from the very top, e.g., island team promote * The command chain from the very top, e.g., island team promote
*/ */
private String usage; private String usage;
/**
* The prefix to be used in this command
*/
private String permissionPrefix = "";
/** /**
* Used only for testing.... * Used only for testing....
@ -137,6 +142,8 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
if (!getSubCommand("help").isPresent() && !label.equals("help")) { if (!getSubCommand("help").isPresent() && !label.equals("help")) {
new DefaultHelpCommand(this); new DefaultHelpCommand(this);
} }
// Set permission prefix
this.permissionPrefix = parent.getPermissionPrefix();
} }
/* /*
@ -377,9 +384,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.parameters = parameters; this.parameters = parameters;
} }
/* (non-Javadoc)
* @see org.bukkit.command.Command#setPermission(java.lang.String)
*/
@Override @Override
public void setPermission(String permission) { public void setPermission(String permission) {
this.permission = permission; this.permission = permissionPrefix + permission;
} }
/** /**
@ -454,4 +464,23 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
public Map<String, CompositeCommand> getSubCommandAliases() { public Map<String, CompositeCommand> getSubCommandAliases() {
return subCommandAliases; return subCommandAliases;
} }
/**
* If the permission prefix has been set, will return the prefix plus a trailing dot.
* @return the permissionPrefix
*/
public String getPermissionPrefix() {
return permissionPrefix;
}
/**
* Set the permission prefix. This will be added automatically to the permission
* and will apply to any sub commands too.
* Do not put a dot on the end of it.
* @param permissionPrefix the permissionPrefix to set
*/
public void setPermissionPrefix(String permissionPrefix) {
this.permissionPrefix = permissionPrefix + ".";
}
} }

View File

@ -110,5 +110,10 @@ public interface WorldSettings {
* @return the dragonSpawn * @return the dragonSpawn
*/ */
public boolean isDragonSpawn(); public boolean isDragonSpawn();
/**
* @return the max team size for this world
*/
public int getMaxTeamSize();
} }

View File

@ -25,7 +25,8 @@ public class AdminCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.*"); setPermissionPrefix("bskyblock");
setPermission("admin.*");
setOnlyPlayer(false); setOnlyPlayer(false);
setParameters("commands.admin.help.parameters"); setParameters("commands.admin.help.parameters");
setDescription("commands.admin.help.description"); setDescription("commands.admin.help.description");

View File

@ -40,7 +40,8 @@ public class IslandCommand extends CompositeCommand {
setDescription("commands.island.help.description"); setDescription("commands.island.help.description");
setOnlyPlayer(true); setOnlyPlayer(true);
// Permission // Permission
setPermission(Constants.PERMPREFIX + "island"); setPermissionPrefix("bskyblock");
setPermission("island");
// Set up subcommands // Set up subcommands
new IslandAboutCommand(this); new IslandAboutCommand(this);
new IslandCreateCommand(this); new IslandCreateCommand(this);
@ -56,7 +57,6 @@ public class IslandCommand extends CompositeCommand {
new IslandBanlistCommand(this); new IslandBanlistCommand(this);
// Team commands // Team commands
new IslandTeamCommand(this); new IslandTeamCommand(this);
new IslandTeamInviteCommand(this);
} }

View File

@ -12,7 +12,6 @@ import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -33,7 +32,7 @@ public class AdminGetRankCommand extends CompositeCommand {
*/ */
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.setrank"); setPermission("admin.setrank");
setOnlyPlayer(false); setOnlyPlayer(false);
setParameters("commands.admin.getrank.parameters"); setParameters("commands.admin.getrank.parameters");
setDescription("commands.admin.getrank.description"); setDescription("commands.admin.getrank.description");

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -17,7 +16,7 @@ public class AdminInfoCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.info"); setPermission("admin.info");
setOnlyPlayer(false); setOnlyPlayer(false);
setParameters("commands.admin.info.parameters"); setParameters("commands.admin.info.parameters");
setDescription("commands.admin.info.description"); setDescription("commands.admin.info.description");

View File

@ -6,7 +6,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -15,15 +14,15 @@ import us.tastybento.bskyblock.util.Util;
public class AdminRegisterCommand extends CompositeCommand { public class AdminRegisterCommand extends CompositeCommand {
public AdminRegisterCommand(CompositeCommand parent) { public AdminRegisterCommand(CompositeCommand parent) {
super(parent, "unregister"); super(parent, "register");
} }
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.unregister"); setPermission("admin.register");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.admin.unregister.parameters"); setParameters("commands.admin.register.parameters");
setDescription("commands.admin.unregister.description"); setDescription("commands.admin.register.description");
} }
@Override @Override

View File

@ -6,7 +6,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.island.builders.Clipboard; import us.tastybento.bskyblock.island.builders.Clipboard;
@ -20,7 +19,7 @@ public class AdminSchemCommand extends CompositeCommand {
} }
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.schem"); setPermission("admin.schem");
setParameters("commands.admin.schem.parameters"); setParameters("commands.admin.schem.parameters");
setDescription("commands.admin.schem.description"); setDescription("commands.admin.schem.description");
setOnlyPlayer(true); setOnlyPlayer(true);

View File

@ -10,7 +10,6 @@ import java.util.stream.Collectors;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -31,7 +30,7 @@ public class AdminSetRankCommand extends CompositeCommand {
*/ */
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.setrank"); setPermission("admin.setrank");
setOnlyPlayer(false); setOnlyPlayer(false);
setParameters("commands.admin.setrank.parameters"); setParameters("commands.admin.setrank.parameters");
setDescription("commands.admin.setrank.description"); setDescription("commands.admin.setrank.description");

View File

@ -8,7 +8,6 @@ import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -22,7 +21,8 @@ public class AdminTeleportCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.tp"); // Permission
setPermission(getPermissionPrefix() + "admin.tp");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.admin.tp.parameters"); setParameters("commands.admin.tp.parameters");
setDescription("commands.admin.tp.description"); setDescription("commands.admin.tp.description");

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -18,7 +17,7 @@ public class AdminUnregisterCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.unregister"); setPermission("admin.unregister");
setParameters("commands.admin.unregister.parameters"); setParameters("commands.admin.unregister.parameters");
setDescription("commands.admin.unregister.description"); setDescription("commands.admin.unregister.description");
} }

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.commands.admin;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -15,7 +14,7 @@ public class AdminVersionCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
// Permission // Permission
setPermission(Constants.PERMPREFIX + "admin.version"); setPermission(getPermissionPrefix() + "admin.version");
setDescription("commands.admin.version.description"); setDescription("commands.admin.version.description");
} }

View File

@ -18,7 +18,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.team"); setPermission("admin.team");
setParameters("commands.admin.team.add.parameters"); setParameters("commands.admin.team.add.parameters");
setDescription("commands.admin.team.add.description"); setDescription("commands.admin.team.add.description");
} }

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -17,7 +16,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.team"); setPermission("admin.team");
setParameters("commands.admin.team.disband.parameters"); setParameters("commands.admin.team.disband.parameters");
setDescription("commands.admin.team.disband.description"); setDescription("commands.admin.team.disband.description");
} }

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -18,7 +17,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.team"); setPermission("admin.team");
setParameters("commands.admin.team.kick.parameters"); setParameters("commands.admin.team.kick.parameters");
setDescription("commands.admin.team.kick.description"); setDescription("commands.admin.team.kick.description");
} }

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -17,7 +16,7 @@ public class AdminTeamMakeLeaderCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "admin.team"); setPermission("admin.team");
setParameters("commands.admin.team.makeleader.parameters"); setParameters("commands.admin.team.makeleader.parameters");
setDescription("commands.admin.team.makeleader.description"); setDescription("commands.admin.team.makeleader.description");
} }

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -48,7 +47,7 @@ public class CustomIslandMultiHomeHelp extends CompositeCommand {
private void showPrettyHelp(User user, String usage, String params, String desc) { private void showPrettyHelp(User user, String usage, String params, String desc) {
// Player. Check perms // Player. Check perms
if (user.hasPermission(getPermission())) { if (user.hasPermission(getPermission())) {
int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes()); int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes());
if (maxHomes > 1) { if (maxHomes > 1) {
params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters()); params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters());
} }

View File

@ -9,7 +9,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -23,7 +22,7 @@ public class IslandBanCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.ban"); setPermission("island.ban");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.island.ban.parameters"); setParameters("commands.island.ban.parameters");
setDescription("commands.island.ban.description"); setDescription("commands.island.ban.description");

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -17,7 +16,7 @@ public class IslandBanlistCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.ban"); setPermission("island.ban");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.banlist.description"); setDescription("commands.island.banlist.description");
} }

View File

@ -9,7 +9,6 @@ import java.util.Set;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -29,7 +28,7 @@ public class IslandCreateCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.create"); setPermission("island.create");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.create.description"); setDescription("commands.island.create.description");
} }

View File

@ -9,7 +9,6 @@ import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
@ -29,7 +28,7 @@ public class IslandGoCommand extends CompositeCommand {
*/ */
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.home"); setPermission("island.home");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.go.description"); setDescription("commands.island.go.description");
new CustomIslandMultiHomeHelp(this); new CustomIslandMultiHomeHelp(this);
@ -63,7 +62,7 @@ public class IslandGoCommand extends CompositeCommand {
} }
if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) { if (!args.isEmpty() && NumberUtils.isDigits(args.get(0))) {
int homeValue = Integer.valueOf(args.get(0)); int homeValue = Integer.valueOf(args.get(0));
int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes()); int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes());
if (homeValue > 1 && homeValue <= maxHomes) { if (homeValue > 1 && homeValue <= maxHomes) {
getIslands().homeTeleport(world, user.getPlayer(), homeValue); getIslands().homeTeleport(world, user.getPlayer(), homeValue);
return true; return true;

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
@ -22,7 +21,7 @@ public class IslandLanguageCommand extends CompositeCommand {
*/ */
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.language"); setPermission("island.language");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.language.description"); setDescription("commands.island.language.description");
} }

View File

@ -31,7 +31,7 @@ public class IslandResetCommand extends CompositeCommand {
public void setup() { public void setup() {
cooldown = new HashMap<>(); cooldown = new HashMap<>();
confirm = new HashMap<>(); confirm = new HashMap<>();
setPermission(Constants.PERMPREFIX + "island.create"); setPermission("island.create");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.reset.description"); setDescription("commands.island.reset.description");
} }

View File

@ -6,7 +6,6 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -22,7 +21,7 @@ public class IslandResetnameCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.name"); setPermission("island.name");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.resetname.description"); setDescription("commands.island.resetname.description");

View File

@ -3,7 +3,6 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -16,7 +15,7 @@ public class IslandSethomeCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.sethome"); setPermission("island.sethome");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.sethome.description"); setDescription("commands.island.sethome.description");
new CustomIslandMultiHomeHelp(this); new CustomIslandMultiHomeHelp(this);
@ -40,7 +39,7 @@ public class IslandSethomeCommand extends CompositeCommand {
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
int maxHomes = Util.getPermValue(user.getPlayer(), Constants.PERMPREFIX + "island.maxhomes", getSettings().getMaxHomes()); int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getSettings().getMaxHomes());
if (maxHomes > 1) { if (maxHomes > 1) {
// Check the number given is a number // Check the number given is a number
int number = 0; int number = 0;

View File

@ -10,7 +10,6 @@ import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
@ -26,7 +25,7 @@ public class IslandSetnameCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.name"); setPermission("island.name");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.island.setname.parameters"); setParameters("commands.island.setname.parameters");
setDescription("commands.island.setname.description"); setDescription("commands.island.setname.description");
@ -69,7 +68,7 @@ public class IslandSetnameCommand extends CompositeCommand {
} }
// Set the name // Set the name
if (!player.hasPermission(Constants.PERMPREFIX + "island.name.format")) { if (!player.hasPermission("island.name.format")) {
getIslands().getIsland(user.getWorld(), player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name)); getIslands().getIsland(user.getWorld(), player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
} else { } else {
getIslands().getIsland(user.getWorld(), playerUUID).setName(name); getIslands().getIsland(user.getWorld(), playerUUID).setName(name);

View File

@ -2,7 +2,6 @@ package us.tastybento.bskyblock.commands.island;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand; import us.tastybento.bskyblock.commands.IslandCommand;
@ -22,7 +21,7 @@ public class IslandSettingsCommand extends CompositeCommand {
*/ */
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.settings"); setPermission("island.settings");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.settings.description"); setDescription("commands.island.settings.description");
} }

View File

@ -5,7 +5,6 @@ import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -19,7 +18,7 @@ public class IslandUnbanCommand extends CompositeCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.ban"); setPermission("island.ban");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.island.unban.parameters"); setParameters("commands.island.unban.parameters");
setDescription("commands.island.unban.description"); setDescription("commands.island.unban.description");

View File

@ -1,48 +0,0 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util;
/**
* A safe common space for team commands to share data
* @author tastybento
*
*/
public abstract class AbstractIslandTeamCommand extends CompositeCommand {
protected static final boolean DEBUG = false;
protected static BiMap<UUID, UUID> inviteList = HashBiMap.create();
// The time a player has to wait until they can reset their island again
protected static HashMap<UUID, Long> resetWaitTime = new HashMap<>();
protected static Set<UUID> leavingPlayers = new HashSet<>();
protected static Set<UUID> kickingPlayers = new HashSet<>();
public AbstractIslandTeamCommand(CompositeCommand command, String label, String... aliases) {
super(command, label,aliases);
}
/**
* Sets a timeout for player into the Hashmap resetWaitTime
*
* @param player - the player
*/
protected void setResetWaitTime(final Player player) {
resetWaitTime.put(player.getUniqueId(), Calendar.getInstance().getTimeInMillis() + getSettings().getResetWait() * 1000);
}
protected int getMaxTeamSize(User user) {
return Util.getPermValue(user.getPlayer(), "team.maxsize.", getSettings().getMaxTeamSize());
}
}

View File

@ -4,29 +4,27 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
public class IslandTeamCommand extends AbstractIslandTeamCommand { public class IslandTeamCommand extends CompositeCommand {
public IslandTeamCommand(CompositeCommand islandCommand) { private IslandTeamInviteCommand inviteCommand;
super(islandCommand, "team");
public IslandTeamCommand(CompositeCommand parent) {
super(parent, "team");
} }
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.description"); setDescription("commands.island.team.description");
new IslandTeamInviteCommand(this); inviteCommand = new IslandTeamInviteCommand(this);
new IslandTeamLeaveCommand(this); new IslandTeamLeaveCommand(this);
// TODO: These are still in development
//new IslandTeamPromoteCommand(this, "promote");
//new IslandTeamPromoteCommand(this, "demote");
new IslandTeamSetownerCommand(this); new IslandTeamSetownerCommand(this);
new IslandTeamKickCommand(this); new IslandTeamKickCommand(this);
new IslandTeamInviteAcceptCommand(this); new IslandTeamInviteAcceptCommand(this);
@ -50,7 +48,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
} }
Set<UUID> teamMembers = getMembers(user.getWorld(), user); Set<UUID> teamMembers = getMembers(user.getWorld(), user);
if (teamLeaderUUID.equals(playerUUID)) { if (teamLeaderUUID.equals(playerUUID)) {
int maxSize = getMaxTeamSize(user); int maxSize = inviteCommand.getMaxTeamSize(user);
if (teamMembers.size() < maxSize) { if (teamMembers.size() < maxSize) {
user.sendMessage("commands.island.team.invite.you-can-invite", "[number]", String.valueOf(maxSize - teamMembers.size())); user.sendMessage("commands.island.team.invite.you-can-invite", "[number]", String.valueOf(maxSize - teamMembers.size()));
} else { } else {
@ -74,4 +72,11 @@ public class IslandTeamCommand extends AbstractIslandTeamCommand {
return event.isCancelled(); return event.isCancelled();
} }
/**
* @return the inviteCommand
*/
public IslandTeamInviteCommand getInviteCommand() {
return inviteCommand;
}
} }

View File

@ -13,15 +13,18 @@ import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand { public class IslandTeamInviteAcceptCommand extends CompositeCommand {
private IslandTeamCommand itc;
public IslandTeamInviteAcceptCommand(CompositeCommand islandTeamCommand) { public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) {
super(islandTeamCommand, "accept"); super(islandTeamCommand, "accept");
this.itc = islandTeamCommand;
} }
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.invite.accept.description"); setDescription("commands.island.team.invite.accept.description");
} }
@ -30,11 +33,8 @@ public class IslandTeamInviteAcceptCommand 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(!inviteList.containsKey(playerUUID)) {
return false;
}
// Check if player has been invited // Check if player has been invited
if (!inviteList.containsKey(playerUUID)) { if (!itc.getInviteCommand().getInviteList().containsKey(playerUUID)) {
user.sendMessage("commands.island.team.invite.errors.none-invited-you"); user.sendMessage("commands.island.team.invite.errors.none-invited-you");
return false; return false;
} }
@ -44,10 +44,10 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
return false; return false;
} }
// Get the team leader // Get the team leader
UUID prospectiveTeamLeaderUUID = inviteList.get(playerUUID); UUID prospectiveTeamLeaderUUID = itc.getInviteCommand().getInviteList().get(playerUUID);
if (!getIslands().hasIsland(user.getWorld(), prospectiveTeamLeaderUUID)) { if (!getIslands().hasIsland(user.getWorld(), prospectiveTeamLeaderUUID)) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite"); user.sendMessage("commands.island.team.invite.errors.invalid-invite");
inviteList.remove(playerUUID); itc.getInviteCommand().getInviteList().remove(playerUUID);
return false; return false;
} }
// Fire event so add-ons can run commands, etc. // Fire event so add-ons can run commands, etc.
@ -62,7 +62,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
return true; return true;
} }
// Remove the invite // Remove the invite
inviteList.remove(playerUUID); itc.getInviteCommand().getInviteList().remove(playerUUID);
// Put player into Spectator mode // Put player into Spectator mode
user.setGameMode(GameMode.SPECTATOR); user.setGameMode(GameMode.SPECTATOR);
// Get the player's island - may be null if the player has no island // Get the player's island - may be null if the player has no island
@ -83,8 +83,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
getPlayers().setHomeLocation(playerUUID, user.getLocation()); getPlayers().setHomeLocation(playerUUID, user.getLocation());
// Delete the old island // Delete the old island
getIslands().deleteIsland(island, true); getIslands().deleteIsland(island, true);
// Set the cooldown // TODO Set the cooldown
setResetWaitTime(user.getPlayer());
// Reset deaths // Reset deaths
if (getSettings().isTeamJoinDeathReset()) { if (getSettings().isTeamJoinDeathReset()) {
getPlayers().setDeaths(playerUUID, 0); getPlayers().setDeaths(playerUUID, 0);
@ -93,7 +92,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
user.setGameMode(GameMode.SURVIVAL); user.setGameMode(GameMode.SURVIVAL);
user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND); user.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND);
User inviter = User.getInstance(inviteList.get(playerUUID)); User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
if (inviter != null) { if (inviter != null) {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName()); inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", user.getName());
} }

View File

@ -8,16 +8,19 @@ import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import us.tastybento.bskyblock.Constants; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
public class IslandTeamInviteCommand extends AbstractIslandTeamCommand { public class IslandTeamInviteCommand extends CompositeCommand {
private static final String NAME_PLACEHOLDER = "[name]"; private static final String NAME_PLACEHOLDER = "[name]";
private BiMap<UUID, UUID> inviteList;
public IslandTeamInviteCommand(CompositeCommand islandCommand) { public IslandTeamInviteCommand(CompositeCommand islandCommand) {
super(islandCommand, "invite"); super(islandCommand, "invite");
@ -25,9 +28,10 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.invite.description"); setDescription("commands.island.team.invite.description");
inviteList = HashBiMap.create();
} }
@Override @Override
@ -136,4 +140,21 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
return Optional.of(Util.tabLimit(options, lastArg)); return Optional.of(Util.tabLimit(options, lastArg));
} }
/**
* Order is Invited, Inviter
* @return the inviteList
*/
public BiMap<UUID, UUID> getInviteList() {
return inviteList;
}
/**
* Gets the maximum team size for this player in this game based on the permission or the world's setting
* @param user
* @return max team size
*/
public int getMaxTeamSize(User user) {
return Util.getPermValue(user.getPlayer(), getPermissionPrefix() + "team.maxsize.", getIWM().getMaxTeamSize(user.getWorld()));
}
} }

View File

@ -3,21 +3,23 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand { public class IslandTeamInviteRejectCommand extends CompositeCommand {
private IslandTeamCommand itc;
public IslandTeamInviteRejectCommand(CompositeCommand islandTeamCommand) { public IslandTeamInviteRejectCommand(IslandTeamCommand islandTeamCommand) {
super(islandTeamCommand, "reject"); super(islandTeamCommand, "reject");
this.itc = islandTeamCommand;
} }
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.invite.reject.description"); setDescription("commands.island.team.invite.reject.description");
} }
@ -26,11 +28,11 @@ public class IslandTeamInviteRejectCommand 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();
// Reject /island reject // Reject /island reject
if (inviteList.containsKey(playerUUID)) { if (itc.getInviteCommand().getInviteList().containsKey(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()
.getIsland(user.getWorld(), inviteList.get(playerUUID))) .getIsland(user.getWorld(), itc.getInviteCommand().getInviteList().get(playerUUID)))
.reason(TeamEvent.Reason.REJECT) .reason(TeamEvent.Reason.REJECT)
.involvedPlayer(playerUUID) .involvedPlayer(playerUUID)
.build(); .build();
@ -40,13 +42,14 @@ public class IslandTeamInviteRejectCommand extends AbstractIslandTeamCommand {
} }
// Remove this player from the global invite list // Remove this player from the global invite list
inviteList.remove(user.getUniqueId()); itc.getInviteCommand().getInviteList().remove(user.getUniqueId());
user.sendMessage("commands.island.team.invite.reject.you-rejected-invite"); user.sendMessage("commands.island.team.invite.reject.you-rejected-invite");
User inviter = User.getInstance(inviteList.get(playerUUID)); User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", "[name]", user.getName()); inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", "[name]", user.getName());
} else { } else {
// Someone typed /island reject and had not been invited // Someone typed /island reject and had not been invited
// TODO: make the error nicer if there are invites in other worlds
user.sendMessage("commands.island.team.invite.errors.none-invited-you"); user.sendMessage("commands.island.team.invite.errors.none-invited-you");
return false; return false;
} }

View File

@ -7,11 +7,10 @@ import java.util.UUID;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
public class IslandTeamKickCommand extends AbstractIslandTeamCommand { public class IslandTeamKickCommand extends CompositeCommand {
Set<UUID> kickSet; Set<UUID> kickSet;
@ -21,7 +20,7 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.island.team.kick.parameters"); setParameters("commands.island.team.kick.parameters");
setDescription("commands.island.team.kick.description"); setDescription("commands.island.team.kick.description");

View File

@ -7,11 +7,10 @@ import java.util.UUID;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand { public class IslandTeamLeaveCommand extends CompositeCommand {
Set<UUID> leaveSet; Set<UUID> leaveSet;
@ -21,7 +20,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.leave.description"); setDescription("commands.island.team.leave.description");
leaveSet = new HashSet<>(); leaveSet = new HashSet<>();

View File

@ -2,11 +2,10 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.List; import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand { public class IslandTeamPromoteCommand extends CompositeCommand {
public IslandTeamPromoteCommand(CompositeCommand islandTeamCommand, String string) { public IslandTeamPromoteCommand(CompositeCommand islandTeamCommand, String string) {
super(islandTeamCommand, string); super(islandTeamCommand, string);
@ -14,7 +13,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
if (this.getLabel().equals("promote")) { if (this.getLabel().equals("promote")) {
setParameters("commands.island.team.promote.parameters"); setParameters("commands.island.team.promote.parameters");

View File

@ -5,14 +5,13 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent; import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand { public class IslandTeamSetownerCommand extends CompositeCommand {
public IslandTeamSetownerCommand(CompositeCommand islandTeamCommand) { public IslandTeamSetownerCommand(CompositeCommand islandTeamCommand) {
super(islandTeamCommand, "setleader"); super(islandTeamCommand, "setleader");
@ -20,7 +19,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
@Override @Override
public void setup() { public void setup() {
setPermission(Constants.PERMPREFIX + "island.team"); setPermission("island.team");
setOnlyPlayer(true); setOnlyPlayer(true);
setParameters("commands.island.team.setowner.parameters"); setParameters("commands.island.team.setowner.parameters");
setDescription("commands.island.team.setowner.description"); setDescription("commands.island.team.setowner.description");

View File

@ -418,5 +418,14 @@ public class IslandWorldManager {
public World getIslandWorld(String friendlyWorldName) { public World getIslandWorld(String friendlyWorldName) {
return worlds.entrySet().stream().filter(e -> e.getValue().equalsIgnoreCase(friendlyWorldName)).findFirst().map(en -> en.getKey()).orElse(null); return worlds.entrySet().stream().filter(e -> e.getValue().equalsIgnoreCase(friendlyWorldName)).findFirst().map(en -> en.getKey()).orElse(null);
} }
/**
* Get max team size for this world
* @param world
* @return max team size
*/
public int getMaxTeamSize(World world) {
return worldSettings.get(Util.getWorld(world)).getMaxTeamSize();
}
} }

View File

@ -48,7 +48,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.commands.CompositeCommand; import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
@ -115,7 +114,7 @@ public class TestBSkyBlock {
player = mock(Player.class); player = mock(Player.class);
ownerOfIsland = mock(Player.class); ownerOfIsland = mock(Player.class);
visitorToIsland = mock(Player.class); visitorToIsland = mock(Player.class);
Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true); Mockito.when(player.hasPermission("default.permission")).thenReturn(true);
location = mock(Location.class); location = mock(Location.class);
@ -191,7 +190,7 @@ public class TestBSkyBlock {
User user = User.getInstance(playerUUID); User user = User.getInstance(playerUUID);
CompositeCommand testCommand = new TestCommand(); CompositeCommand testCommand = new TestCommand();
testCommand.setOnlyPlayer(true); testCommand.setOnlyPlayer(true);
testCommand.setPermission(Constants.PERMPREFIX + "default.permission"); testCommand.setPermission("default.permission");
// Test basic execution // Test basic execution
assertTrue(testCommand.execute(user, new ArrayList<>())); assertTrue(testCommand.execute(user, new ArrayList<>()));
assertEquals("test",testCommand.getLabel()); assertEquals("test",testCommand.getLabel());
@ -199,7 +198,7 @@ public class TestBSkyBlock {
assertEquals("t", testCommand.getAliases().get(0)); assertEquals("t", testCommand.getAliases().get(0));
assertTrue(testCommand.isOnlyPlayer()); assertTrue(testCommand.isOnlyPlayer());
assertNull(testCommand.getParent()); assertNull(testCommand.getParent());
assertEquals(Constants.PERMPREFIX + "default.permission", testCommand.getPermission()); assertEquals("default.permission", testCommand.getPermission());
// Check commands and aliases match to correct class // Check commands and aliases match to correct class
for (Entry<String, CompositeCommand> command : testCommand.getSubCommands().entrySet()) { for (Entry<String, CompositeCommand> command : testCommand.getSubCommands().entrySet()) {
assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue())); assertEquals(testCommand.getSubCommand(command.getKey()), Optional.of(command.getValue()));
@ -233,7 +232,7 @@ public class TestBSkyBlock {
// Test command arguments // Test command arguments
CompositeCommand argCmd = new Test3ArgsCommand(); CompositeCommand argCmd = new Test3ArgsCommand();
argCmd.setOnlyPlayer(true); argCmd.setOnlyPlayer(true);
argCmd.setPermission(Constants.PERMPREFIX + "default.permission"); argCmd.setPermission("default.permission");
assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"})); assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"})); assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"}));

View File

@ -28,7 +28,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.managers.CommandsManager; import us.tastybento.bskyblock.managers.CommandsManager;
@ -85,7 +84,7 @@ public class AdminCommandTest {
when(plugin.getCommandsManager()).thenReturn(cm); when(plugin.getCommandsManager()).thenReturn(cm);
AdminCommand ac = new AdminCommand(); AdminCommand ac = new AdminCommand();
ac.setup(); ac.setup();
assertEquals(Constants.PERMPREFIX + "admin.*", ac.getPermission()); assertEquals("bskyblock.admin.*", ac.getPermission());
assertFalse(ac.isOnlyPlayer()); assertFalse(ac.isOnlyPlayer());
assertEquals("commands.admin.help.parameters", ac.getParameters()); assertEquals("commands.admin.help.parameters", ac.getParameters());
assertEquals("commands.admin.help.description", ac.getDescription()); assertEquals("commands.admin.help.description", ac.getDescription());

View File

@ -31,7 +31,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.events.IslandBaseEvent; import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent; import us.tastybento.bskyblock.api.events.island.IslandEvent;
@ -99,7 +98,7 @@ public class IslandCommandTest {
assertEquals("commands.island.help.description", ic.getDescription()); assertEquals("commands.island.help.description", ic.getDescription());
assertTrue(ic.isOnlyPlayer()); assertTrue(ic.isOnlyPlayer());
// Permission // Permission
assertEquals(Constants.PERMPREFIX + "island", ic.getPermission()); assertEquals("bskyblock.island", ic.getPermission());
} }