Fixed some code smells

This commit is contained in:
Florian CUNY 2019-10-28 10:04:44 +01:00
parent a27f54a6f7
commit 5ef74bd0f4
5 changed files with 34 additions and 57 deletions

View File

@ -67,7 +67,7 @@ public class AdminRegisterCommand extends ConfirmableCommand {
return false; return false;
} }
// Check if island is spawn // Check if island is spawn
if (island.map(i -> i.isSpawn()).orElse(false)) { if (island.map(Island::isSpawn).orElse(false)) {
askConfirmation(user, user.getTranslation("commands.admin.register.island-is-spawn"), () -> register(user, targetUUID, island, closestIsland)); askConfirmation(user, user.getTranslation("commands.admin.register.island-is-spawn"), () -> register(user, targetUUID, island, closestIsland));
return false; return false;
} }

View File

@ -30,6 +30,12 @@ public class IslandTeamCommand extends CompositeCommand {
*/ */
private Map<UUID, Invite> inviteMap; private Map<UUID, Invite> inviteMap;
/**
* Contains the text variable for units.
* @since 1.9.0
*/
private final String UNIT = "[unit]";
private IslandTeamInviteCommand inviteCommand; private IslandTeamInviteCommand inviteCommand;
public IslandTeamCommand(CompositeCommand parent) { public IslandTeamCommand(CompositeCommand parent) {
@ -137,15 +143,15 @@ public class IslandTeamCommand extends CompositeCommand {
if (duration.toMinutes() < 60L) { if (duration.toMinutes() < 60L) {
lastSeen = user.getTranslation(reference, lastSeen = user.getTranslation(reference,
TextVariables.NUMBER, String.valueOf(duration.toMinutes()), TextVariables.NUMBER, String.valueOf(duration.toMinutes()),
"[unit]", user.getTranslation("commands.island.team.info.last-seen.minutes")); UNIT, user.getTranslation("commands.island.team.info.last-seen.minutes"));
} else if (duration.toHours() < 24L) { } else if (duration.toHours() < 24L) {
lastSeen = user.getTranslation(reference, lastSeen = user.getTranslation(reference,
TextVariables.NUMBER, String.valueOf(duration.toHours()), TextVariables.NUMBER, String.valueOf(duration.toHours()),
"[unit]", user.getTranslation("commands.island.team.info.last-seen.hours")); UNIT, user.getTranslation("commands.island.team.info.last-seen.hours"));
} else { } else {
lastSeen = user.getTranslation(reference, lastSeen = user.getTranslation(reference,
TextVariables.NUMBER, String.valueOf(duration.toDays()), TextVariables.NUMBER, String.valueOf(duration.toDays()),
"[unit]", user.getTranslation("commands.island.team.info.last-seen.days")); UNIT, user.getTranslation("commands.island.team.info.last-seen.days"));
} }
user.sendMessage("commands.island.team.info.member-layout.offline", user.sendMessage("commands.island.team.info.member-layout.offline",

View File

@ -111,35 +111,6 @@ public class IslandTeamTrustCommand extends CompositeCommand {
} }
} }
/*
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island != null) {
if (getPlugin().getSettings().isInviteConfirmation()) {
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.TRUST)) {
// Prevent spam
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
return false;
}
// Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite!
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId());
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
// Send message to online player
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
} else {
island.setRank(target, RanksManager.TRUSTED_RANK);
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
}
return true;
} else {
// Should not happen
user.sendMessage("general.errors.general");
return false;
}
}*/
@Override @Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) { public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
if (args.isEmpty()) { if (args.isEmpty()) {

View File

@ -159,8 +159,8 @@ public class BlueprintPaster {
// Tell the owner we're pasting blocks and how much time it might take // Tell the owner we're pasting blocks and how much time it might take
owner.ifPresent(user -> { owner.ifPresent(user -> {
// Estimated time: // Estimated time:
double total = blocks.size() + attached.size() + entities.size(); double total = (double) blocks.size() + attached.size() + entities.size();
BigDecimal time = new BigDecimal(total / (pasteSpeed * 20.0D)).setScale(1, RoundingMode.UP); BigDecimal time = BigDecimal.valueOf(total / (pasteSpeed * 20.0D)).setScale(1, RoundingMode.UP);
user.sendMessage("commands.island.create.pasting.estimated-time", TextVariables.NUMBER, String.valueOf(time.doubleValue())); user.sendMessage("commands.island.create.pasting.estimated-time", TextVariables.NUMBER, String.valueOf(time.doubleValue()));
// We're pasting blocks! // We're pasting blocks!
user.sendMessage("commands.island.create.pasting.blocks", TextVariables.NUMBER, String.valueOf(blocks.size() + attached.size())); user.sendMessage("commands.island.create.pasting.blocks", TextVariables.NUMBER, String.valueOf(blocks.size() + attached.size()));

View File

@ -299,28 +299,28 @@ public class IslandWorldManager {
* @return the endGenerate * @return the endGenerate
*/ */
public boolean isEndGenerate(@NonNull World world) { public boolean isEndGenerate(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isEndGenerate() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isEndGenerate();
} }
/** /**
* @return the endIslands * @return the endIslands
*/ */
public boolean isEndIslands(@NonNull World world) { public boolean isEndIslands(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isEndIslands() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isEndIslands();
} }
/** /**
* @return the netherGenerate * @return the netherGenerate
*/ */
public boolean isNetherGenerate(@NonNull World world) { public boolean isNetherGenerate(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isNetherGenerate() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherGenerate();
} }
/** /**
* @return the netherIslands * @return the netherIslands
*/ */
public boolean isNetherIslands(@NonNull World world) { public boolean isNetherIslands(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isNetherIslands() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherIslands();
} }
/** /**
@ -511,21 +511,21 @@ public class IslandWorldManager {
* @return the onJoinResetMoney * @return the onJoinResetMoney
*/ */
public boolean isOnJoinResetMoney(@NonNull World world) { public boolean isOnJoinResetMoney(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetMoney() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnJoinResetMoney();
} }
/** /**
* @return the onJoinResetInventory * @return the onJoinResetInventory
*/ */
public boolean isOnJoinResetInventory(@NonNull World world) { public boolean isOnJoinResetInventory(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetInventory() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnJoinResetInventory();
} }
/** /**
* @return the onJoinResetEnderChest * @return the onJoinResetEnderChest
*/ */
public boolean isOnJoinResetEnderChest(@NonNull World world) { public boolean isOnJoinResetEnderChest(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest();
} }
/** /**
@ -535,7 +535,7 @@ public class IslandWorldManager {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isOnJoinResetHealth(@NonNull World world) { public boolean isOnJoinResetHealth(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetHealth() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnJoinResetHealth();
} }
/** /**
@ -545,7 +545,7 @@ public class IslandWorldManager {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isOnJoinResetHunger(@NonNull World world) { public boolean isOnJoinResetHunger(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetHunger() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnJoinResetHunger();
} }
/** /**
@ -555,7 +555,7 @@ public class IslandWorldManager {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isOnJoinResetXP(@NonNull World world) { public boolean isOnJoinResetXP(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetXP() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnJoinResetXP();
} }
/** /**
@ -574,21 +574,21 @@ public class IslandWorldManager {
* @return the onLeaveResetMoney * @return the onLeaveResetMoney
*/ */
public boolean isOnLeaveResetMoney(@NonNull World world) { public boolean isOnLeaveResetMoney(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetMoney() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnLeaveResetMoney();
} }
/** /**
* @return the onLeaveResetInventory * @return the onLeaveResetInventory
*/ */
public boolean isOnLeaveResetInventory(@NonNull World world) { public boolean isOnLeaveResetInventory(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetInventory() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnLeaveResetInventory();
} }
/** /**
* @return the onLeaveResetEnderChest * @return the onLeaveResetEnderChest
*/ */
public boolean isOnLeaveResetEnderChest(@NonNull World world) { public boolean isOnLeaveResetEnderChest(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest();
} }
/** /**
@ -598,7 +598,7 @@ public class IslandWorldManager {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isOnLeaveResetHealth(@NonNull World world) { public boolean isOnLeaveResetHealth(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetHealth() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnLeaveResetHealth();
} }
/** /**
@ -608,7 +608,7 @@ public class IslandWorldManager {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isOnLeaveResetHunger(@NonNull World world) { public boolean isOnLeaveResetHunger(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetHunger() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnLeaveResetHunger();
} }
/** /**
@ -618,7 +618,7 @@ public class IslandWorldManager {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isOnLeaveResetXP(@NonNull World world) { public boolean isOnLeaveResetXP(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetXP() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isOnLeaveResetXP();
} }
/** /**
@ -684,7 +684,7 @@ public class IslandWorldManager {
} }
public boolean isUseOwnGenerator(@NonNull World world) { public boolean isUseOwnGenerator(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isUseOwnGenerator() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isUseOwnGenerator();
} }
/** /**
@ -709,7 +709,7 @@ public class IslandWorldManager {
* @return true if water is not safe, e.g.for home locations * @return true if water is not safe, e.g.for home locations
*/ */
public boolean isWaterNotSafe(@NonNull World world) { public boolean isWaterNotSafe(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isWaterUnsafe() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isWaterUnsafe();
} }
/** /**
@ -753,7 +753,7 @@ public class IslandWorldManager {
* @return true or false * @return true or false
*/ */
public boolean isTeamJoinDeathReset(@NonNull World world) { public boolean isTeamJoinDeathReset(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isTeamJoinDeathReset() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isTeamJoinDeathReset();
} }
/** /**
@ -764,7 +764,7 @@ public class IslandWorldManager {
* @since 1.6.0 * @since 1.6.0
*/ */
public boolean isDeathsResetOnNewIsland(@NonNull World world) { public boolean isDeathsResetOnNewIsland(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isDeathsResetOnNewIsland() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isDeathsResetOnNewIsland();
} }
/** /**
@ -789,14 +789,14 @@ public class IslandWorldManager {
* @return whether leavers should lose a reset or not * @return whether leavers should lose a reset or not
*/ */
public boolean isLeaversLoseReset(@NonNull World world) { public boolean isLeaversLoseReset(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isLeaversLoseReset() : false; return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isLeaversLoseReset();
} }
/** /**
* @return whether players keep their inventory if they are kicked. Overrides leave inventory clearing * @return whether players keep their inventory if they are kicked. Overrides leave inventory clearing
*/ */
public boolean isKickedKeepInventory(@NonNull World world) { public boolean isKickedKeepInventory(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isKickedKeepInventory() : true; return !gameModes.containsKey(world) || gameModes.get(world).getWorldSettings().isKickedKeepInventory();
} }
} }