Fixed typos, added DisguiseParser.parsetoString(Disguise)

This commit is contained in:
libraryaddict 2019-12-31 19:35:21 +13:00
parent ce1472eaf7
commit 7aa3a8a2ef
54 changed files with 555 additions and 114 deletions

View File

@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
@ -77,6 +78,8 @@ public class LibsDisguises extends JavaPlugin {
DisguiseConfig.loadConfig();
DisguiseParser.createDefaultMethods();
PacketsManager.addPacketListeners();
listener = new DisguiseListener(this);

View File

@ -87,7 +87,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setViewSelfDisguise"))
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;

View File

@ -131,7 +131,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setViewSelfDisguise"))
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;

View File

@ -219,7 +219,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
private boolean setViewDisguise(String[] strings) {
for (String string : strings) {
if (!string.equalsIgnoreCase("setViewSelfDisguise"))
if (!string.equalsIgnoreCase("setSelfDisguiseVisible"))
continue;
return true;

View File

@ -406,14 +406,24 @@ public abstract class Disguise {
return playerHiddenFromTab;
}
@Deprecated
public boolean isHidingArmorFromSelf() {
return hideArmorFromSelf;
}
@Deprecated
public boolean isHidingHeldItemFromSelf() {
return hideHeldItemFromSelf;
}
public boolean isHideArmorFromSelf() {
return hideArmorFromSelf;
}
public boolean isHideHeldItemFromSelf() {
return hideHeldItemFromSelf;
}
public boolean isKeepDisguiseOnPlayerDeath() {
return this.keepDisguisePlayerDeath;
}
@ -442,6 +452,7 @@ public abstract class Disguise {
(getEntity() instanceof Player ? !isKeepDisguiseOnPlayerDeath() : getEntity().isDead());
}
@Deprecated
public boolean isSelfDisguiseSoundsReplaced() {
return hearSelfDisguise;
}
@ -455,6 +466,10 @@ public abstract class Disguise {
return viewSelfDisguise;
}
public void setSelfDisguiseVisible(boolean selfDisguiseVisible) {
setViewSelfDisguise(selfDisguiseVisible);
}
/**
* Returns true if the entity's name is showing through the disguise
*
@ -619,6 +634,10 @@ public abstract class Disguise {
return this;
}
public boolean isHearSelfDisguise() {
return hearSelfDisguise;
}
public Disguise setHearSelfDisguise(boolean hearSelfDisguise) {
this.hearSelfDisguise = hearSelfDisguise;
@ -711,8 +730,6 @@ public abstract class Disguise {
getWatcher().setBackupValue(flag, backup == null ? null : backup.getDefault());
}
getWatcher().setNoGravity(true);
if (getEntity() instanceof Player && !getWatcher().hasCustomName()) {
getWatcher().setCustomName("");
}
@ -730,6 +747,7 @@ public abstract class Disguise {
* @param viewSelfDisguise
* @return
*/
@Deprecated
public Disguise setViewSelfDisguise(boolean viewSelfDisguise) {
if (isSelfDisguiseVisible() != viewSelfDisguise) {
this.viewSelfDisguise = viewSelfDisguise;

View File

@ -44,6 +44,8 @@ public class FlagWatcher {
public FlagWatcher(Disguise disguise) {
this.disguise = (TargetedDisguise) disguise;
equipment = new LibsEquipment(this);
setNoGravity(true);
}
private byte addEntityAnimations(byte originalValue, byte entityValue) {
@ -265,7 +267,7 @@ public class FlagWatcher {
return getCustomName() != null;
}
protected boolean hasValue(MetaIndex no) {
public boolean hasValue(MetaIndex no) {
if (no == null)
return false;
@ -280,6 +282,7 @@ public class FlagWatcher {
return getData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE);
}
@Deprecated
public boolean isEntityAnimationsAdded() {
return addEntityAnimations;
}
@ -335,7 +338,8 @@ public class FlagWatcher {
}
protected void sendData(MetaIndex... dataValues) {
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) {
if (getDisguise() == null || !DisguiseAPI.isDisguiseInUse(getDisguise()) ||
getDisguise().getWatcher() != this) {
return;
}
@ -391,6 +395,10 @@ public class FlagWatcher {
}
}
public boolean isAddEntityAnimations() {
return isEntityAnimationsAdded();
}
public void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
addEntityAnimations = isEntityAnimationsAdded;
}

View File

@ -24,6 +24,10 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
return isHorseFlag(8);
}
public boolean isCarryingChest() {
return hasChest();
}
/**
* If the horse can be breeded, no visible effect
*
@ -71,6 +75,11 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
return getData(MetaIndex.HORSE_META);
}
public void setBreedable(boolean breedable) {
setCanBreed(breedable);
}
@Deprecated
public void setCanBreed(boolean breed) {
setHorseFlag(16, breed);
}
@ -84,8 +93,7 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
if (flag) {
setData(MetaIndex.HORSE_META, (byte) (j | i));
}
else {
} else {
setData(MetaIndex.HORSE_META, (byte) (j & ~i));
}
@ -116,5 +124,4 @@ public abstract class AbstractHorseWatcher extends AgeableWatcher {
public void setTamed(boolean tamed) {
setHorseFlag(2, tamed);
}
}

View File

@ -15,4 +15,12 @@ public class AbstractVillagerWatcher extends AgeableWatcher {
setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks);
sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
}
public int getAngry() {
return getData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
}
public boolean isAngry() {
return getAngry() > 0;
}
}

View File

@ -4,6 +4,7 @@ import com.comphenix.protocol.wrappers.WrappedParticle;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Color;
import org.bukkit.Particle;
@ -36,6 +37,7 @@ public class AreaEffectCloudWatcher extends FlagWatcher {
return Color.fromRGB(color);
}
@RandomDefaultValue
public void setColor(Color color) {
setData(MetaIndex.AREA_EFFECT_CLOUD_COLOR, color.asRGB());
sendData(MetaIndex.AREA_EFFECT_CLOUD_COLOR);

View File

@ -3,23 +3,19 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class BatWatcher extends InsentientWatcher
{
public class BatWatcher extends InsentientWatcher {
public BatWatcher(Disguise disguise)
{
public BatWatcher(Disguise disguise) {
super(disguise);
setHanging(false);
}
public boolean isHanging()
{
public boolean isHanging() {
return getData(MetaIndex.BAT_HANGING) == 1;
}
public void setHanging(boolean hanging)
{
public void setHanging(boolean hanging) {
setData(MetaIndex.BAT_HANGING, hanging ? (byte) 1 : (byte) 0);
sendData(MetaIndex.BAT_HANGING);
}

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.DyeColor;
import org.bukkit.entity.Cat;
@ -22,6 +23,7 @@ public class CatWatcher extends TameableWatcher {
return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)];
}
@RandomDefaultValue
public void setType(Cat.Type type) {
setData(MetaIndex.CAT_TYPE, type.ordinal());
sendData(MetaIndex.CAT_TYPE);
@ -37,7 +39,7 @@ public class CatWatcher extends TameableWatcher {
setTamed(true);
}
if (newColor == getCollarColor().getDyeColor()) {
if (newColor == getCollarColor()) {
return;
}
@ -45,8 +47,8 @@ public class CatWatcher extends TameableWatcher {
sendData(MetaIndex.CAT_COLLAR);
}
public AnimalColor getCollarColor() {
return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR));
public DyeColor getCollarColor() {
return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor();
}
public void setLyingDown(boolean value) {

View File

@ -10,33 +10,26 @@ import java.util.Optional;
/**
* @author Navid
*/
public class EnderCrystalWatcher extends FlagWatcher
{
public EnderCrystalWatcher(Disguise disguise)
{
public class EnderCrystalWatcher extends FlagWatcher {
public EnderCrystalWatcher(Disguise disguise) {
super(disguise);
}
public void setBeamTarget(BlockPosition position)
{
setData(MetaIndex.ENDER_CRYSTAL_BEAM, Optional.of(position));
public void setBeamTarget(BlockPosition position) {
setData(MetaIndex.ENDER_CRYSTAL_BEAM, position == null ? Optional.empty() : Optional.of(position));
sendData(MetaIndex.ENDER_CRYSTAL_BEAM);
}
public Optional<BlockPosition> getBeamTarget()
{
return getData(MetaIndex.ENDER_CRYSTAL_BEAM);
public BlockPosition getBeamTarget() {
return getData(MetaIndex.ENDER_CRYSTAL_BEAM).orElse(null);
}
public void setShowBottom(boolean bool)
{
public void setShowBottom(boolean bool) {
setData(MetaIndex.ENDER_CRYSTAL_PLATE, bool);
sendData(MetaIndex.ENDER_CRYSTAL_PLATE);
}
public boolean isShowBottom()
{
public boolean isShowBottom() {
return getData(MetaIndex.ENDER_CRYSTAL_PLATE);
}
}

View File

@ -55,9 +55,4 @@ public class EndermanWatcher extends InsentientWatcher {
setData(MetaIndex.ENDERMAN_AGRESSIVE, isAggressive);
sendData(MetaIndex.ENDERMAN_AGRESSIVE);
}
public void setUnknown(boolean bo) {
setData(MetaIndex.ENDERMAN_UNKNOWN, bo);
sendData(MetaIndex.ENDERMAN_UNKNOWN);
}
}

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.entity.Fox;
import java.util.Random;
@ -40,6 +41,7 @@ public class FoxWatcher extends AgeableWatcher {
setFoxFlag(32, value);
}
@RandomDefaultValue
public Fox.Type getType() {
return Fox.Type.values()[getData(MetaIndex.FOX_TYPE)];
}

View File

@ -31,6 +31,13 @@ public class GuardianWatcher extends InsentientWatcher {
sendData(MetaIndex.GUARDIAN_TARGET);
}
/**
* @return Entity id of target
*/
public int getTarget() {
return getData(MetaIndex.GUARDIAN_TARGET);
}
public void setTarget(Entity entity) {
setTarget(entity == null ? 0 : entity.getEntityId());
}
@ -58,5 +65,4 @@ public class GuardianWatcher extends InsentientWatcher {
setData(MetaIndex.GUARDIAN_RETRACT_SPIKES, isRetracting);
sendData(MetaIndex.GUARDIAN_RETRACT_SPIKES);
}
}

View File

@ -1,13 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Material;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.inventory.ItemStack;
public class HorseWatcher extends AbstractHorseWatcher {
public HorseWatcher(Disguise disguise) {
@ -25,11 +24,13 @@ public class HorseWatcher extends AbstractHorseWatcher {
return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)];
}
@RandomDefaultValue
public void setColor(Color color) {
setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
sendData(MetaIndex.HORSE_COLOR);
}
@RandomDefaultValue
public void setStyle(Style style) {
setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(MetaIndex.HORSE_COLOR);

View File

@ -17,10 +17,7 @@ import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.*;
public class LivingWatcher extends FlagWatcher {
private double maxHealth;
@ -122,6 +119,22 @@ public class LivingWatcher extends FlagWatcher {
return maxHealthSet;
}
public PotionEffectType[] getPotionEffects() {
PotionEffectType[] effects = new PotionEffectType[potionEffects.size()];
int i = 0;
Iterator<String> itel = potionEffects.iterator();
while (itel.hasNext()) {
PotionEffectType type = PotionEffectType.getByName(itel.next());
effects[i++] = type;
}
return effects;
}
public void addPotionEffect(PotionEffectType potionEffect) {
if (!hasPotionEffect(potionEffect)) {
potionEffects.add(potionEffect.getName());

View File

@ -31,8 +31,12 @@ public class LlamaWatcher extends ChestedHorseWatcher {
setCarpet(color.getDyeColor());
}
public AnimalColor getCarpet() {
return AnimalColor.getColorByWool(getData(MetaIndex.LLAMA_CARPET));
public DyeColor getCarpet() {
if (!hasValue(MetaIndex.LLAMA_CARPET)) {
return null;
}
return AnimalColor.getColorByWool(getData(MetaIndex.LLAMA_CARPET)).getDyeColor();
}
public void setStrength(int strength) {

View File

@ -14,13 +14,22 @@ public class MinecartWatcher extends FlagWatcher {
}
public ItemStack getBlockInCart() {
if (!hasValue(MetaIndex.MINECART_BLOCK)) {
return new ItemStack(Material.AIR);
}
return ReflectionManager.getItemStackByCombinedId(getData(MetaIndex.MINECART_BLOCK));
}
@Deprecated
public int getBlockYOffset() {
return getData(MetaIndex.MINECART_BLOCK_Y);
}
public int getBlockOffset() {
return getData(MetaIndex.MINECART_BLOCK_Y);
}
public boolean isViewBlockInCart() {
return getData(MetaIndex.MINECART_BLOCK_VISIBLE);
}

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.entity.Panda;
import java.util.Random;
@ -45,11 +46,13 @@ public class PandaWatcher extends AgeableWatcher {
return Panda.Gene.NORMAL;
}
@RandomDefaultValue
public void setMainGene(Panda.Gene gene) {
setData(MetaIndex.PANDA_MAIN_GENE, (byte) gene.ordinal());
sendData(MetaIndex.PANDA_MAIN_GENE);
}
@RandomDefaultValue
public void setHiddenGene(Panda.Gene gene) {
setData(MetaIndex.PANDA_HIDDEN_GENE, (byte) gene.ordinal());
sendData(MetaIndex.PANDA_HIDDEN_GENE);
@ -92,6 +95,11 @@ public class PandaWatcher extends AgeableWatcher {
sendData(MetaIndex.PANDA_HEAD_SHAKING);
}
public int getHeadShaking() {
return getHeadShakingTicks();
}
@Deprecated
public int getHeadShakingTicks() {
return getData(MetaIndex.PANDA_HEAD_SHAKING);
}

View File

@ -11,7 +11,7 @@ public class PillagerWatcher extends IllagerWatcher {
super(disguise);
}
public void setAimimgBow(boolean value) {
public void setAimingBow(boolean value) {
setData(MetaIndex.PILLAGER_AIMING_BOW, value);
sendData(MetaIndex.PILLAGER_AIMING_BOW);
}

View File

@ -1,22 +1,14 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.EntityPose;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.MainHand;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseAPI;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.inventory.MainHand;
public class PlayerWatcher extends LivingWatcher {
private boolean alwaysShowInTab = DisguiseConfig.isShowDisguisedPlayersInTab();
@ -70,7 +62,7 @@ public class PlayerWatcher extends LivingWatcher {
return isSkinFlag(1);
}
public boolean isJackedEnabled() {
public boolean isJacketEnabled() {
return isSkinFlag(2);
}
@ -136,10 +128,15 @@ public class PlayerWatcher extends LivingWatcher {
sendData(MetaIndex.PLAYER_SKIN);
}
public WrappedGameProfile getSkin() {
return ((PlayerDisguise) getDisguise()).getGameProfile();
}
public void setSkin(String playerName) {
((PlayerDisguise) getDisguise()).setSkin(playerName);
}
@RandomDefaultValue
public void setSkin(WrappedGameProfile profile) {
((PlayerDisguise) getDisguise()).setSkin(profile);
}

View File

@ -4,25 +4,22 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
public class RabbitWatcher extends AgeableWatcher
{
public class RabbitWatcher extends AgeableWatcher {
public RabbitWatcher(Disguise disguise)
{
public RabbitWatcher(Disguise disguise) {
super(disguise);
setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]);
}
public RabbitType getType()
{
public RabbitType getType() {
return RabbitType.getType(getData(MetaIndex.RABBIT_TYPE));
}
public void setType(RabbitType type)
{
@RandomDefaultValue
public void setType(RabbitType type) {
setData(MetaIndex.RABBIT_TYPE, type.getTypeId());
sendData(MetaIndex.RABBIT_TYPE);
}
}

View File

@ -11,8 +11,8 @@ public class SheepWatcher extends AgeableWatcher {
super(disguise);
}
public AnimalColor getColor() {
return AnimalColor.getColorByWool(((int) getData(MetaIndex.SHEEP_WOOL) & 15));
public DyeColor getColor() {
return AnimalColor.getColorByWool(((int) getData(MetaIndex.SHEEP_WOOL) & 15)).getDyeColor();
}
public boolean isSheared() {

View File

@ -29,7 +29,7 @@ public class ShulkerWatcher extends InsentientWatcher {
}
public BlockPosition getAttachmentPosition() {
return getData(MetaIndex.SHULKER_ATTACHED).get();
return getData(MetaIndex.SHULKER_ATTACHED).orElse(BlockPosition.ORIGIN);
}
public void setAttachmentPosition(BlockPosition pos) {
@ -59,7 +59,7 @@ public class ShulkerWatcher extends InsentientWatcher {
}
public void setColor(DyeColor newColor) {
if (newColor == getColor().getDyeColor()) {
if (newColor == getColor()) {
return;
}
@ -67,7 +67,11 @@ public class ShulkerWatcher extends InsentientWatcher {
sendData(MetaIndex.SHULKER_COLOR);
}
public AnimalColor getColor() {
return AnimalColor.getColorByWool(getData(MetaIndex.SHULKER_COLOR));
public DyeColor getColor() {
if (!hasValue(MetaIndex.SHULKER_COLOR)) {
return DyeColor.PURPLE;
}
return AnimalColor.getColorByWool(getData(MetaIndex.SHULKER_COLOR)).getDyeColor();
}
}

View File

@ -3,11 +3,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
public class SlimeWatcher extends InsentientWatcher {
public SlimeWatcher(Disguise disguise) {
super(disguise);
setSize(DisguiseUtilities.random.nextInt(4) + 1);
}
@ -15,6 +17,7 @@ public class SlimeWatcher extends InsentientWatcher {
return getData(MetaIndex.SLIME_SIZE);
}
@RandomDefaultValue
public void setSize(int size) {
if (size < 1) {
size = 1;

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.inventory.ItemStack;
/**
@ -21,6 +22,7 @@ public abstract class ThrowableWatcher extends FlagWatcher {
return getData(MetaIndex.THROWABLE_ITEM);
}
@RandomDefaultValue
public void setItemStack(ItemStack item) {
setData(MetaIndex.THROWABLE_ITEM, item);
sendData(MetaIndex.THROWABLE_ITEM);

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Color;
@ -20,10 +21,15 @@ public class TippedArrowWatcher extends ArrowWatcher {
}
public Color getColor() {
if (!hasValue(MetaIndex.TIPPED_ARROW_COLOR)) {
return Color.GRAY;
}
int color = getData(MetaIndex.TIPPED_ARROW_COLOR);
return Color.fromRGB(color);
}
@RandomDefaultValue
public void setColor(Color color) {
setData(MetaIndex.TIPPED_ARROW_COLOR, color.asRGB());
sendData(MetaIndex.TIPPED_ARROW_COLOR);

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.DyeColor;
import org.bukkit.entity.TropicalFish;
@ -71,6 +72,7 @@ public class TropicalFishWatcher extends FishWatcher {
return DyeColor.getByWoolData((byte) (getVariant() >> 24 & 0xFF));
}
@RandomDefaultValue
public void setPatternColor(DyeColor dyeColor) {
setVariant(getData(dyeColor, getBodyColor(), getPattern()));
}
@ -84,6 +86,7 @@ public class TropicalFishWatcher extends FishWatcher {
return DyeColor.getByWoolData((byte) (getVariant() >> 16 & 0xFF));
}
@RandomDefaultValue
public void setBodyColor(DyeColor dyeColor) {
setVariant(getData(dyeColor, dyeColor, getPattern()));
}
@ -92,6 +95,7 @@ public class TropicalFishWatcher extends FishWatcher {
return CraftPattern.fromData(getVariant() & 0xFFFF);
}
@RandomDefaultValue
public void setPattern(TropicalFish.Pattern pattern) {
setVariant(getData(getPatternColor(), getBodyColor(), pattern));
}

View File

@ -4,6 +4,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.VillagerData;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
@ -45,6 +46,7 @@ public class VillagerWatcher extends AbstractVillagerWatcher {
return getVillagerData().getLevel();
}
@RandomDefaultValue
public void setProfession(Profession profession) {
setVillagerData(new VillagerData(getType(), profession, getLevel()));
}

View File

@ -11,8 +11,8 @@ public class WolfWatcher extends TameableWatcher {
super(disguise);
}
public AnimalColor getCollarColor() {
return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR));
public DyeColor getCollarColor() {
return AnimalColor.getColorByWool(getData(MetaIndex.WOLF_COLLAR)).getDyeColor();
}
public boolean isBegging() {
@ -42,7 +42,7 @@ public class WolfWatcher extends TameableWatcher {
setTamed(true);
}
if (newColor == getCollarColor().getDyeColor()) {
if (newColor == getCollarColor()) {
return;
}

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.VillagerData;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession;
@ -55,6 +56,7 @@ public class ZombieVillagerWatcher extends ZombieWatcher {
return getVillagerData().getLevel();
}
@RandomDefaultValue
public void setProfession(Profession profession) {
setVillagerData(new VillagerData(getType(), profession, getLevel()));
}

View File

@ -1,15 +1,13 @@
package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.*;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.mojang.authlib.properties.PropertyMap;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
@ -18,7 +16,6 @@ import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.json.*;
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
@ -29,8 +26,10 @@ import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.logging.log4j.util.Strings;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
@ -600,6 +599,12 @@ public class DisguiseUtilities {
return gson.fromJson(cached, WrappedGameProfile.class);
}
catch (JsonSyntaxException ex) {
DisguiseUtilities.getLogger()
.warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted");
cachedNames.remove(playerName.toLowerCase());
file.delete();
}
catch (Exception e) {
e.printStackTrace();
}
@ -705,8 +710,14 @@ public class DisguiseUtilities {
final String playerName = origName.toLowerCase();
if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) {
return getGameProfile(playerName);
} else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
WrappedGameProfile profile = getGameProfile(playerName);
if (profile != null) {
return profile;
}
}
if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
final Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {

View File

@ -182,17 +182,19 @@ public class PacketListenerClientInteract extends PacketAdapter {
if (disguise.getType() == DisguiseType.SHEEP) {
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color.getDyeColor() : watcher.getColor());
break;
} else if (disguise.getType() == DisguiseType.WOLF) {
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
watcher.setCollarColor(
DisguiseConfig.isWolfDyeable() ? color.getDyeColor() : watcher.getCollarColor());
break;
} else if (disguise.getType() == DisguiseType.CAT) {
CatWatcher watcher = (CatWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isCatDyeable() ? color : watcher.getCollarColor());
watcher.setCollarColor(
DisguiseConfig.isCatDyeable() ? color.getDyeColor() : watcher.getCollarColor());
break;
}
}

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities.parser;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.Gson;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -17,6 +18,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -25,6 +27,185 @@ import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
public class DisguiseParser {
private static HashMap<Method, Map.Entry<Method, Object>> defaultWatcherValues = new HashMap<>();
public static void createDefaultMethods() {
try {
for (DisguiseType type : DisguiseType.values()) {
Disguise disguise;
if (type.isMisc()) {
disguise = new MiscDisguise(type);
} else if (type.isMob()) {
disguise = new MobDisguise(type);
} else {
disguise = new PlayerDisguise("Foobar");
}
FlagWatcher watcher = type.getWatcherClass().getConstructor(Disguise.class).newInstance(disguise);
Method[] methods = ParamInfoManager.getDisguiseWatcherMethods(watcher.getClass());
for (Method setMethod : methods) {
// Invalidate methods that can't be handled normally
if (setMethod.getName().equals("addPotionEffect") || (setMethod.getName().equals("setSkin") &&
setMethod.getParameterTypes()[0] == String.class) ||
(setMethod.getName().equals("setTarget") &&
setMethod.getParameterTypes()[0] != int.class) ||
(setMethod.getName().equals("setItemInMainHand") &&
setMethod.getParameterTypes()[0] == Material.class)) {
continue;
}
String getName = setMethod.getName().substring(3); // Remove 'set'
if (getName.equals("HasNectar")) {
getName = "hasNectar";
} else if (getName.equals("HasStung")) {
getName = "hasStung";
} else if (setMethod.getParameterTypes()[0].isAssignableFrom(boolean.class)) {
getName = "is" + getName;
} else {
getName = "get" + getName;
}
Method getMethod = null;
for (Method m : setMethod.getDeclaringClass().getDeclaredMethods()) {
if (!m.getName().equals(getName)) {
continue;
}
if (m.getParameterTypes().length > 0 || m.getReturnType() != setMethod.getParameterTypes()[0]) {
continue;
}
getMethod = m;
break;
}
if (getMethod == null) {
DisguiseUtilities.getLogger().severe(String
.format("No such method '%s' when looking for the companion of '%s' in '%s'", getName,
setMethod.getName(), setMethod.getDeclaringClass().getSimpleName()));
continue;
}
Object defaultValue = null;
// Value is randomish so shouldn't be checked, should always specify value when setting
if (!setMethod.isAnnotationPresent(RandomDefaultValue.class)) {
Object invokeWith = watcher;
if (!FlagWatcher.class.isAssignableFrom(getMethod.getDeclaringClass())) {
invokeWith = disguise;
}
defaultValue = getMethod.invoke(invokeWith);
}
addWatcherDefault(setMethod, getMethod, defaultValue);
}
}
}
catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
public static String parseToString(Disguise disguise) {
try {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(disguise.getType().name());
if (disguise.isPlayerDisguise()) {
stringBuilder.append(" ").append(((PlayerDisguise) disguise).getName());
}
for (Method m : ParamInfoManager.getDisguiseWatcherMethods(disguise.getType().getWatcherClass())) {
// Special handling for this method
if (m.getName().equals("addPotionEffect")) {
PotionEffectType[] types = (PotionEffectType[]) m.getDeclaringClass().getMethod("getPotionEffects")
.invoke(disguise.getWatcher());
for (PotionEffectType type : types) {
if (type == null) {
continue;
}
stringBuilder.append(" ").append(m.getName()).append(" ").append(type.getName());
}
} else {
Entry<Method, Object> entry = defaultWatcherValues.get(m);
if (entry == null) {
continue;
}
Object invokeWith = m.getDeclaringClass().isInstance(disguise) ? disguise : disguise.getWatcher();
Object ourValue = entry.getKey().invoke(invokeWith);
// Escape a hacky fix for custom names, disguised players with custom names don't want to show it
// so it was set to an empty string.
if ("".equals(ourValue) && m.getName().equals("setCustomName")) {
ourValue = null;
}
// If its the same as default, continue
if (!m.isAnnotationPresent(RandomDefaultValue.class) &&
Objects.deepEquals(entry.getValue(), ourValue)) {
continue;
}
stringBuilder.append(" ").append(m.getName());
if (ourValue instanceof Boolean && (Boolean) ourValue) {
continue;
}
String valueString;
if (ourValue != null) {
valueString = ParamInfoManager.getParamInfo(ourValue.getClass()).toString(ourValue);
if (valueString.contains(" ") || valueString.contains("\"")) {
valueString = "\"" + valueString.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
}
} else {
valueString = "null";
}
stringBuilder.append(" ").append(valueString);
}
}
return stringBuilder.toString();
}
catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
private static void addWatcherDefault(Method setMethod, Method getMethod, Object object) {
Map.Entry<Method, Object> entry = new HashMap.SimpleEntry<>(getMethod, object);
if (defaultWatcherValues.containsKey(setMethod)) {
Object dObj = defaultWatcherValues.get(setMethod);
if (!Objects.deepEquals(defaultWatcherValues.get(setMethod).getValue(), object)) {
throw new IllegalStateException(String.format("%s has conflicting values!", setMethod.getName()));
}
return;
}
defaultWatcherValues.put(setMethod, entry);
}
private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm,
Collection<String> usedOptions) throws DisguiseParseException {

View File

@ -0,0 +1,14 @@
package me.libraryaddict.disguise.utilities.parser;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by libraryaddict on 31/12/2019.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RandomDefaultValue {
}

View File

@ -77,6 +77,8 @@ public abstract class ParamInfo {
protected abstract Object fromString(String string) throws DisguiseParseException;
public abstract String toString(Object object);
public Object fromString(List<String> arguments) throws DisguiseParseException {
// Don't consume a string immediately, if it errors we need to check other param types
String string = arguments.get(0);
@ -101,7 +103,7 @@ public abstract class ParamInfo {
return getValues() != null;
}
private Class getParamClass() {
protected Class getParamClass() {
return paramClass;
}

View File

@ -105,8 +105,8 @@ public class ParamInfoManager {
});
// Add these last as it's what we want to present to be called the least
for (String methodName : new String[]{"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf",
"setHearSelfDisguise", "setHidePlayer", "setExpires"}) {
for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf",
"setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires"}) {
try {
methods.add(Disguise.class
.getMethod(methodName, methodName.equals("setExpires") ? long.class : boolean.class));

View File

@ -107,9 +107,9 @@ public class ParamInfoTypes {
return paramInfos;
}
private Map<String, Object> getColors() {
private Map<String, Color> getColors() {
try {
Map<String, Object> map = new HashMap<>();
Map<String, Color> map = new HashMap<>();
Class cl = Class.forName("org.bukkit.Color");
for (Field field : cl.getFields()) {
@ -117,7 +117,7 @@ public class ParamInfoTypes {
continue;
}
map.put(field.getName(), field.get(null));
map.put(field.getName(), (Color) field.get(null));
}
return map;

View File

@ -21,7 +21,7 @@ public class ParamInfoEnum extends ParamInfo {
super(paramClass, name, name, description, possibleValues);
}
public ParamInfoEnum(Class paramClass, String name, String description, Map<String,Object> possibleValues) {
public ParamInfoEnum(Class paramClass, String name, String description, Map<String, Object> possibleValues) {
super(paramClass, name, name, description, possibleValues);
}
@ -39,4 +39,9 @@ public class ParamInfoEnum extends ParamInfo {
return null;
}
@Override
public String toString(Object object) {
return object.toString();
}
}

View File

@ -42,6 +42,11 @@ public class ParamInfoBoolean extends ParamInfo {
throw new IllegalStateException("This shouldn't be called");
}
@Override
public String toString(Object object) {
return object.toString();
}
@Override
public int getMinArguments() {
return 0;

View File

@ -19,4 +19,9 @@ public class ParamInfoDouble extends ParamInfo {
protected Object fromString(String string) {
return Double.parseDouble(string);
}
@Override
public String toString(Object object) {
return object.toString();
}
}

View File

@ -19,4 +19,9 @@ public class ParamInfoFloat extends ParamInfo {
protected Object fromString(String string) {
return Float.parseFloat(string);
}
@Override
public String toString(Object object) {
return object.toString();
}
}

View File

@ -19,4 +19,9 @@ public class ParamInfoInteger extends ParamInfo {
protected Object fromString(String string) {
return Integer.parseInt(string);
}
@Override
public String toString(Object object) {
return object.toString();
}
}

View File

@ -15,4 +15,9 @@ public class ParamInfoString extends ParamInfo {
protected Object fromString(String string) {
return ChatColor.translateAlternateColorCodes('&', string);
}
@Override
public String toString(Object object) {
return object.toString();
}
}

View File

@ -21,4 +21,11 @@ public class ParamInfoBlockPosition extends ParamInfo {
return new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
}
@Override
public String toString(Object object) {
BlockPosition position = (BlockPosition) object;
return String.format("%s,%s,%s", position.getX(), position.getY(), position.getZ());
}
}

View File

@ -9,23 +9,23 @@ import java.util.Map;
* Created by libraryaddict on 19/09/2018.
*/
public class ParamInfoColor extends ParamInfoEnum {
private static Map<String, Object> staticColors;
private static Map<String, Color> staticColors;
public ParamInfoColor(Class paramClass, String name, String description, Map<String, Object> possibleValues) {
public ParamInfoColor(Class paramClass, String name, String description, Map possibleValues) {
super(paramClass, name, description, possibleValues);
staticColors = possibleValues;
staticColors = (Map<String, Color>) possibleValues;
}
protected static Color parseToColor(String string) {
protected Color parseToColor(String string) {
string = string.replace("_", "");
for (Map.Entry<String, Object> entry : staticColors.entrySet()) {
for (Map.Entry<String, Color> entry : staticColors.entrySet()) {
if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) {
continue;
}
return (Color) entry.getValue();
return entry.getValue();
}
String[] split = string.split(",");
@ -39,6 +39,23 @@ public class ParamInfoColor extends ParamInfoEnum {
return null;
}
@Override
public String toString(Object object) {
Color color = (Color) object;
if (staticColors.containsValue(color)) {
for (String key : staticColors.keySet()) {
if (staticColors.get(key) != color) {
continue;
}
return key;
}
}
return String.format("%s,%s,%s", color.getRed(), color.getGreen(), color.getBlue());
}
@Override
protected Object fromString(String string) {
return parseToColor(string);

View File

@ -21,4 +21,11 @@ public class ParamInfoEulerAngle extends ParamInfo {
return new EulerAngle(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]));
}
@Override
public String toString(Object object) {
EulerAngle angle = (EulerAngle) object;
return String.format("%s,%s,%s", angle.getX(), angle.getY(), angle.getZ());
}
}

View File

@ -1,11 +1,11 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import java.lang.reflect.Method;
/**
* Created by libraryaddict on 7/09/2018.
*/
@ -15,7 +15,12 @@ public class ParamInfoGameProfile extends ParamInfo {
}
@Override
protected Object fromString( String string) {
protected Object fromString(String string) {
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
}
@Override
public String toString(Object object) {
return DisguiseUtilities.getGson().toJson(((WrappedGameProfile) object).getHandle(), GameProfile.class);
}
}

View File

@ -1,10 +1,12 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Created by libraryaddict on 7/09/2018.
@ -32,7 +34,20 @@ public class ParamInfoItemStack extends ParamInfoEnum {
return parseToItemstack(string);
}
@Override
public String toString(Object object) {
return DisguiseUtilities.getGson().toJson(object);
}
protected static ItemStack parseToItemstack(String string) {
if (string.startsWith("{") && string.endsWith("}")) {
try {
return DisguiseUtilities.getGson().fromJson(string, ItemStack.class);
}
catch (Exception ex) {
}
}
return parseToItemstack(string.split("[:,]")); // Split on colon or comma
}
@ -70,4 +85,8 @@ public class ParamInfoItemStack extends ParamInfoEnum {
return itemStack;
}
public boolean isParam(Class paramClass) {
return getParamClass().isAssignableFrom(paramClass);
}
}

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.inventory.ItemStack;
import java.util.LinkedHashSet;
@ -36,8 +37,21 @@ public class ParamInfoItemStackArray extends ParamInfoItemStack {
return toReturn;
}
@Override
public String toString(Object object) {
return DisguiseUtilities.getGson().toJson(object);
}
@Override
public Object fromString(String string) {
if (string.startsWith("{") && string.endsWith("}")) {
try {
return DisguiseUtilities.getGson().fromJson(string, ItemStack[].class);
}
catch (Exception ex) {
}
}
String[] split = string.split(",", -1);
if (split.length != 4) {

View File

@ -2,13 +2,15 @@ package me.libraryaddict.disguise.utilities.parser.params.types.custom;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedParticle;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.HashSet;
@ -57,6 +59,32 @@ public class ParamInfoParticle extends ParamInfoEnum {
return enums;
}
@Override
public String toString(Object object) {
WrappedParticle particle = (WrappedParticle) object;
Object data = particle.getData();
String returns = particle.getParticle().name();
if (data != null) {
if (data instanceof ItemStack) {
returns += "," + ((ItemStack) data).getType().name();
} else if (data instanceof WrappedBlockData) {
returns += "," + ((WrappedBlockData) data).getType().name();
} else if (data instanceof Particle.DustOptions) {
returns += "," +
ParamInfoManager.getParamInfo(Color.class).toString(((Particle.DustOptions) data).getColor());
if (((Particle.DustOptions) data).getSize() != 1f) {
returns += "," + ((Particle.DustOptions) data).getSize();
}
}
}
return returns;
}
@Override
public Object fromString(String string) throws DisguiseParseException {
String[] split = string.split("[:,]"); // Split on comma or colon
@ -99,7 +127,7 @@ public class ParamInfoParticle extends ParamInfoEnum {
throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string);
}
Color color = ParamInfoColor.parseToColor(
Color color = ((ParamInfoColor) ParamInfoManager.getParamInfo(Color.class)).parseToColor(
StringUtils.join(Arrays.copyOfRange(split, 1, split.length - (split.length % 2)), ","));
if (color == null) {

View File

@ -15,6 +15,10 @@ public class ParamInfoTime extends ParamInfo {
@Override
protected Object fromString(String string) throws DisguiseParseException {
if (string.matches("[0-9]{13,}")) {
return Long.parseLong(string);
}
long time = DisguiseParser.parseStringToTime(string);
// If disguise expires X ticks afterwards
@ -27,4 +31,9 @@ public class ParamInfoTime extends ParamInfo {
return time;
}
@Override
public String toString(Object object) {
return object.toString();
}
}

View File

@ -650,6 +650,9 @@ public class ReflectionManager {
return null;
}
/**
* Gets the UUID of the player, as well as properly capitalized playername
*/
public static WrappedGameProfile grabProfileAddUUID(String playername) {
try {
Object minecraftServer = getMinecraftServer();