mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Update to mockbukkit 4.3.1
This commit is contained in:
parent
7d8b733cc7
commit
366b4d3e3f
9 changed files with 29 additions and 126 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package io.delilaheve.util;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import be.seeseemelk.mockbukkit.inventory.ItemStackMock;
|
||||
import org.mockbukkit.mockbukkit.entity.PlayerMock;
|
||||
import org.mockbukkit.mockbukkit.inventory.ItemStackMock;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
|
@ -12,7 +12,6 @@ import org.bukkit.permissions.PermissionAttachment;
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.tests.ConfigResetCustomAnvilTest;
|
||||
import xyz.alexcrea.cuanvil.util.AnvilFuseTestData;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.anvil;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.mockbukkit.mockbukkit.entity.PlayerMock;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.AnvilInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.api;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.mockbukkit.mockbukkit.entity.PlayerMock;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.mock;
|
||||
|
||||
import be.seeseemelk.mockbukkit.inventory.PlayerInventoryViewMock;
|
||||
import org.mockbukkit.mockbukkit.inventory.PlayerInventoryViewMock;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.AnvilInventory;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.mock;
|
||||
|
||||
import be.seeseemelk.mockbukkit.inventory.meta.ItemMetaMock;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EnchantedItemMetaMock extends ItemMetaMock implements EnchantmentStorageMeta {
|
||||
|
||||
|
||||
public EnchantedItemMetaMock() {
|
||||
|
||||
}
|
||||
|
||||
public EnchantedItemMetaMock(@NotNull ItemMeta meta) {
|
||||
super(meta);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasStoredEnchants() {
|
||||
return super.hasEnchants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStoredEnchant(@NotNull Enchantment ench) {
|
||||
return super.hasEnchant(ench);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredEnchantLevel(@NotNull Enchantment ench) {
|
||||
return super.getEnchantLevel(ench);
|
||||
}
|
||||
|
||||
// badly imitate paper (and I hope spigot) behavior and avoid concurrent modification exception
|
||||
@Override
|
||||
public @NotNull Map<Enchantment, Integer> getStoredEnchants() {
|
||||
return ImmutableMap.copyOf(super.getEnchants());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addStoredEnchant(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction) {
|
||||
return super.addEnchant(ench, level, ignoreLevelRestriction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeStoredEnchant(@NotNull Enchantment ench) throws IllegalArgumentException {
|
||||
return super.removeEnchant(ench);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasConflictingStoredEnchant(@NotNull Enchantment ench) {
|
||||
return super.hasConflictingEnchant(ench);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EnchantedItemMetaMock clone() {
|
||||
// Not ideal but we do with what we have
|
||||
return new EnchantedItemMetaMock(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +1,29 @@
|
|||
package xyz.alexcrea.cuanvil.mock;
|
||||
|
||||
import be.seeseemelk.mockbukkit.inventory.ItemStackMock;
|
||||
import be.seeseemelk.mockbukkit.inventory.meta.ItemMetaMock;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.mockbukkit.mockbukkit.inventory.ItemStackMock;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnchantedItemStackMock extends ItemStackMock {
|
||||
|
||||
public EnchantedItemStackMock(@NotNull Material type, int amount) {
|
||||
super(type, amount);
|
||||
updateItemMeta();
|
||||
}
|
||||
|
||||
public EnchantedItemStackMock(@NotNull Material type) {
|
||||
this(type, 1);
|
||||
updateItemMeta();
|
||||
}
|
||||
|
||||
public EnchantedItemStackMock(@NotNull ItemStack stack) throws IllegalArgumentException {
|
||||
public EnchantedItemStackMock(@NotNull ItemStack stack) {
|
||||
super(stack);
|
||||
updateItemMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeEnchantment(@NotNull Enchantment ench) {
|
||||
if(!this.hasItemMeta()) return 0;
|
||||
|
||||
int level = this.getEnchantmentLevel(ench);
|
||||
this.getItemMeta().removeEnchant(ench);
|
||||
|
||||
|
|
@ -39,13 +32,16 @@ public class EnchantedItemStackMock extends ItemStackMock {
|
|||
|
||||
@Override
|
||||
public void removeEnchantments() {
|
||||
if(!this.hasItemMeta()) return;
|
||||
|
||||
this.getItemMeta().removeEnchantments();
|
||||
}
|
||||
|
||||
// badly imitate paper (and I hope spigot) behavior and avoid concurrent modification exception
|
||||
@Override
|
||||
public @NotNull Map<Enchantment, Integer> getEnchantments() {
|
||||
return ImmutableMap.copyOf(super.getEnchantments());
|
||||
public boolean equals(Object obj) {
|
||||
if(!super.equals(obj)) return false;
|
||||
|
||||
return getItemMeta().equals(((ItemStack)obj).getItemMeta());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,41 +49,9 @@ public class EnchantedItemStackMock extends ItemStackMock {
|
|||
EnchantedItemStackMock clone = new EnchantedItemStackMock(this.getType());
|
||||
|
||||
clone.setAmount(this.getAmount());
|
||||
clone.setItemMeta(this.getItemMeta());
|
||||
clone.setDurability(this.getDurability());
|
||||
clone.setItemMeta(this.hasItemMeta() ? this.getItemMeta().clone() : null);
|
||||
clone.updateItemMeta();
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(@NotNull Material type) {
|
||||
super.setType(type);
|
||||
updateItemMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setItemMeta(@Nullable ItemMeta itemMeta) {
|
||||
boolean success = super.setItemMeta(itemMeta);
|
||||
updateItemMeta();
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDurability(short durability) {
|
||||
if(getType().getMaxDurability() == 0) return;
|
||||
super.setDurability(durability);
|
||||
}
|
||||
|
||||
private void updateItemMeta() {
|
||||
super.setItemMeta(updateItemMeta(getType(), getItemMeta()));
|
||||
}
|
||||
|
||||
private static @Nullable ItemMeta updateItemMeta(Material material, ItemMeta oldMeta) {
|
||||
if(oldMeta == null) return null;
|
||||
if(material != Material.ENCHANTED_BOOK) return oldMeta;
|
||||
if(oldMeta instanceof ItemMetaMock) return new EnchantedItemMetaMock(oldMeta);
|
||||
|
||||
return oldMeta;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.tests;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import org.mockbukkit.mockbukkit.MockBukkit;
|
||||
import org.mockbukkit.mockbukkit.ServerMock;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
|
|||
|
|
@ -90,8 +90,7 @@ public class AnvilFuseTestUtil {
|
|||
new PrepareAnvilListener().anvilCombineCheck(event);
|
||||
anvil.setResult(event.getResult());
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
Assertions.fail();
|
||||
Assertions.fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,8 +140,15 @@ public class AnvilFuseTestUtil {
|
|||
}
|
||||
|
||||
public static void assertEqual(@Nullable ItemStack item1, @Nullable ItemStack item2) {
|
||||
if(isAir(item1)) Assertions.assertTrue(isAir(item2),"Item "+item2+" was not AIR but was expected to be air");
|
||||
else Assertions.assertEquals(item1, item2);
|
||||
boolean secondIsAir = isAir(item2);
|
||||
if(isAir(item1)) Assertions.assertTrue(secondIsAir,"Item "+item2+" was not AIR but was expected to be air");
|
||||
else {
|
||||
Assertions.assertFalse(secondIsAir,"Item "+item2+" was expected not to be air");
|
||||
|
||||
item1.setDurability(item1.getDurability());
|
||||
item2.setDurability(item2.getDurability());
|
||||
Assertions.assertEquals(item1, item2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue