Skip to content

Commit

Permalink
1.2.2: homes are now numeric in config
Browse files Browse the repository at this point in the history
cleaned Messages class
  • Loading branch information
aleksilassila committed Oct 1, 2020
1 parent 95e3b42 commit 2227168
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 88 deletions.
39 changes: 8 additions & 31 deletions src/me/aleksilassila/islands/commands/IslandCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.aleksilassila.islands.Islands;
import me.aleksilassila.islands.Main;
import me.aleksilassila.islands.utils.Messages;
import me.aleksilassila.islands.utils.Permissions;
import me.aleksilassila.islands.generation.IslandGrid;
import me.aleksilassila.islands.utils.ChatUtils;
Expand Down Expand Up @@ -143,7 +144,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
}

String homeId = args.length == 0 ? "1" : args[0];
int homeId;

try {
homeId = args.length == 0 ? 1 : Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
homeId = 1;
}

Location location = grid.getIslandSpawn(grid.getHomeIsland(player.getUniqueId(), homeId));

Expand Down Expand Up @@ -180,34 +187,4 @@ private int teleportCooldown(Player player) {

return 0;
}

static class Messages extends ChatUtils {
static class error {
public static final String ISLAND_NOT_FOUND = error("404 - Home not found.");
public static final String NO_PERMISSION = error("You don't have permission to use this command.");
public static final String HOME_NOT_FOUND = error("404 - Home not found :(");

public static String COOLDOWN(int remainingTime) {
return error("You took damage recently. You have to wait for " + remainingTime + "s before teleporting.");
}
}

static class success {


public static String HOMES_FOUND(int amount) {
return success("Found " + amount + " home(s).");
}
}

static class info {
public static final String ON_SURFACE = info("You can only use this command on surface.");
public static final String IN_OVERWORLD = info("You can only use this command in overworld.");
}

static class help {
public static final String VISIT = info("Usage: /visit name");
public static final String HOME = error("Usage: /home <id>");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
return;
}

if (plugin.getIslandsConfig().getInt("islands." + islandId + ".home") <= 0
|| plugin.getIslandsConfig().getString("islands." + islandId + ".UUID") == null) {
player.sendMessage(Messages.error.ISLAND_NO_OWNER);
return;
}

if (plugin.getIslandsConfig().getString("islands." + islandId + ".UUID").equals(player.getUniqueId().toString())
|| Permissions.checkPermission(player, Permissions.bypass.unname)) {
grid.unnameIsland(islandId);
Expand Down
47 changes: 11 additions & 36 deletions src/me/aleksilassila/islands/generation/IslandGeneration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sun.istack.internal.Nullable;
import me.aleksilassila.islands.Islands;
import me.aleksilassila.islands.utils.ChatUtils;
import me.aleksilassila.islands.utils.Messages;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void addToQueue(CopyTask task) {
popFromQueue(task.player.getUniqueId().toString());
queue.add(task);

task.player.sendMessage(Messages.Info.QUEUE_STATUS(queue.size()));
task.player.sendMessage(Messages.info.QUEUE_STATUS(queue.size()));
}

@Nullable
Expand Down Expand Up @@ -114,16 +115,16 @@ public void run() {
}

if (clearingIndex >= islands.grid.islandSpacing * islands.grid.islandSpacing) {
player.sendMessage(Messages.Success.CLEARING_DONE);
player.sendMessage(Messages.success.CLEARING_DONE);

clearingArea = false;
break;
} else if (clearingIndex == islands.grid.islandSpacing * islands.grid.islandSpacing / 4) {
player.sendMessage(Messages.Info.CLEARING_STATUS(25));
player.sendMessage(Messages.info.CLEARING_STATUS(25));
} else if (clearingIndex == islands.grid.islandSpacing * islands.grid.islandSpacing / 2) {
player.sendMessage(Messages.Info.CLEARING_STATUS(50));
player.sendMessage(Messages.info.CLEARING_STATUS(50));
} else if (clearingIndex == islands.grid.islandSpacing * islands.grid.islandSpacing / 4 * 3) {
player.sendMessage(Messages.Info.CLEARING_STATUS(75));
player.sendMessage(Messages.info.CLEARING_STATUS(75));
}

clearingIndex++;
Expand Down Expand Up @@ -159,23 +160,23 @@ public void run() {
// Update lighting
islands.plugin.islandsWorld.getChunkAt(targetX + islandSize / 2, targetZ + islandSize / 2);

player.sendMessage(Messages.Success.GENERATION_DONE);
player.sendMessage(Messages.success.GENERATION_DONE);
queue.remove(this);

if (queue.size() > 0) {
CopyTask nextTask = queue.get(0);
nextTask.runTaskTimer(islands.plugin, 0, buildDelay);
nextTask.player.sendMessage(Messages.Info.GENERATION_STARTED(nextTask.islandSize * nextTask.islandSize / 20.0));
nextTask.player.sendMessage(Messages.info.GENERATION_STARTED(nextTask.islandSize * nextTask.islandSize / 20.0));
}

this.cancel();
break loop;
} else if (index == islandSize * islandSize / 4) {
player.sendMessage(Messages.Info.GENERATION_STATUS(25));
player.sendMessage(Messages.info.GENERATION_STATUS(25));
} else if (index == islandSize * islandSize / 2) {
player.sendMessage(Messages.Info.GENERATION_STATUS(50));
player.sendMessage(Messages.info.GENERATION_STATUS(50));
} else if (index == islandSize * islandSize / 4 * 3) {
player.sendMessage(Messages.Info.GENERATION_STATUS(75));
player.sendMessage(Messages.info.GENERATION_STATUS(75));
}

index++;
Expand Down Expand Up @@ -242,30 +243,4 @@ public boolean isBlockInIslandCircle(int relativeX, int relativeZ, int islandSiz
return (Math.pow(relativeX - islandSize / 2.0, 2) + Math.pow(relativeZ - islandSize / 2.0, 2))
<= Math.pow(islandSize / 2.0, 2);
}

static class Messages extends ChatUtils {
static class Success {

public static final String GENERATION_DONE = success("Island generation completed.");
public static final String CLEARING_DONE = success("Island clearing done.");
}

static class Info {
public static String GENERATION_STARTED(double time) {
return info("Your generation event has been started. It will take approximately " + (int) time + " seconds.");
}

public static String QUEUE_STATUS(int queueSize) {
return info("Your event has been added to the queue. There are " + (queueSize - 1) + " event(s) before yours.");
}

public static String GENERATION_STATUS(int status) {
return info("Your generation event is " + status + "% completed.");
}

public static String CLEARING_STATUS(int status) {
return info("Clearing event " + status + "% completed.");
}
}
}
}
22 changes: 11 additions & 11 deletions src/me/aleksilassila/islands/generation/IslandGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ private FileConfiguration getIslandsConfig() {
}

public void unnameIsland(String islandId) {
String homeId = islands.plugin.getIslandsConfig().getString("islands." + islandId + ".home");
int homeId = islands.plugin.getIslandsConfig().getInt("islands." + islandId + ".home");

getIslandsConfig().set("islands." + islandId + ".name", homeId);
getIslandsConfig().set("islands." + islandId + ".name", String.valueOf(homeId));
getIslandsConfig().set("islands." + islandId + ".public", 0);

islands.plugin.saveIslandsConfig();
Expand Down Expand Up @@ -111,11 +111,11 @@ public String getPublicIsland(String name) {
}

@Nullable
public String getHomeIsland(UUID uuid, String homeId) {
public String getHomeIsland(UUID uuid, int homeId) {
List<String> allIslands = getAllIslandIds(uuid);

for (String islandId : allIslands) {
if (getIslandsConfig().getString("islands." + islandId + ".home").equals(homeId)) {
if (getIslandsConfig().getInt("islands." + islandId + ".home") == homeId) {
return islandId;
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ private String addIslandToConfig(int xIndex, int zIndex, int islandSize, UUID uu
int realY = getIslandY(xIndex, zIndex);
int realZ = zIndex * islandSpacing + islandSpacing / 2 - islandSize / 2;

String home = getNewHomeId(uuid);
int home = getNewHomeId(uuid);

String islandId = xIndex + "x" + zIndex;

Expand Down Expand Up @@ -212,7 +212,7 @@ public String createIsland(UUID uuid, int islandSize) {
}
}

return addIslandToConfig(x, z, islandSize, uuid, getNewHomeId(uuid));
return addIslandToConfig(x, z, islandSize, uuid, String.valueOf(getNewHomeId(uuid)));
}
}

Expand Down Expand Up @@ -291,19 +291,19 @@ public void setSpawnPoint(String islandId, int x, int y) {
getIslandsConfig().set("islands." + islandId + ".spawnPoint.y", y);
}

public String getNewHomeId(UUID uuid) {
public int getNewHomeId(UUID uuid) {
List<String> ids = getAllIslandIds(uuid);
List<String> homeIds = new ArrayList<>();
List<Integer> homeIds = new ArrayList<>();

for (String islandId : ids) {
String homeNumber = getIslandsConfig().getString("islands." + islandId + ".home");
int homeNumber = getIslandsConfig().getInt("islands." + islandId + ".home");
homeIds.add(homeNumber);
}

String home = String.valueOf(getNumberOfIslands(uuid) + 1);
int home = getNumberOfIslands(uuid) + 1;

for (int i = 1; i <= getNumberOfIslands(uuid) + 1; i++) {
if (!homeIds.contains(String.valueOf(i))) home = String.valueOf(i);
if (!homeIds.contains(i)) home = i;
}

return home;
Expand Down
49 changes: 41 additions & 8 deletions src/me/aleksilassila/islands/utils/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ public static class error {
public static final String NOT_ON_ISLAND = error("You have to be on an island.");
public static final String NOT_OWNED = error("You don't own this island.");
public static final String PLAYER_NOT_FOUND = error("Player not found.");
public static String NO_BIOME_FOUND = error("Biome not found.");
public static String NO_LOCATIONS_FOR_BIOME = error("No available locations for specified biome.");
public static final String ISLAND_NO_OWNER = error("To make an island private, it must have an owner.");
public static final String NO_BIOME_FOUND = error("Biome not found.");
public static final String NO_LOCATIONS_FOR_BIOME = error("No available locations for specified biome.");
public static final String ISLAND_NOT_FOUND = error("404 - Home not found.");
public static final String HOME_NOT_FOUND = error("404 - Home not found :(");

public static String COOLDOWN(int remainingTime) {
return error("You took damage recently. You have to wait for " + remainingTime + "s before teleporting.");
}
}

public static class success {
Expand All @@ -31,6 +38,8 @@ public static class success {
public static final String TRUSTED = success("Player trusted!");
public static final String SPAWNPOINT_CHANGED = success("Island spawn point changed.");
public static final String OWNER_REMOVED = success("Island owner removed.");
public static final String GENERATION_DONE = success("Island generation completed.");
public static final String CLEARING_DONE = success("Island clearing done.");

public static String OWNER_CHANGED(String name) {
return success("Island owner switched to " + name + ".");
Expand All @@ -43,10 +52,16 @@ public static String NAME_CHANGED(String name) {
public static String ISLAND_RECEIVED(String playerName, String islandName) {
return success("You are now the owner of " + playerName + "'s island " + islandName + ".");
}

public static String HOMES_FOUND(int amount) {
return success("Found " + amount + " home(s).");
}
}

public static class info {
public static final String CONFIRM = info("Are you sure? Repeat the command to confirm.");
public static final String ON_SURFACE = info("You can only use this command on surface.");
public static final String IN_OVERWORLD = info("You can only use this command in overworld.");

public static String TRUSTED_INFO(int numberOfPlayers) {
return info("You have trusted " + numberOfPlayers + " player(s).");
Expand All @@ -55,17 +70,35 @@ public static String TRUSTED_INFO(int numberOfPlayers) {
public static String TRUSTED_PLAYER(String displayName) {
return ChatColor.GRAY + " - " + displayName;
}

public static String GENERATION_STARTED(double time) {
return info("Your generation event has been started. It will take approximately " + (int) time + " seconds.");
}

public static String QUEUE_STATUS(int queueSize) {
return info("Your event has been added to the queue. There are " + (queueSize - 1) + " event(s) before yours.");
}

public static String GENERATION_STATUS(int status) {
return info("Your generation event is " + status + "% completed.");
}

public static String CLEARING_STATUS(int status) {
return info("Clearing event " + status + "% completed.");
}
}

public static class help {
public static final String UNTRUST = info("/untrust <player> (You have to be on target island)");
public static final String TRUST = info("/trust <player> (You have to be on target island)");
public static final String SETSPAWN = info("/island setspawn");
public static String CREATE = ChatColor.GRAY + "/island create <biome> (<BIG/NORMAL/SMALL>)";
public static String REGENERATE = ChatColor.GRAY + "/island regenerate <biome> (<BIG/NORMAL/SMALL>) (You have to be on target island)";
public static String NAME = ChatColor.GRAY + "/island name <name> (You have to be on target island)";
public static String UNNAME = ChatColor.GRAY + "/island unname (You have to be on target island)";
public static String GIVE = ChatColor.GRAY + "/island give <name> (You have to be on target island)";
public static String DELETE = ChatColor.GRAY + "/island delete (You have to be on target island)";
public static final String CREATE = ChatColor.GRAY + "/island create <biome> (<BIG/NORMAL/SMALL>)";
public static final String REGENERATE = ChatColor.GRAY + "/island regenerate <biome> (<BIG/NORMAL/SMALL>) (You have to be on target island)";
public static final String NAME = ChatColor.GRAY + "/island name <name> (You have to be on target island)";
public static final String UNNAME = ChatColor.GRAY + "/island unname (You have to be on target island)";
public static final String GIVE = ChatColor.GRAY + "/island give <name> (You have to be on target island)";
public static final String DELETE = ChatColor.GRAY + "/island delete (You have to be on target island)";
public static final String VISIT = info("Usage: /visit name");
public static final String HOME = error("Usage: /home <id>");
}
}
4 changes: 2 additions & 2 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Islands
version: 1.2.0
version: 1.2.2
author: Aleksi Lassila
main: me.aleksilassila.islands.Main
api-version: 1.16
softdepend: [Vault]
commands:
island:
description: Island managment
usage: /<command> biome
usage: /<command>
aliases: [is]
visit:
description: Visit islands
Expand Down

0 comments on commit 2227168

Please sign in to comment.