use of com.wasteofplastic.acidisland.Island.SettingsFlag in project acidisland by tastybento.
the class AdminCmd method onTabComplete.
@Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
final List<String> options = new ArrayList<String>();
String lastArg = (args.length != 0 ? args[args.length - 1] : "");
if (!(sender instanceof Player)) {
switch(args.length) {
case 0:
case 1:
options.addAll(Arrays.asList("reload", "topten", "unregister", "delete", "completechallenge", "resetchallenge", "resetchallengeforall", "resetallchallenges", "purge", "info", "info", "info", "listchallengeresets", "clearreset", "clearresetall", "setbiome", "topbreeders", "team", "name", "setdeaths", "settingsreset", "setrange", "addrange", "resetname", "register", "cobblestats", "clearchallengereset", "setlanguage"));
break;
case 2:
if (args[0].equalsIgnoreCase("setlanguage")) {
options.addAll(plugin.getAvailableLocales().keySet());
}
if (args[0].equalsIgnoreCase("name") || args[0].equalsIgnoreCase("resetname") || args[0].equalsIgnoreCase("setdeaths")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("setrange") || args[0].equalsIgnoreCase("addrange")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("resetsign")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("unregister") || args[0].equalsIgnoreCase("register")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("resetchallenge")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("completechallenge") || args[0].equalsIgnoreCase("resetallchallenges")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("info")) {
options.add("challenges");
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("clearreset")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("setbiome")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("team")) {
options.add("add");
options.add("kick");
}
if (args[0].equalsIgnoreCase("settingsreset")) {
options.add("help");
options.add("all");
for (SettingsFlag flag : SettingsFlag.values()) {
options.add(flag.toString());
}
}
if (args[0].equalsIgnoreCase("resetchallengeforall")) {
options.addAll(Settings.challengeList);
}
if (args[0].equalsIgnoreCase("clearchallengereset")) {
options.addAll(plugin.getChallenges().getRepeatingChallengeResetsRaw());
}
break;
case 3:
if (args[0].equalsIgnoreCase("completechallenge")) {
UUID uuid = plugin.getPlayers().getUUID(args[1]);
// plugin.getLogger().info("DEBUG: uuid = " + uuid);
if (uuid != null) {
options.addAll(plugin.getPlayers().getChallengesNotDone(uuid));
} else {
options.addAll(plugin.getChallenges().getAllChallenges());
}
}
if (args[0].equalsIgnoreCase("resetchallenge")) {
UUID uuid = plugin.getPlayers().getUUID(args[1]);
// plugin.getLogger().info("DEBUG: uuid = " + uuid);
if (uuid != null) {
options.addAll(plugin.getPlayers().getChallengesDone(uuid));
} else {
options.addAll(plugin.getChallenges().getAllChallenges());
}
}
if (args[0].equalsIgnoreCase("info") && args[1].equalsIgnoreCase("challenges")) {
options.addAll(Util.getOnlinePlayerList());
}
if (args[0].equalsIgnoreCase("setbiome")) {
final Biome[] biomes = Biome.values();
for (Biome b : biomes) {
if (plugin.getConfig().contains("biomes." + b.name())) {
options.add(b.name());
}
}
}
if (args[0].equalsIgnoreCase("team") && (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("kick"))) {
options.addAll(Util.getOnlinePlayerList());
}
break;
case 4:
if (args[0].equalsIgnoreCase("team") && args[1].equalsIgnoreCase("add")) {
options.addAll(Util.getOnlinePlayerList());
}
}
} else {
final Player player = (Player) sender;
switch(args.length) {
case 0:
case 1:
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.setlanguage") || player.isOp()) {
options.add("setlanguage");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.reload") || player.isOp()) {
options.add("reload");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.register") || player.isOp()) {
options.add("register");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.unregister") || player.isOp()) {
options.add("unregister");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.reserve") || player.isOp()) {
options.add("reserve");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.delete") || player.isOp()) {
options.add("delete");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.deleteisland") || player.isOp()) {
options.add("deleteisland");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.purge") || player.isOp()) {
options.add("purge");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.topten") || player.isOp()) {
options.add("topten");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.topbreeders") || player.isOp()) {
options.add("topbreeders");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.challenges") || player.isOp()) {
options.add("completechallenge");
options.add("resetchallenge");
options.add("resetallchallenges");
options.add("listchallengeresets");
options.add("resetchallengeforall");
options.add("clearchallengereset");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.info") || player.isOp()) {
options.add("info");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.clearreset") || player.isOp()) {
options.add("clearreset");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.setdeaths") || player.isOp()) {
options.add("setdeaths");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.clearresetall") || player.isOp()) {
options.add("clearresetall");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.setspawn") || player.isOp()) {
options.add("setspawn");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.setrange") || player.isOp()) {
options.add("setrange");
options.add("addrange");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.tp") || player.isOp()) {
options.add("tp");
}
if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null && (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.tpnether") || player.isOp())) {
options.add("tpnether");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.setbiome") || player.isOp()) {
options.add("setbiome");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.team") || player.isOp()) {
options.add("team");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.lock") || player.isOp()) {
options.add("lock");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.signadmin") || player.isOp()) {
options.add("resetsign");
}
if (Settings.teamChat && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.spy") || player.isOp()) {
options.add("spy");
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.switch")) {
options.add("switch");
}
break;
case 2:
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.setlanguage") || player.isOp()) && args[0].equalsIgnoreCase("setlanguage")) {
options.addAll(plugin.getAvailableLocales().keySet());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.setrange") || player.isOp()) && (args[0].equalsIgnoreCase("setrange") || args[0].equalsIgnoreCase("addrange"))) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.reserve") || player.isOp()) && args[0].equalsIgnoreCase("reserve")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.lock") || player.isOp()) && args[0].equalsIgnoreCase("lock")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.signadmin") || player.isOp()) && args[0].equalsIgnoreCase("signadmin")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.unregister") || player.isOp()) && args[0].equalsIgnoreCase("unregister")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.delete") || player.isOp()) && args[0].equalsIgnoreCase("delete")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.challenges") || player.isOp()) && (args[0].equalsIgnoreCase("completechallenge") || args[0].equalsIgnoreCase("resetchallenge"))) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.challenges") || player.isOp()) && args[0].equalsIgnoreCase("resetallchallenges")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.challenges") || player.isOp()) && args[0].equalsIgnoreCase("resetchallengeforall")) {
options.addAll(Settings.challengeList);
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.challenges") || player.isOp()) && args[0].equalsIgnoreCase("clearchallengereset")) {
options.addAll(plugin.getChallenges().getRepeatingChallengeResetsRaw());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.info") || player.isOp()) && args[0].equalsIgnoreCase("info")) {
options.add("challenges");
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.clearreset") || player.isOp()) && args[0].equalsIgnoreCase("clearreset")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.setdeaths") || player.isOp()) && args[0].equalsIgnoreCase("setdeaths")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.tp") || player.isOp()) && (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("tpnether"))) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.setbiome") || player.isOp()) && args[0].equalsIgnoreCase("setbiome")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.team") || player.isOp()) && args[0].equalsIgnoreCase("team")) {
options.add("kick");
options.add("add");
}
break;
case 3:
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.challenges") || player.isOp())) {
if (args[0].equalsIgnoreCase("completechallenge")) {
UUID uuid = plugin.getPlayers().getUUID(args[1]);
// plugin.getLogger().info("DEBUG: uuid = " + uuid);
if (uuid != null) {
options.addAll(plugin.getPlayers().getChallengesNotDone(uuid));
} else {
options.addAll(plugin.getChallenges().getAllChallenges());
}
}
if (args[0].equalsIgnoreCase("resetchallenge")) {
UUID uuid = plugin.getPlayers().getUUID(args[1]);
// plugin.getLogger().info("DEBUG: uuid = " + uuid);
if (uuid != null) {
options.addAll(plugin.getPlayers().getChallengesDone(uuid));
} else {
options.addAll(plugin.getChallenges().getAllChallenges());
}
}
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.info") || player.isOp()) && args[0].equalsIgnoreCase("info") && args[1].equalsIgnoreCase("challenges")) {
options.addAll(Util.getOnlinePlayerList());
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.setbiome") || player.isOp()) && args[0].equalsIgnoreCase("setbiome")) {
final Biome[] biomes = Biome.values();
for (Biome b : biomes) {
if (plugin.getConfig().contains("biomes." + b.name())) {
options.add(b.name());
}
}
}
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.team") || player.isOp()) && args[0].equalsIgnoreCase("team") && (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("kick"))) {
options.addAll(Util.getOnlinePlayerList());
}
break;
case 4:
if ((VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.team") || player.isOp()) && args[0].equalsIgnoreCase("team") && args[1].equalsIgnoreCase("add")) {
for (Player p : plugin.getServer().getOnlinePlayers()) {
options.add(p.getName());
}
}
}
}
return Util.tabLimit(options, lastArg);
}
use of com.wasteofplastic.acidisland.Island.SettingsFlag in project acidisland by tastybento.
the class GridManager method convert.
/**
* Converts from the old version where islands were stored in an island
* folder.
* Did not work for large installations.
*/
private void convert() {
// Read spawn file if it exists
final File spawnFile = new File(plugin.getDataFolder(), "spawn.yml");
if (spawnFile.exists()) {
YamlConfiguration spawn = new YamlConfiguration();
try {
spawn.load(spawnFile);
int range = spawn.getInt("spawn.range");
// plugin.getLogger().info("DEBUG:" + range + " " +
// spawn.getString("spawn.bedrock",""));
Location spawnLoc = Util.getLocationString(spawn.getString("spawn.bedrock", ""));
if (spawnLoc != null && onGrid(spawnLoc)) {
Island newIsland = addIsland(spawnLoc.getBlockX(), spawnLoc.getBlockZ());
setSpawn(newIsland);
newIsland.setProtectionSize(range);
} else {
plugin.getLogger().severe("Spawn could not be imported! Location " + spawnLoc);
plugin.getLogger().severe("Go to the spawn island and set it manually");
}
} catch (Exception e) {
plugin.getLogger().severe("Spawn could not be imported! File could not load.");
}
}
// Go through player folder
final File playerFolder = new File(plugin.getDataFolder() + File.separator + "players");
final File quarantineFolder = new File(plugin.getDataFolder() + File.separator + "quarantine");
YamlConfiguration playerFile = new YamlConfiguration();
int noisland = 0;
int inTeam = 0;
int count = 0;
if (playerFolder.exists() && playerFolder.listFiles().length > 0) {
plugin.getLogger().warning("Reading player folder...");
if (playerFolder.listFiles().length > 5000) {
plugin.getLogger().warning("This could take some time with a large number of islands...");
}
for (File f : playerFolder.listFiles()) {
// Need to remove the .yml suffix
String fileName = f.getName();
if (fileName.endsWith(".yml")) {
try {
playerFile.load(f);
boolean hasIsland = playerFile.getBoolean("hasIsland", false);
if (hasIsland) {
String islandLocation = playerFile.getString("islandLocation");
if (islandLocation.isEmpty()) {
plugin.getLogger().severe("Problem with " + fileName);
plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
plugin.getLogger().severe("Player file says they have an island, but there is no location.");
// Move to quarantine
if (!quarantineFolder.exists()) {
quarantineFolder.mkdir();
}
// Move the file
plugin.getLogger().severe("Moving " + f.getName() + " to " + quarantineFolder.getName());
File rename = new File(quarantineFolder, f.getName());
f.renameTo(rename);
} else {
// Location exists
Location islandLoc = Util.getLocationString(islandLocation);
if (islandLoc != null) {
// Check to see if this island is already loaded
Island island = getIslandAt(islandLoc);
if (island != null) {
// PlayerIsland exists, compare creation dates
plugin.getLogger().severe("Problem with " + fileName);
plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
plugin.getLogger().severe("This island location already exists and is already imported");
if (island.getUpdatedDate() > f.lastModified()) {
plugin.getLogger().severe("Previous file is more recent so keeping it.");
// Move to quarantine
if (!quarantineFolder.exists()) {
quarantineFolder.mkdir();
}
plugin.getLogger().severe("Moving " + (playerFile.getString("playerName", "Unknown")) + "'s file (" + f.getName() + ") to " + quarantineFolder.getName());
File rename = new File(quarantineFolder, f.getName());
f.renameTo(rename);
} else {
// New file is more recent
plugin.getLogger().severe(playerFile.getString("playerName", "Unknown") + "'s file is more recent");
File oldFile = new File(playerFolder, island.getOwner().toString() + ".yml");
File rename = new File(quarantineFolder, oldFile.getName());
// Move to quarantine
if (!quarantineFolder.exists()) {
quarantineFolder.mkdir();
}
plugin.getLogger().severe("Moving previous file (" + oldFile.getName() + ") to " + quarantineFolder.getName());
oldFile.renameTo(rename);
deleteIsland(islandLoc);
island = null;
}
}
if (island == null) {
if (!onGrid(islandLoc)) {
plugin.getLogger().severe("Problem with " + fileName);
plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
plugin.getLogger().severe("Island is not on grid lines! " + islandLoc);
}
String ownerString = fileName.substring(0, fileName.length() - 4);
// Add the island
UUID owner = UUID.fromString(ownerString);
Island newIsland = addIsland(islandLoc.getBlockX(), islandLoc.getBlockZ(), owner);
ownershipMap.put(owner, newIsland);
// Grab when this was last updated
newIsland.setUpdatedDate(f.lastModified());
if ((count) % 1000 == 0) {
plugin.getLogger().info("Converted " + count + " islands");
}
count++;
// plugin.getLogger().info("Converted island at "
// + islandLoc);
// Top ten
int islandLevel = playerFile.getInt("islandLevel", 0);
String teamLeaderUUID = playerFile.getString("teamLeader", "");
if (islandLevel > 0) {
if (!playerFile.getBoolean("hasTeam")) {
plugin.getTopTen().topTenAddEntry(owner, islandLevel);
} else if (!teamLeaderUUID.isEmpty()) {
if (teamLeaderUUID.equals(ownerString)) {
plugin.getTopTen().topTenAddEntry(owner, islandLevel);
}
}
}
// Check if there is an island info string and see if it jibes
String islandInfo = playerFile.getString("islandInfo", "");
if (!islandInfo.isEmpty()) {
String[] split = islandInfo.split(":");
try {
// int protectionRange = Integer.parseInt(split[3]);
// int islandDistance = Integer.parseInt(split[4]);
newIsland.setLocked(false);
if (split.length > 6) {
// Get locked status
if (split[6].equalsIgnoreCase("true")) {
newIsland.setLocked(true);
}
}
// Check if deletable
newIsland.setPurgeProtected(false);
if (split.length > 7) {
if (split[7].equalsIgnoreCase("true")) {
newIsland.setPurgeProtected(true);
}
}
if (!split[5].equals("null")) {
if (split[5].equals("spawn")) {
newIsland.setSpawn(true);
// Try to get the spawn point
if (split.length > 8) {
// plugin.getLogger().info("DEBUG: " + serial.substring(serial.indexOf(":SP:") + 4));
Location spawnPoint = Util.getLocationString(islandInfo.substring(islandInfo.indexOf(":SP:") + 4));
newIsland.setSpawnPoint(spawnPoint);
}
}
}
// Check if protection options there
if (!newIsland.isSpawn()) {
// plugin.getLogger().info("DEBUG: NOT SPAWN owner is " + owner + " location " + center);
if (split.length > 8 && split[8].length() == 29) {
// Parse the 8th string into island guard protection settings
int index = 0;
// Run through the enum and set
for (SettingsFlag flag : SettingsFlag.values()) {
if (index < split[8].length()) {
newIsland.setIgsFlag(flag, split[8].charAt(index++) == '1');
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else {
plugin.getLogger().severe("Problem with " + fileName);
plugin.getLogger().severe("Owner :" + playerFile.getString("playerName", "Unknown"));
plugin.getLogger().severe("The world for this file does not exist!");
}
}
} else {
noisland++;
if (playerFile.getBoolean("hasTeam", false)) {
inTeam++;
}
}
} catch (Exception e) {
plugin.getLogger().severe("Problem with " + fileName);
// e.printStackTrace();
}
}
}
plugin.getLogger().info("Converted " + count + " islands from player's folder");
plugin.getLogger().info(noisland + " have no island, of which " + inTeam + " are in a team.");
plugin.getLogger().info((noisland - inTeam) + " are in the system, but have no island or team");
}
int count2 = 0;
// Check island folder
final File islandFolder = new File(plugin.getDataFolder() + File.separator + "islands");
if (islandFolder.exists() && islandFolder.listFiles().length > 0) {
plugin.getLogger().warning("Reading island folder...");
if (islandFolder.listFiles().length > 5000) {
plugin.getLogger().warning("This could take some time with a large number of islands...");
}
for (File f : islandFolder.listFiles()) {
// Need to remove the .yml suffix
String fileName = f.getName();
int comma = fileName.indexOf(",");
if (fileName.endsWith(".yml") && comma != -1) {
try {
// Parse to an island value
int x = Integer.parseInt(fileName.substring(0, comma));
int z = Integer.parseInt(fileName.substring(comma + 1, fileName.indexOf(".")));
if (!onGrid(x, z)) {
plugin.getLogger().severe("Island is not on grid lines! " + x + "," + z + " skipping...");
} else {
// Note that this is the CENTER of the island
if (getIslandAt(x, z) == null) {
addIsland(x, z);
if (count2 % 1000 == 0) {
plugin.getLogger().info("Converted " + count + " islands");
}
count2++;
// plugin.getLogger().info("Added island from island folder: "
// + x + "," +z);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
plugin.getLogger().info("Converted " + count2 + " islands from island folder");
plugin.getLogger().info("Total " + (count + count2) + " islands converted.");
}
// Now save the islandGrid
saveGrid();
}
Aggregations