Added API for EnderCrystal options

Removed Optionals from parameters in certain watchers
Fixed issue with createEntityEquipment in ReflectionManager, was using NMS instead of CraftBukkit classes
This commit is contained in:
NavidK0 2016-03-29 20:28:17 -04:00
parent 8690cd6604
commit 976d00dcc2
4 changed files with 56 additions and 5 deletions

View File

@ -0,0 +1,36 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
/**
* @author Navid
*/
public class EnderCrystalWatcher extends FlagWatcher {
public EnderCrystalWatcher(Disguise disguise) {
super(disguise);
}
public void setBeamTarget(BlockPosition position) {
setValue(5, Optional.of(position));
sendData(5);
}
public Optional<BlockPosition> getBeamTarget() {
return (Optional) getValue(5, Optional.absent());
}
public void setShowBottom(boolean bool) {
setValue(6, bool);
sendData(6);
}
public boolean isShowBottom() {
return (boolean) getValue(6, false);
}
}

View File

@ -153,8 +153,8 @@ public class HorseWatcher extends AgeableWatcher {
setHorseFlag(128, mouthOpen);
}
public void setOwner(Optional<UUID> uuid) {
setValue(15, uuid);
public void setOwner(UUID uuid) {
setValue(15, Optional.of(uuid));
sendData(15);
}

View File

@ -37,8 +37,8 @@ public class TameableWatcher extends AgeableWatcher {
sendData(12);
}
public void setOwner(Optional<UUID> owner) {
setValue(13, owner);
public void setOwner(UUID owner) {
setValue(13, Optional.of(owner));
sendData(13);
}

View File

@ -219,6 +219,21 @@ public class ReflectionManager {
return null;
}
public static Constructor getCraftConstructor(Class clazz, Class<?>... parameters) {
try {
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
declaredConstructor.setAccessible(true);
return declaredConstructor;
} catch (NoSuchMethodException e) {
e.printStackTrace(System.out);
}
return null;
}
public static Constructor getCraftConstructor(String className, Class<?>... parameters) {
return getCraftConstructor(getCraftClass(className), parameters);
}
public static String getCraftSound(Sound sound) {
try {
return (String) getCraftClass("CraftSound").getMethod("getSound", Sound.class).invoke(null, sound);
@ -655,7 +670,7 @@ public class ReflectionManager {
public static EntityEquipment createEntityEquipment(Entity entity) {
if (!(entity instanceof LivingEntity)) return null;
Constructor construct = getNmsConstructor("CraftEntityEquipment", getNmsClass("CraftLivingEntity"));
Constructor construct = getCraftConstructor("CraftEntityEquipment", getCraftClass("CraftLivingEntity"));
try {
return (EntityEquipment) construct.newInstance((LivingEntity) entity);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException e) {