From acfc001cd62b3cb3c89ed75fdd93c7f9775d592d Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 31 Jul 2021 08:48:26 -0700 Subject: [PATCH] Java upgrade (#1814) * Version 1.17.3 * Use Map.of and List.of instead of Immutable collections * Replace explicit type argument. * Replace lamba with method reference * Replace condition with Objects.requireNonNullElseGet * Use String.repeat * Use new switch expressions * Use instanceof patten variables which are more compact * Fuse toUnmodifiableList into stream and return it. * Remove unnecessary toString() calls. * Remove unnecessary public * Extracted common part from if * Simplify conditional expressions * Remove unused IOExceptions * Cast to long * Use Map.putAll * Use primitives * Clarify what is null or not * Addedd @Serial annotation introduced with Java 14. * Use Optional.isEmpty instead of !isPresent * Use flatMap then ifPresent * Just use Arrays.stream * Swap map and filter for null with Objects::nonNull * Use expression lambda --- pom.xml | 2 +- .../api/addons/exceptions/AddonException.java | 3 + .../exceptions/AddonRequestException.java | 5 +- .../InvalidAddonDescriptionException.java | 3 + .../InvalidAddonFormatException.java | 2 + .../InvalidAddonInheritException.java | 3 + .../api/commands/CompositeCommand.java | 16 +- .../AdminSetProtectionCenterCommand.java | 2 +- .../commands/admin/AdminSettingsCommand.java | 24 +- .../commands/admin/AdminSwitchtoCommand.java | 2 +- .../admin/purge/AdminPurgeCommand.java | 2 +- .../admin/range/AdminRangeDisplayCommand.java | 26 +- .../api/commands/island/team/Invite.java | 3 +- .../team/IslandTeamInviteAcceptCommand.java | 12 +- .../island/team/IslandTeamInviteCommand.java | 12 +- .../bentobox/api/events/addon/AddonEvent.java | 32 +-- .../api/events/island/IslandEvent.java | 143 ++++------- .../bentobox/api/events/team/TeamEvent.java | 74 ++---- .../bentobox/bentobox/api/flags/Flag.java | 59 ++--- .../bentobox/api/metadata/MetaDataAble.java | 4 +- .../bentobox/api/metadata/MetaDataValue.java | 4 +- .../bentobox/bentobox/api/panels/Panel.java | 12 +- .../bentobox/api/panels/TabbedPanel.java | 2 +- .../bentobox/bentobox/api/user/Notifier.java | 2 +- .../bentobox/bentobox/api/user/User.java | 3 +- .../blueprints/BlueprintClipboard.java | 18 +- .../bentobox/blueprints/BlueprintPaster.java | 6 +- .../conversation/NameSuccessPrompt.java | 3 +- .../dataobjects/BlueprintEntity.java | 3 +- .../worldedit/BlueprintClipboardFormat.java | 4 +- .../worldedit/BlueprintClipboardReader.java | 5 +- .../worldedit/BlueprintClipboardWriter.java | 5 +- .../BlueprintSchematicConverter.java | 2 +- .../database/json/JSONDatabaseConnector.java | 4 +- .../json/adapters/FlagTypeAdapter.java | 2 +- .../mongodb/MongoDBDatabaseHandler.java | 3 +- .../bentobox/database/objects/Island.java | 2 +- .../database/objects/IslandDeletion.java | 3 +- .../objects/adapters/FlagSerializer.java | 3 +- .../objects/adapters/FlagSerializer2.java | 3 +- .../objects/adapters/FlagSerializer3.java | 3 +- .../database/yaml/YamlDatabaseConnector.java | 8 +- .../database/yaml/YamlDatabaseHandler.java | 2 +- .../bentobox/hooks/LangUtilsHook.java | 226 +++++++++--------- .../bentobox/listeners/JoinLeaveListener.java | 7 +- .../listeners/PlayerEntityPortalEvent.java | 2 +- .../PortalTeleportationListener.java | 16 +- .../protection/BlockInteractionListener.java | 6 +- .../flags/protection/BreakBlocksListener.java | 6 +- .../flags/protection/BreedingListener.java | 3 +- .../flags/protection/BucketListener.java | 27 ++- .../flags/protection/ElytraListener.java | 3 +- .../flags/protection/HurtingListener.java | 6 +- .../flags/protection/InventoryListener.java | 3 +- .../PhysicalInteractionListener.java | 24 +- .../flags/protection/TNTListener.java | 9 +- .../listeners/flags/settings/PVPListener.java | 16 +- .../flags/worldsettings/CreeperListener.java | 3 +- .../worldsettings/GeoLimitMobsListener.java | 3 +- .../InvincibleVisitorsListener.java | 3 +- .../LiquidsFlowingOutListener.java | 2 +- .../NaturalSpawningOutsideRangeListener.java | 2 +- .../worldsettings/PetTeleportListener.java | 3 +- .../TreesGrowingOutsideRangeListener.java | 8 +- .../bentobox/managers/AddonsManager.java | 11 +- .../bentobox/managers/IslandsManager.java | 43 +--- .../DefaultNewIslandLocationStrategy.java | 2 +- .../bentobox/managers/island/IslandCache.java | 12 +- .../bentobox/bentobox/nms/NMSAbstraction.java | 2 +- .../panels/BlueprintManagementPanel.java | 15 +- .../bentobox/panels/LanguagePanel.java | 8 +- .../bentobox/panels/ManagementPanel.java | 169 ++++++------- .../bentobox/panels/settings/SettingsTab.java | 16 +- .../world/bentobox/bentobox/util/Pair.java | 3 +- .../world/bentobox/bentobox/util/Util.java | 49 ++-- 75 files changed, 498 insertions(+), 741 deletions(-) diff --git a/pom.xml b/pom.xml index db6efb907..7fb8f18e6 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ -LOCAL - 1.17.2 + 1.17.3 diff --git a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonException.java b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonException.java index 543e20bd7..36e7a1961 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonException.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonException.java @@ -1,10 +1,13 @@ package world.bentobox.bentobox.api.addons.exceptions; +import java.io.Serial; + public abstract class AddonException extends Exception { /** * */ + @Serial private static final long serialVersionUID = 4203162022348693854L; protected AddonException(String errorMessage){ diff --git a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonRequestException.java b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonRequestException.java index 29ec3f051..bba12bf74 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonRequestException.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/AddonRequestException.java @@ -1,8 +1,11 @@ package world.bentobox.bentobox.api.addons.exceptions; +import java.io.Serial; + public class AddonRequestException extends AddonException { - private static final long serialVersionUID = -5698456013070166174L; + @Serial + private static final long serialVersionUID = -5698456013070166174L; public AddonRequestException(String errorMessage) { super(errorMessage); diff --git a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonDescriptionException.java b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonDescriptionException.java index b6f3fae62..3af6e932d 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonDescriptionException.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonDescriptionException.java @@ -1,5 +1,7 @@ package world.bentobox.bentobox.api.addons.exceptions; +import java.io.Serial; + /** * @since 1.11.0 */ @@ -8,6 +10,7 @@ public class InvalidAddonDescriptionException extends AddonException { /** * */ + @Serial private static final long serialVersionUID = 7741502900847049986L; public InvalidAddonDescriptionException(String errorMessage) { diff --git a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonFormatException.java b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonFormatException.java index dc228a1a5..d5d61d965 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonFormatException.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonFormatException.java @@ -1,5 +1,6 @@ package world.bentobox.bentobox.api.addons.exceptions; +import java.io.Serial; import java.util.logging.Level; import org.bukkit.Bukkit; @@ -9,6 +10,7 @@ public class InvalidAddonFormatException extends AddonException { /** * */ + @Serial private static final long serialVersionUID = 7741502900847049986L; public InvalidAddonFormatException(String errorMessage) { diff --git a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonInheritException.java b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonInheritException.java index dec1db6db..7a367207a 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonInheritException.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/exceptions/InvalidAddonInheritException.java @@ -1,10 +1,13 @@ package world.bentobox.bentobox.api.addons.exceptions; +import java.io.Serial; + public class InvalidAddonInheritException extends AddonException { /** * */ + @Serial private static final long serialVersionUID = -5847358994397613244L; public InvalidAddonInheritException(String errorMessage) { diff --git a/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java index 2a88cd0b4..c582e39a4 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java @@ -144,7 +144,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi // Run setup setup(); - if (!getSubCommand("help").isPresent() && !label.equals("help")) { + if (getSubCommand("help").isEmpty() && !label.equals("help")) { new DefaultHelpCommand(this); } } @@ -204,11 +204,11 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi p = p.getParent(); index++; } - setDescription(COMMANDS + reference.toString() + ".description"); - setParametersHelp(COMMANDS + reference.toString() + ".parameters"); + setDescription(COMMANDS + reference + ".description"); + setParametersHelp(COMMANDS + reference + ".parameters"); setup(); // If this command does not define its own help class, then use the default help command - if (!getSubCommand("help").isPresent() && !label.equals("help")) { + if (getSubCommand("help").isEmpty() && !label.equals("help")) { new DefaultHelpCommand(this); } } @@ -278,7 +278,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi // get the subcommand corresponding to the arg if (subCommand.hasSubCommands()) { Optional sub = subCommand.getSubCommand(arg); - if (!sub.isPresent()) { + if (sub.isEmpty()) { return subCommand; } // Step down one @@ -602,7 +602,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi return options; } // Add any tab completion from the subcommand - options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(() -> new ArrayList<>())); + options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new)); if (command.hasSubCommands()) { options.addAll(getSubCommandLabels(sender, command)); } @@ -701,7 +701,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi * @since 1.5.0 */ public void setCooldown(String uniqueId, String targetUUID, int timeInSeconds) { - cooldowns.computeIfAbsent(uniqueId, k -> new HashMap<>()).put(targetUUID, System.currentTimeMillis() + timeInSeconds * 1000); + cooldowns.computeIfAbsent(uniqueId, k -> new HashMap<>()).put(targetUUID, System.currentTimeMillis() + timeInSeconds * 1000L); } /** @@ -711,7 +711,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi * @param timeInSeconds - time in seconds to cool down */ public void setCooldown(UUID uniqueId, UUID targetUUID, int timeInSeconds) { - cooldowns.computeIfAbsent(uniqueId.toString(), k -> new HashMap<>()).put(targetUUID == null ? null : targetUUID.toString(), System.currentTimeMillis() + timeInSeconds * 1000); + cooldowns.computeIfAbsent(uniqueId.toString(), k -> new HashMap<>()).put(targetUUID == null ? null : targetUUID.toString(), System.currentTimeMillis() + timeInSeconds * 1000L); } /** diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSetProtectionCenterCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSetProtectionCenterCommand.java index 8f7766058..77de3e13e 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSetProtectionCenterCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSetProtectionCenterCommand.java @@ -59,7 +59,7 @@ public class AdminSetProtectionCenterCommand extends ConfirmableCommand return false; } Optional optionalIsland = getIslands().getIslandAt(targetLoc); - if (!optionalIsland.isPresent()) { + if (optionalIsland.isEmpty()) { user.sendMessage("commands.admin.setspawnpoint.no-island-here"); return false; } diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java index f06126b25..d69454e96 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSettingsCommand.java @@ -39,7 +39,7 @@ public class AdminSettingsCommand extends CompositeCommand { private Island island; private final List SETTING_FLAG_NAMES; private List WORLD_SETTING_FLAG_NAMES; - private @NonNull Optional flag; + private @NonNull Optional flag = Optional.empty(); private boolean activeState; private int rank; @@ -258,20 +258,14 @@ public class AdminSettingsCommand extends CompositeCommand { } } else if (args.size() == 4) { // Get flag in previous argument - options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> { - switch (f.getType()) { - case PROTECTION: - return getPlugin().getRanksManager() - .getRanks().entrySet().stream() - .filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK) - .map(Entry::getKey) - .map(user::getTranslation).collect(Collectors.toList()); - case SETTING: - return Arrays.asList(active, disabled); - default: - return Collections.emptyList(); - - } + options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> switch (f.getType()) { + case PROTECTION -> getPlugin().getRanksManager() + .getRanks().entrySet().stream() + .filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK) + .map(Entry::getKey) + .map(user::getTranslation).collect(Collectors.toList()); + case SETTING -> Arrays.asList(active, disabled); + default -> Collections.emptyList(); }).orElse(Collections.emptyList()); } return Optional.of(Util.tabLimit(options, lastArg)); diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchtoCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchtoCommand.java index 5978050e0..3bb91c4c4 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchtoCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/AdminSwitchtoCommand.java @@ -63,7 +63,7 @@ public class AdminSwitchtoCommand extends ConfirmableCommand { public boolean execute(User user, String label, List args) { if (NumberUtils.isDigits(args.get(1))) { try { - Integer n = Integer.valueOf(args.get(1)); + int n = Integer.parseInt(args.get(1)); if (n < 1 || n > islands.size()) { user.sendMessage("commands.admin.switchto.out-of-range", TextVariables.NUMBER, String.valueOf(islands.size()), TextVariables.LABEL, getTopLabel()); return false; diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java index b7b916077..a4218ac9d 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/purge/AdminPurgeCommand.java @@ -70,7 +70,7 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener { islands.clear(); this.user = user; try { - Integer days = Integer.parseInt(args.get(0)); + int days = Integer.parseInt(args.get(0)); if (days < 1) { user.sendMessage("commands.admin.purge.days-one-or-more"); return false; diff --git a/src/main/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommand.java index 05392b038..f8f877888 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/admin/range/AdminRangeDisplayCommand.java @@ -46,29 +46,15 @@ public class AdminRangeDisplayCommand extends CompositeCommand { if (!displayRanges.containsKey(user)) { switch (label) { - case DISPLAY: - case SHOW: - showZones(user); - break; - case HIDE: - user.sendMessage("commands.admin.range.display.already-off"); - break; - default: - showHelp(this, user); - break; + case DISPLAY, SHOW -> showZones(user); + case HIDE -> user.sendMessage("commands.admin.range.display.already-off"); + default -> showHelp(this, user); } } else { switch (label) { - case DISPLAY: - case HIDE: - hideZones(user); - break; - case SHOW: - user.sendMessage("commands.admin.range.display.already-on"); - break; - default: - showHelp(this, user); - break; + case DISPLAY, HIDE -> hideZones(user); + case SHOW -> user.sendMessage("commands.admin.range.display.already-on"); + default -> showHelp(this, user); } } diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/Invite.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/Invite.java index 658d0be53..aec829c17 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/Invite.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/Invite.java @@ -75,10 +75,9 @@ public class Invite { if (obj == null) { return false; } - if (!(obj instanceof Invite)) { + if (!(obj instanceof Invite other)) { return false; } - Invite other = (Invite) obj; return Objects.equals(invitee, other.invitee) && Objects.equals(inviter, other.inviter) && type == other.type; } } diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java index 2987453d4..9bf79cdaf 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java @@ -82,14 +82,10 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand { // Get the invite Invite invite = itc.getInvite(playerUUID); switch (invite.getType()) { - case COOP: - askConfirmation(user, () -> acceptCoopInvite(user, invite)); - break; - case TRUST: - askConfirmation(user, () -> acceptTrustInvite(user, invite)); - break; - default: - askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), () -> acceptTeamInvite(user, invite)); + case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite)); + case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite)); + default -> askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), + () -> acceptTeamInvite(user, invite)); } return true; } diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java index 2de24d487..cbed7e3d9 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java @@ -51,15 +51,9 @@ public class IslandTeamInviteCommand extends CompositeCommand { Invite invite = itc.getInvite(playerUUID); String name = getPlayers().getName(playerUUID); switch (invite.getType()) { - case COOP: - user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name); - break; - case TRUST: - user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name); - break; - default: - user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name); - break; + case COOP -> user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name); + case TRUST -> user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name); + default -> user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name); } return true; } diff --git a/src/main/java/world/bentobox/bentobox/api/events/addon/AddonEvent.java b/src/main/java/world/bentobox/bentobox/api/events/addon/AddonEvent.java index 76c8dfaec..78d1cd277 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/addon/AddonEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/addon/AddonEvent.java @@ -100,29 +100,21 @@ public class AddonEvent { } private AddonBaseEvent getDeprecatedEvent() { - switch (reason) { - case ENABLE: - return new AddonEnableEvent(addon, keyValues); - case DISABLE: - return new AddonDisableEvent(addon, keyValues); - case LOAD: - return new AddonLoadEvent(addon, keyValues); - default: - return new AddonGeneralEvent(addon, keyValues); - } + return switch (reason) { + case ENABLE -> new AddonEnableEvent(addon, keyValues); + case DISABLE -> new AddonDisableEvent(addon, keyValues); + case LOAD -> new AddonLoadEvent(addon, keyValues); + default -> new AddonGeneralEvent(addon, keyValues); + }; } private AddonBaseEvent getEvent() { - switch (reason) { - case ENABLE: - return new world.bentobox.bentobox.api.events.addon.AddonEnableEvent(addon, keyValues); - case DISABLE: - return new world.bentobox.bentobox.api.events.addon.AddonDisableEvent(addon, keyValues); - case LOAD: - return new world.bentobox.bentobox.api.events.addon.AddonLoadEvent(addon, keyValues); - default: - return new world.bentobox.bentobox.api.events.addon.AddonGeneralEvent(addon, keyValues); - } + return switch (reason) { + case ENABLE -> new world.bentobox.bentobox.api.events.addon.AddonEnableEvent(addon, keyValues); + case DISABLE -> new world.bentobox.bentobox.api.events.addon.AddonDisableEvent(addon, keyValues); + case LOAD -> new world.bentobox.bentobox.api.events.addon.AddonLoadEvent(addon, keyValues); + default -> new world.bentobox.bentobox.api.events.addon.AddonGeneralEvent(addon, keyValues); + }; } /** diff --git a/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java b/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java index b957b127f..14aad63ff 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/island/IslandEvent.java @@ -801,103 +801,58 @@ public class IslandEvent extends IslandBaseEvent { * @return deprecated event */ private IslandBaseEvent getDeprecatedEvent() { - switch (reason) { - case EXPEL: - return new IslandExpelEvent(island, player, admin, location); - case BAN: - return new IslandBanEvent(island, player, admin, location); - case PRECREATE: - return new IslandPreCreateEvent(player); - case CREATE: - return new IslandCreateEvent(island, player, admin, location, blueprintBundle); - case CREATED: - return new IslandCreatedEvent(island, player, admin, location); - case DELETE: - return new IslandDeleteEvent(island, player, admin, location); - case DELETE_CHUNKS: - return new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo); - case DELETED: - return new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo); - case ENTER: - return new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent); - case EXIT: - return new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent); - case LOCK: - return new IslandLockEvent(island, player, admin, location); - case RESET: - return new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland); - case RESETTED: - return new IslandResettedEvent(island, player, admin, location, oldIsland); - case UNBAN: - return new IslandUnbanEvent(island, player, admin, location); - case UNLOCK: - return new IslandUnlockEvent(island, player, admin, location); - case REGISTERED: - return new IslandRegisteredEvent(island, player, admin, location); - case UNREGISTERED: - return new IslandUnregisteredEvent(island, player, admin, location); - case RANGE_CHANGE: - return new IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange); - case PRECLEAR: - return new IslandPreclearEvent(island, player, admin, location, oldIsland); - case RESERVED: - return new IslandReservedEvent(island, player, admin, location); - case RANK_CHANGE: - return new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank); - default: - return new IslandGeneralEvent(island, player, admin, location); - } + return switch (reason) { + case EXPEL -> new IslandExpelEvent(island, player, admin, location); + case BAN -> new IslandBanEvent(island, player, admin, location); + case PRECREATE -> new IslandPreCreateEvent(player); + case CREATE -> new IslandCreateEvent(island, player, admin, location, blueprintBundle); + case CREATED -> new IslandCreatedEvent(island, player, admin, location); + case DELETE -> new IslandDeleteEvent(island, player, admin, location); + case DELETE_CHUNKS -> new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo); + case DELETED -> new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo); + case ENTER -> new IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent); + case EXIT -> new IslandExitEvent(island, player, admin, location, oldIsland, rawEvent); + case LOCK -> new IslandLockEvent(island, player, admin, location); + case RESET -> new IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland); + case RESETTED -> new IslandResettedEvent(island, player, admin, location, oldIsland); + case UNBAN -> new IslandUnbanEvent(island, player, admin, location); + case UNLOCK -> new IslandUnlockEvent(island, player, admin, location); + case REGISTERED -> new IslandRegisteredEvent(island, player, admin, location); + case UNREGISTERED -> new IslandUnregisteredEvent(island, player, admin, location); + case RANGE_CHANGE -> new IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange); + case PRECLEAR -> new IslandPreclearEvent(island, player, admin, location, oldIsland); + case RESERVED -> new IslandReservedEvent(island, player, admin, location); + case RANK_CHANGE -> new IslandRankChangeEvent(island, player, admin, location, oldRank, newRank); + default -> new IslandGeneralEvent(island, player, admin, location); + }; } private IslandBaseEvent getEvent() { - switch (reason) { - case EXPEL: - return new world.bentobox.bentobox.api.events.island.IslandExpelEvent(island, player, admin, location); - case BAN: - return new world.bentobox.bentobox.api.events.island.IslandBanEvent(island, player, admin, location); - case PRECREATE: - return new world.bentobox.bentobox.api.events.island.IslandPreCreateEvent(player); - case CREATE: - return new world.bentobox.bentobox.api.events.island.IslandCreateEvent(island, player, admin, location, blueprintBundle); - case CREATED: - return new world.bentobox.bentobox.api.events.island.IslandCreatedEvent(island, player, admin, location); - case DELETE: - return new world.bentobox.bentobox.api.events.island.IslandDeleteEvent(island, player, admin, location); - case DELETE_CHUNKS: - return new world.bentobox.bentobox.api.events.island.IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo); - case DELETED: - return new world.bentobox.bentobox.api.events.island.IslandDeletedEvent(island, player, admin, location, deletedIslandInfo); - case ENTER: - return new world.bentobox.bentobox.api.events.island.IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent); - case EXIT: - return new world.bentobox.bentobox.api.events.island.IslandExitEvent(island, player, admin, location, oldIsland, rawEvent); - case LOCK: - return new world.bentobox.bentobox.api.events.island.IslandLockEvent(island, player, admin, location); - case RESET: - return new world.bentobox.bentobox.api.events.island.IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland); - case RESETTED: - return new world.bentobox.bentobox.api.events.island.IslandResettedEvent(island, player, admin, location, oldIsland); - case UNBAN: - return new world.bentobox.bentobox.api.events.island.IslandUnbanEvent(island, player, admin, location); - case UNLOCK: - return new world.bentobox.bentobox.api.events.island.IslandUnlockEvent(island, player, admin, location); - case REGISTERED: - return new world.bentobox.bentobox.api.events.island.IslandRegisteredEvent(island, player, admin, location); - case UNREGISTERED: - return new world.bentobox.bentobox.api.events.island.IslandUnregisteredEvent(island, player, admin, location); - case RANGE_CHANGE: - return new world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange); - case PRECLEAR: - return new world.bentobox.bentobox.api.events.island.IslandPreclearEvent(island, player, admin, location, oldIsland); - case RESERVED: - return new world.bentobox.bentobox.api.events.island.IslandReservedEvent(island, player, admin, location); - case RANK_CHANGE: - return new world.bentobox.bentobox.api.events.island.IslandRankChangeEvent(island, player, admin, location, oldRank, newRank); - case NEW_ISLAND: - return new IslandNewIslandEvent(island, player, admin, location); - default: - return new world.bentobox.bentobox.api.events.island.IslandGeneralEvent(island, player, admin, location); - } + return switch (reason) { + case EXPEL -> new world.bentobox.bentobox.api.events.island.IslandExpelEvent(island, player, admin, location); + case BAN -> new world.bentobox.bentobox.api.events.island.IslandBanEvent(island, player, admin, location); + case PRECREATE -> new world.bentobox.bentobox.api.events.island.IslandPreCreateEvent(player); + case CREATE -> new world.bentobox.bentobox.api.events.island.IslandCreateEvent(island, player, admin, location, blueprintBundle); + case CREATED -> new world.bentobox.bentobox.api.events.island.IslandCreatedEvent(island, player, admin, location); + case DELETE -> new world.bentobox.bentobox.api.events.island.IslandDeleteEvent(island, player, admin, location); + case DELETE_CHUNKS -> new world.bentobox.bentobox.api.events.island.IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo); + case DELETED -> new world.bentobox.bentobox.api.events.island.IslandDeletedEvent(island, player, admin, location, deletedIslandInfo); + case ENTER -> new world.bentobox.bentobox.api.events.island.IslandEnterEvent(island, player, admin, location, oldIsland, rawEvent); + case EXIT -> new world.bentobox.bentobox.api.events.island.IslandExitEvent(island, player, admin, location, oldIsland, rawEvent); + case LOCK -> new world.bentobox.bentobox.api.events.island.IslandLockEvent(island, player, admin, location); + case RESET -> new world.bentobox.bentobox.api.events.island.IslandResetEvent(island, player, admin, location, blueprintBundle, oldIsland); + case RESETTED -> new world.bentobox.bentobox.api.events.island.IslandResettedEvent(island, player, admin, location, oldIsland); + case UNBAN -> new world.bentobox.bentobox.api.events.island.IslandUnbanEvent(island, player, admin, location); + case UNLOCK -> new world.bentobox.bentobox.api.events.island.IslandUnlockEvent(island, player, admin, location); + case REGISTERED -> new world.bentobox.bentobox.api.events.island.IslandRegisteredEvent(island, player, admin, location); + case UNREGISTERED -> new world.bentobox.bentobox.api.events.island.IslandUnregisteredEvent(island, player, admin, location); + case RANGE_CHANGE -> new world.bentobox.bentobox.api.events.island.IslandProtectionRangeChangeEvent(island, player, admin, location, newRange, oldRange); + case PRECLEAR -> new world.bentobox.bentobox.api.events.island.IslandPreclearEvent(island, player, admin, location, oldIsland); + case RESERVED -> new world.bentobox.bentobox.api.events.island.IslandReservedEvent(island, player, admin, location); + case RANK_CHANGE -> new world.bentobox.bentobox.api.events.island.IslandRankChangeEvent(island, player, admin, location, oldRank, newRank); + case NEW_ISLAND -> new IslandNewIslandEvent(island, player, admin, location); + default -> new world.bentobox.bentobox.api.events.island.IslandGeneralEvent(island, player, admin, location); + }; } /** diff --git a/src/main/java/world/bentobox/bentobox/api/events/team/TeamEvent.java b/src/main/java/world/bentobox/bentobox/api/events/team/TeamEvent.java index 19303c307..94791ef72 100644 --- a/src/main/java/world/bentobox/bentobox/api/events/team/TeamEvent.java +++ b/src/main/java/world/bentobox/bentobox/api/events/team/TeamEvent.java @@ -237,57 +237,35 @@ public class TeamEvent { } private IslandBaseEvent getDeprecatedEvent() { - switch (reason) { - case JOIN: - return new TeamJoinEvent(island, player, admin, location); - case JOINED: - return new TeamJoinedEvent(island, player, admin, location); - case INVITE: - return new TeamInviteEvent(island, player, admin, location); - case LEAVE: - return new TeamLeaveEvent(island, player, admin, location); - case REJECT: - return new TeamRejectEvent(island, player, admin, location); - case KICK: - return new TeamKickEvent(island, player, admin, location); - case SETOWNER: - return new TeamSetownerEvent(island, player, admin, location); - case INFO: - return new TeamInfoEvent(island, player, admin, location); - case DELETE: - return new TeamDeleteEvent(island, player, admin, location); - case UNINVITE: - return new TeamUninviteEvent(island, player, admin, location); - default: - return new TeamGeneralEvent(island, player, admin, location); - } + return switch (reason) { + case JOIN -> new TeamJoinEvent(island, player, admin, location); + case JOINED -> new TeamJoinedEvent(island, player, admin, location); + case INVITE -> new TeamInviteEvent(island, player, admin, location); + case LEAVE -> new TeamLeaveEvent(island, player, admin, location); + case REJECT -> new TeamRejectEvent(island, player, admin, location); + case KICK -> new TeamKickEvent(island, player, admin, location); + case SETOWNER -> new TeamSetownerEvent(island, player, admin, location); + case INFO -> new TeamInfoEvent(island, player, admin, location); + case DELETE -> new TeamDeleteEvent(island, player, admin, location); + case UNINVITE -> new TeamUninviteEvent(island, player, admin, location); + default -> new TeamGeneralEvent(island, player, admin, location); + }; } private IslandBaseEvent getEvent() { - switch (reason) { - case JOIN: - return new world.bentobox.bentobox.api.events.team.TeamJoinEvent(island, player, admin, location); - case JOINED: - return new world.bentobox.bentobox.api.events.team.TeamJoinedEvent(island, player, admin, location); - case INVITE: - return new world.bentobox.bentobox.api.events.team.TeamInviteEvent(island, player, admin, location); - case LEAVE: - return new world.bentobox.bentobox.api.events.team.TeamLeaveEvent(island, player, admin, location); - case REJECT: - return new world.bentobox.bentobox.api.events.team.TeamRejectEvent(island, player, admin, location); - case KICK: - return new world.bentobox.bentobox.api.events.team.TeamKickEvent(island, player, admin, location); - case SETOWNER: - return new world.bentobox.bentobox.api.events.team.TeamSetownerEvent(island, player, admin, location); - case INFO: - return new world.bentobox.bentobox.api.events.team.TeamInfoEvent(island, player, admin, location); - case DELETE: - return new world.bentobox.bentobox.api.events.team.TeamDeleteEvent(island, player, admin, location); - case UNINVITE: - return new world.bentobox.bentobox.api.events.team.TeamUninviteEvent(island, player, admin, location); - default: - return new world.bentobox.bentobox.api.events.team.TeamGeneralEvent(island, player, admin, location); - } + return switch (reason) { + case JOIN -> new world.bentobox.bentobox.api.events.team.TeamJoinEvent(island, player, admin, location); + case JOINED -> new world.bentobox.bentobox.api.events.team.TeamJoinedEvent(island, player, admin, location); + case INVITE -> new world.bentobox.bentobox.api.events.team.TeamInviteEvent(island, player, admin, location); + case LEAVE -> new world.bentobox.bentobox.api.events.team.TeamLeaveEvent(island, player, admin, location); + case REJECT -> new world.bentobox.bentobox.api.events.team.TeamRejectEvent(island, player, admin, location); + case KICK -> new world.bentobox.bentobox.api.events.team.TeamKickEvent(island, player, admin, location); + case SETOWNER -> new world.bentobox.bentobox.api.events.team.TeamSetownerEvent(island, player, admin, location); + case INFO -> new world.bentobox.bentobox.api.events.team.TeamInfoEvent(island, player, admin, location); + case DELETE -> new world.bentobox.bentobox.api.events.team.TeamDeleteEvent(island, player, admin, location); + case UNINVITE -> new world.bentobox.bentobox.api.events.team.TeamUninviteEvent(island, player, admin, location); + default -> new world.bentobox.bentobox.api.events.team.TeamGeneralEvent(island, player, admin, location); + }; } /** diff --git a/src/main/java/world/bentobox/bentobox/api/flags/Flag.java b/src/main/java/world/bentobox/bentobox/api/flags/Flag.java index 754cdf325..adef79149 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/Flag.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/Flag.java @@ -91,14 +91,11 @@ public class Flag implements Comparable { * @return next ranking mode */ public Mode getNext() { - switch(this) { - case ADVANCED: - return EXPERT; - case BASIC: - return ADVANCED; - default: - return BASIC; - } + return switch (this) { + case ADVANCED -> EXPERT; + case BASIC -> ADVANCED; + default -> BASIC; + }; } /** @@ -107,14 +104,11 @@ public class Flag implements Comparable { * @return true if ranked greater */ public boolean isGreaterThan(Mode rank) { - switch(this) { - case EXPERT: - return rank.equals(BASIC) || rank.equals(ADVANCED); - case ADVANCED: - return rank.equals(BASIC); - default: - return false; - } + return switch (this) { + case EXPERT -> rank.equals(BASIC) || rank.equals(ADVANCED); + case ADVANCED -> rank.equals(BASIC); + default -> false; + }; } } @@ -300,10 +294,9 @@ public class Flag implements Comparable { if (obj == null) { return false; } - if (!(obj instanceof Flag)) { + if (!(obj instanceof Flag other)) { return false; } - Flag other = (Flag) obj; if (id == null) { if (other.id != null) { return false; @@ -392,16 +385,12 @@ public class Flag implements Comparable { pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()))); return pib.build(); } - switch(getType()) { - case PROTECTION: - return createProtectionFlag(plugin, user, island, pib).build(); - case SETTING: - return createSettingFlag(user, island, pib).build(); - case WORLD_SETTING: - return createWorldSettingFlag(user, pib).build(); - default: - return pib.build(); - } + return switch (getType()) { + case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build(); + case SETTING -> createSettingFlag(user, island, pib).build(); + case WORLD_SETTING -> createWorldSettingFlag(user, pib).build(); + default -> pib.build(); + }; } private PanelItemBuilder createWorldSettingFlag(User user, PanelItemBuilder pib) { @@ -653,17 +642,9 @@ public class Flag implements Comparable { // If no clickHandler has been set, then apply default ones if (clickHandler == null) { switch (type) { - case SETTING: - clickHandler = new IslandToggleClick(id); - break; - case WORLD_SETTING: - clickHandler = new WorldToggleClick(id); - break; - case PROTECTION: - // Default option - default: - clickHandler = new CycleClick(id); - break; + case SETTING -> clickHandler = new IslandToggleClick(id); + case WORLD_SETTING -> clickHandler = new WorldToggleClick(id); + default -> clickHandler = new CycleClick(id); } } diff --git a/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataAble.java b/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataAble.java index 6e706505b..5233d0d23 100644 --- a/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataAble.java +++ b/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataAble.java @@ -13,13 +13,13 @@ public interface MetaDataAble { /** * @return the metaData */ - public Optional> getMetaData(); + Optional> getMetaData(); /** * @param metaData the metaData to set * @since 1.15.4 */ - public void setMetaData(Map metaData); + void setMetaData(Map metaData); /** * Get meta data by key diff --git a/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataValue.java b/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataValue.java index 4ae5c6d14..ea6d7c0a9 100644 --- a/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataValue.java +++ b/src/main/java/world/bentobox/bentobox/api/metadata/MetaDataValue.java @@ -29,7 +29,7 @@ public class MetaDataValue { @Expose private Boolean booleanValue; @Expose - private @NonNull String stringValue; + private String stringValue; /** * Initialize this meta data value @@ -85,6 +85,6 @@ public class MetaDataValue { @NonNull public String asString() { - return stringValue; + return stringValue == null ? "" : stringValue; } } diff --git a/src/main/java/world/bentobox/bentobox/api/panels/Panel.java b/src/main/java/world/bentobox/bentobox/api/panels/Panel.java index 39d330465..9691371ad 100644 --- a/src/main/java/world/bentobox/bentobox/api/panels/Panel.java +++ b/src/main/java/world/bentobox/bentobox/api/panels/Panel.java @@ -80,15 +80,9 @@ public class Panel implements HeadRequester, InventoryHolder { // Create panel switch (type) { - case INVENTORY: - inventory = Bukkit.createInventory(null, fixSize(size), name); - break; - case HOPPER: - inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name); - break; - case DROPPER: - inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name); - break; + case INVENTORY -> inventory = Bukkit.createInventory(null, fixSize(size), name); + case HOPPER -> inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name); + case DROPPER -> inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name); } // Fill the inventory and return diff --git a/src/main/java/world/bentobox/bentobox/api/panels/TabbedPanel.java b/src/main/java/world/bentobox/bentobox/api/panels/TabbedPanel.java index d9527a0f7..bb55c9135 100644 --- a/src/main/java/world/bentobox/bentobox/api/panels/TabbedPanel.java +++ b/src/main/java/world/bentobox/bentobox/api/panels/TabbedPanel.java @@ -146,7 +146,7 @@ public class TabbedPanel extends Panel implements PanelListener { } } // Add any subsidiary icons - tab.getTabIcons().forEach(items::put); + items.putAll(tab.getTabIcons()); } private void setupFooter(TreeMap items) { diff --git a/src/main/java/world/bentobox/bentobox/api/user/Notifier.java b/src/main/java/world/bentobox/bentobox/api/user/Notifier.java index c6027af03..7fc77f9dc 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/Notifier.java +++ b/src/main/java/world/bentobox/bentobox/api/user/Notifier.java @@ -22,7 +22,7 @@ public class Notifier { .expireAfterAccess(NOTIFICATION_DELAY, TimeUnit.SECONDS) .maximumSize(500) .build( - new CacheLoader() { + new CacheLoader<>() { @Override public Notification load(User user) { return new Notification(null, 0); diff --git a/src/main/java/world/bentobox/bentobox/api/user/User.java b/src/main/java/world/bentobox/bentobox/api/user/User.java index 9fa33b437..20f249c86 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -618,10 +618,9 @@ public class User implements MetaDataAble { if (obj == null) { return false; } - if (!(obj instanceof User)) { + if (!(obj instanceof User other)) { return false; } - User other = (User) obj; if (playerUUID == null) { return other.playerUUID == null; } else return playerUUID.equals(other.playerUUID); diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java index f02173dd5..6b7d5f888 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java @@ -198,8 +198,7 @@ public class BlueprintClipboard { if (entity instanceof Villager) { setVillager(entity, bpe); } - if (entity instanceof Colorable) { - Colorable c = (Colorable)entity; + if (entity instanceof Colorable c) { if (c.getColor() != null) { bpe.setColor(c.getColor()); } @@ -214,8 +213,7 @@ public class BlueprintClipboard { if (entity instanceof Ageable && !((Ageable)entity).isAdult()) { bpe.setAdult(false); } - if (entity instanceof AbstractHorse) { - AbstractHorse horse = (AbstractHorse)entity; + if (entity instanceof AbstractHorse horse) { bpe.setDomestication(horse.getDomestication()); bpe.setInventory(new HashMap<>()); for (int i = 0; i < horse.getInventory().getSize(); i++) { @@ -226,8 +224,7 @@ public class BlueprintClipboard { } } - if (entity instanceof Horse) { - Horse horse = (Horse)entity; + if (entity instanceof Horse horse) { bpe.setStyle(horse.getStyle()); } bpEnts.add(bpe); @@ -248,8 +245,7 @@ public class BlueprintClipboard { // Biome b.setBiome(block.getBiome()); // Signs - if (blockState instanceof Sign) { - Sign sign = (Sign)blockState; + if (blockState instanceof Sign sign) { b.setSignLines(Arrays.asList(sign.getLines())); } // Set block data @@ -272,9 +268,8 @@ public class BlueprintClipboard { } // Chests - if (blockState instanceof InventoryHolder) { + if (blockState instanceof InventoryHolder ih) { b.setInventory(new HashMap<>()); - InventoryHolder ih = (InventoryHolder)blockState; for (int i = 0; i < ih.getInventory().getSize(); i++) { ItemStack item = ih.getInventory().getItem(i); if (item != null) { @@ -283,8 +278,7 @@ public class BlueprintClipboard { } } - if (blockState instanceof CreatureSpawner) { - CreatureSpawner spawner = (CreatureSpawner)blockState; + if (blockState instanceof CreatureSpawner spawner) { BlueprintCreatureSpawner cs = new BlueprintCreatureSpawner(); cs.setSpawnedType(spawner.getSpawnedType()); cs.setDelay(spawner.getDelay()); diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java index d6f754863..1c559d356 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintPaster.java @@ -301,8 +301,7 @@ public class BlueprintPaster { bpBlock.getInventory().forEach(ih::setItem); } // Mob spawners - if (bs instanceof CreatureSpawner) { - CreatureSpawner spawner = ((CreatureSpawner) bs); + if (bs instanceof CreatureSpawner spawner) { BlueprintCreatureSpawner s = bpBlock.getCreatureSpawner(); spawner.setSpawnedType(s.getSpawnedType()); spawner.setMaxNearbyEntities(s.getMaxNearbyEntities()); @@ -314,8 +313,7 @@ public class BlueprintPaster { bs.update(true, false); } // Banners - if (bs instanceof Banner && bpBlock.getBannerPatterns() != null) { - Banner banner = (Banner) bs; + if (bs instanceof Banner banner && bpBlock.getBannerPatterns() != null) { bpBlock.getBannerPatterns().removeIf(Objects::isNull); banner.setPatterns(bpBlock.getBannerPatterns()); banner.update(true, false); diff --git a/src/main/java/world/bentobox/bentobox/blueprints/conversation/NameSuccessPrompt.java b/src/main/java/world/bentobox/bentobox/blueprints/conversation/NameSuccessPrompt.java index ad9422f32..de2d4731a 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/conversation/NameSuccessPrompt.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/conversation/NameSuccessPrompt.java @@ -42,7 +42,6 @@ public class NameSuccessPrompt extends MessagePrompt { if (bp != null) { BentoBox.getInstance().getBlueprintsManager().renameBlueprint(addon, bp, name); new BlueprintManagementPanel(BentoBox.getInstance(), user, addon).openBB(bb); - return user.getTranslation("commands.admin.blueprint.management.description.success"); } else { // Blueprint Bundle if (bb == null) { @@ -61,8 +60,8 @@ public class NameSuccessPrompt extends MessagePrompt { new BlueprintManagementPanel(BentoBox.getInstance(), user, addon).openPanel(); // Set the name // if successfully - return user.getTranslation("commands.admin.blueprint.management.description.success"); } + return user.getTranslation("commands.admin.blueprint.management.description.success"); } @Override diff --git a/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java b/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java index a99e972d9..e173f6b86 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java @@ -75,8 +75,7 @@ public class BlueprintEntity { ((Ageable)e).setBaby(); } } - if (e instanceof AbstractHorse) { - AbstractHorse horse = (AbstractHorse)e; + if (e instanceof AbstractHorse horse) { if (domestication != null) horse.setDomestication(domestication); if (inventory != null) { inventory.forEach(horse.getInventory()::setItem); diff --git a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardFormat.java b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardFormat.java index 2cc438013..602827df5 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardFormat.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardFormat.java @@ -49,12 +49,12 @@ public class BlueprintClipboardFormat implements ClipboardFormat { } @Override - public ClipboardReader getReader(InputStream inputStream) throws IOException { + public ClipboardReader getReader(InputStream inputStream) { return new BlueprintClipboardReader(inputStream); } @Override - public ClipboardWriter getWriter(OutputStream outputStream) throws IOException { + public ClipboardWriter getWriter(OutputStream outputStream) { return new BlueprintClipboardWriter(outputStream); } diff --git a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardReader.java b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardReader.java index c944294ee..7d5ecf12e 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardReader.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardReader.java @@ -1,6 +1,5 @@ package world.bentobox.bentobox.blueprints.worldedit; -import java.io.IOException; import java.io.InputStream; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -19,12 +18,12 @@ public class BlueprintClipboardReader implements ClipboardReader { } @Override - public Clipboard read() throws IOException { + public Clipboard read() { throw new UnsupportedOperationException(); // TODO } @Override - public void close() throws IOException { + public void close() { throw new UnsupportedOperationException(); // TODO } diff --git a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardWriter.java b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardWriter.java index 105b19b87..5d4e4c680 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardWriter.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintClipboardWriter.java @@ -1,6 +1,5 @@ package world.bentobox.bentobox.blueprints.worldedit; -import java.io.IOException; import java.io.OutputStream; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -18,12 +17,12 @@ public class BlueprintClipboardWriter implements ClipboardWriter { this.outputStream = outputStream; } @Override - public void write(Clipboard clipboard) throws IOException { + public void write(Clipboard clipboard) { throw new UnsupportedOperationException(); // TODO } @Override - public void close() throws IOException { + public void close() { throw new UnsupportedOperationException(); // TODO } diff --git a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintSchematicConverter.java b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintSchematicConverter.java index 6a1708006..05c4621a9 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintSchematicConverter.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/worldedit/BlueprintSchematicConverter.java @@ -18,7 +18,7 @@ public class BlueprintSchematicConverter { private File blueprintFile; public BlueprintSchematicConverter(File blueprintFile) { - if(!BentoBox.getInstance().getHooks().getHook("WorldEdit").isPresent()) { + if(BentoBox.getInstance().getHooks().getHook("WorldEdit").isEmpty()) { BentoBox.getInstance().logError("WorldEdit must be installed to use that class !"); return; } diff --git a/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseConnector.java b/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseConnector.java index fab8aa33e..82a49c031 100644 --- a/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseConnector.java +++ b/src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseConnector.java @@ -23,11 +23,11 @@ public class JSONDatabaseConnector implements DatabaseConnector { @NonNull public String getUniqueId(String tableName) { UUID uuid = UUID.randomUUID(); - File file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON); + File file = new File(dataFolder, tableName + File.separator + uuid + JSON); int limit = 0; while (file.exists() && limit++ < MAX_LOOPS) { uuid = UUID.randomUUID(); - file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON); + file = new File(dataFolder, tableName + File.separator + uuid + JSON); } return uuid.toString(); } diff --git a/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java b/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java index 2b283ae93..2acd1225e 100644 --- a/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java +++ b/src/main/java/world/bentobox/bentobox/database/json/adapters/FlagTypeAdapter.java @@ -42,7 +42,7 @@ public class FlagTypeAdapter extends TypeAdapter { // Flags can end up null if an addon that created one is removed or if a flag name was changed if (f == null) { // Create a temporary flag with a unique key. It will be immediately deleted after loading - f = new Flag.Builder("NULL_FLAG_"+ UUID.randomUUID().toString(), Material.STONE).build(); + f = new Flag.Builder("NULL_FLAG_"+ UUID.randomUUID(), Material.STONE).build(); } return f; } diff --git a/src/main/java/world/bentobox/bentobox/database/mongodb/MongoDBDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/mongodb/MongoDBDatabaseHandler.java index a347b94dd..8a17ac144 100644 --- a/src/main/java/world/bentobox/bentobox/database/mongodb/MongoDBDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/mongodb/MongoDBDatabaseHandler.java @@ -142,12 +142,11 @@ public class MongoDBDatabaseHandler extends AbstractJSONDatabaseHandler { completableFuture.complete(false); return completableFuture; } - if (!(instance instanceof DataObject)) { + if (!(instance instanceof DataObject dataObj)) { plugin.logError("This class is not a DataObject: " + instance.getClass().getName()); completableFuture.complete(false); return completableFuture; } - DataObject dataObj = (DataObject)instance; try { Gson gson = getGson(); String toStore = gson.toJson(instance); diff --git a/src/main/java/world/bentobox/bentobox/database/objects/Island.java b/src/main/java/world/bentobox/bentobox/database/objects/Island.java index a2273e16f..d0d111dbc 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/Island.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/Island.java @@ -1346,7 +1346,7 @@ public class Island implements DataObject, MetaDataAble { * @param flag - Flag to cooldown */ public void setCooldown(Flag flag) { - cooldowns.put(flag, flag.getCooldown() * 1000 + System.currentTimeMillis()); + cooldowns.put(flag, flag.getCooldown() * 1000L + System.currentTimeMillis()); setChanged(); } diff --git a/src/main/java/world/bentobox/bentobox/database/objects/IslandDeletion.java b/src/main/java/world/bentobox/bentobox/database/objects/IslandDeletion.java index 30a5a9697..2b444a5e6 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/IslandDeletion.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/IslandDeletion.java @@ -79,10 +79,9 @@ public class IslandDeletion implements DataObject { if (obj == null) { return false; } - if (!(obj instanceof IslandDeletion)) { + if (!(obj instanceof IslandDeletion other)) { return false; } - IslandDeletion other = (IslandDeletion) obj; if (uniqueId == null) { return other.uniqueId == null; } else return uniqueId.equals(other.uniqueId); diff --git a/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer.java b/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer.java index 118bd0932..128ede5a8 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer.java @@ -26,8 +26,7 @@ public class FlagSerializer implements AdapterInterface, Map< return result; } // For YAML - if (object instanceof MemorySection) { - MemorySection section = (MemorySection) object; + if (object instanceof MemorySection section) { for (String key : section.getKeys(false)) { BentoBox.getInstance().getFlagsManager().getFlag(key).ifPresent(flag -> result.put(flag, section.getInt(key))); } diff --git a/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer2.java b/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer2.java index 564eec52c..0c43f6de7 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer2.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer2.java @@ -23,8 +23,7 @@ public class FlagSerializer2 implements AdapterInterface, Map return result; } // For YAML - if (object instanceof MemorySection) { - MemorySection section = (MemorySection) object; + if (object instanceof MemorySection section) { for (String key : section.getKeys(false)) { BentoBox.getInstance().getFlagsManager().getFlag(key).ifPresent(flag -> result.put(flag, section.getBoolean(key) ? 0 : -1)); } diff --git a/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer3.java b/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer3.java index 7ef181eeb..c6997f8fc 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer3.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/adapters/FlagSerializer3.java @@ -26,8 +26,7 @@ public class FlagSerializer3 implements AdapterInterface, Map result.put(flag, section.getLong(key))); } diff --git a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseConnector.java b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseConnector.java index c7a132965..5c91278d8 100644 --- a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseConnector.java +++ b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseConnector.java @@ -152,9 +152,7 @@ public class YamlDatabaseConnector implements DatabaseConnector { if (nextLine.contains(e.getKey())) { // We want the comment to start at the same level as the entry StringBuilder commentLine = new StringBuilder(); - for (int i = 0; i < nextLine.indexOf(e.getKey()); i++){ - commentLine.append(' '); - } + commentLine.append(" ".repeat(Math.max(0, nextLine.indexOf(e.getKey())))); commentLine.append(e.getValue()); nextLine = commentLine.toString(); break; @@ -191,11 +189,11 @@ public class YamlDatabaseConnector implements DatabaseConnector { @NonNull public String getUniqueId(String tableName) { UUID uuid = UUID.randomUUID(); - File file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML); + File file = new File(dataFolder, tableName + File.separator + uuid + YML); int limit = 0; while (file.exists() && limit++ < MAX_LOOPS) { uuid = UUID.randomUUID(); - file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML); + file = new File(dataFolder, tableName + File.separator + uuid + YML); } return uuid.toString(); } diff --git a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java index 6cad6bd8d..1f1ef97ea 100644 --- a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java @@ -534,7 +534,7 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { } private void setComment(@NonNull String comment, @NonNull YamlConfiguration config, @NonNull Map yamlComments, @NonNull String parent) { - String random = "comment-" + UUID.randomUUID().toString(); + String random = "comment-" + UUID.randomUUID(); // Store placeholder config.set(parent + random, " "); // Create comment diff --git a/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java b/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java index 2d5aa10ae..8112b9f39 100644 --- a/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java +++ b/src/main/java/world/bentobox/bentobox/hooks/LangUtilsHook.java @@ -262,31 +262,30 @@ public class LangUtilsHook extends Hook { if (hooked) { return LanguageHelper.getPotionName(potionType, getUserLocale(user)); } - switch (potionType) { - case UNCRAFTABLE: return "Uncraftable Potion"; - case WATER: return "Water Bottle"; - case MUNDANE: return "Mundane Potion"; - case THICK: return "Thick Potion"; - case AWKWARD: return "Awkward Potion"; - case NIGHT_VISION: return "Potion of Night Vision"; - case INVISIBILITY: return "Potion of Invisibility"; - case JUMP: return "Potion of Leaping"; - case FIRE_RESISTANCE: return "Potion of Fire Resistance"; - case SPEED: return "Potion of Swiftness"; - case SLOWNESS: return "Potion of Slowness"; - case WATER_BREATHING: return "Potion of Water Breathing"; - case INSTANT_HEAL: return "Potion of Healing"; - case INSTANT_DAMAGE: return "Potion of Harming"; - case POISON: return "Potion of Poison"; - case REGEN: return "Potion of Regeneration"; - case STRENGTH: return "Potion of Strength"; - case WEAKNESS: return "Potion of Weakness"; - case LUCK: return "Potion of Luck"; - case TURTLE_MASTER: return "Potion of the Turtle Master"; - case SLOW_FALLING: return "Potion of Slow Falling"; - default: - return Util.prettifyText(potionType.name()); - } + return switch (potionType) { + case UNCRAFTABLE -> "Uncraftable Potion"; + case WATER -> "Water Bottle"; + case MUNDANE -> "Mundane Potion"; + case THICK -> "Thick Potion"; + case AWKWARD -> "Awkward Potion"; + case NIGHT_VISION -> "Potion of Night Vision"; + case INVISIBILITY -> "Potion of Invisibility"; + case JUMP -> "Potion of Leaping"; + case FIRE_RESISTANCE -> "Potion of Fire Resistance"; + case SPEED -> "Potion of Swiftness"; + case SLOWNESS -> "Potion of Slowness"; + case WATER_BREATHING -> "Potion of Water Breathing"; + case INSTANT_HEAL -> "Potion of Healing"; + case INSTANT_DAMAGE -> "Potion of Harming"; + case POISON -> "Potion of Poison"; + case REGEN -> "Potion of Regeneration"; + case STRENGTH -> "Potion of Strength"; + case WEAKNESS -> "Potion of Weakness"; + case LUCK -> "Potion of Luck"; + case TURTLE_MASTER -> "Potion of the Turtle Master"; + case SLOW_FALLING -> "Potion of Slow Falling"; + default -> Util.prettifyText(potionType.name()); + }; } @@ -301,31 +300,30 @@ public class LangUtilsHook extends Hook { if (hooked) { return LanguageHelper.getSplashPotionName(potionType, getUserLocale(user)); } - switch (potionType) { - case UNCRAFTABLE: return "Splash Uncraftable Potion"; - case WATER: return "Splash Water Bottle"; - case MUNDANE: return "Mundane Splash Potion"; - case THICK: return "Thick Splash Potion"; - case AWKWARD: return "Awkward Splash Potion"; - case NIGHT_VISION: return "Splash Potion of Night Vision"; - case INVISIBILITY: return "Splash Potion of Invisibility"; - case JUMP: return "Splash Potion of Leaping"; - case FIRE_RESISTANCE: return "Splash Potion of Fire Resistance"; - case SPEED: return "Splash Potion of Swiftness"; - case SLOWNESS: return "Splash Potion of Slowness"; - case WATER_BREATHING: return "Splash Potion of Water Breathing"; - case INSTANT_HEAL: return "Splash Potion of Healing"; - case INSTANT_DAMAGE: return "Splash Potion of Harming"; - case POISON: return "Splash Potion of Poison"; - case REGEN: return "Splash Potion of Regeneration"; - case STRENGTH: return "Splash Potion of Strength"; - case WEAKNESS: return "Splash Potion of Weakness"; - case LUCK: return "Splash Potion of Luck"; - case TURTLE_MASTER: return "Splash Potion of the Turtle Master"; - case SLOW_FALLING: return "Splash Potion of Slow Falling"; - default: - return Util.prettifyText(potionType.name()); - } + return switch (potionType) { + case UNCRAFTABLE -> "Splash Uncraftable Potion"; + case WATER -> "Splash Water Bottle"; + case MUNDANE -> "Mundane Splash Potion"; + case THICK -> "Thick Splash Potion"; + case AWKWARD -> "Awkward Splash Potion"; + case NIGHT_VISION -> "Splash Potion of Night Vision"; + case INVISIBILITY -> "Splash Potion of Invisibility"; + case JUMP -> "Splash Potion of Leaping"; + case FIRE_RESISTANCE -> "Splash Potion of Fire Resistance"; + case SPEED -> "Splash Potion of Swiftness"; + case SLOWNESS -> "Splash Potion of Slowness"; + case WATER_BREATHING -> "Splash Potion of Water Breathing"; + case INSTANT_HEAL -> "Splash Potion of Healing"; + case INSTANT_DAMAGE -> "Splash Potion of Harming"; + case POISON -> "Splash Potion of Poison"; + case REGEN -> "Splash Potion of Regeneration"; + case STRENGTH -> "Splash Potion of Strength"; + case WEAKNESS -> "Splash Potion of Weakness"; + case LUCK -> "Splash Potion of Luck"; + case TURTLE_MASTER -> "Splash Potion of the Turtle Master"; + case SLOW_FALLING -> "Splash Potion of Slow Falling"; + default -> Util.prettifyText(potionType.name()); + }; } /** @@ -339,31 +337,30 @@ public class LangUtilsHook extends Hook { if (hooked) { return LanguageHelper.getLingeringPotionName(potionType, getUserLocale(user)); } - switch (potionType) { - case UNCRAFTABLE: return "Lingering Uncraftable Potion"; - case WATER: return "Lingering Water Bottle"; - case MUNDANE: return "Mundane Lingering Potion"; - case THICK: return "Thick Lingering Potion"; - case AWKWARD: return "Awkward Lingering Potion"; - case NIGHT_VISION: return "Lingering Potion of Night Vision"; - case INVISIBILITY: return "Lingering Potion of Invisibility"; - case JUMP: return "Lingering Potion of Leaping"; - case FIRE_RESISTANCE: return "Lingering Potion of Fire Resistance"; - case SPEED: return "Lingering Potion of Swiftness"; - case SLOWNESS: return "Lingering Potion of Slowness"; - case WATER_BREATHING: return "Lingering Potion of Water Breathing"; - case INSTANT_HEAL: return "Lingering Potion of Healing"; - case INSTANT_DAMAGE: return "Lingering Potion of Harming"; - case POISON: return "Lingering Potion of Poison"; - case REGEN: return "Lingering Potion of Regeneration"; - case STRENGTH: return "Lingering Potion of Strength"; - case WEAKNESS: return "Lingering Potion of Weakness"; - case LUCK: return "Lingering Potion of Luck"; - case TURTLE_MASTER: return "Lingering Potion of the Turtle Master"; - case SLOW_FALLING: return "Lingering Potion of Slow Falling"; - default: - return Util.prettifyText(potionType.name()); - } + return switch (potionType) { + case UNCRAFTABLE -> "Lingering Uncraftable Potion"; + case WATER -> "Lingering Water Bottle"; + case MUNDANE -> "Mundane Lingering Potion"; + case THICK -> "Thick Lingering Potion"; + case AWKWARD -> "Awkward Lingering Potion"; + case NIGHT_VISION -> "Lingering Potion of Night Vision"; + case INVISIBILITY -> "Lingering Potion of Invisibility"; + case JUMP -> "Lingering Potion of Leaping"; + case FIRE_RESISTANCE -> "Lingering Potion of Fire Resistance"; + case SPEED -> "Lingering Potion of Swiftness"; + case SLOWNESS -> "Lingering Potion of Slowness"; + case WATER_BREATHING -> "Lingering Potion of Water Breathing"; + case INSTANT_HEAL -> "Lingering Potion of Healing"; + case INSTANT_DAMAGE -> "Lingering Potion of Harming"; + case POISON -> "Lingering Potion of Poison"; + case REGEN -> "Lingering Potion of Regeneration"; + case STRENGTH -> "Lingering Potion of Strength"; + case WEAKNESS -> "Lingering Potion of Weakness"; + case LUCK -> "Lingering Potion of Luck"; + case TURTLE_MASTER -> "Lingering Potion of the Turtle Master"; + case SLOW_FALLING -> "Lingering Potion of Slow Falling"; + default -> Util.prettifyText(potionType.name()); + }; } /** @@ -377,31 +374,28 @@ public class LangUtilsHook extends Hook { if (hooked) { return LanguageHelper.getTippedArrowName(potionType, getUserLocale(user)); } - switch (potionType) { - case UNCRAFTABLE: return "Uncraftable Tipped Arrow"; - case WATER: return "Arrow of Splashing"; - case MUNDANE: - case THICK: - case AWKWARD: return "Tipped Arrow"; - case NIGHT_VISION: return "Arrow of Night Vision"; - case INVISIBILITY: return "Arrow of Invisibility"; - case JUMP: return "Arrow of Leaping"; - case FIRE_RESISTANCE: return "Arrow of Fire Resistance"; - case SPEED: return "Arrow of Swiftness"; - case SLOWNESS: return "Arrow of Slowness"; - case WATER_BREATHING: return "Arrow of Water Breathing"; - case INSTANT_HEAL: return "Arrow of Healing"; - case INSTANT_DAMAGE: return "Arrow of Harming"; - case POISON: return "Arrow of Poison"; - case REGEN: return "Arrow of Regeneration"; - case STRENGTH: return "Arrow of Strength"; - case WEAKNESS: return "Arrow of Weakness"; - case LUCK: return "Arrow of Luck"; - case TURTLE_MASTER: return "Arrow of the Turtle Master"; - case SLOW_FALLING: return "Arrow of Slow Falling"; - default: - return Util.prettifyText(potionType.name()); - } + return switch (potionType) { + case UNCRAFTABLE -> "Uncraftable Tipped Arrow"; + case WATER -> "Arrow of Splashing"; + case MUNDANE, THICK, AWKWARD -> "Tipped Arrow"; + case NIGHT_VISION -> "Arrow of Night Vision"; + case INVISIBILITY -> "Arrow of Invisibility"; + case JUMP -> "Arrow of Leaping"; + case FIRE_RESISTANCE -> "Arrow of Fire Resistance"; + case SPEED -> "Arrow of Swiftness"; + case SLOWNESS -> "Arrow of Slowness"; + case WATER_BREATHING -> "Arrow of Water Breathing"; + case INSTANT_HEAL -> "Arrow of Healing"; + case INSTANT_DAMAGE -> "Arrow of Harming"; + case POISON -> "Arrow of Poison"; + case REGEN -> "Arrow of Regeneration"; + case STRENGTH -> "Arrow of Strength"; + case WEAKNESS -> "Arrow of Weakness"; + case LUCK -> "Arrow of Luck"; + case TURTLE_MASTER -> "Arrow of the Turtle Master"; + case SLOW_FALLING -> "Arrow of Slow Falling"; + default -> Util.prettifyText(potionType.name()); + }; } /** @@ -620,22 +614,22 @@ public class LangUtilsHook extends Hook { // The description of the music record is the same in any language, // so directly output it here. - switch (material) { - case MUSIC_DISC_13 : return "C418 - 13"; - case MUSIC_DISC_CAT : return "C418 - cat"; - case MUSIC_DISC_BLOCKS : return "C418 - blocks"; - case MUSIC_DISC_CHIRP : return "C418 - chirp"; - case MUSIC_DISC_FAR : return "C418 - far"; - case MUSIC_DISC_MALL : return "C418 - mall"; - case MUSIC_DISC_MELLOHI : return "C418 - mellohi"; - case MUSIC_DISC_STAL : return "C418 - stal"; - case MUSIC_DISC_STRAD : return "C418 - strad"; - case MUSIC_DISC_WARD : return "C418 - ward"; - case MUSIC_DISC_11 : return "C418 - 11"; - case MUSIC_DISC_WAIT : return "C418 - wait"; - case MUSIC_DISC_PIGSTEP : return "Lena Raine - Pigstep"; - default : return null; - } + return switch (material) { + case MUSIC_DISC_13 -> "C418 - 13"; + case MUSIC_DISC_CAT -> "C418 - cat"; + case MUSIC_DISC_BLOCKS -> "C418 - blocks"; + case MUSIC_DISC_CHIRP -> "C418 - chirp"; + case MUSIC_DISC_FAR -> "C418 - far"; + case MUSIC_DISC_MALL -> "C418 - mall"; + case MUSIC_DISC_MELLOHI -> "C418 - mellohi"; + case MUSIC_DISC_STAL -> "C418 - stal"; + case MUSIC_DISC_STRAD -> "C418 - strad"; + case MUSIC_DISC_WARD -> "C418 - ward"; + case MUSIC_DISC_11 -> "C418 - 11"; + case MUSIC_DISC_WAIT -> "C418 - wait"; + case MUSIC_DISC_PIGSTEP -> "Lena Raine - Pigstep"; + default -> null; + }; } } diff --git a/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java b/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java index bac2aa6b1..634fdc05b 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java @@ -80,7 +80,7 @@ public class JoinLeaveListener implements Listener { players.setPlayerName(user); players.save(playerUUID); } else { - plugin.logWarning("Player that just logged in has no name! " + playerUUID.toString()); + plugin.logWarning("Player that just logged in has no name! " + playerUUID); } // If mobs have to be removed when a player joins, then wipe all the mobs on his island. @@ -126,9 +126,8 @@ public class JoinLeaveListener implements Listener { // - abort on logout is false // - abort on logout is true && user is online if (!plugin.getIWM().isCreateIslandOnFirstLoginAbortOnLogout(w) || user.isOnline()){ - plugin.getIWM().getAddon(w).ifPresent(addon -> addon.getPlayerCommand() - .map(command -> command.getSubCommand("create").orElse(null)) - .ifPresent(command -> command.execute(user, "create", Collections.singletonList(BlueprintsManager.DEFAULT_BUNDLE_NAME)))); + plugin.getIWM().getAddon(w).flatMap(addon -> addon.getPlayerCommand().map(command -> command.getSubCommand("create").orElse(null))) + .ifPresent(command -> command.execute(user, "create", Collections.singletonList(BlueprintsManager.DEFAULT_BUNDLE_NAME))); } }; diff --git a/src/main/java/world/bentobox/bentobox/listeners/PlayerEntityPortalEvent.java b/src/main/java/world/bentobox/bentobox/listeners/PlayerEntityPortalEvent.java index ed0cff519..3a8c04cd4 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/PlayerEntityPortalEvent.java +++ b/src/main/java/world/bentobox/bentobox/listeners/PlayerEntityPortalEvent.java @@ -47,7 +47,7 @@ public class PlayerEntityPortalEvent { * @return whether there should create be a destination portal created */ public boolean getCanCreatePortal() { - return epe == null ? ppe.getCanCreatePortal() : false; + return epe == null && ppe.getCanCreatePortal(); } /** diff --git a/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java b/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java index 495d4e1ab..3f0402051 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/PortalTeleportationListener.java @@ -117,7 +117,7 @@ public class PortalTeleportationListener implements Listener { || m.equals(Material.END_PORTAL) || m.equals(Material.END_GATEWAY)) .findFirst(); - if (!mat.isPresent()) { + if (mat.isEmpty()) { e.setCancelled(true); return false; } else if (mat.get().equals(Material.NETHER_PORTAL)){ @@ -135,15 +135,11 @@ public class PortalTeleportationListener implements Listener { */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public boolean onIslandPortal(PlayerPortalEvent e) { - switch (e.getCause()) { - case END_GATEWAY: - case END_PORTAL: - return processPortal(new PlayerEntityPortalEvent(e), Environment.THE_END); - case NETHER_PORTAL: - return processPortal(new PlayerEntityPortalEvent(e), Environment.NETHER); - default: - return false; - } + return switch (e.getCause()) { + case END_GATEWAY, END_PORTAL -> processPortal(new PlayerEntityPortalEvent(e), Environment.THE_END); + case NETHER_PORTAL -> processPortal(new PlayerEntityPortalEvent(e), Environment.NETHER); + default -> false; + }; } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListener.java index faf4408ad..7b64ca275 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListener.java @@ -1,7 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -36,9 +34,7 @@ public class BlockInteractionListener extends FlagListener { */ private final static Map stringFlags; static { - Map f = new HashMap<>(); - f.put("RESPAWN_ANCHOR", "PLACE_BLOCKS"); - stringFlags = Collections.unmodifiableMap(f); + stringFlags = Map.of("RESPAWN_ANCHOR", "PLACE_BLOCKS"); } /** diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java index 35b4bc0ea..391f2605d 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreakBlocksListener.java @@ -46,9 +46,8 @@ public class BreakBlocksListener extends FlagListener { checkIsland(e, (Player)e.getRemover(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS); } // Check for projectiles - if (e.getRemover() instanceof Projectile) { + if (e.getRemover() instanceof Projectile p) { // Find out who fired it - Projectile p = (Projectile)e.getRemover(); if (p.getShooter() instanceof Player) { checkIsland(e, (Player)p.getShooter(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS); } @@ -118,9 +117,8 @@ public class BreakBlocksListener extends FlagListener { if (e.getDamager() instanceof Player) { // Check the break blocks flag notAllowed(e, (Player)e.getDamager(), e.getEntity().getLocation()); - } else if (e.getDamager() instanceof Projectile) { + } else if (e.getDamager() instanceof Projectile p) { // Find out who fired the arrow - Projectile p = (Projectile) e.getDamager(); if (p.getShooter() instanceof Player && notAllowed(e, (Player)p.getShooter(), e.getEntity().getLocation())) { e.getEntity().setFireTicks(0); p.setFireTicks(0); diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java index d509d9627..1548535b2 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BreedingListener.java @@ -73,8 +73,7 @@ public class BreedingListener extends FlagListener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true) public void onPlayerInteract(final PlayerInteractAtEntityEvent e) { Player p = e.getPlayer(); - if (e.getRightClicked() instanceof Animals && BREEDING_ITEMS.containsKey(e.getRightClicked().getType())) { - Animals animal = (Animals) e.getRightClicked(); + if (e.getRightClicked() instanceof Animals animal && BREEDING_ITEMS.containsKey(e.getRightClicked().getType())) { ItemStack inHand = p.getInventory().getItemInMainHand(); if (e.getHand().equals(EquipmentSlot.OFF_HAND)) { inHand = p.getInventory().getItemInOffHand(); diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java index 3dd360185..73a19c4aa 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/BucketListener.java @@ -40,18 +40,21 @@ public class BucketListener extends FlagListener { public void onBucketFill(final PlayerBucketFillEvent e) { // Check filling of various liquids switch (e.getItemStack().getType()) { - case LAVA_BUCKET: - checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA); - return; - case WATER_BUCKET: - checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER); - return; - case MILK_BUCKET: - checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING); - return; - default: - // Check general bucket use - checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET); + case LAVA_BUCKET -> { + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA); + return; + } + case WATER_BUCKET -> { + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER); + return; + } + case MILK_BUCKET -> { + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING); + return; + } + default -> + // Check general bucket use + checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET); } } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListener.java index 9338e5a9c..f3d4b585c 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/ElytraListener.java @@ -18,8 +18,7 @@ public class ElytraListener extends FlagListener { */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onGlide(EntityToggleGlideEvent e) { - if (e.getEntity() instanceof Player) { - Player player = (Player) e.getEntity(); + if (e.getEntity() instanceof Player player) { if (!checkIsland(e, player, player.getLocation(), Flags.ELYTRA)) { player.setGliding(false); } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListener.java index d0e060912..9e4922083 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/HurtingListener.java @@ -71,9 +71,8 @@ public class HurtingListener extends FlagListener { // Get the attacker if (damager instanceof Player) { checkIsland(e, (Player)damager, damager.getLocation(), flag); - } else if (damager instanceof Projectile) { + } else if (damager instanceof Projectile p) { // Find out who fired the projectile - Projectile p = (Projectile) damager; if (p.getShooter() instanceof Player && !checkIsland(e, (Player)p.getShooter(), damager.getLocation(), flag)) { e.getEntity().setFireTicks(0); } @@ -123,8 +122,7 @@ public class HurtingListener extends FlagListener { public void onSplashPotionSplash(final PotionSplashEvent e) { // Try to get the shooter Projectile projectile = e.getEntity(); - if (projectile.getShooter() instanceof Player) { - Player attacker = (Player)projectile.getShooter(); + if (projectile.getShooter() instanceof Player attacker) { // Run through all the affected entities for (LivingEntity entity: e.getAffectedEntities()) { // Self damage diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListener.java index f9e5275be..250969322 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/InventoryListener.java @@ -72,9 +72,8 @@ public class InventoryListener extends FlagListener { else if (inventoryHolder instanceof ShulkerBox) { checkIsland(e, player, e.getInventory().getLocation(), Flags.SHULKER_BOX); } - else if (inventoryHolder instanceof Chest) { + else if (inventoryHolder instanceof Chest chestInventoryHolder) { // To differentiate between a Chest and a Trapped Chest we need to get the Block corresponding to the inventory - Chest chestInventoryHolder = (Chest) inventoryHolder; try { if (chestInventoryHolder.getType() == Material.TRAPPED_CHEST) { checkIsland(e, player, e.getInventory().getLocation(), Flags.TRAPPED_CHEST); diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListener.java index d29e4330b..26ef9d7d8 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/PhysicalInteractionListener.java @@ -53,10 +53,9 @@ public class PhysicalInteractionListener extends FlagListener { */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onProjectileHit(EntityInteractEvent e) { - if (!(e.getEntity() instanceof Projectile)) { + if (!(e.getEntity() instanceof Projectile p)) { return; } - Projectile p = (Projectile)e.getEntity(); if (p.getShooter() instanceof Player) { if (Tag.WOODEN_BUTTONS.isTagged(e.getBlock().getType())) { checkIsland(e, (Player)p.getShooter(), e.getBlock().getLocation(), Flags.BUTTON); @@ -71,23 +70,10 @@ public class PhysicalInteractionListener extends FlagListener { } private boolean isPressurePlate(Material material) { - switch(material) { - case STONE_PRESSURE_PLATE: - case POLISHED_BLACKSTONE_PRESSURE_PLATE: - case ACACIA_PRESSURE_PLATE: - case BIRCH_PRESSURE_PLATE: - case CRIMSON_PRESSURE_PLATE: - case DARK_OAK_PRESSURE_PLATE: - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case JUNGLE_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - case OAK_PRESSURE_PLATE: - case SPRUCE_PRESSURE_PLATE: - case WARPED_PRESSURE_PLATE: - return true; - default: - return false; - } + return switch (material) { + case STONE_PRESSURE_PLATE, POLISHED_BLACKSTONE_PRESSURE_PLATE, ACACIA_PRESSURE_PLATE, BIRCH_PRESSURE_PLATE, CRIMSON_PRESSURE_PLATE, DARK_OAK_PRESSURE_PLATE, HEAVY_WEIGHTED_PRESSURE_PLATE, JUNGLE_PRESSURE_PLATE, LIGHT_WEIGHTED_PRESSURE_PLATE, OAK_PRESSURE_PLATE, SPRUCE_PRESSURE_PLATE, WARPED_PRESSURE_PLATE -> true; + default -> false; + }; } } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/TNTListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/TNTListener.java index 514d255bf..1d1b43a2e 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/TNTListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/TNTListener.java @@ -1,7 +1,5 @@ package world.bentobox.bentobox.listeners.flags.protection; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.bukkit.Location; @@ -31,13 +29,13 @@ public class TNTListener extends FlagListener { * Contains {@link EntityType}s that generates an explosion. * @since 1.5.0 */ - private static final List TNT_TYPES = Collections.unmodifiableList(Arrays.asList(EntityType.PRIMED_TNT, EntityType.MINECART_TNT)); + private static final List TNT_TYPES = List.of(EntityType.PRIMED_TNT, EntityType.MINECART_TNT); /** * Contains {@link Material}s that can be used to prime a TNT. * @since 1.5.0 */ - private static final List PRIMING_ITEMS = Collections.unmodifiableList(Arrays.asList(Material.FLINT_AND_STEEL, Material.FIRE_CHARGE)); + private static final List PRIMING_ITEMS = List.of(Material.FLINT_AND_STEEL, Material.FIRE_CHARGE); /** * Protect TNT from being set light by a fire arrow @@ -50,8 +48,7 @@ public class TNTListener extends FlagListener { return false; } // Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow - if (e.getEntity() instanceof Projectile) { - Projectile projectile = (Projectile) e.getEntity(); + if (e.getEntity() instanceof Projectile projectile) { // Find out who fired it if (projectile.getShooter() instanceof Player && projectile.getFireTicks() > 0 && !checkIsland(e, (Player)projectile.getShooter(), e.getBlock().getLocation(), Flags.TNT_PRIMING)) { diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java index 0a39e2ad7..8a053aca9 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/settings/PVPListener.java @@ -83,9 +83,8 @@ public class PVPListener extends FlagListener { user.notify(getFlag(damager.getWorld()).getHintReference()); e.setCancelled(true); } - } else if (damager instanceof Projectile && ((Projectile)damager).getShooter() instanceof Player) { + } else if (damager instanceof Projectile p && ((Projectile)damager).getShooter() instanceof Player) { // Find out who fired the arrow - Projectile p = (Projectile) damager; Player shooter =(Player)p.getShooter(); processDamage(e, damager, shooter, hurtEntity, flag); } else if (damager instanceof Firework && firedFireworks.containsKey(damager)) { @@ -198,14 +197,11 @@ public class PVPListener extends FlagListener { } private Flag getFlag(World w) { - switch (w.getEnvironment()) { - case NETHER: - return Flags.PVP_NETHER; - case THE_END: - return Flags.PVP_END; - default: - return Flags.PVP_OVERWORLD; - } + return switch (w.getEnvironment()) { + case NETHER -> Flags.PVP_NETHER; + case THE_END -> Flags.PVP_END; + default -> Flags.PVP_OVERWORLD; + }; } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CreeperListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CreeperListener.java index e70571b83..814c982ed 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CreeperListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CreeperListener.java @@ -41,8 +41,7 @@ public class CreeperListener extends FlagListener { } // Check for griefing Creeper creeper = (Creeper)e.getEntity(); - if (!Flags.CREEPER_GRIEFING.isSetForWorld(e.getLocation().getWorld()) && creeper.getTarget() instanceof Player) { - Player target = (Player)creeper.getTarget(); + if (!Flags.CREEPER_GRIEFING.isSetForWorld(e.getLocation().getWorld()) && creeper.getTarget() instanceof Player target) { if (!getIslands().locationIsOnIsland(target, e.getLocation())) { User user = User.getInstance(target); user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.CREEPER_GRIEFING.getHintReference())); diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/GeoLimitMobsListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/GeoLimitMobsListener.java index bded3d444..3a73ed6e4 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/GeoLimitMobsListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/GeoLimitMobsListener.java @@ -69,8 +69,7 @@ public class GeoLimitMobsListener extends FlagListener { public void onProjectileExplode(final ExplosionPrimeEvent e) { if (e.getEntity() instanceof Projectile && getIWM().inWorld(e.getEntity().getLocation())) { ProjectileSource source = ((Projectile)e.getEntity()).getShooter(); - if (source instanceof Entity) { - Entity shooter = (Entity)source; + if (source instanceof Entity shooter) { if (mobSpawnTracker.containsKey(shooter) && !mobSpawnTracker.get(shooter).onIsland(e.getEntity().getLocation())) { e.getEntity().remove(); diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java index 87bbb4379..683a034d1 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/InvincibleVisitorsListener.java @@ -124,7 +124,7 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onVisitorGetDamage(EntityDamageEvent e) { World world = e.getEntity().getWorld(); - if (!(e.getEntity() instanceof Player) + if (!(e.getEntity() instanceof Player p) || !getIWM().inWorld(world) || e.getEntity().hasMetadata("NPC") || !getIWM().getIvSettings(world).contains(e.getCause().name()) @@ -133,7 +133,6 @@ public class InvincibleVisitorsListener extends FlagListener implements ClickHan } // Player is a visitor and should be protected from damage e.setCancelled(true); - Player p = (Player) e.getEntity(); // Handle the void - teleport player back to island in a safe spot if(e.getCause().equals(DamageCause.VOID)) { if (getIslands().getIslandAt(p.getLocation()).isPresent()) { diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/LiquidsFlowingOutListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/LiquidsFlowingOutListener.java index 9cb5b6e3a..3c533adbf 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/LiquidsFlowingOutListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/LiquidsFlowingOutListener.java @@ -38,7 +38,7 @@ public class LiquidsFlowingOutListener extends FlagListener { // Only prevent if it is flowing into the area between islands or into another island. Optional fromIsland = getIslands().getProtectedIslandAt(from.getLocation()); Optional toIsland = getIslands().getProtectedIslandAt(to.getLocation()); - if (!toIsland.isPresent() || (fromIsland.isPresent() && !fromIsland.equals(toIsland))) { + if (toIsland.isEmpty() || (fromIsland.isPresent() && !fromIsland.equals(toIsland))) { e.setCancelled(true); } } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/NaturalSpawningOutsideRangeListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/NaturalSpawningOutsideRangeListener.java index 769078eae..ade03ed48 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/NaturalSpawningOutsideRangeListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/NaturalSpawningOutsideRangeListener.java @@ -23,7 +23,7 @@ public class NaturalSpawningOutsideRangeListener extends FlagListener { } // If it is a natural spawn and there is no protected island at the location, block the spawn. - if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && !getIslands().getProtectedIslandAt(e.getLocation()).isPresent()) { + if (e.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && getIslands().getProtectedIslandAt(e.getLocation()).isEmpty()) { e.setCancelled(true); } } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListener.java index 379c44de3..ced124ed8 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/PetTeleportListener.java @@ -25,9 +25,8 @@ public class PetTeleportListener extends FlagListener { if (e.getTo() == null || !getIWM().inWorld(e.getFrom()) || !Flags.PETS_STAY_AT_HOME.isSetForWorld(e.getFrom().getWorld()) - || !(e.getEntity() instanceof Tameable) + || !(e.getEntity() instanceof Tameable t) ) return; - Tameable t = (Tameable)e.getEntity(); if (t.isTamed() && t.getOwner() != null) { // Get where the pet is going e.setCancelled(getIslands().getProtectedIslandAt(e.getTo()) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/TreesGrowingOutsideRangeListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/TreesGrowingOutsideRangeListener.java index e927acd07..9f77ec728 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/TreesGrowingOutsideRangeListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/TreesGrowingOutsideRangeListener.java @@ -24,14 +24,14 @@ public class TreesGrowingOutsideRangeListener extends FlagListener { } // If there is no protected island at the location of the sapling, just cancel the event (prevents the sapling from growing). - if (!getIslands().getProtectedIslandAt(e.getLocation()).isPresent()) { + if (getIslands().getProtectedIslandAt(e.getLocation()).isEmpty()) { e.setCancelled(true); return; } // Now, run through all the blocks that will be generated and if there is no protected island at their location, turn them into AIR. e.getBlocks().stream() - .filter(blockState -> !getIslands().getProtectedIslandAt(blockState.getLocation()).isPresent()) + .filter(blockState -> getIslands().getProtectedIslandAt(blockState.getLocation()).isEmpty()) .forEach(blockState -> blockState.setType(Material.AIR)); } @@ -45,13 +45,13 @@ public class TreesGrowingOutsideRangeListener extends FlagListener { } // If there is no protected island at the location of the chorus flower, just cancel the event (prevents the flower from growing). - if (!getIslands().getProtectedIslandAt(e.getSource().getLocation()).isPresent()) { + if (getIslands().getProtectedIslandAt(e.getSource().getLocation()).isEmpty()) { e.setCancelled(true); return; } // Now prevent the flower to grow if this is growing outside the island - if (!getIslands().getProtectedIslandAt(e.getBlock().getLocation()).isPresent()) { + if (getIslands().getProtectedIslandAt(e.getBlock().getLocation()).isEmpty()) { e.setCancelled(true); } } diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 9e0ae0d45..7b8e28a15 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -211,8 +211,7 @@ public class AddonsManager { // Run the onLoad. addon.onLoad(); // if game mode, get the world name and generate - if (addon instanceof GameModeAddon && !addon.getState().equals(State.DISABLED)) { - GameModeAddon gameMode = (GameModeAddon) addon; + if (addon instanceof GameModeAddon gameMode && !addon.getState().equals(State.DISABLED)) { if (!gameMode.getWorldSettings().getWorldName().isEmpty()) { worldNames.put(gameMode.getWorldSettings().getWorldName().toLowerCase(Locale.ENGLISH), gameMode); } @@ -282,8 +281,7 @@ public class AddonsManager { plugin.log("Enabling " + addon.getDescription().getName() + " (" + addon.getDescription().getVersion() + ")..."); try { // If this is a GameModeAddon create the worlds, register it and load the blueprints - if (addon instanceof GameModeAddon) { - GameModeAddon gameMode = (GameModeAddon) addon; + if (addon instanceof GameModeAddon gameMode) { // Create the gameWorlds gameMode.createWorlds(); plugin.getIWM().addGameMode(gameMode); @@ -296,8 +294,7 @@ public class AddonsManager { plugin.log(addon.getDescription().getName() + " is disabled."); return; } - if (addon instanceof GameModeAddon) { - GameModeAddon gameMode = (GameModeAddon) addon; + if (addon instanceof GameModeAddon gameMode) { // Set the worlds for the commands gameMode.getPlayerCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld())); gameMode.getAdminCommand().ifPresent(c -> c.setWorld(gameMode.getOverWorld())); @@ -327,7 +324,7 @@ public class AddonsManager { plugin.logWarning("NOTE: DO NOT report this as a bug from BentoBox."); StringBuilder a = new StringBuilder(); addon.getDescription().getAuthors().forEach(author -> a.append(author).append(" ")); - plugin.getLogger().log(Level.SEVERE, "Please report this stack trace to the addon's author(s): " + a.toString(), e); + plugin.getLogger().log(Level.SEVERE, "Please report this stack trace to the addon's author(s): " + a, e); } diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index bc0bfb1d8..b4e7a57a7 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -144,7 +144,7 @@ public class IslandsManager { depth = i; } else { Optional island = getIslandAt(l); - if (!island.isPresent()) { + if (island.isEmpty()) { return null; } i = island.get().getProtectionRange(); @@ -270,31 +270,12 @@ public class IslandsManager { return false; } // Known unsafe blocks - switch (ground) { - // Unsafe - case ANVIL: - case BARRIER: - case CACTUS: - case END_PORTAL: - case END_ROD: - case FIRE: - case FLOWER_POT: - case LADDER: - case LEVER: - case TALL_GRASS: - case PISTON_HEAD: - case MOVING_PISTON: - case TORCH: - case WALL_TORCH: - case TRIPWIRE: - case WATER: - case COBWEB: - case NETHER_PORTAL: - case MAGMA_BLOCK: - return false; - default: - return true; - } + return switch (ground) { + // Unsafe + case ANVIL, BARRIER, CACTUS, END_PORTAL, END_ROD, FIRE, FLOWER_POT, LADDER, LEVER, TALL_GRASS, PISTON_HEAD, + MOVING_PISTON, TORCH, WALL_TORCH, TRIPWIRE, WATER, COBWEB, NETHER_PORTAL, MAGMA_BLOCK -> false; + default -> true; + }; } /** @@ -324,7 +305,7 @@ public class IslandsManager { // This should never happen, so although this is a potential infinite loop I'm going to leave it here because // it will be bad if this does occur and the server should crash. plugin.logWarning("Duplicate island UUID occurred"); - island.setUniqueId(gmName + UUID.randomUUID().toString()); + island.setUniqueId(gmName + UUID.randomUUID()); } if (islandCache.addIsland(island)) { return island; @@ -919,7 +900,7 @@ public class IslandsManager { * @since 1.16.0 */ public boolean removeHomeLocation(@Nullable Island island, String name) { - return island == null ? false : island.removeHome(name); + return island != null && island.removeHome(name); } /** @@ -930,7 +911,7 @@ public class IslandsManager { * @return true if successful, false if not */ public boolean renameHomeLocation(@Nullable Island island, String oldName, String newName) { - return island == null ? false : island.renameHome(oldName, newName); + return island != null && island.renameHome(oldName, newName); } /** @@ -1200,7 +1181,7 @@ public class IslandsManager { player.leaveVehicle(); // Remove the boat so they don't lie around everywhere boat.remove(); - Material boatMat = Material.getMaterial(((Boat) boat).getWoodType().toString() + "_BOAT"); + Material boatMat = Material.getMaterial(((Boat) boat).getWoodType() + "_BOAT"); if (boatMat == null) { boatMat = Material.OAK_BOAT; } @@ -1796,7 +1777,7 @@ public class IslandsManager { * @since 1.7.0 */ public boolean nameExists(@NonNull World world, @NonNull String name) { - return getIslands(world).stream().filter(island -> island.getName() != null).map(Island::getName) + return getIslands(world).stream().map(Island::getName).filter(Objects::nonNull) .anyMatch(n -> ChatColor.stripColor(n).equals(ChatColor.stripColor(name))); } diff --git a/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java b/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java index 11d3a117f..77d8888de 100644 --- a/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java +++ b/src/main/java/world/bentobox/bentobox/managers/island/DefaultNewIslandLocationStrategy.java @@ -102,7 +102,7 @@ public class DefaultNewIslandLocationStrategy implements NewIslandLocationStrate // Block check if (plugin.getIWM().isCheckForBlocks(world) && !plugin.getIWM().isUseOwnGenerator(world) - && Arrays.asList(BlockFace.values()).stream().anyMatch(bf -> + && Arrays.stream(BlockFace.values()).anyMatch(bf -> !location.getBlock().getRelative(bf).isEmpty() && !location.getBlock().getRelative(bf).getType().equals(Material.WATER))) { // Block found diff --git a/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java b/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java index c0cf5278c..4247bf672 100644 --- a/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java +++ b/src/main/java/world/bentobox/bentobox/managers/island/IslandCache.java @@ -1,11 +1,9 @@ package world.bentobox.bentobox.managers.island; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -115,7 +113,7 @@ public class IslandCache { grids.putIfAbsent(island.getWorld(), new IslandGrid()); return grids.get(island.getWorld()).removeFromGrid(island); } - + /** * Delete island from the cache by ID. Does not remove blocks. * @param uniqueId - island unique ID @@ -180,12 +178,10 @@ public class IslandCache { @NonNull public Collection getIslands(@NonNull World world) { World overworld = Util.getWorld(world); - List islandsInWorld = islandsByLocation.entrySet().stream() - .filter(entry -> overworld.equals(Util.getWorld(entry.getKey().getWorld()))) // shouldn't make NPEs - .map(Map.Entry::getValue) - .collect(Collectors.toCollection(ArrayList::new)); - return Collections.unmodifiableCollection(islandsInWorld); + return islandsByLocation.entrySet().stream() + .filter(entry -> overworld.equals(Util.getWorld(entry.getKey().getWorld()))) // shouldn't make NPEs + .map(Map.Entry::getValue).collect(Collectors.toUnmodifiableList()); } /** diff --git a/src/main/java/world/bentobox/bentobox/nms/NMSAbstraction.java b/src/main/java/world/bentobox/bentobox/nms/NMSAbstraction.java index 24bca0842..f2e30c157 100644 --- a/src/main/java/world/bentobox/bentobox/nms/NMSAbstraction.java +++ b/src/main/java/world/bentobox/bentobox/nms/NMSAbstraction.java @@ -16,6 +16,6 @@ public interface NMSAbstraction { * @param blockData - block data to set the block * @param applyPhysics - apply physics or not */ - public void setBlockInNativeChunk(Chunk chunk, int x, int y, int z, BlockData blockData, boolean applyPhysics); + void setBlockInNativeChunk(Chunk chunk, int x, int y, int z, BlockData blockData, boolean applyPhysics); } diff --git a/src/main/java/world/bentobox/bentobox/panels/BlueprintManagementPanel.java b/src/main/java/world/bentobox/bentobox/panels/BlueprintManagementPanel.java index 304ae8c79..7ee686657 100644 --- a/src/main/java/world/bentobox/bentobox/panels/BlueprintManagementPanel.java +++ b/src/main/java/world/bentobox/bentobox/panels/BlueprintManagementPanel.java @@ -257,21 +257,22 @@ public class BlueprintManagementPanel { Material icon; String worldName; switch (env) { - case NORMAL: + case NORMAL -> { icon = Material.GRASS_BLOCK; worldName = normalBlueprint.getName(); - break; - case NETHER: + } + case NETHER -> { icon = Material.NETHERRACK; worldName = netherBlueprint.getName(); - break; - case THE_END: + } + case THE_END -> { icon = Material.END_STONE; worldName = endBlueprint.getName(); - break; - default: + } + default -> { icon = Material.STONE; worldName = Util.prettifyText(env.name()); + } } return new PanelItemBuilder() diff --git a/src/main/java/world/bentobox/bentobox/panels/LanguagePanel.java b/src/main/java/world/bentobox/bentobox/panels/LanguagePanel.java index cf4c2e830..ca2e96ef0 100644 --- a/src/main/java/world/bentobox/bentobox/panels/LanguagePanel.java +++ b/src/main/java/world/bentobox/bentobox/panels/LanguagePanel.java @@ -1,6 +1,7 @@ package world.bentobox.bentobox.panels; import java.util.Locale; +import java.util.Objects; import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; @@ -38,11 +39,8 @@ public class LanguagePanel { BentoBoxLocale language = localesManager.getLanguages().get(locale); ItemStack localeBanner = language.getBanner(); - if (localeBanner != null) { - localeIcon.icon(localeBanner); - } else { - localeIcon.icon(new ItemStack(Material.WHITE_BANNER, 1)); // Set to a blank banner. - } + // Set to a blank banner. + localeIcon.icon(Objects.requireNonNullElseGet(localeBanner, () -> new ItemStack(Material.WHITE_BANNER, 1))); localeIcon.name(ChatColor.WHITE + WordUtils.capitalize(locale.getDisplayName(user.getLocale()))) .clickHandler((panel, u, click, slot) -> { BentoBox.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag()); diff --git a/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java b/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java index b1f5a0e6e..3c6293c6a 100644 --- a/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java +++ b/src/main/java/world/bentobox/bentobox/panels/ManagementPanel.java @@ -53,86 +53,86 @@ public class ManagementPanel { int i = 0; List addons; switch (view) { - case GAMEMODES: - addons = plugin.getAddonsManager().getGameModeAddons(); - if (addons.isEmpty()) { - looksEmpty(builder, user); - break; - } - for (Addon addon : addons) { - GameModeAddon gameModeAddon = (GameModeAddon) addon; - PanelItem addonItem = new PanelItemBuilder() - .icon(addon.getDescription().getIcon()) - .name(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.name", TextVariables.NAME, addon.getDescription().getName())) - .description(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.description", - "[islands]", String.valueOf(addon.getIslands().getIslandCount(gameModeAddon.getOverWorld())))) - .clickHandler((panel, user1, clickType, slot) -> { - if (clickType.equals(ClickType.MIDDLE)) { - CreditsPanel.openPanel(user, addon); - } - return true; - }) - .build(); + case GAMEMODES -> { + addons = plugin.getAddonsManager().getGameModeAddons(); + if (addons.isEmpty()) { + looksEmpty(builder, user); + break; + } + for (Addon addon : addons) { + GameModeAddon gameModeAddon = (GameModeAddon) addon; + PanelItem addonItem = new PanelItemBuilder() + .icon(addon.getDescription().getIcon()) + .name(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.name", TextVariables.NAME, addon.getDescription().getName())) + .description(user.getTranslation(LOCALE_REF + "views.gamemodes.gamemode.description", + "[islands]", String.valueOf(addon.getIslands().getIslandCount(gameModeAddon.getOverWorld())))) + .clickHandler((panel, user1, clickType, slot) -> { + if (clickType.equals(ClickType.MIDDLE)) { + CreditsPanel.openPanel(user, addon); + } + return true; + }) + .build(); - builder.item(startSlot + i, addonItem); + builder.item(startSlot + i, addonItem); - PanelItem blueprints = new PanelItemBuilder() - .icon(Material.STRUCTURE_BLOCK) - .name(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.name")) - .description(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.description")) - .clickHandler((panel, user1, clickType, slot) -> { - new BlueprintManagementPanel(plugin, user, gameModeAddon).openPanel(); - return true; - }) - .build(); + PanelItem blueprints = new PanelItemBuilder() + .icon(Material.STRUCTURE_BLOCK) + .name(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.name")) + .description(user.getTranslation(LOCALE_REF + "views.gamemodes.blueprints.description")) + .clickHandler((panel, user1, clickType, slot) -> { + new BlueprintManagementPanel(plugin, user, gameModeAddon).openPanel(); + return true; + }) + .build(); - builder.item(startSlot + i + 9, blueprints); - i++; - } - break; - case ADDONS: - addons = plugin.getAddonsManager().getEnabledAddons().stream().filter(addon -> !(addon instanceof GameModeAddon)).collect(Collectors.toList()); - if (addons.isEmpty()) { - looksEmpty(builder, user); - break; - } - for (Addon addon : addons) { - PanelItem addonItem = new PanelItemBuilder() - .icon(addon.getDescription().getIcon()) - .name(ChatColor.WHITE + addon.getDescription().getName()) - .clickHandler((panel, user1, clickType, slot) -> { - if (clickType.equals(ClickType.MIDDLE)) { - CreditsPanel.openPanel(user, addon); - } - return true; - }) - .build(); - - builder.item(startSlot + i, addonItem); - i++; - if (builder.slotOccupied(startSlot + i)) { - i = i+2; + builder.item(startSlot + i + 9, blueprints); + i++; } } - break; - case HOOKS: - if (plugin.getHooks().getHooks().isEmpty()) { - looksEmpty(builder, user); - break; - } - for (Hook hook : plugin.getHooks().getHooks()) { - PanelItem hookItem = new PanelItemBuilder() - .icon(hook.getIcon()) - .name(ChatColor.WHITE + hook.getPluginName()) - .build(); + case ADDONS -> { + addons = plugin.getAddonsManager().getEnabledAddons().stream().filter(addon -> !(addon instanceof GameModeAddon)).collect(Collectors.toList()); + if (addons.isEmpty()) { + looksEmpty(builder, user); + break; + } + for (Addon addon : addons) { + PanelItem addonItem = new PanelItemBuilder() + .icon(addon.getDescription().getIcon()) + .name(ChatColor.WHITE + addon.getDescription().getName()) + .clickHandler((panel, user1, clickType, slot) -> { + if (clickType.equals(ClickType.MIDDLE)) { + CreditsPanel.openPanel(user, addon); + } + return true; + }) + .build(); - builder.item(startSlot + i, hookItem); - i++; - if (builder.slotOccupied(startSlot + i)) { - i = i+2; + builder.item(startSlot + i, addonItem); + i++; + if (builder.slotOccupied(startSlot + i)) { + i = i + 2; + } + } + } + case HOOKS -> { + if (plugin.getHooks().getHooks().isEmpty()) { + looksEmpty(builder, user); + break; + } + for (Hook hook : plugin.getHooks().getHooks()) { + PanelItem hookItem = new PanelItemBuilder() + .icon(hook.getIcon()) + .name(ChatColor.WHITE + hook.getPluginName()) + .build(); + + builder.item(startSlot + i, hookItem); + i++; + if (builder.slotOccupied(startSlot + i)) { + i = i + 2; + } } } - break; } // Setup a few more buttons @@ -196,15 +196,9 @@ public class ManagementPanel { }); switch (view) { - case GAMEMODES: - gamemodesIconBuilder.glow(true); - break; - case ADDONS: - addonsIconBuilder.glow(true); - break; - case HOOKS: - hooksIconBuilder.glow(true); - break; + case GAMEMODES -> gamemodesIconBuilder.glow(true); + case ADDONS -> addonsIconBuilder.glow(true); + case HOOKS -> hooksIconBuilder.glow(true); } builder.item(1, gamemodesIconBuilder.build()); @@ -235,16 +229,9 @@ public class ManagementPanel { TextVariables.VERSION, serverVersion != null ? serverVersion.toString() : user.getTranslation("general.invalid"))); switch (compatibility) { - case COMPATIBLE: - case SUPPORTED: - compatibilityItemBuilder.icon(Material.GREEN_CONCRETE); - break; - case NOT_SUPPORTED: - compatibilityItemBuilder.icon(Material.ORANGE_CONCRETE); - break; - case INCOMPATIBLE: - compatibilityItemBuilder.icon(Material.RED_CONCRETE); - break; + case COMPATIBLE, SUPPORTED -> compatibilityItemBuilder.icon(Material.GREEN_CONCRETE); + case NOT_SUPPORTED -> compatibilityItemBuilder.icon(Material.ORANGE_CONCRETE); + case INCOMPATIBLE -> compatibilityItemBuilder.icon(Material.RED_CONCRETE); } builder.item(7, compatibilityItemBuilder.build()); diff --git a/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java b/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java index 9e9e2d97c..cc3dcbcd7 100644 --- a/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java +++ b/src/main/java/world/bentobox/bentobox/panels/settings/SettingsTab.java @@ -135,27 +135,22 @@ public class SettingsTab implements Tab, ClickHandler { icons.put(5, Flags.LOCK.toPanelItem(plugin, user, island, false)); } // Add the mode icon - switch(plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId())) { - case ADVANCED: - icons.put(7, new PanelItemBuilder().icon(Material.GOLD_INGOT) + switch (plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId())) { + case ADVANCED -> icons.put(7, new PanelItemBuilder().icon(Material.GOLD_INGOT) .name(user.getTranslation(PROTECTION_PANEL + "mode.advanced.name")) .description(user.getTranslation(PROTECTION_PANEL + "mode.advanced.description"), "", user.getTranslation(CLICK_TO_SWITCH, TextVariables.NEXT, user.getTranslation(PROTECTION_PANEL + "mode.expert.name"))) .clickHandler(this) .build()); - break; - case EXPERT: - icons.put(7, new PanelItemBuilder().icon(Material.NETHER_BRICK) + case EXPERT -> icons.put(7, new PanelItemBuilder().icon(Material.NETHER_BRICK) .name(user.getTranslation(PROTECTION_PANEL + "mode.expert.name")) .description(user.getTranslation(PROTECTION_PANEL + "mode.expert.description"), "", user.getTranslation(CLICK_TO_SWITCH, TextVariables.NEXT, user.getTranslation(PROTECTION_PANEL + "mode.basic.name"))) .clickHandler(this) .build()); - break; - default: - icons.put(7, new PanelItemBuilder().icon(Material.IRON_INGOT) + default -> icons.put(7, new PanelItemBuilder().icon(Material.IRON_INGOT) .name(user.getTranslation(PROTECTION_PANEL + "mode.basic.name")) .description(user.getTranslation(PROTECTION_PANEL + "mode.basic.description"), "", user.getTranslation(CLICK_TO_SWITCH, @@ -219,8 +214,7 @@ public class SettingsTab implements Tab, ClickHandler { public boolean onClick(Panel panel, User user, ClickType clickType, int slot) { // Cycle the mode plugin.getPlayers().setFlagsDisplayMode(user.getUniqueId(), plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId()).getNext()); - if (panel instanceof TabbedPanel) { - TabbedPanel tp = ((TabbedPanel)panel); + if (panel instanceof TabbedPanel tp) { tp.setActivePage(0); tp.refreshPanel(); user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 1F, 1F); diff --git a/src/main/java/world/bentobox/bentobox/util/Pair.java b/src/main/java/world/bentobox/bentobox/util/Pair.java index 775c5f111..d2109480a 100644 --- a/src/main/java/world/bentobox/bentobox/util/Pair.java +++ b/src/main/java/world/bentobox/bentobox/util/Pair.java @@ -67,10 +67,9 @@ public class Pair { if (obj == null) { return false; } - if (!(obj instanceof Pair)) { + if (!(obj instanceof Pair other)) { return false; } - Pair other = (Pair) obj; if (x == null) { if (other.x != null) { return false; diff --git a/src/main/java/world/bentobox/bentobox/util/Util.java b/src/main/java/world/bentobox/bentobox/util/Util.java index 82eda60b5..83e3a5768 100644 --- a/src/main/java/world/bentobox/bentobox/util/Util.java +++ b/src/main/java/world/bentobox/bentobox/util/Util.java @@ -278,38 +278,23 @@ public class Util { * @return degrees */ public static float blockFaceToFloat(BlockFace face) { - switch (face) { - case EAST: - return 90F; - case EAST_NORTH_EAST: - return 67.5F; - case NORTH_EAST: - return 45F; - case NORTH_NORTH_EAST: - return 22.5F; - case NORTH_NORTH_WEST: - return 337.5F; - case NORTH_WEST: - return 315F; - case SOUTH: - return 180F; - case SOUTH_EAST: - return 135F; - case SOUTH_SOUTH_EAST: - return 157.5F; - case SOUTH_SOUTH_WEST: - return 202.5F; - case SOUTH_WEST: - return 225F; - case WEST: - return 270F; - case WEST_NORTH_WEST: - return 292.5F; - case WEST_SOUTH_WEST: - return 247.5F; - default: - return 0F; - } + return switch (face) { + case EAST -> 90F; + case EAST_NORTH_EAST -> 67.5F; + case NORTH_EAST -> 45F; + case NORTH_NORTH_EAST -> 22.5F; + case NORTH_NORTH_WEST -> 337.5F; + case NORTH_WEST -> 315F; + case SOUTH -> 180F; + case SOUTH_EAST -> 135F; + case SOUTH_SOUTH_EAST -> 157.5F; + case SOUTH_SOUTH_WEST -> 202.5F; + case SOUTH_WEST -> 225F; + case WEST -> 270F; + case WEST_NORTH_WEST -> 292.5F; + case WEST_SOUTH_WEST -> 247.5F; + default -> 0F; + }; } /**