Writes a lot of code necessary for the scrapper

Adds the classes necessary for the new scrapper
Partly implements some scrapper functionality
Restructures some classes to reduce code duplication
Moves some classes to make some classes easier to find
Adds a bunch of TODOs where things have an unfinished implementation
This commit is contained in:
2023-11-14 16:04:48 +01:00
parent 1938a690c6
commit f3f3f66c38
40 changed files with 1788 additions and 594 deletions

View File

@@ -24,10 +24,9 @@ public class ReloadCommand implements TabExecutor {
return true;
}
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
return new ArrayList<>();
}

View File

@@ -1,10 +1,11 @@
package net.knarcraft.blacksmith.command;
package net.knarcraft.blacksmith.command.blacksmith;
import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.command.ReloadCommand;
import net.knarcraft.blacksmith.config.SettingValueType;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting;
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.config.SettingValueType;
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
import net.knarcraft.blacksmith.formatting.ItemType;
import net.knarcraft.blacksmith.util.InputParsingHelper;
@@ -17,6 +18,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -38,7 +40,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
if (commandName.equalsIgnoreCase("reload")) {
return new ReloadCommand().onCommand(sender, command, label, args);
}
GlobalBlacksmithSettings settings = BlacksmithPlugin.getInstance().getSettings();
GlobalBlacksmithSettings settings = BlacksmithPlugin.getInstance().getGlobalBlacksmithSettings();
//Find which global setting the user has specified, if any
GlobalBlacksmithSetting detectedGlobalBlacksmithSetting = null;
@@ -86,15 +88,16 @@ public class BlackSmithConfigCommand implements CommandExecutor {
/**
* Changes the value of the setting defined in the user's input
*
* @param args <p>The arguments given by the user</p>
* @param args <p>The arguments given by the user</p>
* @param detectedGlobalBlacksmithSetting <p>The global setting recognized from the input, if any</p>
* @param detectedBlacksmithNPCSetting <p>The NPC setting recognized from the input, if any</p>
* @param settings <p>The global settings object to get settings from</p>
* @param sender <p>The command sender to display any output to</p>
* @param settings <p>The global settings object to get settings from</p>
* @param sender <p>The command sender to display any output to</p>
* @return <p>True if the value was successfully changed</p>
*/
private boolean changeValue(String[] args, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, BlacksmithNPCSetting detectedBlacksmithNPCSetting,
GlobalBlacksmithSettings settings, CommandSender sender) {
private boolean changeValue(@NotNull String[] args, @Nullable GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
@Nullable BlacksmithNPCSetting detectedBlacksmithNPCSetting,
@NotNull GlobalBlacksmithSettings settings, @NotNull CommandSender sender) {
String newValue = args[1];
if (detectedGlobalBlacksmithSetting != null) {
settings.changeValue(detectedGlobalBlacksmithSetting, newValue);
@@ -120,12 +123,13 @@ public class BlackSmithConfigCommand implements CommandExecutor {
*
* @param detectedGlobalBlacksmithSetting <p>The global setting recognized from the input, if any</p>
* @param detectedBlacksmithNPCSetting <p>The NPC setting recognized from the input, if any</p>
* @param settings <p>The global settings object to get settings from</p>
* @param sender <p>The command sender to display any output to</p>
* @param settings <p>The global settings object to get settings from</p>
* @param sender <p>The command sender to display any output to</p>
* @return <p>True if a settings was successfully displayed</p>
*/
private boolean displayCurrentValue(GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, BlacksmithNPCSetting detectedBlacksmithNPCSetting,
GlobalBlacksmithSettings settings, CommandSender sender) {
private boolean displayCurrentValue(@Nullable GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
@Nullable BlacksmithNPCSetting detectedBlacksmithNPCSetting,
@NotNull GlobalBlacksmithSettings settings, @NotNull CommandSender sender) {
String settingValue;
String correctCommandName;
boolean printRawValue = false;
@@ -165,8 +169,9 @@ public class BlackSmithConfigCommand implements CommandExecutor {
* @param settings <p>The settings object to query</p>
* @return <p>True if the value was successfully displayed</p>
*/
private boolean displaySpecialCaseValue(String selector, CommandSender sender, GlobalBlacksmithSetting setting,
GlobalBlacksmithSettings settings) {
private boolean displaySpecialCaseValue(@NotNull String selector, @NotNull CommandSender sender,
@Nullable GlobalBlacksmithSetting setting,
@NotNull GlobalBlacksmithSettings settings) {
if (setting == GlobalBlacksmithSetting.BASE_PRICE || setting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) {
Material material = InputParsingHelper.matchMaterial(selector);
if (material == null) {
@@ -203,7 +208,7 @@ public class BlackSmithConfigCommand implements CommandExecutor {
* @param commandName <p>The command specified</p>
* @return <p>True if the command is a special case</p>
*/
private boolean isSpecialCase(String commandName) {
private boolean isSpecialCase(@NotNull String commandName) {
return commandName.equalsIgnoreCase(GlobalBlacksmithSetting.BASE_PRICE.getCommandName()) ||
commandName.equalsIgnoreCase(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getCommandName()) ||
commandName.equalsIgnoreCase(GlobalBlacksmithSetting.ENCHANTMENT_COST.getCommandName());
@@ -212,13 +217,15 @@ public class BlackSmithConfigCommand implements CommandExecutor {
/**
* Updates a special-case configuration value if a special-case is encountered
*
* @param settings <p>The settings to modify</p>
* @param settings <p>The settings to modify</p>
* @param detectedGlobalBlacksmithSetting <p>The global setting specified</p>
* @param args <p>All arguments given</p>
* @param sender <p>The command sender to notify if successful</p>
* @param args <p>All arguments given</p>
* @param sender <p>The command sender to notify if successful</p>
* @return <p>True if already handled as a special case</p>
*/
private boolean updateSpecialCase(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting, String[] args,
private boolean updateSpecialCase(@NotNull GlobalBlacksmithSettings settings,
@Nullable GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
@NotNull String[] args,
CommandSender sender) {
if (InputParsingHelper.isEmpty(args[2])) {
args[2] = "-1";
@@ -252,15 +259,17 @@ public class BlackSmithConfigCommand implements CommandExecutor {
/**
* Updates a special case price configuration value if a special case is encountered
*
* @param settings <p>The settings to modify</p>
* @param settings <p>The settings to modify</p>
* @param detectedGlobalBlacksmithSetting <p>The global setting specified</p>
* @param materialName <p>The material name to update the price for</p>
* @param newPrice <p>The new price to update to</p>
* @param sender <p>The command sender to respond to</p>
* @param materialName <p>The material name to update the price for</p>
* @param newPrice <p>The new price to update to</p>
* @param sender <p>The command sender to respond to</p>
* @return <p>True if the input was valid, and the item(s) was/were updated</p>
*/
private boolean updatePriceSpecialCase(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
String materialName, double newPrice, CommandSender sender) {
private boolean updatePriceSpecialCase(@NotNull GlobalBlacksmithSettings settings,
@NotNull GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
@NotNull String materialName, double newPrice,
@NotNull CommandSender sender) {
ItemType itemType = ItemType.MATERIAL;
String itemChanged;
//Update base price or price per durability point for an item
@@ -289,13 +298,14 @@ public class BlackSmithConfigCommand implements CommandExecutor {
/**
* Updates all materials matching the material name wildcard
*
* @param settings <p>The settings to modify</p>
* @param settings <p>The settings to modify</p>
* @param detectedGlobalBlacksmithSetting <p>The global setting specified</p>
* @param materialName <p>The wildcard material name to update cost for</p>
* @param newPrice <p>The new cost for the matched items</p>
* @param materialName <p>The wildcard material name to update cost for</p>
* @param newPrice <p>The new cost for the matched items</p>
*/
private void updateAllMatchedPrices(GlobalBlacksmithSettings settings, GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
String materialName, double newPrice) {
private void updateAllMatchedPrices(@NotNull GlobalBlacksmithSettings settings,
@NotNull GlobalBlacksmithSetting detectedGlobalBlacksmithSetting,
@NotNull String materialName, double newPrice) {
String search = InputParsingHelper.regExIfy(materialName);
for (Material material : ItemHelper.getAllReforgeAbleMaterials()) {
if (!material.name().matches(search)) {

View File

@@ -1,8 +1,8 @@
package net.knarcraft.blacksmith.command;
package net.knarcraft.blacksmith.command.blacksmith;
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.config.SettingValueType;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSetting;
import net.knarcraft.blacksmith.util.InputParsingHelper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -66,7 +66,7 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
* @param args <p>The arguments given by the user</p>
* @return <p>Null if not writing a spaced message</p>
*/
private List<String> skipCompletionForSpacedMessage(String[] args) {
private List<String> skipCompletionForSpacedMessage(@NotNull String[] args) {
if (args.length > 2) {
BlacksmithNPCSetting blacksmithNpcSetting = null;
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
@@ -86,10 +86,11 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
* Gets tab-completions for a selected material or enchantment
*
* @param globalBlacksmithSetting <p>The global setting to get tab-completions for</p>
* @param args <p>The arguments given by the user</p>
* @param args <p>The arguments given by the user</p>
* @return <p>The tab-completions to show to the user</p>
*/
private List<String> getPerTypeTabCompletions(GlobalBlacksmithSetting globalBlacksmithSetting, String[] args) {
private List<String> getPerTypeTabCompletions(@NotNull GlobalBlacksmithSetting globalBlacksmithSetting,
@NotNull String[] args) {
//Display possible tab-completions only if a valid enchantment or material is provided
if (((globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE ||
globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) &&
@@ -109,7 +110,7 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
* @param commandValue <p>The command value used to filter tab-completions</p>
* @return <p>Some valid options for the command's argument</p>
*/
private List<String> tabCompleteCommandValues(String commandName, String commandValue) {
private List<String> tabCompleteCommandValues(@NotNull String commandName, @NotNull String commandValue) {
if (commandName.equalsIgnoreCase("reload")) {
return new ArrayList<>();
}
@@ -131,12 +132,15 @@ public class BlackSmithConfigTabCompleter implements TabCompleter {
* Gets tab-completions for the given global setting and filters on the command value
*
* @param globalBlacksmithSetting <p>The global setting to get tab-completions for</p>
* @param commandValue <p>The command value used to filter between available tab-completions</p>
* @param commandValue <p>The command value used to filter between available tab-completions</p>
* @return <p>The available tab-completions</p>
*/
private List<String> getCompletions(GlobalBlacksmithSetting globalBlacksmithSetting, String commandValue) {
List<String> returnValues = filterMatchingContains(getTabCompletions(globalBlacksmithSetting.getValueType()), commandValue);
if (globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE || globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) {
private List<String> getCompletions(@NotNull GlobalBlacksmithSetting globalBlacksmithSetting,
@NotNull String commandValue) {
List<String> returnValues = filterMatchingContains(
getTabCompletions(globalBlacksmithSetting.getValueType()), commandValue);
if (globalBlacksmithSetting == GlobalBlacksmithSetting.BASE_PRICE ||
globalBlacksmithSetting == GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT) {
returnValues.addAll(filterMatchingContains(getTabCompletions(SettingValueType.MATERIAL), commandValue));
} else if (globalBlacksmithSetting == GlobalBlacksmithSetting.ENCHANTMENT_COST) {
returnValues.addAll(filterMatchingContains(getTabCompletions(SettingValueType.ENCHANTMENT), commandValue));

View File

@@ -1,10 +1,10 @@
package net.knarcraft.blacksmith.command;
package net.knarcraft.blacksmith.command.blacksmith;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.config.SettingValueType;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
import net.knarcraft.blacksmith.util.InputParsingHelper;
@@ -14,6 +14,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -58,14 +59,16 @@ public class BlackSmithEditCommand implements CommandExecutor {
/**
* Changes the given NPC setting, or displays the current value if a new value isn't specified
*
* @param blacksmithTrait <p>The blacksmith trait belonging to the selected NPC</p>
* @param blacksmithNpcSetting <p>The NPC setting to change</p>
* @param newValue <p>The value to change the setting to</p>
* @param sender <p>The command sender to notify about results</p>
* @param blacksmithTrait <p>The blacksmith trait belonging to the selected NPC</p>
* @param blacksmithNpcSetting <p>The NPC setting to change</p>
* @param newValue <p>The value to change the setting to</p>
* @param sender <p>The command sender to notify about results</p>
* @return <p>True if everything went successfully</p>
*/
private boolean displayOrChangeNPCSetting(BlacksmithTrait blacksmithTrait, BlacksmithNPCSetting blacksmithNpcSetting, String newValue,
CommandSender sender) {
private boolean displayOrChangeNPCSetting(@NotNull BlacksmithTrait blacksmithTrait,
@NotNull BlacksmithNPCSetting blacksmithNpcSetting,
@Nullable String newValue,
@NotNull CommandSender sender) {
if (newValue == null) {
//Display the current value of the setting
displayNPCSetting(blacksmithTrait, blacksmithNpcSetting, sender);
@@ -95,15 +98,17 @@ public class BlackSmithEditCommand implements CommandExecutor {
/**
* Displays the current value of the given NPC setting
*
* @param blacksmithTrait <p>The blacksmith trait of the NPC to get the value from</p>
* @param blacksmithNpcSetting <p>The NPC setting to see the value of</p>
* @param sender <p>The command sender to display the value to</p>
* @param blacksmithTrait <p>The blacksmith trait of the NPC to get the value from</p>
* @param blacksmithNpcSetting <p>The NPC setting to see the value of</p>
* @param sender <p>The command sender to display the value to</p>
*/
private void displayNPCSetting(BlacksmithTrait blacksmithTrait, BlacksmithNPCSetting blacksmithNpcSetting, CommandSender sender) {
private void displayNPCSetting(@NotNull BlacksmithTrait blacksmithTrait,
@NotNull BlacksmithNPCSetting blacksmithNpcSetting, @NotNull CommandSender sender) {
String rawValue = String.valueOf(blacksmithTrait.getSettings().getRawValue(blacksmithNpcSetting));
if (InputParsingHelper.isEmpty(rawValue)) {
//Display the default value, if no custom value has been specified
rawValue = String.valueOf(BlacksmithPlugin.getInstance().getSettings().getRawValue(blacksmithNpcSetting));
rawValue = String.valueOf(BlacksmithPlugin.getInstance().getGlobalBlacksmithSettings().getRawValue(
blacksmithNpcSetting));
BlacksmithPlugin.getStringFormatter().displaySuccessMessage(sender,
getCurrentValueMessage(blacksmithNpcSetting.getCommandName(), rawValue));
} else {

View File

@@ -1,4 +1,4 @@
package net.knarcraft.blacksmith.command;
package net.knarcraft.blacksmith.command.blacksmith;
import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSetting;
import net.knarcraft.blacksmith.util.TabCompleteValuesHelper;
@@ -17,10 +17,9 @@ import java.util.List;
*/
public class BlackSmithEditTabCompleter implements TabCompleter {
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
if (!sender.hasPermission("blacksmith.edit")) {
return new ArrayList<>();
}
@@ -48,7 +47,7 @@ public class BlackSmithEditTabCompleter implements TabCompleter {
* @param commandValue <p>The command value used to filter tab-completions</p>
* @return <p>Some valid options for the command's argument</p>
*/
private List<String> tabCompleteCommandValues(String commandName, String commandValue) {
private @Nullable List<String> tabCompleteCommandValues(@NotNull String commandName, @NotNull String commandValue) {
for (BlacksmithNPCSetting blacksmithNpcSetting : BlacksmithNPCSetting.values()) {
if (blacksmithNpcSetting.getCommandName().equalsIgnoreCase(commandName)) {
return TabCompletionHelper.filterMatchingContains(TabCompleteValuesHelper.getTabCompletions(

View File

@@ -0,0 +1,17 @@
package net.knarcraft.blacksmith.command.scrapper;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class ScrapperConfigCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] strings) {
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,20 @@
package net.knarcraft.blacksmith.command.scrapper;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class ScrapperConfigTabCompleter implements TabCompleter {
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command,
@NotNull String s, @NotNull String[] strings) {
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,15 @@
package net.knarcraft.blacksmith.command.scrapper;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class ScrapperEditCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] strings) {
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,18 @@
package net.knarcraft.blacksmith.command.scrapper;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class ScrapperEditTabCompleter implements TabCompleter {
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command,
@NotNull String s, @NotNull String[] strings) {
throw new NotImplementedException();
}
}