Fixed some code smells

This commit is contained in:
Florian CUNY 2018-08-06 18:00:47 +02:00
parent 28cf3ca278
commit 16e864f495
10 changed files with 27 additions and 21 deletions

View File

@ -96,7 +96,7 @@ public class Settings implements DataObject {
@ConfigComment("Allow FTB Autonomous Activator to work (will allow a pseudo player [CoFH] to place and break blocks and hang items)") @ConfigComment("Allow FTB Autonomous Activator to work (will allow a pseudo player [CoFH] to place and break blocks and hang items)")
@ConfigComment("Add other fake player names here if required") @ConfigComment("Add other fake player names here if required")
@ConfigEntry(path = "general.fakeplayers") @ConfigEntry(path = "general.fakeplayers", experimental = true)
private Set<String> fakePlayers = new HashSet<>(); private Set<String> fakePlayers = new HashSet<>();
@ConfigComment("Allow obsidian to be scooped up with an empty bucket back into lava") @ConfigComment("Allow obsidian to be scooped up with an empty bucket back into lava")

View File

@ -59,10 +59,11 @@ public class DefaultHelpCommand extends CompositeCommand {
if (depth < MAX_DEPTH) { if (depth < MAX_DEPTH) {
if (!parent.getLabel().equals(HELP)) { if (!parent.getLabel().equals(HELP)) {
// Get elements // Get elements
String usage = parent.getUsage().isEmpty() ? "" : user.getTranslation(parent.getUsage()); String usage = user.getTranslationOrNothing(parent.getUsage());
String params = getParameters().isEmpty() ? "" : user.getTranslation(getParameters()); String params = user.getTranslationOrNothing(getParameters());
String desc = getDescription().isEmpty() ? "" : user.getTranslation(getDescription()); String desc = user.getTranslationOrNothing(getDescription());
if (showPrettyHelp(user, usage, params, desc)) { if (showPrettyHelp(user, usage, params, desc)) {
// No more to show // No more to show

View File

@ -34,7 +34,7 @@ public class AdminClearResetsAllCommand extends CompositeCommand {
Bukkit.getOnlinePlayers().stream().map(Player::getUniqueId).filter(getPlayers()::isKnown).forEach(u -> getPlayers().setResets(getWorld(), u, 0)); Bukkit.getOnlinePlayers().stream().map(Player::getUniqueId).filter(getPlayers()::isKnown).forEach(u -> getPlayers().setResets(getWorld(), u, 0));
user.sendMessage("general.success"); user.sendMessage("general.success");
}); });
return false; return true;
} }
} }

View File

@ -47,6 +47,9 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
case "hide": case "hide":
user.sendMessage("commands.admin.range.display.already-off"); user.sendMessage("commands.admin.range.display.already-off");
break; break;
default:
showHelp(this, user);
break;
} }
} else { } else {
switch (label) { switch (label) {
@ -57,6 +60,9 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
case "show": case "show":
user.sendMessage("commands.admin.range.display.already-on"); user.sendMessage("commands.admin.range.display.already-on");
break; break;
default:
showHelp(this, user);
break;
} }
} }

View File

@ -47,7 +47,7 @@ public class AdminRangeSetCommand extends CompositeCommand {
user.sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, args.get(1)); user.sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, args.get(1));
return false; return false;
} }
int range = Integer.valueOf(args.get(1)); int range = Integer.parseInt(args.get(1));
// Get island // Get island
Island island = getIslands().getIsland(getWorld(), targetUUID); Island island = getIslands().getIsland(getWorld(), targetUUID);

View File

@ -33,7 +33,7 @@ public class IslandGoCommand extends CompositeCommand {
return false; return false;
} }
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.parseInt(args.get(0));
int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getIWM().getMaxHomes(getWorld())); int maxHomes = Util.getPermValue(user.getPlayer(), "island.maxhomes", getIWM().getMaxHomes(getWorld()));
if (homeValue > 1 && homeValue <= maxHomes) { if (homeValue > 1 && homeValue <= maxHomes) {
getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue); getIslands().homeTeleport(getWorld(), user.getPlayer(), homeValue);

View File

@ -74,13 +74,9 @@ public class IslandTeamKickCommand extends CompositeCommand {
user.sendMessage("general.success"); user.sendMessage("general.success");
// Add cooldown for this player and target // Add cooldown for this player and target
if (getSettings().getInviteWait() > 0) { if (getSettings().getInviteWait() > 0 && getParent() != null) {
// Get the invite class from the parent // Get the invite class from the parent
if (getParent() != null) { getParent().getSubCommand("invite").ifPresent(c -> c.setCooldown(user.getUniqueId(), targetUUID, getSettings().getInviteWait() * 60));
getParent().getSubCommand("invite").ifPresent(c -> c.setCooldown(user.getUniqueId(), targetUUID, getSettings().getInviteWait() * 60));
}
} }
} }
} }

View File

@ -119,7 +119,9 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Information about the field // Information about the field
String storageLocation = field.getName(); String storageLocation = field.getName();
boolean overrideOnChange, experimental, needsReset = false; boolean overrideOnChange = false;
boolean experimental = false;
boolean needsReset = false;
// Check if there is an annotation on the field // Check if there is an annotation on the field
ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class);

View File

@ -21,6 +21,7 @@ import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.adapters.Adapter; import world.bentobox.bentobox.database.objects.adapters.Adapter;
import world.bentobox.bentobox.database.objects.adapters.FlagSerializer; import world.bentobox.bentobox.database.objects.adapters.FlagSerializer;
@ -623,7 +624,7 @@ public class Island implements DataObject {
Set<UUID> banned = getBanned(); Set<UUID> banned = getBanned();
if (!banned.isEmpty()) { if (!banned.isEmpty()) {
user.sendMessage("commands.admin.info.banned-players"); user.sendMessage("commands.admin.info.banned-players");
banned.forEach(u -> user.sendMessage("commands.admin.info.banned-format", "[name]", plugin.getPlayers().getName(u))); banned.forEach(u -> user.sendMessage("commands.admin.info.banned-format", TextVariables.NAME, plugin.getPlayers().getName(u)));
} }
return true; return true;
} }
@ -639,10 +640,10 @@ public class Island implements DataObject {
user.sendMessage("commands.admin.info.team-members-title"); user.sendMessage("commands.admin.info.team-members-title");
members.forEach((u, i) -> { members.forEach((u, i) -> {
if (owner.equals(u)) { if (owner.equals(u)) {
user.sendMessage("commands.admin.info.team-owner-format", "[name]", plugin.getPlayers().getName(u) user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME, plugin.getPlayers().getName(u)
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i))); , "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
} else if (i > RanksManager.VISITOR_RANK){ } else if (i > RanksManager.VISITOR_RANK){
user.sendMessage("commands.admin.info.team-member-format", "[name]", plugin.getPlayers().getName(u) user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME, plugin.getPlayers().getName(u)
, "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i))); , "[rank]", user.getTranslation(plugin.getRanksManager().getRank(i)));
} }
}); });

View File

@ -24,6 +24,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
@ -550,7 +551,7 @@ public class IslandsManager {
if (number == 1) { if (number == 1) {
user.sendMessage("commands.island.go.teleport"); user.sendMessage("commands.island.go.teleport");
} else { } else {
user.sendMessage("commands.island.go.teleported", "[number]", String.valueOf(number)); user.sendMessage("commands.island.go.teleported", TextVariables.NUMBER, String.valueOf(number));
} }
// Exit spectator mode if in it // Exit spectator mode if in it
if (player.getGameMode().equals(GameMode.SPECTATOR)) { if (player.getGameMode().equals(GameMode.SPECTATOR)) {
@ -769,7 +770,6 @@ public class IslandsManager {
return getMembers(world, playerUUID).size() > 1; return getMembers(world, playerUUID).size() > 1;
} }
/** /**
* Makes a new leader for an island * Makes a new leader for an island
* @param world - world * @param world - world
@ -799,8 +799,8 @@ public class IslandsManager {
int range = Util.getPermValue(target.getPlayer(), permPrefix + "island.range.", plugin.getIWM().getIslandProtectionRange(Util.getWorld(island.getWorld()))); int range = Util.getPermValue(target.getPlayer(), permPrefix + "island.range.", plugin.getIWM().getIslandProtectionRange(Util.getWorld(island.getWorld())));
// Range can go up or down // Range can go up or down
if (range != island.getProtectionRange()) { if (range != island.getProtectionRange()) {
user.sendMessage("commands.admin.setrange.range-updated", "[number]", String.valueOf(range)); user.sendMessage("commands.admin.setrange.range-updated", TextVariables.NUMBER, String.valueOf(range));
target.sendMessage("commands.admin.setrange.range-updated", "[number]", String.valueOf(range)); target.sendMessage("commands.admin.setrange.range-updated", TextVariables.NUMBER, String.valueOf(range));
plugin.log("Makeleader: Island protection range changed from " + island.getProtectionRange() + " to " plugin.log("Makeleader: Island protection range changed from " + island.getProtectionRange() + " to "
+ range + " for " + user.getName() + " due to permission."); + range + " for " + user.getName() + " due to permission.");
} }