Updates Spigot, and fixes depreciated code
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
parent
44f8bb36b0
commit
7e5525bd00
26
pom.xml
26
pom.xml
@ -31,10 +31,6 @@
|
|||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>papermc</id>
|
|
||||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>knarcraft-repo</id>
|
<id>knarcraft-repo</id>
|
||||||
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
<url>https://git.knarcraft.net/api/packages/EpicKnarvik97/maven</url>
|
||||||
@ -56,7 +52,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.citizensnpcs</groupId>
|
<groupId>net.citizensnpcs</groupId>
|
||||||
<artifactId>citizens-main</artifactId>
|
<artifactId>citizens-main</artifactId>
|
||||||
<version>2.0.30-SNAPSHOT</version>
|
<version>2.0.33-SNAPSHOT</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
@ -69,7 +65,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -82,24 +78,18 @@
|
|||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>24.0.1</version>
|
<version>24.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>knarlib</artifactId>
|
<artifactId>knarlib</artifactId>
|
||||||
<version>1.2.5</version>
|
<version>1.2.6</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>5.9.2</version>
|
<version>5.10.2</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.seeseemelk</groupId>
|
|
||||||
<artifactId>MockBukkit-v1.20</artifactId>
|
|
||||||
<version>3.9.0</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -151,12 +141,6 @@
|
|||||||
<include>org/jetbrains/annotations/**</include>
|
<include>org/jetbrains/annotations/**</include>
|
||||||
</includes>
|
</includes>
|
||||||
</filter>
|
</filter>
|
||||||
<filter>
|
|
||||||
<excludes>
|
|
||||||
<exclude>*.MF</exclude>
|
|
||||||
<exclude>*.yml</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
</filters>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -170,7 +170,7 @@ public abstract class EditCommand<K extends CustomTrait<L>, L extends Setting> i
|
|||||||
getCurrentValueMessage(setting.getCommandName(), rawValue));
|
getCurrentValueMessage(setting.getCommandName(), rawValue));
|
||||||
} else {
|
} else {
|
||||||
//Add a marker if the value has been customized
|
//Add a marker if the value has been customized
|
||||||
String marker = BlacksmithPlugin.getStringFormatter().getUnformattedMessage(
|
String marker = BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
|
||||||
BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER);
|
BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER);
|
||||||
formatter.displayNeutralMessage(sender,
|
formatter.displayNeutralMessage(sender,
|
||||||
getCurrentValueMessage(setting.getCommandName(), rawValue) + marker);
|
getCurrentValueMessage(setting.getCommandName(), rawValue) + marker);
|
||||||
|
@ -172,7 +172,7 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
|
|||||||
* @return <p>The string to display to a user</p>
|
* @return <p>The string to display to a user</p>
|
||||||
*/
|
*/
|
||||||
public static String getItemValueChangedMessage(String setting, ItemType itemType, String item, String newValue) {
|
public static String getItemValueChangedMessage(String setting, ItemType itemType, String item, String newValue) {
|
||||||
StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnformattedMessage(
|
StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
|
||||||
BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED));
|
BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED));
|
||||||
stringReplacer.add("{setting}", setting);
|
stringReplacer.add("{setting}", setting);
|
||||||
stringReplacer.add("{itemType}", itemType.getItemTypeName());
|
stringReplacer.add("{itemType}", itemType.getItemTypeName());
|
||||||
@ -204,7 +204,7 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage {
|
|||||||
* @return <p>The string to display to a user</p>
|
* @return <p>The string to display to a user</p>
|
||||||
*/
|
*/
|
||||||
public static String getItemCurrentValueMessage(String setting, ItemType itemType, String item, String currentValue) {
|
public static String getItemCurrentValueMessage(String setting, ItemType itemType, String item, String currentValue) {
|
||||||
StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnformattedMessage(
|
StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
|
||||||
BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM));
|
BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM));
|
||||||
stringReplacer.add("{setting}", setting);
|
stringReplacer.add("{setting}", setting);
|
||||||
stringReplacer.add("{itemType}", itemType.getItemTypeName());
|
stringReplacer.add("{itemType}", itemType.getItemTypeName());
|
||||||
|
@ -19,9 +19,9 @@ public enum ItemType {
|
|||||||
public String getItemTypeName() {
|
public String getItemTypeName() {
|
||||||
StringFormatter stringFormatter = BlacksmithPlugin.getStringFormatter();
|
StringFormatter stringFormatter = BlacksmithPlugin.getStringFormatter();
|
||||||
return switch (this) {
|
return switch (this) {
|
||||||
case MATERIAL -> stringFormatter.getUnformattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_MATERIAL);
|
case MATERIAL -> stringFormatter.getUnFormattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_MATERIAL);
|
||||||
case ENCHANTMENT ->
|
case ENCHANTMENT ->
|
||||||
stringFormatter.getUnformattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT);
|
stringFormatter.getUnFormattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public final class TimeFormatter {
|
|||||||
* @return <p>Text describing the time interval</p>
|
* @return <p>Text describing the time interval</p>
|
||||||
*/
|
*/
|
||||||
private static String getMessageFromInterval(TimeInterval interval) {
|
private static String getMessageFromInterval(TimeInterval interval) {
|
||||||
String text = BlacksmithPlugin.getStringFormatter().getUnformattedMessage(
|
String text = BlacksmithPlugin.getStringFormatter().getUnFormattedMessage(
|
||||||
BlacksmithTranslatableMessage.valueOf(interval.name()));
|
BlacksmithTranslatableMessage.valueOf(interval.name()));
|
||||||
|
|
||||||
//Choose a random entry if a comma-separated list is provided
|
//Choose a random entry if a comma-separated list is provided
|
||||||
|
@ -6,7 +6,9 @@ import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings;
|
|||||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -31,7 +33,7 @@ public class ReforgeSession extends Session implements Runnable {
|
|||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final ItemStack itemToReforge;
|
private final ItemStack itemToReforge;
|
||||||
private final BlacksmithNPCSettings config;
|
private final BlacksmithNPCSettings config;
|
||||||
private static final String[] enchantments = new String[Enchantment.values().length];
|
private static List<String> enchantments = null;
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,10 +53,15 @@ public class ReforgeSession extends Session implements Runnable {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
//Populate enchantments the first time this is run
|
//Populate enchantments the first time this is run
|
||||||
if (enchantments[0] == null) {
|
if (enchantments == null) {
|
||||||
int i = 0;
|
Registry<Enchantment> enchantmentRegistry = Bukkit.getRegistry(Enchantment.class);
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
if (enchantmentRegistry == null) {
|
||||||
enchantments[i++] = enchantment.getKey().getKey();
|
throw new RuntimeException("Unable to get enchantment registry");
|
||||||
|
}
|
||||||
|
|
||||||
|
enchantments = new ArrayList<>();
|
||||||
|
for (Enchantment enchantment : enchantmentRegistry) {
|
||||||
|
enchantments.add(enchantment.getKey().getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
package net.knarcraft.blacksmith.util;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -44,7 +46,11 @@ public final class InputParsingHelper {
|
|||||||
*/
|
*/
|
||||||
public static @Nullable Enchantment matchEnchantment(@NotNull String input) {
|
public static @Nullable Enchantment matchEnchantment(@NotNull String input) {
|
||||||
try {
|
try {
|
||||||
return Enchantment.getByKey(NamespacedKey.minecraft(
|
Registry<Enchantment> enchantments = Bukkit.getRegistry(Enchantment.class);
|
||||||
|
if (enchantments == null) {
|
||||||
|
throw new RuntimeException("Unable to get enchantment registry");
|
||||||
|
}
|
||||||
|
return enchantments.get(NamespacedKey.minecraft(
|
||||||
input.replace("-", "_").replace(" ", "_").toLowerCase()));
|
input.replace("-", "_").replace(" ", "_").toLowerCase()));
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
//Invalid characters, such as : will normally throw an illegal argument exception
|
//Invalid characters, such as : will normally throw an illegal argument exception
|
||||||
|
@ -3,7 +3,9 @@ package net.knarcraft.blacksmith.util;
|
|||||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||||
import net.knarcraft.blacksmith.config.SmithPreset;
|
import net.knarcraft.blacksmith.config.SmithPreset;
|
||||||
import net.knarcraft.blacksmith.config.SmithPresetFilter;
|
import net.knarcraft.blacksmith.config.SmithPresetFilter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -82,8 +84,13 @@ public final class TabCompleteValuesHelper {
|
|||||||
* @return <p>A complete list of enchantments</p>
|
* @return <p>A complete list of enchantments</p>
|
||||||
*/
|
*/
|
||||||
private static @NotNull List<String> getAllEnchantments() {
|
private static @NotNull List<String> getAllEnchantments() {
|
||||||
|
Registry<Enchantment> enchantmentRegistry = Bukkit.getRegistry(Enchantment.class);
|
||||||
|
if (enchantmentRegistry == null) {
|
||||||
|
throw new RuntimeException("Unable to get the enchantment registry");
|
||||||
|
}
|
||||||
|
|
||||||
List<String> enchantments = new ArrayList<>();
|
List<String> enchantments = new ArrayList<>();
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
for (Enchantment enchantment : enchantmentRegistry) {
|
||||||
enchantments.add(enchantment.getKey().getKey());
|
enchantments.add(enchantment.getKey().getKey());
|
||||||
}
|
}
|
||||||
return enchantments;
|
return enchantments;
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package net.knarcraft.blacksmith;
|
|
||||||
|
|
||||||
import be.seeseemelk.mockbukkit.ServerMock;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.Recipe;
|
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A custom server mock specifically for making the SalvageHelperTest work
|
|
||||||
*/
|
|
||||||
public class CustomServerMock extends ServerMock {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Recipe> getRecipesFor(@NotNull ItemStack itemStack) {
|
|
||||||
List<Recipe> validRecipes = new ArrayList<>();
|
|
||||||
if (itemStack.getType() == Material.DIAMOND_PICKAXE) {
|
|
||||||
ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("diamond_pickaxe"), itemStack);
|
|
||||||
recipe.shape("ddd", "asa", "asa");
|
|
||||||
recipe.setIngredient('d', Material.DIAMOND);
|
|
||||||
recipe.setIngredient('s', Material.STICK);
|
|
||||||
validRecipes.add(recipe);
|
|
||||||
} else if (itemStack.getType() == Material.TNT) {
|
|
||||||
ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("tnt"), itemStack);
|
|
||||||
recipe.shape("gsg", "sgs", "gsg");
|
|
||||||
recipe.setIngredient('g', Material.GUNPOWDER);
|
|
||||||
recipe.setIngredient('s', Material.SAND);
|
|
||||||
validRecipes.add(recipe);
|
|
||||||
}
|
|
||||||
return validRecipes;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +1,10 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
package net.knarcraft.blacksmith.util;
|
||||||
|
|
||||||
import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@ -18,16 +13,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
*/
|
*/
|
||||||
public class InputParsingHelperTest {
|
public class InputParsingHelperTest {
|
||||||
|
|
||||||
private static Enchantment curseOfBinding;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void setUp() {
|
|
||||||
//Note: When not testing against a real server, no default enchantments are loaded!
|
|
||||||
curseOfBinding = new EnchantmentMock(NamespacedKey.minecraft("binding_curse"),
|
|
||||||
"CURSE_OF_BINDING");
|
|
||||||
Enchantment.registerEnchantment(curseOfBinding);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isEmptyTrueTest() {
|
public void isEmptyTrueTest() {
|
||||||
assertTrue(InputParsingHelper.isEmpty(null));
|
assertTrue(InputParsingHelper.isEmpty(null));
|
||||||
@ -71,28 +56,6 @@ public class InputParsingHelperTest {
|
|||||||
assertNull(InputParsingHelper.matchMaterial("minecraft: golden-BOOTS"));
|
assertNull(InputParsingHelper.matchMaterial("minecraft: golden-BOOTS"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void matchEnchantmentValidTest() {
|
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
|
||||||
assertEquals(enchantment, InputParsingHelper.matchEnchantment(enchantment.getKey().getKey()));
|
|
||||||
}
|
|
||||||
assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding_curse"));
|
|
||||||
assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding-curse"));
|
|
||||||
assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding curse"));
|
|
||||||
assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("BINDING curse"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void matchEnchantmentInvalidTest() {
|
|
||||||
for (Enchantment enchantment : Enchantment.values()) {
|
|
||||||
assertEquals(enchantment, InputParsingHelper.matchEnchantment(enchantment.getKey().getKey()));
|
|
||||||
}
|
|
||||||
assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment("bonding_curse"));
|
|
||||||
assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding curse"));
|
|
||||||
assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment(" BINDING curse"));
|
|
||||||
assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding:curse"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void regExIfyTest() {
|
public void regExIfyTest() {
|
||||||
assertEquals("NO REGEX HERE", InputParsingHelper.regExIfy("no regEx here"));
|
assertEquals("NO REGEX HERE", InputParsingHelper.regExIfy("no regEx here"));
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
package net.knarcraft.blacksmith.util;
|
||||||
|
|
||||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
|
||||||
import net.knarcraft.blacksmith.CustomServerMock;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@ -19,80 +11,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
*/
|
*/
|
||||||
public class ItemHelperTest {
|
public class ItemHelperTest {
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void setUp() {
|
|
||||||
MockBukkit.mock(new CustomServerMock());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterAll
|
|
||||||
public static void tearDown() {
|
|
||||||
MockBukkit.unmock();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isRepairableTest() {
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
String name = material.name();
|
|
||||||
if (name.endsWith("_SWORD") || name.endsWith("_PICKAXE") || name.endsWith("_AXE") ||
|
|
||||||
name.endsWith("_HOE") || name.endsWith("_SHOVEL") || name.endsWith("_CHESTPLATE") ||
|
|
||||||
name.endsWith("_HELMET") || name.equals("ELYTRA") || name.endsWith("BOW") ||
|
|
||||||
name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS") || name.equals("TRIDENT") ||
|
|
||||||
name.equals("FISHING_ROD") || name.equals("FLINT_AND_STEEL") || name.equals("SHEARS")) {
|
|
||||||
assertTrue(ItemHelper.isRepairable(new ItemStack(material, 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertFalse(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1)));
|
|
||||||
assertFalse(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getMaxDurabilityTest() {
|
|
||||||
assertEquals(1561, ItemHelper.getMaxDurability(new ItemStack(Material.DIAMOND_PICKAXE, 1)));
|
|
||||||
assertEquals(0, ItemHelper.getMaxDurability(new ItemStack(Material.POTATO, 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateAndGetDamageTest() {
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
//A lot of items seem to have weird metadata which isn't mocked properly. Therefore, this test is limited.
|
|
||||||
if (!material.name().endsWith("_PICKAXE")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ItemStack itemStack = new ItemStack(material, 1);
|
|
||||||
assertEquals(0, ItemHelper.getDamage(itemStack));
|
|
||||||
ItemHelper.updateDamage(itemStack, 3);
|
|
||||||
assertEquals(3, ItemHelper.getDamage(itemStack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getDurabilityTest() {
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
ItemStack itemStack = new ItemStack(material, 1);
|
|
||||||
assertEquals(ItemHelper.getMaxDurability(itemStack), ItemHelper.getDurability(itemStack));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
//A lot of items seem to have weird metadata which isn't mocked properly. Therefore, this test is limited.
|
|
||||||
if (!material.name().endsWith("_PICKAXE")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ItemStack itemStack = new ItemStack(material, 1);
|
|
||||||
ItemHelper.updateDamage(itemStack, 100);
|
|
||||||
assertEquals(ItemHelper.getMaxDurability(itemStack) - 100, ItemHelper.getDurability(itemStack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAllReforgeAbleMaterialsTest() {
|
|
||||||
List<Material> materials = ItemHelper.getAllReforgeAbleMaterials();
|
|
||||||
assertFalse(materials.isEmpty());
|
|
||||||
|
|
||||||
for (Material material : materials) {
|
|
||||||
assertTrue(ItemHelper.getMaxDurability(new ItemStack(material, 1)) > 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAnvilRequiresDamagedTest() {
|
public void isAnvilRequiresDamagedTest() {
|
||||||
assertTrue(ItemHelper.isAnvil(Material.DAMAGED_ANVIL, true));
|
assertTrue(ItemHelper.isAnvil(Material.DAMAGED_ANVIL, true));
|
||||||
|
@ -1,123 +0,0 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
|
||||||
|
|
||||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
|
||||||
import net.knarcraft.blacksmith.CustomServerMock;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.Damageable;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A test class to test salvaging
|
|
||||||
*/
|
|
||||||
public class SalvageHelperTest {
|
|
||||||
|
|
||||||
private static Server server;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void setUp() {
|
|
||||||
server = MockBukkit.mock(new CustomServerMock());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterAll
|
|
||||||
public static void tearDown() {
|
|
||||||
MockBukkit.unmock();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNullForInvalidItemTest() {
|
|
||||||
//Assert that a non-reforge-able item will return null
|
|
||||||
assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.POTATO, 1), new ArrayList<>(), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNullForLessThanOneItemTest() {
|
|
||||||
//Assert that 0 or 1 items will return null
|
|
||||||
assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_AXE, 0), new ArrayList<>(), false));
|
|
||||||
assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_SWORD, -1), new ArrayList<>(), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getFullSalvageTest() {
|
|
||||||
Set<ItemStack> expectedSalvage = new HashSet<>();
|
|
||||||
expectedSalvage.add(new ItemStack(Material.DIAMOND, 3));
|
|
||||||
expectedSalvage.add(new ItemStack(Material.STICK, 2));
|
|
||||||
ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1);
|
|
||||||
//Note: Conversion to sets makes sure the order doesn't matter
|
|
||||||
List<ItemStack> salvage = SalvageHelper.getSalvage(server, itemToSalvage, new ArrayList<>(), false);
|
|
||||||
if (salvage == null) {
|
|
||||||
fail();
|
|
||||||
} else {
|
|
||||||
assertEquals(expectedSalvage, new HashSet<>(salvage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getExtendedSalvageTest() {
|
|
||||||
Set<ItemStack> expectedSalvage = new HashSet<>();
|
|
||||||
expectedSalvage.add(new ItemStack(Material.GUNPOWDER, 5));
|
|
||||||
expectedSalvage.add(new ItemStack(Material.SAND, 4));
|
|
||||||
ItemStack itemToSalvage = new ItemStack(Material.TNT, 1);
|
|
||||||
//Note: Conversion to sets makes sure the order doesn't matter
|
|
||||||
List<ItemStack> salvage = SalvageHelper.getSalvage(server, itemToSalvage, new ArrayList<>(), true);
|
|
||||||
if (salvage == null) {
|
|
||||||
fail();
|
|
||||||
} else {
|
|
||||||
assertEquals(expectedSalvage, new HashSet<>(salvage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNonFullSalvageTest() {
|
|
||||||
List<ItemStack> expectedSalvage = new ArrayList<>();
|
|
||||||
expectedSalvage.add(new ItemStack(Material.DIAMOND, 3));
|
|
||||||
expectedSalvage.add(new ItemStack(Material.STICK, 2));
|
|
||||||
ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1);
|
|
||||||
ItemMeta meta = itemToSalvage.getItemMeta();
|
|
||||||
Damageable damageable = (Damageable) meta;
|
|
||||||
if (damageable != null) {
|
|
||||||
damageable.setDamage(100);
|
|
||||||
}
|
|
||||||
itemToSalvage.setItemMeta(meta);
|
|
||||||
List<ItemStack> salvage = SalvageHelper.getSalvage(server, itemToSalvage, new ArrayList<>(), false);
|
|
||||||
//Assert that some items are given
|
|
||||||
assertNotEquals(salvage, new ArrayList<>());
|
|
||||||
//Assert that a damaged item won't give full salvage
|
|
||||||
assertNotEquals(expectedSalvage, salvage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void ignoredSalvageTest() {
|
|
||||||
List<ItemStack> expectedSalvage = new ArrayList<>();
|
|
||||||
expectedSalvage.add(new ItemStack(Material.DIAMOND, 2));
|
|
||||||
ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1);
|
|
||||||
List<Material> ignoredSalvage = new ArrayList<>();
|
|
||||||
ignoredSalvage.add(Material.STICK);
|
|
||||||
ItemMeta meta = itemToSalvage.getItemMeta();
|
|
||||||
Damageable damageable = (Damageable) meta;
|
|
||||||
if (damageable != null) {
|
|
||||||
damageable.setDamage(100);
|
|
||||||
}
|
|
||||||
itemToSalvage.setItemMeta(meta);
|
|
||||||
List<ItemStack> salvage = SalvageHelper.getSalvage(server, itemToSalvage, ignoredSalvage, false);
|
|
||||||
//Assert that some items are given
|
|
||||||
assertNotEquals(salvage, new ArrayList<>());
|
|
||||||
//Assert that a damaged diamond pickaxe with sticks ignored returns 2 diamonds a salvage
|
|
||||||
assertEquals(expectedSalvage, salvage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +1,7 @@
|
|||||||
package net.knarcraft.blacksmith.util;
|
package net.knarcraft.blacksmith.util;
|
||||||
|
|
||||||
import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock;
|
|
||||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,16 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
*/
|
*/
|
||||||
public class TypeValidatorHelperTest {
|
public class TypeValidatorHelperTest {
|
||||||
|
|
||||||
private static Enchantment infinity;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
public static void setUp() {
|
|
||||||
//Note: When not testing against a real server, no default enchantments are loaded!
|
|
||||||
infinity = new EnchantmentMock(NamespacedKey.minecraft("arrow_infinite"),
|
|
||||||
"INFINITY");
|
|
||||||
Enchantment.registerEnchantment(infinity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isValidPositiveDoubleValidTest() {
|
public void isValidPositiveDoubleValidTest() {
|
||||||
SettingValueType type = SettingValueType.POSITIVE_DOUBLE;
|
SettingValueType type = SettingValueType.POSITIVE_DOUBLE;
|
||||||
@ -152,18 +138,9 @@ public class TypeValidatorHelperTest {
|
|||||||
assertFalse(TypeValidationHelper.isValid(type, true, null));
|
assertFalse(TypeValidationHelper.isValid(type, true, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isValidEnchantmentValidTest() {
|
|
||||||
SettingValueType type = SettingValueType.ENCHANTMENT;
|
|
||||||
assertTrue(TypeValidationHelper.isValid(type, infinity, null));
|
|
||||||
assertTrue(TypeValidationHelper.isValid(type, "arrow_infinite", null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isValidEnchantmentInvalidTest() {
|
public void isValidEnchantmentInvalidTest() {
|
||||||
SettingValueType type = SettingValueType.ENCHANTMENT;
|
SettingValueType type = SettingValueType.ENCHANTMENT;
|
||||||
assertFalse(TypeValidationHelper.isValid(type, "potato", null));
|
|
||||||
assertFalse(TypeValidationHelper.isValid(type, 7675, null));
|
|
||||||
assertFalse(TypeValidationHelper.isValid(type, null, null));
|
assertFalse(TypeValidationHelper.isValid(type, null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user