2013-05-17 23:05:19 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2015-07-07 17:30:12 +02:00
|
|
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
2016-02-19 20:23:46 +01:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
2016-03-05 05:45:38 +01:00
|
|
|
import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
|
2016-02-19 20:23:46 +01:00
|
|
|
import me.libraryaddict.disguise.commands.DisguiseCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.DisguiseViewSelf;
|
2016-03-05 05:45:38 +01:00
|
|
|
import me.libraryaddict.disguise.commands.EntityDisguiseCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.HelpDisguiseCommand;
|
2016-02-19 20:23:46 +01:00
|
|
|
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
|
2016-03-05 05:45:38 +01:00
|
|
|
import me.libraryaddict.disguise.commands.PlayerDisguiseCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.RadiusDisguiseCommand;
|
2016-02-19 20:23:46 +01:00
|
|
|
import me.libraryaddict.disguise.commands.UndisguiseCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
|
|
|
|
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
|
2013-09-25 16:49:24 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
2014-09-27 02:18:54 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
|
2013-11-22 20:22:06 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
2013-09-25 16:49:24 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
2013-11-22 20:22:06 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
|
2016-03-07 04:46:46 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
|
2013-11-22 20:22:06 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
|
2014-05-23 06:40:22 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
|
2013-11-22 20:22:06 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
2013-11-22 21:10:20 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseSound;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
2016-02-19 20:23:46 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseValues;
|
|
|
|
import me.libraryaddict.disguise.utilities.FakeBoundingBox;
|
|
|
|
import me.libraryaddict.disguise.utilities.Metrics;
|
2013-11-22 21:10:20 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.PacketsManager;
|
|
|
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
2013-05-29 16:25:00 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2013-07-28 01:00:29 +02:00
|
|
|
import org.bukkit.entity.Ageable;
|
2014-05-23 04:52:21 +02:00
|
|
|
import org.bukkit.entity.Damageable;
|
2013-11-18 04:24:25 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
2013-07-28 01:00:29 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2014-05-23 06:40:22 +02:00
|
|
|
import org.bukkit.entity.Tameable;
|
2013-12-22 00:36:06 +01:00
|
|
|
import org.bukkit.entity.Zombie;
|
2016-02-19 20:23:46 +01:00
|
|
|
import org.bukkit.event.HandlerList;
|
2013-05-17 23:05:19 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2016-02-19 20:23:46 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.reflect.Field;
|
2013-07-11 20:38:07 +02:00
|
|
|
|
2013-11-18 04:24:25 +01:00
|
|
|
public class LibsDisguises extends JavaPlugin {
|
2015-08-03 00:39:44 +02:00
|
|
|
|
2016-02-19 20:23:46 +01:00
|
|
|
private static LibsDisguises instance;
|
2015-03-30 04:47:29 +02:00
|
|
|
private DisguiseListener listener;
|
2013-07-11 20:38:07 +02:00
|
|
|
|
2013-07-21 05:14:59 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2016-03-05 03:02:39 +01:00
|
|
|
getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
|
2013-07-31 07:46:24 +02:00
|
|
|
saveDefaultConfig();
|
2014-05-30 19:29:40 +02:00
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
PacketsManager.init(this);
|
2013-11-22 21:04:31 +01:00
|
|
|
DisguiseUtilities.init(this);
|
2014-06-04 02:42:13 +02:00
|
|
|
DisguiseConfig.initConfig(getConfig());
|
|
|
|
|
2014-05-22 22:14:46 +02:00
|
|
|
PacketsManager.addPacketListeners();
|
2015-03-30 04:47:29 +02:00
|
|
|
listener = new DisguiseListener(this);
|
2013-07-16 07:23:11 +02:00
|
|
|
Bukkit.getPluginManager().registerEvents(listener, this);
|
2013-05-21 04:23:58 +02:00
|
|
|
getCommand("disguise").setExecutor(new DisguiseCommand());
|
|
|
|
getCommand("undisguise").setExecutor(new UndisguiseCommand());
|
2016-03-05 05:45:38 +01:00
|
|
|
getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
|
2013-05-29 00:44:55 +02:00
|
|
|
getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
|
2015-03-30 04:47:29 +02:00
|
|
|
getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand());
|
2016-03-05 05:45:38 +01:00
|
|
|
getCommand("disguiseentity").setExecutor(new EntityDisguiseCommand());
|
|
|
|
getCommand("disguiseradius").setExecutor(new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax")));
|
2013-07-16 08:53:39 +02:00
|
|
|
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
|
2016-03-05 05:45:38 +01:00
|
|
|
getCommand("disguisehelp").setExecutor(new HelpDisguiseCommand());
|
|
|
|
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
|
2014-04-06 14:15:47 +02:00
|
|
|
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
|
2015-07-15 11:51:38 +02:00
|
|
|
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
|
2013-07-11 20:38:07 +02:00
|
|
|
registerValues();
|
2015-03-29 00:59:42 +01:00
|
|
|
instance = this;
|
2015-03-26 00:23:16 +01:00
|
|
|
try {
|
|
|
|
Metrics metrics = new Metrics(this);
|
|
|
|
metrics.start();
|
2015-08-03 00:39:44 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
2013-07-11 20:38:07 +02:00
|
|
|
}
|
2015-08-03 00:39:44 +02:00
|
|
|
|
2015-03-30 04:47:29 +02:00
|
|
|
/**
|
|
|
|
* Reloads the config with new config options.
|
|
|
|
*/
|
|
|
|
public void reload() {
|
|
|
|
HandlerList.unregisterAll(listener);
|
|
|
|
reloadConfig();
|
2015-08-03 00:39:44 +02:00
|
|
|
DisguiseConfig.initConfig(getConfig());
|
2014-06-04 02:46:52 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 21:04:31 +01:00
|
|
|
/**
|
2015-08-03 00:39:44 +02:00
|
|
|
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume for mob noises. As well as setting their watcher class and entity size.
|
2013-11-22 21:04:31 +01:00
|
|
|
*/
|
2013-07-11 20:38:07 +02:00
|
|
|
private void registerValues() {
|
|
|
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
2015-03-10 01:28:41 +01:00
|
|
|
if (disguiseType.getEntityType() == null) {
|
2014-06-10 02:42:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-10 06:44:11 +01:00
|
|
|
Class watcherClass = null;
|
2013-07-28 01:00:29 +02:00
|
|
|
try {
|
|
|
|
switch (disguiseType) {
|
2016-03-10 06:44:11 +01:00
|
|
|
case ITEM_FRAME: //Not really supported...
|
|
|
|
break;
|
2015-08-03 00:39:44 +02:00
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_COMMAND:
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
watcherClass = MinecartWatcher.class;
|
|
|
|
break;
|
|
|
|
case DONKEY:
|
|
|
|
case MULE:
|
|
|
|
case UNDEAD_HORSE:
|
|
|
|
case SKELETON_HORSE:
|
|
|
|
watcherClass = HorseWatcher.class;
|
|
|
|
break;
|
|
|
|
case ZOMBIE_VILLAGER:
|
|
|
|
case PIG_ZOMBIE:
|
|
|
|
watcherClass = ZombieWatcher.class;
|
|
|
|
break;
|
|
|
|
case MAGMA_CUBE:
|
|
|
|
watcherClass = SlimeWatcher.class;
|
|
|
|
break;
|
|
|
|
case ELDER_GUARDIAN:
|
|
|
|
watcherClass = GuardianWatcher.class;
|
|
|
|
break;
|
|
|
|
case ENDERMITE:
|
|
|
|
watcherClass = LivingWatcher.class;
|
|
|
|
break;
|
2016-03-07 04:46:46 +01:00
|
|
|
case WITHER_SKELETON:
|
|
|
|
watcherClass = SkeletonWatcher.class;
|
|
|
|
break;
|
2015-08-03 00:39:44 +02:00
|
|
|
default:
|
|
|
|
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
|
|
|
|
+ toReadable(disguiseType.name()) + "Watcher");
|
|
|
|
break;
|
2013-07-28 01:00:29 +02:00
|
|
|
}
|
2013-11-22 20:22:06 +01:00
|
|
|
} catch (ClassNotFoundException ex) {
|
2013-11-22 20:52:15 +01:00
|
|
|
// There is no explicit watcher for this entity.
|
|
|
|
Class entityClass = disguiseType.getEntityType().getEntityClass();
|
2015-07-07 17:30:12 +02:00
|
|
|
if (entityClass != null) {
|
|
|
|
if (Tameable.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = TameableWatcher.class;
|
|
|
|
} else if (Ageable.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = AgeableWatcher.class;
|
|
|
|
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = LivingWatcher.class;
|
|
|
|
} else {
|
|
|
|
watcherClass = FlagWatcher.class;
|
|
|
|
}
|
2013-11-22 15:15:07 +01:00
|
|
|
} else {
|
2015-07-07 17:30:12 +02:00
|
|
|
watcherClass = FlagWatcher.class; //Disguise is unknown type
|
2013-07-28 01:00:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
disguiseType.setWatcherClass(watcherClass);
|
2014-09-27 02:18:54 +02:00
|
|
|
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-22 21:04:31 +01:00
|
|
|
String nmsEntityName = toReadable(disguiseType.name());
|
2013-07-28 01:00:29 +02:00
|
|
|
switch (disguiseType) {
|
2015-08-03 00:39:44 +02:00
|
|
|
case WITHER_SKELETON:
|
|
|
|
case ZOMBIE_VILLAGER:
|
|
|
|
case DONKEY:
|
|
|
|
case MULE:
|
|
|
|
case UNDEAD_HORSE:
|
|
|
|
case SKELETON_HORSE:
|
|
|
|
continue;
|
|
|
|
case PRIMED_TNT:
|
|
|
|
nmsEntityName = "TNTPrimed";
|
|
|
|
break;
|
|
|
|
case MINECART_TNT:
|
|
|
|
nmsEntityName = "MinecartTNT";
|
|
|
|
break;
|
|
|
|
case MINECART:
|
|
|
|
nmsEntityName = "MinecartRideable";
|
|
|
|
break;
|
|
|
|
case FIREWORK:
|
|
|
|
nmsEntityName = "Fireworks";
|
|
|
|
break;
|
|
|
|
case SPLASH_POTION:
|
|
|
|
nmsEntityName = "Potion";
|
|
|
|
break;
|
|
|
|
case GIANT:
|
|
|
|
nmsEntityName = "GiantZombie";
|
|
|
|
break;
|
|
|
|
case DROPPED_ITEM:
|
|
|
|
nmsEntityName = "Item";
|
|
|
|
break;
|
|
|
|
case FIREBALL:
|
|
|
|
nmsEntityName = "LargeFireball";
|
|
|
|
break;
|
|
|
|
case LEASH_HITCH:
|
|
|
|
nmsEntityName = "Leash";
|
|
|
|
break;
|
|
|
|
case ELDER_GUARDIAN:
|
|
|
|
nmsEntityName = "Guardian";
|
|
|
|
break;
|
2016-03-10 06:44:11 +01:00
|
|
|
case ARROW:
|
|
|
|
nmsEntityName = "TippedArrow";
|
2015-08-03 00:39:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
2013-07-28 01:00:29 +02:00
|
|
|
}
|
2013-07-11 20:38:07 +02:00
|
|
|
try {
|
2015-07-07 17:30:12 +02:00
|
|
|
if (nmsEntityName.equalsIgnoreCase("Unknown")) {
|
|
|
|
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
|
|
|
|
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
|
|
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
|
|
|
if (sound != null) {
|
|
|
|
sound.setDamageAndIdleSoundVolume(1f);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-22 21:04:31 +01:00
|
|
|
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
2013-11-27 04:54:38 +01:00
|
|
|
if (nmsEntity == null) {
|
2016-03-05 03:02:39 +01:00
|
|
|
getLogger().warning("Entity not found! (" + nmsEntityName + ")");
|
2013-11-27 04:54:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-27 04:38:51 +01:00
|
|
|
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
2013-11-22 21:04:31 +01:00
|
|
|
int entitySize = 0;
|
2013-11-18 04:24:25 +01:00
|
|
|
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
|
|
|
if (field.getType().getName().equals("EnumEntitySize")) {
|
2013-11-22 21:04:31 +01:00
|
|
|
Enum enumEntitySize = (Enum) field.get(nmsEntity);
|
|
|
|
entitySize = enumEntitySize.ordinal();
|
2013-11-18 04:24:25 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-07-11 20:38:07 +02:00
|
|
|
}
|
2014-05-23 04:52:21 +02:00
|
|
|
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
|
|
|
|
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
2016-03-05 03:02:39 +01:00
|
|
|
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
|
|
|
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
|
2013-11-22 20:52:15 +01:00
|
|
|
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
|
2013-12-14 05:01:25 +01:00
|
|
|
// Uncomment when I need to find the new datawatcher values for a class..
|
2016-03-06 05:14:19 +01:00
|
|
|
int id = watch.getIndex();
|
|
|
|
Object val = watch.getValue();
|
|
|
|
Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
|
|
|
|
try {
|
|
|
|
val = val.toString();
|
|
|
|
} catch (Exception e) {
|
|
|
|
val = val != null ? val.getClass() : "null";
|
|
|
|
}
|
|
|
|
System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" : valClazz) + ", Value: " + val);
|
2013-12-14 05:01:25 +01:00
|
|
|
}
|
2013-07-22 15:32:05 +02:00
|
|
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
|
|
|
if (sound != null) {
|
2013-11-22 21:04:31 +01:00
|
|
|
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
2013-11-18 04:24:25 +01:00
|
|
|
if (soundStrength != null) {
|
2015-07-07 17:30:12 +02:00
|
|
|
sound.setDamageAndIdleSoundVolume(soundStrength);
|
2013-11-18 04:24:25 +01:00
|
|
|
}
|
2013-07-22 15:32:05 +02:00
|
|
|
}
|
2013-12-22 00:36:06 +01:00
|
|
|
|
|
|
|
// Get the bounding box
|
|
|
|
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
if (bukkitEntity instanceof Ageable) {
|
|
|
|
((Ageable) bukkitEntity).setBaby();
|
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
} else if (bukkitEntity instanceof Zombie) {
|
|
|
|
((Zombie) bukkitEntity).setBaby(true);
|
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
}
|
2013-12-22 05:35:57 +01:00
|
|
|
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
|
2015-07-07 17:30:12 +02:00
|
|
|
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
|
2013-12-16 20:11:30 +01:00
|
|
|
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name()
|
|
|
|
+ "!");
|
|
|
|
System.out.print("[LibsDisguises] Before reporting this error, "
|
2014-06-24 03:31:22 +02:00
|
|
|
+ "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
|
2016-03-05 03:02:39 +01:00
|
|
|
System.out
|
|
|
|
.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
|
|
|
|
+ "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
|
2014-06-24 03:31:22 +02:00
|
|
|
|
2015-03-30 04:47:29 +02:00
|
|
|
ex.printStackTrace(System.out);
|
2013-07-11 20:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-31 10:55:55 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 20:38:38 +02:00
|
|
|
private String toReadable(String string) {
|
2013-07-28 01:00:29 +02:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
for (String s : string.split("_")) {
|
2014-06-04 03:18:43 +02:00
|
|
|
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
|
2013-07-28 01:00:29 +02:00
|
|
|
}
|
|
|
|
return builder.toString();
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
2013-08-01 10:29:04 +02:00
|
|
|
|
2015-03-30 04:47:29 +02:00
|
|
|
public DisguiseListener getListener() {
|
|
|
|
return listener;
|
2014-06-04 02:53:00 +02:00
|
|
|
}
|
2016-02-19 20:23:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* External APIs shouldn't actually need this instance.
|
|
|
|
* DisguiseAPI should be enough to handle most cases.
|
2016-03-05 03:02:39 +01:00
|
|
|
*
|
2016-02-19 20:23:46 +01:00
|
|
|
* @return The instance of this plugin
|
|
|
|
*/
|
|
|
|
public static LibsDisguises getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
2013-11-14 06:36:53 +01:00
|
|
|
}
|