Fixes some code smells.

This commit is contained in:
tastybento 2018-12-13 08:10:33 +09:00
parent f61b109060
commit ca844f1727
3 changed files with 8 additions and 9 deletions

View File

@ -12,6 +12,7 @@ import world.bentobox.bentobox.api.user.User;
*/
public class VaultHook extends Hook {
private static final String AMOUNT_MUST_BE_POSITIVE = "Amount must be positive.";
private Economy economy;
public VaultHook() {
@ -61,7 +62,7 @@ public class VaultHook extends Hook {
throw new IllegalArgumentException("User must be a Player or an OfflinePlayer");
}
if (amount < 0.0D) {
throw new IllegalArgumentException("Amount must be positive.");
throw new IllegalArgumentException(AMOUNT_MUST_BE_POSITIVE);
}
return economy.withdrawPlayer(user.getPlayer(), amount);
}
@ -77,7 +78,7 @@ public class VaultHook extends Hook {
throw new IllegalArgumentException("User must be a Player or an OfflinePlayer");
}
if (amount < 0.0D) {
throw new IllegalArgumentException("Amount must be positive.");
throw new IllegalArgumentException(AMOUNT_MUST_BE_POSITIVE);
}
return economy.depositPlayer(user.getPlayer(), amount);
}
@ -92,7 +93,7 @@ public class VaultHook extends Hook {
*/
public boolean has(User user, double amount) {
if (amount < 0.0D) {
throw new IllegalArgumentException("Amount must be positive.");
throw new IllegalArgumentException(AMOUNT_MUST_BE_POSITIVE);
}
return user.isPlayer() && economy.has(user.getPlayer(), amount);
}

View File

@ -88,9 +88,9 @@ public class JoinLeaveListener implements Listener {
plugin.getIWM().getOverWorlds().forEach(w -> {
Island island = plugin.getIslands().getIsland(w, User.getInstance(event.getPlayer()));
// Are there any online players still for this island?
if (island != null && !plugin.getServer().getOnlinePlayers().stream()
if (island != null && plugin.getServer().getOnlinePlayers().stream()
.filter(p -> !event.getPlayer().equals(p))
.anyMatch(p -> plugin.getIslands().getMembers(w, event.getPlayer().getUniqueId()).contains(p.getUniqueId()))) {
.noneMatch(p -> plugin.getIslands().getMembers(w, event.getPlayer().getUniqueId()).contains(p.getUniqueId()))) {
// No, there are no more players online on this island
// Tell players they are being removed
island.getMembers().entrySet().stream()

View File

@ -40,10 +40,8 @@ public class BreedingListener extends FlagListener {
if (e.getHand().equals(EquipmentSlot.OFF_HAND)) {
inHand = e.getPlayer().getInventory().getItemInOffHand();
}
if (inHand != null && BREEDING_ITEMS.contains(inHand.getType())) {
if (!checkIsland(e, e.getRightClicked().getLocation(), Flags.BREEDING)) {
((Animals)e.getRightClicked()).setBreed(false);
}
if (inHand != null && BREEDING_ITEMS.contains(inHand.getType()) && !checkIsland(e, e.getRightClicked().getLocation(), Flags.BREEDING)) {
((Animals)e.getRightClicked()).setBreed(false);
}
}
}