Added 1.13.2 support, made backwards premium

This commit is contained in:
libraryaddict 2020-02-13 19:47:02 +13:00
parent 7fdbea1185
commit 1fcefbcdcc
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
49 changed files with 1114 additions and 539 deletions

25
pom.xml
View File

@ -8,7 +8,7 @@
<version>9.9.3-SNAPSHOT</version> <version>9.9.3-SNAPSHOT</version>
<build> <build>
<defaultGoal>clean install</defaultGoal> <defaultGoal>exec:java clean install</defaultGoal>
<finalName>LibsDisguises</finalName> <finalName>LibsDisguises</finalName>
<resources> <resources>
@ -31,6 +31,25 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version> <version>3.0.0-M1</version>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>my-execution</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>me.libraryaddict.disguise.utilities.reflection.CompileMethods</mainClass>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
@ -60,12 +79,12 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.15-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.15-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<!-- testing --> <!-- testing -->
<dependency> <dependency>

View File

@ -16,11 +16,11 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -308,9 +308,13 @@ public class DisguiseConfig {
try { try {
explain.createNewFile(); explain.createNewFile();
FileUtils.write(explain,
"This folder is used to store .png files for uploading with the /savedisguise or /grabskin " + try (PrintWriter out = new PrintWriter(explain)) {
"commands"); out.println(
"This folder is used to store .png files for uploading with the /savedisguise or " +
"/grabskin " +
"commands");
}
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -20,6 +20,8 @@ import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.stream.Collectors;
public class LibsDisguises extends JavaPlugin { public class LibsDisguises extends JavaPlugin {
private static LibsDisguises instance; private static LibsDisguises instance;
@ -71,7 +73,15 @@ public class LibsDisguises extends JavaPlugin {
if (ReflectionManager.getVersion() == null) { if (ReflectionManager.getVersion() == null) {
getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " + getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
"intended for 1.14 & 1.15!"); "intended for " + StringUtils
.join(Arrays.stream(NmsVersion.values()).map(v -> v.name().replace("_", "."))
.collect(Collectors.toList()), " & ") + "!");
getPluginLoader().disablePlugin(this);
return;
}
if (!LibsPremium.isPremium() && ReflectionManager.getVersion().ordinal() < NmsVersion.values().length - 1) {
getLogger().severe("Backwards compatibility is premium only! Use older builds or purchase the plugin!");
getPluginLoader().disablePlugin(this); getPluginLoader().disablePlugin(this);
return; return;
} }

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -9,17 +10,20 @@ public enum AnimalColor {
BROWN(DyeColor.BROWN, Material.COCOA_BEANS), BROWN(DyeColor.BROWN, Material.COCOA_BEANS),
CYAN(DyeColor.CYAN, Material.CYAN_DYE), CYAN(DyeColor.CYAN, Material.CYAN_DYE),
GRAY(DyeColor.GRAY, Material.GRAY_DYE), GRAY(DyeColor.GRAY, Material.GRAY_DYE),
GREEN(DyeColor.GREEN, Material.GREEN_DYE), GREEN(DyeColor.GREEN,
NmsVersion.v1_14.isSupported() ? Material.getMaterial("GREEN_DYE") : Material.getMaterial("CATCUS_GREEN")),
LIGHT_BLUE(DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_DYE), LIGHT_BLUE(DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_DYE),
LIME(DyeColor.LIME, Material.LIME_DYE), LIME(DyeColor.LIME, Material.LIME_DYE),
MAGENTA(DyeColor.MAGENTA, Material.MAGENTA_DYE), MAGENTA(DyeColor.MAGENTA, Material.MAGENTA_DYE),
ORANGE(DyeColor.ORANGE, Material.ORANGE_DYE), ORANGE(DyeColor.ORANGE, Material.ORANGE_DYE),
PINK(DyeColor.PINK, Material.PINK_DYE), PINK(DyeColor.PINK, Material.PINK_DYE),
PURPLE(DyeColor.PURPLE, Material.PURPLE_DYE), PURPLE(DyeColor.PURPLE, Material.PURPLE_DYE),
RED(DyeColor.RED, Material.RED_DYE), RED(DyeColor.RED,
NmsVersion.v1_14.isSupported() ? Material.getMaterial("RED_DYE") : Material.getMaterial("ROSE_RED")),
LIGHT_GRAY(DyeColor.LIGHT_GRAY, Material.LIGHT_GRAY_DYE), LIGHT_GRAY(DyeColor.LIGHT_GRAY, Material.LIGHT_GRAY_DYE),
WHITE(DyeColor.WHITE, Material.BONE_MEAL), WHITE(DyeColor.WHITE, Material.BONE_MEAL),
YELLOW(DyeColor.YELLOW, Material.YELLOW_DYE); YELLOW(DyeColor.YELLOW, NmsVersion.v1_14.isSupported() ? Material.getMaterial("YELLOW_DYE") :
Material.getMaterial("DANDELION_YELLOW"));
public static AnimalColor getColorByWool(int woolId) { public static AnimalColor getColorByWool(int woolId) {
for (AnimalColor color : values()) { for (AnimalColor color : values()) {

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.utilities.reflection.NmsAdded; import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.translations.TranslateType; import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -16,13 +17,13 @@ public enum DisguiseType {
BAT, BAT,
@NmsAdded(added = NmsVersion.v1_15) BEE, @NmsAddedIn(val = NmsVersion.v1_15) BEE,
BLAZE, BLAZE,
BOAT(1), BOAT(1),
CAT, @NmsAddedIn(val = NmsVersion.v1_14) CAT,
CAVE_SPIDER, CAVE_SPIDER,
@ -74,7 +75,7 @@ public enum DisguiseType {
FISHING_HOOK(90), FISHING_HOOK(90),
FOX, @NmsAddedIn(val = NmsVersion.v1_14) FOX,
GHAST, GHAST,
@ -122,7 +123,7 @@ public enum DisguiseType {
PAINTING, PAINTING,
PANDA, @NmsAddedIn(val = NmsVersion.v1_14) PANDA,
PARROT, PARROT,
@ -132,7 +133,7 @@ public enum DisguiseType {
PIG_ZOMBIE, PIG_ZOMBIE,
PILLAGER, @NmsAddedIn(val = NmsVersion.v1_14) PILLAGER,
PLAYER, PLAYER,
@ -144,7 +145,7 @@ public enum DisguiseType {
RABBIT, RABBIT,
RAVAGER, @NmsAddedIn(val = NmsVersion.v1_14) RAVAGER,
SALMON, SALMON,
@ -180,9 +181,11 @@ public enum DisguiseType {
THROWN_EXP_BOTTLE(75), THROWN_EXP_BOTTLE(75),
@NmsRemovedIn(val = NmsVersion.v1_14) TIPPED_ARROW(60),
TRIDENT(94, 0), TRIDENT(94, 0),
TRADER_LLAMA, @NmsAddedIn(val = NmsVersion.v1_14) TRADER_LLAMA,
TROPICAL_FISH, TROPICAL_FISH,
@ -198,7 +201,7 @@ public enum DisguiseType {
VINDICATOR, VINDICATOR,
WANDERING_TRADER, @NmsAddedIn(val = NmsVersion.v1_14) WANDERING_TRADER,
WITCH, WITCH,

View File

@ -13,6 +13,8 @@ import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
@ -195,10 +197,12 @@ public class FlagWatcher {
return newList; return newList;
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public EntityPose getEntityPose() { public EntityPose getEntityPose() {
return getData(MetaIndex.ENTITY_POSE); return getData(MetaIndex.ENTITY_POSE);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setEntityPose(EntityPose entityPose) { public void setEntityPose(EntityPose entityPose) {
setData(MetaIndex.ENTITY_POSE, entityPose); setData(MetaIndex.ENTITY_POSE, entityPose);
sendData(MetaIndex.ENTITY_POSE); sendData(MetaIndex.ENTITY_POSE);
@ -208,6 +212,10 @@ public class FlagWatcher {
return getEquipment().getArmorContents(); return getEquipment().getArmorContents();
} }
public void setArmor(ItemStack[] items) {
getEquipment().setArmorContents(items);
}
public String getCustomName() { public String getCustomName() {
Optional<WrappedChatComponent> optional = getData(MetaIndex.ENTITY_CUSTOM_NAME); Optional<WrappedChatComponent> optional = getData(MetaIndex.ENTITY_CUSTOM_NAME);
@ -220,10 +228,29 @@ public class FlagWatcher {
return null; return null;
} }
public void setCustomName(String name) {
if (Strings.isNullOrEmpty(name)) {
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty());
} else {
if (name.length() > 64) {
name = name.substring(0, 64);
}
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name)));
}
sendData(MetaIndex.ENTITY_CUSTOM_NAME);
}
protected TargetedDisguise getDisguise() { protected TargetedDisguise getDisguise() {
return disguise; return disguise;
} }
protected void setDisguise(TargetedDisguise disguise) {
this.disguise = disguise;
equipment.setFlagWatcher(this);
}
private boolean getEntityFlag(int byteValue) { private boolean getEntityFlag(int byteValue) {
return (getData(MetaIndex.ENTITY_META) & 1 << byteValue) != 0; return (getData(MetaIndex.ENTITY_META) & 1 << byteValue) != 0;
} }
@ -236,10 +263,18 @@ public class FlagWatcher {
return equipment.getItemInMainHand(); return equipment.getItemInMainHand();
} }
public void setItemInMainHand(ItemStack itemstack) {
setItemStack(EquipmentSlot.HAND, itemstack);
}
public ItemStack getItemInOffHand() { public ItemStack getItemInOffHand() {
return equipment.getItemInOffHand(); return equipment.getItemInOffHand();
} }
public void setItemInOffHand(ItemStack itemstack) {
setItemStack(EquipmentSlot.OFF_HAND, itemstack);
}
public ItemStack getItemStack(EquipmentSlot slot) { public ItemStack getItemStack(EquipmentSlot slot) {
return equipment.getItem(slot); return equipment.getItem(slot);
} }
@ -278,10 +313,21 @@ public class FlagWatcher {
return getEntityFlag(0); return getEntityFlag(0);
} }
public void setBurning(boolean setBurning) {
setEntityFlag(0, setBurning);
sendData(MetaIndex.ENTITY_META);
}
public boolean isCustomNameVisible() { public boolean isCustomNameVisible() {
return getData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE); return getData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE);
} }
public void setCustomNameVisible(boolean display) {
setData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE, display);
sendData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE);
}
@Deprecated @Deprecated
public boolean isEntityAnimationsAdded() { public boolean isEntityAnimationsAdded() {
return addEntityAnimations; return addEntityAnimations;
@ -291,30 +337,67 @@ public class FlagWatcher {
return getEntityFlag(7); return getEntityFlag(7);
} }
public void setFlyingWithElytra(boolean flying) {
setEntityFlag(7, flying);
sendData(MetaIndex.ENTITY_META);
}
public boolean isGlowing() { public boolean isGlowing() {
return getEntityFlag(6); return getEntityFlag(6);
} }
public void setGlowing(boolean glowing) {
setEntityFlag(6, glowing);
sendData(MetaIndex.ENTITY_META);
}
public boolean isInvisible() { public boolean isInvisible() {
return getEntityFlag(5); return getEntityFlag(5);
} }
public void setInvisible(boolean setInvis) {
setEntityFlag(5, setInvis);
sendData(MetaIndex.ENTITY_META);
}
public boolean isNoGravity() { public boolean isNoGravity() {
return getData(MetaIndex.ENTITY_NO_GRAVITY); return getData(MetaIndex.ENTITY_NO_GRAVITY);
} }
public void setNoGravity(boolean noGravity) {
setData(MetaIndex.ENTITY_NO_GRAVITY, noGravity);
sendData(MetaIndex.ENTITY_NO_GRAVITY);
}
public boolean isRightClicking() { public boolean isRightClicking() {
return getEntityFlag(4); return getEntityFlag(4);
} }
public void setRightClicking(boolean setRightClicking) {
setEntityFlag(4, setRightClicking);
sendData(MetaIndex.ENTITY_META);
}
public boolean isSneaking() { public boolean isSneaking() {
return getEntityFlag(1); return getEntityFlag(1);
} }
public void setSneaking(boolean setSneaking) {
setEntityFlag(1, setSneaking);
sendData(MetaIndex.ENTITY_META);
updatePose();
}
public boolean isSprinting() { public boolean isSprinting() {
return getEntityFlag(3); return getEntityFlag(3);
} }
public void setSprinting(boolean setSprinting) {
setEntityFlag(3, setSprinting);
sendData(MetaIndex.ENTITY_META);
}
public void rebuildWatchableObjects() { public void rebuildWatchableObjects() {
watchableObjects = new ArrayList<>(); watchableObjects = new ArrayList<>();
@ -355,8 +438,7 @@ public class FlagWatcher {
Object value = entityValues.get(data.getIndex()); Object value = entityValues.get(data.getIndex());
if (isEntityAnimationsAdded() && DisguiseConfig.isMetaPacketsEnabled() && if (isEntityAnimationsAdded() && DisguiseConfig.isMetaPacketsEnabled() && data == MetaIndex.ENTITY_META) {
data == MetaIndex.ENTITY_META) {
value = addEntityAnimations((byte) value, value = addEntityAnimations((byte) value,
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
} }
@ -403,10 +485,6 @@ public class FlagWatcher {
addEntityAnimations = isEntityAnimationsAdded; addEntityAnimations = isEntityAnimationsAdded;
} }
public void setArmor(ItemStack[] items) {
getEquipment().setArmorContents(items);
}
protected void setBackupValue(MetaIndex no, Object value) { protected void setBackupValue(MetaIndex no, Object value) {
if (no == null) if (no == null)
return; return;
@ -414,31 +492,6 @@ public class FlagWatcher {
backupEntityValues.put(no.getIndex(), value); backupEntityValues.put(no.getIndex(), value);
} }
public void setBurning(boolean setBurning) {
setEntityFlag(0, setBurning);
sendData(MetaIndex.ENTITY_META);
}
public void setCustomName(String name) {
if (Strings.isNullOrEmpty(name)) {
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty());
} else {
if (name.length() > 64) {
name = name.substring(0, 64);
}
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name)));
}
sendData(MetaIndex.ENTITY_CUSTOM_NAME);
}
public void setCustomNameVisible(boolean display) {
setData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE, display);
sendData(MetaIndex.ENTITY_CUSTOM_NAME_VISIBLE);
}
private void setEntityFlag(int byteValue, boolean flag) { private void setEntityFlag(int byteValue, boolean flag) {
modifiedEntityAnimations[byteValue] = true; modifiedEntityAnimations[byteValue] = true;
@ -451,21 +504,6 @@ public class FlagWatcher {
} }
} }
public void setFlyingWithElytra(boolean flying) {
setEntityFlag(7, flying);
sendData(MetaIndex.ENTITY_META);
}
public void setGlowing(boolean glowing) {
setEntityFlag(6, glowing);
sendData(MetaIndex.ENTITY_META);
}
public void setInvisible(boolean setInvis) {
setEntityFlag(5, setInvis);
sendData(MetaIndex.ENTITY_META);
}
/** /**
* Don't use this, use setItemInMainHand instead * Don't use this, use setItemInMainHand instead
* *
@ -476,14 +514,6 @@ public class FlagWatcher {
setItemInMainHand(itemstack); setItemInMainHand(itemstack);
} }
public void setItemInMainHand(ItemStack itemstack) {
setItemStack(EquipmentSlot.HAND, itemstack);
}
public void setItemInOffHand(ItemStack itemstack) {
setItemStack(EquipmentSlot.OFF_HAND, itemstack);
}
public void setItemStack(EquipmentSlot slot, ItemStack itemStack) { public void setItemStack(EquipmentSlot slot, ItemStack itemStack) {
equipment.setItem(slot, itemStack); equipment.setItem(slot, itemStack);
} }
@ -540,23 +570,6 @@ public class FlagWatcher {
} }
} }
public void setNoGravity(boolean noGravity) {
setData(MetaIndex.ENTITY_NO_GRAVITY, noGravity);
sendData(MetaIndex.ENTITY_NO_GRAVITY);
}
public void setRightClicking(boolean setRightClicking) {
setEntityFlag(4, setRightClicking);
sendData(MetaIndex.ENTITY_META);
}
public void setSneaking(boolean setSneaking) {
setEntityFlag(1, setSneaking);
sendData(MetaIndex.ENTITY_META);
updatePose();
}
public boolean isSleeping() { public boolean isSleeping() {
return sleeping; return sleeping;
} }
@ -597,15 +610,15 @@ public class FlagWatcher {
} }
} }
public void setSprinting(boolean setSprinting) {
setEntityFlag(3, setSprinting);
sendData(MetaIndex.ENTITY_META);
}
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;
if (id.getIndex() == -1) {
throw new IllegalArgumentException(
"You can't do that in this version of Minecraft! I can't use " + MetaIndex.getName(id) + "!");
}
if (value == null && id.getDefault() instanceof ItemStack) if (value == null && id.getDefault() instanceof ItemStack)
throw new IllegalArgumentException("Cannot use null ItemStacks"); throw new IllegalArgumentException("Cannot use null ItemStacks");
@ -615,9 +628,4 @@ public class FlagWatcher {
rebuildWatchableObjects(); rebuildWatchableObjects();
} }
} }
protected void setDisguise(TargetedDisguise disguise) {
this.disguise = disguise;
equipment.setFlagWatcher(this);
}
} }

View File

@ -7,15 +7,14 @@ import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.comphenix.protocol.wrappers.nbt.NbtType; import com.comphenix.protocol.wrappers.nbt.NbtType;
import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.NmsAdded; import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsRemoved; import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.entity.MushroomCow;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -105,6 +104,7 @@ public class MetaIndex<Y> {
*/ */
public static MetaIndex<Optional<UUID>> ARROW_UUID = new MetaIndex<>(ArrowWatcher.class, 1, Optional.empty()); public static MetaIndex<Optional<UUID>> ARROW_UUID = new MetaIndex<>(ArrowWatcher.class, 1, Optional.empty());
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> ARROW_PIERCE_LEVEL = new MetaIndex<>(ArrowWatcher.class, 2, (byte) 0); public static MetaIndex<Byte> ARROW_PIERCE_LEVEL = new MetaIndex<>(ArrowWatcher.class, 2, (byte) 0);
/** /**
@ -112,10 +112,10 @@ public class MetaIndex<Y> {
*/ */
public static MetaIndex<Byte> BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1); public static MetaIndex<Byte> BAT_HANGING = new MetaIndex<>(BatWatcher.class, 0, (byte) 1);
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public static MetaIndex<Byte> BEE_META = new MetaIndex<>(BeeWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> BEE_META = new MetaIndex<>(BeeWatcher.class, 0, (byte) 0);
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public static MetaIndex<Integer> BEE_ANGER = new MetaIndex<>(BeeWatcher.class, 1, 0); public static MetaIndex<Integer> BEE_ANGER = new MetaIndex<>(BeeWatcher.class, 1, 0);
/** /**
@ -143,12 +143,16 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0); public static MetaIndex<Integer> BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> CAT_TYPE = new MetaIndex<>(CatWatcher.class, 0, 0); public static MetaIndex<Integer> CAT_TYPE = new MetaIndex<>(CatWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> CAT_LYING_DOWN = new MetaIndex<>(CatWatcher.class, 1, false); public static MetaIndex<Boolean> CAT_LYING_DOWN = new MetaIndex<>(CatWatcher.class, 1, false);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> CAT_LOOKING_UP = new MetaIndex<>(CatWatcher.class, 2, false); public static MetaIndex<Boolean> CAT_LOOKING_UP = new MetaIndex<>(CatWatcher.class, 2, false);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> CAT_COLLAR = new MetaIndex<>(CatWatcher.class, 3, AnimalColor.RED.ordinal()); public static MetaIndex<Integer> CAT_COLLAR = new MetaIndex<>(CatWatcher.class, 3, AnimalColor.RED.ordinal());
/** /**
@ -197,6 +201,7 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> ENDER_DRAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 10); public static MetaIndex<Integer> ENDER_DRAGON_PHASE = new MetaIndex<>(EnderDragonWatcher.class, 0, 10);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<ItemStack> ENDER_SIGNAL_ITEM = new MetaIndex<>(EnderSignalWatcher.class, 0, public static MetaIndex<ItemStack> ENDER_SIGNAL_ITEM = new MetaIndex<>(EnderSignalWatcher.class, 0,
new ItemStack(Material.AIR)); new ItemStack(Material.AIR));
@ -205,7 +210,7 @@ public class MetaIndex<Y> {
*/ */
public static MetaIndex<Boolean> ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false); public static MetaIndex<Boolean> ENDERMAN_AGRESSIVE = new MetaIndex<>(EndermanWatcher.class, 1, false);
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public static MetaIndex<Boolean> ENDERMAN_UNKNOWN = new MetaIndex<>(EndermanWatcher.class, 2, false); public static MetaIndex<Boolean> ENDERMAN_UNKNOWN = new MetaIndex<>(EndermanWatcher.class, 2, false);
/** /**
@ -245,11 +250,14 @@ public class MetaIndex<Y> {
/** /**
* If entity can make sounds, no noticable effects * If entity can make sounds, no noticable effects
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<EntityPose> ENTITY_POSE = new MetaIndex<>(FlagWatcher.class, 6, EntityPose.STANDING); public static MetaIndex<EntityPose> ENTITY_POSE = new MetaIndex<>(FlagWatcher.class, 6, EntityPose.STANDING);
public static MetaIndex<BlockPosition> FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0, public static MetaIndex<BlockPosition> FALLING_BLOCK_POSITION = new MetaIndex<>(FallingBlockWatcher.class, 0,
BlockPosition.ORIGIN); BlockPosition.ORIGIN);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<ItemStack> FIREBALL_ITEM = new MetaIndex<>(FireballWatcher.class, 0, public static MetaIndex<ItemStack> FIREBALL_ITEM = new MetaIndex<>(FireballWatcher.class, 0,
new ItemStack(Material.AIR)); new ItemStack(Material.AIR));
@ -258,9 +266,14 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> FISH_FROM_BUCKET = new MetaIndex<>(FishWatcher.class, 0, false); public static MetaIndex<Boolean> FISH_FROM_BUCKET = new MetaIndex<>(FishWatcher.class, 0, false);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> FIREWORK_ATTACHED_ENTITY_OLD = new MetaIndex<>(FireworkWatcher.class, 1, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<OptionalInt> FIREWORK_ATTACHED_ENTITY = new MetaIndex<>(FireworkWatcher.class, 1, public static MetaIndex<OptionalInt> FIREWORK_ATTACHED_ENTITY = new MetaIndex<>(FireworkWatcher.class, 1,
OptionalInt.empty()); OptionalInt.empty());
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> FIREWORK_SHOT_AT_ANGLE = new MetaIndex<>(FireworkWatcher.class, 2, false); public static MetaIndex<Boolean> FIREWORK_SHOT_AT_ANGLE = new MetaIndex<>(FireworkWatcher.class, 2, false);
public static MetaIndex<Integer> FISHING_HOOK_HOOKED = new MetaIndex<>(FishingHookWatcher.class, 0, 0); public static MetaIndex<Integer> FISHING_HOOK_HOOKED = new MetaIndex<>(FishingHookWatcher.class, 0, 0);
@ -268,12 +281,16 @@ public class MetaIndex<Y> {
/** /**
* The type of fox, its coloring * The type of fox, its coloring
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> FOX_TYPE = new MetaIndex<>(FoxWatcher.class, 0, 0); public static MetaIndex<Integer> FOX_TYPE = new MetaIndex<>(FoxWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> FOX_META = new MetaIndex<>(FoxWatcher.class, 1, (byte) 0); public static MetaIndex<Byte> FOX_META = new MetaIndex<>(FoxWatcher.class, 1, (byte) 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Optional<UUID>> FOX_TRUSTED_1 = new MetaIndex<>(FoxWatcher.class, 2, Optional.empty()); public static MetaIndex<Optional<UUID>> FOX_TRUSTED_1 = new MetaIndex<>(FoxWatcher.class, 2, Optional.empty());
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Optional<UUID>> FOX_TRUSTED_2 = new MetaIndex<>(FoxWatcher.class, 3, Optional.empty()); public static MetaIndex<Optional<UUID>> FOX_TRUSTED_2 = new MetaIndex<>(FoxWatcher.class, 3, Optional.empty());
/** /**
@ -297,6 +314,8 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> HORSE_CHESTED_CARRYING_CHEST = new MetaIndex<>(ChestedHorseWatcher.class, 0, public static MetaIndex<Boolean> HORSE_CHESTED_CARRYING_CHEST = new MetaIndex<>(ChestedHorseWatcher.class, 0,
false); false);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> HORSE_ARMOR = new MetaIndex<>(HorseWatcher.class, 1, 0);
/** /**
* Color of the horse, uses enum not RGB * Color of the horse, uses enum not RGB
*/ */
@ -313,8 +332,15 @@ public class MetaIndex<Y> {
public static MetaIndex<Optional<UUID>> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1, public static MetaIndex<Optional<UUID>> HORSE_OWNER = new MetaIndex<>(AbstractHorseWatcher.class, 1,
Optional.empty()); Optional.empty());
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> ILLAGER_SPELL = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> ILLAGER_SPELL = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> ILLAGER_META = new MetaIndex<>(IllagerWatcher.class, 0, (byte) 0);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> ILLAGER_SPELL_TICKS = new MetaIndex<>(IllagerWizardWatcher.class, 0, (byte) 0);
public static MetaIndex<Byte> INSENTIENT_META = new MetaIndex<>(InsentientWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> INSENTIENT_META = new MetaIndex<>(InsentientWatcher.class, 0, (byte) 0);
public static MetaIndex<Byte> IRON_GOLEM_PLAYER_CREATED = new MetaIndex<>(IronGolemWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> IRON_GOLEM_PLAYER_CREATED = new MetaIndex<>(IronGolemWatcher.class, 0, (byte) 0);
@ -358,9 +384,10 @@ public class MetaIndex<Y> {
/** /**
* How many bee stings does the entity have * How many bee stings does the entity have
*/ */
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public static MetaIndex<Integer> LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0); public static MetaIndex<Integer> LIVING_STINGS = new MetaIndex<>(LivingWatcher.class, 5, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Optional<BlockPosition>> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6, public static MetaIndex<Optional<BlockPosition>> LIVING_BED_POSITION = new MetaIndex<>(LivingWatcher.class, 6,
Optional.empty()); Optional.empty());
@ -410,21 +437,31 @@ public class MetaIndex<Y> {
*/ */
public static MetaIndex<Boolean> MINECART_FURANCE_FUELED = new MetaIndex<>(MinecartFurnaceWatcher.class, 0, false); public static MetaIndex<Boolean> MINECART_FURANCE_FUELED = new MetaIndex<>(MinecartFurnaceWatcher.class, 0, false);
public static MetaIndex<String> MUSHROOM_COW_TYPE = new MetaIndex<>(MushroomCowWatcher.class, 0, @NmsAddedIn(val = NmsVersion.v1_14)
MushroomCow.Variant.RED.name().toLowerCase()); public static MetaIndex<String> MUSHROOM_COW_TYPE = new MetaIndex<>(MushroomCowWatcher.class, 0, "RED");
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> OCELOT_TRUST = new MetaIndex<>(OcelotWatcher.class, 0, false); public static MetaIndex<Boolean> OCELOT_TRUST = new MetaIndex<>(OcelotWatcher.class, 0, false);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> PANDA_HEAD_SHAKING = new MetaIndex<>(PandaWatcher.class, 0, 0); public static MetaIndex<Integer> PANDA_HEAD_SHAKING = new MetaIndex<>(PandaWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> PANDA_UNKNOWN_1 = new MetaIndex<>(PandaWatcher.class, 1, 0); public static MetaIndex<Integer> PANDA_UNKNOWN_1 = new MetaIndex<>(PandaWatcher.class, 1, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> PANDA_UNKNOWN_2 = new MetaIndex<>(PandaWatcher.class, 2, 0); public static MetaIndex<Integer> PANDA_UNKNOWN_2 = new MetaIndex<>(PandaWatcher.class, 2, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> PANDA_MAIN_GENE = new MetaIndex<>(PandaWatcher.class, 3, (byte) 0); public static MetaIndex<Byte> PANDA_MAIN_GENE = new MetaIndex<>(PandaWatcher.class, 3, (byte) 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> PANDA_HIDDEN_GENE = new MetaIndex<>(PandaWatcher.class, 4, (byte) 0); public static MetaIndex<Byte> PANDA_HIDDEN_GENE = new MetaIndex<>(PandaWatcher.class, 4, (byte) 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Byte> PANDA_META = new MetaIndex<>(PandaWatcher.class, 5, (byte) 0); public static MetaIndex<Byte> PANDA_META = new MetaIndex<>(PandaWatcher.class, 5, (byte) 0);
public static MetaIndex<Integer> PARROT_VARIANT = new MetaIndex<>(ParrotWatcher.class, 0, 0); public static MetaIndex<Integer> PARROT_VARIANT = new MetaIndex<>(ParrotWatcher.class, 0, 0);
@ -438,6 +475,7 @@ public class MetaIndex<Y> {
*/ */
public static MetaIndex<Integer> PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0); public static MetaIndex<Integer> PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> PILLAGER_AIMING_BOW = new MetaIndex<>(PillagerWatcher.class, 0, false); public static MetaIndex<Boolean> PILLAGER_AIMING_BOW = new MetaIndex<>(PillagerWatcher.class, 0, false);
public static MetaIndex<Float> PLAYER_ABSORPTION = new MetaIndex<>(PlayerWatcher.class, 0, 0F); public static MetaIndex<Float> PLAYER_ABSORPTION = new MetaIndex<>(PlayerWatcher.class, 0, 0F);
@ -460,6 +498,7 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0); public static MetaIndex<Integer> RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> RAIDER_CASTING_SPELL = new MetaIndex<>(RaiderWatcher.class, 0, false); public static MetaIndex<Boolean> RAIDER_CASTING_SPELL = new MetaIndex<>(RaiderWatcher.class, 0, false);
public static MetaIndex<Byte> SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0);
@ -473,6 +512,9 @@ public class MetaIndex<Y> {
public static MetaIndex<Byte> SHULKER_PEEKING = new MetaIndex<>(ShulkerWatcher.class, 2, (byte) 0); public static MetaIndex<Byte> SHULKER_PEEKING = new MetaIndex<>(ShulkerWatcher.class, 2, (byte) 0);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> SKELETON_SWING_ARMS = new MetaIndex<>(SkeletonWatcher.class, 0, false);
public static MetaIndex<Integer> SLIME_SIZE = new MetaIndex<>(SlimeWatcher.class, 0, 1); public static MetaIndex<Integer> SLIME_SIZE = new MetaIndex<>(SlimeWatcher.class, 0, 1);
public static MetaIndex<Byte> SNOWMAN_DERP = new MetaIndex<>(SnowmanWatcher.class, 0, (byte) 16); public static MetaIndex<Byte> SNOWMAN_DERP = new MetaIndex<>(SnowmanWatcher.class, 0, (byte) 16);
@ -487,6 +529,7 @@ public class MetaIndex<Y> {
public static MetaIndex<Optional<UUID>> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1, public static MetaIndex<Optional<UUID>> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1,
Optional.empty()); Optional.empty());
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<ItemStack> THROWABLE_ITEM = new MetaIndex<>(ThrowableWatcher.class, 0, public static MetaIndex<ItemStack> THROWABLE_ITEM = new MetaIndex<>(ThrowableWatcher.class, 0,
new ItemStack(Material.AIR)); new ItemStack(Material.AIR));
@ -496,7 +539,7 @@ public class MetaIndex<Y> {
public static MetaIndex<Byte> TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0);
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public static MetaIndex<Boolean> TRIDENT_ENCHANTED = new MetaIndex<>(TridentWatcher.class, 1, false); public static MetaIndex<Boolean> TRIDENT_ENCHANTED = new MetaIndex<>(TridentWatcher.class, 1, false);
public static MetaIndex<Integer> TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0); public static MetaIndex<Integer> TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0);
@ -517,10 +560,16 @@ public class MetaIndex<Y> {
public static MetaIndex<Byte> VEX_ANGRY = new MetaIndex<>(VexWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> VEX_ANGRY = new MetaIndex<>(VexWatcher.class, 0, (byte) 0);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> VILLAGER_PROFESSION = new MetaIndex<>(VillagerWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> ABSTRACT_VILLAGER_ANGRY = new MetaIndex<>(AbstractVillagerWatcher.class, 0, 0); public static MetaIndex<Integer> ABSTRACT_VILLAGER_ANGRY = new MetaIndex<>(AbstractVillagerWatcher.class, 0, 0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<VillagerData> VILLAGER_DATA = new MetaIndex<>(VillagerWatcher.class, 0, public static MetaIndex<VillagerData> VILLAGER_DATA = new MetaIndex<>(VillagerWatcher.class, 0,
new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1)); NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) :
null);
public static MetaIndex<Boolean> WITCH_AGGRESSIVE = new MetaIndex<>(WitchWatcher.class, 0, false); public static MetaIndex<Boolean> WITCH_AGGRESSIVE = new MetaIndex<>(WitchWatcher.class, 0, false);
@ -536,19 +585,28 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 1, false); public static MetaIndex<Boolean> WOLF_BEGGING = new MetaIndex<>(WolfWatcher.class, 1, false);
@NmsRemoved(removed = NmsVersion.v1_15) @NmsRemovedIn(val = NmsVersion.v1_15)
public static MetaIndex<Float> WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 1F); public static MetaIndex<Float> WOLF_DAMAGE = new MetaIndex<>(WolfWatcher.class, 0, 1F);
public static MetaIndex<Integer> WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 2, 14); public static MetaIndex<Integer> WOLF_COLLAR = new MetaIndex<>(WolfWatcher.class, 2, 14);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Boolean> ZOMBIE_AGGRESSIVE = new MetaIndex<>(ZombieWatcher.class, 2, false);
public static MetaIndex<Boolean> ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false); public static MetaIndex<Boolean> ZOMBIE_BABY = new MetaIndex<>(ZombieWatcher.class, 0, false);
public static MetaIndex<Boolean> ZOMBIE_CONVERTING_DROWNED = new MetaIndex<>(ZombieWatcher.class, 2, false); public static MetaIndex<Boolean> ZOMBIE_CONVERTING_DROWNED = new MetaIndex<>(ZombieWatcher.class, 2, false);
public static MetaIndex<Integer> ZOMBIE_PLACEHOLDER = new MetaIndex<>(ZombieWatcher.class, 1, 0); public static MetaIndex<Integer> ZOMBIE_PLACEHOLDER = new MetaIndex<>(ZombieWatcher.class, 1, 0);
@NmsRemovedIn(val = NmsVersion.v1_14)
public static MetaIndex<Integer> ZOMBIE_VILLAGER_PROFESSION_OLD = new MetaIndex<>(ZombieVillagerWatcher.class, 1,
0);
@NmsAddedIn(val = NmsVersion.v1_14)
public static MetaIndex<VillagerData> ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1, public static MetaIndex<VillagerData> ZOMBIE_VILLAGER_PROFESSION = new MetaIndex<>(ZombieVillagerWatcher.class, 1,
new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1)); NmsVersion.v1_14.isSupported() ? new VillagerData(Villager.Type.PLAINS, Villager.Profession.NONE, 1) :
null);
/** /**
* Shown for villager conversion * Shown for villager conversion
@ -561,35 +619,20 @@ public class MetaIndex<Y> {
orderMetaIndexes(); orderMetaIndexes();
} }
@Deprecated
private static void eliminateBlankIndexes() { private static void eliminateBlankIndexes() {
ArrayList<Entry<Class, ArrayList<MetaIndex>>> list = new ArrayList<>(); HashMap<Class, ArrayList<MetaIndex>> metas = new HashMap<>();
for (MetaIndex index : values()) { for (MetaIndex index : values()) {
Entry<Class, ArrayList<MetaIndex>> entry = null; metas.computeIfAbsent(index.getFlagWatcher(), (a) -> new ArrayList<>()).add(index);
for (Entry e : list) {
if (e.getKey() != index.getFlagWatcher())
continue;
entry = e;
break;
}
if (entry == null) {
entry = new AbstractMap.SimpleEntry(index.getFlagWatcher(), new ArrayList<MetaIndex>());
list.add(entry);
}
entry.getValue().add(index);
} }
for (Entry<Class, ArrayList<MetaIndex>> entry : list) { for (ArrayList<MetaIndex> list : metas.values()) {
entry.getValue().sort(Comparator.comparingInt(MetaIndex::getIndex)); list.sort(Comparator.comparingInt(MetaIndex::getIndex));
for (MetaIndex ind : entry.getValue()) { int i = 0;
ind._index = entry.getValue().indexOf(ind);
for (MetaIndex ind : list) {
ind._index = i++;
} }
} }
} }
@ -599,7 +642,7 @@ public class MetaIndex<Y> {
if (flagType.getFlagWatcher() == FlagWatcher.class) if (flagType.getFlagWatcher() == FlagWatcher.class)
continue; continue;
flagType._index += getNoIndexes(flagType.getFlagWatcher().getSuperclass()); flagType._index += getNoIndexes(ReflectionManager.getSuperClass(flagType.getFlagWatcher()));
} }
} }
@ -628,7 +671,7 @@ public class MetaIndex<Y> {
if (type.getIndex() != i) if (type.getIndex() != i)
continue; continue;
if (!type.getFlagWatcher().isAssignableFrom(entry.getKey())) if (!ReflectionManager.isAssignableFrom(entry.getKey(), type.getFlagWatcher()))
continue; continue;
if (found != null) { if (found != null) {
@ -702,7 +745,7 @@ public class MetaIndex<Y> {
if (type.getIndex() != flagNo) if (type.getIndex() != flagNo)
continue; continue;
if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) if (!ReflectionManager.isAssignableFrom(watcherClass, type.getFlagWatcher()))
continue; continue;
return type; return type;
@ -719,7 +762,7 @@ public class MetaIndex<Y> {
ArrayList<MetaIndex> list = new ArrayList<>(); ArrayList<MetaIndex> list = new ArrayList<>();
for (MetaIndex type : values()) { for (MetaIndex type : values()) {
if (type == null || !type.getFlagWatcher().isAssignableFrom(watcherClass)) if (type == null || !ReflectionManager.isAssignableFrom(watcherClass, type.getFlagWatcher()))
continue; continue;
list.add(type); list.add(type);
@ -741,7 +784,7 @@ public class MetaIndex<Y> {
} }
if (c != FlagWatcher.class) { if (c != FlagWatcher.class) {
found += getNoIndexes(c.getSuperclass()); found += getNoIndexes(ReflectionManager.getSuperClass(c));
} }
return found; return found;
@ -839,12 +882,13 @@ public class MetaIndex<Y> {
if (field.getType() != MetaIndex.class) if (field.getType() != MetaIndex.class)
continue; continue;
MetaIndex index = (MetaIndex) field.get(null);
if (!ReflectionManager.isSupported(field)) { if (!ReflectionManager.isSupported(field)) {
index._index = -1;
continue; continue;
} }
MetaIndex index = (MetaIndex) field.get(null);
if (index == null) if (index == null)
continue; continue;

View File

@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
* Created by libraryaddict on 18/05/2019. * Created by libraryaddict on 18/05/2019.
@ -11,16 +13,19 @@ public class AbstractVillagerWatcher extends AgeableWatcher {
super(disguise); super(disguise);
} }
public void setAngry(int ticks) { @NmsAddedIn(val = NmsVersion.v1_14)
setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks);
sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
}
public int getAngry() { public int getAngry() {
return getData(MetaIndex.ABSTRACT_VILLAGER_ANGRY); return getData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public boolean isAngry() { public boolean isAngry() {
return getAngry() > 0; return getAngry() > 0;
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setAngry(int ticks) {
setData(MetaIndex.ABSTRACT_VILLAGER_ANGRY, ticks);
sendData(MetaIndex.ABSTRACT_VILLAGER_ANGRY);
}
} }

View File

@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
public class ArrowWatcher extends FlagWatcher { public class ArrowWatcher extends FlagWatcher {
public ArrowWatcher(Disguise disguise) { public ArrowWatcher(Disguise disguise) {
@ -18,12 +20,14 @@ public class ArrowWatcher extends FlagWatcher {
sendData(MetaIndex.ARROW_CRITICAL); sendData(MetaIndex.ARROW_CRITICAL);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public int getPierceLevel() {
return getData(MetaIndex.ARROW_PIERCE_LEVEL);
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setPierceLevel(int pierceLevel) { public void setPierceLevel(int pierceLevel) {
setData(MetaIndex.ARROW_PIERCE_LEVEL, (byte) pierceLevel); setData(MetaIndex.ARROW_PIERCE_LEVEL, (byte) pierceLevel);
sendData(MetaIndex.ARROW_PIERCE_LEVEL); sendData(MetaIndex.ARROW_PIERCE_LEVEL);
} }
public int getPierceLevel() {
return getData(MetaIndex.ARROW_PIERCE_LEVEL);
}
} }

View File

@ -2,10 +2,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
* Created by libraryaddict on 14/12/2019. * Created by libraryaddict on 14/12/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_15)
public class BeeWatcher extends AgeableWatcher { public class BeeWatcher extends AgeableWatcher {
public BeeWatcher(Disguise disguise) { public BeeWatcher(Disguise disguise) {
super(disguise); super(disguise);

View File

@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.entity.Cat; import org.bukkit.entity.Cat;
@ -12,6 +14,7 @@ import java.util.Random;
/** /**
* Created by libraryaddict on 6/05/2019. * Created by libraryaddict on 6/05/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public class CatWatcher extends TameableWatcher { public class CatWatcher extends TameableWatcher {
public CatWatcher(Disguise disguise) { public CatWatcher(Disguise disguise) {
super(disguise); super(disguise);
@ -29,6 +32,10 @@ public class CatWatcher extends TameableWatcher {
sendData(MetaIndex.CAT_TYPE); sendData(MetaIndex.CAT_TYPE);
} }
public DyeColor getCollarColor() {
return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor();
}
@Deprecated @Deprecated
public void setCollarColor(AnimalColor color) { public void setCollarColor(AnimalColor color) {
setCollarColor(color.getDyeColor()); setCollarColor(color.getDyeColor());
@ -47,8 +54,8 @@ public class CatWatcher extends TameableWatcher {
sendData(MetaIndex.CAT_COLLAR); sendData(MetaIndex.CAT_COLLAR);
} }
public DyeColor getCollarColor() { public boolean isLyingDown() {
return AnimalColor.getColorByWool(getData(MetaIndex.CAT_COLLAR)).getDyeColor(); return getData(MetaIndex.CAT_LYING_DOWN);
} }
public void setLyingDown(boolean value) { public void setLyingDown(boolean value) {
@ -56,16 +63,12 @@ public class CatWatcher extends TameableWatcher {
sendData(MetaIndex.CAT_LYING_DOWN); sendData(MetaIndex.CAT_LYING_DOWN);
} }
public boolean isLyingDown() { public boolean isLookingUp() {
return getData(MetaIndex.CAT_LYING_DOWN); return getData(MetaIndex.CAT_LOOKING_UP);
} }
public void setLookingUp(boolean value) { public void setLookingUp(boolean value) {
setData(MetaIndex.CAT_LOOKING_UP, value); setData(MetaIndex.CAT_LOOKING_UP, value);
sendData(MetaIndex.CAT_LOOKING_UP); sendData(MetaIndex.CAT_LOOKING_UP);
} }
public boolean isLookingUp() {
return getData(MetaIndex.CAT_LOOKING_UP);
}
} }

View File

@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -13,15 +15,19 @@ public class EnderSignalWatcher extends FlagWatcher {
public EnderSignalWatcher(Disguise disguise) { public EnderSignalWatcher(Disguise disguise) {
super(disguise); super(disguise);
setItemStack(new ItemStack(Material.ENDER_EYE)); if (NmsVersion.v1_14.isSupported()) {
setItemStack(new ItemStack(Material.ENDER_EYE));
}
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public ItemStack getItemStack() {
return getData(MetaIndex.ENDER_SIGNAL_ITEM);
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setItemStack(ItemStack item) { public void setItemStack(ItemStack item) {
setData(MetaIndex.ENDER_SIGNAL_ITEM, item); setData(MetaIndex.ENDER_SIGNAL_ITEM, item);
sendData(MetaIndex.ENDER_SIGNAL_ITEM); sendData(MetaIndex.ENDER_SIGNAL_ITEM);
} }
public ItemStack getItemStack() {
return getData(MetaIndex.ENDER_SIGNAL_ITEM);
}
} }

View File

@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -13,13 +15,17 @@ public class FireballWatcher extends FlagWatcher {
public FireballWatcher(Disguise disguise) { public FireballWatcher(Disguise disguise) {
super(disguise); super(disguise);
setData(MetaIndex.FIREBALL_ITEM, new ItemStack(Material.FIRE_CHARGE)); if (NmsVersion.v1_14.isSupported()) {
setData(MetaIndex.FIREBALL_ITEM, new ItemStack(Material.FIRE_CHARGE));
}
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public ItemStack getItemStack() { public ItemStack getItemStack() {
return getData(MetaIndex.FIREBALL_ITEM); return getData(MetaIndex.FIREBALL_ITEM);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setItemStack(ItemStack item) { public void setItemStack(ItemStack item) {
setData(MetaIndex.FIREBALL_ITEM, item); setData(MetaIndex.FIREBALL_ITEM, item);
sendData(MetaIndex.FIREBALL_ITEM); sendData(MetaIndex.FIREBALL_ITEM);

View File

@ -1,12 +1,13 @@
package me.libraryaddict.disguise.disguisetypes.watchers; 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.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import java.util.OptionalInt; import java.util.OptionalInt;
public class FireworkWatcher extends FlagWatcher { public class FireworkWatcher extends FlagWatcher {
@ -22,15 +23,6 @@ public class FireworkWatcher extends FlagWatcher {
return getData(MetaIndex.FIREWORK_ITEM); return getData(MetaIndex.FIREWORK_ITEM);
} }
public boolean isShotAtAngle() {
return getData(MetaIndex.FIREWORK_SHOT_AT_ANGLE);
}
public void setShotAtAngle(boolean shotAtAngle) {
setData(MetaIndex.FIREWORK_SHOT_AT_ANGLE, shotAtAngle);
sendData(MetaIndex.FIREWORK_SHOT_AT_ANGLE);
}
public void setFirework(ItemStack newItem) { public void setFirework(ItemStack newItem) {
if (newItem == null) { if (newItem == null) {
newItem = new ItemStack(Material.AIR); newItem = new ItemStack(Material.AIR);
@ -43,12 +35,38 @@ public class FireworkWatcher extends FlagWatcher {
sendData(MetaIndex.FIREWORK_ITEM); sendData(MetaIndex.FIREWORK_ITEM);
} }
public void setAttachedEntity(OptionalInt entityId) { @NmsAddedIn(val = NmsVersion.v1_14)
setData(MetaIndex.FIREWORK_ATTACHED_ENTITY, entityId); public boolean isShotAtAngle() {
sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY); return getData(MetaIndex.FIREWORK_SHOT_AT_ANGLE);
} }
public OptionalInt getAttachedEntity() { @NmsAddedIn(val = NmsVersion.v1_14)
public void setShotAtAngle(boolean shotAtAngle) {
setData(MetaIndex.FIREWORK_SHOT_AT_ANGLE, shotAtAngle);
sendData(MetaIndex.FIREWORK_SHOT_AT_ANGLE);
}
@NmsAddedIn(val = NmsVersion.v1_14)
public OptionalInt getAttachedEntityOpt() {
return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY); return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY);
} }
public int getAttachedEntity() {
return getData(MetaIndex.FIREWORK_ATTACHED_ENTITY).orElse(0);
}
public void setAttachedEntity(int entityId) {
setAttachedEntity(entityId == 0 ? OptionalInt.empty() : OptionalInt.of(entityId));
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setAttachedEntity(OptionalInt entityId) {
if (NmsVersion.v1_14.isSupported()) {
setData(MetaIndex.FIREWORK_ATTACHED_ENTITY, entityId);
sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY);
} else {
setData(MetaIndex.FIREWORK_ATTACHED_ENTITY_OLD, entityId.orElse(0));
sendData(MetaIndex.FIREWORK_ATTACHED_ENTITY_OLD);
}
}
} }

View File

@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Fox; import org.bukkit.entity.Fox;
import java.util.Random; import java.util.Random;
@ -10,6 +12,7 @@ import java.util.Random;
/** /**
* Created by libraryaddict on 6/05/2019. * Created by libraryaddict on 6/05/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public class FoxWatcher extends AgeableWatcher { public class FoxWatcher extends AgeableWatcher {
public FoxWatcher(Disguise disguise) { public FoxWatcher(Disguise disguise) {
super(disguise); super(disguise);
@ -21,6 +24,10 @@ public class FoxWatcher extends AgeableWatcher {
return getFoxFlag(1); return getFoxFlag(1);
} }
public void setSitting(boolean value) {
setFoxFlag(1, value);
}
public boolean isCrouching() { public boolean isCrouching() {
return getFoxFlag(4); return getFoxFlag(4);
} }
@ -29,10 +36,6 @@ public class FoxWatcher extends AgeableWatcher {
setFoxFlag(4, value); setFoxFlag(4, value);
} }
public void setSitting(boolean value) {
setFoxFlag(1, value);
}
public boolean isSleeping() { public boolean isSleeping() {
return getFoxFlag(32); return getFoxFlag(32);
} }
@ -51,38 +54,38 @@ public class FoxWatcher extends AgeableWatcher {
sendData(MetaIndex.FOX_TYPE); sendData(MetaIndex.FOX_TYPE);
} }
public void setHeadTilted(boolean value) {
setFoxFlag(8, value);
}
public boolean isHeadTilted() { public boolean isHeadTilted() {
return getFoxFlag(8); return getFoxFlag(8);
} }
public void setSpringing(boolean value) { public void setHeadTilted(boolean value) {
setFoxFlag(16, value); setFoxFlag(8, value);
} }
public boolean isSpringing() { public boolean isSpringing() {
return getFoxFlag(16); return getFoxFlag(16);
} }
public void setTipToeing(boolean value) { public void setSpringing(boolean value) {
setFoxFlag(64, value); setFoxFlag(16, value);
} }
public boolean isTipToeing() { public boolean isTipToeing() {
return getFoxFlag(64); return getFoxFlag(64);
} }
public void setAngry(boolean value) { public void setTipToeing(boolean value) {
setFoxFlag(128, value); setFoxFlag(64, value);
} }
public boolean isAngry() { public boolean isAngry() {
return getFoxFlag(128); return getFoxFlag(128);
} }
public void setAngry(boolean value) {
setFoxFlag(128, value);
}
private boolean getFoxFlag(int value) { private boolean getFoxFlag(int value) {
return (getData(MetaIndex.FOX_META) & value) != 0; return (getData(MetaIndex.FOX_META) & value) != 0;
} }

View File

@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.Material;
import org.bukkit.entity.Horse.Color; import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style; import org.bukkit.entity.Horse.Style;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -20,27 +22,46 @@ public class HorseWatcher extends AbstractHorseWatcher {
return Color.values()[(getData(MetaIndex.HORSE_COLOR) & 0xFF)]; return Color.values()[(getData(MetaIndex.HORSE_COLOR) & 0xFF)];
} }
public Style getStyle() {
return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)];
}
@RandomDefaultValue @RandomDefaultValue
public void setColor(Color color) { public void setColor(Color color) {
setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); setData(MetaIndex.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
sendData(MetaIndex.HORSE_COLOR); sendData(MetaIndex.HORSE_COLOR);
} }
public Style getStyle() {
return Style.values()[(getData(MetaIndex.HORSE_COLOR) >>> 8)];
}
@RandomDefaultValue @RandomDefaultValue
public void setStyle(Style style) { public void setStyle(Style style) {
setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8); setData(MetaIndex.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(MetaIndex.HORSE_COLOR); sendData(MetaIndex.HORSE_COLOR);
} }
public void setHorseArmor(ItemStack item) {
getEquipment().setChestplate(item);
}
public ItemStack getHorseArmor() { public ItemStack getHorseArmor() {
return getEquipment().getChestplate(); return getEquipment().getChestplate();
} }
public void setHorseArmor(ItemStack item) {
getEquipment().setChestplate(item);
if (!NmsVersion.v1_14.isSupported()) {
int value = 0;
if (item != null) {
Material mat = item.getType();
if (mat == Material.IRON_HORSE_ARMOR) {
value = 1;
} else if (mat == Material.GOLDEN_HORSE_ARMOR) {
value = 2;
} else if (mat == Material.DIAMOND_HORSE_ARMOR) {
value = 3;
}
}
setData(MetaIndex.HORSE_ARMOR, value);
sendData(MetaIndex.HORSE_ARMOR);
}
}
} }

View File

@ -2,6 +2,9 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Spellcaster; import org.bukkit.entity.Spellcaster;
public class IllagerWizardWatcher extends IllagerWatcher { public class IllagerWizardWatcher extends IllagerWatcher {
@ -9,12 +12,27 @@ public class IllagerWizardWatcher extends IllagerWatcher {
super(disguise); super(disguise);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public Spellcaster.Spell getSpell() {
return Spellcaster.Spell.values()[getData(MetaIndex.ILLAGER_SPELL)];
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setSpell(Spellcaster.Spell spell) { public void setSpell(Spellcaster.Spell spell) {
setData(MetaIndex.ILLAGER_SPELL, (byte) spell.ordinal()); setData(MetaIndex.ILLAGER_SPELL, (byte) spell.ordinal());
sendData(MetaIndex.ILLAGER_SPELL); sendData(MetaIndex.ILLAGER_SPELL);
} }
public Spellcaster.Spell getSpell() { @Deprecated
return Spellcaster.Spell.values()[getData(MetaIndex.ILLAGER_SPELL)]; @NmsRemovedIn(val = NmsVersion.v1_14)
public int getSpellTicks() {
return getData(MetaIndex.ILLAGER_SPELL_TICKS);
}
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public void setSpellTicks(int spellTicks) {
setData(MetaIndex.ILLAGER_SPELL_TICKS, (byte) spellTicks);
sendData(MetaIndex.ILLAGER_SPELL_TICKS);
} }
} }

View File

@ -11,6 +11,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -38,6 +40,12 @@ public class LivingWatcher extends FlagWatcher {
return clone; return clone;
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public BlockPosition getBedPosition() {
return getData(MetaIndex.LIVING_BED_POSITION).orElse(null);
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setBedPosition(BlockPosition blockPosition) { public void setBedPosition(BlockPosition blockPosition) {
Optional<BlockPosition> optional; Optional<BlockPosition> optional;
@ -51,22 +59,61 @@ public class LivingWatcher extends FlagWatcher {
sendData(MetaIndex.LIVING_BED_POSITION); sendData(MetaIndex.LIVING_BED_POSITION);
} }
public BlockPosition getBedPosition() {
return getData(MetaIndex.LIVING_BED_POSITION).orElse(null);
}
public float getHealth() { public float getHealth() {
return getData(MetaIndex.LIVING_HEALTH); return getData(MetaIndex.LIVING_HEALTH);
} }
public void setHealth(float health) {
setData(MetaIndex.LIVING_HEALTH, health);
sendData(MetaIndex.LIVING_HEALTH);
}
public double getMaxHealth() { public double getMaxHealth() {
return maxHealth; return maxHealth;
} }
public void setMaxHealth(double newHealth) {
this.maxHealth = newHealth;
this.maxHealthSet = true;
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES);
List<WrappedAttribute> attributes = new ArrayList<>();
Builder builder;
builder = WrappedAttribute.newBuilder();
builder.attributeKey("generic.maxHealth");
builder.baseValue(getMaxHealth());
builder.packet(packet);
attributes.add(builder.build());
Entity entity = getDisguise().getEntity();
packet.getIntegers().write(0, entity.getEntityId());
packet.getAttributeCollectionModifier().write(0, attributes);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
public boolean isPotionParticlesAmbient() { public boolean isPotionParticlesAmbient() {
return getData(MetaIndex.LIVING_POTION_AMBIENT); return getData(MetaIndex.LIVING_POTION_AMBIENT);
} }
public void setPotionParticlesAmbient(boolean particles) {
setData(MetaIndex.LIVING_POTION_AMBIENT, particles);
sendData(MetaIndex.LIVING_POTION_AMBIENT);
}
public Color getParticlesColor() { public Color getParticlesColor() {
int color = getData(MetaIndex.LIVING_POTIONS); int color = getData(MetaIndex.LIVING_POTIONS);
return Color.fromRGB(color); return Color.fromRGB(color);
@ -151,21 +198,11 @@ public class LivingWatcher extends FlagWatcher {
sendPotionEffects(); sendPotionEffects();
} }
public void setPotionParticlesAmbient(boolean particles) {
setData(MetaIndex.LIVING_POTION_AMBIENT, particles);
sendData(MetaIndex.LIVING_POTION_AMBIENT);
}
private void sendPotionEffects() { private void sendPotionEffects() {
setData(MetaIndex.LIVING_POTIONS, getPotions()); setData(MetaIndex.LIVING_POTIONS, getPotions());
sendData(MetaIndex.LIVING_POTIONS); sendData(MetaIndex.LIVING_POTIONS);
} }
public void setHealth(float health) {
setData(MetaIndex.LIVING_HEALTH, health);
sendData(MetaIndex.LIVING_HEALTH);
}
public int getArrowsSticking() { public int getArrowsSticking() {
return getData(MetaIndex.LIVING_ARROWS); return getData(MetaIndex.LIVING_ARROWS);
} }
@ -174,37 +211,4 @@ public class LivingWatcher extends FlagWatcher {
setData(MetaIndex.LIVING_ARROWS, Math.max(0, Math.min(127, arrowsNo))); setData(MetaIndex.LIVING_ARROWS, Math.max(0, Math.min(127, arrowsNo)));
sendData(MetaIndex.LIVING_ARROWS); sendData(MetaIndex.LIVING_ARROWS);
} }
public void setMaxHealth(double newHealth) {
this.maxHealth = newHealth;
this.maxHealthSet = true;
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES);
List<WrappedAttribute> attributes = new ArrayList<>();
Builder builder;
builder = WrappedAttribute.newBuilder();
builder.attributeKey("generic.maxHealth");
builder.baseValue(getMaxHealth());
builder.packet(packet);
attributes.add(builder.build());
Entity entity = getDisguise().getEntity();
packet.getIntegers().write(0, entity.getEntityId());
packet.getAttributeCollectionModifier().write(0, attributes);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
} }

View File

@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.MushroomCow; import org.bukkit.entity.MushroomCow;
/** /**
@ -12,10 +14,12 @@ public class MushroomCowWatcher extends AgeableWatcher {
super(disguise); super(disguise);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public MushroomCow.Variant getVariant() { public MushroomCow.Variant getVariant() {
return MushroomCow.Variant.valueOf(getData(MetaIndex.MUSHROOM_COW_TYPE).toUpperCase()); return MushroomCow.Variant.valueOf(getData(MetaIndex.MUSHROOM_COW_TYPE).toUpperCase());
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setVariant(MushroomCow.Variant variant) { public void setVariant(MushroomCow.Variant variant) {
setData(MetaIndex.MUSHROOM_COW_TYPE, variant.name().toLowerCase()); setData(MetaIndex.MUSHROOM_COW_TYPE, variant.name().toLowerCase());
sendData(MetaIndex.MUSHROOM_COW_TYPE); sendData(MetaIndex.MUSHROOM_COW_TYPE);

View File

@ -1,10 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Ocelot.Type;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Ocelot;
public class OcelotWatcher extends AgeableWatcher { public class OcelotWatcher extends AgeableWatcher {
@ -12,12 +13,27 @@ public class OcelotWatcher extends AgeableWatcher {
super(disguise); super(disguise);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public boolean isTrusting() { public boolean isTrusting() {
return getData(MetaIndex.OCELOT_TRUST); return getData(MetaIndex.OCELOT_TRUST);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setTrusting(boolean trusting) { public void setTrusting(boolean trusting) {
setData(MetaIndex.OCELOT_TRUST, trusting); setData(MetaIndex.OCELOT_TRUST, trusting);
sendData(MetaIndex.OCELOT_TRUST); sendData(MetaIndex.OCELOT_TRUST);
} }
@NmsRemovedIn(val = NmsVersion.v1_14)
@Deprecated
public Ocelot.Type getType() {
return Ocelot.Type.getType(getData(MetaIndex.OCELOT_TYPE));
}
@NmsRemovedIn(val = NmsVersion.v1_14)
@Deprecated
public void setType(Ocelot.Type newType) {
setData(MetaIndex.OCELOT_TYPE, newType.getId());
sendData(MetaIndex.OCELOT_TYPE);
}
} }

View File

@ -3,6 +3,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Panda; import org.bukkit.entity.Panda;
import java.util.Random; import java.util.Random;
@ -10,6 +12,7 @@ import java.util.Random;
/** /**
* Created by libraryaddict on 6/05/2019. * Created by libraryaddict on 6/05/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public class PandaWatcher extends AgeableWatcher { public class PandaWatcher extends AgeableWatcher {
public PandaWatcher(Disguise disguise) { public PandaWatcher(Disguise disguise) {
super(disguise); super(disguise);
@ -32,6 +35,12 @@ public class PandaWatcher extends AgeableWatcher {
return Panda.Gene.NORMAL; return Panda.Gene.NORMAL;
} }
@RandomDefaultValue
public void setMainGene(Panda.Gene gene) {
setData(MetaIndex.PANDA_MAIN_GENE, (byte) gene.ordinal());
sendData(MetaIndex.PANDA_MAIN_GENE);
}
public Panda.Gene getHiddenGene() { public Panda.Gene getHiddenGene() {
int id = getData(MetaIndex.PANDA_HIDDEN_GENE); int id = getData(MetaIndex.PANDA_HIDDEN_GENE);
@ -46,59 +55,53 @@ public class PandaWatcher extends AgeableWatcher {
return Panda.Gene.NORMAL; 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 @RandomDefaultValue
public void setHiddenGene(Panda.Gene gene) { public void setHiddenGene(Panda.Gene gene) {
setData(MetaIndex.PANDA_HIDDEN_GENE, (byte) gene.ordinal()); setData(MetaIndex.PANDA_HIDDEN_GENE, (byte) gene.ordinal());
sendData(MetaIndex.PANDA_HIDDEN_GENE); sendData(MetaIndex.PANDA_HIDDEN_GENE);
} }
public void setSneeze(boolean value) {
setPandaFlag(2, value);
}
public boolean isSneeze() { public boolean isSneeze() {
return getPandaFlag(2); return getPandaFlag(2);
} }
public void setTumble(boolean value) { public void setSneeze(boolean value) {
setPandaFlag(4, value); setPandaFlag(2, value);
} }
public boolean isTumble() { public boolean isTumble() {
return getPandaFlag(4); return getPandaFlag(4);
} }
public void setSitting(boolean value) { public void setTumble(boolean value) {
setPandaFlag(8, value); setPandaFlag(4, value);
} }
public boolean isSitting() { public boolean isSitting() {
return getPandaFlag(8); return getPandaFlag(8);
} }
public void setUpsideDown(boolean value) { public void setSitting(boolean value) {
setPandaFlag(16, value); setPandaFlag(8, value);
} }
public boolean isUpsideDown() { public boolean isUpsideDown() {
return getPandaFlag(16); return getPandaFlag(16);
} }
public void setHeadShaking(int timeInTicks) { public void setUpsideDown(boolean value) {
setData(MetaIndex.PANDA_HEAD_SHAKING, timeInTicks); setPandaFlag(16, value);
sendData(MetaIndex.PANDA_HEAD_SHAKING);
} }
public int getHeadShaking() { public int getHeadShaking() {
return getHeadShakingTicks(); return getHeadShakingTicks();
} }
public void setHeadShaking(int timeInTicks) {
setData(MetaIndex.PANDA_HEAD_SHAKING, timeInTicks);
sendData(MetaIndex.PANDA_HEAD_SHAKING);
}
@Deprecated @Deprecated
public int getHeadShakingTicks() { public int getHeadShakingTicks() {
return getData(MetaIndex.PANDA_HEAD_SHAKING); return getData(MetaIndex.PANDA_HEAD_SHAKING);

View File

@ -2,21 +2,24 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
* Created by libraryaddict on 6/05/2019. * Created by libraryaddict on 6/05/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public class PillagerWatcher extends IllagerWatcher { public class PillagerWatcher extends IllagerWatcher {
public PillagerWatcher(Disguise disguise) { public PillagerWatcher(Disguise disguise) {
super(disguise); super(disguise);
} }
public boolean isAimingBow() {
return getData(MetaIndex.PILLAGER_AIMING_BOW);
}
public void setAimingBow(boolean value) { public void setAimingBow(boolean value) {
setData(MetaIndex.PILLAGER_AIMING_BOW, value); setData(MetaIndex.PILLAGER_AIMING_BOW, value);
sendData(MetaIndex.PILLAGER_AIMING_BOW); sendData(MetaIndex.PILLAGER_AIMING_BOW);
} }
public boolean isAimingBow() {
return getData(MetaIndex.PILLAGER_AIMING_BOW);
}
} }

View File

@ -1,10 +1,13 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
* Created by libraryaddict on 6/05/2019. * Created by libraryaddict on 6/05/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public class RavagerWatcher extends RaiderWatcher { public class RavagerWatcher extends RaiderWatcher {
public RavagerWatcher(Disguise disguise) { public RavagerWatcher(Disguise disguise) {
super(disguise); super(disguise);

View File

@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
* @author Navid * @author Navid
@ -10,4 +12,17 @@ public class SkeletonWatcher extends InsentientWatcher {
public SkeletonWatcher(Disguise disguise) { public SkeletonWatcher(Disguise disguise) {
super(disguise); super(disguise);
} }
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public boolean isSwingArms() {
return getData(MetaIndex.SKELETON_SWING_ARMS);
}
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public void setSwingArms(boolean swingingArms) {
setData(MetaIndex.SKELETON_SWING_ARMS, swingingArms);
sendData(MetaIndex.SKELETON_SWING_ARMS);
}
} }

View File

@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
@ -13,16 +15,20 @@ public abstract class ThrowableWatcher extends FlagWatcher {
public ThrowableWatcher(Disguise disguise) { public ThrowableWatcher(Disguise disguise) {
super(disguise); super(disguise);
setItemStack(getDefaultItemStack()); if (NmsVersion.v1_14.isSupported()) {
setItemStack(getDefaultItemStack());
}
} }
protected abstract ItemStack getDefaultItemStack(); protected abstract ItemStack getDefaultItemStack();
@NmsAddedIn(val = NmsVersion.v1_14)
public ItemStack getItemStack() { public ItemStack getItemStack() {
return getData(MetaIndex.THROWABLE_ITEM); return getData(MetaIndex.THROWABLE_ITEM);
} }
@RandomDefaultValue @RandomDefaultValue
@NmsAddedIn(val = NmsVersion.v1_14)
public void setItemStack(ItemStack item) { public void setItemStack(ItemStack item) {
setData(MetaIndex.THROWABLE_ITEM, item); setData(MetaIndex.THROWABLE_ITEM, item);
sendData(MetaIndex.THROWABLE_ITEM); sendData(MetaIndex.THROWABLE_ITEM);

View File

@ -1,10 +1,13 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
* Created by libraryaddict on 6/05/2019. * Created by libraryaddict on 6/05/2019.
*/ */
@NmsAddedIn(val = NmsVersion.v1_14)
public class TraderLlamaWatcher extends LlamaWatcher { public class TraderLlamaWatcher extends LlamaWatcher {
public TraderLlamaWatcher(Disguise disguise) { public TraderLlamaWatcher(Disguise disguise) {
super(disguise); super(disguise);

View File

@ -2,7 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsAdded; import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
/** /**
@ -13,12 +13,12 @@ public class TridentWatcher extends ArrowWatcher {
super(disguise); super(disguise);
} }
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public boolean isEnchanted() { public boolean isEnchanted() {
return getData(MetaIndex.TRIDENT_ENCHANTED); return getData(MetaIndex.TRIDENT_ENCHANTED);
} }
@NmsAdded(added = NmsVersion.v1_15) @NmsAddedIn(val = NmsVersion.v1_15)
public void setEnchanted(boolean enchanted) { public void setEnchanted(boolean enchanted) {
setData(MetaIndex.TRIDENT_ENCHANTED, enchanted); setData(MetaIndex.TRIDENT_ENCHANTED, enchanted);
sendData(MetaIndex.TRIDENT_ENCHANTED); sendData(MetaIndex.TRIDENT_ENCHANTED);

View File

@ -5,6 +5,8 @@ import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.VillagerData; import me.libraryaddict.disguise.disguisetypes.VillagerData;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
@ -16,46 +18,63 @@ public class VillagerWatcher extends AbstractVillagerWatcher {
setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public VillagerData getVillagerData() { public VillagerData getVillagerData() {
return getData(MetaIndex.VILLAGER_DATA); return getData(MetaIndex.VILLAGER_DATA);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setVillagerData(VillagerData villagerData) { public void setVillagerData(VillagerData villagerData) {
setData(MetaIndex.VILLAGER_DATA, villagerData); setData(MetaIndex.VILLAGER_DATA, villagerData);
sendData(MetaIndex.VILLAGER_DATA); sendData(MetaIndex.VILLAGER_DATA);
} }
public Profession getProfession() { public Profession getProfession() {
return getVillagerData().getProfession(); if (NmsVersion.v1_14.isSupported()) {
} return getVillagerData().getProfession();
}
@Deprecated return Profession.values()[getData(MetaIndex.VILLAGER_PROFESSION) + 1];
public Villager.Type getType() {
return getVillagerData().getType();
}
public Villager.Type getBiome() {
return getType();
}
public void setBiome(Villager.Type type) {
setType(type);
}
public int getLevel() {
return getVillagerData().getLevel();
} }
@RandomDefaultValue @RandomDefaultValue
public void setProfession(Profession profession) { public void setProfession(Profession profession) {
setVillagerData(new VillagerData(getType(), profession, getLevel())); if (NmsVersion.v1_14.isSupported()) {
setVillagerData(new VillagerData(getType(), profession, getLevel()));
} else {
setData(MetaIndex.VILLAGER_PROFESSION, profession.ordinal() - 1);
sendData(MetaIndex.VILLAGER_PROFESSION);
}
} }
@Deprecated @Deprecated
@NmsAddedIn(val = NmsVersion.v1_14)
public Villager.Type getType() {
return getVillagerData().getType();
}
@Deprecated
@NmsAddedIn(val = NmsVersion.v1_14)
public void setType(Villager.Type type) { public void setType(Villager.Type type) {
setVillagerData(new VillagerData(type, getProfession(), getLevel())); setVillagerData(new VillagerData(type, getProfession(), getLevel()));
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public Villager.Type getBiome() {
return getType();
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setBiome(Villager.Type type) {
setType(type);
}
@NmsAddedIn(val = NmsVersion.v1_14)
public int getLevel() {
return getVillagerData().getLevel();
}
@NmsAddedIn(val = NmsVersion.v1_14)
public void setLevel(int level) { public void setLevel(int level) {
setVillagerData(new VillagerData(getType(), getProfession(), getLevel())); setVillagerData(new VillagerData(getType(), getProfession(), getLevel()));
} }

View File

@ -2,10 +2,25 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
public class VindicatorWatcher extends IllagerWatcher { public class VindicatorWatcher extends IllagerWatcher {
public VindicatorWatcher(Disguise disguise) { public VindicatorWatcher(Disguise disguise) {
super(disguise); super(disguise);
} }
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public boolean isJohnny() {
return getData(MetaIndex.ILLAGER_META) == 1;
}
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public void setJohnny(boolean isJohnny) {
setData(MetaIndex.ILLAGER_META, (byte) (isJohnny ? 1 : 0));
sendData(MetaIndex.ILLAGER_META);
}
} }

View File

@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsRemoved; import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
@ -57,7 +57,8 @@ public class WolfWatcher extends TameableWatcher {
* *
* @return * @return
*/ */
@NmsRemoved(removed = NmsVersion.v1_15) @NmsRemovedIn(val = NmsVersion.v1_15)
@Deprecated
public float getDamageTaken() { public float getDamageTaken() {
return getData(MetaIndex.WOLF_DAMAGE); return getData(MetaIndex.WOLF_DAMAGE);
} }
@ -67,7 +68,8 @@ public class WolfWatcher extends TameableWatcher {
* *
* @param damage * @param damage
*/ */
@NmsRemoved(removed = NmsVersion.v1_15) @Deprecated
@NmsRemovedIn(val = NmsVersion.v1_15)
public void setDamageTaken(float damage) { public void setDamageTaken(float damage) {
setData(MetaIndex.WOLF_DAMAGE, damage); setData(MetaIndex.WOLF_DAMAGE, damage);
sendData(MetaIndex.WOLF_DAMAGE); sendData(MetaIndex.WOLF_DAMAGE);

View File

@ -4,6 +4,8 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.VillagerData; import me.libraryaddict.disguise.disguisetypes.VillagerData;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Villager.Profession;
@ -21,24 +23,30 @@ public class ZombieVillagerWatcher extends ZombieWatcher {
return getData(MetaIndex.ZOMBIE_VILLAGER_SHAKING); return getData(MetaIndex.ZOMBIE_VILLAGER_SHAKING);
} }
public void setShaking(boolean shaking) {
setData(MetaIndex.ZOMBIE_VILLAGER_SHAKING, shaking);
sendData(MetaIndex.ZOMBIE_VILLAGER_SHAKING);
}
/** /**
* Is this zombie a villager? * Is this zombie a villager?
* *
* @return * @return
*/ */
public boolean isVillager() { public boolean isVillager() {
return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION).getProfession() != Profession.NONE; if (NmsVersion.v1_14.isSupported()) {
} return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION).getProfession() != Profession.NONE;
} else {
public void setShaking(boolean shaking) { return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION_OLD) != 0;
setData(MetaIndex.ZOMBIE_VILLAGER_SHAKING, shaking); }
sendData(MetaIndex.ZOMBIE_VILLAGER_SHAKING);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public VillagerData getVillagerData() { public VillagerData getVillagerData() {
return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION); return getData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION);
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setVillagerData(VillagerData villagerData) { public void setVillagerData(VillagerData villagerData) {
setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION, villagerData); setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION, villagerData);
sendData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION); sendData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION);
@ -48,33 +56,44 @@ public class ZombieVillagerWatcher extends ZombieWatcher {
return getVillagerData().getProfession(); return getVillagerData().getProfession();
} }
@RandomDefaultValue
public void setProfession(Profession profession) {
if (NmsVersion.v1_14.isSupported()) {
setVillagerData(new VillagerData(getType(), profession, getLevel()));
} else {
setData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION_OLD, profession.ordinal() - 1);
sendData(MetaIndex.ZOMBIE_VILLAGER_PROFESSION_OLD);
}
}
@NmsAddedIn(val = NmsVersion.v1_14)
public Villager.Type getType() { public Villager.Type getType() {
return getVillagerData().getType(); return getVillagerData().getType();
} }
public int getLevel() {
return getVillagerData().getLevel();
}
@RandomDefaultValue
public void setProfession(Profession profession) {
setVillagerData(new VillagerData(getType(), profession, getLevel()));
}
@Deprecated @Deprecated
@NmsAddedIn(val = NmsVersion.v1_14)
public void setType(Villager.Type type) { public void setType(Villager.Type type) {
setVillagerData(new VillagerData(type, getProfession(), getLevel())); setVillagerData(new VillagerData(type, getProfession(), getLevel()));
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public int getLevel() {
return getVillagerData().getLevel();
}
@Deprecated @Deprecated
@NmsAddedIn(val = NmsVersion.v1_14)
public void setLevel(int level) { public void setLevel(int level) {
setVillagerData(new VillagerData(getType(), getProfession(), getLevel())); setVillagerData(new VillagerData(getType(), getProfession(), getLevel()));
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public Villager.Type getBiome() { public Villager.Type getBiome() {
return getType(); return getType();
} }
@NmsAddedIn(val = NmsVersion.v1_14)
public void setBiome(Villager.Type type) { public void setBiome(Villager.Type type) {
setType(type); setType(type);
} }

View File

@ -2,6 +2,8 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
public class ZombieWatcher extends InsentientWatcher { public class ZombieWatcher extends InsentientWatcher {
@ -17,6 +19,11 @@ public class ZombieWatcher extends InsentientWatcher {
return getData(MetaIndex.ZOMBIE_BABY); return getData(MetaIndex.ZOMBIE_BABY);
} }
public void setBaby(boolean baby) {
setData(MetaIndex.ZOMBIE_BABY, baby);
sendData(MetaIndex.ZOMBIE_BABY);
}
public void setAdult() { public void setAdult() {
setBaby(false); setBaby(false);
} }
@ -25,11 +32,6 @@ public class ZombieWatcher extends InsentientWatcher {
setBaby(true); setBaby(true);
} }
public void setBaby(boolean baby) {
setData(MetaIndex.ZOMBIE_BABY, baby);
sendData(MetaIndex.ZOMBIE_BABY);
}
public boolean isConverting() { public boolean isConverting() {
return getData(MetaIndex.ZOMBIE_CONVERTING_DROWNED); return getData(MetaIndex.ZOMBIE_CONVERTING_DROWNED);
} }
@ -38,4 +40,17 @@ public class ZombieWatcher extends InsentientWatcher {
setData(MetaIndex.ZOMBIE_CONVERTING_DROWNED, converting); setData(MetaIndex.ZOMBIE_CONVERTING_DROWNED, converting);
sendData(MetaIndex.ZOMBIE_CONVERTING_DROWNED); sendData(MetaIndex.ZOMBIE_CONVERTING_DROWNED);
} }
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public boolean isAggressive() {
return (boolean) getData(MetaIndex.ZOMBIE_AGGRESSIVE);
}
@Deprecated
@NmsRemovedIn(val = NmsVersion.v1_14)
public void setAggressive(boolean handsup) {
setData(MetaIndex.ZOMBIE_AGGRESSIVE, handsup);
sendData(MetaIndex.ZOMBIE_AGGRESSIVE);
}
} }

View File

@ -22,14 +22,10 @@ import me.libraryaddict.disguise.utilities.json.*;
import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI; import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI;
import me.libraryaddict.disguise.utilities.packets.LibsPackets; import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import me.libraryaddict.disguise.utilities.packets.PacketsManager; import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues; import me.libraryaddict.disguise.utilities.reflection.*;
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -41,17 +37,16 @@ import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus; import org.bukkit.scoreboard.Team.OptionStatus;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class DisguiseUtilities { public class DisguiseUtilities {
public static class ExtendedName { public static class ExtendedName {
@ -111,7 +106,6 @@ public class DisguiseUtilities {
private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>(); private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
@Getter @Getter
private static HashSet<UUID> selfDisguised = new HashSet<>(); private static HashSet<UUID> selfDisguised = new HashSet<>();
private static Thread mainThread;
private static HashMap<UUID, String> preDisguiseTeam = new HashMap<>(); private static HashMap<UUID, String> preDisguiseTeam = new HashMap<>();
private static HashMap<UUID, String> disguiseTeam = new HashMap<>(); private static HashMap<UUID, String> disguiseTeam = new HashMap<>();
private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File( private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File(
@ -321,7 +315,13 @@ public class DisguiseUtilities {
} }
try { try {
String cached = FileUtils.readFileToString(disguiseFile, "UTF-8"); String cached = null;
try (FileInputStream input = new FileInputStream(
disguiseFile); InputStreamReader inputReader = new InputStreamReader(input,
StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(inputReader)) {
cached = reader.lines().collect(Collectors.joining("\n"));
}
if (remove) { if (remove) {
removeSavedDisguise(entityUUID); removeSavedDisguise(entityUUID);
@ -515,7 +515,7 @@ public class DisguiseUtilities {
* Sends entity removal packets, as this disguise was removed * Sends entity removal packets, as this disguise was removed
*/ */
public static void destroyEntity(TargetedDisguise disguise) { public static void destroyEntity(TargetedDisguise disguise) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
try { try {
@ -696,7 +696,7 @@ public class DisguiseUtilities {
* @return * @return
*/ */
public static List<Player> getPerverts(Disguise disguise) { public static List<Player> getPerverts(Disguise disguise) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
if (disguise.getEntity() == null) if (disguise.getEntity() == null)
@ -895,16 +895,6 @@ public class DisguiseUtilities {
gson = gsonBuilder.create(); gson = gsonBuilder.create();
try {
Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread");
threadField.setAccessible(true);
mainThread = (Thread) threadField.get(ReflectionManager.getMinecraftServer());
}
catch (Exception ex) {
ex.printStackTrace();
}
if (!profileCache.exists()) if (!profileCache.exists())
profileCache.mkdirs(); profileCache.mkdirs();
@ -953,7 +943,7 @@ public class DisguiseUtilities {
* Resends the entity to this specific player * Resends the entity to this specific player
*/ */
public static void refreshTracker(final TargetedDisguise disguise, String player) { public static void refreshTracker(final TargetedDisguise disguise, String player) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
if (disguise.getEntity() == null || !disguise.getEntity().isValid()) if (disguise.getEntity() == null || !disguise.getEntity().isValid())
@ -990,10 +980,12 @@ public class DisguiseUtilities {
.get(entityTrackerEntry); .get(entityTrackerEntry);
Method clear = ReflectionManager Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager final Method updatePlayer = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException // ConcurrentModificationException
@ -1030,7 +1022,7 @@ public class DisguiseUtilities {
* A convenience method for me to refresh trackers in other plugins * A convenience method for me to refresh trackers in other plugins
*/ */
public static void refreshTrackers(Entity entity) { public static void refreshTrackers(Entity entity) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
if (entity.isValid()) { if (entity.isValid()) {
@ -1044,10 +1036,12 @@ public class DisguiseUtilities {
.get(entityTrackerEntry); .get(entityTrackerEntry);
Method clear = ReflectionManager Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager final Method updatePlayer = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException // ConcurrentModificationException
@ -1081,7 +1075,7 @@ public class DisguiseUtilities {
* Resends the entity to all the watching players, which is where the magic begins * Resends the entity to all the watching players, which is where the magic begins
*/ */
public static void refreshTrackers(final TargetedDisguise disguise) { public static void refreshTrackers(final TargetedDisguise disguise) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
if (!disguise.getEntity().isValid()) { if (!disguise.getEntity().isValid()) {
@ -1115,10 +1109,12 @@ public class DisguiseUtilities {
.get(entityTrackerEntry); .get(entityTrackerEntry);
final Method clear = ReflectionManager final Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager final Method updatePlayer = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "b" : "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
@ -1179,7 +1175,7 @@ public class DisguiseUtilities {
} }
public static void removeSelfDisguise(Player player) { public static void removeSelfDisguise(Player player) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
if (!selfDisguised.contains(player.getUniqueId())) { if (!selfDisguised.contains(player.getUniqueId())) {
@ -1700,7 +1696,7 @@ public class DisguiseUtilities {
* Sends the self disguise to the player * Sends the self disguise to the player
*/ */
public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) { public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
if (mainThread != Thread.currentThread()) if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("Cannot modify disguises on an async thread"); throw new IllegalStateException("Cannot modify disguises on an async thread");
try { try {
@ -1755,7 +1751,8 @@ public class DisguiseUtilities {
boolean isMoving = false; boolean isMoving = false;
try { try {
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("q"); Field field = ReflectionManager.getNmsClass("EntityTrackerEntry")
.getDeclaredField(NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
field.setAccessible(true); field.setAccessible(true);
isMoving = field.getBoolean(entityTrackerEntry); isMoving = field.getBoolean(entityTrackerEntry);
} }
@ -1816,14 +1813,6 @@ public class DisguiseUtilities {
Location loc = player.getLocation(); Location loc = player.getLocation();
// If the disguised is sleeping for w/e reason
if (player.isSleeping()) {
/* sendSelfPacket(player,
manager.createPacketConstructor(Server.BED, player, ReflectionManager.getBlockPosition(0, 0, 0))
.createPacket(player, ReflectionManager
.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));*/
}
// Resend any active potion effects // Resend any active potion effects
for (PotionEffect potionEffect : player.getActivePotionEffects()) { for (PotionEffect potionEffect : player.getActivePotionEffects()) {
Object mobEffect = ReflectionManager.createMobEffect(potionEffect); Object mobEffect = ReflectionManager.createMobEffect(potionEffect);

View File

@ -5,14 +5,12 @@ import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import java.io.File; import java.io.*;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.Date; import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit; import java.util.stream.Collectors;
/** /**
* Created by libraryaddict on 2/06/2017. * Created by libraryaddict on 2/06/2017.
@ -265,7 +263,11 @@ public class LibsPremium {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
try { try {
config.loadFromString(IOUtils.toString(LibsDisguises.getInstance().getResource("plugin.yml"), "UTF-8")); try (InputStream stream = LibsDisguises.getInstance().getResource("plugin.yml")) {
config.loadFromString(
new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining("\n")));
}
// If plugin.yml contains a build-date // If plugin.yml contains a build-date
if (config.contains("build-date")) { if (config.contains("build-date")) {

View File

@ -2,15 +2,16 @@ package me.libraryaddict.disguise.utilities;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.Getter; import lombok.Getter;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
public class UpdateChecker { public class UpdateChecker {
private final String resourceID; private final String resourceID;
@ -75,7 +76,8 @@ public class UpdateChecker {
// Get the input stream, what we receive // Get the input stream, what we receive
try (InputStream input = con.getInputStream()) { try (InputStream input = con.getInputStream()) {
// Read it to string // Read it to string
String version = IOUtils.toString(input); String version = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines().collect(Collectors.joining("\n"));
// If the version is not empty, return it // If the version is not empty, return it
if (!version.isEmpty()) { if (!version.isEmpty()) {
@ -149,7 +151,8 @@ public class UpdateChecker {
// Get the input stream, what we receive // Get the input stream, what we receive
try (InputStream input = con.getInputStream()) { try (InputStream input = con.getInputStream()) {
// Read it to string // Read it to string
String json = IOUtils.toString(input); String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines().collect(Collectors.joining("\n"));
jsonObject = new Gson().fromJson(json, Map.class); jsonObject = new Gson().fromJson(json, Map.class);
} }

View File

@ -3,18 +3,18 @@ package me.libraryaddict.disguise.utilities.mineskin;
import com.google.gson.Gson; import com.google.gson.Gson;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.SkinUtils; import me.libraryaddict.disguise.utilities.SkinUtils;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/** /**
* Created by libraryaddict on 28/12/2019. * Created by libraryaddict on 28/12/2019.
@ -107,7 +107,8 @@ public class MineSkinAPI {
} }
if (connection.getResponseCode() == 500) { if (connection.getResponseCode() == 500) {
APIError error = new Gson().fromJson(IOUtils.toString(connection.getErrorStream()), APIError.class); APIError error = new Gson().fromJson(new BufferedReader(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))
.lines().collect(Collectors.joining("\n")), APIError.class);
if (error.code == 403) { if (error.code == 403) {
callback.onError(LibsMsg.SKIN_API_FAIL_CODE, "" + error.code, LibsMsg.SKIN_API_403.get()); callback.onError(LibsMsg.SKIN_API_FAIL_CODE, "" + error.code, LibsMsg.SKIN_API_403.get());
@ -136,7 +137,8 @@ public class MineSkinAPI {
// Get the input stream, what we receive // Get the input stream, what we receive
try (InputStream input = connection.getInputStream()) { try (InputStream input = connection.getInputStream()) {
// Read it to string // Read it to string
String response = IOUtils.toString(input); String response = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines().collect(Collectors.joining("\n"));
MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class); MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class);
@ -188,7 +190,8 @@ public class MineSkinAPI {
// Get the input stream, what we receive // Get the input stream, what we receive
try (InputStream input = con.getInputStream()) { try (InputStream input = con.getInputStream()) {
// Read it to string // Read it to string
String response = IOUtils.toString(input); String response = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines().collect(Collectors.joining("\n"));
MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class); MineSkinResponse skinResponse = new Gson().fromJson(response, MineSkinResponse.class);

View File

@ -29,7 +29,6 @@ public class PacketsHandler {
packetHandlers.add(new PacketHandlerAnimation()); packetHandlers.add(new PacketHandlerAnimation());
packetHandlers.add(new PacketHandlerAttributes()); packetHandlers.add(new PacketHandlerAttributes());
packetHandlers.add(new PacketHandlerBed());
packetHandlers.add(new PacketHandlerCollect()); packetHandlers.add(new PacketHandlerCollect());
packetHandlers.add(new PacketHandlerEntityStatus()); packetHandlers.add(new PacketHandlerEntityStatus());
packetHandlers.add(new PacketHandlerEquipment(this)); packetHandlers.add(new PacketHandlerEquipment(this));

View File

@ -1,28 +0,0 @@
package me.libraryaddict.disguise.utilities.packets.packethandlers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
/**
* Created by libraryaddict on 3/01/2019.
*/
public class PacketHandlerBed implements IPacketHandler {
@Override
public PacketType[] getHandledPackets() {
return new PacketType[]{};
}
@Override
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) {
// If the entity is going into a bed, stop everything but players from doing this
if (!disguise.getType().isPlayer()) {
packets.clear();
}
}
}

View File

@ -225,7 +225,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
packets.addPacket(spawnPlayer); packets.addPacket(spawnPlayer);
if (ReflectionManager.isSupported(NmsVersion.v1_15)) { if (NmsVersion.v1_15.isSupported()) {
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true) .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true)
.createPacket(entityId, newWatcher, true); .createPacket(entityId, newWatcher, true);
@ -314,7 +314,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), .createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher()); disguise.getWatcher());
if (ReflectionManager.isSupported(NmsVersion.v1_15)) { if (NmsVersion.v1_15.isSupported()) {
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), .createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(),
newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true); newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true);
@ -348,14 +348,26 @@ public class PacketHandlerSpawn implements IPacketHandler {
data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4; data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4;
} }
Object entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType()); PacketContainer spawnEntity;
Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z, if (NmsVersion.v1_14.isSupported()) {
loc.getPitch(), loc.getYaw(), entityType, data, Object entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType());
ReflectionManager.getVec3D(disguisedEntity.getVelocity())};
Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), x, y, z,
loc.getPitch(), loc.getYaw(), entityType, data,
ReflectionManager.getVec3D(disguisedEntity.getVelocity())};
spawnEntity = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params);
} else {
int objectId = disguise.getType().getObjectId();
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
spawnEntity = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
.createPacket(nmsEntity, objectId, data);
}
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params);
packets.addPacket(spawnEntity); packets.addPacket(spawnEntity);
// If it's not the same type, then highly likely they have different velocity settings which we'd want to // If it's not the same type, then highly likely they have different velocity settings which we'd want to

View File

@ -78,26 +78,18 @@ public class DisguiseParser {
getName = "get" + getName; getName = "get" + getName;
} }
Method getMethod = null; Method getMethod = setMethod.getDeclaringClass().getMethod(getName);
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) { if (getMethod == null) {
DisguiseUtilities.getLogger().severe(String DisguiseUtilities.getLogger().severe(String
.format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, .format("No such method '%s' when looking for the companion of '%s' in '%s'", getName,
setMethod.getName(), setMethod.getDeclaringClass().getSimpleName())); setMethod.getName(), setMethod.getDeclaringClass().getSimpleName()));
continue; continue;
}else if (getMethod.getReturnType() != setMethod.getParameterTypes()[0]){
DisguiseUtilities.getLogger().severe(String
.format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName,
setMethod.getName(), setMethod.getDeclaringClass().getSimpleName()));
continue;
} }
Object defaultValue = null; Object defaultValue = null;

View File

@ -9,6 +9,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes; import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
import me.libraryaddict.disguise.utilities.reflection.DisguiseMethods;
import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -21,6 +23,7 @@ import java.util.List;
public class ParamInfoManager { public class ParamInfoManager {
private static List<ParamInfo> paramList; private static List<ParamInfo> paramList;
private static DisguiseMethods disguiseMethods;
public static List<ParamInfo> getParamInfos() { public static List<ParamInfo> getParamInfos() {
return paramList; return paramList;
@ -61,12 +64,6 @@ public class ParamInfoManager {
if (!method.getName().toLowerCase().equals(methodName.toLowerCase())) if (!method.getName().toLowerCase().equals(methodName.toLowerCase()))
continue; continue;
if (method.getParameterTypes().length != 1)
continue;
if (method.getAnnotation(Deprecated.class) != null)
continue;
return getParamInfo(method.getParameterTypes()[0]); return getParamInfo(method.getParameterTypes()[0]);
} }
@ -75,6 +72,7 @@ public class ParamInfoManager {
static { static {
paramList = new ParamInfoTypes().getParamInfos(); paramList = new ParamInfoTypes().getParamInfos();
disguiseMethods = new DisguiseMethods();
//paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())); //paramList.sort((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName()));
} }
@ -84,7 +82,7 @@ public class ParamInfoManager {
return new Method[0]; return new Method[0];
} }
ArrayList<Method> methods = new ArrayList<>(Arrays.asList(watcherClass.getMethods())); ArrayList<Method> methods = new ArrayList<>(disguiseMethods.getMethods(watcherClass));
Iterator<Method> itel = methods.iterator(); Iterator<Method> itel = methods.iterator();
@ -93,20 +91,8 @@ public class ParamInfoManager {
if (!ReflectionManager.isSupported(method)) { if (!ReflectionManager.isSupported(method)) {
itel.remove(); itel.remove();
} else if (method.getParameterTypes().length != 1) {
itel.remove();
} else if (method.getName().startsWith("get")) {
itel.remove();
} else if (method.isAnnotationPresent(Deprecated.class)) {
itel.remove();
} else if (getParamInfo(method.getParameterTypes()[0]) == null) { } else if (getParamInfo(method.getParameterTypes()[0]) == null) {
itel.remove(); itel.remove();
} else if (!method.getReturnType().equals(Void.TYPE)) {
itel.remove();
} else if (method.getName().equals("removePotionEffect")) {
itel.remove();
} else if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) {
itel.remove();
} }
} }

View File

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum; import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.parser.params.types.base.*; import me.libraryaddict.disguise.utilities.parser.params.types.base.*;
import me.libraryaddict.disguise.utilities.parser.params.types.custom.*; import me.libraryaddict.disguise.utilities.parser.params.types.custom.*;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -41,8 +42,12 @@ public class ParamInfoTypes {
paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession", paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a Villager and Zombie Villager")); "View all the professions you can set on a Villager and Zombie Villager"));
paramInfos.add(new ParamInfoEnum(Villager.Type.class, "Villager Biome",
"View all the biomes you can set on a Villager and Zombie Villager")); if (NmsVersion.v1_14.isSupported()) {
paramInfos.add(new ParamInfoEnum(Villager.Type.class, "Villager Biome",
"View all the biomes you can set on a Villager and Zombie Villager"));
}
paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)", paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)",
"View the directions usable on player setSleeping and shulker direction", "View the directions usable on player setSleeping and shulker direction",
Arrays.copyOf(BlockFace.values(), 6))); Arrays.copyOf(BlockFace.values(), 6)));
@ -62,12 +67,15 @@ public class ParamInfoTypes {
paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors")); paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors"));
paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style", paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style",
"Horse style which is the patterns on the horse")); "Horse style which is the patterns on the horse"));
paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike"));
paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat")); if (NmsVersion.v1_14.isSupported()) {
paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox")); paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike"));
paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type")); paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat"));
paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant", paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox"));
"The different variants for mushroom cows")); paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type"));
paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant",
"The different variants for mushroom cows"));
}
// Register custom types // Register custom types
paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)",

View File

@ -2,11 +2,14 @@ package me.libraryaddict.disguise.utilities.reflection;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import java.io.File;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.security.CodeSource; import java.security.CodeSource;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,27 +23,36 @@ import java.util.jar.JarFile;
// Code for this taken and slightly modified from // Code for this taken and slightly modified from
// https://github.com/ddopson/java-class-enumerator // https://github.com/ddopson/java-class-enumerator
public class ClassGetter { public class ClassGetter {
private class TestPrem {
String user = "%%__USER__%%";
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
private @interface PremInfo {
String user();
}
public static ArrayList<Class<?>> getClassesForPackage(String pkgname) { public static ArrayList<Class<?>> getClassesForPackage(String pkgname) {
return getClassesForPackage(Entity.class, pkgname);
}
public static ArrayList<Class<?>> getClassesForPackage(Class runFrom, String pkgname) {
ArrayList<Class<?>> classes = new ArrayList<>(); ArrayList<Class<?>> classes = new ArrayList<>();
// String relPath = pkgname.replace('.', '/'); // String relPath = pkgname.replace('.', '/');
// Get a File object for the package // Get a File object for the package
CodeSource src = Entity.class.getProtectionDomain().getCodeSource(); CodeSource src = runFrom.getProtectionDomain().getCodeSource();
if (src != null) { if (src != null) {
URL resource = src.getLocation(); URL resource = src.getLocation();
resource.getPath();
processJarfile(resource, pkgname, classes); if (resource.getPath().endsWith(".jar")) {
processJarfile(resource, pkgname, classes);
} else {
for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) {
if (!f.getName().endsWith(".class")) {
continue;
}
try {
classes.add(Class.forName(pkgname + "." + f.getName().replace(".class", "")));
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
} }
return classes; return classes;
@ -58,7 +70,6 @@ public class ClassGetter {
} }
} }
@PremInfo(user = "%%__USER__%%")
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) { private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) {
try { try {
String relPath = pkgname.replace('.', '/'); String relPath = pkgname.replace('.', '/');

View File

@ -0,0 +1,79 @@
package me.libraryaddict.disguise.utilities.reflection;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MushroomCowWatcher;
import org.apache.commons.lang.StringUtils;
import java.io.File;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
/**
* Created by libraryaddict on 13/02/2020.
*/
public class CompileMethods {
public static void main(String[] args) {
ArrayList<Class<?>> classes = ClassGetter
.getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers");
classes.add(FlagWatcher.class);
classes.add(MushroomCowWatcher.class);
ArrayList<String> methods = new ArrayList<>();
for (Class c : classes) {
for (Method method : c.getMethods()) {
if (method.getParameterTypes().length != 1) {
continue;
} else if (method.getName().startsWith("get")) {
continue;
} else if (method.isAnnotationPresent(Deprecated.class) &&
!method.isAnnotationPresent(NmsRemovedIn.class)) {
continue;
} else if (!method.getReturnType().equals(Void.TYPE)) {
continue;
} else if (method.getName().equals("removePotionEffect")) {
continue;
} else if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) {
continue;
}
int added = -1;
int removed = -1;
if (method.isAnnotationPresent(NmsAddedIn.class)) {
added = method.getAnnotation(NmsAddedIn.class).val().ordinal();
} else if (method.getDeclaringClass().isAnnotationPresent(NmsAddedIn.class)) {
added = method.getDeclaringClass().getAnnotation(NmsAddedIn.class).val().ordinal();
}
if (method.isAnnotationPresent(NmsRemovedIn.class)) {
removed = method.getAnnotation(NmsRemovedIn.class).val().ordinal();
} else if (method.getDeclaringClass().isAnnotationPresent(NmsRemovedIn.class)) {
removed = method.getDeclaringClass().getAnnotation(NmsRemovedIn.class).val().ordinal();
}
Class<?> param = method.getParameterTypes()[0];
String s = ((added >= 0 || removed >= 0) ? added + ":" + removed + ":" : "") +
method.getDeclaringClass().getSimpleName() + ":" + method.getName() + ":" +
param.getName();
if (methods.contains(s)) {
continue;
}
methods.add(s);
}
}
File methodsFile = new File("target/classes/methods.txt");
try (PrintWriter writer = new PrintWriter(methodsFile, "UTF-8")) {
writer.write(StringUtils.join(methods, "\n"));
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,133 @@
package me.libraryaddict.disguise.utilities.reflection;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import org.apache.commons.lang.ClassUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by libraryaddict on 13/02/2020.
*/
public class DisguiseMethods {
private HashMap<Class<? extends FlagWatcher>, List<Method>> watcherMethods = new HashMap<>();
public ArrayList<Method> getMethods(Class c) {
ArrayList<Method> methods = new ArrayList<>();
if (watcherMethods.containsKey(c)) {
methods.addAll(watcherMethods.get(c));
}
if (c != FlagWatcher.class) {
methods.addAll(getMethods(c.getSuperclass()));
}
return methods;
}
public DisguiseMethods() {
try (InputStream stream = LibsDisguises.getInstance().getResource("methods.txt")) {
List<String> lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
.collect(Collectors.toList());
HashMap<String, Class<? extends FlagWatcher>> classes = new HashMap<>();
classes.put(FlagWatcher.class.getSimpleName(), FlagWatcher.class);
for (DisguiseType t : DisguiseType.values()) {
if (t.getWatcherClass() == null) {
continue;
}
Class c = t.getWatcherClass();
while (!classes.containsKey(c.getSimpleName())) {
classes.put(c.getSimpleName(), c);
c = ReflectionManager.getSuperClass(c);
}
}
for (String line : lines) {
String[] split = line.split(":");
if (split.length > 3) {
int added = Integer.parseInt(split[0]);
int removed = Integer.parseInt(split[1]);
if (added >= 0 && added > ReflectionManager.getVersion().ordinal()) {
continue;
} else if (removed >= 0 && removed <= ReflectionManager.getVersion().ordinal()) {
continue;
}
}
Class<? extends FlagWatcher> watcher = classes.get(split[split.length - 3]);
if (watcher == null) {
continue;
}
String paramName = split[split.length - 1];
Class param;
if (!paramName.contains(".")) {
param = parseType(paramName);
} else {
param = Class.forName(paramName);
}
Method method = watcher.getMethod(split[split.length - 2], param);
watcherMethods.computeIfAbsent(watcher, (a) -> new ArrayList<>()).add(method);
}
}
catch (IOException | ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
}
/**
* Return the java {@link java.lang.Class} object with the specified class name.
* <p>
* This is an "extended" {@link java.lang.Class#forName(java.lang.String) } operation.
* <p>
* + It is able to return Class objects for primitive types
* + Classes in name space `java.lang` do not need the fully qualified name
* + It does not throw a checked Exception
*
* @param className The class name, never `null`
* @throws IllegalArgumentException if no class can be loaded
*/
private Class<?> parseType(final String className) {
switch (className) {
case "boolean":
return boolean.class;
case "byte":
return byte.class;
case "short":
return short.class;
case "int":
return int.class;
case "long":
return long.class;
case "float":
return float.class;
case "double":
return double.class;
case "char":
return char.class;
case "[I":
return int[].class;
default:
throw new IllegalArgumentException("Class not found: " + className);
}
}
}

View File

@ -7,6 +7,6 @@ import java.lang.annotation.RetentionPolicy;
* Created by libraryaddict on 6/02/2020. * Created by libraryaddict on 6/02/2020.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface NmsAdded { public @interface NmsAddedIn {
NmsVersion added(); NmsVersion val();
} }

View File

@ -7,6 +7,6 @@ import java.lang.annotation.RetentionPolicy;
* Created by libraryaddict on 6/02/2020. * Created by libraryaddict on 6/02/2020.
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface NmsRemoved { public @interface NmsRemovedIn {
NmsVersion removed(); NmsVersion val();
} }

View File

@ -4,6 +4,14 @@ package me.libraryaddict.disguise.utilities.reflection;
* Created by libraryaddict on 6/02/2020. * Created by libraryaddict on 6/02/2020.
*/ */
public enum NmsVersion { public enum NmsVersion {
v1_13,
v1_14, v1_14,
v1_15 v1_15;
/**
* If this nms version isn't newer than the running version
*/
public boolean isSupported() {
return ReflectionManager.getVersion().ordinal() >= ordinal();
}
} }

View File

@ -18,7 +18,7 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils; import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -26,15 +26,19 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class ReflectionManager { public class ReflectionManager {
private static String bukkitVersion; private static String bukkitVersion;
@ -43,18 +47,20 @@ public class ReflectionManager {
private static Constructor<?> boundingBoxConstructor; private static Constructor<?> boundingBoxConstructor;
private static Method setBoundingBoxMethod; private static Method setBoundingBoxMethod;
private static Field pingField; private static Field pingField;
public static Field entityCountField; private static Field entityCountField;
private static Field chunkMapField; private static Field chunkMapField;
private static Field chunkProviderField; private static Field chunkProviderField;
private static Field entityTrackerField; private static Field entityTrackerField;
private static Field trackedEntitiesField; private static Field trackedEntitiesField;
@NmsRemovedIn(val = NmsVersion.v1_14)
private static Method ihmGet;
@NmsRemovedIn(val = NmsVersion.v1_14)
private static Field trackerField;
@NmsRemovedIn(val = NmsVersion.v1_14)
private static Field entitiesField;
@Getter @Getter
private static NmsVersion version; private static NmsVersion version;
public static boolean isSupported(NmsVersion version) {
return getVersion().ordinal() >= version.ordinal();
}
public static void init() { public static void init() {
try { try {
Object entity = createEntityInstance(DisguiseType.COW, "Cow"); Object entity = createEntityInstance(DisguiseType.COW, "Cow");
@ -88,10 +94,16 @@ public class ReflectionManager {
pingField = getNmsField("EntityPlayer", "ping"); pingField = getNmsField("EntityPlayer", "ping");
chunkProviderField = getNmsField("World", "chunkProvider"); if (NmsVersion.v1_14.isSupported()) {
chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap"); chunkProviderField = getNmsField("World", "chunkProvider");
trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities"); chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap");
entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry"); trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities");
entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry");
} else {
trackerField = getNmsField("WorldServer", "tracker");
entitiesField = getNmsField("EntityTracker", "trackedEntities");
ihmGet = getNmsMethod("IntHashMap", "get", int.class);
}
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class,
double.class, double.class, double.class); double.class, double.class, double.class);
@ -104,19 +116,19 @@ public class ReflectionManager {
} }
public static boolean isSupported(AccessibleObject obj) { public static boolean isSupported(AccessibleObject obj) {
if (obj.isAnnotationPresent(NmsAdded.class)) { if (obj.isAnnotationPresent(NmsAddedIn.class)) {
NmsAdded added = obj.getAnnotation(NmsAdded.class); NmsAddedIn added = obj.getAnnotation(NmsAddedIn.class);
// If it was added after/on this version // If it was added after this version
if (!isSupported(added.added())) { if (!added.val().isSupported()) {
return false; return false;
} }
} }
if (obj.isAnnotationPresent(NmsRemoved.class)) { if (obj.isAnnotationPresent(NmsRemovedIn.class)) {
NmsRemoved removed = obj.getAnnotation(NmsRemoved.class); NmsRemovedIn removed = obj.getAnnotation(NmsRemovedIn.class);
if (isSupported(removed.removed())) { if (removed.val().isSupported()) {
return false; return false;
} }
} }
@ -152,7 +164,8 @@ public class ReflectionManager {
public static YamlConfiguration getPluginYaml(ClassLoader loader) { public static YamlConfiguration getPluginYaml(ClassLoader loader) {
try (InputStream stream = loader.getResourceAsStream("plugin.yml")) { try (InputStream stream = loader.getResourceAsStream("plugin.yml")) {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.loadFromString(IOUtils.toString(stream, "UTF-8")); config.loadFromString(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining("\n")));
return config; return config;
} }
@ -169,17 +182,21 @@ public class ReflectionManager {
public static int getNewEntityId(boolean increment) { public static int getNewEntityId(boolean increment) {
try { try {
AtomicInteger entityCount = (AtomicInteger) entityCountField.get(null); Number entityCount = (Number) entityCountField.get(null);
int id;
if (increment) { if (increment) {
id = entityCount.getAndIncrement(); if (NmsVersion.v1_14.isSupported()) {
} else { return ((AtomicInteger) entityCount).getAndIncrement();
id = entityCount.get(); } else {
int id = entityCount.intValue();
entityCountField.set(null, id + 1);
return id;
}
} }
return id; return entityCount.intValue();
} }
catch (IllegalAccessException e) { catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
@ -194,34 +211,44 @@ public class ReflectionManager {
Object entityObject; Object entityObject;
Object world = getWorldServer(Bukkit.getWorlds().get(0)); Object world = getWorldServer(Bukkit.getWorlds().get(0));
switch (entityName) { if (entityName.equals("Player")) {
case "Player": Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object playerinteractmanager = getNmsClass("PlayerInteractManager") Object playerinteractmanager = getNmsClass("PlayerInteractManager")
.getDeclaredConstructor(getNmsClass("WorldServer")).newInstance(world); .getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World"))
.newInstance(world);
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
entityObject = entityClass entityObject = entityClass
.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), .getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
gameProfile.getHandleType(), playerinteractmanager.getClass()) gameProfile.getHandleType(), playerinteractmanager.getClass())
.newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); .newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
break; } else if (entityName.equals("EnderPearl")) {
case "EnderPearl": entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow"));
.newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); } else if (entityName.equals("FishingHook")) {
break; if (NmsVersion.v1_14.isSupported()) {
case "FishingHook":
entityObject = entityClass entityObject = entityClass
.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class, .getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class,
int.class) int.class)
.newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0); .newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0);
break; } else {
default: entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman"))
.newInstance(world, createEntityInstance(DisguiseType.PLAYER, "Player"));
}
} else if (!NmsVersion.v1_14.isSupported() && entityName.equals("Potion")) {
entityObject = entityClass
.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE,
getNmsClass("ItemStack"))
.newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION)));
} else {
if (NmsVersion.v1_14.isSupported()) {
entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityTypes"), getNmsClass("World")) entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityTypes"), getNmsClass("World"))
.newInstance(getEntityType(disguiseType.getEntityType()), world); .newInstance(getEntityType(disguiseType.getEntityType()), world);
break; } else {
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World")).newInstance(world);
}
} }
return entityObject; return entityObject;
@ -395,17 +422,25 @@ public class ReflectionManager {
public static Object getEntityTrackerEntry(Entity target) throws Exception { public static Object getEntityTrackerEntry(Entity target) throws Exception {
Object world = getWorldServer(target.getWorld()); Object world = getWorldServer(target.getWorld());
Object chunkProvider = chunkProviderField.get(world);
Object chunkMap = chunkMapField.get(chunkProvider);
Map trackedEntities = (Map) trackedEntitiesField.get(chunkMap);
Object entityTracker = trackedEntities.get(target.getEntityId()); if (NmsVersion.v1_14.isSupported()) {
Object chunkProvider = chunkProviderField.get(world);
Object chunkMap = chunkMapField.get(chunkProvider);
Map trackedEntities = (Map) trackedEntitiesField.get(chunkMap);
if (entityTracker == null) { Object entityTracker = trackedEntities.get(target.getEntityId());
return null;
if (entityTracker == null) {
return null;
}
return entityTrackerField.get(entityTracker);
} }
return entityTrackerField.get(entityTracker); Object tracker = trackerField.get(world);
Object trackedEntities = entitiesField.get(tracker);
return ihmGet.invoke(trackedEntities, target.getEntityId());
} }
public static Object getMinecraftServer() { public static Object getMinecraftServer() {
@ -675,13 +710,21 @@ public class ReflectionManager {
public static float[] getSize(Entity entity) { public static float[] getSize(Entity entity) {
try { try {
Object size = getNmsField("Entity", "size").get(getNmsEntity(entity)); if (NmsVersion.v1_14.isSupported()) {
Object size = getNmsField("Entity", "size").get(getNmsEntity(entity));
//float length = getNmsField("EntitySize", "length").getFloat(size); //float length = getNmsField("EntitySize", "length").getFloat(size);
float width = getNmsField("EntitySize", "width").getFloat(size); float width = getNmsField("EntitySize", "width").getFloat(size);
float height = getNmsField("Entity", "headHeight").getFloat(getNmsEntity(entity)); float height = getNmsField("Entity", "headHeight").getFloat(getNmsEntity(entity));
return new float[]{width, height}; return new float[]{width, height};
} else {
// float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity));
float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity));
float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
return new float[]{width, height};
}
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -1045,6 +1088,30 @@ public class ReflectionManager {
return null; return null;
} }
public static boolean isAssignableFrom(Class toCheck, Class checkAgainst) {
if (!NmsVersion.v1_14.isSupported() && toCheck != checkAgainst) {
if (toCheck == OcelotWatcher.class) {
toCheck = TameableWatcher.class;
}
}
return checkAgainst.isAssignableFrom(toCheck);
}
public static Class getSuperClass(Class cl) {
if (cl == FlagWatcher.class) {
return null;
}
if (!NmsVersion.v1_14.isSupported()) {
if (cl == OcelotWatcher.class) {
return TameableWatcher.class;
}
}
return cl.getSuperclass();
}
public static Object getVillagerProfession(Villager.Profession profession) { public static Object getVillagerProfession(Villager.Profession profession) {
try { try {
Object villagerProfession = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); Object villagerProfession = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
@ -1124,10 +1191,14 @@ public class ReflectionManager {
public static Object getEntityType(EntityType entityType) { public static Object getEntityType(EntityType entityType) {
try { try {
Method entityTypes = getNmsMethod("EntityTypes", "a", String.class); Method entityTypes = getNmsMethod("EntityTypes", "a", String.class);
Object val = entityTypes.invoke(null,
entityType.getName() == null ? entityType.name().toLowerCase() : entityType.getName());
Optional<Object> entityObj = (Optional<Object>) entityTypes.invoke(null, entityType.getName()); if (NmsVersion.v1_14.isSupported()) {
return ((Optional<Object>) val).orElse(null);
}
return entityObj.orElse(null); return val;
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -1513,6 +1584,7 @@ public class ReflectionManager {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger()
.severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + .severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" +
nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName()); nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName());
continue; continue;
} }