2016-06-12 19:43:41 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2017-06-22 18:14:19 +02:00
|
|
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
|
|
|
import me.libraryaddict.disguise.commands.*;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
2017-06-08 17:06:58 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
2019-02-16 04:57:07 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer;
|
|
|
|
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.DisguiseValues;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
|
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
2019-05-18 08:54:51 +02:00
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
2016-06-12 19:43:41 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2016-11-28 15:01:06 +01:00
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.PluginCommand;
|
|
|
|
import org.bukkit.command.TabCompleter;
|
2018-12-16 02:47:42 +01:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2017-06-22 18:14:19 +02:00
|
|
|
import org.bukkit.entity.*;
|
2016-06-12 19:43:41 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2017-06-22 18:14:19 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.lang.reflect.Field;
|
2018-08-06 11:48:19 +02:00
|
|
|
import java.lang.reflect.Modifier;
|
2017-06-22 18:14:19 +02:00
|
|
|
import java.util.ArrayList;
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public class LibsDisguises extends JavaPlugin {
|
2016-06-12 19:43:41 +02:00
|
|
|
private static LibsDisguises instance;
|
|
|
|
private DisguiseListener listener;
|
2018-12-16 02:47:42 +01:00
|
|
|
private String buildNumber;
|
2016-06-12 19:43:41 +02:00
|
|
|
|
|
|
|
@Override
|
2016-11-25 13:07:02 +01:00
|
|
|
public void onEnable() {
|
2016-11-30 18:38:43 +01:00
|
|
|
instance = this;
|
2017-07-10 18:02:24 +02:00
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
if (!new File(getDataFolder(), "disguises.yml").exists()) {
|
|
|
|
saveResource("disguises.yml", false);
|
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
YamlConfiguration pluginYml = ReflectionManager.getPluginYaml(getClassLoader());
|
|
|
|
buildNumber = StringUtils.stripToNull(pluginYml.getString("build-number"));
|
|
|
|
|
|
|
|
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
|
|
|
|
|
2018-12-16 05:19:59 +01:00
|
|
|
getLogger().info("Jenkins Build: " + (isNumberedBuild() ? "#" : "") + getBuildNo());
|
2018-12-16 02:47:42 +01:00
|
|
|
|
2019-02-16 04:57:07 +01:00
|
|
|
getLogger().info("Build Date: " + pluginYml.getString("build-date"));
|
|
|
|
|
2019-06-29 03:38:20 +02:00
|
|
|
LibsPremium.check(getDescription().getVersion(), getFile());
|
2017-07-10 18:02:24 +02:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
if (!LibsPremium.isPremium()) {
|
2019-12-21 22:15:52 +01:00
|
|
|
getLogger()
|
|
|
|
.info("You are running the free version, commands limited to non-players and operators. (Console," +
|
|
|
|
" Command " + "Blocks, Admins)");
|
2019-05-18 08:54:51 +02:00
|
|
|
}
|
|
|
|
|
2019-12-14 01:10:11 +01:00
|
|
|
if (!ReflectionManager.getMinecraftVersion().startsWith("1.15")) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " +
|
2019-11-03 06:07:12 +01:00
|
|
|
"intended for 1.14.4!");
|
2018-08-14 07:20:48 +02:00
|
|
|
getPluginLoader().disablePlugin(this);
|
2018-08-12 05:35:06 +02:00
|
|
|
return;
|
2018-08-05 10:34:02 +02:00
|
|
|
}
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
PacketsManager.init(this);
|
|
|
|
DisguiseUtilities.init(this);
|
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
registerValues();
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
DisguiseConfig.loadConfig();
|
2016-06-12 19:43:41 +02:00
|
|
|
|
|
|
|
PacketsManager.addPacketListeners();
|
|
|
|
|
|
|
|
listener = new DisguiseListener(this);
|
|
|
|
|
|
|
|
Bukkit.getPluginManager().registerEvents(listener, this);
|
|
|
|
|
2018-11-08 09:04:18 +01:00
|
|
|
if (!DisguiseConfig.isDisableCommands()) {
|
|
|
|
registerCommand("disguise", new DisguiseCommand());
|
|
|
|
registerCommand("undisguise", new UndisguiseCommand());
|
|
|
|
registerCommand("disguiseplayer", new DisguisePlayerCommand());
|
|
|
|
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
|
|
|
|
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
|
|
|
|
registerCommand("disguiseentity", new DisguiseEntityCommand());
|
|
|
|
registerCommand("disguiseradius", new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
|
|
|
registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
|
|
|
|
registerCommand("disguisehelp", new DisguiseHelpCommand());
|
|
|
|
registerCommand("disguiseclone", new DisguiseCloneCommand());
|
|
|
|
registerCommand("libsdisguises", new LibsDisguisesCommand());
|
|
|
|
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
|
|
|
|
registerCommand("disguisemodify", new DisguiseModifyCommand());
|
|
|
|
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
|
|
|
|
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
|
|
|
|
registerCommand("disguisemodifyradius",
|
|
|
|
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
2018-12-19 03:10:15 +01:00
|
|
|
} else {
|
|
|
|
getLogger().info("Commands has been disabled, as per config");
|
2018-11-08 09:04:18 +01:00
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
new MetricsInitalizer();
|
2017-06-22 18:14:19 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
DisguiseUtilities.saveDisguises();
|
|
|
|
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
DisguiseUtilities.removeSelfDisguiseScoreboard(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isReleaseBuild() {
|
|
|
|
return !getDescription().getVersion().contains("-SNAPSHOT");
|
|
|
|
}
|
2018-08-24 00:01:01 +02:00
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
public String getBuildNo() {
|
|
|
|
return buildNumber;
|
2017-06-02 15:51:03 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 05:19:59 +01:00
|
|
|
public boolean isNumberedBuild() {
|
|
|
|
return getBuildNo() != null && getBuildNo().matches("[0-9]+");
|
|
|
|
}
|
|
|
|
|
2016-11-28 15:01:06 +01:00
|
|
|
private void registerCommand(String commandName, CommandExecutor executioner) {
|
|
|
|
PluginCommand command = getCommand(commandName);
|
|
|
|
|
|
|
|
command.setExecutor(executioner);
|
|
|
|
|
|
|
|
if (executioner instanceof TabCompleter) {
|
|
|
|
command.setTabCompleter((TabCompleter) executioner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
/**
|
|
|
|
* Reloads the config with new config options.
|
|
|
|
*/
|
2018-08-24 00:01:01 +02:00
|
|
|
@Deprecated
|
2016-11-25 13:07:02 +01:00
|
|
|
public void reload() {
|
2018-08-24 00:01:01 +02:00
|
|
|
DisguiseConfig.loadConfig();
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-22 22:37:56 +01:00
|
|
|
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their
|
|
|
|
* sound volume
|
2016-06-12 19:43:41 +02:00
|
|
|
* for mob noises. As well as setting their watcher class and entity size.
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
private void registerValues() {
|
|
|
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
|
|
|
if (disguiseType.getEntityType() == null) {
|
2016-06-12 19:43:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-08 17:06:58 +02:00
|
|
|
Class watcherClass;
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
try {
|
|
|
|
switch (disguiseType) {
|
2018-08-06 11:48:19 +02:00
|
|
|
case ARROW:
|
|
|
|
watcherClass = TippedArrowWatcher.class;
|
|
|
|
break;
|
|
|
|
case COD:
|
|
|
|
case SALMON:
|
|
|
|
watcherClass = FishWatcher.class;
|
|
|
|
break;
|
2017-04-15 06:22:17 +02:00
|
|
|
case SPECTRAL_ARROW:
|
|
|
|
watcherClass = ArrowWatcher.class;
|
|
|
|
break;
|
|
|
|
case PRIMED_TNT:
|
|
|
|
watcherClass = TNTWatcher.class;
|
|
|
|
break;
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
watcherClass = MinecartWatcher.class;
|
|
|
|
break;
|
|
|
|
case SPIDER:
|
|
|
|
case CAVE_SPIDER:
|
|
|
|
watcherClass = SpiderWatcher.class;
|
|
|
|
break;
|
|
|
|
case PIG_ZOMBIE:
|
|
|
|
case HUSK:
|
2018-08-06 11:48:19 +02:00
|
|
|
case DROWNED:
|
2017-04-15 06:22:17 +02:00
|
|
|
watcherClass = ZombieWatcher.class;
|
|
|
|
break;
|
|
|
|
case MAGMA_CUBE:
|
|
|
|
watcherClass = SlimeWatcher.class;
|
|
|
|
break;
|
|
|
|
case ELDER_GUARDIAN:
|
|
|
|
watcherClass = GuardianWatcher.class;
|
|
|
|
break;
|
|
|
|
case WITHER_SKELETON:
|
|
|
|
case STRAY:
|
|
|
|
watcherClass = SkeletonWatcher.class;
|
|
|
|
break;
|
2017-06-08 17:06:58 +02:00
|
|
|
case ILLUSIONER:
|
|
|
|
case EVOKER:
|
|
|
|
watcherClass = IllagerWizardWatcher.class;
|
|
|
|
break;
|
2018-08-06 11:48:19 +02:00
|
|
|
case PUFFERFISH:
|
|
|
|
watcherClass = PufferFishWatcher.class;
|
|
|
|
break;
|
2017-04-15 06:22:17 +02:00
|
|
|
default:
|
2017-12-22 22:37:56 +01:00
|
|
|
watcherClass = Class.forName(
|
|
|
|
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) +
|
|
|
|
"Watcher");
|
2017-04-15 06:22:17 +02:00
|
|
|
break;
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
catch (ClassNotFoundException ex) {
|
2016-06-12 19:43:41 +02:00
|
|
|
// There is no explicit watcher for this entity.
|
|
|
|
Class entityClass = disguiseType.getEntityType().getEntityClass();
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (entityClass != null) {
|
|
|
|
if (Tameable.class.isAssignableFrom(entityClass)) {
|
2016-06-12 19:43:41 +02:00
|
|
|
watcherClass = TameableWatcher.class;
|
2017-04-15 06:22:17 +02:00
|
|
|
} else if (Ageable.class.isAssignableFrom(entityClass)) {
|
2016-06-12 19:43:41 +02:00
|
|
|
watcherClass = AgeableWatcher.class;
|
2017-04-15 06:22:17 +02:00
|
|
|
} else if (Creature.class.isAssignableFrom(entityClass)) {
|
2016-06-12 19:43:41 +02:00
|
|
|
watcherClass = InsentientWatcher.class;
|
2017-04-15 06:22:17 +02:00
|
|
|
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
2016-06-12 19:43:41 +02:00
|
|
|
watcherClass = LivingWatcher.class;
|
2018-08-06 11:48:19 +02:00
|
|
|
} else if (Fish.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = FishWatcher.class;
|
2017-04-15 06:22:17 +02:00
|
|
|
} else {
|
2016-06-12 19:43:41 +02:00
|
|
|
watcherClass = FlagWatcher.class;
|
|
|
|
}
|
2017-04-15 06:22:17 +02:00
|
|
|
} else {
|
2016-06-12 19:43:41 +02:00
|
|
|
watcherClass = FlagWatcher.class; // Disguise is unknown type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (watcherClass == null) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
|
2016-06-12 19:43:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-29 03:38:20 +02:00
|
|
|
// Invalidate invalid distribution
|
2019-12-21 22:15:52 +01:00
|
|
|
if (LibsPremium.isPremium() &&
|
2019-12-22 06:15:55 +01:00
|
|
|
((LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isPremium() &&
|
|
|
|
!LibsPremium.getPaidInformation().isLegit()) ||
|
2019-12-21 22:15:52 +01:00
|
|
|
(LibsPremium.getPluginInformation() != null &&
|
2019-12-22 06:15:55 +01:00
|
|
|
LibsPremium.getPluginInformation().isPremium() &&
|
2019-12-22 00:30:44 +01:00
|
|
|
!LibsPremium.getPluginInformation().isLegit()))) {
|
2019-06-29 03:38:20 +02:00
|
|
|
throw new IllegalStateException(
|
|
|
|
"Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " +
|
|
|
|
"reporting this error!");
|
|
|
|
}
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
disguiseType.setWatcherClass(watcherClass);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
|
2016-06-12 19:43:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String nmsEntityName = toReadable(disguiseType.name());
|
2018-08-06 11:48:19 +02:00
|
|
|
Class nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2018-08-06 11:48:19 +02:00
|
|
|
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
|
|
|
|
String[] split = splitReadable(disguiseType.name());
|
|
|
|
ArrayUtils.reverse(split);
|
|
|
|
|
|
|
|
nmsEntityName = StringUtils.join(split);
|
|
|
|
nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
|
|
|
|
|
|
|
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
|
|
|
|
nmsEntityName = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nmsEntityName == null) {
|
|
|
|
switch (disguiseType) {
|
|
|
|
case DONKEY:
|
|
|
|
nmsEntityName = "HorseDonkey";
|
|
|
|
break;
|
|
|
|
case ARROW:
|
|
|
|
nmsEntityName = "TippedArrow";
|
|
|
|
break;
|
|
|
|
case DROPPED_ITEM:
|
|
|
|
nmsEntityName = "Item";
|
|
|
|
break;
|
|
|
|
case FIREBALL:
|
|
|
|
nmsEntityName = "LargeFireball";
|
|
|
|
break;
|
|
|
|
case FIREWORK:
|
|
|
|
nmsEntityName = "Fireworks";
|
|
|
|
break;
|
|
|
|
case GIANT:
|
|
|
|
nmsEntityName = "GiantZombie";
|
|
|
|
break;
|
|
|
|
case HUSK:
|
|
|
|
nmsEntityName = "ZombieHusk";
|
|
|
|
break;
|
|
|
|
case ILLUSIONER:
|
|
|
|
nmsEntityName = "IllagerIllusioner";
|
|
|
|
break;
|
|
|
|
case LEASH_HITCH:
|
|
|
|
nmsEntityName = "Leash";
|
|
|
|
break;
|
|
|
|
case MINECART:
|
|
|
|
nmsEntityName = "MinecartRideable";
|
|
|
|
break;
|
|
|
|
case MINECART_COMMAND:
|
|
|
|
nmsEntityName = "MinecartCommandBlock";
|
|
|
|
break;
|
|
|
|
case MINECART_TNT:
|
|
|
|
nmsEntityName = "MinecartTNT";
|
|
|
|
break;
|
|
|
|
case MULE:
|
|
|
|
nmsEntityName = "HorseMule";
|
|
|
|
break;
|
|
|
|
case PRIMED_TNT:
|
|
|
|
nmsEntityName = "TNTPrimed";
|
|
|
|
break;
|
|
|
|
case PUFFERFISH:
|
|
|
|
nmsEntityName = "PufferFish";
|
|
|
|
break;
|
|
|
|
case SPLASH_POTION:
|
|
|
|
nmsEntityName = "Potion";
|
|
|
|
break;
|
|
|
|
case STRAY:
|
|
|
|
nmsEntityName = "SkeletonStray";
|
|
|
|
break;
|
|
|
|
case TRIDENT:
|
|
|
|
nmsEntityName = "ThrownTrident";
|
|
|
|
break;
|
2019-05-18 08:54:51 +02:00
|
|
|
case WANDERING_TRADER:
|
|
|
|
nmsEntityName = "VillagerTrader";
|
|
|
|
break;
|
|
|
|
case TRADER_LLAMA:
|
|
|
|
nmsEntityName = "LLamaTrader"; // Interesting capitalization
|
|
|
|
break;
|
2018-08-06 11:48:19 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
try {
|
2018-08-06 11:48:19 +02:00
|
|
|
if (disguiseType == DisguiseType.UNKNOWN) {
|
2016-06-12 19:43:41 +02:00
|
|
|
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
|
|
|
|
|
|
|
|
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
|
|
|
|
|
|
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (sound != null) {
|
2016-06-12 19:43:41 +02:00
|
|
|
sound.setDamageAndIdleSoundVolume(1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:48:19 +02:00
|
|
|
if (nmsEntityName == null) {
|
|
|
|
getLogger().warning("Entity name not found! (" + disguiseType.name() + ")");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, nmsEntityName);
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (nmsEntity == null) {
|
2016-06-12 19:43:41 +02:00
|
|
|
getLogger().warning("Entity not found! (" + nmsEntityName + ")");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
disguiseType.setTypeId(ReflectionManager.getEntityTypeId(disguiseType.getEntityType()));
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
2018-08-06 11:48:19 +02:00
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
int entitySize = 0;
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
|
|
|
if (field.getType().getName().equals("EnumEntitySize")) {
|
2016-06-12 19:43:41 +02:00
|
|
|
Enum enumEntitySize = (Enum) field.get(nmsEntity);
|
|
|
|
|
|
|
|
entitySize = enumEntitySize.ordinal();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
|
|
|
|
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
|
|
|
|
|
|
|
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
2018-09-13 08:56:46 +02:00
|
|
|
ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass());
|
2018-08-29 03:05:29 +02:00
|
|
|
boolean loggedName = false;
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
|
2018-09-13 08:56:46 +02:00
|
|
|
MetaIndex flagType = MetaIndex.getMetaIndex(watcherClass, watch.getIndex());
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (flagType == null) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
|
|
|
|
getLogger().severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() +
|
|
|
|
") (" + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName());
|
2016-06-12 19:43:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-11-26 16:36:57 +01:00
|
|
|
|
2017-06-08 23:14:36 +02:00
|
|
|
indexes.remove(flagType);
|
|
|
|
|
2018-08-05 10:34:02 +02:00
|
|
|
Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault());
|
|
|
|
Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getValue());
|
2017-07-10 18:02:24 +02:00
|
|
|
|
2018-08-29 03:05:29 +02:00
|
|
|
if (ourValue.getClass() != nmsValue.getClass()) {
|
|
|
|
if (!loggedName) {
|
|
|
|
getLogger().severe(StringUtils.repeat("=", 20));
|
|
|
|
getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " +
|
|
|
|
nmsEntityName);
|
|
|
|
loggedName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLogger().severe(StringUtils.repeat("-", 20));
|
|
|
|
getLogger().severe("Index: " + watch.getIndex() + " | " +
|
|
|
|
flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType));
|
|
|
|
Object flagDefault = flagType.getDefault();
|
|
|
|
|
|
|
|
getLogger().severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")");
|
|
|
|
getLogger().severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")");
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() +
|
|
|
|
")");
|
2018-08-29 03:05:29 +02:00
|
|
|
getLogger().severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")");
|
|
|
|
getLogger().severe(StringUtils.repeat("-", 20));
|
2016-11-26 16:36:57 +01:00
|
|
|
}
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
|
2017-06-08 23:14:36 +02:00
|
|
|
for (MetaIndex index : indexes) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().warning(
|
|
|
|
disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() +
|
|
|
|
" at index " + index.getIndex());
|
2017-06-08 23:14:36 +02:00
|
|
|
}
|
|
|
|
|
2016-06-12 19:43:41 +02:00
|
|
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (sound != null) {
|
2016-06-12 19:43:41 +02:00
|
|
|
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (soundStrength != null) {
|
2016-06-12 19:43:41 +02:00
|
|
|
sound.setDamageAndIdleSoundVolume(soundStrength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the bounding box
|
|
|
|
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
if (bukkitEntity instanceof Ageable) {
|
2016-06-12 19:43:41 +02:00
|
|
|
((Ageable) bukkitEntity).setBaby();
|
|
|
|
|
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
2017-04-15 06:22:17 +02:00
|
|
|
} else if (bukkitEntity instanceof Zombie) {
|
2016-06-12 19:43:41 +02:00
|
|
|
((Zombie) bukkitEntity).setBaby(true);
|
|
|
|
|
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
//disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
2016-11-25 13:07:02 +01:00
|
|
|
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
|
|
|
|
getLogger().severe("Before reporting this error, " +
|
2017-12-22 22:37:56 +01:00
|
|
|
"please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
|
2018-08-14 02:42:35 +02:00
|
|
|
getLogger().severe("Development builds are available at (ProtocolLib) " +
|
|
|
|
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" +
|
|
|
|
".net/job/LibsDisguises/");
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2016-06-18 17:16:32 +02:00
|
|
|
ex.printStackTrace();
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:48:19 +02:00
|
|
|
private String[] splitReadable(String string) {
|
|
|
|
String[] split = string.split("_");
|
2016-06-12 19:43:41 +02:00
|
|
|
|
2018-08-06 11:48:19 +02:00
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
|
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 11:48:19 +02:00
|
|
|
return split;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String toReadable(String string) {
|
|
|
|
return StringUtils.join(splitReadable(string));
|
2016-06-12 19:43:41 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 13:07:02 +01:00
|
|
|
public DisguiseListener getListener() {
|
2016-06-12 19:43:41 +02:00
|
|
|
return listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
|
|
|
|
*
|
|
|
|
* @return The instance of this plugin
|
|
|
|
*/
|
2016-11-25 13:07:02 +01:00
|
|
|
public static LibsDisguises getInstance() {
|
2016-06-12 19:43:41 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|