Change how disguise construction works, and a few minor other stuff
This commit is contained in:
parent
bca3483e49
commit
9042cb4212
@ -1,6 +1,8 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.libraryaddict.disguise.disguisetypes.*;
|
import me.libraryaddict.disguise.disguisetypes.*;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||||
@ -94,11 +96,11 @@ public class DisguiseAPI {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Disguise constructDisguise(Entity entity) {
|
public static Disguise constructDisguise(Entity entity) {
|
||||||
return constructDisguise(entity, true, true, true);
|
return constructDisguise(entity, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) {
|
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doAddedAnimations) {
|
||||||
DisguiseType disguiseType = DisguiseType.getType(entity);
|
DisguiseType disguiseType = DisguiseType.getType(entity);
|
||||||
Disguise disguise;
|
Disguise disguise;
|
||||||
|
|
||||||
@ -112,98 +114,38 @@ public class DisguiseAPI {
|
|||||||
|
|
||||||
FlagWatcher watcher = disguise.getWatcher();
|
FlagWatcher watcher = disguise.getWatcher();
|
||||||
|
|
||||||
if (entity instanceof LivingEntity) {
|
|
||||||
for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) {
|
|
||||||
((LivingWatcher) watcher).addPotionEffect(effect.getType());
|
|
||||||
|
|
||||||
if (effect.getType() == PotionEffectType.INVISIBILITY) {
|
|
||||||
watcher.setInvisible(true);
|
|
||||||
} else if (effect.getType() == PotionEffectType.GLOWING) {
|
|
||||||
watcher.setGlowing(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.getFireTicks() > 0) {
|
|
||||||
watcher.setBurning(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doEquipment && entity instanceof LivingEntity) {
|
if (doEquipment && entity instanceof LivingEntity) {
|
||||||
EntityEquipment equip = ((LivingEntity) entity).getEquipment();
|
EntityEquipment equip = ((LivingEntity) entity).getEquipment();
|
||||||
|
|
||||||
watcher.setArmor(equip.getArmorContents());
|
watcher.setArmor(equip.getArmorContents());
|
||||||
watcher.setItemInMainHand(equip.getItemInMainHand());
|
|
||||||
|
|
||||||
if (disguiseType.getEntityType() == EntityType.HORSE) {
|
ItemStack mainItem = equip.getItemInMainHand();
|
||||||
Horse horse = (Horse) entity;
|
|
||||||
HorseInventory horseInventory = horse.getInventory();
|
|
||||||
ItemStack saddle = horseInventory.getSaddle();
|
|
||||||
|
|
||||||
if (saddle != null && saddle.getType() == Material.SADDLE) {
|
if (mainItem != null && mainItem.getType() != Material.AIR) {
|
||||||
((AbstractHorseWatcher) watcher).setSaddled(true);
|
watcher.setItemInMainHand(mainItem);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Method method : entity.getClass().getMethods()) {
|
|
||||||
if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting")) &&
|
|
||||||
method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
|
|
||||||
Class methodReturn = method.getReturnType();
|
|
||||||
|
|
||||||
if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) {
|
|
||||||
methodReturn = double.class;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int firstCapitalMethod = firstCapital(method.getName());
|
ItemStack offItem = equip.getItemInMainHand();
|
||||||
|
|
||||||
if (firstCapitalMethod > 0) {
|
if (offItem != null && offItem.getType() != Material.AIR) {
|
||||||
for (Method watcherMethod : watcher.getClass().getMethods()) {
|
watcher.setItemInOffHand(offItem);
|
||||||
if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class &&
|
}
|
||||||
watcherMethod.getParameterTypes().length == 1) {
|
}
|
||||||
int firstCapitalWatcher = firstCapital(watcherMethod.getName());
|
|
||||||
|
|
||||||
if (firstCapitalWatcher > 0 &&
|
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity);
|
||||||
method.getName().substring(firstCapitalMethod).equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) {
|
|
||||||
Class methodParam = watcherMethod.getParameterTypes()[0];
|
|
||||||
|
|
||||||
if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) {
|
for (WrappedWatchableObject obj : dataWatcher.getWatchableObjects()) {
|
||||||
methodParam = double.class;
|
MetaIndex index = MetaIndex.getMetaIndex(watcher.getClass(), obj.getIndex());
|
||||||
} else if (methodParam == AnimalColor.class) {
|
|
||||||
methodParam = DyeColor.class;
|
if (index == null) {
|
||||||
}
|
|
||||||
if (methodReturn == methodParam) {
|
|
||||||
try {
|
|
||||||
Object value = method.invoke(entity);
|
|
||||||
if (value != null) {
|
|
||||||
Class toCast = watcherMethod.getParameterTypes()[0];
|
|
||||||
if (!(toCast.isInstance(value))) {
|
|
||||||
if (toCast == float.class) {
|
|
||||||
if (!(value instanceof Float)) {
|
|
||||||
double d = (Double) value;
|
|
||||||
value = (float) d;
|
|
||||||
}
|
|
||||||
} else if (toCast == double.class) {
|
|
||||||
if (!(value instanceof Double)) {
|
|
||||||
float d = (Float) value;
|
|
||||||
value = (double) d;
|
|
||||||
}
|
|
||||||
} else if (toCast == AnimalColor.class) {
|
|
||||||
value = AnimalColor.valueOf(((DyeColor) value).name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (value instanceof Boolean && !(Boolean) value && watcherMethod.getDeclaringClass() == FlagWatcher.class) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index.getDefault() == obj.getValue() || index.getDefault() == obj.getRawValue()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
watcherMethod.invoke(watcher, value);
|
|
||||||
} catch (Exception ex) {
|
watcher.setUnsafeData(index, obj.getRawValue());
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return disguise;
|
return disguise;
|
||||||
|
@ -33,8 +33,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean doEquipment = true;
|
boolean doEquipment = true;
|
||||||
boolean doSneak = false;
|
boolean doAdded = false;
|
||||||
boolean doSprint = false;
|
|
||||||
Player player = null;
|
Player player = null;
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
@ -45,20 +44,15 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
|
|||||||
String option = args[i];
|
String option = args[i];
|
||||||
if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
|
if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
|
||||||
doEquipment = false;
|
doEquipment = false;
|
||||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) {
|
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_ADDEDANIMATIONS.get())) {
|
||||||
doSneak = true;
|
doAdded = true;
|
||||||
doSprint = true;
|
|
||||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
|
|
||||||
doSneak = true;
|
|
||||||
} else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
|
|
||||||
doSprint = true;
|
|
||||||
} else {
|
} else {
|
||||||
LibsMsg.INVALID_CLONE.send(sender, option);
|
LibsMsg.INVALID_CLONE.send(sender, option);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
|
Boolean[] options = new Boolean[]{doEquipment, doAdded};
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
|
DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
|
||||||
@ -91,9 +85,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
|
|||||||
}
|
}
|
||||||
|
|
||||||
tabs.add(LibsMsg.DCLONE_EQUIP.get());
|
tabs.add(LibsMsg.DCLONE_EQUIP.get());
|
||||||
tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get());
|
tabs.add(LibsMsg.DCLONE_ADDEDANIMATIONS.get());
|
||||||
tabs.add(LibsMsg.DCLONE_SNEAK.get());
|
|
||||||
tabs.add(LibsMsg.DCLONE_SPRINT.get());
|
|
||||||
|
|
||||||
return filterTabs(tabs, origArgs);
|
return filterTabs(tabs, origArgs);
|
||||||
}
|
}
|
||||||
|
@ -990,6 +990,11 @@ public class FlagWatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public <Y> void setUnsafeData(MetaIndex<Y> id, Y value) {
|
||||||
|
setData(id, value);
|
||||||
|
}
|
||||||
|
|
||||||
protected <Y> void setData(MetaIndex<Y> id, Y value) {
|
protected <Y> void setData(MetaIndex<Y> id, Y value) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -558,7 +558,7 @@ public class DisguiseUtilities {
|
|||||||
Disguise disguise = DisguiseAPI.getDisguise(player, toClone);
|
Disguise disguise = DisguiseAPI.getDisguise(player, toClone);
|
||||||
|
|
||||||
if (disguise == null) {
|
if (disguise == null) {
|
||||||
disguise = DisguiseAPI.constructDisguise(toClone, options[0], options[1], options[2]);
|
disguise = DisguiseAPI.constructDisguise(toClone, options[0], options[1]);
|
||||||
} else {
|
} else {
|
||||||
disguise = disguise.clone();
|
disguise = disguise.clone();
|
||||||
}
|
}
|
||||||
|
@ -1895,7 +1895,7 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
for (MetaIndex index : indexes) {
|
for (MetaIndex index : indexes) {
|
||||||
DisguiseUtilities.getLogger()
|
DisguiseUtilities.getLogger()
|
||||||
.warning(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
|
.severe(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
||||||
|
@ -82,9 +82,7 @@ public enum LibsMsg {
|
|||||||
DHELP_SHOW("Show"),
|
DHELP_SHOW("Show"),
|
||||||
DHELP_NO_OPTIONS(ChatColor.RED + "No options with permission to use"),
|
DHELP_NO_OPTIONS(ChatColor.RED + "No options with permission to use"),
|
||||||
DCLONE_EQUIP("ignoreEquip"),
|
DCLONE_EQUIP("ignoreEquip"),
|
||||||
DCLONE_SNEAKSPRINT("doSneakSprint"),
|
DCLONE_ADDEDANIMATIONS("doAddedAnimations"),
|
||||||
DCLONE_SNEAK("doSneak"),
|
|
||||||
DCLONE_SPRINT("doSprint"),
|
|
||||||
DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" +
|
DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" +
|
||||||
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Methods>")
|
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Methods>")
|
||||||
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
|
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
|
||||||
|
Loading…
Reference in New Issue
Block a user