2013-05-17 23:05:19 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2013-08-05 14:04:01 +02:00
|
|
|
import java.io.File;
|
2013-10-01 12:51:21 +02:00
|
|
|
import java.io.IOException;
|
2013-07-29 01:21:25 +02:00
|
|
|
import java.lang.reflect.Field;
|
2013-07-22 15:32:05 +02:00
|
|
|
import java.lang.reflect.Method;
|
2013-05-17 23:05:19 +02:00
|
|
|
import java.util.List;
|
2013-09-25 16:49:24 +02:00
|
|
|
|
|
|
|
import me.libraryaddict.disguise.commands.*;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseSound;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.Values;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
2013-09-20 05:59:28 +02:00
|
|
|
import net.minecraft.server.v1_6_R3.ChatMessage;
|
|
|
|
import net.minecraft.server.v1_6_R3.ChunkCoordinates;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityHuman;
|
|
|
|
import net.minecraft.server.v1_6_R3.EntityLiving;
|
|
|
|
import net.minecraft.server.v1_6_R3.GenericAttributes;
|
|
|
|
import net.minecraft.server.v1_6_R3.WatchableObject;
|
|
|
|
import net.minecraft.server.v1_6_R3.World;
|
2013-05-29 16:25:00 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2013-11-05 16:33:40 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2013-10-01 12:51:21 +02:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
2013-08-05 14:04:01 +02:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2013-09-20 05:59:28 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
|
2013-07-28 01:00:29 +02:00
|
|
|
import org.bukkit.entity.Ageable;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2013-05-17 23:05:19 +02:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2013-07-21 05:14:59 +02:00
|
|
|
public class LibsDisguises extends JavaPlugin {
|
2013-07-11 20:38:07 +02:00
|
|
|
private class DisguiseHuman extends EntityHuman {
|
|
|
|
|
|
|
|
public DisguiseHuman(World world) {
|
|
|
|
super(world, "LibsDisguises");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(int arg0, String arg1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ChunkCoordinates b() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendMessage(ChatMessage arg0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-21 05:14:59 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2013-11-05 16:33:40 +01:00
|
|
|
// Simple codes to make sure a few certain people don't run this on their server -.-
|
2013-11-05 17:35:59 +01:00
|
|
|
for (String s : new String[] { "enayet123", "shazz96", "PimpMyCreeper", "DemandedLogic", "LinearLogic", "FileDotJar",
|
|
|
|
"ExoticGhost", "gizzy14gazza", "C43DR", "ExportB", "OverlordKiller", "Scribbles21", "Queen_Cerii" }) {
|
2013-11-05 16:33:40 +01:00
|
|
|
OfflinePlayer offline = Bukkit.getOfflinePlayer(s);
|
|
|
|
if (offline.isOp())
|
|
|
|
return;
|
|
|
|
}
|
2013-11-05 17:35:59 +01:00
|
|
|
if (Bukkit.getMotd().toLowerCase().contains("archergames")) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-31 07:46:24 +02:00
|
|
|
saveDefaultConfig();
|
2013-10-01 12:51:21 +02:00
|
|
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml"));
|
|
|
|
try {
|
|
|
|
for (String option : YamlConfiguration
|
|
|
|
.loadConfiguration(this.getClassLoader().getResource("config.yml").openStream()).getKeys(false)) {
|
|
|
|
if (!config.contains(option)) {
|
|
|
|
config.set(option, getConfig().get(option));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
config.save(new File(getDataFolder(), "config.yml"));
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
PacketsManager.init(this);
|
|
|
|
DisguiseAPI.setSoundsEnabled(getConfig().getBoolean("DisguiseSounds"));
|
2013-07-31 07:46:24 +02:00
|
|
|
DisguiseAPI.setVelocitySent(getConfig().getBoolean("SendVelocity"));
|
2013-11-05 18:01:52 +01:00
|
|
|
DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewSelfDisguises"));
|
2013-07-31 07:46:24 +02:00
|
|
|
DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise"));
|
2013-10-18 01:53:56 +02:00
|
|
|
DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor"));
|
|
|
|
DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem"));
|
2013-10-01 12:51:21 +02:00
|
|
|
if (DisguiseAPI.isHidingArmorFromSelf() || DisguiseAPI.isHidingHeldItemFromSelf()) {
|
|
|
|
DisguiseAPI.setInventoryListenerEnabled(true);
|
|
|
|
}
|
2013-07-29 01:21:25 +02:00
|
|
|
try {
|
|
|
|
// Here I use reflection to set the plugin for Disguise..
|
|
|
|
// Kinda stupid but I don't want open API calls.
|
|
|
|
Field field = Disguise.class.getDeclaredField("plugin");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(null, this);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
PacketsManager.addPacketListeners(this);
|
2013-07-16 07:23:11 +02:00
|
|
|
DisguiseListener listener = new DisguiseListener(this);
|
|
|
|
Bukkit.getPluginManager().registerEvents(listener, this);
|
2013-05-21 04:23:58 +02:00
|
|
|
getCommand("disguise").setExecutor(new DisguiseCommand());
|
|
|
|
getCommand("undisguise").setExecutor(new UndisguiseCommand());
|
2013-05-29 00:44:55 +02:00
|
|
|
getCommand("disguiseplayer").setExecutor(new DisguisePlayerCommand());
|
|
|
|
getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
|
2013-07-16 07:23:11 +02:00
|
|
|
getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand(listener));
|
|
|
|
getCommand("disguiseentity").setExecutor(new DisguiseEntityCommand(listener));
|
2013-07-16 08:53:39 +02:00
|
|
|
getCommand("disguiseradius").setExecutor(new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
|
|
|
|
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
|
2013-11-05 16:16:46 +01:00
|
|
|
getCommand("disguisehelp").setExecutor(new DisguiseHelpCommand());
|
2013-07-11 20:38:07 +02:00
|
|
|
registerValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void registerValues() {
|
|
|
|
World world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
|
|
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
2013-07-28 01:00:29 +02:00
|
|
|
Class watcherClass = null;
|
|
|
|
try {
|
|
|
|
String name;
|
|
|
|
switch (disguiseType) {
|
|
|
|
case MINECART_FURNACE:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
case MINECART_CHEST:
|
|
|
|
name = "Minecart";
|
|
|
|
break;
|
|
|
|
case DONKEY:
|
|
|
|
case MULE:
|
|
|
|
case UNDEAD_HORSE:
|
|
|
|
case SKELETON_HORSE:
|
|
|
|
name = "Horse";
|
|
|
|
break;
|
|
|
|
case ZOMBIE_VILLAGER:
|
|
|
|
case PIG_ZOMBIE:
|
|
|
|
name = "Zombie";
|
|
|
|
break;
|
|
|
|
case MAGMA_CUBE:
|
|
|
|
name = "Slime";
|
2013-08-05 14:08:53 +02:00
|
|
|
break;
|
2013-07-28 01:00:29 +02:00
|
|
|
default:
|
|
|
|
name = toReadable(disguiseType.name());
|
|
|
|
break;
|
|
|
|
}
|
2013-10-01 12:51:21 +02:00
|
|
|
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + name + "Watcher");
|
2013-07-28 01:00:29 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
// There is no watcher for this entity, or a error was thrown.
|
|
|
|
try {
|
|
|
|
Class c = disguiseType.getEntityType().getEntityClass();
|
2013-09-17 23:30:58 +02:00
|
|
|
if (Ageable.class.isAssignableFrom(c)) {
|
2013-07-28 01:00:29 +02:00
|
|
|
watcherClass = AgeableWatcher.class;
|
2013-09-17 23:30:58 +02:00
|
|
|
} else if (LivingEntity.class.isAssignableFrom(c)) {
|
2013-07-28 01:00:29 +02:00
|
|
|
watcherClass = LivingWatcher.class;
|
2013-09-17 23:30:58 +02:00
|
|
|
} else {
|
2013-07-28 01:00:29 +02:00
|
|
|
watcherClass = FlagWatcher.class;
|
2013-09-17 23:30:58 +02:00
|
|
|
}
|
2013-07-28 01:00:29 +02:00
|
|
|
} catch (Exception ex1) {
|
|
|
|
ex1.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
disguiseType.setWatcherClass(watcherClass);
|
2013-07-11 20:38:07 +02:00
|
|
|
String name = toReadable(disguiseType.name());
|
2013-07-28 01:00:29 +02:00
|
|
|
switch (disguiseType) {
|
|
|
|
case WITHER_SKELETON:
|
|
|
|
case ZOMBIE_VILLAGER:
|
|
|
|
case DONKEY:
|
|
|
|
case MULE:
|
|
|
|
case UNDEAD_HORSE:
|
|
|
|
case SKELETON_HORSE:
|
2013-08-05 14:21:47 +02:00
|
|
|
continue;
|
2013-07-28 01:00:29 +02:00
|
|
|
case PRIMED_TNT:
|
2013-07-11 20:38:07 +02:00
|
|
|
name = "TNTPrimed";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case MINECART_TNT:
|
2013-07-11 20:38:07 +02:00
|
|
|
name = "MinecartTNT";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case MINECART:
|
2013-07-16 13:42:35 +02:00
|
|
|
name = "MinecartRideable";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case FIREWORK:
|
2013-07-16 13:42:35 +02:00
|
|
|
name = "Fireworks";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case SPLASH_POTION:
|
2013-07-11 20:38:07 +02:00
|
|
|
name = "Potion";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case GIANT:
|
2013-07-11 20:38:07 +02:00
|
|
|
name = "GiantZombie";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case DROPPED_ITEM:
|
2013-07-11 20:38:07 +02:00
|
|
|
name = "Item";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
case FIREBALL:
|
2013-07-11 20:38:07 +02:00
|
|
|
name = "LargeFireball";
|
2013-07-28 01:00:29 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-07-11 20:38:07 +02:00
|
|
|
try {
|
2013-09-20 05:59:28 +02:00
|
|
|
net.minecraft.server.v1_6_R3.Entity entity = null;
|
2013-07-15 09:33:23 +02:00
|
|
|
Class entityClass;
|
2013-07-11 20:38:07 +02:00
|
|
|
if (disguiseType == DisguiseType.PLAYER) {
|
2013-07-15 09:33:23 +02:00
|
|
|
entityClass = EntityHuman.class;
|
2013-07-11 20:38:07 +02:00
|
|
|
entity = new DisguiseHuman(world);
|
|
|
|
} else {
|
2013-09-20 05:59:28 +02:00
|
|
|
entityClass = Class.forName("net.minecraft.server.v1_6_R3.Entity" + name);
|
|
|
|
entity = (net.minecraft.server.v1_6_R3.Entity) entityClass.getConstructor(World.class).newInstance(world);
|
2013-07-11 20:38:07 +02:00
|
|
|
}
|
2013-08-05 07:26:56 +02:00
|
|
|
Values value = new Values(disguiseType, entityClass, entity.at);
|
2013-07-11 20:38:07 +02:00
|
|
|
List<WatchableObject> watchers = entity.getDataWatcher().c();
|
|
|
|
for (WatchableObject watch : watchers)
|
|
|
|
value.setMetaValue(watch.a(), watch.b());
|
|
|
|
if (entity instanceof EntityLiving) {
|
|
|
|
EntityLiving livingEntity = (EntityLiving) entity;
|
2013-07-12 22:19:24 +02:00
|
|
|
value.setAttributesValue(GenericAttributes.d.a(), livingEntity.getAttributeInstance(GenericAttributes.d)
|
2013-07-11 20:38:07 +02:00
|
|
|
.getValue());
|
|
|
|
}
|
2013-07-22 15:32:05 +02:00
|
|
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
|
|
|
if (sound != null) {
|
2013-09-20 12:15:39 +02:00
|
|
|
Method soundStrength = EntityLiving.class.getDeclaredMethod("ba");
|
2013-07-22 15:32:05 +02:00
|
|
|
soundStrength.setAccessible(true);
|
|
|
|
sound.setDamageSoundVolume((Float) soundStrength.invoke(entity));
|
|
|
|
}
|
2013-07-11 20:38:07 +02:00
|
|
|
} catch (Exception e1) {
|
|
|
|
System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + e1.getMessage());
|
|
|
|
System.out.print("[LibsDisguises] Please report this to LibsDisguises author");
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
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("_")) {
|
|
|
|
builder.append(s.substring(0, 1) + s.substring(1).toLowerCase());
|
|
|
|
}
|
|
|
|
return builder.toString();
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
2013-08-01 10:29:04 +02:00
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|