Implement ItemFactory and ItemMeta values. Adds BUKKIT-15

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
CraftBukkit/Spigot
2012-12-17 01:31:41 -06:00
parent 9d7ccb79f2
commit 1d39ac678a
46 changed files with 3701 additions and 222 deletions

View File

@@ -17,5 +17,8 @@ public abstract class AbstractTestingBase {
@BeforeClass
public static void setup() {
StatisticList.a();
DummyServer.setup();
DummyPotions.setup();
DummyEnchantments.setup();
}
}

View File

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

View File

@@ -0,0 +1,17 @@
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

@@ -0,0 +1,79 @@
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 static interface MethodHandler {
Object handle(DummyServer server, Object[] args);
}
private static final HashMap<Method, MethodHandler> methods = new HashMap<Method, MethodHandler>();
static {
try {
methods.put(
Server.class.getMethod("getItemFactory"),
new MethodHandler() {
public Object handle(DummyServer server, Object[] args) {
return CraftItemFactory.instance();
}
}
);
methods.put(
Server.class.getMethod("getName"),
new MethodHandler() {
public Object handle(DummyServer server, Object[] args) {
return DummyServer.class.getName();
}
}
);
methods.put(
Server.class.getMethod("getVersion"),
new MethodHandler() {
public Object handle(DummyServer server, Object[] args) {
return DummyServer.class.getPackage().getImplementationVersion();
}
}
);
methods.put(
Server.class.getMethod("getBukkitVersion"),
new MethodHandler() {
public Object handle(DummyServer server, Object[] args) {
return 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

@@ -0,0 +1,30 @@
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<T>(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);
}
}
}