added more shit

This commit is contained in:
beaness 2022-07-02 17:33:32 +02:00
parent faf402abe9
commit 4dbe6b1853
35 changed files with 27 additions and 3008 deletions

View File

@ -28,6 +28,10 @@ public class PacketPlayInClientCommand implements Packet<PacketListenerPlayIn> {
return this.a; return this.a;
} }
public PacketPlayInClientCommand.EnumClientCommand getCommand() {
return a;
}
public static enum EnumClientCommand { public static enum EnumClientCommand {
PERFORM_RESPAWN, REQUEST_STATS, OPEN_INVENTORY_ACHIEVEMENT; PERFORM_RESPAWN, REQUEST_STATS, OPEN_INVENTORY_ACHIEVEMENT;

View File

@ -28,6 +28,18 @@ public class PacketPlayOutEntityEquipment implements Packet<PacketListenerPlayOu
packetdataserializer.a(this.c); packetdataserializer.a(this.c);
} }
public int getId() {
return a;
}
public int getSlot() {
return b;
}
public ItemStack getItem() {
return c;
}
public void a(PacketListenerPlayOut packetlistenerplayout) { public void a(PacketListenerPlayOut packetlistenerplayout) {
packetlistenerplayout.a(this); packetlistenerplayout.a(this);
} }

View File

@ -967,6 +967,17 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
// CraftBukkit end // CraftBukkit end
try { try {
// Loop through cancellable handlers first
for (PacketHandler handler : eSpigot.getInstance().getPacketHandlers()) {
try {
if (!handler.handleSentPacketCancellable(this, packet)) {
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Loop through normal handlers // Loop through normal handlers
for (PacketHandler handler : eSpigot.getInstance().getPacketHandlers()) { for (PacketHandler handler : eSpigot.getInstance().getPacketHandlers()) {
handler.handleSentPacket(this, packet); handler.handleSentPacket(this, packet);

View File

@ -1,65 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import net.minecraft.server.EntityPainting.EnumArt;
import org.bukkit.craftbukkit.CraftArt;
import org.junit.Test;
import com.google.common.collect.Lists;
public class ArtTest {
private static final int UNIT_MULTIPLIER = 16;
@Test
public void verifyMapping() {
List<Art> arts = Lists.newArrayList(Art.values());
for (EnumArt enumArt : EnumArt.values()) {
int id = enumArt.ordinal();
String name = enumArt.B;
int width = enumArt.C / UNIT_MULTIPLIER;
int height = enumArt.D / UNIT_MULTIPLIER;
Art subject = Art.getById(id);
String message = String.format("org.bukkit.Art is missing id: %d named: '%s'", id, name);
assertNotNull(message, subject);
assertThat(Art.getByName(name), is(subject));
assertThat("Art." + subject + "'s width", subject.getBlockWidth(), is(width));
assertThat("Art." + subject + "'s height", subject.getBlockHeight(), is(height));
arts.remove(subject);
}
assertThat("org.bukkit.Art has too many arts", arts, is(Collections.EMPTY_LIST));
}
@Test
public void testCraftArtToNotch() {
Map<EnumArt, Art> cache = new EnumMap(EnumArt.class);
for (Art art : Art.values()) {
EnumArt enumArt = CraftArt.BukkitToNotch(art);
assertNotNull(art.name(), enumArt);
assertThat(art.name(), cache.put(enumArt, art), is(nullValue()));
}
}
@Test
public void testCraftArtToBukkit() {
Map<Art, EnumArt> cache = new EnumMap(Art.class);
for (EnumArt enumArt : EnumArt.values()) {
Art art = CraftArt.NotchToBukkit(enumArt);
assertNotNull(enumArt.name(), art);
assertThat(enumArt.name(), cache.put(art, enumArt), is(nullValue()));
}
}
}

View File

@ -1,48 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EntitySheep;
import net.minecraft.server.EnumColor;
import net.minecraft.server.ItemDye;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class DyeColorsTest extends AbstractTestingBase {
@Parameters(name= "{index}: {0}")
public static List<Object[]> data() {
List<Object[]> list = new ArrayList<>();
for (DyeColor dye : DyeColor.values()) {
list.add(new Object[] {dye});
}
return list;
}
@Parameter public DyeColor dye;
@Test
public void checkColor() {
Color color = dye.getColor();
float[] nmsColorArray = EntitySheep.a(EnumColor.fromColorIndex(dye.getWoolData()));
Color nmsColor = Color.fromRGB((int) (nmsColorArray[0] * 255), (int) (nmsColorArray[1] * 255), (int) (nmsColorArray[2] * 255));
assertThat(color, is(nmsColor));
}
@Test
public void checkFireworkColor() {
Color color = dye.getFireworkColor();
int nmsColor = ItemDye.a[dye.getDyeData()];
assertThat(color, is(Color.fromRGB(nmsColor)));
}
}

View File

@ -1,45 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.Collections;
import java.util.Map;
import net.minecraft.server.Item;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
import com.google.common.collect.Maps;
import java.util.Iterator;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
public class MaterialTest extends AbstractTestingBase {
@Test
public void verifyMapping() {
Map<Integer, Material> materials = Maps.newHashMap();
for (Material material : Material.values()) {
if (INVALIDATED_MATERIALS.contains(material)) {
continue;
}
materials.put(material.getId(), material);
}
materials.remove(0); // Purge air.
for (Item item : Item.REGISTRY) {
if (item == null) continue;
int id = CraftMagicNumbers.getId(item);
String name = item.getName();
Material material = materials.remove(id);
assertThat("Missing " + name + "(" + id + ")", material, is(not(nullValue())));
}
assertThat(materials, is(Collections.EMPTY_MAP));
}
}

View File

@ -1,149 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.List;
import net.minecraft.server.BlockFalling;
import net.minecraft.server.BlockFire;
import net.minecraft.server.Item;
import net.minecraft.server.ItemFood;
import net.minecraft.server.ItemRecord;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.support.AbstractTestingBase;
import org.bukkit.support.Util;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.collect.Lists;
import java.util.Map;
import net.minecraft.server.Block;
import net.minecraft.server.Blocks;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@RunWith(Parameterized.class)
public class PerMaterialTest extends AbstractTestingBase {
private static Map<Block, Integer> fireValues;
@BeforeClass
public static void getFireValues() {
fireValues = Util.getInternalState(BlockFire.class, Blocks.FIRE, "flameChances");
}
@Parameters(name= "{index}: {0}")
public static List<Object[]> data() {
List<Object[]> list = Lists.newArrayList();
for (Material material : Material.values()) {
list.add(new Object[] {material});
}
return list;
}
@Parameter public Material material;
@Test
public void isSolid() {
if (material == Material.AIR) {
assertFalse(material.isSolid());
} else if (material.isBlock()) {
assertThat(material.isSolid(), is(CraftMagicNumbers.getBlock(material).getMaterial().isSolid()));
} else {
assertFalse(material.isSolid());
}
}
@Test
public void isEdible() {
assertThat(material.isEdible(), is(CraftMagicNumbers.getItem(material) instanceof ItemFood));
}
@Test
public void isRecord() {
assertThat(material.isRecord(), is(CraftMagicNumbers.getItem(material) instanceof ItemRecord));
}
@Test
public void maxDurability() {
if (INVALIDATED_MATERIALS.contains(material)) return;
if (material == Material.AIR) {
assertThat((int) material.getMaxDurability(), is(0));
} else if (material.isBlock()){
Item item = CraftMagicNumbers.getItem(material);
assertThat((int) material.getMaxDurability(), is(item.getMaxDurability()));
}
}
@Test
public void maxStackSize() {
if (INVALIDATED_MATERIALS.contains(material)) return;
final ItemStack bukkit = new ItemStack(material);
final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit);
if (material == Material.AIR) {
final int MAX_AIR_STACK = 0 /* Why can't I hold all of these AIR? */;
assertThat(material.getMaxStackSize(), is(MAX_AIR_STACK));
assertThat(bukkit.getMaxStackSize(), is(MAX_AIR_STACK));
assertThat(craft.getMaxStackSize(), is(MAX_AIR_STACK));
} else {
assertThat(material.getMaxStackSize(), is(CraftMagicNumbers.getItem(material).getMaxStackSize()));
assertThat(bukkit.getMaxStackSize(), is(material.getMaxStackSize()));
assertThat(craft.getMaxStackSize(), is(material.getMaxStackSize()));
}
}
@Test
public void isTransparent() {
if (material == Material.AIR) {
assertTrue(material.isTransparent());
} else if (material.isBlock()) {
assertThat(material.isTransparent(), is(not(CraftMagicNumbers.getBlock(material).getMaterial().blocksLight())));
} else {
assertFalse(material.isTransparent());
}
}
@Test
public void isFlammable() {
if (material != Material.AIR && material.isBlock()) {
assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).getMaterial().isBurnable()));
} else {
assertFalse(material.isFlammable());
}
}
@Test
public void isBurnable() {
if (material.isBlock()) {
Block block = CraftMagicNumbers.getBlock(material);
assertThat(material.isBurnable(), is(fireValues.containsKey(block) && fireValues.get(block) > 0));
} else {
assertFalse(material.isBurnable());
}
}
@Test
public void isOccluding() {
if (material.isBlock()) {
assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).isOccluding()));
} else {
assertFalse(material.isOccluding());
}
}
@Test
public void hasGravity() {
if (material.isBlock()) {
assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof BlockFalling));
} else {
assertFalse(material.hasGravity());
}
}
}

View File

@ -1,18 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import org.bukkit.craftbukkit.CraftSound;
import org.junit.Test;
public class SoundTest {
@Test
public void testGetSound() {
for (Sound sound : Sound.values()) {
assertThat(sound.name(), CraftSound.getSound(sound), is(not(nullValue())));
}
}
}

View File

@ -1,60 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.List;
import net.minecraft.server.AchievementList;
import net.minecraft.server.StatisticList;
import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Lists;
public class StatisticsAndAchievementsTest extends AbstractTestingBase {
@Test
@SuppressWarnings("unchecked")
public void verifyAchievementMapping() throws Throwable {
List<Achievement> achievements = Lists.newArrayList(Achievement.values());
for (net.minecraft.server.Achievement achievement : AchievementList.e) {
String name = achievement.name;
String message = String.format("org.bukkit.Achievement is missing: '%s'", name);
Achievement subject = CraftStatistic.getBukkitAchievement(achievement);
assertThat(message, subject, is(not(nullValue())));
assertThat(name, achievements.remove(subject), is(true));
}
assertThat("org.bukkit.Achievement has too many achievements", achievements, is(empty()));
}
@Test
@SuppressWarnings("unchecked")
public void verifyStatisticMapping() throws Throwable {
HashMultiset<Statistic> statistics = HashMultiset.create();
for (net.minecraft.server.Statistic statistic : StatisticList.stats) {
if (statistic instanceof net.minecraft.server.Achievement) {
continue;
}
String name = statistic.name;
String message = String.format("org.bukkit.Statistic is missing: '%s'", name);
Statistic subject = CraftStatistic.getBukkitStatistic(statistic);
assertThat(message, subject, is(not(nullValue())));
statistics.add(subject);
}
for (Statistic statistic : Statistic.values()) {
String message = String.format("org.bukkit.Statistic.%s does not have a corresponding minecraft statistic", statistic.name());
assertThat(message, statistics.remove(statistic, statistics.count(statistic)), is(greaterThan(0)));
}
}
}

View File

@ -1,19 +0,0 @@
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import net.minecraft.server.WorldType;
import org.junit.Test;
public class WorldTypeTest {
@Test
public void testTypes() {
for (WorldType type : WorldType.types) {
if (type == null) continue;
if (type == WorldType.DEBUG_ALL_BLOCK_STATES) continue; // Doesn't work anyway
assertThat(type.name() + " has no Bukkit world", org.bukkit.WorldType.getByName(type.name()), is(not(nullValue())));
}
}
}

View File

@ -1,61 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class CompositeSerialization extends AbstractTestingBase {
public YamlConfiguration getConfig() {
return new YamlConfiguration();
}
@Test
public void testSaveRestoreCompositeList() throws InvalidConfigurationException {
YamlConfiguration out = getConfig();
List<ItemStack> stacks = new ArrayList<>();
stacks.add(new ItemStack(1));
stacks.add(new ItemStack(2));
stacks.add(new ItemStack(3));
stacks.add(new ItemStack(4, 17));
stacks.add(new ItemStack(5, 63));
stacks.add(new ItemStack(6, 1, (short) 1));
stacks.add(new ItemStack(18, 32, (short) 2));
ItemStack item7 = new ItemStack(256);
item7.addUnsafeEnchantment(Enchantment.getById(1), 1);
stacks.add(item7);
ItemStack item8 = new ItemStack(257);
item8.addUnsafeEnchantment(Enchantment.getById(2), 2);
item8.addUnsafeEnchantment(Enchantment.getById(3), 1);
item8.addUnsafeEnchantment(Enchantment.getById(4), 5);
item8.addUnsafeEnchantment(Enchantment.getById(5), 4);
stacks.add(item8);
out.set("composite-list.abc.def", stacks);
String yaml = out.saveToString();
YamlConfiguration in = new YamlConfiguration();
in.loadFromString(yaml);
List<?> raw = in.getList("composite-list.abc.def");
assertThat(stacks, hasSize(raw.size()));
for (int i = 0; i < 9; i++) {
assertThat(String.valueOf(i), (Object) stacks.get(i), is(raw.get(i)));
}
}
}

View File

@ -1,155 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class FactoryItemMaterialTest extends AbstractTestingBase {
static final ItemFactory factory = CraftItemFactory.instance();
static final StringBuilder buffer = new StringBuilder();
static final Material[] materials;
static {
Material[] local_materials = Material.values();
List<Material> list = new ArrayList<>(local_materials.length);
for (Material material : local_materials) {
if (INVALIDATED_MATERIALS.contains(material)) {
continue;
}
list.add(material);
}
materials = list.toArray(new Material[0]);
}
static String name(Enum<?> from, Enum<?> to) {
if (from.getClass() == to.getClass()) {
return buffer.delete(0, Integer.MAX_VALUE).append(from.getClass().getName()).append(' ').append(from.name()).append(" to ").append(to.name()).toString();
}
return buffer.delete(0, Integer.MAX_VALUE).append(from.getClass().getName()).append('(').append(from.name()).append(") to ").append(to.getClass().getName()).append('(').append(to.name()).append(')').toString();
}
@Parameters(name="Material[{index}]:{0}")
public static List<Object[]> data() {
List<Object[]> list = new ArrayList<>();
for (Material material : materials) {
list.add(new Object[] {material});
}
return list;
}
@Parameter(0) public Material material;
@Test
public void itemStack() {
ItemStack bukkitStack = new ItemStack(material);
CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack);
ItemMeta meta = factory.getItemMeta(material);
if (meta == null) {
assertThat(material, is(Material.AIR));
} else {
assertTrue(factory.isApplicable(meta, bukkitStack));
assertTrue(factory.isApplicable(meta, craftStack));
}
}
@Test
public void generalCase() {
CraftMetaItem meta = (CraftMetaItem) factory.getItemMeta(material);
if (meta == null) {
assertThat(material, is(Material.AIR));
} else {
assertTrue(factory.isApplicable(meta, material));
assertTrue(meta.applicableTo(material));
meta = meta.clone();
assertTrue(factory.isApplicable(meta, material));
assertTrue(meta.applicableTo(material));
}
}
@Test
public void asMetaFor() {
final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material);
if (baseMeta == null) {
assertThat(material, is(Material.AIR));
return;
}
for (Material other : materials) {
final ItemStack bukkitStack = new ItemStack(other);
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack);
final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMeta, other);
final String testName = name(material, other);
if (otherMeta == null) {
assertThat(testName, other, is(Material.AIR));
continue;
}
assertTrue(testName, factory.isApplicable(otherMeta, craftStack));
assertTrue(testName, factory.isApplicable(otherMeta, bukkitStack));
assertTrue(testName, factory.isApplicable(otherMeta, other));
assertTrue(testName, otherMeta.applicableTo(other));
}
}
@Test
public void blankEqualities() {
if (material == Material.AIR) {
return;
}
final CraftMetaItem baseMeta = (CraftMetaItem) factory.getItemMeta(material);
final CraftMetaItem baseMetaClone = baseMeta.clone();
final ItemStack baseMetaStack = new ItemStack(material);
baseMetaStack.setItemMeta(baseMeta);
assertThat(baseMeta, is(not(sameInstance(baseMetaStack.getItemMeta()))));
assertTrue(factory.equals(baseMeta, null));
assertTrue(factory.equals(null, baseMeta));
assertTrue(factory.equals(baseMeta, baseMetaClone));
assertTrue(factory.equals(baseMetaClone, baseMeta));
assertThat(baseMeta, is(not(sameInstance(baseMetaClone))));
assertThat(baseMeta, is(baseMetaClone));
assertThat(baseMetaClone, is(baseMeta));
for (Material other : materials) {
final String testName = name(material, other);
final CraftMetaItem otherMeta = (CraftMetaItem) factory.asMetaFor(baseMetaClone, other);
if (otherMeta == null) {
assertThat(testName, other, is(Material.AIR));
continue;
}
assertTrue(testName, factory.equals(baseMeta, otherMeta));
assertTrue(testName, factory.equals(otherMeta, baseMeta));
assertThat(testName, baseMeta, is(otherMeta));
assertThat(testName, otherMeta, is(baseMeta));
assertThat(testName, baseMeta.hashCode(), is(otherMeta.hashCode()));
}
}
}

View File

@ -1,47 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.HashSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.minecraft.server.CommandAbstract;
import net.minecraft.server.IAttribute;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class ItemFactoryTest extends AbstractTestingBase {
@Test
public void testKnownAttributes() throws Throwable {
final ZipInputStream nmsZipStream = new ZipInputStream(CommandAbstract.class/* Magic class that isn't imported! */.getProtectionDomain().getCodeSource().getLocation().openStream());
final Collection<String> names = new HashSet<>();
for (ZipEntry clazzEntry; (clazzEntry = nmsZipStream.getNextEntry()) != null; ) {
final String entryName = clazzEntry.getName();
if (!(entryName.endsWith(".class") && entryName.startsWith("net/minecraft/server/"))) {
continue;
}
final Class<?> clazz = Class.forName(entryName.substring(0, entryName.length() - ".class".length()).replace('/', '.'));
assertThat(entryName, clazz, is(not(nullValue())));
for (final Field field : clazz.getDeclaredFields()) {
if (IAttribute.class.isAssignableFrom(field.getType()) && Modifier.isStatic(field.getModifiers())) {
field.setAccessible(true);
final String attributeName = ((IAttribute) field.get(null)).getName();
assertThat("Logical error: duplicate name `" + attributeName + "' in " + clazz.getName(), names.add(attributeName), is(true));
assertThat(clazz.getName(), CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES, hasItem(attributeName));
}
}
}
nmsZipStream.close();
assertThat("Extra values detected", CraftItemFactory.KNOWN_NBT_ATTRIBUTE_NAMES, is(names));
}
}

View File

@ -1,72 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.craftbukkit.Overridden;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ItemMetaImplementationOverrideTest {
static final Class<CraftMetaItem> parent = CraftMetaItem.class;
@Parameters(name="[{index}]:{1}")
public static List<Object[]> data() {
final List<Object[]> testData = new ArrayList<>();
List<Class<? extends CraftMetaItem>> classes = new ArrayList<>();
for (Material material : ItemStackTest.COMPOUND_MATERIALS) {
Class<? extends CraftMetaItem> clazz = CraftItemFactory.instance().getItemMeta(material).getClass().asSubclass(parent);
if (clazz != parent) {
classes.add(clazz);
}
}
List<Method> list = new ArrayList<>();
for (Method method: parent.getDeclaredMethods()) {
if (method.isAnnotationPresent(Overridden.class)) {
list.add(method);
}
}
for (final Class<?> clazz : classes) {
for (final Method method : list) {
testData.add(
new Object[] {
(Callable<Method>) () -> clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()),
clazz.getSimpleName() + " contains " + method.getName()
}
);
}
testData.add(
new Object[] {
(Callable<DelegateDeserialization>) () -> clazz.getAnnotation(DelegateDeserialization.class),
clazz.getSimpleName() + " contains annotation " + DelegateDeserialization.class
}
);
}
return testData;
}
@Parameter(0) public Callable<?> test;
@Parameter(1) public String name;
@Test
public void testClass() throws Throwable {
assertThat(name, test.call(), is(not(nullValue())));
}
}

View File

@ -1,250 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackWrapper;
import org.bukkit.craftbukkit.inventory.ItemStackTest.BukkitWrapper;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CraftWrapper;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class ItemMetaTest extends AbstractTestingBase {
static final int MAX_FIREWORK_POWER = 127; // Please update ItemStackFireworkTest if/when this gets changed.
@Test(expected=IllegalArgumentException.class)
public void testPowerLimitExact() {
newFireworkMeta().setPower(MAX_FIREWORK_POWER + 1);
}
@Test(expected=IllegalArgumentException.class)
public void testPowerLimitMax() {
newFireworkMeta().setPower(Integer.MAX_VALUE);
}
@Test(expected=IllegalArgumentException.class)
public void testPowerLimitMin() {
newFireworkMeta().setPower(Integer.MIN_VALUE);
}
@Test(expected=IllegalArgumentException.class)
public void testPowerLimitNegative() {
newFireworkMeta().setPower(-1);
}
@Test
public void testPowers() {
for (int i = 0; i <= MAX_FIREWORK_POWER; i++) {
FireworkMeta firework = newFireworkMeta();
firework.setPower(i);
assertThat(String.valueOf(i), firework.getPower(), is(i));
}
}
@Test
public void testConflictingEnchantment() {
ItemMeta itemMeta = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE);
assertThat(itemMeta.hasConflictingEnchant(Enchantment.DURABILITY), is(false));
itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, false);
assertThat(itemMeta.hasConflictingEnchant(Enchantment.DURABILITY), is(false));
assertThat(itemMeta.hasConflictingEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
assertThat(itemMeta.hasConflictingEnchant(null), is(false));
}
@Test
public void testConflictingStoredEnchantment() {
EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.DURABILITY), is(false));
itemMeta.addStoredEnchant(Enchantment.SILK_TOUCH, 1, false);
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.DURABILITY), is(false));
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
assertThat(itemMeta.hasConflictingStoredEnchant(null), is(false));
}
@Test
public void testConflictingEnchantments() {
ItemMeta itemMeta = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE);
itemMeta.addEnchant(Enchantment.DURABILITY, 6, true);
itemMeta.addEnchant(Enchantment.DIG_SPEED, 6, true);
assertThat(itemMeta.hasConflictingEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(false));
itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, false);
assertThat(itemMeta.hasConflictingEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
assertThat(itemMeta.hasConflictingEnchant(null), is(false));
}
@Test
public void testConflictingStoredEnchantments() {
EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);
itemMeta.addStoredEnchant(Enchantment.DURABILITY, 6, true);
itemMeta.addStoredEnchant(Enchantment.DIG_SPEED, 6, true);
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(false));
itemMeta.addStoredEnchant(Enchantment.SILK_TOUCH, 1, false);
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
assertThat(itemMeta.hasConflictingStoredEnchant(null), is(false));
}
private static FireworkMeta newFireworkMeta() {
return ((FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK));
}
@Test
public void testCrazyEquality() {
CraftItemStack craft = CraftItemStack.asCraftCopy(new ItemStack(1));
craft.setItemMeta(craft.getItemMeta());
ItemStack bukkit = new ItemStack(craft);
assertThat(craft, is(bukkit));
assertThat(bukkit, is(craft));
}
@Test
public void testEachExtraData() {
final List<StackProvider> providers = Arrays.asList(
new StackProvider(Material.BOOK_AND_QUILL) {
@Override ItemStack operate(final ItemStack cleanStack) {
final BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("Some author");
meta.setPages("Page 1", "Page 2");
meta.setTitle("A title");
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.WRITTEN_BOOK) {
@Override ItemStack operate(final ItemStack cleanStack) {
final BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("Some author");
meta.setPages("Page 1", "Page 2");
meta.setTitle("A title");
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
/* Skulls rely on a running server instance
new StackProvider(Material.SKULL_ITEM) {
@Override ItemStack operate(final ItemStack cleanStack) {
final SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
meta.setOwner("Notch");
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
*/
new StackProvider(Material.MAP) {
@Override ItemStack operate(final ItemStack cleanStack) {
final MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(true);
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.LEATHER_BOOTS) {
@Override ItemStack operate(final ItemStack cleanStack) {
final LeatherArmorMeta meta = (LeatherArmorMeta) cleanStack.getItemMeta();
meta.setColor(Color.FUCHSIA);
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.POTION) {
@Override ItemStack operate(final ItemStack cleanStack) {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.CONFUSION.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.FIREWORK) {
@Override ItemStack operate(final ItemStack cleanStack) {
final FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.GREEN).withFade(Color.OLIVE).with(Type.BALL_LARGE).build());
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.ENCHANTED_BOOK) {
@Override ItemStack operate(final ItemStack cleanStack) {
final EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addStoredEnchant(Enchantment.ARROW_FIRE, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.FIREWORK_CHARGE) {
@Override ItemStack operate(final ItemStack cleanStack) {
final FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.MAROON, Color.BLACK).with(Type.CREEPER).withFlicker().build());
cleanStack.setItemMeta(meta);
return cleanStack;
}
},
new StackProvider(Material.BANNER) {
@Override ItemStack operate(ItemStack cleanStack) {
final BannerMeta meta = (BannerMeta) cleanStack.getItemMeta();
meta.setBaseColor(DyeColor.CYAN);
meta.addPattern(new Pattern(DyeColor.WHITE, PatternType.BRICKS));
cleanStack.setItemMeta(meta);
return cleanStack;
}
}
);
assertThat("Forgotten test?", providers, hasSize(ItemStackTest.COMPOUND_MATERIALS.length - 3/* Normal item meta, skulls and tile entities */));
for (final StackProvider provider : providers) {
downCastTest(new BukkitWrapper(provider));
downCastTest(new CraftWrapper(provider));
}
}
private void downCastTest(final StackWrapper provider) {
final String name = provider.toString();
final ItemStack blank = new ItemStack(1);
final ItemStack craftBlank = CraftItemStack.asCraftCopy(blank);
downCastTest(name, provider.stack(), blank);
blank.setItemMeta(blank.getItemMeta());
downCastTest(name, provider.stack(), blank);
downCastTest(name, provider.stack(), craftBlank);
craftBlank.setItemMeta(craftBlank.getItemMeta());
downCastTest(name, provider.stack(), craftBlank);
}
private void downCastTest(final String name, final ItemStack stack, final ItemStack blank) {
assertThat(name, stack, is(not(blank)));
assertThat(name, stack.getItemMeta(), is(not(blank.getItemMeta())));
stack.setTypeId(1);
assertThat(name, stack, is(blank));
}
}

View File

@ -1,167 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackBookTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.WRITTEN_BOOK, Material.BOOK_AND_QUILL);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("1110", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.addPage("Page 1", "Page 2");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Pages vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.addPage("Page 1", "Page 2");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
cleanStack.setItemMeta(cleanStack.getItemMeta());
return cleanStack;
},
"Pages vs. blank"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.addPage("Page 1", "Page 2");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.addPage("Page 2", "Page 1");
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Pages switched"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.addPage("Page 1", "Page 2");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.addPage("Page 1");
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Pages short"
}
),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("AnAuthor");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Author vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("AnAuthor");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
cleanStack.setItemMeta(cleanStack.getItemMeta());
return cleanStack;
},
"Author vs. blank"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("AnAuthor");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setAuthor("AnotherAuthor");
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Authors"
}
),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setTitle("Some title");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Title vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setTitle("Some title");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
cleanStack.setItemMeta(cleanStack.getItemMeta());
return cleanStack;
},
"title vs. blank"
},
new Object[] {
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setTitle("Some title");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
BookMeta meta = (BookMeta) cleanStack.getItemMeta();
meta.setTitle("Different title");
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Titles"
}
)
);
}
}

View File

@ -1,90 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackEnchantStorageTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.ENCHANTED_BOOK);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("10", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addStoredEnchant(Enchantment.DURABILITY, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Enchantable vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addStoredEnchant(Enchantment.KNOCKBACK, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Enchantable vs Null"
},
new Object[] {
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addStoredEnchant(Enchantment.DAMAGE_UNDEAD, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addStoredEnchant(Enchantment.DAMAGE_UNDEAD, 1, true);
meta.addStoredEnchant(Enchantment.FIRE_ASPECT, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Enchantable vs More"
},
new Object[] {
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addStoredEnchant(Enchantment.PROTECTION_FIRE, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) cleanStack.getItemMeta();
meta.addEnchant(Enchantment.PROTECTION_FIRE, 2, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Enchantable vs Other"
}
)
);
}
}

View File

@ -1,106 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackFireworkChargeTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK_CHARGE);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("10", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.BLACK).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect Color 1 vs. Effect Color 2"
},
new Object[] {
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).with(Type.CREEPER).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).with(Type.BURST).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect type 1 vs. Effect type 2"
},
new Object[] {
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).withFade(Color.BLUE).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).withFade(Color.RED).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect fade 1 vs. Effect fade 2"
},
new Object[] {
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).withFlicker().build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
FireworkEffectMeta meta = (FireworkEffectMeta) cleanStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(Color.WHITE).withTrail().build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Effect vs. None"
}
)
);
}
}

View File

@ -1,148 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackFireworkTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.FIREWORK);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("110", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.BLACK).build());
meta.addEffect(FireworkEffect.builder().withColor(Color.GREEN).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect Color 1 vs. Effect Color 2"
},
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).with(Type.CREEPER).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).with(Type.BURST).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect type 1 vs. Effect type 2"
},
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).withFade(Color.BLUE).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).withFade(Color.RED).build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect fade 1 vs. Effect fade 2"
},
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).withFlicker().build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Effect vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.addEffect(FireworkEffect.builder().withColor(Color.WHITE).withTrail().build());
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Effect vs. None"
}
),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.setPower(127);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.setPower(100);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Height vs. Other"
},
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.setPower(42);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Height vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
FireworkMeta meta = (FireworkMeta) cleanStack.getItemMeta();
meta.setPower(10);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Height vs. None"
}
)
);
}
}

View File

@ -1,75 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackLeatherTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.LEATHER_BOOTS, Material.LEATHER_CHESTPLATE, Material.LEATHER_HELMET, Material.LEATHER_LEGGINGS);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("10", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
LeatherArmorMeta meta = (LeatherArmorMeta) cleanStack.getItemMeta();
meta.setColor(Color.FUCHSIA);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Color vs Null"
},
new Object[] {
(Operator) cleanStack -> {
LeatherArmorMeta meta = (LeatherArmorMeta) cleanStack.getItemMeta();
meta.setColor(Color.GRAY);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
LeatherArmorMeta meta = (LeatherArmorMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Color vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
LeatherArmorMeta meta = (LeatherArmorMeta) cleanStack.getItemMeta();
meta.setColor(Color.MAROON);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
LeatherArmorMeta meta = (LeatherArmorMeta) cleanStack.getItemMeta();
meta.setColor(Color.ORANGE);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Color vs Other"
}
)
);
}
}

View File

@ -1,227 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.Repairable;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackLoreEnchantmentTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, ItemStackTest.COMPOUND_MATERIALS);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
~0l,
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setLore(Arrays.asList("First Lore", "Second Lore"));
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Lore vs Null"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setLore(Arrays.asList("Some lore"));
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Lore vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setLore(Arrays.asList("Some more lore", "Another lore"));
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setLore(Arrays.asList("Some more lore"));
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Lore vs Other"
}
),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setDisplayName("TestItemName");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Name vs Null"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setDisplayName("AnotherItemName");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Name vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setDisplayName("The original ItemName");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.setDisplayName("The other name");
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Name vs Other"
}
),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
cleanStack.addUnsafeEnchantment(Enchantment.DIG_SPEED, 2);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"EnchantStack vs Null"
},
new Object[] {
(Operator) cleanStack -> {
cleanStack.addUnsafeEnchantment(Enchantment.OXYGEN, 1);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"EnchantStack vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
cleanStack.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, 1);
return cleanStack;
},
(Operator) cleanStack -> {
cleanStack.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 1);
return cleanStack;
},
"EnchantStack vs OtherEnchantStack"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.addEnchant(Enchantment.DURABILITY, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Enchant vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.addEnchant(Enchantment.KNOCKBACK, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Enchant vs Null"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.addEnchant(Enchantment.PROTECTION_FIRE, 1, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
meta.addEnchant(Enchantment.PROTECTION_FIRE, 2, true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Enchant vs Other"
}
),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
((Repairable) meta).setRepairCost(42);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Repair vs Null"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
((Repairable) meta).setRepairCost(36);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Repair vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
((Repairable) meta).setRepairCost(89);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
ItemMeta meta = cleanStack.getItemMeta();
((Repairable) meta).setRepairCost(88);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Repair vs Other"
}
)
);
}
}

View File

@ -1,97 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackMapTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.MAP);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("10", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Scale vs. Unscale"
},
new Object[] {
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Scale vs. Blank"
},
new Object[] {
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Unscale vs. Blank"
},
new Object[] {
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(true);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Scale vs. None"
},
new Object[] {
(Operator) cleanStack -> {
MapMeta meta = (MapMeta) cleanStack.getItemMeta();
meta.setScaling(false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Unscale vs. None"
}
)
);
}
}

View File

@ -1,120 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackPotionsTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.POTION);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("10", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.CONFUSION.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Potion vs Null"
},
new Object[] {
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.HARM.createEffect(2, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Potion vs Blank"
},
new Object[] {
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.SLOW_DIGGING.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.FAST_DIGGING.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Potion vs Harder"
},
new Object[] {
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.JUMP.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.JUMP.createEffect(1, 1), false);
meta.addCustomEffect(PotionEffectType.REGENERATION.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Potion vs Better"
},
new Object[] {
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.SPEED.createEffect(10, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.SPEED.createEffect(5, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Potion vs Faster"
},
new Object[] {
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.INCREASE_DAMAGE.createEffect(1, 1), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta();
meta.addCustomEffect(PotionEffectType.INCREASE_DAMAGE.createEffect(1, 2), false);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Potion vs Stronger"
}
)
);
}
}

View File

@ -1,74 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Joiner;
@RunWith(Parameterized.class)
public class ItemStackSkullTest extends ItemStackTest {
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return StackProvider.compound(operators(), "%s %s", NAME_PARAMETER, Material.SKULL_ITEM);
}
@SuppressWarnings("unchecked")
static List<Object[]> operators() {
return CompoundOperator.compound(
Joiner.on('+'),
NAME_PARAMETER,
Long.parseLong("10", 2),
ItemStackLoreEnchantmentTest.operators(),
Arrays.asList(
new Object[] {
(Operator) cleanStack -> {
SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
meta.setOwner("Notch");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
meta.setOwner("Dinnerbone");
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Name 1 vs. Name 2"
},
new Object[] {
(Operator) cleanStack -> {
SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
meta.setOwner("Notch");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> {
SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
meta.setOwner(null);
cleanStack.setItemMeta(meta);
return cleanStack;
},
"Name vs. Null"
},
new Object[] {
(Operator) cleanStack -> {
SkullMeta meta = (SkullMeta) cleanStack.getItemMeta();
meta.setOwner("Notch");
cleanStack.setItemMeta(meta);
return cleanStack;
},
(Operator) cleanStack -> cleanStack,
"Name vs. None"
}
)
);
}
}

View File

@ -1,480 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.bukkit.support.Matchers.sameHash;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.support.AbstractTestingBase;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@RunWith(Parameterized.class)
public class ItemStackTest extends AbstractTestingBase {
static abstract class StackProvider {
final Material material;
StackProvider(Material material) {
this.material = material;
}
ItemStack bukkit() {
return operate(cleanStack(material, false));
}
ItemStack craft() {
return operate(cleanStack(material, true));
}
abstract ItemStack operate(ItemStack cleanStack);
static ItemStack cleanStack(Material material, boolean craft) {
final ItemStack stack = new ItemStack(material);
return craft ? CraftItemStack.asCraftCopy(stack) : stack;
}
@Override
public String toString() {
return material.toString();
}
/**
* For each item in parameterList, it will apply nameFormat at nameIndex.
* For each item in parameterList for each item in materials, it will create a stack provider at each array index that contains an Operator.
*
* @param parameterList
* @param nameFormat
* @param nameIndex
* @param materials
* @return
*/
static List<Object[]> compound(final List<Object[]> parameterList, final String nameFormat, final int nameIndex, final Material...materials) {
final List<Object[]> out = new ArrayList<>();
for (Object[] params : parameterList) {
final int len = params.length;
for (final Material material : materials) {
final Object[] paramsOut = params.clone();
for (int i = 0; i < len; i++) {
final Object param = paramsOut[i];
if (param instanceof Operator) {
final Operator operator = (Operator) param;
paramsOut[i] = new StackProvider(material) {
@Override
ItemStack operate(ItemStack cleanStack) {
return operator.operate(cleanStack);
}
};
}
}
paramsOut[nameIndex] = String.format(nameFormat, paramsOut[nameIndex], material);
out.add(paramsOut);
}
}
return out;
}
}
interface Operator {
ItemStack operate(ItemStack cleanStack);
}
static class CompoundOperator implements Operator {
static class RecursiveContainer {
final Joiner joiner;
final Object[] strings;
final int nameParameter;
final List<Object[]> stack;
final List<Object[]> out;
final List<Object[]>[] lists;
RecursiveContainer(Joiner joiner, Object[] strings, int nameParameter, List<Object[]> stack, List<Object[]> out, List<Object[]>[] lists) {
this.joiner = joiner;
this.strings = strings;
this.nameParameter = nameParameter;
this.stack = stack;
this.out = out;
this.lists = lists;
}
}
final Operator[] operators;
CompoundOperator(Operator...operators) {
this.operators = operators;
}
public ItemStack operate(ItemStack cleanStack) {
for (Operator operator : operators) {
operator.operate(cleanStack);
}
return cleanStack;
}
@Override
public String toString() {
return Arrays.toString(operators);
}
/**
* This combines different tests into one large collection, combining no two tests from the same list.
* @param joiner used to join names
* @param nameParameter index of the name parameter
* @param singletonBitmask a list of bits representing the 'singletons' located in your originalLists. Lowest order bits represent the first items in originalLists.
* Singletons are exponentially linked with each other, such that,
* the output will contain every unique subset of only items from the singletons,
* as well as every unique subset that contains at least one item from each non-singleton.
* @param originalLists
* @return
*/
static List<Object[]> compound(final Joiner joiner, final int nameParameter, final long singletonBitmask, final List<Object[]>...originalLists) {
final List<Object[]> out = new ArrayList<>();
final List<List<Object[]>> singletons = new ArrayList<>();
final List<List<Object[]>> notSingletons = new ArrayList<>();
{ // Separate and prime the 'singletons'
int i = 0;
for (List<Object[]> list : originalLists) {
(((singletonBitmask >>> i++) & 0x1) == 0x1 ? singletons : notSingletons).add(list);
}
}
for (final List<Object[]> primarySingleton : singletons) {
// Iterate over our singletons, to multiply the 'out' each time
for (final Object[] entry : out.toArray(EMPTY_ARRAY)) {
// Iterate over a snapshot of 'out' to prevent CMEs / infinite iteration
final int len = entry.length;
for (final Object[] singleton : primarySingleton) {
// Iterate over each item in our singleton for the current 'out' entry
final Object[] toOut = entry.clone();
for (int i = 0; i < len; i++) {
// Iterate over each parameter
if (i == nameParameter) {
toOut[i] = joiner.join(toOut[i], singleton[i]);
} else if (toOut[i] instanceof Operator) {
final Operator op1 = (Operator) toOut[i];
final Operator op2 = (Operator) singleton[i];
toOut[i] = (Operator) cleanStack -> op2.operate(op1.operate(cleanStack));
}
}
out.add(toOut);
}
}
out.addAll(primarySingleton);
}
@SuppressWarnings("unchecked")
final List<Object[]>[] lists = new List[notSingletons.size() + 1];
notSingletons.toArray(lists);
lists[lists.length - 1] = out;
final RecursiveContainer methodParams = new RecursiveContainer(joiner, new Object[lists.length], nameParameter, new ArrayList<>(lists.length), new ArrayList<>(), lists);
recursivelyCompound(methodParams, 0);
methodParams.out.addAll(out);
return methodParams.out;
}
private static void recursivelyCompound(final RecursiveContainer methodParams, final int level) {
final List<Object[]> stack = methodParams.stack;
if (level == methodParams.lists.length) {
final Object[] firstParams = stack.get(0);
final int len = firstParams.length;
final int stackSize = stack.size();
final Object[] params = new Object[len];
for (int i = 0; i < len; i++) {
final Object firstParam = firstParams[i];
if (firstParam instanceof Operator) {
final Operator[] operators = new Operator[stackSize];
for (int j = 0; j < stackSize; j++) {
operators[j] = (Operator) stack.get(j)[i];
}
params[i] = new CompoundOperator(operators);
} else if (i == methodParams.nameParameter) {
final Object[] strings = methodParams.strings;
for (int j = 0; j < stackSize; j++) {
strings[j] = stack.get(j)[i];
}
params[i] = methodParams.joiner.join(strings);
} else {
params[i] = firstParam;
}
}
methodParams.out.add(params);
} else {
final int marker = stack.size();
for (final Object[] params : methodParams.lists[level]) {
stack.add(params);
recursivelyCompound(methodParams, level + 1);
stack.remove(marker);
}
}
}
}
interface StackWrapper {
ItemStack stack();
}
static class CraftWrapper implements StackWrapper {
final StackProvider provider;
CraftWrapper(StackProvider provider) {
this.provider = provider;
}
public ItemStack stack() {
return provider.craft();
}
@Override
public String toString() {
return "Craft " + provider;
}
}
static class BukkitWrapper implements StackWrapper {
final StackProvider provider;
BukkitWrapper(StackProvider provider) {
this.provider = provider;
}
public ItemStack stack() {
return provider.bukkit();
}
@Override
public String toString() {
return "Bukkit " + provider;
}
}
static class NoOpProvider extends StackProvider {
NoOpProvider(Material material) {
super(material);
}
@Override
ItemStack operate(ItemStack cleanStack) {
return cleanStack;
}
@Override
public String toString() {
return "NoOp " + super.toString();
}
}
@Parameters(name="[{index}]:{" + NAME_PARAMETER + "}")
public static List<Object[]> data() {
return ImmutableList.of(); // TODO, test basic durability issues
}
static final Object[][] EMPTY_ARRAY = new Object[0][];
/**
* Materials that generate unique item meta types.
*/
static final Material[] COMPOUND_MATERIALS;
static final int NAME_PARAMETER = 2;
static {
final ItemFactory factory = CraftItemFactory.instance();
final Map<Class<? extends ItemMeta>, Material> possibleMaterials = new HashMap<>();
ItemMeta meta;
for (final Material material : Material.values()) {
meta = factory.getItemMeta(material);
if (meta == null || possibleMaterials.containsKey(meta.getClass()))
continue;
possibleMaterials.put(meta.getClass(), material);
}
COMPOUND_MATERIALS = possibleMaterials.values().toArray(new Material[0]);
}
@Parameter(0) public StackProvider provider;
@Parameter(1) public StackProvider unequalProvider;
@Parameter(NAME_PARAMETER) public String name;
@Test
public void testBukkitInequality() {
final StackWrapper bukkitWrapper = new CraftWrapper(provider);
testInequality(bukkitWrapper, new BukkitWrapper(unequalProvider));
testInequality(bukkitWrapper, new BukkitWrapper(new NoOpProvider(provider.material)));
}
@Test
public void testCraftInequality() {
final StackWrapper craftWrapper = new CraftWrapper(provider);
testInequality(craftWrapper, new CraftWrapper(unequalProvider));
testInequality(craftWrapper, new CraftWrapper(new NoOpProvider(provider.material)));
}
@Test
public void testMixedInequality() {
final StackWrapper craftWrapper = new CraftWrapper(provider);
testInequality(craftWrapper, new BukkitWrapper(unequalProvider));
testInequality(craftWrapper, new BukkitWrapper(new NoOpProvider(provider.material)));
final StackWrapper bukkitWrapper = new CraftWrapper(provider);
testInequality(bukkitWrapper, new CraftWrapper(unequalProvider));
testInequality(bukkitWrapper, new CraftWrapper(new NoOpProvider(provider.material)));
}
static void testInequality(StackWrapper provider, StackWrapper unequalProvider) {
final ItemStack stack = provider.stack();
final ItemStack stack2 = provider.stack();
assertThat(stack, allOf(equalTo(stack), sameHash(stack)));
assertThat(stack, is(not(sameInstance(stack2))));
assertThat(stack, allOf(equalTo(stack2), sameHash(stack2)));
final ItemStack unequalStack = unequalProvider.stack();
final ItemStack unequalStack2 = unequalProvider.stack();
assertThat(unequalStack, allOf(equalTo(unequalStack), sameHash(unequalStack)));
assertThat(unequalStack, is(not(sameInstance(unequalStack2))));
assertThat(unequalStack, allOf(equalTo(unequalStack2), sameHash(unequalStack2)));
assertThat(stack, is(not(unequalStack)));
assertThat(unequalStack, is(not(stack)));
final ItemStack newStack = new ItemStack(stack2);
assertThat(newStack, allOf(equalTo(stack), sameHash(stack)));
assertThat(newStack, is(not(unequalStack)));
assertThat(newStack.getItemMeta(), allOf(equalTo(stack.getItemMeta()), sameHash(stack.getItemMeta())));
assertThat(newStack.getItemMeta(), is(not(unequalStack.getItemMeta())));
final ItemStack craftStack = CraftItemStack.asCraftCopy(stack2);
assertThat(craftStack, allOf(equalTo(stack), sameHash(stack)));
assertThat(craftStack, is(not(unequalStack)));
assertThat(craftStack.getItemMeta(), allOf(equalTo(stack.getItemMeta()), sameHash(stack.getItemMeta())));
assertThat(craftStack.getItemMeta(), is(not(unequalStack.getItemMeta())));
final ItemStack newUnequalStack = new ItemStack(unequalStack2);
assertThat(newUnequalStack, allOf(equalTo(unequalStack), sameHash(unequalStack)));
assertThat(newUnequalStack, is(not(stack)));
assertThat(newUnequalStack.getItemMeta(), allOf(equalTo(unequalStack.getItemMeta()), sameHash(unequalStack.getItemMeta())));
assertThat(newUnequalStack.getItemMeta(), is(not(stack.getItemMeta())));
final ItemStack newUnequalCraftStack = CraftItemStack.asCraftCopy(unequalStack2);
assertThat(newUnequalCraftStack, allOf(equalTo(unequalStack), sameHash(unequalStack)));
assertThat(newUnequalCraftStack, is(not(stack)));
assertThat(newUnequalCraftStack.getItemMeta(), allOf(equalTo(unequalStack.getItemMeta()), sameHash(unequalStack.getItemMeta())));
assertThat(newUnequalCraftStack.getItemMeta(), is(not(stack.getItemMeta())));
}
@Test
public void testBukkitYamlDeserialize() throws Throwable {
testYamlDeserialize(new BukkitWrapper(provider), new BukkitWrapper(unequalProvider));
}
@Test
public void testCraftYamlDeserialize() throws Throwable {
testYamlDeserialize(new CraftWrapper(provider), new CraftWrapper(unequalProvider));
}
@Test
public void testBukkitStreamDeserialize() throws Throwable {
testStreamDeserialize(new BukkitWrapper(provider), new BukkitWrapper(unequalProvider));
}
@Test
public void testCraftStreamDeserialize() throws Throwable {
testStreamDeserialize(new CraftWrapper(provider), new CraftWrapper(unequalProvider));
}
static void testStreamDeserialize(StackWrapper provider, StackWrapper unequalProvider) throws Throwable {
final ItemStack stack = provider.stack();
final ItemStack unequalStack = unequalProvider.stack();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new BukkitObjectOutputStream(out)) {
oos.writeObject(stack);
oos.writeObject(unequalStack);
}
final String data = new String(Base64Coder.encode(out.toByteArray()));
ObjectInputStream ois = null;
final ItemStack readFirst;
final ItemStack readSecond;
try {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ois = new BukkitObjectInputStream(in);
readFirst = (ItemStack) ois.readObject();
readSecond = (ItemStack) ois.readObject();
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException ignored) {
}
}
}
testEqualities(data, readFirst, readSecond, stack, unequalStack);
}
static void testYamlDeserialize(StackWrapper provider, StackWrapper unequalProvider) {
final ItemStack stack = provider.stack();
final ItemStack unequalStack = unequalProvider.stack();
final YamlConfiguration configOut = new YamlConfiguration();
configOut.set("provider", stack);
configOut.set("unequal", unequalStack);
final String out = '\n' + configOut.saveToString();
final YamlConfiguration configIn = new YamlConfiguration();
try {
configIn.loadFromString(out);
} catch (InvalidConfigurationException ex) {
throw new RuntimeException(out, ex);
}
testEqualities(out, configIn.getItemStack("provider"), configIn.getItemStack("unequal"), stack, unequalStack);
}
static void testEqualities(String information, ItemStack primaryRead, ItemStack unequalRead, ItemStack primaryOriginal, ItemStack unequalOriginal) {
assertThat(information, primaryRead, allOf(equalTo(primaryOriginal), sameHash(primaryOriginal)));
assertThat(information, unequalRead, allOf(equalTo(unequalOriginal), sameHash(unequalOriginal)));
assertThat(information, primaryRead, is(not(unequalOriginal)));
assertThat(information, primaryRead, is(not(unequalRead)));
}
}

View File

@ -1,36 +0,0 @@
package org.bukkit.craftbukkit.inventory;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import net.minecraft.server.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class NMSCraftItemStackTest extends AbstractTestingBase {
@Test
public void testCloneEnchantedItem() throws Exception {
net.minecraft.server.ItemStack nmsItemStack = new net.minecraft.server.ItemStack(net.minecraft.server.Items.POTION);
nmsItemStack.addEnchantment(Enchantment.DAMAGE_ALL, 1);
ItemStack itemStack = CraftItemStack.asCraftMirror(nmsItemStack);
ItemStack clone = itemStack.clone();
assertThat(clone.getType(), is(itemStack.getType()));
assertThat(clone.getAmount(), is(itemStack.getAmount()));
assertThat(clone.getDurability(), is(itemStack.getDurability()));
assertThat(clone.getEnchantments(), is(itemStack.getEnchantments()));
assertThat(clone.getTypeId(), is(itemStack.getTypeId()));
assertThat(clone.getData(), is(itemStack.getData()));
assertThat(clone, is(itemStack));
}
@Test
public void testCloneNullItem() throws Exception {
net.minecraft.server.ItemStack nmsItemStack = null;
ItemStack itemStack = CraftItemStack.asCraftMirror(nmsItemStack);
ItemStack clone = itemStack.clone();
assertThat(clone, is(itemStack));
}
}

View File

@ -1,62 +0,0 @@
package org.bukkit.craftbukkit.metadata;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataStore;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.List;
public class BlockMetadataTest {
@Test
public void oldNewComparison() {
MetadataStore<Block> oldStore = new BlockMetadataStore(null);
MetadataStore<Block> newStore = new SpecializedBlockMetadataStore(null);
Plugin plugin = Mockito.mock(Plugin.class);
for (int x = 2, y = 0, z = 2, i = 0; i < 20; i++, x += 300, z += 200, y += 10) {
Block block = makeBlock(i % 2 == 0 ? x : -x, y, i % 2 == 0 ? z : -z);
MetadataValue value = new FixedMetadataValue(plugin, i);
oldStore.setMetadata(block, "test", value);
oldStore.setMetadata(block, "test" + i, value);
newStore.setMetadata(block, "test", value);
newStore.setMetadata(block, "test" + i, value);
Assert.assertTrue(newStore.hasMetadata(block, "test"));
Assert.assertTrue(newStore.hasMetadata(block, "test" + i));
List<MetadataValue> test = newStore.getMetadata(block, "test");
Assert.assertEquals(test, oldStore.getMetadata(block, "test"));
Assert.assertTrue("value in newStore[\"test\"]", test.contains(value));
List<MetadataValue> indexTest = newStore.getMetadata(block, "test" + i);
Assert.assertEquals(indexTest, oldStore.getMetadata(block, "test" + i));
Assert.assertTrue("value in newStore[\"test\" + i]", indexTest.contains(value));
}
}
@Test
public void compareIds() {
for (int x = 3, y = 1, z = 2, i = 0; i < 20; i++, x += 300, z += 200, y += 10) {
Block block = makeBlock(i % 2 == 0 ? x : -x, y, i % 2 == 0 ? z : -z);
Location location = new Location(null, block.getX(), block.getY(), block.getZ());
Assert.assertEquals(location, SpecializedBlockMetadataStore.toLocation(null,
SpecializedBlockMetadataStore.getBlockId(block)));
}
}
private static Block makeBlock(int x, int y, int z) {
Block block = Mockito.mock(Block.class);
Mockito.when(block.getX()).thenReturn(x);
Mockito.when(block.getY()).thenReturn(y);
Mockito.when(block.getZ()).thenReturn(z);
return block;
}
}

View File

@ -1,62 +0,0 @@
package org.bukkit.map;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.MaterialMapColor;
import org.junit.Assert;
import org.junit.Test;
public class MapTest {
private static final Logger logger = Logger.getLogger("MapTest");
private static final int[] modifiers = {180, 220, 255, 135};
@Test
public void testColors() {
MaterialMapColor[] nmsColors = MaterialMapColor.a;
Color[] bukkitColors = MapPalette.colors;
boolean fail = false;
for (int i = 0; i < nmsColors.length; i++) {
if (nmsColors[i] == null) {
break;
}
int rgb = nmsColors[i].L;
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = rgb & 0xFF;
if (i > bukkitColors.length/4) {
for (int modi : modifiers) {
int mr = (r * modi) / 255;
int mg = (g * modi) / 255;
int mb = (b * modi) / 255;
logger.log(Level.WARNING, "Missing color: c({0}, {1}, {2})", new Object[]{mr, mg, mb});
}
fail = true;
} else {
for (int j = 0; j < modifiers.length; j++) {
int modi = modifiers[j];
Color bukkit = bukkitColors[i * 4 + j];
int mr = (r * modi) / 255;
int mg = (g * modi) / 255;
int mb = (b * modi) / 255;
if (bukkit.getRed() != mr || bukkit.getGreen() != mg || bukkit.getBlue() != mb) {
logger.log(Level.WARNING, "Incorrect color: {6} {7} c({0}, {1}, {2}) != c({3}, {4}, {5})", new Object[]{
bukkit.getRed(), bukkit.getGreen(), bukkit.getBlue(),
mr, mg, mb,
i, j
});
fail = true;
}
}
}
}
Assert.assertFalse(fail);
}
}

View File

@ -1,45 +0,0 @@
package org.bukkit.potion;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.EnumMap;
import java.util.Map;
import org.bukkit.support.AbstractTestingBase;
import org.bukkit.support.Util;
import org.junit.Test;
public class PotionTest extends AbstractTestingBase {
@Test
public void getEffects() {
for (PotionType type : PotionType.values()) {
for (PotionEffect effect : new Potion(type).getEffects()) {
PotionEffectType potionType = effect.getType();
assertThat(effect.getType(), is(sameInstance(PotionEffectType.getById(potionType.getId()))));
assertNotNull(potionType.getName(), PotionType.getByEffect(potionType));
}
}
}
@Test
public void testEffectCompleteness() throws Throwable {
Map<Integer, ?> effectDurations = Util.getInternalState(net.minecraft.server.PotionBrewer.class, null, "effectDurations");
Map<PotionType, String> effects = new EnumMap(PotionType.class);
for (int id : effectDurations.keySet()) {
PotionEffectType type = PotionEffectType.getById(id);
assertNotNull(String.valueOf(id), PotionEffectType.getById(id));
PotionType enumType = PotionType.getByEffect(type);
assertNotNull(type.getName(), enumType);
assertThat(enumType.name(), effects.put(enumType, enumType.name()), is(nullValue()));
}
assertThat(effects.entrySet(), hasSize(effectDurations.size()));
assertThat(effectDurations.entrySet(), hasSize(PotionType.values().length - /* WATER */ 1));
}
}

View File

@ -1,78 +0,0 @@
package org.bukkit.support;
import com.google.common.collect.ImmutableList;
import java.util.List;
import net.minecraft.server.DispenserRegistry;
import org.bukkit.Material;
import org.junit.BeforeClass;
/**
* If you are getting: java.lang.ExceptionInInitializerError
* at net.minecraft.server.StatisticList.<clinit>(SourceFile:58)
* at net.minecraft.server.Item.<clinit>(SourceFile:252)
* at net.minecraft.server.Block.<clinit>(Block.java:577)
*
* extend this class to solve it.
*/
public abstract class AbstractTestingBase {
public static final List<Material> INVALIDATED_MATERIALS = ImmutableList.<Material>builder()
.add(
Material.BREWING_STAND,
Material.BED_BLOCK,
Material.NETHER_WARTS,
Material.CAULDRON,
Material.FLOWER_POT,
Material.CROPS,
Material.SUGAR_CANE_BLOCK,
Material.CAKE_BLOCK,
Material.SKULL,
Material.PISTON_EXTENSION,
Material.PISTON_MOVING_PIECE,
Material.GLOWING_REDSTONE_ORE,
Material.DIODE_BLOCK_ON,
Material.PUMPKIN_STEM,
Material.SIGN_POST,
Material.REDSTONE_COMPARATOR_ON,
Material.TRIPWIRE,
Material.REDSTONE_LAMP_ON,
Material.MELON_STEM,
Material.REDSTONE_TORCH_OFF,
Material.REDSTONE_COMPARATOR_OFF,
Material.REDSTONE_WIRE,
Material.WALL_SIGN,
Material.DIODE_BLOCK_OFF,
Material.IRON_DOOR_BLOCK,
Material.WOODEN_DOOR,
Material.WATER,
Material.STATIONARY_WATER,
Material.LAVA,
Material.STATIONARY_LAVA,
Material.DOUBLE_STEP,
Material.DOUBLE_STEP,
Material.FIRE,
Material.PORTAL,
Material.ENDER_PORTAL,
Material.WOOD_DOUBLE_STEP,
Material.COCOA,
Material.CARROT,
Material.POTATO,
Material.STANDING_BANNER,
Material.WALL_BANNER,
Material.DAYLIGHT_DETECTOR_INVERTED,
Material.DOUBLE_STONE_SLAB2,
Material.SPRUCE_DOOR,
Material.BIRCH_DOOR,
Material.JUNGLE_DOOR,
Material.ACACIA_DOOR,
Material.DARK_OAK_DOOR
).build();
@BeforeClass
public static void setup() {
DispenserRegistry.c();
DummyServer.setup();
DummyPotions.setup();
DummyEnchantments.setup();
}
}

View File

@ -1,12 +0,0 @@
package org.bukkit.support;
import net.minecraft.server.Enchantment;
public class DummyEnchantments {
static {
Enchantment.getEffects();
org.bukkit.enchantments.Enchantment.stopAcceptingRegistrations();
}
public static void setup() {}
}

View File

@ -1,17 +0,0 @@
package org.bukkit.support;
import net.minecraft.server.MobEffectList;
import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffectType;
public class DummyPotions {
static {
Potion.setPotionBrewer(new CraftPotionBrewer());
MobEffectList.BLINDNESS.getClass();
PotionEffectType.stopAcceptingRegistrations();
}
public static void setup() {}
}

View File

@ -1,63 +0,0 @@
package org.bukkit.support;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.craftbukkit.inventory.CraftItemFactory;
import org.bukkit.craftbukkit.util.Versioning;
public class DummyServer implements InvocationHandler {
private interface MethodHandler {
Object handle(DummyServer server, Object[] args);
}
private static final HashMap<Method, MethodHandler> methods = new HashMap<>();
static {
try {
methods.put(
Server.class.getMethod("getItemFactory"),
(server, args) -> CraftItemFactory.instance()
);
methods.put(
Server.class.getMethod("getName"),
(server, args) -> DummyServer.class.getName()
);
methods.put(
Server.class.getMethod("getVersion"),
(server, args) -> DummyServer.class.getPackage().getImplementationVersion()
);
methods.put(
Server.class.getMethod("getBukkitVersion"),
(server, args) -> Versioning.getBukkitVersion()
);
methods.put(
Server.class.getMethod("getLogger"),
new MethodHandler() {
final Logger logger = Logger.getLogger(DummyServer.class.getCanonicalName());
public Object handle(DummyServer server, Object[] args) {
return logger;
}
}
);
Bukkit.setServer(Proxy.getProxyClass(Server.class.getClassLoader(), Server.class).asSubclass(Server.class).getConstructor(InvocationHandler.class).newInstance(new DummyServer()));
} catch (Throwable t) {
throw new Error(t);
}
}
public static void setup() {}
private DummyServer() {}
public Object invoke(Object proxy, Method method, Object[] args) {
MethodHandler handler = methods.get(method);
if (handler != null) {
return handler.handle(this, args);
}
throw new UnsupportedOperationException(String.valueOf(method));
}
}

View File

@ -1,30 +0,0 @@
package org.bukkit.support;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
public final class Matchers {
private Matchers() {}
public static <T> Matcher<T> sameHash(T value) {
return new SameHash<>(value);
}
static class SameHash<T> extends BaseMatcher<T> {
private final int expected;
SameHash(T object) {
expected = object.hashCode();
}
public boolean matches(Object item) {
return item.hashCode() == expected;
}
public void describeTo(Description description) {
description.appendValue(expected);
}
}
}

View File

@ -1,30 +0,0 @@
package org.bukkit.support;
import java.lang.reflect.Field;
public class Util {
/*
public static <T> T getInternalState(Object object, String fieldName) {
return getInternalState(object.getClass(), object, fieldName);
}
*/
@SuppressWarnings("unchecked")
public static <T> T getInternalState(Class<?> clazz, Object object, String fieldName) {
Field field;
try {
field = clazz.getDeclaredField(fieldName);
} catch (SecurityException e) {
throw new RuntimeException("Not allowed to access " + clazz, e);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Unable to find field " + fieldName, e);
}
field.setAccessible(true);
try {
return (T) field.get(object);
} catch (IllegalArgumentException | IllegalAccessException ignored) {
}
throw new RuntimeException("Unable to get internal value");
}
}