diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/ActivationStrategy.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/ActivationStrategy.java index 078b9a65..6713104d 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/ActivationStrategy.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/ActivationStrategy.java @@ -7,22 +7,22 @@ import org.jetbrains.annotations.NotNull; /** - * Represents the different methods of activating vein miner. + * Represents a different method of activating vein miner. */ public enum ActivationStrategy implements Predicate { /** - * Never activated. Disabled. + * Never activated. */ NONE("None", Predicates.alwaysFalse()), /** - * Activated by the client with a client-sided mod. + * Activated by the client with the client-sided mod. */ CLIENT("Client", VeinMinerPlayer::isClientKeyPressed), /** - * Activated when a player is holding sneak. + * Activated when a player is sneaking. */ SNEAK("Sneak", player -> player.getPlayer().isSneaking()), @@ -45,8 +45,8 @@ private ActivationStrategy(@NotNull String friendlyName, @NotNull Predicate - * This is an internal method. To get an instance of VeinMinerPlayer, the {@link VeinMinerPlayerManager} - * should be used instead. Constructing a new instance of this class may have unintended side-effects - * and will not have accurate information tracked by VeinMiner. + * This is an internal constructor. To get an instance of VeinMinerPlayer, the {@link + * VeinMinerPlayerManager} should be used instead. Constructing a new instance of this class may + * have unintended side-effects and will not have accurate information tracked by VeinMiner. * - * @param player the player + * @param player the player to wrap * @param clientConfig the client configuration * - * @see VeinMinerPlayerManager + * @see VeinMinerPlayerManager#get(Player) */ @Internal public VeinMinerPlayer(@NotNull Player player, @NotNull ClientConfig clientConfig) { @@ -91,9 +91,12 @@ public VeinMinerPlayer(@NotNull Player player, @NotNull ClientConfig clientConfi } /** - * Get the {@link Player} wrapped by this vein miner player. + * Get the wrapped {@link Player}. + *

+ * While this object will never be null, caution should be taken when interacting with this + * object because there is no guarantee that this player will still be online. * - * @return the platform player + * @return the player */ @NotNull public Player getPlayer() { @@ -111,10 +114,10 @@ public UUID getPlayerUUID() { } /** - * Set whether or not the given {@link VeinMinerToolCategory} is enabled. + * Set whether or not the given {@link VeinMinerToolCategory} is enabled for this player. * - * @param category the category to change - * @param enabled whether or not the category is enabled + * @param category the category whose state to update + * @param enabled the enabled state to set * * @return true if the category state was changed, false if the category remains unchanged */ @@ -125,15 +128,11 @@ public boolean setVeinMinerEnabled(@NotNull VeinMinerToolCategory category, bool } /** - * Set whether or not vein miner is enabled entirely. - *

- * If {@code true} and one or more categories are disabled, it will enable all disabled - * categories. If {code false} not all categories have been disabled, it will disable all - * remaining categories. + * Set whether or not vein miner is enabled for all registered categories for this player. * - * @param enabled whether or not to enable vein miner + * @param enabled the enabled state to set * - * @return true if at least one category was changed as a result of the enable toggle + * @return true if at least one category was changed as a result of the change */ public boolean setVeinMinerEnabled(boolean enabled) { boolean changed; @@ -150,9 +149,9 @@ public boolean setVeinMinerEnabled(boolean enabled) { } /** - * Check whether or not the given {@link VeinMinerToolCategory} is enabled. + * Check whether or not this player has the given {@link VeinMinerToolCategory} enabled. * - * @param category the category to check + * @param category the category * * @return true if enabled, false otherwise */ @@ -161,44 +160,45 @@ public boolean isVeinMinerEnabled(@NotNull VeinMinerToolCategory category) { } /** - * Check whether or not vein miner is completely enabled. + * Check whether or not this player has all registered categories enabled. *

* If at least one category is disabled (according to {@link #isVeinMinerEnabled(VeinMinerToolCategory)}), * this method will return {@code false}. * - * @return true if fully enabled, false if at least one category is disabled + * @return true if all categories are enabled, false if at least one category is disabled */ public boolean isVeinMinerEnabled() { return disabledCategories.isEmpty(); } /** - * Check whether or not vein miner is completely disabled. + * Check whether or not this player has all registered categories disabled. *

* If at least one category is enabled (according to {@link #isVeinMinerEnabled(VeinMinerToolCategory)}), * this method will return {@code false}. * - * @return true if fully disabled, false if at least one category is enabled + * @return true if all categories are disabled, false if at least one category is enabled */ public boolean isVeinMinerDisabled() { return disabledCategories.size() >= VeinMinerPlugin.getInstance().getToolCategoryRegistry().size(); } /** - * Check whether or not vein miner has been partially disabled but still has at least - * one category still enabled. + * Check whether or not vein miner has been partially disabled by this player. Vein miner is + * considered partially disabled if one or more category is enabled, but not all categories. + * In other words, there is a mix of both enabled and disabled categories, neither are all the same + * state. * - * @return true if partially disabled, false if all categories are enabled or all - * categories are disabled + * @return true if partially disabled, false if categories are either all enabled or all disabled */ public boolean isVeinMinerPartiallyDisabled() { return !isVeinMinerDisabled() && !isVeinMinerEnabled(); } /** - * Get this player's disabled {@link VeinMinerToolCategory VeinMinerToolCategories}. + * Get an unmodifiable {@link Set} of all categories this player has disabled. * - * @return the disabled tool categories + * @return all disabled tool categories */ @NotNull @UnmodifiableView @@ -207,17 +207,17 @@ public Set getDisabledCategories() { } /** - * Set the {@link ActivationStrategy} to use for this player. + * Set this player's {@link ActivationStrategy}. * - * @param activationStrategy the activation strategy + * @param strategy the new activation strategy */ - public void setActivationStrategy(@NotNull ActivationStrategy activationStrategy) { - this.dirty |= (this.activationStrategy != activationStrategy); - this.activationStrategy = activationStrategy; + public void setActivationStrategy(@NotNull ActivationStrategy strategy) { + this.dirty |= (this.activationStrategy != strategy); + this.activationStrategy = strategy; } /** - * Get the {@link ActivationStrategy} to use for this player. + * Get this player's {@link ActivationStrategy}. * * @return the activation strategy */ @@ -231,35 +231,37 @@ public ActivationStrategy getActivationStrategy() { } /** - * Set the {@link VeinMiningPattern} to use for this player. + * Set this player's active {@link VeinMiningPattern}. * - * @param veinMiningPattern the pattern - * @param updateClient whether or not the client should be informed of this update + * @param pattern the new vein mining pattern + * @param updateClient whether or not the client should be informed of this update. If true and this + * player has the client mod installed ({@link #isUsingClientMod()}, an update packet will be sent + * to the client */ - public void setVeinMiningPattern(@NotNull VeinMiningPattern veinMiningPattern, boolean updateClient) { - boolean changed = !Objects.equals(veinMiningPattern, this.veinMiningPattern); + public void setVeinMiningPattern(@NotNull VeinMiningPattern pattern, boolean updateClient) { + boolean changed = !Objects.equals(pattern, this.veinMiningPattern); this.dirty |= changed; - this.veinMiningPattern = veinMiningPattern; + this.veinMiningPattern = pattern; - if (changed && updateClient) { - this.sendMessage(new ClientboundSetPattern(veinMiningPattern.getKey())); + if (changed && updateClient && isUsingClientMod()) { + this.sendMessage(new ClientboundSetPattern(pattern.getKey())); } } /** - * Set the {@link VeinMiningPattern} to use for this player and update the client. + * Set this player's active {@link VeinMiningPattern} and update the client if necessary. * - * @param veinMiningPattern the pattern + * @param pattern the new vein mining pattern */ - public void setVeinMiningPattern(@NotNull VeinMiningPattern veinMiningPattern) { - this.setVeinMiningPattern(veinMiningPattern, true); + public void setVeinMiningPattern(@NotNull VeinMiningPattern pattern) { + this.setVeinMiningPattern(pattern, true); } /** - * Get the {@link VeinMiningPattern} to use for this player. + * Get this player's active {@link VeinMiningPattern}. * - * @return the pattern + * @return the active vein mining pattern */ @NotNull public VeinMiningPattern getVeinMiningPattern() { @@ -271,7 +273,8 @@ public VeinMiningPattern getVeinMiningPattern() { } /** - * Execute the given {@link Runnable} when the client is ready. + * Queue the given {@link Runnable} for execution when the client is ready, or execute it now + * if the client is ready. * * @param runnable the runnable to execute * @@ -292,7 +295,8 @@ public boolean executeWhenClientIsReady(@NotNull Runnable runnable) { } /** - * Execute the given {@link Consumer} when the client is ready. + * Queue the given {@link Consumer} for execution when the client is ready, or execute it now + * if the client is ready. * * @param consumer the consumer to execute * @@ -308,9 +312,9 @@ public boolean executeWhenClientIsReady(@NotNull Consumer consu /** * Check whether or not the client is ready to receive messages. *

- * This method will only be true if {@link #isUsingClientMod()} is true, and if the client - * has successfully shaken hands with the server, is capable of being sent a client message, - * and has been synchronized with the server as per the protocol specification. + * This method will only be true if {@link #isUsingClientMod()} is {@code true}, the client has + * successfully shaken hands with the server, is capable of being sent a client message, and + * has been synchronized with the server as per the protocol specification. * * @return true if the client is ready, false otherwise * @@ -331,7 +335,8 @@ public boolean isUsingClientMod() { } /** - * Check whether or not vein miner is active as a result of this user's client mod. + * Check whether or not vein miner is active as a result of this user's client mod. This method will + * always return {@code false} if the player {@link #isUsingClientMod() is not using the client mod}. * * @return true if active, false otherwise */ @@ -340,22 +345,26 @@ public boolean isClientKeyPressed() { } /** - * Set the {@link ClientConfig} for this player. + * Set this player's {@link ClientConfig} and update the client. + *

+ * NOTE: This configuration only really applies if the player {@link #isUsingClientMod() + * is not using the client mod}. * * @param clientConfig the client config to set */ public void setClientConfig(@NotNull ClientConfig clientConfig) { this.clientConfig = clientConfig; - if (usingClientMod) { + if (isUsingClientMod()) { this.sendMessage(new ClientboundSetConfig(clientConfig)); } } /** - * Get the {@link ClientConfig} for this player. + * Get this player's {@link ClientConfig}. *

- * Note that this configuration only really applies if {@link #isUsingClientMod()} is true. + * NOTE: This configuration only really applies if the player {@link #isUsingClientMod() + * is not using the client mod}. * * @return the client config */ @@ -365,23 +374,23 @@ public ClientConfig getClientConfig() { } /** - * Check whether or not vein miner is currently active and ready to be used. + * Check whether or not this player has vein miner active and ready use. *

* NOTE: Do not confuse this with {@link #isVeinMinerEnabled()}. This method * verifies whether or not the player has activated vein miner according to their current - * activation strategy ({@link #getActivationStrategy()}), NOT whether they + * ({@link #getActivationStrategy() activation strategy}), NOT whether they * have it enabled via commands. * * @return true if active, false otherwise */ public boolean isVeinMinerActive() { - return activationStrategy.test(this); + return activationStrategy.isActive(this); } /** * Set whether or not the player is actively vein mining. *

- * Not part of the public API. This method is intended for internal use only. + * NOTE: Not part of the public API. This method is intended for internal use only. * * @param veinMining the new vein mining state */ @@ -400,7 +409,8 @@ public boolean isVeinMining() { } /** - * Set whether or not this player data should be written. + * Set whether or not this player's data has changed since it was read from persistent storage + * and needs to be written again. * * @param dirty true if dirty, false otherwise */ @@ -409,7 +419,8 @@ public void setDirty(boolean dirty) { } /** - * Check whether or not this player data has been modified since last write. + * Check whether or not this player's data has changed since it was read from persistent storage + * and needs to be written again. * * @return true if modified, false otherwise */ @@ -417,6 +428,11 @@ public boolean isDirty() { return dirty; } + /** + * {@inheritDoc} + *

+ * NOTE: Not part of the public API. This method is intended for internal use only. + */ @Internal @Override public void sendMessage(@NotNull NamespacedKey channel, byte @NotNull [] message) { @@ -548,7 +564,7 @@ public void handleRequestVeinMine(@NotNull ServerboundRequestVeinMine message) { } BlockList aliasBlockList = veinMinerManager.getAlias(vmBlock); - List blocks = getVeinMiningPattern().allocateBlocks(targetBlock, targetBlockFace, vmBlock, category.getConfig(), aliasBlockList); + List blocks = getVeinMiningPattern().allocateBlocks(targetBlock, targetBlockFace, vmBlock, category.getConfiguration(), aliasBlockList); this.sendMessage(new ClientboundVeinMineResults(blocks.parallelStream().map(block -> new BlockPosition(block.getX(), block.getY(), block.getZ())).toList())); } diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/VeinMinerPlugin.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/VeinMinerPlugin.java index cf0d29cc..a220afdb 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/VeinMinerPlugin.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/VeinMinerPlugin.java @@ -23,6 +23,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.UnmodifiableView; import wtf.choco.network.bukkit.BukkitProtocolConfiguration; import wtf.choco.veinminer.anticheat.AntiCheatHook; @@ -153,8 +154,6 @@ public void onEnable() { }); } - // Everything below this point is exclusive to Bukkit servers - // Enable anti cheat hooks if required PluginManager manager = Bukkit.getPluginManager(); this.registerAntiCheatHookIfEnabled(manager, "AAC5", AntiCheatHookAAC::new); @@ -231,9 +230,9 @@ public void onDisable() { } /** - * Get an instance of the main VeinMiner class (for VeinMiner API). + * Get the {@link VeinMinerPlugin} instance. * - * @return an instance of the VeinMiner class + * @return the vein miner instance */ @NotNull public static VeinMinerPlugin getInstance() { @@ -241,7 +240,7 @@ public static VeinMinerPlugin getInstance() { } /** - * Get the {@link VeinMinerManager}. + * Get VeinMiner's {@link VeinMinerManager} instance. * * @return the vein miner manager */ @@ -251,7 +250,7 @@ public VeinMinerManager getVeinMinerManager() { } /** - * Get the {@link ToolCategoryRegistry}. + * Get VeinMiner's {@link ToolCategoryRegistry} instance. * * @return the tool category registry */ @@ -261,7 +260,7 @@ public ToolCategoryRegistry getToolCategoryRegistry() { } /** - * Get the {@link PatternRegistry}. + * Get VeinMiner's {@link PatternRegistry} instance. * * @return the pattern registry */ @@ -271,7 +270,7 @@ public PatternRegistry getPatternRegistry() { } /** - * Get the {@link VeinMinerPlayerManager} instance. + * Get VeinMiner's {@link VeinMinerPlayerManager} instance. * * @return the player manager */ @@ -281,16 +280,17 @@ public VeinMinerPlayerManager getPlayerManager() { } /** - * Set the {@link SimpleEconomy} implementation. + * Set the economy implementation used to handle economy transactions. * * @param economy the economy */ public void setEconomy(@NotNull SimpleEconomy economy) { + Preconditions.checkArgument(economy != null, "economy must not be null"); this.economy = economy; } /** - * Get the {@link SimpleEconomy}. + * Get the economy instance used to handle economy transactions. * * @return the economy */ @@ -300,16 +300,16 @@ public SimpleEconomy getEconomy() { } /** - * Set the {@link PersistentDataStorage} for the server. + * Set VeinMiner's {@link PersistentDataStorage} implementation. * - * @param storage the persistent data storage to set + * @param storage the persistent data storage */ public void setPersistentDataStorage(@NotNull PersistentDataStorage storage) { this.storage = storage; } /** - * Get the {@link PersistentDataStorage} for the server. + * Get VeinMiner's {@link PersistentDataStorage}. * * @return the persistent data storage */ @@ -329,9 +329,9 @@ public UpdateChecker getUpdateChecker() { } /** - * Get an instance of the categories configuration file. + * Get VeinMiner's categories.yml {@link ConfigWrapper} instance. * - * @return the categories config + * @return the categories config wrapper */ @NotNull public ConfigWrapper getCategoriesConfig() { @@ -349,12 +349,14 @@ public VeinMinerConfiguration getConfiguration() { } /** - * Register an anti cheat hook to VeinMiner. Hooks should be registered for all anti cheat plugins - * as to support VeinMining and not false-flag players with fast-break. + * Register an {@link AntiCheatHook} to VeinMiner. If an AntiCheatHook is registered, it is + * expected to exempt players so as to not false-flag them with a fast-break violation while + * they are vein mining. * * @param hook the hook to register * - * @return true if registered, false if unsupported + * @return true if successfully registered, false if the anti cheat is unsupported (according + * to the hook itself, {@link AntiCheatHook#isSupported()}) */ public boolean registerAntiCheatHook(@NotNull AntiCheatHook hook) { Preconditions.checkNotNull(hook, "Cannot register a null anticheat hook implementation"); @@ -368,24 +370,25 @@ public boolean registerAntiCheatHook(@NotNull AntiCheatHook hook) { } /** - * Get an immutable list of all anti cheat hooks. + * Get an immutable {@link List} of all {@link AntiCheatHook AntiCheatHooks}. * * @return all anti cheat hooks */ @NotNull + @UnmodifiableView public List getAnticheatHooks() { return Collections.unmodifiableList(anticheatHooks); } /** - * Get a {@link NamespacedKey} with VeinMiner's namespace. + * Create a new {@link NamespacedKey} with VeinMiner's namespace. * * @param key the key * - * @return a VeinMiner namespaced key + * @return a "veinminer" namespaced key */ @NotNull - public static NamespacedKey key(String key) { + public static NamespacedKey key(@NotNull String key) { return new NamespacedKey(instance, key); } diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandBlocklist.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandBlocklist.java index 90658630..4aa726c3 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandBlocklist.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandBlocklist.java @@ -10,6 +10,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,7 +18,6 @@ import wtf.choco.veinminer.block.BlockList; import wtf.choco.veinminer.block.VeinMinerBlock; import wtf.choco.veinminer.tool.VeinMinerToolCategory; -import wtf.choco.veinminer.util.StringUtils; public final class CommandBlocklist implements TabExecutor { @@ -69,7 +69,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } // Update configuration - category.getConfig().setBlockListKeys(blockList); + category.getConfiguration().setBlockListKeys(blockList); sender.sendMessage(formatBlockData(block.toStateString()) + ChatColor.GRAY + " successfully added to the block list."); return true; @@ -96,7 +96,7 @@ else if (args[1].equalsIgnoreCase("remove")) { } // Update configuration - category.getConfig().setBlockListKeys(blockList); + category.getConfiguration().setBlockListKeys(blockList); sender.sendMessage(formatBlockData(block.toStateString()) + ChatColor.GRAY + " successfully removed from the block list."); return true; @@ -142,7 +142,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman } if (args.length == 2) { - return StringUtils.copyPartialMatches(args[1], ARGUMENTS_1, new ArrayList<>()); + return StringUtil.copyPartialMatches(args[1], ARGUMENTS_1, new ArrayList<>()); } if (args.length == 3 && !args[1].equalsIgnoreCase("list")) { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandToollist.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandToollist.java index 9dd34b82..1f96fbf3 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandToollist.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandToollist.java @@ -11,13 +11,13 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import wtf.choco.veinminer.VeinMinerPlugin; import wtf.choco.veinminer.tool.VeinMinerToolCategory; import wtf.choco.veinminer.tool.VeinMinerToolCategoryHand; -import wtf.choco.veinminer.util.StringUtils; public final class CommandToollist implements TabExecutor { @@ -73,7 +73,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } // Update configuration - category.getConfig().setItems(new ArrayList<>(category.getItems())); + category.getConfiguration().setItems(new ArrayList<>(category.getItems())); sender.sendMessage(ChatColor.YELLOW + material.getKey().toString() + ChatColor.GRAY + " successfully added to the tool list."); return true; @@ -109,7 +109,7 @@ else if (args[1].equalsIgnoreCase("remove")) { } // Update configuration - category.getConfig().setItems(new ArrayList<>(category.getItems())); + category.getConfiguration().setItems(new ArrayList<>(category.getItems())); sender.sendMessage(ChatColor.YELLOW + material.getKey().toString() + ChatColor.GRAY + " successfully removed from the tool list."); return true; @@ -155,7 +155,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman } if (args.length == 2) { - return StringUtils.copyPartialMatches(args[1], ARGUMENTS_1, new ArrayList<>()); + return StringUtil.copyPartialMatches(args[1], ARGUMENTS_1, new ArrayList<>()); } if (args.length == 3 && !args[1].equalsIgnoreCase("list")) { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandVeinMiner.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandVeinMiner.java index f311b261..05fc684e 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandVeinMiner.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/command/CommandVeinMiner.java @@ -1,5 +1,8 @@ package wtf.choco.veinminer.command; +import com.google.common.base.Enums; +import com.google.common.base.Optional; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -7,7 +10,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.BooleanSupplier; import java.util.stream.Collectors; @@ -20,6 +22,7 @@ import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,8 +36,6 @@ import wtf.choco.veinminer.pattern.VeinMiningPattern; import wtf.choco.veinminer.tool.VeinMinerToolCategory; import wtf.choco.veinminer.update.UpdateResult; -import wtf.choco.veinminer.util.EnumUtil; -import wtf.choco.veinminer.util.StringUtils; import wtf.choco.veinminer.util.VMConstants; import wtf.choco.veinminer.util.VMEventFactory; @@ -81,7 +82,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command else if (args[0].equalsIgnoreCase("version")) { PluginDescriptionFile description = plugin.getDescription(); - String headerFooter = ChatColor.GOLD.toString() + ChatColor.BOLD + ChatColor.STRIKETHROUGH + StringUtils.repeat('-', 44); + String headerFooter = ChatColor.GOLD.toString() + ChatColor.BOLD + ChatColor.STRIKETHROUGH + "-".repeat(44); sender.sendMessage(headerFooter); sender.sendMessage(""); @@ -157,7 +158,7 @@ else if (args[0].equalsIgnoreCase("mode")) { return true; } - Optional strategyOptional = EnumUtil.get(ActivationStrategy.class, args[1].toUpperCase()); + Optional strategyOptional = Enums.getIfPresent(ActivationStrategy.class, args[1].toUpperCase()); if (!strategyOptional.isPresent()) { player.sendMessage(ChatColor.RED + "Invalid mode " + args[1] + "."); return true; @@ -290,7 +291,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman this.addConditionally(suggestions, "pattern", () -> sender.hasPermission(VMConstants.PERMISSION_COMMAND_PATTERN)); this.addConditionally(suggestions, "import", () -> sender.hasPermission(VMConstants.PERMISSION_COMMAND_IMPORT)); - return StringUtils.copyPartialMatches(args[0], suggestions, new ArrayList<>()); + return StringUtil.copyPartialMatches(args[0], suggestions, new ArrayList<>()); } if (args[0].equalsIgnoreCase("blocklist")) { @@ -337,7 +338,7 @@ else if (args[0].equalsIgnoreCase("pattern")) { } } - return StringUtils.copyPartialMatches(args[1], suggestions, new ArrayList<>()); + return StringUtil.copyPartialMatches(args[1], suggestions, new ArrayList<>()); } return Collections.emptyList(); diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ConfigWrapper.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ConfigWrapper.java index 50e0a7bd..88c10959 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ConfigWrapper.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ConfigWrapper.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; /** - * A simple wrapper to more easily handle {@link YamlConfiguration} instances. + * A simple wrapper to more easily work with {@link YamlConfiguration} instances. */ public final class ConfigWrapper { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ToolCategoryConfiguration.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ToolCategoryConfiguration.java index f2212fc2..64a1ff8b 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ToolCategoryConfiguration.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/ToolCategoryConfiguration.java @@ -2,31 +2,147 @@ import java.util.Collection; import java.util.List; +import java.util.Set; import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import wtf.choco.veinminer.block.BlockList; +import wtf.choco.veinminer.tool.VeinMinerToolCategory; +/** + * A configuration contract for a {@link VeinMinerToolCategory}'s configurable values. + *

+ * If this category configuration does not explicitly set a value for a {@link + * VeinMiningConfiguration} method, it will default to the global value as set by the + * VeinMiningConfiguration. + *

+ * Unless otherwise specified, all values obtained via this contract are updated in real + * time and will always return the values that were last loaded into memory via + * {@link JavaPlugin#reloadConfig()} and {@link ConfigWrapper#reload()}. + */ public interface ToolCategoryConfiguration extends VeinMiningConfiguration { + /** + * Get this category's configured priority. + * + * @return the priority + * + * @see VeinMinerToolCategory#getPriority() + */ public int getPriority(); + /** + * Get this category's required NBT value. + * + * @return the NBT value, or null if not set + * + * @see VeinMinerToolCategory#getNBTValue() + */ @Nullable public String getNBTValue(); + /** + * Set the {@link List} of item {@link Material Materials} that are represented by this + * category. + * + * @param items the item list + */ public void setItems(@NotNull List items); + /** + * Get an unmodifiable {@link Collection} of Strings, each entry a Minecraft item key, for + * the list of items that are represented by this category. + * + * @return the item keys + * + * @apiNote The returned Collection is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull @Unmodifiable public Collection getItemKeys(); + /** + * Set the {@link BlockList} for this category. + * + * @param blockList the block list + */ public void setBlockListKeys(@NotNull BlockList blockList); + /** + * Get an unmodifiable {@link Collection} of Strings, each entry a Minecraft block key, for + * the list of blocks that are vein mineable with this category. + * + * @return the block list keys + * + * @apiNote The returned Collection is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull @Unmodifiable public Collection getBlockListKeys(); + /** + * {@inheritDoc}. + *

+ * If this category configuration does not explicitly set a value, it will default to the + * global value as set by {@link VeinMinerConfiguration#isRepairFriendly()}. + */ + @Override + public boolean isRepairFriendly(); + + /** + * {@inheritDoc}. + *

+ * If this category configuration does not explicitly set a value, it will default to the + * global value as set by {@link VeinMinerConfiguration#getMaxVeinSize()}. + */ + @Override + public int getMaxVeinSize(); + + /** + * {@inheritDoc}. + *

+ * If this category configuration does not explicitly set a value, it will default to the + * global value as set by {@link VeinMinerConfiguration#getCost()}. + */ + @Override + public double getCost(); + + /** + * {@inheritDoc}. + *

+ * If this category configuration does not explicitly set a value, it will default to the + * global value as set by {@link VeinMinerConfiguration#isDisabledWorld(String)}. + */ + @Override + public boolean isDisabledWorld(@NotNull String worldName); + + /** + * {@inheritDoc}. + *

+ * If this category configuration does not explicitly set a value, it will default to the + * global value as set by {@link VeinMinerConfiguration#isDisabledWorld(World)}. + */ + @Override + public default boolean isDisabledWorld(@NotNull World world) { + return isDisabledWorld(world.getName()); + } + + /** + * {@inheritDoc}. + *

+ * If this category configuration does not explicitly set a value, it will default to the + * global value as set by {@link VeinMinerConfiguration#getDisabledWorlds()}. + */ + @Override + @NotNull + @Unmodifiable + public Set getDisabledWorlds(); + } diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMinerConfiguration.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMinerConfiguration.java index f90a3a9e..2aa3e1a9 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMinerConfiguration.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMinerConfiguration.java @@ -6,96 +6,319 @@ import org.bukkit.GameMode; import org.bukkit.permissions.Permissible; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import wtf.choco.veinminer.ActivationStrategy; +import wtf.choco.veinminer.block.BlockList; import wtf.choco.veinminer.data.PersistentDataStorage; import wtf.choco.veinminer.pattern.VeinMiningPattern; /** - * Represents a configuration contract for VeinMiner. + * A configuration contract for all of VeinMiner's configurable values. *

- * Note that any methods declared in this interface are pulled from a configuration file and - * should not be confused with any similarly named methods that represent a stored state. + * Unless otherwise specified, all values obtained via this contract are updated in real + * time and will always return the values that were last loaded into memory via + * {@link JavaPlugin#reloadConfig()} and {@link ConfigWrapper#reload()}. */ public interface VeinMinerConfiguration extends VeinMiningConfiguration { + /** + * Get whether or not metrics are enabled. + *

+ * If this value returns true, bStats Metrics will be used to send anonymous data to + * . + * + * @return true if metrics are enabled, false if disabled + */ public boolean isMetricsEnabled(); + /** + * Get whether or not an update check should be performed when VeinMiner is enabled. + * + * @return true if an update check should be performed, false otherwise + */ public boolean isPerformUpdateChecks(); + /** + * Get the default {@link ActivationStrategy} that will be used for any players that + * do not have an activation strategy explicitly set. + * + * @return the default activation strategy + */ @NotNull public ActivationStrategy getDefaultActivationStrategy(); + /** + * Get the default {@link VeinMiningPattern} that will be used for any players that + * do not have a vein mining pattern explicitly set. + * + * @return the default vein mining pattern + */ @NotNull public VeinMiningPattern getDefaultVeinMiningPattern(); + /** + * Get whether or not items should be collected and dropped at the origin location. + *

+ * If this value returns true, after a player completes a vein mine, all the item drops + * that occurred as a result of all the blocks being broken will be dropped at the location + * where the original block was broken. If false, the items will drop individually at the + * block's broken position, as though the player broke each block separately. + * + * @return true if items will be collected at the source, false if dropped at each block's + * location + */ public boolean isCollectItemsAtSource(); + /** + * Get whether or not McMMO's experience system should be nerfed while vein mining. + *

+ * If this value returns true, McMMO experience will only be yielded for the initial block + * break. If false, every block broken in the vein mine will yield mining experience. + * + * @return true to nerf McMMO experience yield, false to behave as normal + */ public boolean isNerfMcMMO(); + /** + * Check whether or not vein mining is disabled when the player activates it while in the + * specified {@link GameMode}. + * + * @param gameMode the game mode + * + * @return true if vein mining is disabled in the provided game mode, false if enabled + */ public boolean isDisabledGameMode(@NotNull GameMode gameMode); + /** + * Get an unmodifiable {@link Set} of all game modes in which vein miner is disabled. + * + * @return all disabled game modes + */ @NotNull @Unmodifiable public Set getDisabledGameModes(); + /** + * Get the hunger modifier to apply to a player for each block broken when vein mining. This + * is not a hunger value, but rather a modifier to apply on top of traditional hunger + * while vein mining as a punishment for its efficiency. + * + * @return the hunger modifier + */ public float getHungerModifier(); + /** + * Get the minimum amount of food required for a player to vein mine. + *

+ * This food level is checked in two different situations: + *

    + *
  1. When a player tries to start vein mining, they must have at least this amount of hunger + * to successfully initiate a vein mine. + *
  2. While a player is mining, if the food level goes below the minimum amount, vein mining + * will stop immediately. + *
+ * + * @return the minimum food level + */ public int getMinimumFoodLevel(); + /** + * Get the message to send to the player when they were too hungry to vein mine. The returned + * string is legacy colour code formatted with {@code '&'} used in place of section symbols. + * + * @return the hungry message + */ @Nullable public String getHungryMessage(); + /** + * Get the default {@link ClientConfig}. + * + * @return the default client configuration + * + * @see #isAllowActivationKeybind() + * @see #isAllowPatternSwitchingKeybind() + * @see #isAllowWireframeRendering() + * + * @apiNote The returned ClientConfig is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull public ClientConfig getClientConfiguration(); + /** + * Create a {@link ClientConfig} using the values specified in this configuration as well as the + * permissions calculated by the given {@link Permissible} object. If any individual option is + * {@code true}, it will be &&'d with whether or not {@link Permissible#hasPermission(String)} for + * the permission associated with each value. + * + * @param permissible the permissible object + * + * @return the client configuration relative to the given Permissible object + * + * @see #isAllowActivationKeybind() + * @see #isAllowPatternSwitchingKeybind() + * @see #isAllowWireframeRendering() + * + * @apiNote The returned ClientConfig is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull public ClientConfig getClientConfiguration(@NotNull Permissible permissible); + /** + * Get whether or not clients with the client-sided mod are allowed to use their own configured + * keybind to activate vein miner. + *

+ * NOTE: This value is only relevant for players that have the client-sided mod + * installed. + * + * @return true if allowed to use the activation keybind, false otherwise + */ public boolean isAllowActivationKeybind(); + /** + * Get whether or not clients with the client-sided mod are allowed to use their own configured + * keybind to switch between registered vein mining patterns. + *

+ * NOTE: This value is only relevant for players that have the client-sided mod + * installed. + * + * @return true if allowed to use the pattern switching keybinds, false otherwise + */ public boolean isAllowPatternSwitchingKeybind(); + /** + * Get whether or not clients with the client-sided mod are allowed to render a wireframe outline + * around blocks they are able to vein mine. The wireframe shape is calculated by the server. + *

+ * NOTE: This value is only relevant for players that have the client-sided mod + * installed. + * + * @return true if allowed to render a wireframe, false otherwise + */ public boolean isAllowWireframeRendering(); + /** + * Get the type of storage to be used when storing persistent data. + * + * @return the storage type + */ @NotNull public PersistentDataStorage.Type getStorageType(); + /** + * Get the {@link File} directory in which JSON data is stored. + * + * @return the JSON storage directory + */ @Nullable public File getJsonStorageDirectory(); + /** + * Get the host represented as a String for the MySQL server in which persistent data will be + * stored. + * + * @return the MySQL host + */ @Nullable public String getMySQLHost(); + /** + * Get the port for the MySQL server in which persistent data will be stored. + * + * @return the MySQL port + */ public int getMySQLPort(); + /** + * Get the username for the MySQL instance in which persistent data will be stored. + * + * @return the MySQL username + */ @Nullable public String getMySQLUsername(); + /** + * Get the password for the MySQL instance in which persistent data will be stored. + * + * @return the MySQL password + */ @Nullable public String getMySQLPassword(); + /** + * Get the database for the MySQL instance in which persistent data will be stored. + * + * @return the MySQL database + */ @Nullable public String getMySQLDatabase(); + /** + * Get the prefix to use before all MySQL tables VeinMiner will create for persistent data. + * + * @return the MySQL port + */ @Nullable public String getMySQLTablePrefix(); + /** + * Get an unmodifiable {@link Collection} of Strings containing the aliases that need to + * be parsed by VeinMiner to create a {@link BlockList}. Each returned string entry should + * be a pseudo "array" of Minecraft block keys separated by {@code ';'}s. + * + * @return the alias strings + * + * @apiNote The returned Collection is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull @Unmodifiable public Collection getAliasStrings(); + /** + * Get an unmodifiable {@link Collection} of Strings, each entry a Minecraft block key, for + * the list of blocks that are vein mineable with all categories. + * + * @return the global block list keys + * + * @apiNote The returned Collection is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull @Unmodifiable public Collection getGlobalBlockListKeys(); + /** + * Get an unmodifiable {@link Collection} of Strings, each entry a unique id for a category + * defined in the categories.yml. This will always exclude "All" which is not a registerable + * category. + * + * @return all defined category ids + * + * @apiNote The returned Collection is a snapshot of current values and, unlike other methods + * in this configuration, will not be updated when this configuration is reloaded! + */ @NotNull @Unmodifiable public Collection getDefinedCategoryIds(); + /** + * Get a {@link ToolCategoryConfiguration} for the category with the given id. + *

+ * The returned instance will be updated automatically if the configuration is ever reloaded. + * A new instance does not need to be returned upon reloading. Existing instances may be + * reused but still have their values reflect the newly reloaded ones. + * + * @param categoryId the category id whose configuration to get + * + * @return the tool category configuration + */ @NotNull public ToolCategoryConfiguration getToolCategoryConfiguration(@NotNull String categoryId); diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMiningConfiguration.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMiningConfiguration.java index 497ed1ae..d57f8035 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMiningConfiguration.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/VeinMiningConfiguration.java @@ -3,23 +3,71 @@ import java.util.Set; import org.bukkit.World; +import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; +/** + * A configuration object holding values for the vein mining process. + *

+ * Unless otherwise specified, all values obtained via this contract are updated in real + * time and will always return the values that were last loaded into memory via + * {@link JavaPlugin#reloadConfig()} and {@link ConfigWrapper#reload()}. + */ public interface VeinMiningConfiguration { + /** + * Get the "repair friendly" value. + *

+ * If vein mining is repair friendly, it signifies that vein mining should stop if + * the tool reaches a durability of 1 so that it may be repaired. If not repair + * friendly, vein miner will continue mining until the tool in hand breaks. + * + * @return true if repair friendly, false otherwise + */ public boolean isRepairFriendly(); + /** + * Get the maximum amount of blocks allowed to be mined in a single vein. + * + * @return the maximum vein size + */ public int getMaxVeinSize(); + /** + * Get the amount of money to be withdrawn from a player's bank account each time + * they initiate a vein mine. + * + * @return the cost of vein mining, or 0.0 to not withdraw any currency + */ public double getCost(); + /** + * Check whether or not vein miner is disabled in worlds with the given name. + * + * @param worldName the name of the world to check + * + * @return true if the world is disabled, false if allowed + */ public boolean isDisabledWorld(@NotNull String worldName); + /** + * Check whether or not vein miner is disabled in the given world. + * + * @param world the world to check + * + * @return true if the world is disabled, false if allowed + */ public default boolean isDisabledWorld(@NotNull World world) { return isDisabledWorld(world.getName()); } + /** + * Get an unmodifiable {@link Set} of the names of all worlds in which vein mining + * is disabled. + * + * @return the names of all worlds where vein mining is disabled + */ @NotNull @Unmodifiable public Set getDisabledWorlds(); diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/ConfigKeys.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/ConfigKeys.java index 1d57eedf..5251f1b2 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/ConfigKeys.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/ConfigKeys.java @@ -1,5 +1,8 @@ package wtf.choco.veinminer.config.impl; +/** + * A class containing keys for configurable values in the standard VeinMiner configurations. + */ final class ConfigKeys { // VeinMinerConfiguration diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardToolCategoryConfiguration.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardToolCategoryConfiguration.java index bcedf472..9e7c9ef1 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardToolCategoryConfiguration.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardToolCategoryConfiguration.java @@ -21,12 +21,22 @@ import static wtf.choco.veinminer.config.impl.ConfigKeys.*; +/** + * A standard {@link ToolCategoryConfiguration} implementation. + */ public final class StandardToolCategoryConfiguration implements ToolCategoryConfiguration { private final String categoryId; private final ConfigWrapper categoriesConfig; private final VeinMinerConfiguration parent; + /** + * Construct a new {@link StandardToolCategoryConfiguration}. + * + * @param categoryId the id of the category for this configuration + * @param categoriesConfig the {@link ConfigWrapper} instance for the categories.yml + * @param parent the parent {@link VeinMinerConfiguration} + */ StandardToolCategoryConfiguration(@NotNull String categoryId, @NotNull ConfigWrapper categoriesConfig, @NotNull VeinMinerConfiguration parent) { this.categoryId = categoryId; this.categoriesConfig = categoriesConfig; diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardVeinMinerConfiguration.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardVeinMinerConfiguration.java index 458f0e57..5add5ea0 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardVeinMinerConfiguration.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/config/impl/StandardVeinMinerConfiguration.java @@ -1,6 +1,7 @@ package wtf.choco.veinminer.config.impl; import com.google.common.base.Enums; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -27,11 +28,20 @@ import static wtf.choco.veinminer.config.impl.ConfigKeys.*; +/** + * A standard {@link VeinMinerConfiguration} implementation. + */ public final class StandardVeinMinerConfiguration implements VeinMinerConfiguration { private final VeinMinerPlugin plugin; - public StandardVeinMinerConfiguration(VeinMinerPlugin plugin) { + /** + * Construct a new {@link StandardVeinMinerConfiguration}. + * + * @param plugin the plugin instance + */ + public StandardVeinMinerConfiguration(@NotNull VeinMinerPlugin plugin) { + Preconditions.checkArgument(plugin != null, "plugin must not be null"); this.plugin = plugin; } diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/data/LegacyPlayerData.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/data/LegacyPlayerData.java index 779af96f..7a6d3a70 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/data/LegacyPlayerData.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/data/LegacyPlayerData.java @@ -15,4 +15,4 @@ * @param activationStrategy the activation strategy * @param disabledCategories the disabled categories */ -public record LegacyPlayerData(@NotNull UUID playerUUID, @NotNull ActivationStrategy activationStrategy, @NotNull List disabledCategories) { } +record LegacyPlayerData(@NotNull UUID playerUUID, @NotNull ActivationStrategy activationStrategy, @NotNull List disabledCategories) { } diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleEconomy.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleEconomy.java index 0bcd0f6d..a771719e 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleEconomy.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleEconomy.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull; /** - * A wrapper for economic transactions + * A wrapper for economic transactions. */ public interface SimpleEconomy { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleVaultEconomy.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleVaultEconomy.java index 52d81ecc..870b0747 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleVaultEconomy.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/economy/SimpleVaultEconomy.java @@ -25,7 +25,14 @@ public class SimpleVaultEconomy implements SimpleEconomy { private final Plugin plugin; private final Supplier economy; - public SimpleVaultEconomy(Plugin plugin) { + /** + * Construct a new {@link SimpleVaultEconomy}. + * + * @param plugin the plugin instance + */ + public SimpleVaultEconomy(@NotNull Plugin plugin) { + Preconditions.checkArgument(plugin != null, "plugin must not be null"); + this.plugin = plugin; this.economy = Suppliers.memoize(this::getEconomy); } diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/listener/BreakBlockListener.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/listener/BreakBlockListener.java index f0500cd7..8d36f301 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/listener/BreakBlockListener.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/listener/BreakBlockListener.java @@ -83,7 +83,7 @@ private void onBlockBreak(BlockBreakEvent event) { if (!veinMinerPlayer.isVeinMinerActive() || !veinMinerPlayer.isVeinMinerEnabled(category) || plugin.getConfiguration().isDisabledGameMode(player.getGameMode()) - || category.getConfig().isDisabledWorld(origin.getWorld().getName()) + || category.getConfiguration().isDisabledWorld(origin.getWorld().getName()) || !player.hasPermission(VMConstants.PERMISSION_VEINMINE.apply(category))) { return; } @@ -98,7 +98,7 @@ private void onBlockBreak(BlockBreakEvent event) { // Economy check SimpleEconomy economy = plugin.getEconomy(); if (economy.shouldCharge(player)) { - double cost = category.getConfig().getCost(); + double cost = category.getConfiguration().getCost(); if (!economy.hasSufficientBalance(player, cost)) { player.sendMessage(ChatColor.GRAY + "You have insufficient funds to vein mine (Required: " + ChatColor.YELLOW + cost + ChatColor.GRAY + ")"); return; @@ -122,7 +122,7 @@ private void onBlockBreak(BlockBreakEvent event) { VeinMiningPattern pattern = veinMinerPlayer.getVeinMiningPattern(); BlockList aliasBlockList = veinMinerManager.getAlias(originVeinMinerBlock); - List blocks = pattern.allocateBlocks(origin, targetBlockFace, originVeinMinerBlock, category.getConfig(), aliasBlockList); + List blocks = pattern.allocateBlocks(origin, targetBlockFace, originVeinMinerBlock, category.getConfiguration(), aliasBlockList); blocks.removeIf(Block::isEmpty); if (blocks.isEmpty()) { @@ -147,7 +147,7 @@ private void onBlockBreak(BlockBreakEvent event) { hooks.forEach(h -> h.exempt(player)); // Actually destroying the allocated blocks - int maxDurability = item.getType().getMaxDurability() - (category.getConfig().isRepairFriendly() ? 1 : 0); + int maxDurability = item.getType().getMaxDurability() - (category.getConfiguration().isRepairFriendly() ? 1 : 0); float hungerModifier = plugin.getConfiguration().getHungerModifier() * 0.025F; int minimumFoodLevel = plugin.getConfiguration().getMinimumFoodLevel(); diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/pattern/VeinMiningPattern.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/pattern/VeinMiningPattern.java index 04575949..80a25ce5 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/pattern/VeinMiningPattern.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/pattern/VeinMiningPattern.java @@ -11,7 +11,6 @@ import wtf.choco.veinminer.block.BlockList; import wtf.choco.veinminer.block.VeinMinerBlock; import wtf.choco.veinminer.config.VeinMiningConfiguration; -import wtf.choco.veinminer.util.BlockPosition; /** * Represents a pattern used to allocate blocks for vein mining. @@ -27,28 +26,31 @@ public interface VeinMiningPattern { public NamespacedKey getKey(); /** - * Allocate all {@link BlockPosition BlockPositions} that should be mined according to the input values. + * Allocate a {@link List} of {@link Block Blocks} that should be destroyed. The returned List of + * blocks will be broken in the order that they are inserted. * - * @param origin the position at which the vein mining was initiated - * @param destroyedFace the face on which the block was destroyed - * @param block the type of {@link VeinMinerBlock} that was broken at the origin - * @param config the configuration applicable for this instance of vein mining + * @param origin the block where vein miner was initiated + * @param destroyedFace the block face that was destroyed + * @param block the {@link VeinMinerBlock} that was broken at the origin + * @param config the configuration applicable for this vein mine * @param aliasList a {@link BlockList} of all blocks that should also be considered. May be empty + * or null * - * @return the allocated block positions + * @return the allocated blocks to break */ @NotNull public List allocateBlocks(@NotNull Block origin, @NotNull BlockFace destroyedFace, @NotNull VeinMinerBlock block, @NotNull VeinMiningConfiguration config, @Nullable BlockList aliasList); /** - * Allocate all {@link BlockPosition BlockPositions} that should be mined according to the input values. + * Allocate a {@link List} of {@link Block Blocks} that should be destroyed. The returned List of + * blocks will be broken in the order that they are inserted. * - * @param origin the position at which the vein mining was initiated - * @param destroyedFace the face on which the block was destroyed - * @param block the type of {@link VeinMinerBlock} that was broken at the origin - * @param config the configuration applicable for this instance of vein mining + * @param origin the block where vein miner was initiated + * @param destroyedFace the block face that was destroyed + * @param block the {@link VeinMinerBlock} that was broken at the origin + * @param config the configuration applicable for this vein mine * - * @return the allocated block positions + * @return the allocated blocks to break */ @NotNull public default List allocateBlocks(@NotNull Block origin, @NotNull BlockFace destroyedFace, @NotNull VeinMinerBlock block, @NotNull VeinMiningConfiguration config) { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/ToolCategoryRegistry.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/ToolCategoryRegistry.java index 880c55d2..3acbbdbb 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/ToolCategoryRegistry.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/ToolCategoryRegistry.java @@ -26,7 +26,7 @@ import wtf.choco.veinminer.block.BlockList; import wtf.choco.veinminer.config.ToolCategoryConfiguration; import wtf.choco.veinminer.config.VeinMinerConfiguration; -import wtf.choco.veinminer.util.ItemUtil; +import wtf.choco.veinminer.util.ItemStackUtil; /** * A registry to which {@link VeinMinerToolCategory VeinMinerToolCategories} may be registered. @@ -37,6 +37,11 @@ public final class ToolCategoryRegistry { private final VeinMinerPlugin plugin; + /** + * Construct a new {@link ToolCategoryRegistry}. + * + * @param plugin the plugin instance + */ public ToolCategoryRegistry(@NotNull VeinMinerPlugin plugin) { this.plugin = plugin; } @@ -90,8 +95,8 @@ private VeinMinerToolCategory get(@NotNull Material item, @Nullable String itemN /** * Get the {@link VeinMinerToolCategory} that contains the given {@link Material}. There is - * no guarantee as to which category will be returned if more than one category contains the - * provided ItemType. + * no guarantee which category will be returned if more than one category contains the provided + * item type. * * @param item the item type * @@ -108,8 +113,8 @@ public VeinMinerToolCategory get(@NotNull Material item) { /** * Get the {@link VeinMinerToolCategory} that contains the given {@link Material}. There is - * no guarantee as to which category will be returned if more than one category contains the - * provided ItemType. + * no guarantee which category will be returned if more than one category contains the provided + * item type. * * @param item the item type * @param categoryPredicate a predicate to apply on top of the item condition. If the predicate @@ -129,8 +134,8 @@ public VeinMinerToolCategory get(@NotNull Material item, @NotNull Predicate categoryPredicate) { - return get(itemStack.getType(), ItemUtil.getVeinMinerNBTValue(itemStack), categoryPredicate); + return get(itemStack.getType(), ItemStackUtil.getVeinMinerNBTValue(itemStack), categoryPredicate); } /** @@ -201,6 +206,10 @@ public Collection getAll() { return Collections.unmodifiableCollection(categories.values()); } + /** + * Unregister all tool categories from this registry and re-register categories that have + * been read and parsed from VeinMiner's configuration files. + */ public void reloadFromConfig() { this.unregisterAll(); diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategory.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategory.java index 3b795c62..e66859bf 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategory.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategory.java @@ -11,8 +11,10 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.UnmodifiableView; +import wtf.choco.veinminer.VeinMinerPlugin; import wtf.choco.veinminer.block.BlockList; import wtf.choco.veinminer.config.ToolCategoryConfiguration; +import wtf.choco.veinminer.util.VMConstants; /** * Represents a category of tools. @@ -72,12 +74,14 @@ public int getPriority() { } /** - * Get the value that must be on items in this category to be vein mineable. + * Get the NBT value that must be on items in this category to be vein mineable. *

* Callers of {@link #containsItem(Material)} should verify also that any ItemStack to be * checked contains also the value returned by this method. * * @return the NBT value, or null if no NBT is required + * + * @see VMConstants#getVeinMinerNBTKey() */ @Nullable public String getNBTValue() { @@ -96,11 +100,14 @@ public BlockList getBlockList() { /** * Get the {@link ToolCategoryConfiguration} for this tool category. + *

+ * The returned configuration may be edited. It will be saved in memory until saved via the + * {@link VeinMinerPlugin#getCategoriesConfig()}. * * @return the config */ @NotNull - public ToolCategoryConfiguration getConfig() { + public ToolCategoryConfiguration getConfiguration() { return config; } @@ -142,7 +149,7 @@ public boolean containsItem(@NotNull Material item) { } /** - * Get an unmodifiable collection of all items in this category. + * Get an unmodifiable {@link Set} of all items in this category. * * @return the items */ diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategoryHand.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategoryHand.java index b26c65b2..d7f74b15 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategoryHand.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/tool/VeinMinerToolCategoryHand.java @@ -9,8 +9,8 @@ import wtf.choco.veinminer.config.ToolCategoryConfiguration; /** - * A more specific type of {@link VeinMinerToolCategory} whereby the hand category - * is being represented. No items may be added to or removed from this category. + * A more specific type of {@link VeinMinerToolCategory} that represents the hand category. + * No items may be added to or removed from this category. */ public final class VeinMinerToolCategoryHand extends VeinMinerToolCategory { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/StandardVersionSchemes.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/StandardVersionSchemes.java index db3beaaf..1ead28bd 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/StandardVersionSchemes.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/StandardVersionSchemes.java @@ -3,7 +3,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import wtf.choco.veinminer.util.StringUtils; +import org.apache.commons.lang.math.NumberUtils; /** * A utility class holding constants representing standard version schemes. @@ -17,7 +17,7 @@ public final class StandardVersionSchemes { String[] firstSplit = splitVersionInfo(first), secondSplit = splitVersionInfo(second); for (int i = 0; i < Math.min(firstSplit.length, secondSplit.length); i++) { - int currentValue = StringUtils.toInt(firstSplit[i], -1), newestValue = StringUtils.toInt(secondSplit[i], -1); + int currentValue = NumberUtils.toInt(firstSplit[i], -1), newestValue = NumberUtils.toInt(secondSplit[i], -1); if (newestValue > currentValue) { return second; diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/UpdateChecker.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/UpdateChecker.java index a1a6f578..fc563a70 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/UpdateChecker.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/update/UpdateChecker.java @@ -11,7 +11,7 @@ public interface UpdateChecker { /** - * Get the {@link UpdateResult result} of the last update check that was performed. + * Get the {@link UpdateResult UpdateResult} of the last update check that was performed. * * @return the last update result, or an empty {@link Optional} if an update check has * not yet been performed diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/EnumUtil.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/EnumUtil.java deleted file mode 100644 index 5de5a8ef..00000000 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/EnumUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -package wtf.choco.veinminer.util; - -import java.util.Optional; - -import org.jetbrains.annotations.NotNull; - -/** - * A utility class to more easily operate with enums. - */ -public final class EnumUtil { - - private EnumUtil() { } - - /** - * Get an enum constant with the given name if it exists. - * - * @param enumClass the class of the enum from which to get a constant - * @param name the name of the constant. This name is case-insensitive - * @param the enum type - * - * @return an {@link Optional} containing the constant, or an empty Optional if a constant - * with the given name did not exist - */ - @NotNull - public static > Optional get(@NotNull Class enumClass, @NotNull String name) { - try { - return Optional.ofNullable(Enum.valueOf(enumClass, name.toUpperCase())); - } catch (IllegalArgumentException e) { - return Optional.empty(); - } - } - -} diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/ItemUtil.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/ItemStackUtil.java similarity index 60% rename from veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/ItemUtil.java rename to veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/ItemStackUtil.java index 9eeaf758..1b0f056a 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/ItemUtil.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/ItemStackUtil.java @@ -6,10 +6,21 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public final class ItemUtil { +/** + * A utility class for {@link ItemStack} instances. + */ +public final class ItemStackUtil { - private ItemUtil() { } + private ItemStackUtil() { } + /** + * Get the String value for VeinMiner's NBT key on the given {@link ItemStack}. + * + * @param itemStack the item stack + * + * @return the value set for VeinMiner's NBT key, or null if not set or if the item + * does not have any item meta + */ @Nullable public static String getVeinMinerNBTValue(@NotNull ItemStack itemStack) { if (!itemStack.hasItemMeta()) { diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/StringUtils.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/StringUtils.java deleted file mode 100644 index 5cba93ff..00000000 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/StringUtils.java +++ /dev/null @@ -1,106 +0,0 @@ -package wtf.choco.veinminer.util; - -import java.util.Collection; - -import org.jetbrains.annotations.NotNull; - -/** - * Various utility methods handy for tab completion. - */ -public final class StringUtils { - - private StringUtils() { } - - /** - * Copies all elements from the iterable collection of originals to the - * collection provided. - * - * @param the collection of strings - * @param token string to search for - * @param originals an iterable collection of strings to filter. - * @param collection the collection to add matches to - * @return the collection provided that would have the elements copied into - * - * @throws UnsupportedOperationException if the collection is immutable - * and originals contains a string which starts with the specified - * search string - * @throws IllegalArgumentException if originals contains a null element - */ - @NotNull - public static > T copyPartialMatches(@NotNull String token, @NotNull Iterable originals, @NotNull T collection) { - for (String string : originals) { - if (startsWithIgnoreCase(string, token)) { - collection.add(string); - } - } - - return collection; - } - - /** - * This method uses a region to check case-insensitive equality. This - * means the internal array does not need to be copied like a - * toLowerCase() call would. - * - * @param string the string to check - * @param prefix prefix of string to compare - * - * @return true if provided string starts with, ignoring case, the prefix provided - */ - public static boolean startsWithIgnoreCase(@NotNull String string, @NotNull String prefix) { - return string.length() >= prefix.length() && string.regionMatches(true, 0, prefix, 0, prefix.length()); - } - - /** - * Repeat the given character x amount of times and buffer it to a string. - * - * @param character the character to repeat - * @param times the amount of times to repeat the character - * - * @return a string containing the repeated characters - */ - @NotNull - public static String repeat(char character, int times) { - if (times <= 0) { - throw new IllegalArgumentException("Cannot repeat less than 1 time"); - } - - StringBuilder builder = new StringBuilder(); - - for (int i = 0; i < times; i++) { - builder.append(character); - } - - return builder.toString(); - } - - /** - * Convert the given string to an integer primitive, or a default value if the - * string is not in a supported number format. - * - * @param string the string to parse - * @param defaultValue the default value to return if the parsing fails - * - * @return the int representation of the string, or the default value - */ - public static int toInt(@NotNull String string, int defaultValue) { - try { - return Integer.parseInt(string); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - /** - * Convert the given string to an integer primitive, or 0 if the string is not in - * a supported number format. - * - * @param string the string to parse - * - * @return the int representation of the string, or 0 - */ - public static int toInt(@NotNull String string) { - return toInt(string, 0); - } - -} diff --git a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/VMEventFactory.java b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/VMEventFactory.java index 6316907b..81f787d3 100644 --- a/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/VMEventFactory.java +++ b/veinminer-bukkit/src/main/java/wtf/choco/veinminer/util/VMEventFactory.java @@ -27,7 +27,7 @@ private VMEventFactory() { } * Call the {@link PlayerVeinMineEvent}. * * @param player the player - * @param block the origin block that was broken by the player + * @param block the block that was broken by the player * @param veinMinerBlock the type of block being vein mined * @param item the item used to vein mine * @param category the tool category @@ -60,7 +60,7 @@ public static boolean callPlayerClientActivateVeinMinerEvent(@NotNull Player pla /** * Call the {@link PlayerVeinMiningPatternChangeEvent}. * - * @param player the player whose pattern was changed + * @param player the player * @param currentPattern the player's current pattern * @param newPattern the pattern to be set * @param cause the cause of the event diff --git a/veinminer-bukkit/src/test/java/wtf/choco/veinminer/util/EnumUtilTest.java b/veinminer-bukkit/src/test/java/wtf/choco/veinminer/util/EnumUtilTest.java deleted file mode 100644 index 474b3be8..00000000 --- a/veinminer-bukkit/src/test/java/wtf/choco/veinminer/util/EnumUtilTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package wtf.choco.veinminer.util; - -import org.bukkit.ChatColor; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class EnumUtilTest { - - @Test - void testSuccess() { - assertAll( - () -> assertTrue(EnumUtil.get(ChatColor.class, "RED").isPresent()), - () -> assertTrue(EnumUtil.get(ChatColor.class, "BLURPLE").isEmpty()), - () -> assertSame(ChatColor.RED, EnumUtil.get(ChatColor.class, "RED").get()) - ); - } - -} diff --git a/veinminer-bukkit/src/test/java/wtf/choco/veinminer/util/StringUtilsTest.java b/veinminer-bukkit/src/test/java/wtf/choco/veinminer/util/StringUtilsTest.java deleted file mode 100644 index 9d8d5bda..00000000 --- a/veinminer-bukkit/src/test/java/wtf/choco/veinminer/util/StringUtilsTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package wtf.choco.veinminer.util; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertLinesMatch; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class StringUtilsTest { - - @Test - void testCopyPartialMatches() { - assertLinesMatch(List.of("hello world", "hello"), StringUtils.copyPartialMatches("hell", List.of("hello world", "hello", "hi"), new ArrayList<>())); - assertLinesMatch(List.of("Professional", "pRops", "proDUCT"), StringUtils.copyPartialMatches("pro", List.of("pride", "Professional", "apple", "pRops", "proDUCT"), new ArrayList<>())); - } - - @Test - void testStartsWithIgnoreCase() { - assertTrue(StringUtils.startsWithIgnoreCase("This is a string", "thIS Is")); - assertFalse(StringUtils.startsWithIgnoreCase("This doesn't start with this prefix:", "doesn't")); - } - - @Test - void testRepeat() { - assertEquals("----------", StringUtils.repeat('-', 10)); - assertEquals(".....", StringUtils.repeat('.', 5)); - } - - @Test - void testToInt() { - assertEquals(69, StringUtils.toInt("69")); - assertEquals(-420, StringUtils.toInt("-420")); - assertEquals(0, StringUtils.toInt("invalid", 0)); - assertEquals(-1, StringUtils.toInt("nonsense", -1)); - } - -}