From dd4b01f922bcb4e2c73febd2b7d829e8d759b8c6 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:07:25 +0800 Subject: [PATCH] Fix a lot of checkstyles throughout --- config/mv_checks.xml | 7 ++- .../MultiverseCore/MultiverseCore.java | 11 ++-- .../commands/GamerulesCommand.java | 4 +- .../config/MVCoreConfigNodes.java | 52 +++++++++++------- .../handle/CommentedYamlConfigHandle.java | 22 ++++++-- .../handle/ConfigurationSectionHandle.java | 6 +++ .../destination/DestinationsProvider.java | 38 ++++++------- .../destination/core/AnchorDestination.java | 5 +- .../core/AnchorDestinationInstance.java | 5 +- .../destination/core/BedDestination.java | 7 ++- .../core/BedDestinationInstance.java | 5 +- .../destination/core/CannonDestination.java | 5 +- .../core/CannonDestinationInstance.java | 5 +- .../destination/core/ExactDestination.java | 3 ++ .../core/ExactDestinationInstance.java | 5 +- .../destination/core/PlayerDestination.java | 5 +- .../core/PlayerDestinationInstance.java | 5 +- .../destination/core/WorldDestination.java | 5 +- .../core/WorldDestinationInstance.java | 9 +++- .../display/ContentDisplay.java | 2 +- .../display/filters/DefaultContentFilter.java | 9 +++- .../display/filters/RegexContentFilter.java | 19 ++++++- .../display/handlers/BaseSendHandler.java | 22 ++++++-- .../display/handlers/DefaultSendHandler.java | 10 +++- .../display/handlers/InlineSendHandler.java | 2 +- .../display/handlers/PagedSendHandler.java | 4 +- .../display/parsers/ContentProvider.java | 1 + .../display/parsers/ListContentProvider.java | 2 +- .../display/parsers/MapContentProvider.java | 2 +- .../MultiverseCore/economy/ItemEconomy.java | 1 + .../MultiverseCore/economy/MVEconomist.java | 2 +- .../MultiverseCore/economy/VaultHandler.java | 11 ++-- .../inject/PluginInjection.java | 22 +++----- .../listeners/MVChatListener.java | 7 ++- .../listeners/MVEntityListener.java | 11 ++-- .../listeners/MVPlayerListener.java | 8 +-- .../listeners/MVPortalListener.java | 3 +- .../listeners/MVWeatherListener.java | 8 +-- .../listeners/MVWorldListener.java | 2 +- .../utils/webpaste/GitHubPasteService.java | 7 +-- .../configuration/AllowedPortalType.java | 7 +++ .../worldnew/MultiverseWorld.java | 53 ++++++++++++++++++- 42 files changed, 299 insertions(+), 120 deletions(-) diff --git a/config/mv_checks.xml b/config/mv_checks.xml index 6f3d42b3..d72dacdb 100644 --- a/config/mv_checks.xml +++ b/config/mv_checks.xml @@ -134,7 +134,7 @@ - + @@ -161,6 +161,8 @@ + + @@ -381,7 +383,7 @@ - + @@ -404,6 +406,7 @@ RECORD_COMPONENT_DEF"/> + diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 61a158e7..b832f7c9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -84,12 +84,16 @@ public class MultiverseCore extends JavaPlugin implements MVCore { @Override public void onLoad() { - // Create our DataFolder - getDataFolder().mkdirs(); - // Setup our Logging Logging.init(this); + // Create our DataFolder + if (!getDataFolder().exists() && !getDataFolder().mkdirs()) { + Logging.severe("Failed to create data folder!"); + getServer().getPluginManager().disablePlugin(this); + return; + } + // Register our config classes SerializationConfig.registerAll(WorldProperties.class); SerializationConfig.initLogging(Logging.getLogger()); @@ -373,6 +377,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore { * * @param contractOrImpl The contract or concrete implementation to get the best instance of * @param qualifiers The set of qualifiers that must match this service definition + * @param The type of the contract to get * @return An instance of the contract or impl if it is a service and is already instantiated, null otherwise * @throws MultiException if there was an error during service lookup */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java index 71088d17..4ce44ae4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java @@ -91,10 +91,10 @@ public class GamerulesCommand extends MultiverseCommand { ParsedCommandFlags parsedFlags = parseFlags(flags); ContentDisplay.create() - .addContent(new MapContentProvider<>(getGameRuleMap(world.getBukkitWorld().getOrNull())) // TODO: Handle null + .addContent(MapContentProvider.forContent(getGameRuleMap(world.getBukkitWorld().getOrNull())) // TODO: Handle null .withKeyColor(ChatColor.AQUA) .withValueColor(ChatColor.WHITE)) - .withSendHandler(new PagedSendHandler() + .withSendHandler(PagedSendHandler.create() .withHeader(this.getTitle(issuer, world.getBukkitWorld().getOrNull())) .doPagination(true) .withTargetPage(parsedFlags.flagValue(PAGE_FLAG, 1)) diff --git a/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigNodes.java b/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigNodes.java index 8711d55a..9893a588 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigNodes.java +++ b/src/main/java/com/onarandombox/MultiverseCore/config/MVCoreConfigNodes.java @@ -28,6 +28,13 @@ class MVCoreConfigNodes { return node; } + // BEGIN CHECKSTYLE-SUPPRESSION: Javadoc + // BEGIN CHECKSTYLE-SUPPRESSION: MemberName + // BEGIN CHECKSTYLE-SUPPRESSION: Abbreviation + // BEGIN CHECKSTYLE-SUPPRESSION: VisibilityModifier + // BEGIN CHECKSTYLE-SUPPRESSION: MultipleStringLiterals + // BEGIN CHECKSTYLE-SUPPRESSION: LineLength + // TODO: hacky way to get the header to the top of the file private final ConfigHeaderNode HEADER = node(ConfigHeaderNode.builder("world") .comment("####################################################################################################") @@ -53,12 +60,12 @@ class MVCoreConfigNodes { .comment("") .build()); -// private final ConfigHeaderNode WORLD_HEADER = node(ConfigHeaderNode.builder("world") -// .comment("") -// .comment("") -// .build()); + //private final ConfigHeaderNode WORLD_HEADER = node(ConfigHeaderNode.builder("world") + // .comment("") + // .comment("") + // .build()); - public final ConfigNode ENFORCE_ACCESS = node(ConfigNode.builder("world.enforce-access", Boolean.class) + final ConfigNode ENFORCE_ACCESS = node(ConfigNode.builder("world.enforce-access", Boolean.class) .comment("This setting will prevent players from entering worlds they don't have access to.") .comment("If this is set to false, players will be able to enter any world they want.") .comment("If this is set to true, players will only be able to enter worlds they have") @@ -67,7 +74,7 @@ class MVCoreConfigNodes { .name("enforce-access") .build()); - public final ConfigNode ENFORCE_GAMEMODE = node(ConfigNode.builder("world.enforce-gamemode", Boolean.class) + final ConfigNode ENFORCE_GAMEMODE = node(ConfigNode.builder("world.enforce-gamemode", Boolean.class) .comment("") .comment("Sets whether Multiverse will should enforce gamemode on world change.") .comment("If enabled, players will be forced into the gamemode of the world they are entering, unless they have") @@ -76,14 +83,14 @@ class MVCoreConfigNodes { .name("enforce-gamemode") .build()); - public final ConfigNode AUTO_PURGE_ENTITIES = node(ConfigNode.builder("world.auto-purge-entities", Boolean.class) + final ConfigNode AUTO_PURGE_ENTITIES = node(ConfigNode.builder("world.auto-purge-entities", Boolean.class) .comment("") .comment("Sets whether Multiverse will purge mobs and entities with be automatically.") .defaultValue(false) .name("auto-purge-entities") .build()); - public final ConfigNode TELEPORT_INTERCEPT = node(ConfigNode.builder("world.teleport-intercept", Boolean.class) + final ConfigNode TELEPORT_INTERCEPT = node(ConfigNode.builder("world.teleport-intercept", Boolean.class) .comment("") .comment("If this is set to true, Multiverse will enforce access permissions for all teleportation,") .comment("including teleportation from other plugins.") @@ -96,7 +103,7 @@ class MVCoreConfigNodes { .comment("") .build()); - public final ConfigNode FIRST_SPAWN_OVERRIDE = node(ConfigNode.builder("spawn.first-spawn-override", Boolean.class) + final ConfigNode FIRST_SPAWN_OVERRIDE = node(ConfigNode.builder("spawn.first-spawn-override", Boolean.class) .comment("Sets whether Multiverse will override the first spawn location of a world.") .comment("If enabled, Multiverse will set the first spawn location of a world to the spawn location of the world.") .comment("If disabled, it will default to server.properties settings.") @@ -104,7 +111,7 @@ class MVCoreConfigNodes { .name("first-spawn-override") .build()); - public final ConfigNode FIRST_SPAWN_LOCATION = node(ConfigNode.builder("spawn.first-spawn-location", String.class) + final ConfigNode FIRST_SPAWN_LOCATION = node(ConfigNode.builder("spawn.first-spawn-location", String.class) .comment("") .comment("Sets the world that Multiverse will use as the location for players that first join the server.") .comment("This only applies if first-spawn-override is set to true.") @@ -117,14 +124,14 @@ class MVCoreConfigNodes { .comment("") .build()); - public final ConfigNode USE_CUSTOM_PORTAL_SEARCH = node(ConfigNode.builder("portal.use-custom-portal-search", Boolean.class) + final ConfigNode USE_CUSTOM_PORTAL_SEARCH = node(ConfigNode.builder("portal.use-custom-portal-search", Boolean.class) .comment("This config option defines whether or not Multiverse should interfere with's Bukkit's default portal search radius.") .comment("Setting it to false would mean you want to simply let Bukkit decides the search radius itself.") .defaultValue(false) .name("use-custom-portal-search") .build()); - public final ConfigNode CUSTOM_PORTAL_SEARCH_RADIUS = node(ConfigNode.builder("portal.custom-portal-search-radius", Integer.class) + final ConfigNode CUSTOM_PORTAL_SEARCH_RADIUS = node(ConfigNode.builder("portal.custom-portal-search-radius", Integer.class) .comment("") .comment("This config option defines the search radius Multiverse should use when searching for a portal.") .comment("This only applies if use-custom-portal-search is set to true.") @@ -140,14 +147,14 @@ class MVCoreConfigNodes { .comment("") .build()); - public final ConfigNode ENABLE_CHAT_PREFIX = node(ConfigNode.builder("messaging.enable-chat-prefix", Boolean.class) + final ConfigNode ENABLE_CHAT_PREFIX = node(ConfigNode.builder("messaging.enable-chat-prefix", Boolean.class) .comment("This config option defines whether or not Multiverse should prefix the chat with the world name.") .comment("This only applies if use-custom-portal-search is set to true.") .defaultValue(false) .name("enable-chat-prefix") .build()); - public final ConfigNode CHAT_PREFIX_FORMAT = node(ConfigNode.builder("messaging.chat-prefix-format", String.class) + final ConfigNode CHAT_PREFIX_FORMAT = node(ConfigNode.builder("messaging.chat-prefix-format", String.class) .comment("") .comment("This config option defines the format Multiverse should use when prefixing the chat with the world name.") .comment("This only applies if enable-chat-prefix is set to true.") @@ -155,7 +162,7 @@ class MVCoreConfigNodes { .name("chat-prefix-format") .build()); - public final ConfigNode REGISTER_PAPI_HOOK = node(ConfigNode.builder("messaging.register-papi-hook", Boolean.class) + final ConfigNode REGISTER_PAPI_HOOK = node(ConfigNode.builder("messaging.register-papi-hook", Boolean.class) .comment("") .comment("This config option defines whether or not Multiverse should register the PlaceholderAPI hook.") .comment("This only applies if PlaceholderAPI is installed.") @@ -168,7 +175,7 @@ class MVCoreConfigNodes { .comment("") .build()); - public final ConfigNode GLOBAL_DEBUG = node(ConfigNode.builder("misc.global-debug", Integer.class) + final ConfigNode GLOBAL_DEBUG = node(ConfigNode.builder("misc.global-debug", Integer.class) .comment("This is our debug flag to help identify issues with Multiverse.") .comment("If you are having issues with Multiverse, please set this to 3 and then post your log to pastebin.com") .comment("Otherwise, there's no need to touch this. If not instructed by a wiki page or developer.") @@ -190,7 +197,7 @@ class MVCoreConfigNodes { }) .build()); - public final ConfigNode SILENT_START = node(ConfigNode.builder("misc.silent-start", Boolean.class) + final ConfigNode SILENT_START = node(ConfigNode.builder("misc.silent-start", Boolean.class) .comment("") .comment("If true, the startup console messages will no longer show.") .defaultValue(false) @@ -198,14 +205,14 @@ class MVCoreConfigNodes { .onSetValue((oldValue, newValue) -> Logging.setShowingConfig(!newValue)) .build()); - public final ConfigNode SHOW_DONATION_MESSAGE = node(ConfigNode.builder("misc.show-donation-message", Boolean.class) + final ConfigNode SHOW_DONATION_MESSAGE = node(ConfigNode.builder("misc.show-donation-message", Boolean.class) .comment("") .comment("If you don't want to donate, you can set this to false and Multiverse will stop nagging you.") .defaultValue(true) .name("show-donation-message") .build()); - public final ConfigNode VERSION = node(ConfigNode.builder("version", Double.class) + final ConfigNode VERSION = node(ConfigNode.builder("version", Double.class) .comment("") .comment("") .comment("This just signifies the version number so we can see what version of config you have.") @@ -213,4 +220,11 @@ class MVCoreConfigNodes { .defaultValue(MVCoreConfig.CONFIG_VERSION) .name(null) .build()); + + // END CHECKSTYLE-SUPPRESSION: Javadoc + // END CHECKSTYLE-SUPPRESSION: MemberName + // END CHECKSTYLE-SUPPRESSION: Abbreviation + // END CHECKSTYLE-SUPPRESSION: VisibilityModifier + // END CHECKSTYLE-SUPPRESSION: MultipleStringLiterals + // END CHECKSTYLE-SUPPRESSION: LineLength } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/CommentedYamlConfigHandle.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/CommentedYamlConfigHandle.java index 04b989e1..23208c8d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/CommentedYamlConfigHandle.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/CommentedYamlConfigHandle.java @@ -29,7 +29,11 @@ public class CommentedYamlConfigHandle extends FileConfigHandle { - Logging.warning("Failed to set node " + valueNode.getPath() + " to " + valueNode.getDefaultValue()); - setDefault(valueNode); - }); + //noinspection unchecked + set(valueNode, oldConfig.getObject( + valueNode.getPath(), + valueNode.getType(), + valueNode.getDefaultValue())).onFailure(e -> { + Logging.warning("Failed to set node " + valueNode.getPath() + + " to " + valueNode.getDefaultValue()); + setDefault(valueNode); + }); } }); } @@ -81,6 +90,9 @@ public class CommentedYamlConfigHandle extends FileConfigHandle config.save()); } + /** + * Builder for {@link CommentedYamlConfigHandle}. + */ public static class Builder extends FileConfigHandle.Builder { protected Builder(@NotNull Path configPath) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/ConfigurationSectionHandle.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/ConfigurationSectionHandle.java index 6a3bf1b4..7e7aeeef 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/ConfigurationSectionHandle.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/handle/ConfigurationSectionHandle.java @@ -13,6 +13,12 @@ import java.util.logging.Logger; * Configuration handle for a single configuration section. */ public class ConfigurationSectionHandle extends GenericConfigHandle { + /** + * Creates a new builder for a {@link ConfigurationSectionHandle}. + * + * @param configurationSection The configuration section. + * @return The builder. + */ public static Builder builder(@NotNull ConfigurationSection configurationSection) { return new Builder<>(configurationSection); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java index a430f537..0b043019 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java @@ -31,16 +31,13 @@ public class DestinationsProvider { private static final String PERMISSION_PREFIX = "multiverse.teleport."; private final PluginManager pluginManager; - private final SafeTTeleporter safeTTeleporter; + private final SafeTTeleporter safetyTeleporter; private final Map> destinationMap; - /** - * Creates a new destinations provider. - */ @Inject - public DestinationsProvider(@NotNull PluginManager pluginManager, @NotNull SafeTTeleporter safeTTeleporter) { + DestinationsProvider(@NotNull PluginManager pluginManager, @NotNull SafeTTeleporter safetyTeleporter) { this.pluginManager = pluginManager; - this.safeTTeleporter = safeTTeleporter; + this.safetyTeleporter = safetyTeleporter; this.destinationMap = new HashMap<>(); } @@ -66,9 +63,9 @@ public class DestinationsProvider { * @param deststring The current destination string. * @return A collection of tab completions. */ - public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, - @Nullable String deststring - ) { + public @NotNull Collection suggestDestinations( + @NotNull BukkitCommandIssuer issuer, + @Nullable String deststring) { return destinationMap.values().stream() .filter(destination -> issuer.hasPermission(PERMISSION_PREFIX + "self." + destination.getIdentifier()) || issuer.hasPermission(PERMISSION_PREFIX + "other." + destination.getIdentifier())) @@ -129,11 +126,12 @@ public class DestinationsProvider { * @param teleporter The teleporter. * @param teleportee The teleportee. * @param destination The destination. + * @return The async teleport result. */ - public CompletableFuture playerTeleportAsync(@NotNull BukkitCommandIssuer teleporter, - @NotNull Player teleportee, - @NotNull ParsedDestination destination - ) { + public CompletableFuture playerTeleportAsync( + @NotNull BukkitCommandIssuer teleporter, + @NotNull Player teleportee, + @NotNull ParsedDestination destination) { if (!checkTeleportPermissions(teleporter, teleportee, destination)) { return CompletableFuture.completedFuture(TeleportResult.FAIL_PERMISSION); } @@ -146,14 +144,15 @@ public class DestinationsProvider { * @param teleporter The teleporter. * @param teleportee The teleportee. * @param destination The destination. + * @return The async teleport result. */ - public CompletableFuture teleportAsync(@NotNull BukkitCommandIssuer teleporter, - @NotNull Entity teleportee, - @NotNull ParsedDestination destination - ) { + public CompletableFuture teleportAsync( + @NotNull BukkitCommandIssuer teleporter, + @NotNull Entity teleportee, + @NotNull ParsedDestination destination) { Teleporter teleportHandler = destination.getDestination().getTeleporter(); if (teleportHandler == null) { - teleportHandler = safeTTeleporter; + teleportHandler = safetyTeleporter; } return teleportHandler.teleportAsync(teleporter, teleportee, destination); } @@ -166,7 +165,8 @@ public class DestinationsProvider { * @param destination The destination. * @return True if the teleporter has permission, false otherwise. */ - public boolean checkTeleportPermissions(CommandIssuer teleporter, Entity teleportee, ParsedDestination destination) { + public boolean checkTeleportPermissions( + CommandIssuer teleporter, Entity teleportee, ParsedDestination destination) { // TODO: Move permission checking to a separate class String permission = PERMISSION_PREFIX + (teleportee.equals(teleporter.getIssuer()) ? "self" : "other") + "." diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java index 273f7571..82a5645c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java @@ -12,13 +12,16 @@ import org.jvnet.hk2.annotations.Service; import java.util.Collection; +/** + * {@link Destination} implementation for anchors. + */ @Service public class AnchorDestination implements Destination { private final AnchorManager anchorManager; @Inject - public AnchorDestination(AnchorManager anchorManager) { + AnchorDestination(AnchorManager anchorManager) { this.anchorManager = anchorManager; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java index f0cc0bbd..ebcdb3a3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java @@ -7,6 +7,9 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Destination instance implementation for the {@link AnchorDestination}. + */ public class AnchorDestinationInstance implements DestinationInstance { private final String anchorName; private final Location anchorLocation; @@ -17,7 +20,7 @@ public class AnchorDestinationInstance implements DestinationInstance { * @param anchorName The name of the anchor. * @param anchorLocation The location of the anchor. */ - public AnchorDestinationInstance(@NotNull String anchorName, @NotNull Location anchorLocation) { + AnchorDestinationInstance(@NotNull String anchorName, @NotNull Location anchorLocation) { this.anchorName = anchorName; this.anchorLocation = anchorLocation; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java index abb33afc..26a5a714 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java @@ -14,11 +14,14 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +/** + * {@link Destination} implementation for beds. + */ @Service public class BedDestination implements Destination { - public static final String OWN_BED_STRING = "playerbed"; + static final String OWN_BED_STRING = "playerbed"; - public BedDestination() { + BedDestination() { } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java index 8e7c0edb..edfea1dc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java @@ -8,6 +8,9 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Destination instance implementation for the {@link BedDestination}. + */ public class BedDestinationInstance implements DestinationInstance { private final Player player; @@ -16,7 +19,7 @@ public class BedDestinationInstance implements DestinationInstance { * * @param player The player whose bed to use. */ - public BedDestinationInstance(Player player) { + BedDestinationInstance(Player player) { this.player = player; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java index 2648e549..dc365cbb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java @@ -15,13 +15,16 @@ import org.jvnet.hk2.annotations.Service; import java.util.Collection; import java.util.Collections; +/** + * {@link Destination} implementation for cannons. + */ @Service public class CannonDestination implements Destination { private final WorldManager worldManager; @Inject - public CannonDestination(WorldManager worldManager) { + CannonDestination(WorldManager worldManager) { this.worldManager = worldManager; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java index 8ceb8c80..33c55f14 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java @@ -7,6 +7,9 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Destination instance implementation for the {@link CannonDestination}. + */ public class CannonDestinationInstance implements DestinationInstance { private final Location location; private final double speed; @@ -17,7 +20,7 @@ public class CannonDestinationInstance implements DestinationInstance { * @param location The location to teleport to. * @param speed The speed to fire the player at. */ - public CannonDestinationInstance(@NotNull Location location, double speed) { + CannonDestinationInstance(@NotNull Location location, double speed) { this.location = location; this.speed = speed; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java index 7b70ebf7..6430e9e1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java @@ -15,6 +15,9 @@ import org.jvnet.hk2.annotations.Service; import java.util.Collection; import java.util.Collections; +/** + * {@link Destination} implementation for exact locations. + */ @Service public class ExactDestination implements Destination { diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java index e2235829..173122fe 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java @@ -7,6 +7,9 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Destination instance implementation for the {@link ExactDestination}. + */ public class ExactDestinationInstance implements DestinationInstance { private final Location location; @@ -15,7 +18,7 @@ public class ExactDestinationInstance implements DestinationInstance { * * @param location The location to teleport to. */ - public ExactDestinationInstance(Location location) { + ExactDestinationInstance(Location location) { this.location = location; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java index 04deceae..5b2d7fa2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java @@ -13,12 +13,15 @@ import org.jvnet.hk2.annotations.Service; import java.util.Collection; import java.util.stream.Collectors; +/** + * {@link Destination} implementation for players.s + */ @Service public class PlayerDestination implements Destination { /** * Creates a new instance of the PlayerDestination. */ - public PlayerDestination() { + PlayerDestination() { } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java index fc31082f..c72c4962 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java @@ -8,6 +8,9 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Destination instance implementation for the {@link PlayerDestination}. + */ public class PlayerDestinationInstance implements DestinationInstance { private final Player player; @@ -16,7 +19,7 @@ public class PlayerDestinationInstance implements DestinationInstance { * * @param player The player whose location to go to. */ - public PlayerDestinationInstance(Player player) { + PlayerDestinationInstance(Player player) { this.player = player; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java index f9bc48f0..0239668d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java @@ -14,6 +14,9 @@ import org.jvnet.hk2.annotations.Service; import java.util.Collection; import java.util.Collections; +/** + * {@link Destination} implementation for exact locations. + */ @Service public class WorldDestination implements Destination { @@ -21,7 +24,7 @@ public class WorldDestination implements Destination { private final LocationManipulation locationManipulation; @Inject - public WorldDestination(WorldManager worldManager, LocationManipulation locationManipulation) { + WorldDestination(WorldManager worldManager, LocationManipulation locationManipulation) { this.worldManager = worldManager; this.locationManipulation = locationManipulation; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java index e4d47c5b..18d92fe6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java @@ -8,6 +8,9 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Destination instance implementation for the {@link WorldDestination}. + */ public class WorldDestinationInstance implements DestinationInstance { private final LoadedMultiverseWorld world; private final String direction; @@ -16,9 +19,11 @@ public class WorldDestinationInstance implements DestinationInstance { /** * Constructor. * - * @param world The world to teleport to. + * @param world The world to teleport to. + * @param direction The direction to face. + * @param yaw The yaw to face. */ - public WorldDestinationInstance(@NotNull LoadedMultiverseWorld world, @Nullable String direction, float yaw) { + WorldDestinationInstance(@NotNull LoadedMultiverseWorld world, @Nullable String direction, float yaw) { this.world = world; this.direction = direction; this.yaw = yaw; diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java b/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java index 7122554d..4679ad5b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java @@ -28,7 +28,7 @@ public class ContentDisplay { private final List contentParsers = new ArrayList<>(); private SendHandler sendHandler = DefaultSendHandler.getInstance(); - public ContentDisplay() { + ContentDisplay() { } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java b/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java index 590abe15..c0b51c8e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java @@ -3,10 +3,15 @@ package com.onarandombox.MultiverseCore.display.filters; /** * Default implementation of {@link ContentFilter} that doesn't filter anything. */ -public class DefaultContentFilter implements ContentFilter { +public final class DefaultContentFilter implements ContentFilter { - public static DefaultContentFilter instance; + private static DefaultContentFilter instance; + /** + * Gets the singleton instance of this class. + * + * @return The singleton instance of this class. + */ public static DefaultContentFilter get() { if (instance == null) { instance = new DefaultContentFilter(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java b/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java index 59c17fce..44cd574d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java @@ -18,7 +18,7 @@ public class RegexContentFilter implements ContentFilter { /** * Compile regex pattern to create a regex filter. - * + *
* When prefixed with 'r=', filter string is used as the full regex pattern. * Else, set to regex that contains the filterString. * @@ -40,7 +40,7 @@ public class RegexContentFilter implements ContentFilter { private final String regexString; private Pattern regexPattern; - public RegexContentFilter(@Nullable String regexString) { + RegexContentFilter(@Nullable String regexString) { this.regexString = regexString; convertToPattern(); } @@ -85,14 +85,29 @@ public class RegexContentFilter implements ContentFilter { return hasValidRegex(); } + /** + * Check if the regex is valid. + * + * @return True if the regex is valid. + */ public boolean hasValidRegex() { return regexPattern != null; } + /** + * Get the regex string. + * + * @return The regex string. + */ public String getRegexString() { return regexString; } + /** + * Get the compiled regex pattern. + * + * @return The compiled regex pattern. + */ public Pattern getRegexPattern() { return regexPattern; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java index 82c620c9..5afd56f6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java @@ -18,8 +18,19 @@ import java.util.stream.Collectors; */ public abstract class BaseSendHandler> implements SendHandler { + /** + * Header to be displayed. + */ protected String header = ""; + + /** + * Filter to keep only contents that matches the filter. + */ protected ContentFilter filter = DefaultContentFilter.get(); + + /** + * Fallback message to be displayed when there is no content to display. + */ protected String noContentMessage = String.format("%sThere is no content to display.", ChatColor.RED); /** @@ -75,9 +86,9 @@ public abstract class BaseSendHandler> implements S * @param replacements String formatting replacements. * @return Same {@link T} for method chaining. */ - public T withHeader(@NotNull String header, @NotNull Object...replacements) { + public T withHeader(@NotNull String header, @NotNull Object... replacements) { this.header = String.format(header, replacements); - return (T) this; + return getT(); } /** @@ -88,7 +99,7 @@ public abstract class BaseSendHandler> implements S */ public T withFilter(@NotNull ContentFilter filter) { this.filter = filter; - return (T) this; + return getT(); } /** @@ -99,6 +110,11 @@ public abstract class BaseSendHandler> implements S */ public T noContentMessage(@Nullable String message) { this.noContentMessage = message; + return getT(); + } + + @SuppressWarnings("unchecked") + private @NotNull T getT() { return (T) this; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java index 38258d42..e2230eed 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java @@ -5,10 +5,18 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -public class DefaultSendHandler implements SendHandler { +/** + * Most basic implementation of {@link SendHandler} that just sends content with no formatting. + */ +public final class DefaultSendHandler implements SendHandler { private static DefaultSendHandler instance; + /** + * Gets the singleton instance of this class. + * + * @return The singleton instance of this class. + */ public static DefaultSendHandler getInstance() { if (instance == null) { instance = new DefaultSendHandler(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java index 283d3891..62b06414 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java @@ -23,7 +23,7 @@ public class InlineSendHandler extends BaseSendHandler { private String delimiter = ChatColor.WHITE + ", "; private String prefix = null; - public InlineSendHandler() { + InlineSendHandler() { } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java index c5d27d92..4bb62fa2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java @@ -24,10 +24,10 @@ public class PagedSendHandler extends BaseSendHandler { private boolean paginate = true; private boolean paginateInConsole = false; private boolean padEnd = true; - private int linesPerPage = 8; + private int linesPerPage = 8; // SUPPRESS CHECKSTYLE: MagicNumberCheck private int targetPage = 1; - public PagedSendHandler() { + PagedSendHandler() { } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentProvider.java b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentProvider.java index 628f8851..a86d627c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentProvider.java @@ -14,6 +14,7 @@ public interface ContentProvider { * Parse the object to string(s) and add it to the content. * * @param issuer The target which the content will be displayed to. + * @return The parsed content list. */ Collection parse(@NotNull BukkitCommandIssuer issuer); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentProvider.java b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentProvider.java index caaba140..a2767e27 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentProvider.java @@ -29,7 +29,7 @@ public class ListContentProvider implements ContentProvider { private String format = null; - public ListContentProvider(List list) { + ListContentProvider(List list) { this.list = list; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentProvider.java b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentProvider.java index e8954d35..537493a5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentProvider.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentProvider.java @@ -35,7 +35,7 @@ public class MapContentProvider implements ContentProvider { private ChatColor valueColor = ChatColor.WHITE; private String separator = ": "; - public MapContentProvider(Map map) { + MapContentProvider(Map map) { this.map = map; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/economy/ItemEconomy.java b/src/main/java/com/onarandombox/MultiverseCore/economy/ItemEconomy.java index 31b77dea..1155a526 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/economy/ItemEconomy.java +++ b/src/main/java/com/onarandombox/MultiverseCore/economy/ItemEconomy.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import java.util.HashMap; +// TODO: Make thsi no static class ItemEconomy { private static final String ECONOMY_NAME = "Simple Item Economy"; diff --git a/src/main/java/com/onarandombox/MultiverseCore/economy/MVEconomist.java b/src/main/java/com/onarandombox/MultiverseCore/economy/MVEconomist.java index 832cb031..814b6934 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/economy/MVEconomist.java +++ b/src/main/java/com/onarandombox/MultiverseCore/economy/MVEconomist.java @@ -103,7 +103,7 @@ public class MVEconomist { } /** - * Pays for a given amount of currency either from the player's economy account or inventory if the currency + * Pays for a given amount of currency either from the player's economy account or inventory if the currency. * * @param player the player to take currency from. * @param price the amount to take. diff --git a/src/main/java/com/onarandombox/MultiverseCore/economy/VaultHandler.java b/src/main/java/com/onarandombox/MultiverseCore/economy/VaultHandler.java index d00c3261..a26aaf01 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/economy/VaultHandler.java +++ b/src/main/java/com/onarandombox/MultiverseCore/economy/VaultHandler.java @@ -17,15 +17,16 @@ public class VaultHandler implements Listener { private Economy economy; - public VaultHandler(final Plugin plugin) { + VaultHandler(final Plugin plugin) { Bukkit.getPluginManager().registerEvents(new VaultListener(), plugin); setupVaultEconomy(); } private boolean setupVaultEconomy() { if (Bukkit.getPluginManager().getPlugin("Vault") != null) { - final RegisteredServiceProvider economyProvider = - Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); + final RegisteredServiceProvider economyProvider = Bukkit + .getServicesManager() + .getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { Logging.fine("Vault economy enabled."); economy = economyProvider.getProvider(); @@ -38,7 +39,7 @@ public class VaultHandler implements Listener { economy = null; } - return (economy != null); + return economy != null; } /** @@ -62,7 +63,7 @@ public class VaultHandler implements Listener { /** * Listens for Vault plugin events. */ - private class VaultListener implements Listener { + private final class VaultListener implements Listener { @EventHandler private void vaultEnabled(PluginEnableEvent event) { if (event.getPlugin() != null && event.getPlugin().getName().equals("Vault")) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java b/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java index 638905fe..312acb2b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java +++ b/src/main/java/com/onarandombox/MultiverseCore/inject/PluginInjection.java @@ -30,7 +30,7 @@ public final class PluginInjection { * {@link org.bukkit.plugin.java.JavaPlugin}. * * @param pluginBinder The plugin binder for the plugin. - * @return + * @return A {@link ServiceLocator} for the plugin. */ @NotNull public static Try createServiceLocator(@NotNull PluginBinder pluginBinder) { @@ -74,8 +74,7 @@ public final class PluginInjection { private PluginInjection( @NotNull PluginBinder pluginBinder, @NotNull ServiceLocatorFactory serviceLocatorFactory, - @NotNull ServiceLocator serverServiceLocator - ) { + @NotNull ServiceLocator serverServiceLocator) { this.pluginBinder = pluginBinder; plugin = pluginBinder.getPlugin(); pluginServiceLocator = serviceLocatorFactory.create(plugin.getName(), serverServiceLocator); @@ -89,16 +88,14 @@ public final class PluginInjection { @NotNull private static Try createServerServiceLocator( @NotNull ServiceLocatorFactory serviceLocatorFactory, - @NotNull ServiceLocator systemServiceLocator - ) { + @NotNull ServiceLocator systemServiceLocator) { return Try.of(() -> serviceLocatorFactory.create("server", systemServiceLocator)) .andThenTry(locator -> ServiceLocatorUtilities.bind(locator, new ServerBinder())); } @NotNull private static Try createSystemServiceLocator( - @NotNull ServiceLocatorFactory serviceLocatorFactory - ) { + @NotNull ServiceLocatorFactory serviceLocatorFactory) { ServiceLocator serviceLocator = serviceLocatorFactory.create("system"); return Try.of(() -> serviceLocator.getService(DynamicConfigurationService.class)) @@ -111,15 +108,12 @@ public final class PluginInjection { @NotNull private static Try populatePluginServiceLocator( @NotNull ServiceLocator serviceLocator, - @NotNull Plugin plugin - ) { + @NotNull Plugin plugin) { return Try.of(() -> serviceLocator.getService(DynamicConfigurationService.class)) .mapTry(dynamicConfigurationService -> { - dynamicConfigurationService - .getPopulator() - .populate(new ClasspathDescriptorFileFinder( - plugin.getClass().getClassLoader(), - plugin.getName())); + dynamicConfigurationService.getPopulator().populate(new ClasspathDescriptorFileFinder( + plugin.getClass().getClassLoader(), + plugin.getName())); return serviceLocator; }); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java index 6c750d80..6823765b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java @@ -19,11 +19,10 @@ public class MVChatListener implements InjectableListener { private final MVPlayerListener playerListener; @Inject - public MVChatListener( + MVChatListener( MVCoreConfig config, WorldManager worldManager, - MVPlayerListener playerListener - ) { + MVPlayerListener playerListener) { this.config = config; this.worldManager = worldManager; this.playerListener = playerListener; @@ -52,7 +51,7 @@ public class MVChatListener implements InjectableListener { } String prefix = this.worldManager.getLoadedWorld(world) - .map((mvworld) -> mvworld.isHidden() ? "" : mvworld.getAlias()) + .map(mvworld -> mvworld.isHidden() ? "" : mvworld.getAlias()) .getOrElse(""); String chat = event.getFormat(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index b014d8f8..6a8bea53 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -32,10 +32,9 @@ public class MVEntityListener implements InjectableListener { private final WorldPurger worldPurger; @Inject - public MVEntityListener( + MVEntityListener( @NotNull WorldManager worldManager, - @NotNull WorldPurger worldPurger - ) { + @NotNull WorldPurger worldPurger) { this.worldManager = worldManager; this.worldPurger = worldPurger; } @@ -53,7 +52,7 @@ public class MVEntityListener implements InjectableListener { return; } worldManager.getLoadedWorld(player.getWorld()) - .peek((world) -> { + .peek(world -> { if (!world.getHunger() && event.getFoodLevel() < player.getFoodLevel()) { event.setCancelled(true); } @@ -70,7 +69,7 @@ public class MVEntityListener implements InjectableListener { return; } worldManager.getLoadedWorld(event.getEntity().getWorld()) - .peek((world) -> { + .peek(world -> { if (!world.getAutoHeal()) { event.setCancelled(true); } @@ -96,7 +95,7 @@ public class MVEntityListener implements InjectableListener { } worldManager.getLoadedWorld(event.getEntity().getWorld()) - .peek((world) -> { + .peek(world -> { if (this.worldPurger.shouldWeKillThisCreature(world, event.getEntity())) { Logging.finer("Cancelling Creature Spawn Event for: " + event.getEntity()); event.setCancelled(true); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index e5ccfcfa..c635565b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -68,7 +68,7 @@ public class MVPlayerListener implements InjectableListener { private final Map playerWorld = new ConcurrentHashMap(); @Inject - public MVPlayerListener( + MVPlayerListener( MultiverseCore plugin, MVCoreConfig config, Provider worldManagerProvider, @@ -79,8 +79,7 @@ public class MVPlayerListener implements InjectableListener { WorldEntryCheckerProvider worldEntryCheckerProvider, Provider commandManagerProvider, CorePermissionsChecker permissionsChecker, - DestinationsProvider destinationsProvider - ) { + DestinationsProvider destinationsProvider) { this.plugin = plugin; this.config = config; this.worldManagerProvider = worldManagerProvider; @@ -103,6 +102,8 @@ public class MVPlayerListener implements InjectableListener { } /** + * Gets the map of player and the world name they are in. + * * @return the playerWorld-map */ public Map getPlayerWorld() { @@ -111,6 +112,7 @@ public class MVPlayerListener implements InjectableListener { /** * This method is called when a player respawns. + * * @param event The Event that was fired. */ @EventHandler(priority = EventPriority.LOW) diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java index 1e4650e3..629babef 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java @@ -34,7 +34,7 @@ public class MVPortalListener implements InjectableListener { private final WorldManager worldManager; @Inject - public MVPortalListener(@NotNull MVCoreConfig config, @NotNull WorldManager worldManager) { + MVPortalListener(@NotNull MVCoreConfig config, @NotNull WorldManager worldManager) { this.config = config; this.worldManager = worldManager; } @@ -118,6 +118,7 @@ public class MVPortalListener implements InjectableListener { /** * Handles portal search radius adjustment. + * * @param event The Event that was fired. */ @EventHandler diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java index c4310304..0da82eed 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWeatherListener.java @@ -25,12 +25,13 @@ public class MVWeatherListener implements InjectableListener { private final WorldManager worldManager; @Inject - public MVWeatherListener(WorldManager worldManager) { + MVWeatherListener(WorldManager worldManager) { this.worldManager = worldManager; } /** * This method is called when the weather changes. + * * @param event The Event that was fired. */ @EventHandler @@ -39,7 +40,7 @@ public class MVWeatherListener implements InjectableListener { return; } worldManager.getLoadedWorld(event.getWorld()) - .peek((world) -> { + .peek(world -> { if (!world.getAllowWeather()) { Logging.fine("Cancelling weather for %s as getAllowWeather is false", world.getName()); event.setCancelled(true); @@ -49,6 +50,7 @@ public class MVWeatherListener implements InjectableListener { /** * This method is called when a big storm is going to start. + * * @param event The Event that was fired. */ @EventHandler @@ -57,7 +59,7 @@ public class MVWeatherListener implements InjectableListener { return; } worldManager.getLoadedWorld(event.getWorld()) - .peek((world) -> { + .peek(world -> { if (!world.getAllowWeather()) { Logging.fine("Cancelling thunder for %s as getAllowWeather is false", world.getName()); event.setCancelled(true); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldListener.java index 8e36ca05..55804bd1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVWorldListener.java @@ -29,7 +29,7 @@ public class MVWorldListener implements InjectableListener { private final WorldManager worldManager; @Inject - public MVWorldListener(WorldManager worldManager) { + MVWorldListener(WorldManager worldManager) { this.worldManager = worldManager; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java index e9680183..d17062bd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/GitHubPasteService.java @@ -20,6 +20,7 @@ class GitHubPasteService extends PasteService { GitHubPasteService(boolean isPrivate) { super(GITHUB_POST_REQUEST, ACCESS_TOKEN); this.isPrivate = isPrivate; + //noinspection ConstantValue - this is a placeholder that should be replaced with a real access token if (ACCESS_TOKEN.endsWith("access-token")) { throw new UnsupportedOperationException(); } @@ -60,8 +61,8 @@ class GitHubPasteService extends PasteService { @Override public String postData(String data) throws PasteFailedException { try { - String stringJSON = this.exec(encodeData(data), ContentType.JSON); - return (String) ((JSONObject) new JSONParser().parse(stringJSON)).get("html_url"); + String stringJson = this.exec(encodeData(data), ContentType.JSON); + return (String) ((JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(stringJson)).get("html_url"); } catch (IOException | ParseException e) { throw new PasteFailedException(e); } @@ -74,7 +75,7 @@ class GitHubPasteService extends PasteService { public String postData(Map data) throws PasteFailedException { try { String stringJSON = this.exec(encodeData(data), ContentType.JSON); - return (String) ((JSONObject) new JSONParser().parse(stringJSON)).get("html_url"); + return (String) ((JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(stringJSON)).get("html_url"); } catch (IOException | ParseException e) { throw new PasteFailedException(e); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/world/configuration/AllowedPortalType.java b/src/main/java/com/onarandombox/MultiverseCore/world/configuration/AllowedPortalType.java index 8a3ba778..26dceeb9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/world/configuration/AllowedPortalType.java +++ b/src/main/java/com/onarandombox/MultiverseCore/world/configuration/AllowedPortalType.java @@ -38,12 +38,19 @@ public enum AllowedPortalType { /** * Gets the text. + * * @return The text. */ public PortalType getActualPortalType() { return this.type; } + /** + * Checks if the given portal type is allowed. + * + * @param portalType The portal type. + * @return True if allowed, else false. + */ public boolean isPortalAllowed(PortalType portalType) { return this != NONE && (getActualPortalType() == portalType || this == ALL); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java index 4a7df261..49b817fc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java @@ -19,8 +19,14 @@ import java.util.List; * Represents a world handled by Multiverse which has all the custom properties provided by Multiverse. */ public class MultiverseWorld { - + /** + * This world's name. + */ protected final String worldName; + + /** + * This world's configuration. + */ protected WorldConfig worldConfig; MultiverseWorld(String worldName, WorldConfig worldConfig) { @@ -49,14 +55,33 @@ public class MultiverseWorld { return worldConfig.hasMVWorld(); } + /** + * Gets the properties that can be configured on this world. Can be used for {@link #getProperty(String)} and + * {@link #setProperty(String, Object)}. + * + * @return A collection of property names. + */ public Collection getConfigurablePropertyNames() { return worldConfig.getConfigurablePropertyNames(); } + /** + * Gets a property on this world. + * + * @param name The name of the property. + * @return The value of the property. + */ public Try getProperty(String name) { return worldConfig.getProperty(name); } + /** + * Sets a property on this world. + * + * @param name The name of the property. + * @param value The value of the property. + * @return Result of setting property. + */ public Try setProperty(String name, Object value) { return worldConfig.setProperty(name, value); } @@ -74,6 +99,7 @@ public class MultiverseWorld { * Sets whether or not Multiverse should auto-adjust the spawn for this world. * * @param adjustSpawn True if multiverse should adjust the spawn, false if not. + * @return Result of setting property. */ public Try setAdjustSpawn(boolean adjustSpawn) { return worldConfig.setAdjustSpawn(adjustSpawn); @@ -94,6 +120,7 @@ public class MultiverseWorld { * Sets the alias of the world. * * @param alias A string that is the new alias. + * @return Result of setting property. */ public Try setAlias(String alias) { return worldConfig.setAlias(alias); @@ -112,6 +139,7 @@ public class MultiverseWorld { * Sets whether or not players are allowed to fly in this world. * * @param allowFlight True to allow flight in this world. + * @return Result of setting property. */ public Try setAllowFlight(boolean allowFlight) { return worldConfig.setAllowFlight(allowFlight); @@ -131,6 +159,7 @@ public class MultiverseWorld { * If set to false, Multiverse will disable the weather in the world immediately. * * @param allowWeather True if weather events should occur in a world, false if not. + * @return Result of setting property. */ public Try setAllowWeather(boolean allowWeather) { return worldConfig.setAllowWeather(allowWeather); @@ -149,6 +178,7 @@ public class MultiverseWorld { * Sets whether or not a world will auto-heal players if the difficulty is on peaceful. * * @param autoHeal True if the world will heal. + * @return Result of setting property. */ public Try setAutoHeal(boolean autoHeal) { return worldConfig.setAutoHeal(autoHeal); @@ -169,6 +199,7 @@ public class MultiverseWorld { * True is default. * * @param autoLoad True if multiverse should autoload this world the spawn, false if not. + * @return Result of setting property. */ public Try setAutoLoad(boolean autoLoad) { return worldConfig.setAutoLoad(autoLoad); @@ -191,6 +222,7 @@ public class MultiverseWorld { * True is default. * * @param bedRespawn True if players dying in this world respawn at their bed. + * @return Result of setting property. */ public Try setBedRespawn(boolean bedRespawn) { return worldConfig.setBedRespawn(bedRespawn); @@ -211,6 +243,7 @@ public class MultiverseWorld { * Use a value of null to specify a non-item based currency. * * @param currency The Type of currency that will be used when users enter this world. + * @return Result of setting property. */ public Try setCurrency(Material currency) { return worldConfig.setEntryFeeCurrency(currency); @@ -231,6 +264,7 @@ public class MultiverseWorld { * the name that resides in the Bukkit enum, ex. PEACEFUL * * @param difficulty The new difficulty. + * @return Result of setting property. */ public Try setDifficulty(Difficulty difficulty) { return worldConfig.setDifficulty(difficulty); @@ -258,6 +292,7 @@ public class MultiverseWorld { * Sets the game mode of this world. * * @param gameMode The new {@link GameMode}. + * @return Result of setting property. */ public Try setGameMode(GameMode gameMode) { return worldConfig.setGameMode(gameMode); @@ -287,6 +322,7 @@ public class MultiverseWorld { * access permissions to go to this world. * * @param hidden True if the world should be hidden, false if not. + * @return Result of setting property. */ public Try setHidden(boolean hidden) { return worldConfig.setHidden(hidden); @@ -305,6 +341,7 @@ public class MultiverseWorld { * Sets whether or not the hunger level of players will go down in a world. * * @param hunger True if hunger will go down, false to keep it at the level they entered a world with. + * @return Result of setting property. */ public Try setHunger(boolean hunger) { return worldConfig.setHunger(hunger); @@ -325,6 +362,7 @@ public class MultiverseWorld { * This will not happen immediately. * * @param keepSpawnInMemory If true, CraftBukkit will keep the spawn chunks loaded in memory. + * @return Result of setting property. */ public Try setKeepSpawnInMemory(boolean keepSpawnInMemory) { return worldConfig.setKeepSpawnInMemory(keepSpawnInMemory); @@ -345,6 +383,7 @@ public class MultiverseWorld { * permission node will not be allowed in. A value of -1 or less signifies no limit * * @param playerLimit The new limit + * @return Result of setting property. */ public Try setPlayerLimit(int playerLimit) { return worldConfig.setPlayerLimit(playerLimit); @@ -363,6 +402,7 @@ public class MultiverseWorld { * Sets The types of portals that are allowed in this world. * * @param portalForm The type of portals allowed in this world. + * @return Result of setting property. */ public Try setPortalForm(AllowedPortalType portalForm) { return worldConfig.setPortalForm(portalForm); @@ -383,6 +423,7 @@ public class MultiverseWorld { * The type can be set with {@link #setCurrency(Material)} * * @param price The Amount of money/item to enter the world. + * @return Result of setting property. */ public Try setPrice(double price) { return worldConfig.setEntryFeeAmount(price); @@ -401,6 +442,7 @@ public class MultiverseWorld { * Turn pvp on or off. This setting is used to set the world's PVP mode. * * @param pvp True to enable PVP damage, false to disable it. + * @return Result of setting property. */ public Try setPvp(boolean pvp) { return worldConfig.setPvp(pvp); @@ -429,6 +471,7 @@ public class MultiverseWorld { * Returns true upon success, false upon failure. * * @param respawnWorld The name of a world that exists on the server. + * @return Result of setting property. */ public Try setRespawnWorld(World respawnWorld) { return worldConfig.setRespawnWorld(respawnWorld.getName()); @@ -439,6 +482,7 @@ public class MultiverseWorld { * Returns true upon success, false upon failure. * * @param respawnWorld The name of a world that exists on the server. + * @return Result of setting property. */ public Try setRespawnWorld(MultiverseWorld respawnWorld) { return worldConfig.setRespawnWorld(respawnWorld.getName()); @@ -449,6 +493,7 @@ public class MultiverseWorld { * Returns true upon success, false upon failure. * * @param respawnWorld The name of a world that exists on the server. + * @return Result of setting property. */ public Try setRespawnWorld(String respawnWorld) { return worldConfig.setRespawnWorld(respawnWorld); @@ -464,11 +509,13 @@ public class MultiverseWorld { return worldConfig.getScale(); } + //TODO: we are removing mvnp /** * Sets the scale of this world. Really only has an effect if you use - * Multiverse-NetherPortals. TODO: we are removing mvnp. + * Multiverse-NetherPortals. * * @param scale A scaling value, cannot be negative or 0. + * @return Result of setting property. */ public Try setScale(double scale) { return worldConfig.setScale(scale); @@ -496,6 +543,7 @@ public class MultiverseWorld { * Sets the spawn location for a world. * * @param spawnLocation The spawn location for a world. + * @return Result of setting property. */ public Try setSpawnLocation(Location spawnLocation) { return worldConfig.setSpawnLocation(spawnLocation); @@ -517,6 +565,7 @@ public class MultiverseWorld { * those animals become the exceptions, and will spawn * * @param spawningAnimals True to allow spawning of monsters, false to prevent. + * @return Result of setting property. */ public Try setSpawningAnimals(boolean spawningAnimals) { return worldConfig.setSpawningAnimals(spawningAnimals);