Removed code smells.

This commit is contained in:
Tastybento 2018-05-01 23:20:13 -07:00
parent de85f85bbe
commit cccbf2d270
5 changed files with 25 additions and 17 deletions

View File

@ -19,6 +19,7 @@ import us.tastybento.bskyblock.managers.island.NewIsland;
public class IslandResetCommand extends CompositeCommand {
private static final String SECONDS_PLACEHOLDER = "[seconds]";
private Map<UUID, Long> cooldown;
private Map<UUID, Long> confirm;
@ -39,7 +40,7 @@ public class IslandResetCommand extends CompositeCommand {
public boolean execute(User user, List<String> args) {
// Check cooldown
if (getSettings().getResetWait() > 0 && onRestartWaitTime(user) > 0 && !user.isOp()) {
user.sendMessage("general.errors.you-must-wait", "[seconds]", String.valueOf(onRestartWaitTime(user)));
user.sendMessage("general.errors.you-must-wait", SECONDS_PLACEHOLDER, String.valueOf(onRestartWaitTime(user)));
return false;
}
if (!getIslands().hasIsland(user.getUniqueId())) {
@ -80,13 +81,13 @@ public class IslandResetCommand extends CompositeCommand {
} else {
// Show how many seconds left to confirm
int time = (int)((confirm.get(user.getUniqueId()) - System.currentTimeMillis()) / 1000D);
user.sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, "[seconds]", String.valueOf(time));
user.sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, "SECONDS_PLACEHOLDER", String.valueOf(time));
}
return true;
}
private void requestConfirmation(User user) {
user.sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, "[seconds]", String.valueOf(getSettings().getConfirmationTime()));
user.sendMessage("commands.island.reset.confirm", "[label]", Constants.ISLANDCOMMAND, "SECONDS_PLACEHOLDER", String.valueOf(getSettings().getConfirmationTime()));
// Require confirmation
confirm.put(user.getUniqueId(), System.currentTimeMillis() + getSettings().getConfirmationTime() * 1000L);
Bukkit.getScheduler().runTaskLater(getPlugin(), () -> {

View File

@ -37,6 +37,8 @@ public class IslandBuilder {
END
}
private static final String PLAYER_PLACEHOLDER = "[player]";
private Island island;
private World world;
private IslandType type = IslandType.ISLAND;
@ -460,10 +462,10 @@ public class IslandBuilder {
User user = User.getInstance(playerUUID);
// Sets the lines of the sign
sign.setLine(0, user.getTranslation("new-island.sign.line0", "[player]", playerName));
sign.setLine(1, user.getTranslation("new-island.sign.line1", "[player]", playerName));
sign.setLine(2, user.getTranslation("new-island.sign.line2", "[player]", playerName));
sign.setLine(3, user.getTranslation("new-island.sign.line3", "[player]", playerName));
sign.setLine(0, user.getTranslation("new-island.sign.line0", PLAYER_PLACEHOLDER, playerName));
sign.setLine(1, user.getTranslation("new-island.sign.line1", PLAYER_PLACEHOLDER, playerName));
sign.setLine(2, user.getTranslation("new-island.sign.line2", PLAYER_PLACEHOLDER, playerName));
sign.setLine(3, user.getTranslation("new-island.sign.line3", PLAYER_PLACEHOLDER, playerName));
((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
sign.update();

View File

@ -105,13 +105,18 @@ public class LockAndBanListener implements Listener {
* @return CheckResult LOCKED, BANNED or OPEN. If an island is locked, that will take priority over banned
*/
private CheckResult check(Player player, Location loc) {
// See if the island is locked to non-members or player is banned
return im.getProtectedIslandAt(loc)
.map(is -> !is.isAllowed(User.getInstance(player), Flags.LOCK) ? CheckResult.LOCKED
: is.isBanned(player.getUniqueId()) ? CheckResult.BANNED
: CheckResult.OPEN)
.orElse(CheckResult.OPEN);
.map(is -> {
if (is.isBanned(player.getUniqueId())) {
return CheckResult.BANNED;
}
if (!is.isAllowed(User.getInstance(player), Flags.LOCK)) {
return CheckResult.LOCKED;
}
return CheckResult.OPEN;
}).orElse(CheckResult.OPEN);
}
/**

View File

@ -53,14 +53,12 @@ public class LocalesManager {
/**
* Loads all the locales available. If the locale folder does not exist, one will be created and
* filled with locale files from the jar.
* TODO: Make more robust. The file filter is fragile.
*/
public void loadLocales(String parent) {
// Describe the filter - we only want files that are correctly named
FilenameFilter ymlFilter = (dir, name) -> {
// Files must be 9 chars long
return name.toLowerCase().endsWith(".yml") && name.length() == 9;
};
// Files must be 9 chars long
FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase().endsWith(".yml") && name.length() == 9;
// Run through the files and store the locales
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);

View File

@ -11,6 +11,8 @@ import us.tastybento.bskyblock.api.user.User;
* @author Poslovitch
*/
public class LanguagePanel {
private LanguagePanel() {}
/**
* Dynamically creates the panel.