diff --git a/pom.xml b/pom.xml index 27c85c2c..e60d7274 100644 --- a/pom.xml +++ b/pom.xml @@ -43,12 +43,12 @@ org.spigotmc spigot-api - 1.13-R0.1-SNAPSHOT + 1.13.1-R0.1-SNAPSHOT org.spigotmc spigot - 1.13-R0.1-SNAPSHOT + 1.13.1-R0.1-SNAPSHOT diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index a599849f..120ed000 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -453,10 +453,6 @@ public class LibsDisguises extends JavaPlugin { default: break; } - - if (nmsEntityName != null) { - nmsClass = ReflectionManager.getNmsClass("Entity" + nmsEntityName); - } } try { @@ -506,6 +502,7 @@ public class LibsDisguises extends JavaPlugin { WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); ArrayList indexes = MetaIndex.getFlags(disguiseType.getWatcherClass()); + boolean loggedName = false; for (WrappedWatchableObject watch : watcher.getWatchableObjects()) { MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex()); @@ -522,14 +519,25 @@ public class LibsDisguises extends JavaPlugin { Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault()); Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getValue()); - if (ourValue != nmsValue && - ((ourValue == null || nmsValue == null) || ourValue.getClass() != nmsValue.getClass())) { - getLogger().severe("[MetaIndex mismatch for " + disguiseType + "! Index: " + watch.getIndex()); - getLogger().severe("MetaIndex: " + flagType.getDefault() + " (" + - flagType.getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " + - watcherClass.getSimpleName()); + if (ourValue.getClass() != nmsValue.getClass()) { + if (!loggedName) { + getLogger().severe(StringUtils.repeat("=", 20)); + getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + + nmsEntityName); + loggedName = true; + } + + getLogger().severe(StringUtils.repeat("-", 20)); + getLogger().severe("Index: " + watch.getIndex() + " | " + + flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType)); + Object flagDefault = flagType.getDefault(); + + getLogger().severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")"); + getLogger().severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")"); getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ")"); + getLogger().severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")"); + getLogger().severe(StringUtils.repeat("-", 20)); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index fcc3a20b..bca8306b 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -33,7 +33,7 @@ public class MetaIndex { public static MetaIndex AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3, Particle.SPELL_MOB); - public static MetaIndex AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 0F); + public static MetaIndex AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 3F); public static MetaIndex ARMORSTAND_BODY = new MetaIndex<>(ArmorStandWatcher.class, 2, new Vector3F(0, 0, 0)); @@ -42,28 +42,30 @@ public class MetaIndex { new Vector3F(0, 0, 0)); public static MetaIndex ARMORSTAND_LEFT_ARM = new MetaIndex<>(ArmorStandWatcher.class, 3, - new Vector3F(0, 0, 0)); + new Vector3F(-10, 0, -10)); public static MetaIndex ARMORSTAND_LEFT_LEG = new MetaIndex<>(ArmorStandWatcher.class, 5, - new Vector3F(0, 0, 0)); + new Vector3F(-1, 0, -1)); public static MetaIndex ARMORSTAND_META = new MetaIndex<>(ArmorStandWatcher.class, 0, (byte) 0); public static MetaIndex ARMORSTAND_RIGHT_ARM = new MetaIndex<>(ArmorStandWatcher.class, 4, - new Vector3F(0, 0, 0)); + new Vector3F(-15, 0, 10)); public static MetaIndex ARMORSTAND_RIGHT_LEG = new MetaIndex<>(ArmorStandWatcher.class, 6, - new Vector3F(0, 0, 0)); + new Vector3F(1, 0, 1)); public static MetaIndex ARROW_CRITICAL = new MetaIndex<>(ArrowWatcher.class, 0, (byte) 0); + public static MetaIndex> ARROW_UUID = new MetaIndex<>(ArrowWatcher.class, 1, Optional.empty()); + public static MetaIndex BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1); public static MetaIndex BLAZE_BLAZING = new MetaIndex<>(BlazeWatcher.class, 0, (byte) 0); - public static MetaIndex BOAT_DAMAGE = new MetaIndex<>(BoatWatcher.class, 2, 40F); + public static MetaIndex BOAT_DAMAGE = new MetaIndex<>(BoatWatcher.class, 2, 0F); - public static MetaIndex BOAT_DIRECTION = new MetaIndex<>(BoatWatcher.class, 1, 0); + public static MetaIndex BOAT_DIRECTION = new MetaIndex<>(BoatWatcher.class, 1, 1); public static MetaIndex BOAT_LAST_HIT = new MetaIndex<>(BoatWatcher.class, 0, 0); @@ -89,21 +91,21 @@ public class MetaIndex { public static MetaIndex DOLPHIN_BREATH = new MetaIndex<>(DolphinWatcher.class, 2, 2400); public static MetaIndex DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0, - new ItemStack(Material.STONE)); + new ItemStack(Material.AIR)); public static MetaIndex> ENDER_CRYSTAL_BEAM = new MetaIndex<>(EnderCrystalWatcher.class, 0, Optional.empty()); - public static MetaIndex ENDER_CRYSTAL_PLATE = new MetaIndex<>(EnderCrystalWatcher.class, 1, false); + public static MetaIndex ENDER_CRYSTAL_PLATE = new MetaIndex<>(EnderCrystalWatcher.class, 1, true); - public static MetaIndex ENDERD_RAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 0); + public static MetaIndex ENDER_DRAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 10); public static MetaIndex ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false); public static MetaIndex> ENDERMAN_ITEM = new MetaIndex<>(EndermanWatcher.class, 0, Optional.empty()); - public static MetaIndex ENTITY_AIR_TICKS = new MetaIndex<>(FlagWatcher.class, 1, 0); + public static MetaIndex ENTITY_AIR_TICKS = new MetaIndex<>(FlagWatcher.class, 1, 300); public static MetaIndex> ENTITY_CUSTOM_NAME = new MetaIndex<>(FlagWatcher.class, 2, Optional.empty()); @@ -120,7 +122,7 @@ public class MetaIndex { BlockPosition.ORIGIN); public static MetaIndex FIREWORK_ITEM = new MetaIndex<>(FireworkWatcher.class, 0, - new ItemStack(Material.AIR)); + new ItemStack(Material.FIREWORK_ROCKET)); public static MetaIndex FISH_FROM_BUCKET = new MetaIndex<>(FishWatcher.class, 0, false); @@ -169,9 +171,9 @@ public class MetaIndex { public static MetaIndex LIVING_POTIONS = new MetaIndex<>(LivingWatcher.class, 2, 0); - public static MetaIndex LLAMA_CARPET = new MetaIndex<>(LlamaWatcher.class, 1, 0); + public static MetaIndex LLAMA_CARPET = new MetaIndex<>(LlamaWatcher.class, 1, -1); - public static MetaIndex LLAMA_COLOR = new MetaIndex<>(LlamaWatcher.class, 2, -1); + public static MetaIndex LLAMA_COLOR = new MetaIndex<>(LlamaWatcher.class, 2, 0); public static MetaIndex LLAMA_STRENGTH = new MetaIndex<>(LlamaWatcher.class, 0, 0); @@ -179,7 +181,7 @@ public class MetaIndex { public static MetaIndex MINECART_BLOCK_VISIBLE = new MetaIndex<>(MinecartWatcher.class, 5, false); - public static MetaIndex MINECART_BLOCK_Y = new MetaIndex<>(MinecartWatcher.class, 4, 0); + public static MetaIndex MINECART_BLOCK_Y = new MetaIndex<>(MinecartWatcher.class, 4, 6); public static MetaIndex MINECART_SHAKING_DIRECTION = new MetaIndex<>(MinecartWatcher.class, 1, 1); @@ -229,7 +231,7 @@ public class MetaIndex { public static MetaIndex> SHULKER_ATTACHED = new MetaIndex<>(ShulkerWatcher.class, 1, Optional.empty()); - public static MetaIndex SHULKER_COLOR = new MetaIndex<>(ShulkerWatcher.class, 3, (byte) 10); + public static MetaIndex SHULKER_COLOR = new MetaIndex<>(ShulkerWatcher.class, 3, (byte) 16); public static MetaIndex SHULKER_FACING = new MetaIndex<>(ShulkerWatcher.class, 0, Direction.DOWN); @@ -237,21 +239,21 @@ public class MetaIndex { public static MetaIndex SKELETON_SWING_ARMS = new MetaIndex<>(SkeletonWatcher.class, 0, false); - public static MetaIndex SLIME_SIZE = new MetaIndex<>(SlimeWatcher.class, 0, 0); + public static MetaIndex SLIME_SIZE = new MetaIndex<>(SlimeWatcher.class, 0, 1); public static MetaIndex SNOWMAN_DERP = new MetaIndex<>(SnowmanWatcher.class, 0, (byte) 16); public static MetaIndex SPIDER_CLIMB = new MetaIndex<>(SpiderWatcher.class, 0, (byte) 0); - public static MetaIndex SPLASH_POTION_ITEM; + public static MetaIndex SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, + new ItemStack(Material.SPLASH_POTION)); public static MetaIndex TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0); public static MetaIndex> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1, Optional.empty()); - public static MetaIndex TIPPED_ARROW_COLOR = new MetaIndex<>(TippedArrowWatcher.class, 0, - Color.WHITE.asRGB()); + public static MetaIndex TIPPED_ARROW_COLOR = new MetaIndex<>(TippedArrowWatcher.class, 0, -1); public static MetaIndex TNT_FUSE_TICKS = new MetaIndex<>(TNTWatcher.class, 0, Integer.MAX_VALUE); @@ -293,7 +295,7 @@ public class MetaIndex { public static MetaIndex WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 2, 14); - public static MetaIndex WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 0F); + public static MetaIndex WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 1F); public static MetaIndex ZOMBIE_AGGRESSIVE = new MetaIndex<>(ZombieWatcher.class, 2, false); @@ -308,14 +310,6 @@ public class MetaIndex { public static MetaIndex ZOMBIE_VILLAGER_SHAKING = new MetaIndex<>(ZombieVillagerWatcher.class, 0, false); static { - try { - SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, - new ItemStack(Material.valueOf("SPLASH_POTION"))); - } - catch (Exception ex) { - SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, new ItemStack(Material.POTION)); - } - setValues(); orderMetaIndexes(); } @@ -432,7 +426,7 @@ public class MetaIndex { toPrint.sort(String.CASE_INSENSITIVE_ORDER); for (String s : toPrint) { - DisguiseUtilities.getLogger().info(s); + DisguiseUtilities.getLogger().info(s); } } @@ -486,6 +480,24 @@ public class MetaIndex { return _values; } + @Deprecated + public static String getName(MetaIndex metaIndex) { + try { + for (Field field : MetaIndex.class.getFields()) { + if (field.get(null) != metaIndex) { + continue; + } + + return field.getName(); + } + } + catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return null; + } + public static void addMetaIndexes(MetaIndex... metaIndexes) { _values = Arrays.copyOf(values(), values().length + metaIndexes.length); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java index c6be1090..76742ff2 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java @@ -3,6 +3,8 @@ 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 org.apache.commons.lang.math.RandomUtils; +import org.bukkit.Color; import org.bukkit.Particle; /** @@ -13,21 +15,13 @@ public class AreaEffectCloudWatcher extends FlagWatcher { public AreaEffectCloudWatcher(Disguise disguise) { super(disguise); - setRadius(1); + setColor(Color.fromRGB(RandomUtils.nextInt(256), RandomUtils.nextInt(256), RandomUtils.nextInt(256))); } public float getRadius() { return getData(MetaIndex.AREA_EFFECT_RADIUS); } - public int getColor() { - return getData(MetaIndex.AREA_EFFECT_CLOUD_COLOR); - } - - public boolean isIgnoreRadius() { - return getData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); - } - public void setRadius(float radius) { if (radius > 30) radius = 30; @@ -36,11 +30,20 @@ public class AreaEffectCloudWatcher extends FlagWatcher { sendData(MetaIndex.AREA_EFFECT_RADIUS); } - public void setColor(int color) { - setData(MetaIndex.AREA_EFFECT_CLOUD_COLOR, color); + public Color getColor() { + int color = getData(MetaIndex.AREA_EFFECT_CLOUD_COLOR); + return Color.fromRGB(color); + } + + public void setColor(Color color) { + setData(MetaIndex.AREA_EFFECT_CLOUD_COLOR, color.asRGB()); sendData(MetaIndex.AREA_EFFECT_CLOUD_COLOR); } + public boolean isIgnoreRadius() { + return getData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); + } + public void setIgnoreRadius(boolean ignore) { setData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS, ignore); sendData(MetaIndex.AREA_EFFECT_IGNORE_RADIUS); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java index 307edb5c..bcb9de03 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java @@ -10,7 +10,7 @@ public class ArrowWatcher extends FlagWatcher { } public boolean isCritical() { - return (byte) getData(MetaIndex.ARROW_CRITICAL) == 1; + return getData(MetaIndex.ARROW_CRITICAL) == 1; } public void setCritical(boolean critical) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java index 79298032..3c9cd10f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java @@ -16,12 +16,12 @@ public class EnderDragonWatcher extends InsentientWatcher public int getPhase() { - return getData(MetaIndex.ENDERD_RAGON_PHASE); + return getData(MetaIndex.ENDER_DRAGON_PHASE); } public void setPhase(int phase) { - setData(MetaIndex.ENDERD_RAGON_PHASE, phase); - sendData(MetaIndex.ENDERD_RAGON_PHASE); + setData(MetaIndex.ENDER_DRAGON_PHASE, phase); + sendData(MetaIndex.ENDER_DRAGON_PHASE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index 3b260183..dfb50931 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -1,71 +1,38 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; - import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.ReflectionManager; +import org.bukkit.Color; +import org.bukkit.entity.Entity; +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; public class LivingWatcher extends FlagWatcher { - static Map list = new HashMap<>(); - static Method getId; - - static { - try { - getId = ReflectionManager - .getNmsMethod("MobEffectList", "getId", ReflectionManager.getNmsClass("MobEffectList")); - Object REGISTRY = ReflectionManager.getNmsField("MobEffectList", "REGISTRY").get(null); - - for (Object next : ((Iterable) REGISTRY)) { - int id = (int) getId.invoke(null, next); - list.put(id, next); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - } - private double maxHealth; private boolean maxHealthSet; - private HashSet potionEffects = new HashSet<>(); + private HashSet potionEffects = new HashSet<>(); public LivingWatcher(Disguise disguise) { super(disguise); } - public void addPotionEffect(PotionEffectType potionEffect) { - if (!hasPotionEffect(potionEffect)) { - removePotionEffect(potionEffect); - potionEffects.add(potionEffect.getId()); - - sendPotionEffects(); - } - } - @Override public LivingWatcher clone(Disguise disguise) { LivingWatcher clone = (LivingWatcher) super.clone(disguise); - clone.potionEffects = (HashSet) potionEffects.clone(); + clone.potionEffects = (HashSet) potionEffects.clone(); clone.maxHealth = maxHealth; clone.maxHealthSet = maxHealthSet; @@ -73,7 +40,7 @@ public class LivingWatcher extends FlagWatcher { } public float getHealth() { - return (float) getData(MetaIndex.LIVING_HEALTH); + return getData(MetaIndex.LIVING_HEALTH); } public double getMaxHealth() { @@ -81,53 +48,75 @@ public class LivingWatcher extends FlagWatcher { } public boolean isPotionParticlesAmbient() { - return (boolean) getData(MetaIndex.LIVING_POTION_AMBIENT); + return getData(MetaIndex.LIVING_POTION_AMBIENT); + } + + public Color getParticlesColor() { + int color = getData(MetaIndex.LIVING_POTIONS); + return Color.fromRGB(color); + } + + public void setParticlesColor(Color color) { + potionEffects.clear(); + + setData(MetaIndex.LIVING_POTIONS, color.asRGB()); + sendData(MetaIndex.LIVING_POTIONS); } private int getPotions() { - int m = 3694022; - if (potionEffects.isEmpty()) { - return m; + return 0; } - float f1 = 0.0F; - float f2 = 0.0F; - float f3 = 0.0F; - float f4 = 0.0F; - try { - for (int localMobEffect : potionEffects) { - int n = (Integer) getId.invoke(null, list.get(localMobEffect)); - f1 += (n >> 16 & 0xFF) / 255.0F; - f2 += (n >> 8 & 0xFF) / 255.0F; - f3 += (n & 0xFF) / 255.0F; - f4 += 1.0F; + ArrayList colors = new ArrayList<>(); + + for (String typeId : potionEffects) { + PotionEffectType type = PotionEffectType.getByName(typeId); + + if (type == null) { + continue; } - } - catch (Exception ex) { - ex.printStackTrace(); + + Color color = type.getColor(); + + if (color == null) { + continue; + } + + colors.add(color); } - f1 = f1 / f4 * 255.0F; - f2 = f2 / f4 * 255.0F; - f3 = f3 / f4 * 255.0F; + if (colors.isEmpty()) { + return 0; + } - return (int) f1 << 16 | (int) f2 << 8 | (int) f3; + Color color = colors.remove(0); + + return color.mixColors(colors.toArray(new Color[0])).asRGB(); } public boolean hasPotionEffect(PotionEffectType type) { - return potionEffects.contains(type.getId()); + return potionEffects.contains(type.getName()); } public boolean isMaxHealthSet() { return maxHealthSet; } - public void removePotionEffect(PotionEffectType type) { - if (potionEffects.contains(type.getId())) { - potionEffects.remove(type.getId()); - sendPotionEffects(); + public void addPotionEffect(PotionEffectType potionEffect) { + if (!hasPotionEffect(potionEffect)) { + potionEffects.add(potionEffect.getName()); } + + sendPotionEffects(); + } + + public void removePotionEffect(PotionEffectType potionEffect) { + if (hasPotionEffect(potionEffect)) { + potionEffects.remove(potionEffect.getId()); + } + + sendPotionEffects(); } public void setPotionParticlesAmbient(boolean particles) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java index b73b85d0..58828732 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java @@ -1,26 +1,26 @@ 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.DisguiseUtilities; +import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Color; /** * @author Navid */ public class TippedArrowWatcher extends ArrowWatcher { + public TippedArrowWatcher(Disguise disguise) { super(disguise); - int r = DisguiseUtilities.random.nextInt(256); - int g = DisguiseUtilities.random.nextInt(256); - int b = DisguiseUtilities.random.nextInt(256); - - setColor(Color.fromRGB(r, g, b)); + if (getDisguise().getType() != DisguiseType.ARROW) { + setColor(Color.fromRGB(RandomUtils.nextInt(256), RandomUtils.nextInt(256), RandomUtils.nextInt(256))); + } } public Color getColor() { - int color = (int) getData(MetaIndex.TIPPED_ARROW_COLOR); + int color = getData(MetaIndex.TIPPED_ARROW_COLOR); return Color.fromRGB(color); } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index 3c3c2aaa..6f569698 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -17,10 +17,12 @@ import org.bukkit.util.EulerAngle; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map.Entry; import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class DisguiseParser { public static class DisguiseParseException extends Exception { @@ -435,41 +437,15 @@ public class DisguiseParser { * Splits a string while respecting quotes */ public static String[] split(String string) { - String[] strings = ChatColor.translateAlternateColorCodes('&', string).split(" "); + Matcher matcher = Pattern.compile("\"(?:\"(?=\\S)|\\\\\"|[^\"])*(?:[^\\\\]\"(?=\\s|$))|\\S+").matcher(string); - ArrayList list = new ArrayList<>(); - StringBuilder builder = new StringBuilder(); + List list = new ArrayList<>(); - for (String s : strings) { - String a = s.replaceAll("\\\\", ""); - - if (builder.length() != 0 || s.startsWith("\"")) { - if (builder.length() != 0) - builder.append(' '); - - String append; - - if (s.startsWith("\"")) - builder.append(s.substring(1)); - else if (a.endsWith("\"") && !a.endsWith("\\\"")) - builder.append(s.substring(0, s.length() - 1)); - else - builder.append(s); - - if (a.endsWith("\"") && !a.endsWith("\\\"")) { - list.add(builder.toString()); - builder = new StringBuilder(); - } - } else { - list.add(s); - } + while (matcher.find()) { + list.add(matcher.group()); } - if (builder.length() != 0) { - list.addAll(Arrays.asList(("\"" + builder.toString()).split(" "))); - } - - return list.toArray(new String[list.size()]); + return list.toArray(new String[0]); } /** @@ -844,6 +820,29 @@ public class DisguiseParser { } else if (param == Ocelot.Type.class) { // Parse to ocelot type value = callValueOf(param, valueString, methodName); + } else if (param == Color.class) { + Class cl = Class.forName("org.bukkit.Color"); + + try { + value = cl.getField(valueString.toUpperCase()).get(null); + } + catch (Exception ex) { + try { + String[] split = valueString.split(","); + + if (split.length == 1) { + value = Color.fromRGB(Integer.parseInt(split[0])); + } else if (split.length == 3) { + value = Color.fromRGB(Integer.parseInt(split[0]), Integer.parseInt(split[1]), + Integer.parseInt(split[2])); + } else { + throw new Exception(); + } + } + catch (Exception ex2) { + throw parseToException(param, valueString, methodName); + } + } } else if (param.getSimpleName().equals("TreeSpecies")) { // Parse to tree species value = callValueOf(param, valueString, methodName); @@ -915,7 +914,9 @@ public class DisguiseParser { try { String[] split = valueString.split(","); - assert split.length == 3; + if (split.length != 3) { + throw new Exception(); + } value = new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 33f960fe..fe6a8df5 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -857,8 +857,7 @@ public class DisguiseUtilities { gson = gsonBuilder.create(); try { - Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null); - Object world = ((List) server.getClass().getField("worlds").get(server)).get(0); + Object world = ReflectionManager.getWorldServer(Bukkit.getWorlds().get(0)); Class chunkClass = ReflectionManager.getNmsClass("Chunk"); Object bedChunk = null; @@ -883,8 +882,10 @@ public class DisguiseUtilities { .newInstance(0, true); Class blockClass = ReflectionManager.getNmsClass("Block"); + Object REGISTRY = ReflectionManager.getNmsField("IRegistry", "BLOCK").get(null); + Object minecraftKey = ReflectionManager.createMinecraftKey("white_bed"); - Object block = blockClass.getMethod("getByName", String.class).invoke(null, "white_bed"); + Object block = REGISTRY.getClass().getMethod("get", minecraftKey.getClass()).invoke(REGISTRY, minecraftKey); Object blockData = ReflectionManager.getNmsMethod(blockClass, "getBlockData").invoke(block); Method method = null; diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java index adfcb34b..3c18e99d 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionFlagWatchers.java @@ -14,6 +14,7 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.util.EulerAngle; import javax.annotation.Nullable; +import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.*; @@ -154,6 +155,25 @@ public class ReflectionFlagWatchers { new ParamInfo(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish"); new ParamInfo(DyeColor.class, "DyeColor", "Dye colors of many different colors"); + try { + ArrayList colors = new ArrayList<>(); + Class cl = Class.forName("org.bukkit.Color"); + + for (Field field : cl.getFields()) { + if (field.getType() != cl) { + continue; + } + + colors.add(field.getName()); + } + + new ParamInfo(Color.class, "Color", "Colors that can also be defined through RGB", + colors.toArray(new String[0])); + } + catch (ClassNotFoundException e) { + e.printStackTrace(); + } + ArrayList potionEnums = new ArrayList<>(); for (PotionEffectType effectType : PotionEffectType.values()) { diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 7e17991f..84210686 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -927,6 +927,16 @@ public class ReflectionManager { return null; } + public static Object createMinecraftKey(String name) { + try{ + return getNmsClass("MinecraftKey").getConstructor(String.class).newInstance(name); + }catch(Exception ex) { + ex.printStackTrace(); + } + + return null; + } + public static int getEntityType(Object nmsEntity) { try { Field entityTypesField = null; @@ -936,9 +946,9 @@ public class ReflectionManager { continue; Object entityType = method.invoke(nmsEntity); - Class typesClass = getNmsClass("EntityTypes"); + Class typesClass = getNmsClass("IRegistry"); - Object registry = typesClass.getField("REGISTRY").get(null); + Object registry = typesClass.getField("ENTITY_TYPE").get(null); return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType); }