Revert "Revert "Test Commit""

This reverts commit fed5641931.
This commit is contained in:
Andrew
2013-10-04 21:21:24 +13:00
parent a5a7f5ab5f
commit 782f4b9bc0
47 changed files with 505 additions and 113 deletions

View File

@@ -0,0 +1,348 @@
package me.libraryaddict.disguise;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent;
import net.minecraft.server.v1_6_R3.AttributeMapServer;
import net.minecraft.server.v1_6_R3.EntityHuman;
import net.minecraft.server.v1_6_R3.EntityInsentient;
import net.minecraft.server.v1_6_R3.EntityLiving;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
import net.minecraft.server.v1_6_R3.ItemStack;
import net.minecraft.server.v1_6_R3.MobEffect;
import net.minecraft.server.v1_6_R3.Packet17EntityLocationAction;
import net.minecraft.server.v1_6_R3.Packet20NamedEntitySpawn;
import net.minecraft.server.v1_6_R3.Packet28EntityVelocity;
import net.minecraft.server.v1_6_R3.Packet35EntityHeadRotation;
import net.minecraft.server.v1_6_R3.Packet39AttachEntity;
import net.minecraft.server.v1_6_R3.Packet40EntityMetadata;
import net.minecraft.server.v1_6_R3.Packet41MobEffect;
import net.minecraft.server.v1_6_R3.Packet44UpdateAttributes;
import net.minecraft.server.v1_6_R3.Packet5EntityEquipment;
import net.minecraft.server.v1_6_R3.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
public class DisguiseAPI {
// Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
private static HashMap<Integer, Disguise> disguises = new HashMap<Integer, Disguise>();
private static boolean hearSelfDisguise;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
private static LibsDisguises libsDisguises;
// A internal storage of fake entity ID's I can use.
// Realistically I could probably use a ID like "4" for everyone seeing as no one shares the ID
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
private static boolean sendVelocity;
public static boolean canHearSelfDisguise() {
return hearSelfDisguise;
}
public static void setInventoryListenerEnabled(boolean inventoryListenerEnabled) {
if (PacketsManager.isInventoryListenerEnabled() != inventoryListenerEnabled) {
PacketsManager.setInventoryListenerEnabled(inventoryListenerEnabled);
}
}
public static boolean isInventoryListenerEnabled() {
return PacketsManager.isInventoryListenerEnabled();
}
/**
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
*/
public static void disguiseNextEntity(Disguise disguise) {
if (disguise == null)
return;
if (disguise.getEntity() != null || disguises.containsValue(disguise)) {
disguise = disguise.clone();
}
try {
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
field.setAccessible(true);
int id = field.getInt(null);
disguises.put(id, disguise);
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Disguise this entity with this disguise
*/
public static void disguiseToAll(Entity entity, Disguise disguise) {
// If they are trying to disguise a null entity or use a null disguise
// Just return.
if (entity == null || disguise == null)
return;
// Fire a disguise event
DisguiseEvent event = new DisguiseEvent(entity, disguise);
Bukkit.getPluginManager().callEvent(event);
// If they cancelled this disguise event. No idea why.
// Just return.
if (event.isCancelled())
return;
// The event wasn't cancelled.
// If the disguise entity isn't the same as the one we are disguising
if (disguise.getEntity() != entity) {
// If the disguise entity actually exists
if (disguise.getEntity() != null) {
// Clone the disguise
disguise = disguise.clone();
}
// Set the disguise's entity
disguise.setEntity(entity);
} // If there was a old disguise
Disguise oldDisguise = getDisguise(entity);
// Stick the disguise in the disguises bin
disguises.put(entity.getEntityId(), disguise);
// Resend the disguised entity's packet
refreshTrackers(entity);
// If he is a player, then self disguise himself
setupPlayerFakeDisguise(disguise);
// Discard the disguise
if (oldDisguise != null)
oldDisguise.removeDisguise();
}
/**
* Get the disguise of a entity
*/
public static Disguise getDisguise(Entity disguiser) {
if (disguiser == null)
return null;
if (disguises.containsKey(disguiser.getEntityId()))
return disguises.get(disguiser.getEntityId());
return null;
}
/**
* Get the ID of a fake disguise for a entityplayer
*/
public static int getFakeDisguise(int id) {
if (selfDisguisesIds.containsKey(id))
return selfDisguisesIds.get(id);
return -1;
}
protected static void init(LibsDisguises mainPlugin) {
libsDisguises = mainPlugin;
}
/**
* Is this entity disguised
*/
public static boolean isDisguised(Entity disguiser) {
return getDisguise(disguiser) != null;
}
/**
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
*/
public static boolean isHidingArmorFromSelf() {
return hidingArmor;
}
/**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
*/
public static boolean isHidingHeldItemFromSelf() {
return hidingHeldItem;
}
/**
* Is the sound packets caught and modified
*/
public static boolean isSoundEnabled() {
return PacketsManager.isHearDisguisesEnabled();
}
/**
* Is the velocity packets sent
*/
public static boolean isVelocitySent() {
return sendVelocity;
}
/**
* The default value if a player views his own disguise
*/
public static boolean isViewDisguises() {
return PacketsManager.isViewDisguisesListenerEnabled();
}
/**
* @param Resends
* the entity to all the watching players, which is where the magic begins
*/
private static void refreshTrackers(Entity entity) {
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
.get(entity.getEntityId());
if (entry != null) {
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
for (EntityPlayer player : players) {
if (entity instanceof Player && !player.getBukkitEntity().canSee((Player) entity))
continue;
entry.clear(player);
entry.updatePlayer(player);
}
}
}
private static void removeSelfDisguise(Player player) {
if (selfDisguisesIds.containsKey(player.getEntityId())) {
// Send a packet to destroy the fake entity
PacketContainer packet = new PacketContainer(Packets.Server.DESTROY_ENTITY);
packet.getModifier().write(0, new int[] { selfDisguisesIds.get(player.getEntityId()) });
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} catch (Exception ex) {
ex.printStackTrace();
}
// Remove the fake entity ID from the disguise bin
selfDisguisesIds.remove(player.getEntityId());
// Get the entity tracker
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities
.get(player.getEntityId());
// If the tracker exists. Remove himself from his tracker
if (tracker != null) {
tracker.trackedPlayers.remove(entityplayer);
}
// Resend entity metadata else he will be invisible to himself until its resent
PacketContainer packetMetadata = new PacketContainer(Packets.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packetMetadata.getModifier();
mods.write(0, player.getEntityId());
mods.write(1, entityplayer.getDataWatcher().c());
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
} catch (Exception ex) {
ex.printStackTrace();
}
// TODO Restore their currently held item
// TODO Restore their armor
}
}
/**
* Can players hear their own disguises
*/
public static void setHearSelfDisguise(boolean replaceSound) {
if (hearSelfDisguise != replaceSound) {
hearSelfDisguise = replaceSound;
}
}
/**
* Set the plugin to hide self disguises armor from theirselves
*/
public static void setHideArmorFromSelf(boolean hideArmor) {
if (hidingArmor != hideArmor) {
hidingArmor = hideArmor;
}
}
/**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
*/
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
if (hidingHeldItem != hideHelditem) {
hidingHeldItem = hideHelditem;
}
}
/**
* Set if the disguises play sounds when hurt
*/
public static void setSoundsEnabled(boolean isSoundsEnabled) {
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
}
/**
* Setup it so he can see himself when disguised
*/
private static void setupPlayerFakeDisguise(final Disguise disguise) {
// If the disguises entity is null, or the disguised entity isn't a player return
if (disguise.getEntity() == null || !(disguise.getEntity() instanceof Player) || !disguises.containsValue(disguise))
return;
Player player = (Player) disguise.getEntity();
// Remove the old disguise, else we have weird disguises around the place
removeSelfDisguise(player);
// If the disguised player can't see himself. Return
if (!disguise.viewSelfDisguise())
return;
try {
// Grab the entity ID the fake disguise will use
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
field.setAccessible(true);
int id = field.getInt(null);
// Set the entitycount plus one so we don't have the id being reused
field.set(null, id + 1);
selfDisguisesIds.put(player.getEntityId(), id);
} catch (Exception ex) {
ex.printStackTrace();
}
PacketsManager.sendSelfDisguise(player);
}
/**
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
*/
public static void setVelocitySent(boolean sendVelocityPackets) {
sendVelocity = sendVelocityPackets;
}
public static void setViewDisguises(boolean seeOwnDisguise) {
PacketsManager.setViewDisguisesListener(seeOwnDisguise);
}
/**
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from
* the world.
*/
public static void undisguiseToAll(Entity entity) {
Disguise disguise = getDisguise(entity);
if (disguise == null)
return;
UndisguiseEvent event = new UndisguiseEvent(entity, disguise);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
disguise.removeDisguise();
}
public HashMap<Integer, Disguise> getDisguises() {
return disguises;
}
public void refreshWatchingPlayers(Entity entity) {
refreshTrackers(entity);
}
public void removeVisibleDisguise(Player player) {
removeSelfDisguise(player);
}
public void setupFakeDisguise(Disguise disguise) {
setupPlayerFakeDisguise(disguise);
}
}

View File

@@ -0,0 +1,105 @@
package me.libraryaddict.disguise;
import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class DisguiseListener implements Listener {
private String currentVersion;
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<String, BukkitRunnable>();
private HashMap<String, Disguise> disguiseSlap = new HashMap<String, Disguise>();
private String latestVersion;
private String permission;
private LibsDisguises plugin;
private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED
+ "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED
+ ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!";
public DisguiseListener(LibsDisguises libsDisguises) {
plugin = libsDisguises;
permission = plugin.getConfig().getString("Permission");
if (plugin.getConfig().getBoolean("NotifyUpdate")) {
currentVersion = plugin.getDescription().getVersion();
Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
public void run() {
try {
UpdateChecker updateChecker = new UpdateChecker();
updateChecker.checkUpdate("v" + currentVersion);
latestVersion = updateChecker.getLatestVersion();
if (latestVersion != null) {
latestVersion = "v" + latestVersion;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
for (Player p : Bukkit.getOnlinePlayers())
if (p.hasPermission(permission))
p.sendMessage(String.format(updateMessage, currentVersion, latestVersion));
}
});
}
} catch (Exception ex) {
System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage()));
}
}
}, 0, (20 * 60 * 60 * 6)); // Check every 6 hours
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
if (latestVersion != null && p.hasPermission(permission))
p.sendMessage(String.format(updateMessage, currentVersion, latestVersion));
}
@EventHandler
public void onRightClick(PlayerInteractEntityEvent event) {
if (disguiseSlap.containsKey(event.getPlayer().getName())) {
event.setCancelled(true);
Disguise disguise = disguiseSlap.remove(event.getPlayer().getName());
disguiseRunnable.remove(event.getPlayer().getName()).cancel();
String entityName = event.getRightClicked().getType().name().toLowerCase().replace("_", " ");
if (disguise != null) {
DisguiseAPI.disguiseToAll(event.getRightClicked(), disguise);
event.getPlayer().sendMessage(
ChatColor.RED + "Disguised the " + entityName + " as a "
+ disguise.getType().name().toLowerCase().replace("_", " ") + "!");
} else {
if (DisguiseAPI.isDisguised(event.getRightClicked())) {
DisguiseAPI.undisguiseToAll(event.getRightClicked());
event.getPlayer().sendMessage(ChatColor.RED + "Undisguised the " + entityName);
} else
event.getPlayer().sendMessage(ChatColor.RED + entityName + " isn't disguised!");
}
}
}
public void setSlap(final String player, Disguise disguise) {
if (disguiseSlap.containsKey(player)) {
disguiseSlap.remove(player);
disguiseRunnable.remove(player).cancel();
}
BukkitRunnable runnable = new BukkitRunnable() {
public void run() {
disguiseSlap.remove(player);
disguiseRunnable.remove(player);
}
};
runnable.runTaskLater(plugin, 20 * 10);
disguiseRunnable.put(player, runnable);
disguiseSlap.put(player, disguise);
}
}

View File

@@ -0,0 +1,231 @@
package me.libraryaddict.disguise;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
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;
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;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.LivingEntity;
import org.bukkit.plugin.java.JavaPlugin;
public class LibsDisguises extends JavaPlugin {
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) {
}
}
@Override
public void onEnable() {
saveDefaultConfig();
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();
}
PacketsManager.init(this);
DisguiseAPI.init(this);
DisguiseAPI.setSoundsEnabled(getConfig().getBoolean("DisguiseSounds"));
DisguiseAPI.setVelocitySent(getConfig().getBoolean("SendVelocity"));
DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewDisguises"));
DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise"));
DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor"));
DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem"));
if (DisguiseAPI.isHidingArmorFromSelf() || DisguiseAPI.isHidingHeldItemFromSelf()) {
DisguiseAPI.setInventoryListenerEnabled(true);
}
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();
}
PacketsManager.addPacketListeners(this);
DisguiseListener listener = new DisguiseListener(this);
Bukkit.getPluginManager().registerEvents(listener, this);
getCommand("disguise").setExecutor(new DisguiseCommand());
getCommand("undisguise").setExecutor(new UndisguiseCommand());
getCommand("disguiseplayer").setExecutor(new DisguisePlayerCommand());
getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand(listener));
getCommand("disguiseentity").setExecutor(new DisguiseEntityCommand(listener));
getCommand("disguiseradius").setExecutor(new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
registerValues();
}
private void registerValues() {
World world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
for (DisguiseType disguiseType : DisguiseType.values()) {
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";
break;
default:
name = toReadable(disguiseType.name());
break;
}
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." + name + "Watcher");
} catch (Exception ex) {
// There is no watcher for this entity, or a error was thrown.
try {
Class c = disguiseType.getEntityType().getEntityClass();
if (Ageable.class.isAssignableFrom(c)) {
watcherClass = AgeableWatcher.class;
} else if (LivingEntity.class.isAssignableFrom(c)) {
watcherClass = LivingWatcher.class;
} else {
watcherClass = FlagWatcher.class;
}
} catch (Exception ex1) {
ex1.printStackTrace();
}
}
disguiseType.setWatcherClass(watcherClass);
String name = toReadable(disguiseType.name());
switch (disguiseType) {
case WITHER_SKELETON:
case ZOMBIE_VILLAGER:
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
continue;
case PRIMED_TNT:
name = "TNTPrimed";
break;
case MINECART_TNT:
name = "MinecartTNT";
break;
case MINECART:
name = "MinecartRideable";
break;
case FIREWORK:
name = "Fireworks";
break;
case SPLASH_POTION:
name = "Potion";
break;
case GIANT:
name = "GiantZombie";
break;
case DROPPED_ITEM:
name = "Item";
break;
case FIREBALL:
name = "LargeFireball";
break;
default:
break;
}
try {
net.minecraft.server.v1_6_R3.Entity entity = null;
Class entityClass;
if (disguiseType == DisguiseType.PLAYER) {
entityClass = EntityHuman.class;
entity = new DisguiseHuman(world);
} else {
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);
}
Values value = new Values(disguiseType, entityClass, entity.at);
List<WatchableObject> watchers = entity.getDataWatcher().c();
for (WatchableObject watch : watchers)
value.setMetaValue(watch.a(), watch.b());
if (entity instanceof EntityLiving) {
EntityLiving livingEntity = (EntityLiving) entity;
value.setAttributesValue(GenericAttributes.d.a(), livingEntity.getAttributeInstance(GenericAttributes.d)
.getValue());
}
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null) {
Method soundStrength = EntityLiving.class.getDeclaredMethod("ba");
soundStrength.setAccessible(true);
sound.setDamageSoundVolume((Float) soundStrength.invoke(entity));
}
} 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();
}
}
}
private String toReadable(String string) {
StringBuilder builder = new StringBuilder();
for (String s : string.split("_")) {
builder.append(s.substring(0, 1) + s.substring(1).toLowerCase());
}
return builder.toString();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
package me.libraryaddict.disguise;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Pattern;
public class UpdateChecker {
private String latestVersion;
private boolean checkHigher(String currentVersion, String newVersion) {
String current = toReadable(currentVersion);
String newVers = toReadable(newVersion);
return current.compareTo(newVers) < 0;
}
public void checkUpdate(String currentVersion) throws Exception {
String version = getVersion("98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4", 81);
if (checkHigher(currentVersion, version))
latestVersion = version;
}
public String getLatestVersion() {
return latestVersion;
}
private String getVersion(String key, int resourceId) {
String version = null;
try {
HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream().write(("key=" + key + "&resource=" + resourceId).getBytes("UTF-8"));
version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return version;
}
public String toReadable(String version) {
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
version = "";
for (String s : split)
version += String.format("%4s", s);
return version;
}
}

View File

@@ -0,0 +1,175 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import java.util.Collections;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DisguiseCommand implements CommandExecutor {
private ArrayList<String> allowedDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (sender.hasPermission("libsdisguises.disguise.*") || sender.hasPermission("libsdisguises.disguise." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private ArrayList<String> forbiddenDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
if (sender.hasPermission("libsdisguises.disguise.*"))
return names;
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (!sender.hasPermission("libsdisguises.disguise." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private boolean isNumeric(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
// What disguises can he use
ArrayList<String> allowedDisguises = allowedDisguises(sender);
// If he owns at least one disguise
if (allowedDisguises.size() > 0) {
// Get his forbidden disguises (Disguises he can't use) for later use
ArrayList<String> forbiddenDisguises = forbiddenDisguises(sender);
// If he is attempting to do something
if (args.length > 0) {
// If he owns the disguise
if (allowedDisguises.contains(args[0].toLowerCase())) {
Disguise disguise = null;
// Time to start constructing the disguise.
// We will need to check between all 3 kinds of disguises
if (args[0].equalsIgnoreCase("player")) {// If he is doing a player disguise
if (args.length == 1) {
// He needs to give the player name
sender.sendMessage(ChatColor.RED + "Error! You need to give a player name!");
return true;
} else {
// Construct the player disguise
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
}
} else {
// Grab the disguise type so we know what constructor to use
DisguiseType disguiseType = DisguiseType.valueOf(args[0].toUpperCase());
if (disguiseType.isMob()) { // Its a mob, use the mob constructor
boolean adult = true;
if (args.length > 1) {
// Seems they want to make this a baby disguise!
if (!args[1].equalsIgnoreCase("false") && !args[1].equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[1] + ChatColor.RED
+ " isn't true or false!");
return true;
}
adult = args[1].equalsIgnoreCase("false"); // Adult = !arg
}
disguise = new MobDisguise(disguiseType, adult);
} else if (disguiseType.isMisc()) {
// Its a misc, we are going to use the MiscDisguise constructor.
int miscId = -1;
int miscData = -1;
if (args.length > 1) {
// They have defined more arguements!
// If the first arg is a number
if (isNumeric(args[1])) {
miscId = Integer.parseInt(args[1]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[1] + ChatColor.RED
+ " is not a number!");
return true;
}
// If they also defined a data value
if (args.length > 2) {
if (isNumeric(args[1])) {
miscData = Integer.parseInt(args[2]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[2] + ChatColor.RED
+ " is not a number!");
return true;
}
}
}
// Construct the disguise
disguise = new MiscDisguise(disguiseType, true, miscId, miscData);
}
}
// Alright. We've constructed our disguise.
// Time to use it!
DisguiseAPI.disguiseToAll((Player) sender, disguise);
sender.sendMessage(ChatColor.RED + "Successfully disguised as a " + toReadable(disguise.getType().name())
+ "!");
} else {
// He doesn't. Either tell him its incorrect or he isn't allowed to use it
if (forbiddenDisguises.contains(args[0].toLowerCase())) {
// He isn't allowed to use it..
sender.sendMessage(ChatColor.RED + "You are forbidden to use this disguise!");
} else {
sender.sendMessage(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0] + ChatColor.RED
+ " doesn't exist!");
}
}
} else {
// Just send the disguises information.
sendDisguises(sender, allowedDisguises, forbiddenDisguises);
}
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
/**
* Send the player the information
*/
private void sendDisguises(CommandSender sender, ArrayList<String> allowedDisguises, ArrayList<String> forbiddenDisguises) {
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>");
}
private String toReadable(String name) {
String[] split = name.split("_");
for (int i = 0; i < split.length; i++)
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
return StringUtils.join(split, " ");
}
}

View File

@@ -0,0 +1,181 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import java.util.Collections;
import me.libraryaddict.disguise.DisguiseListener;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class DisguiseEntityCommand implements CommandExecutor {
private DisguiseListener listener;
public DisguiseEntityCommand(DisguiseListener listener) {
this.listener = listener;
}
private ArrayList<String> allowedDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (sender.hasPermission("libsdisguises.disguiseentity.*")
|| sender.hasPermission("libsdisguises.disguiseentity." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private ArrayList<String> forbiddenDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
if (sender.hasPermission("libsdisguises.disguiseentity.*"))
return names;
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (!sender.hasPermission("libsdisguises.disguiseentity." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private boolean isNumeric(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
// What disguises can he use
ArrayList<String> allowedDisguises = allowedDisguises(sender);
// If he owns at least one disguise
if (allowedDisguises.size() > 0) {
// Get his forbidden disguises (Disguises he can't use) for later use
ArrayList<String> forbiddenDisguises = forbiddenDisguises(sender);
// If he is attempting to do something
if (args.length > 0) {
// If he owns the disguise
if (allowedDisguises.contains(args[0].toLowerCase())) {
Disguise disguise = null;
// Time to start constructing the disguise.
// We will need to check between all 3 kinds of disguises
if (args[0].equalsIgnoreCase("player")) { // If he is doing a player disguise
if (args.length == 1) {
// He needs to give the player name
sender.sendMessage(ChatColor.RED + "Error! You need to give a player name!");
return true;
} else {
// Construct the player disguise
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
}
} else {
// Grab the disguise type so we know what constructor to use
DisguiseType disguiseType = DisguiseType.valueOf(args[0].toUpperCase());
if (disguiseType.isMob()) { // Its a mob, use the mob constructor
boolean adult = true;
if (args.length > 1) {
// Seems they want to make this a baby disguise!
if (!args[1].equalsIgnoreCase("false") && !args[1].equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[1] + ChatColor.RED
+ " isn't true or false!");
return true;
}
adult = args[1].equalsIgnoreCase("false"); // Adult = !arg
}
disguise = new MobDisguise(disguiseType, adult);
} else if (disguiseType.isMisc()) {
// Its a misc, we are going to use the MiscDisguise constructor.
int miscId = -1;
int miscData = -1;
if (args.length > 1) {
// They have defined more arguements!
// If the first arg is a number
if (isNumeric(args[1])) {
miscId = Integer.parseInt(args[1]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[1] + ChatColor.RED
+ " is not a number!");
return true;
}
// If they also defined a data value
if (args.length > 2) {
if (isNumeric(args[1])) {
miscData = Integer.parseInt(args[2]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[2] + ChatColor.RED
+ " is not a number!");
return true;
}
}
}
// Construct the disguise
disguise = new MiscDisguise(disguiseType, true, miscId, miscData);
}
}
// Alright. We've constructed our disguise.
// Time to use it!
listener.setSlap(sender.getName(), disguise);
sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a "
+ toReadable(disguise.getType().name()) + "!");
} else {
// He doesn't. Either tell him its incorrect or he isn't allowed to use it
if (forbiddenDisguises.contains(args[0].toLowerCase())) {
// He isn't allowed to use it..
sender.sendMessage(ChatColor.RED + "You are forbidden to use this disguise!");
} else {
sender.sendMessage(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0] + ChatColor.RED
+ " doesn't exist!");
}
}
} else {
// Just send the disguises information.
sendDisguises(sender, allowedDisguises, forbiddenDisguises);
}
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
/**
* Send the player the information
*/
private void sendDisguises(CommandSender sender, ArrayList<String> allowedDisguises, ArrayList<String> forbiddenDisguises) {
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then slap a entity to disguise it!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>");
}
private String toReadable(String name) {
String[] split = name.split("_");
for (int i = 0; i < split.length; i++)
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
return StringUtils.join(split, " ");
}
}

View File

@@ -0,0 +1,177 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import java.util.Collections;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DisguisePlayerCommand implements CommandExecutor {
private ArrayList<String> allowedDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (sender.hasPermission("libsdisguises.disguiseplayer.*")
|| sender.hasPermission("libsdisguises.disguiseplayer." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private ArrayList<String> forbiddenDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
if (sender.hasPermission("libsdisguises.disguiseplayer.*"))
return names;
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (!sender.hasPermission("libsdisguises.disguiseplayer." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private boolean isNumeric(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// What disguises can he use
ArrayList<String> allowedDisguises = allowedDisguises(sender);
// If he owns at least one disguise
if (allowedDisguises.size() > 0) {
// Get his forbidden disguises (Disguises he can't use) for later use
ArrayList<String> forbiddenDisguises = forbiddenDisguises(sender);
// If he is attempting to do something
if (args.length > 0) {// Better go check that the player exists.
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {// Player doesn't exist. Knew it!
sender.sendMessage(ChatColor.RED + "Error! Player " + ChatColor.GREEN + args[0] + ChatColor.RED
+ " doesn't exist!");
return true;
}
if (args.length > 1) {
// If he owns the disguise
if (allowedDisguises.contains(args[1].toLowerCase())) {
// He can use the disguise huh.
Disguise disguise = null;
// Time to start constructing the disguise.
// We will need to check between all 3 kinds of disguises
if (args[1].equalsIgnoreCase("player")) { // If he is doing a player disguise
// Did he give enough args?
if (args.length == 2) {
// He needs to give the player name
sender.sendMessage(ChatColor.RED + "Error! You need to give a player name!");
return true;
} else {
// Construct the player disguise
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[2]));
}
} else {
// Grab the disguise type so we know what constructor to use
DisguiseType disguiseType = DisguiseType.valueOf(args[1].toUpperCase());
if (disguiseType.isMob()) { // Its a mob, use the mob constructor
boolean adult = true;
if (args.length > 2) {
// Seems they want to make this a baby disguise!
if (!args[2].equalsIgnoreCase("false") && !args[2].equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[2] + ChatColor.RED
+ " isn't true or false!");
return true;
}
adult = args[2].equalsIgnoreCase("false"); // Adult = !arg
}
disguise = new MobDisguise(disguiseType, adult);
} else if (disguiseType.isMisc()) {
// Its a misc, we are going to use the MiscDisguise constructor.
int miscId = -1;
int miscData = -1;
if (args.length > 2) {
// They have defined more arguements!
// If the first arg is a number
if (isNumeric(args[2])) {
miscId = Integer.parseInt(args[2]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[2] + ChatColor.RED
+ " is not a number!");
return true;
}
// If they also defined a data value
if (args.length > 3) {
if (isNumeric(args[3])) {
miscData = Integer.parseInt(args[3]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[3]
+ ChatColor.RED + " is not a number!");
return true;
}
}
}
// Construct the disguise
disguise = new MiscDisguise(disguiseType, true, miscId, miscData);
}
}
// Alright. We've constructed our disguise.
// Time to use it!
DisguiseAPI.disguiseToAll(player, disguise);
sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + "!");
} else {
// He doesn't. Either tell him its incorrect or he isn't allowed to use it
if (forbiddenDisguises.contains(args[0].toLowerCase())) {
// He isn't allowed to use it..
sender.sendMessage(ChatColor.RED + "You are forbidden to use this disguise!");
} else {
sender.sendMessage(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[1] + ChatColor.RED
+ " doesn't exist!");
}
}
} else
sender.sendMessage(ChatColor.RED + "Error! You need to state a disguise!");
} else {
// Just send the disguises information.
sendDisguises(sender, allowedDisguises, forbiddenDisguises);
}
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
/**
* Send the player the information
*/
private void sendDisguises(CommandSender sender, ArrayList<String> allowedDisguises, ArrayList<String> forbiddenDisguises) {
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
sender.sendMessage(ChatColor.DARK_GREEN
+ "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}

View File

@@ -0,0 +1,196 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import java.util.Collections;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class DisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30;
public DisguiseRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
}
private ArrayList<String> allowedDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (sender.hasPermission("libsdisguises.disguiseradius.*")
|| sender.hasPermission("libsdisguises.disguiseradius." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private ArrayList<String> forbiddenDisguises(CommandSender sender) {
ArrayList<String> names = new ArrayList<String>();
if (sender.hasPermission("libsdisguises.disguiseradius.*"))
return names;
for (DisguiseType type : DisguiseType.values()) {
String name = type.name().toLowerCase();
if (!sender.hasPermission("libsdisguises.disguiseradius." + name))
names.add(name);
}
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
return names;
}
private boolean isNumeric(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
// What disguises can he use
ArrayList<String> allowedDisguises = allowedDisguises(sender);
// If he owns at least one disguise
if (allowedDisguises.size() > 0) {
// Get his forbidden disguises (Disguises he can't use) for later use
ArrayList<String> forbiddenDisguises = forbiddenDisguises(sender);
// If he is attempting to do something
if (args.length > 0) {// Better go check that its a proper radius
if (!isNumeric(args[0])) {// Radius doesn't exist. Knew it!
sender.sendMessage(ChatColor.RED + "Error! Radius " + ChatColor.GREEN + args[0] + ChatColor.RED
+ " isn't a number!");
return true;
}
if (args.length > 1) {
// If he owns the disguise
if (allowedDisguises.contains(args[1].toLowerCase())) {
// He can use the disguise huh.
int radius = Integer.parseInt(args[0]);
if (radius > maxRadius) {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius
+ "! Don't want to make too much lag right?");
radius = maxRadius;
}
Disguise disguise = null;
// Time to start constructing the disguise.
// We will need to check between all 3 kinds of disguises
if (args[1].equalsIgnoreCase("player")) { // If he is doing a player disguise
// Did he give enough args?
if (args.length == 2) {
// He needs to give the player name
sender.sendMessage(ChatColor.RED + "Error! You need to give a player name!");
return true;
} else {
// Construct the player disguise
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[2]));
}
} else {
// Grab the disguise type so we know what constructor to use
DisguiseType disguiseType = DisguiseType.valueOf(args[1].toUpperCase());
if (disguiseType.isMob()) { // Its a mob, use the mob constructor
boolean adult = true;
if (args.length > 2) {
// Seems they want to make this a baby disguise!
if (!args[2].equalsIgnoreCase("false") && !args[2].equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[2] + ChatColor.RED
+ " isn't true or false!");
return true;
}
adult = args[2].equalsIgnoreCase("false"); // Adult = !arg
}
disguise = new MobDisguise(disguiseType, adult);
} else if (disguiseType.isMisc()) {
// Its a misc, we are going to use the MiscDisguise constructor.
int miscId = -1;
int miscData = -1;
if (args.length > 2) {
// They have defined more arguements!
// If the first arg is a number
if (isNumeric(args[2])) {
miscId = Integer.parseInt(args[2]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[2] + ChatColor.RED
+ " is not a number!");
return true;
}
// If they also defined a data value
if (args.length > 3) {
if (isNumeric(args[3])) {
miscData = Integer.parseInt(args[3]);
} else {
// Send them a error
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[3]
+ ChatColor.RED + " is not a number!");
return true;
}
}
}
// Construct the disguise
disguise = new MiscDisguise(disguiseType, true, miscId, miscData);
}
}
// Alright. We've constructed our disguise.
// Time to use it!
int disguisedEntitys = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender)
continue;
DisguiseAPI.disguiseToAll(entity, disguise);
disguisedEntitys++;
}
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
} else {
// He doesn't. Either tell him its incorrect or he isn't allowed to use it
if (forbiddenDisguises.contains(args[0].toLowerCase())) {
// He isn't allowed to use it..
sender.sendMessage(ChatColor.RED + "You are forbidden to use this disguise!");
} else {
sender.sendMessage(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[1] + ChatColor.RED
+ " doesn't exist!");
}
}
} else
sender.sendMessage(ChatColor.RED + "Error! You need to state a disguise!");
} else {
// Just send the disguises information.
sendDisguises(sender, allowedDisguises, forbiddenDisguises);
}
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
/**
* Send the player the information
*/
private void sendDisguises(CommandSender sender, ArrayList<String> allowedDisguises, ArrayList<String> forbiddenDisguises) {
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseradius <Radius> player <Name>");
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseradius <Radius> <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseradius <Radius> <Dropped_Item/Falling_Block> <Id> <Durability>");
}
}

View File

@@ -0,0 +1,32 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class UndisguiseCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguise")) {
if (DisguiseAPI.isDisguised((Entity) sender)) {
DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(ChatColor.RED + "You are no longer disguised");
} else
sender.sendMessage(ChatColor.RED + "You are not disguised!");
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
}

View File

@@ -0,0 +1,31 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseListener;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class UndisguiseEntityCommand implements CommandExecutor {
private DisguiseListener listener;
public UndisguiseEntityCommand(DisguiseListener listener) {
this.listener = listener;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseentity")) {
listener.setSlap(sender.getName(), null);
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
}

View File

@@ -0,0 +1,35 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class UndisguisePlayerCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("libsdisguises.undisguiseplayer")) {
if (args.length > 0) {
Player p = Bukkit.getPlayer(args[0]);
if (p != null) {
if (DisguiseAPI.isDisguised(p)) {
DisguiseAPI.undisguiseToAll(p);
sender.sendMessage(ChatColor.RED + "He is no longer disguised");
} else
sender.sendMessage(ChatColor.RED + "He is not disguised!");
} else
sender.sendMessage(ChatColor.RED + "Player not found");
} else
sender.sendMessage(ChatColor.RED + "/undisguiseplayer <Name>");
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
}

View File

@@ -0,0 +1,65 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class UndisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30;
public UndisguiseRadiusCommand(int maxRadius) {
this.maxRadius = maxRadius;
}
private boolean isNumeric(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true;
}
if (sender.hasPermission("libsdisguises.undisguiseradius")) {
int radius = maxRadius;
if (args.length > 0) {
if (!isNumeric(args[0])) {
sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED
+ " is not a number!");
return true;
}
radius = Integer.parseInt(args[0]);
if (radius > maxRadius) {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius
+ "! Don't want to make too much lag right?");
radius = maxRadius;
}
}
int disguisedEntitys = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender)
continue;
if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity);
disguisedEntitys++;
}
}
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
} else
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command!");
return true;
}
}

View File

@@ -0,0 +1,16 @@
package me.libraryaddict.disguise.disguisetypes;
public enum AnimalColor {
BLACK(15), BLUE(11), BROWN(
12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(10), RED(14), SILVER(8), WHITE(0), YELLOW(4);
private int value;
private AnimalColor(int newValue) {
value = newValue;
}
public int getId() {
return value;
}
}

View File

@@ -0,0 +1,539 @@
package me.libraryaddict.disguise.disguisetypes;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.PacketsManager;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import net.minecraft.server.v1_6_R3.EntityAgeable;
import net.minecraft.server.v1_6_R3.EntityInsentient;
import net.minecraft.server.v1_6_R3.EntityLiving;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
import net.minecraft.server.v1_6_R3.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
public class Disguise {
/**
* Incase I forget, this is used to access normally hidden api calls.
*/
private static DisguiseAPI disguiseAPI = new DisguiseAPI();
private static JavaPlugin plugin;
private DisguiseType disguiseType;
private org.bukkit.entity.Entity entity;
private boolean hearSelfDisguise = DisguiseAPI.canHearSelfDisguise();
private boolean hideArmorFromSelf = DisguiseAPI.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseAPI.isHidingHeldItemFromSelf();
private boolean replaceSounds = DisguiseAPI.isSoundEnabled();
private BukkitRunnable runnable;
private boolean velocitySent = DisguiseAPI.isVelocitySent();
private boolean viewSelfDisguise = DisguiseAPI.isViewDisguises();
private FlagWatcher watcher;
public boolean canHearSelfDisguise() {
return hearSelfDisguise;
}
public Disguise clone() {
Disguise disguise = new Disguise().createDisguise(getType(), replaceSounds());
disguise.setViewSelfDisguise(viewSelfDisguise());
return disguise;
}
protected Disguise createDisguise(DisguiseType newType, boolean doSounds) {
if (getWatcher() != null)
return this;
// Set the disguise type
disguiseType = newType;
// Set the option to replace the sounds
setReplaceSounds(doSounds);
// Get if they are a adult now..
boolean isBaby = false;
if (this instanceof MobDisguise) {
if (!((MobDisguise) this).isAdult()) {
isBaby = true;
}
}
try {
// Construct the FlagWatcher from the stored class
setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this));
} catch (Exception e) {
e.printStackTrace();
}
// Set the disguise if its a baby or not
if (isBaby) {
if (getWatcher() instanceof AgeableWatcher) {
((AgeableWatcher) getWatcher()).setAdult(false);
} else if (getWatcher() instanceof ZombieWatcher) {
((ZombieWatcher) getWatcher()).setAdult(false);
}
}
// If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton
if (getType() == DisguiseType.WITHER_SKELETON)
getWatcher().setValue(13, (byte) 1);
// Else if its a zombie, but the disguise type is a zombie villager. Set the value.
else if (getType() == DisguiseType.ZOMBIE_VILLAGER)
getWatcher().setValue(13, (byte) 1);
// Else if its a horse. Set the horse watcher type
else if (getWatcher() instanceof HorseWatcher) {
try {
Variant horseType = Variant.valueOf(getType().name());
getWatcher().setValue(19, (byte) horseType.ordinal());
} catch (Exception ex) {
// Ok.. So it aint a horse
}
}
double fallSpeed = 0.0005;
boolean movement = false;
boolean alwaysSend = false;
switch (getType()) {
case EGG:
case ENDER_PEARL:
case BAT:
case EXPERIENCE_ORB:
case FIREBALL:
case SMALL_FIREBALL:
case SNOWBALL:
case SPLASH_POTION:
case THROWN_EXP_BOTTLE:
case WITHER_SKULL:
alwaysSend = true;
break;
default:
break;
}
switch (getType()) {
case FIREWORK:
fallSpeed = -0.040;
break;
case EGG:
case ENDER_PEARL:
case ENDER_SIGNAL:
case FIREBALL:
case SMALL_FIREBALL:
case SNOWBALL:
case SPLASH_POTION:
case THROWN_EXP_BOTTLE:
fallSpeed = 0.0005;
break;
case WITHER_SKULL:
fallSpeed = 0.000001D;
break;
case ARROW:
case BOAT:
case ENDER_CRYSTAL:
case ENDER_DRAGON:
case GHAST:
case ITEM_FRAME:
case MINECART:
case MINECART_CHEST:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
case PAINTING:
case PLAYER:
case SQUID:
fallSpeed = 0;
break;
case DROPPED_ITEM:
case MAGMA_CUBE:
case PRIMED_TNT:
fallSpeed = 0.2;
movement = true;
break;
case WITHER:
case FALLING_BLOCK:
fallSpeed = 0.04;
break;
case EXPERIENCE_ORB:
fallSpeed = 0.0221;
movement = true;
break;
case SPIDER:
case CAVE_SPIDER:
fallSpeed = 0.0040;
break;
default:
break;
}
final boolean sendMovementPacket = movement;
final double vectorY = fallSpeed;
final boolean alwaysSendVelocity = alwaysSend;
// A scheduler to clean up any unused disguises.
runnable = new BukkitRunnable() {
private int i = 0;
public void run() {
// If entity is no longer valid. Remove it.
if (!((CraftEntity) entity).getHandle().valid) {
DisguiseAPI.undisguiseToAll(entity);
} else {
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
if (getType() == DisguiseType.PRIMED_TNT) {
i++;
if (i % 40 == 0) {
i = 0;
List<Player> players = new ArrayList<Player>();
for (EntityPlayer p : getPerverts())
players.add(p.getBukkitEntity());
ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), players);
}
}
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
// If this disguise has velocity sending enabled and the entity is flying.
if (vectorY != 0 && isVelocitySent() && (alwaysSendVelocity || !entity.isOnGround())) {
Vector vector = entity.getVelocity();
// If the entity doesn't have velocity changes already
if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && entity.isOnGround())) {
return;
}
if (getType() != DisguiseType.EXPERIENCE_ORB || !entity.isOnGround()) {
PacketContainer lookPacket = null;
PacketContainer selfLookPacket = null;
if (getType() == DisguiseType.WITHER_SKULL) {
lookPacket = new PacketContainer(Packets.Server.ENTITY_LOOK);
StructureModifier<Object> mods = lookPacket.getModifier();
mods.write(0, entity.getEntityId());
Location loc = entity.getLocation();
mods.write(
4,
PacketsManager.getYaw(getType(), DisguiseType.getType(entity.getType()),
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
selfLookPacket = lookPacket.shallowClone();
}
for (EntityPlayer player : getPerverts()) {
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
StructureModifier<Object> mods = packet.getModifier();
if (entity == player.getBukkitEntity()) {
if (!viewSelfDisguise())
continue;
if (selfLookPacket != null) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
selfLookPacket, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
mods.write(0, DisguiseAPI.getFakeDisguise(entity.getEntityId()));
} else
mods.write(0, entity.getEntityId());
mods.write(1, (int) (vector.getX() * 8000));
mods.write(2, (int) (8000 * (vectorY * (double) player.ping * 0.069)));
mods.write(3, (int) (vector.getZ() * 8000));
try {
if (lookPacket != null)
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
lookPacket, false);
ProtocolLibrary.getProtocolManager()
.sendServerPacket(player.getBukkitEntity(), packet, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
// If we need to send more packets because else it still 'sinks'
if (sendMovementPacket) {
PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, entity.getEntityId());
for (EntityPlayer player : getPerverts()) {
if (DisguiseAPI.isViewDisguises() || entity != player) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
}
}
};
return this;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Disguise other = (Disguise) obj;
if (disguiseType != other.disguiseType)
return false;
if (hearSelfDisguise != other.hearSelfDisguise)
return false;
if (replaceSounds != other.replaceSounds)
return false;
if (velocitySent != other.velocitySent)
return false;
if (viewSelfDisguise != other.viewSelfDisguise)
return false;
if (!watcher.equals(other.watcher))
return false;
return true;
}
/**
* Get the disguised entity
*/
public org.bukkit.entity.Entity getEntity() {
return entity;
}
/**
* Get all EntityPlayers who have this entity in their Entity Tracker
*/
protected EntityPlayer[] getPerverts() {
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
.get(entity.getEntityId());
if (entry != null) {
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
return players;
}
return new EntityPlayer[0];
}
/**
* Get the disguise type
*/
public DisguiseType getType() {
return disguiseType;
}
/**
* Get the flag watcher
*/
public FlagWatcher getWatcher() {
return watcher;
}
public boolean isHidingArmorFromSelf() {
return hideArmorFromSelf;
}
public boolean isHidingHeldItemFromSelf() {
return hideHeldItemFromSelf;
}
public boolean isMiscDisguise() {
return this instanceof MiscDisguise;
}
public boolean isMobDisguise() {
return this instanceof MobDisguise;
}
public boolean isPlayerDisguise() {
return this instanceof PlayerDisguise;
}
public boolean isVelocitySent() {
return velocitySent;
}
/**
* Removes the disguise and undisguises the entity if its using this disguise. This doesn't fire a UndisguiseEvent
*/
public void removeDisguise() {
// Why the hell can't I safely check if its running?!?!
try {
runnable.cancel();
} catch (Exception ex) {
}
HashMap<Integer, Disguise> disguises = disguiseAPI.getDisguises();
// If this disguise has a entity set
if (getEntity() != null) {
// If the entity is valid
if (((CraftEntity) getEntity()).getHandle().valid) {
// If this disguise is active
if (disguises.containsKey(getEntity().getEntityId()) && disguises.get(getEntity().getEntityId()) == this) {
// Now remove the disguise from the current disguises.
disguises.remove(getEntity().getEntityId());
// Gotta do reflection, copy code or open up calls.
// Reflection is the cleanest?
if (getEntity() instanceof Player) {
disguiseAPI.removeVisibleDisguise((Player) entity);
}
// Better refresh the entity to undisguise it
disguiseAPI.refreshWatchingPlayers(getEntity());
}
}
} else {
// Loop through the disguises because it could be used with a unknown entity id.
Iterator<Integer> itel = disguises.keySet().iterator();
while (itel.hasNext()) {
int id = itel.next();
if (disguises.get(id) == this) {
itel.remove();
}
}
}
}
public boolean replaceSounds() {
return replaceSounds;
}
/**
* Set the entity of the disguise. Only used for internal things.
*/
public void setEntity(final org.bukkit.entity.Entity entity) {
if (this.entity != null)
throw new RuntimeException("This disguise is already in use! Try .clone()");
this.entity = entity;
setupWatcher();
runnable.runTaskTimer(plugin, 1, 1);
}
public void setHearSelfDisguise(boolean hearSelfDisguise) {
this.hearSelfDisguise = hearSelfDisguise;
}
public void setHideArmorFromSelf(boolean hideArmor) {
this.hideArmorFromSelf = hideArmor;
// TODO Update their armor if player
}
public void setHideHeldItemFromSelf(boolean hideHeldItem) {
this.hideHeldItemFromSelf = hideHeldItem;
// TODO Update their held item if player
}
public void setReplaceSounds(boolean areSoundsReplaced) {
replaceSounds = areSoundsReplaced;
}
/**
* Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the
* datawatcher.
*/
private void setupWatcher() {
Class disguiseClass = Values.getEntityClass(getType());
HashMap<Integer, Object> disguiseValues = Values.getMetaValues(getType());
HashMap<Integer, Object> entityValues = Values.getMetaValues(DisguiseType.getType(entity.getType()));
// Start from 2 as they ALL share 0 and 1
for (int dataNo = 2; dataNo <= 31; dataNo++) {
// If the watcher already set a metadata on this
if (getWatcher().getValue(dataNo, null) != null) {
// Better check that the value is stable.
if (disguiseValues.containsKey(dataNo)
&& getWatcher().getValue(dataNo, null).getClass() == disguiseValues.get(dataNo).getClass()) {
// The classes are the same. The client "shouldn't" crash.
continue;
}
}
// If neither of them touch it
if (!entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo))
continue;
// If the disguise has this, but not the entity. Then better set it!
if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) {
getWatcher().setValue(dataNo, disguiseValues.get(dataNo));
continue;
}
// Else if the disguise doesn't have it. But the entity does. Better remove it!
if (entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) {
getWatcher().setValue(dataNo, null);
continue;
}
// Since they both share it. Time to check if its from something they extend.
// Better make this clear before I compare the values because some default values are different!
// Entity is 0 & 1 - But we aint gonna be checking that
// EntityAgeable is 16
// EntityInsentient is 10 & 11
// EntityZombie is 12 & 13 & 14 - But it overrides other values and another check already does this.
// EntityLiving is 6 & 7 & 8 & 9
// Lets use switch
Class baseClass = null;
switch (dataNo) {
case 6:
case 7:
case 8:
case 9:
baseClass = EntityLiving.class;
break;
case 10:
case 11:
baseClass = EntityInsentient.class;
break;
case 16:
baseClass = EntityAgeable.class;
break;
default:
break;
}
Class entityClass = ((CraftEntity) entity).getHandle().getClass();
// If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..?
if (baseClass != null && baseClass.isAssignableFrom(disguiseClass) && baseClass.isAssignableFrom(entityClass))
continue;
// So they don't extend a basic class.
// Maybe if I check that they extend each other..
// Seeing as I only store the finished forms of entitys. This should raise no problems and allow for more shared
// datawatchers.
if (entityClass.isAssignableFrom(disguiseClass) || disguiseClass.isAssignableFrom(entityClass))
continue;
// Well I can't find a reason I should leave it alone. They will probably conflict.
// Time to set the value to the disguises value so no conflicts!
getWatcher().setValue(dataNo, disguiseValues.get(dataNo));
}
}
public void setVelocitySent(boolean sendVelocity) {
this.velocitySent = sendVelocity;
}
/**
* Can the disguised view himself as the disguise
*/
public void setViewSelfDisguise(boolean viewSelfDisguise) {
if (this.viewSelfDisguise != viewSelfDisguise) {
this.viewSelfDisguise = viewSelfDisguise;
if (getEntity() != null && getEntity() instanceof Player) {
if (DisguiseAPI.getDisguise(getEntity()) == this) {
if (viewSelfDisguise) {
disguiseAPI.setupFakeDisguise(this);
} else
disguiseAPI.removeVisibleDisguise((Player) getEntity());
}
}
}
}
public void setWatcher(FlagWatcher newWatcher) {
watcher = newWatcher;
}
/**
* Can the disguised view himself as the disguise
*/
public boolean viewSelfDisguise() {
return viewSelfDisguise;
}
}

View File

@@ -0,0 +1,219 @@
package me.libraryaddict.disguise.disguisetypes;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_6_R3.CraftSound;
public enum DisguiseSound {
BAT(Sound.BAT_HURT, null, Sound.BAT_DEATH, Sound.BAT_IDLE, Sound.BAT_LOOP, Sound.BAT_TAKEOFF, Sound.FALL_BIG,
Sound.FALL_SMALL),
BLAZE(Sound.BLAZE_HIT, null, Sound.BLAZE_DEATH, Sound.BLAZE_BREATH, Sound.FALL_BIG, Sound.FALL_SMALL),
CAVE_SPIDER(Sound.SPIDER_IDLE, Sound.SPIDER_WALK, Sound.SPIDER_DEATH, Sound.SPIDER_IDLE),
CHICKEN(Sound.CHICKEN_HURT, Sound.CHICKEN_WALK, Sound.CHICKEN_HURT, Sound.CHICKEN_IDLE, Sound.CHICKEN_EGG_POP,
Sound.FALL_BIG, Sound.FALL_SMALL),
COW(Sound.COW_HURT, Sound.COW_WALK, Sound.COW_HURT, Sound.COW_IDLE),
CREEPER(Sound.CREEPER_HISS, Sound.STEP_GRASS, Sound.CREEPER_DEATH),
DONKEY(Sound.DONKEY_HIT, Sound.STEP_GRASS, Sound.DONKEY_DEATH, Sound.DONKEY_IDLE, Sound.DONKEY_ANGRY, Sound.HORSE_GALLOP,
Sound.HORSE_ANGRY, Sound.HORSE_ARMOR, Sound.HORSE_JUMP, Sound.HORSE_LAND, Sound.HORSE_SADDLE, Sound.HORSE_SOFT,
Sound.HORSE_WOOD),
ENDER_DRAGON(Sound.ENDERDRAGON_HIT, null, Sound.ENDERDRAGON_DEATH, Sound.ENDERDRAGON_GROWL, Sound.ENDERDRAGON_WINGS,
Sound.FALL_BIG, Sound.FALL_SMALL),
ENDERMAN(Sound.ENDERMAN_HIT, Sound.STEP_GRASS, Sound.ENDERMAN_DEATH, Sound.ENDERMAN_IDLE, Sound.ENDERMAN_STARE,
Sound.ENDERMAN_TELEPORT, Sound.ENDERMAN_SCREAM),
GHAST(Sound.GHAST_SCREAM, null, Sound.GHAST_DEATH, Sound.GHAST_MOAN, Sound.GHAST_CHARGE, Sound.GHAST_FIREBALL,
Sound.GHAST_SCREAM2, Sound.FALL_BIG, Sound.FALL_SMALL),
GIANT(Sound.HURT_FLESH, Sound.STEP_GRASS),
HORSE(Sound.HORSE_HIT, Sound.STEP_GRASS, "mob.horse.death", Sound.HORSE_IDLE, Sound.HORSE_GALLOP, Sound.HORSE_ANGRY,
Sound.HORSE_ARMOR, Sound.HORSE_JUMP, Sound.HORSE_LAND, Sound.HORSE_SADDLE, Sound.HORSE_SOFT, Sound.HORSE_WOOD),
IRON_GOLEM(Sound.IRONGOLEM_HIT, Sound.IRONGOLEM_WALK, Sound.IRONGOLEM_DEATH, Sound.IRONGOLEM_THROW),
MAGMA_CUBE(Sound.SLIME_ATTACK, Sound.SLIME_WALK2, null, null, Sound.SLIME_WALK),
MULE(Sound.DONKEY_HIT, Sound.STEP_GRASS, Sound.DONKEY_DEATH, Sound.DONKEY_IDLE),
MUSHROOM_COW(Sound.COW_HURT, Sound.COW_WALK, Sound.COW_HURT, Sound.COW_IDLE),
OCELOT(Sound.CAT_HIT, Sound.STEP_GRASS, Sound.CAT_HIT, Sound.CAT_MEOW, Sound.CAT_PURR, Sound.CAT_PURREOW),
PIG(Sound.PIG_IDLE, Sound.PIG_WALK, Sound.PIG_DEATH, Sound.PIG_IDLE),
PIG_ZOMBIE(Sound.ZOMBIE_PIG_HURT, null, Sound.ZOMBIE_PIG_DEATH, Sound.ZOMBIE_PIG_IDLE, Sound.ZOMBIE_PIG_ANGRY),
PLAYER(Sound.HURT_FLESH, Sound.STEP_GRASS, Sound.HURT_FLESH),
SHEEP(Sound.SHEEP_IDLE, Sound.SHEEP_WALK, null, Sound.SHEEP_IDLE, Sound.SHEEP_SHEAR),
SILVERFISH(Sound.SILVERFISH_HIT, Sound.SILVERFISH_WALK, Sound.SILVERFISH_KILL, Sound.SILVERFISH_IDLE),
SKELETON(Sound.SKELETON_HURT, Sound.SKELETON_WALK, Sound.SKELETON_DEATH, Sound.SKELETON_IDLE),
SKELETON_HORSE("mob.horse.skeleton.hit", Sound.STEP_GRASS, Sound.HORSE_SKELETON_DEATH, Sound.HORSE_SKELETON_IDLE,
Sound.HORSE_GALLOP, Sound.HORSE_ANGRY, Sound.HORSE_ARMOR, Sound.HORSE_JUMP, Sound.HORSE_LAND, Sound.HORSE_SADDLE,
Sound.HORSE_SOFT, Sound.HORSE_WOOD),
SLIME(Sound.SLIME_ATTACK, Sound.SLIME_WALK2, null, null, Sound.SLIME_WALK),
SNOWMAN(),
SPIDER(Sound.SPIDER_IDLE, Sound.SPIDER_WALK, Sound.SPIDER_DEATH, Sound.SPIDER_IDLE),
SQUID(),
UNDEAD_HORSE(Sound.HORSE_ZOMBIE_HIT, Sound.STEP_GRASS, Sound.HORSE_ZOMBIE_DEATH, Sound.HORSE_ZOMBIE_IDLE, Sound.HORSE_GALLOP,
Sound.HORSE_ANGRY, Sound.HORSE_ARMOR, Sound.HORSE_JUMP, Sound.HORSE_LAND, Sound.HORSE_SADDLE, Sound.HORSE_SOFT,
Sound.HORSE_WOOD),
VILLAGER(Sound.VILLAGER_HIT, null, Sound.VILLAGER_DEATH, Sound.VILLAGER_IDLE, Sound.VILLAGER_HAGGLE, Sound.VILLAGER_YES,
Sound.VILLAGER_NO),
WITCH("mob.witch.hurt", null, "mob.witch.death", "mob.witch.idle"),
WITHER(Sound.WITHER_HURT, null, Sound.WITHER_DEATH, Sound.WITHER_IDLE, Sound.WITHER_SHOOT, Sound.WITHER_SPAWN,
Sound.FALL_BIG, Sound.FALL_SMALL),
WITHER_SKELETON(Sound.SKELETON_HURT, Sound.SKELETON_WALK, Sound.SKELETON_DEATH, Sound.SKELETON_IDLE),
WOLF(Sound.WOLF_HURT, Sound.WOLF_WALK, Sound.WOLF_DEATH, Sound.WOLF_BARK, Sound.WOLF_WHINE, Sound.WOLF_GROWL,
Sound.WOLF_HOWL, Sound.WOLF_PANT, Sound.WOLF_SHAKE),
ZOMBIE(Sound.ZOMBIE_HURT, Sound.STEP_GRASS, Sound.ZOMBIE_DEATH, Sound.ZOMBIE_IDLE, Sound.ZOMBIE_INFECT, Sound.ZOMBIE_METAL,
Sound.ZOMBIE_WOODBREAK, Sound.ZOMBIE_WOOD);
public enum SoundType {
CANCEL, DEATH, HURT, IDLE, STEP;
}
public static String getSoundName(Sound sound) {
return CraftSound.getSound(sound);
}
public static DisguiseSound getType(String name) {
try {
return valueOf(name);
} catch (Exception ex) {
return null;
}
}
private HashSet<String> cancelSounds = new HashSet<String>();
private float damageSoundVolume = 1F;
private HashMap<SoundType, String> disguiseSounds = new HashMap<SoundType, String>();
DisguiseSound(Object... sounds) {
for (int i = 0; i < sounds.length; i++) {
Object obj = sounds[i];
String s;
if (obj == null)
continue;
else if (obj instanceof String)
s = (String) obj;
else if (obj instanceof Sound)
s = CraftSound.getSound((Sound) obj);
else
throw new RuntimeException("Was given a unknown object " + obj);
switch (i) {
case 0:
disguiseSounds.put(SoundType.HURT, s);
break;
case 1:
disguiseSounds.put(SoundType.STEP, s);
break;
case 2:
disguiseSounds.put(SoundType.DEATH, s);
break;
case 3:
disguiseSounds.put(SoundType.IDLE, s);
break;
default:
cancelSounds.add(s);
break;
}
}
}
public float getDamageSoundVolume() {
return damageSoundVolume;
}
public String getSound(SoundType type) {
if (type == null || !disguiseSounds.containsKey(type))
return null;
return disguiseSounds.get(type);
}
public HashSet<String> getSoundsToCancel() {
return cancelSounds;
}
/**
* Used to check if this sound name is owned by this disguise sound.
*/
public SoundType getType(String sound, boolean ignoreDamage) {
if (isCancelSound(sound))
return SoundType.CANCEL;
if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
&& sound.startsWith("step."))
return SoundType.STEP;
for (SoundType type : SoundType.values()) {
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT))
continue;
String s = disguiseSounds.get(type);
if (s != null) {
if (s.equals(sound))
return type;
}
}
return null;
}
public boolean isCancelled(String soundName) {
return cancelSounds.contains(soundName);
}
public boolean isCancelSound(String sound) {
return getSoundsToCancel().contains(sound);
}
public void removeSound(SoundType type, Sound sound) {
removeSound(type, CraftSound.getSound(sound));
}
public void removeSound(SoundType type, String sound) {
if (type == SoundType.CANCEL)
cancelSounds.remove(sound);
else {
disguiseSounds.remove(type);
}
}
public void setDamageSoundVolume(float strength) {
this.damageSoundVolume = strength;
}
public void setSound(SoundType type, Sound sound) {
setSound(type, CraftSound.getSound(sound));
}
public void setSound(SoundType type, String sound) {
if (type == SoundType.CANCEL)
cancelSounds.add(sound);
else {
disguiseSounds.put(type, sound);
}
}
}

View File

@@ -0,0 +1,195 @@
package me.libraryaddict.disguise.disguisetypes;
import org.bukkit.entity.EntityType;
public enum DisguiseType {
ARROW(EntityType.ARROW, 60),
BAT(EntityType.BAT),
BLAZE(EntityType.BLAZE),
BOAT(EntityType.BOAT, 1),
CAVE_SPIDER(EntityType.CAVE_SPIDER),
CHICKEN(EntityType.CHICKEN),
COW(EntityType.COW),
CREEPER(EntityType.CREEPER),
DONKEY(EntityType.HORSE),
DROPPED_ITEM(EntityType.DROPPED_ITEM, 2, 1),
EGG(EntityType.EGG, 62),
ENDER_CRYSTAL(EntityType.ENDER_CRYSTAL, 51),
ENDER_DRAGON(EntityType.ENDER_DRAGON),
ENDER_PEARL(EntityType.ENDER_PEARL, 65),
ENDER_SIGNAL(EntityType.ENDER_SIGNAL, 72),
ENDERMAN(EntityType.ENDERMAN),
EXPERIENCE_ORB(EntityType.EXPERIENCE_ORB),
FALLING_BLOCK(EntityType.FALLING_BLOCK, 70, 1),
FIREBALL(EntityType.FIREBALL, 63, 0),
FIREWORK(EntityType.FIREWORK, 76),
FISHING_HOOK(EntityType.FISHING_HOOK, 90),
GHAST(EntityType.GHAST),
GIANT(EntityType.GIANT),
HORSE(EntityType.HORSE),
IRON_GOLEM(EntityType.IRON_GOLEM),
ITEM_FRAME(EntityType.ITEM_FRAME, 71),
MAGMA_CUBE(EntityType.MAGMA_CUBE),
MINECART(EntityType.MINECART, 10, 0),
MINECART_CHEST(EntityType.MINECART_CHEST, 10, 1),
MINECART_FURNACE(EntityType.MINECART_FURNACE, 10, 2),
MINECART_HOPPER(EntityType.MINECART_HOPPER, 10),
MINECART_MOB_SPAWNER(EntityType.MINECART_MOB_SPAWNER, 10, 4),
MINECART_TNT(EntityType.MINECART_TNT, 10, 3),
MULE(EntityType.HORSE),
MUSHROOM_COW(EntityType.MUSHROOM_COW),
OCELOT(EntityType.OCELOT),
PAINTING(EntityType.PAINTING),
PIG(EntityType.PIG),
PIG_ZOMBIE(EntityType.PIG_ZOMBIE),
PLAYER(EntityType.PLAYER),
PRIMED_TNT(EntityType.PRIMED_TNT, 50),
SHEEP(EntityType.SHEEP),
SILVERFISH(EntityType.SILVERFISH),
SKELETON(EntityType.SKELETON),
SKELETON_HORSE(EntityType.HORSE),
SLIME(EntityType.SLIME),
SMALL_FIREBALL(EntityType.SMALL_FIREBALL, 64, 0),
SNOWBALL(EntityType.SNOWBALL, 61),
SNOWMAN(EntityType.SNOWMAN),
SPIDER(EntityType.SPIDER),
SPLASH_POTION(EntityType.SPLASH_POTION, 73),
SQUID(EntityType.SQUID),
THROWN_EXP_BOTTLE(EntityType.THROWN_EXP_BOTTLE, 75),
UNDEAD_HORSE(EntityType.HORSE),
VILLAGER(EntityType.VILLAGER),
WITCH(EntityType.WITCH),
WITHER(EntityType.WITHER),
WITHER_SKELETON(EntityType.SKELETON),
WITHER_SKULL(EntityType.WITHER_SKULL, 66),
WOLF(EntityType.WOLF),
ZOMBIE(EntityType.ZOMBIE),
ZOMBIE_VILLAGER(EntityType.ZOMBIE);
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
return DisguiseType.valueOf(entityType.name());
}
private int defaultData;
private int defaultId;
private int entityId;
private EntityType entityType;
private Class watcherClass;
private DisguiseType(EntityType newType, int... obj) {
entityType = newType;
for (int i = 0; i < obj.length; i++) {
int value = obj[i];
switch (i) {
case 0:
entityId = value;
break;
case 1:
defaultId = value;
break;
case 2:
defaultData = value;
break;
default:
break;
}
}
}
public int getDefaultData() {
return defaultData;
}
public int getDefaultId() {
return defaultId;
}
public int getEntityId() {
return entityId;
}
public EntityType getEntityType() {
return entityType;
}
public Class getWatcherClass() {
return watcherClass;
}
public boolean isMisc() {
return !entityType.isAlive();
}
public boolean isMob() {
return entityType.isAlive() && entityType != EntityType.PLAYER;
}
public boolean isPlayer() {
return entityType == EntityType.PLAYER;
}
public void setWatcherClass(Class c) {
watcherClass = c;
}
}

View File

@@ -0,0 +1,309 @@
package me.libraryaddict.disguise.disguisetypes;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.PacketsManager;
import net.minecraft.server.v1_6_R3.ChunkCoordinates;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.ItemStack;
import net.minecraft.server.v1_6_R3.WatchableObject;
public class FlagWatcher {
public enum SlotType {
BOOTS(0), CHESTPLATE(2), HELD_ITEM(4), HELMET(3), LEGGINGS(1);
private int slotNo = 0;
private SlotType(int no) {
slotNo = no;
}
public int getSlot() {
return slotNo;
}
}
private static HashMap<Class, Integer> classTypes = new HashMap<Class, Integer>();
static {
classTypes.put(Byte.class, 0);
classTypes.put(Short.class, 1);
classTypes.put(Integer.class, 2);
classTypes.put(Float.class, 3);
classTypes.put(String.class, 4);
classTypes.put(ItemStack.class, 5);
classTypes.put(ChunkCoordinates.class, 6);
}
private Disguise disguise;
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5];
private boolean hasDied;
public FlagWatcher(Disguise disguise) {
this.disguise = disguise;
}
public FlagWatcher clone() {
FlagWatcher cloned = new FlagWatcher(disguise);
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
return cloned;
}
public List<WatchableObject> convert(List<WatchableObject> list) {
Iterator<WatchableObject> itel = list.iterator();
List<WatchableObject> newList = new ArrayList<WatchableObject>();
HashSet<Integer> sentValues = new HashSet<Integer>();
boolean sendAllCustom = false;
while (itel.hasNext()) {
WatchableObject watch = itel.next();
int dataType = watch.a();
sentValues.add(dataType);
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
// I send my custom values if I see this!
if (dataType == 1)
sendAllCustom = true;
if (entityValues.containsKey(dataType)) {
if (entityValues.get(dataType) == null)
continue;
Object value = entityValues.get(dataType);
boolean doD = watch.d();
watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value);
if (!doD)
watch.a(false);
} else {
boolean doD = watch.d();
watch = new WatchableObject(watch.c(), dataType, watch.b());
if (!doD)
watch.a(false);
}
newList.add(watch);
}
if (sendAllCustom) {
// Its sending the entire meta data. Better add the custom meta
for (int value : entityValues.keySet()) {
if (sentValues.contains(value))
continue;
Object obj = entityValues.get(value);
if (obj == null)
continue;
WatchableObject watch = new WatchableObject(classTypes.get(obj.getClass()), value, obj);
newList.add(watch);
}
}
// Here we check for if there is a health packet that says they died.
if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) {
for (WatchableObject watch : newList) {
// Its a health packet
if (watch.a() == 6) {
Object value = watch.b();
if (value != null && value instanceof Float) {
float newHealth = (Float) value;
if (newHealth > 0 && hasDied) {
hasDied = false;
PacketsManager.sendSelfDisguise((Player) disguise.getEntity());
} else if (newHealth <= 0 && !hasDied) {
hasDied = true;
}
}
}
}
}
return newList;
}
public boolean equals(FlagWatcher flagWatcher) {
return entityValues.equals(flagWatcher.entityValues);
}
public org.bukkit.inventory.ItemStack[] getArmor() {
org.bukkit.inventory.ItemStack[] armor = new org.bukkit.inventory.ItemStack[4];
for (int i = 0; i < 4; i++) {
armor[i] = items[i];
}
return armor;
}
private boolean getFlag(int i) {
return ((Byte) getValue(0, (byte) 0) & 1 << i) != 0;
}
public org.bukkit.inventory.ItemStack getHeldItem() {
return getItemStack(SlotType.HELD_ITEM);
}
public org.bukkit.inventory.ItemStack getItemStack(int slot) {
return items[slot];
}
public org.bukkit.inventory.ItemStack getItemStack(SlotType slot) {
return getItemStack(slot.getSlot());
}
protected Object getValue(int no, Object backup) {
if (entityValues.containsKey(no))
return entityValues.get(no);
return backup;
}
public boolean isBurning() {
return getFlag(0);
}
public boolean isInvisible() {
return getFlag(5);
}
public boolean isRiding() {
return getFlag(2);
}
public boolean isRightClicking() {
return getFlag(4);
}
public boolean isSneaking() {
return getFlag(1);
}
public boolean isSprinting() {
return getFlag(3);
}
protected void sendData(int data) {
if (disguise.getWatcher() == null || DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
return;
Entity entity = disguise.getEntity();
Object value = entityValues.get(data);
List<WatchableObject> list = new ArrayList<WatchableObject>();
list.add(new WatchableObject(classTypes.get(value.getClass()), data, value));
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, entity.getEntityId());
mods.write(1, list);
for (EntityPlayer player : disguise.getPerverts()) {
Player p = player.getBukkitEntity();
if (DisguiseAPI.isViewDisguises() || p != entity) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
public void setArmor(org.bukkit.inventory.ItemStack[] itemstack) {
for (int i = 0; i < itemstack.length; i++)
setItemStack(i, itemstack[i]);
}
public void setBurning(boolean setBurning) {
setFlag(0, 0, setBurning);
sendData(0);
}
protected void setFlag(int no, int i, boolean flag) {
byte b0 = (Byte) getValue(no, (byte) 0);
if (flag) {
setValue(no, (byte) (b0 | 1 << i));
} else {
setValue(no, (byte) (b0 & ~(1 << i)));
}
}
public void setHeldItem(org.bukkit.inventory.ItemStack itemstack) {
setItemStack(SlotType.HELD_ITEM, itemstack);
}
public void setInvisible(boolean setInvis) {
setFlag(0, 5, setInvis);
sendData(0);
}
public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) {
// Itemstack which is null means that its not replacing the disguises itemstack.
if (itemStack == null) {
// Find the item to replace it with
if (disguise.getEntity() instanceof LivingEntity) {
EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment();
if (slot == 4) {
itemStack = enquipment.getItemInHand();
} else {
itemStack = enquipment.getArmorContents()[slot];
}
if (itemStack != null && itemStack.getTypeId() == 0)
itemStack = null;
}
}
ItemStack itemToSend = null;
if (itemStack != null && itemStack.getTypeId() != 0)
itemToSend = CraftItemStack.asNMSCopy(itemStack);
items[slot] = itemStack;
if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
return;
slot++;
if (slot > 4)
slot = 0;
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, disguise.getEntity().getEntityId());
mods.write(1, slot);
mods.write(2, itemToSend);
for (EntityPlayer player : disguise.getPerverts()) {
Player p = player.getBukkitEntity();
if (p != disguise.getEntity()) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
public void setItemStack(SlotType slot, org.bukkit.inventory.ItemStack itemStack) {
setItemStack(slot.getSlot(), itemStack);
}
public void setRiding(boolean setRiding) {
setFlag(0, 2, setRiding);
sendData(0);
}
public void setRightClicking(boolean setRightClicking) {
setFlag(0, 4, setRightClicking);
sendData(0);
}
public void setSneaking(boolean setSneaking) {
setFlag(0, 1, setSneaking);
sendData(0);
}
public void setSprinting(boolean setSprinting) {
setFlag(0, 3, setSprinting);
sendData(0);
}
protected void setValue(int no, Object value) {
entityValues.put(no, value);
}
}

View File

@@ -0,0 +1,70 @@
package me.libraryaddict.disguise.disguisetypes;
import org.bukkit.entity.EntityType;
public class MiscDisguise extends Disguise {
private int data = -1;
private int id = -1;
public MiscDisguise(DisguiseType disguiseType) {
this(disguiseType, true, -1, -1);
}
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds) {
this(disguiseType, replaceSounds, -1, -1);
}
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
if (id == -1)
id = disguiseType.getDefaultId();
if (data == -1)
data = disguiseType.getDefaultData();
this.id = id;
this.data = data;
createDisguise(disguiseType, replaceSounds);
}
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
this(disguiseType, true, id, data);
}
@Deprecated
public MiscDisguise(EntityType entityType) {
this(entityType, true, -1, -1);
}
@Deprecated
public MiscDisguise(EntityType entityType, boolean replaceSounds) {
this(entityType, replaceSounds, -1, -1);
}
@Deprecated
public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) {
if (id == -1)
id = DisguiseType.getType(entityType).getDefaultId();
if (data == -1)
data = DisguiseType.getType(entityType).getDefaultData();
this.id = id;
this.data = data;
createDisguise(DisguiseType.getType(entityType), replaceSounds);
}
@Deprecated
public MiscDisguise(EntityType disguiseType, int id, int data) {
this(disguiseType, true, id, data);
}
public MiscDisguise clone() {
MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getId(), getData());
return disguise;
}
public int getData() {
return data;
}
public int getId() {
return id;
}
}

View File

@@ -0,0 +1,68 @@
package me.libraryaddict.disguise.disguisetypes;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import org.bukkit.entity.EntityType;
public class MobDisguise extends Disguise {
private boolean isAdult;
public MobDisguise(DisguiseType disguiseType) {
this(disguiseType, true);
}
public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
this(disguiseType, isAdult, true);
}
public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) {
this.isAdult = isAdult;
createDisguise(disguiseType, replaceSounds);
}
@Deprecated
public MobDisguise(EntityType entityType) {
this(entityType, true);
}
@Deprecated
public MobDisguise(EntityType entityType, boolean isAdult) {
this(entityType, isAdult, true);
}
@Deprecated
public MobDisguise(EntityType entityType, boolean isAdult, boolean replaceSounds) {
this.isAdult = isAdult;
createDisguise(DisguiseType.getType(entityType), replaceSounds);
}
public MobDisguise clone() {
MobDisguise disguise = new MobDisguise(getType(), isAdult(), replaceSounds());
return disguise;
}
public boolean doesDisguiseAge() {
if (getWatcher() != null) {
return getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher;
}
return false;
}
public boolean equals(MobDisguise mobDisguise) {
return isAdult == mobDisguise.isAdult && this.equals(mobDisguise);
}
public boolean isAdult() {
if (getWatcher() != null) {
if (getWatcher() instanceof AgeableWatcher)
return ((AgeableWatcher) getWatcher()).isAdult();
else if (getWatcher() instanceof ZombieWatcher)
return ((ZombieWatcher) getWatcher()).isAdult();
return false;
}
return isAdult;
}
}

View File

@@ -0,0 +1,30 @@
package me.libraryaddict.disguise.disguisetypes;
public class PlayerDisguise extends Disguise {
private String playerName;
public PlayerDisguise(String name) {
this(name, true);
}
public PlayerDisguise(String name, boolean replaceSounds) {
if (name.length() > 16)
name = name.substring(0, 16);
playerName = name;
createDisguise(DisguiseType.PLAYER, replaceSounds);
}
public PlayerDisguise clone() {
PlayerDisguise disguise = new PlayerDisguise(getName(), replaceSounds());
return disguise;
}
public boolean equals(PlayerDisguise playerDisguise) {
return getName().equals(playerDisguise.getName()) && this.equals(playerDisguise);
}
public String getName() {
return playerName;
}
}

View File

@@ -0,0 +1,86 @@
package me.libraryaddict.disguise.disguisetypes;
import java.util.HashMap;
import net.minecraft.server.v1_6_R3.EnumEntitySize;
public class Values {
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
return getValues(type).getAttributesValues();
}
public static Class getEntityClass(DisguiseType type) {
return getValues(type).getEntityClass();
}
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
return getValues(type).getMetaValues();
}
public static Values getValues(DisguiseType type) {
switch (type) {
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
type = DisguiseType.HORSE;
break;
case MINECART_CHEST:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_TNT:
case MINECART_MOB_SPAWNER:
type = DisguiseType.MINECART;
break;
case WITHER_SKELETON:
type = DisguiseType.SKELETON;
break;
case ZOMBIE_VILLAGER:
type = DisguiseType.ZOMBIE;
break;
default:
break;
}
return values.get(type);
}
private HashMap<String, Double> attributesValues = new HashMap<String, Double>();
private Class declared;
private EnumEntitySize enumEntitySize;
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
public Values(DisguiseType type, Class classType, EnumEntitySize entitySize) {
values.put(type, this);
enumEntitySize = entitySize;
declared = classType;
}
public HashMap<String, Double> getAttributesValues() {
return attributesValues;
}
public Class getEntityClass() {
return declared;
}
public EnumEntitySize getEntitySize() {
return enumEntitySize;
}
public HashMap<Integer, Object> getMetaValues() {
return metaValues;
}
public void setAttributesValue(String attribute, Double value) {
attributesValues.put(attribute, value);
}
public void setMetaValue(int no, Object value) {
metaValues.put(no, value);
}
}

View File

@@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class AgeableWatcher extends LivingWatcher {
public AgeableWatcher(Disguise disguise) {
super(disguise);
}
public boolean isAdult() {
return (Integer) getValue(12, 0) >= 0;
}
public void setAdult(boolean isAdult) {
setValue(12, isAdult ? 0 : -24000);
sendData(12);
}
}

View File

@@ -0,0 +1,22 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class ArrowWatcher extends FlagWatcher {
public ArrowWatcher(Disguise disguise) {
super(disguise);
setValue(16, (byte) 0);
}
public boolean isMoving() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setMoving(boolean moving) {
setValue(16, (byte) (moving ? 1 : 0));
sendData(16);
}
}

View File

@@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class BatWatcher extends LivingWatcher {
public BatWatcher(Disguise disguise) {
super(disguise);
setFlying(true);
}
public boolean isFlying() {
return (Byte) getValue(16, (byte) 1) == 0;
}
public void setFlying(boolean flying) {
setValue(16, (byte) (flying ? 0 : 1));
sendData(16);
}
}

View File

@@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class BlazeWatcher extends LivingWatcher {
public BlazeWatcher(Disguise disguise) {
super(disguise);
}
public boolean isBlazing() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setBlazing(boolean isBlazing) {
setValue(16, (byte) (isBlazing ? 1 : 0));
sendData(16);
}
}

View File

@@ -0,0 +1,30 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class BoatWatcher extends FlagWatcher {
public BoatWatcher(Disguise disguise) {
super(disguise);
}
public int getDamage() {
return (Integer) getValue(19, 40F);
}
public int getHealth() {
return (Integer) getValue(17, 10);
}
public void setDamage(float dmg) {
setValue(19, dmg);
sendData(19);
}
public void setHealth(int health) {
setValue(17, health);
sendData(17);
}
}

View File

@@ -0,0 +1,29 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class CreeperWatcher extends LivingWatcher {
public CreeperWatcher(Disguise disguise) {
super(disguise);
}
public boolean isFused() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public boolean isPowered() {
return (Byte) getValue(17, (byte) 0) == 1;
}
public void setFuse(boolean isFused) {
setValue(16, (byte) (isFused ? 1 : -1));
sendData(16);
}
public void setPowered(boolean powered) {
setValue(17, (byte) (powered ? 1 : 0));
sendData(17);
}
}

View File

@@ -0,0 +1,27 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class DroppedItemWatcher extends FlagWatcher {
public DroppedItemWatcher(Disguise disguise) {
super(disguise);
}
public ItemStack getItemStack() {
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10,
CraftItemStack.asNMSCopy(new ItemStack(1))));
}
public void setItemStack(ItemStack item) {
setValue(10, CraftItemStack.asNMSCopy(item));
sendData(10);
}
}

View File

@@ -0,0 +1,35 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class EndermanWatcher extends LivingWatcher {
public EndermanWatcher(Disguise disguise) {
super(disguise);
}
public int getCarriedData() {
return ((Byte) getValue(17, (byte) 0));
}
public int getCarriedId() {
return ((Byte) getValue(16, (byte) 0));
}
public boolean isAgressive() {
return (Integer) getValue(18, (byte) 0) == 1;
}
public void setAgressive(boolean isAgressive) {
setValue(18, (byte) (isAgressive ? 1 : 0));
sendData(18);
}
public void setCarriedItem(int id, int dataValue) {
setValue(16, (byte) (id & 255));
setValue(17, (byte) (dataValue & 255));
sendData(16);
sendData(17);
}
}

View File

@@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class GhastWatcher extends LivingWatcher {
public GhastWatcher(Disguise disguise) {
super(disguise);
}
public boolean isAgressive() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setAgressive(boolean isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
}

View File

@@ -0,0 +1,107 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.Random;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
public class HorseWatcher extends AgeableWatcher {
public HorseWatcher(Disguise disguise) {
super(disguise);
setValue(20, new Random().nextInt(7));
}
public Color getColor() {
return Color.values()[((Integer) getValue(20, 0) & 0xFF)];
}
public Style getStyle() {
return Style.values()[((Integer) getValue(20, 0) >>> 8)];
}
public boolean hasChest() {
return isTrue(8);
}
public boolean isBredable() {
return isTrue(16);
}
public boolean isGrazing() {
return isTrue(32);
}
public boolean isMouthOpen() {
return isTrue(128);
}
public boolean isRearing() {
return isTrue(64);
}
public boolean isSaddled() {
return isTrue(4);
}
public boolean isTamed() {
return isTrue(2);
}
private boolean isTrue(int i) {
return ((Integer) getValue(16, (byte) 0) & i) != 0;
}
public void setCanBred(boolean bred) {
setFlag(16, bred);
}
public void setCarryingChest(boolean chest) {
setFlag(8, true);
}
public void setColor(Color color) {
setValue(20, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
sendData(20);
}
private void setFlag(int i, boolean flag) {
int j = (Integer) getValue(16, (byte) 0);
if (flag) {
setValue(16, j | i);
} else {
setValue(16, j & ~i);
}
sendData(16);
}
public void setGrazing(boolean grazing) {
setFlag(32, grazing);
}
public void setMouthOpen(boolean mouthOpen) {
setFlag(128, mouthOpen);
}
public void setRearing(boolean rear) {
setFlag(64, true);
}
public void setSaddled(boolean saddled) {
setFlag(4, saddled);
}
public void setStyle(Style style) {
setValue(20, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(20);
}
public void setTamed(boolean tamed) {
setFlag(2, tamed);
}
}

View File

@@ -0,0 +1,32 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
public class ItemFrameWatcher extends FlagWatcher {
public ItemFrameWatcher(Disguise disguise) {
super(disguise);
}
public ItemStack getItemStack() {
if (getValue(3, (byte) 0) instanceof Integer)
return new ItemStack(0);
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(3, null));
}
public void setItemStack(ItemStack newItem) {
if (newItem.getTypeId() == 0)
setValue(3, (byte) 0);
else {
setValue(3, CraftItemStack.asCraftCopy(newItem));
}
sendData(3);
}
}

View File

@@ -0,0 +1,102 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.HashSet;
import java.util.Iterator;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import net.minecraft.server.v1_6_R3.MobEffect;
import net.minecraft.server.v1_6_R3.PotionBrewer;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class LivingWatcher extends FlagWatcher {
private HashSet<MobEffect> potionEffects = new HashSet<MobEffect>();
public LivingWatcher(Disguise disguise) {
super(disguise);
}
public void addPotionEffect(PotionEffect potionEffect) {
if (hasPotionEffect(potionEffect.getType()))
removePotionEffect(potionEffect.getType());
new MobEffect(potionEffect.getType().getId(), potionEffect.getDuration(), potionEffect.getAmplifier());
sendPotionEffects();
}
public LivingWatcher clone() {
LivingWatcher clone = this.clone();
clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone();
return clone;
}
public String getCustomName() {
return (String) getValue(10, "");
}
public float getHealth() {
return (Float) getValue(6, 0F);
}
public boolean getPotionParticlesRemoved() {
return (Byte) getValue(8, (byte) 0) == 1;
}
public boolean hasCustomName() {
return getCustomName().length() > 0;
}
public boolean hasPotionEffect(PotionEffectType type) {
for (MobEffect effect : potionEffects)
if (effect.getEffectId() == type.getId())
return true;
return false;
}
public boolean isCustomNameVisible() {
return (Byte) getValue(11, (byte) 0) == 1;
}
public void removePotionEffect(PotionEffectType type) {
Iterator<MobEffect> itel = potionEffects.iterator();
while (itel.hasNext()) {
MobEffect effect = itel.next();
if (effect.getEffectId() == type.getId()) {
itel.remove();
sendPotionEffects();
return;
}
}
}
public void removePotionParticles(boolean particles) {
setValue(8, (byte) (particles ? 1 : 0));
sendData(8);
}
private void sendPotionEffects() {
setValue(7, PotionBrewer.a(potionEffects));
sendData(7);
}
public void setCustomName(String name) {
if (name.length() > 64)
name = name.substring(0, 64);
setValue(10, name);
sendData(10);
}
public void setCustomNameVisible(boolean display) {
setValue(11, (byte) (display ? 1 : 0));
sendData(11);
}
public void setHealth(float health) {
setValue(6, health);
sendData(6);
}
}

View File

@@ -0,0 +1,21 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class MinecartWatcher extends FlagWatcher {
public MinecartWatcher(Disguise disguise) {
super(disguise);
}
public float getDamage() {
return (Float) getValue(19, 0F);
}
public void setDamage(float damage) {
setValue(19, damage);
sendData(19);
}
}

View File

@@ -0,0 +1,43 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Ocelot.Type;
public class OcelotWatcher extends AgeableWatcher {
public OcelotWatcher(Disguise disguise) {
super(disguise);
}
public String getOwner() {
return (String) getValue(17, "");
}
public Type getType() {
return Ocelot.Type.getType((Byte) getValue(18, (byte) 0));
}
public void setOwner(String newOwner) {
setValue(17, newOwner);
sendData(17);
}
public void setSitting(boolean sitting) {
setFlag(16, 1, sitting);
sendData(16);
}
public void setTamed(boolean tamed) {
setFlag(16, 4, tamed);
sendData(16);
}
public void setType(Type newType) {
setValue(18, (byte) newType.getId());
sendData(18);
}
}

View File

@@ -0,0 +1,19 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class PigWatcher extends AgeableWatcher {
public PigWatcher(Disguise disguise) {
super(disguise);
}
public boolean isSaddled() {
return (Byte) getValue(16, (byte) 0) == 1;
}
public void setSaddled(boolean isSaddled) {
setValue(16, (byte) (isSaddled ? 1 : 0));
sendData(16);
}
}

View File

@@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class PlayerWatcher extends LivingWatcher {
public PlayerWatcher(Disguise disguise) {
super(disguise);
}
public int getArrowsSticking() {
return (Byte) getValue(9, (byte) 0);
}
public void setArrowsSticking(int arrowsNo) {
setValue(9, (byte) arrowsNo);
sendData(9);
}
}

View File

@@ -0,0 +1,36 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class SheepWatcher extends AgeableWatcher {
public SheepWatcher(Disguise disguise) {
super(disguise);
setValue(16, (byte) 0);
}
public AnimalColor getColor() {
return AnimalColor.values()[(Byte) getValue(16, (byte) 0) & 15];
}
public boolean isSheared() {
return ((Byte) getValue(16, (byte) 0) & 16) != 0;
}
public void setColor(AnimalColor color) {
byte b0 = (Byte) getValue(16, (byte) 0);
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
sendData(16);
}
public void setSheared(boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | 16));
} else {
setValue(16, (byte) (b0 & -17));
}
sendData(16);
}
}

View File

@@ -0,0 +1,25 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.Random;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class SlimeWatcher extends LivingWatcher {
public SlimeWatcher(Disguise disguise) {
super(disguise);
setValue(16, (byte) (new Random().nextInt(4) + 1));
}
public int getSize() {
return (Integer) getValue(16, (byte) 1);
}
public void setSize(int size) {
setValue(16, (byte) size);
sendData(16);
}
}

View File

@@ -0,0 +1,35 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.Random;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Villager.Profession;
public class VillagerWatcher extends AgeableWatcher {
public VillagerWatcher(Disguise disguise) {
super(disguise);
setValue(16, Profession.values()[new Random().nextInt(Profession.values().length)].getId());
}
public Profession getProfession() {
return Profession.values()[(Integer) getValue(16, 0)];
}
public int getProfessionId() {
return (Integer) getValue(16, 0);
}
public void setProfession(Profession newProfession) {
setProfessionId(newProfession.getId());
}
public void setProfessionId(int profession) {
setValue(16, profession % 6);
sendData(16);
}
}

View File

@@ -0,0 +1,21 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
public class WitherSkullWatcher extends FlagWatcher {
public WitherSkullWatcher(Disguise disguise) {
super(disguise);
}
public boolean isBlue() {
return (Byte) getValue(0, (byte) 0) == 1;
}
public void setBlue(boolean blue) {
setValue(0, (byte) (blue ? 1 : 0));
sendData(0);
}
}

View File

@@ -0,0 +1,74 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class WolfWatcher extends AgeableWatcher {
public WolfWatcher(Disguise disguise) {
super(disguise);
}
public AnimalColor getCollarColor() {
return AnimalColor.values()[(Byte) getValue(20, (byte) 14)];
}
public float getHealth() {
return (Float) getValue(18, 8F);
}
public String getName() {
return (String) getValue(17, "");
}
public boolean isAngry() {
return isTrue(2);
}
public boolean isSitting() {
return isTrue(1);
}
public boolean isTamed() {
return isTrue(4);
}
private boolean isTrue(int no) {
return ((Byte) getValue(16, (byte) 0) & no) != 0;
}
public void setAngry(boolean angry) {
setFlag(2, angry);
}
public void setCollarColor(AnimalColor newColor) {
if (newColor != getCollarColor()) {
setValue(20, (byte) newColor.getId());
sendData(20);
}
}
private void setFlag(int no, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | (no)));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
public void setHealth(float newHealth) {
setValue(18, newHealth);
sendData(18);
}
public void setSitting(boolean sitting) {
setFlag(1, sitting);
}
public void setTamed(boolean tamed) {
setFlag(4, tamed);
}
}

View File

@@ -0,0 +1,29 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class ZombieWatcher extends LivingWatcher {
public ZombieWatcher(Disguise disguise) {
super(disguise);
}
public boolean isAdult() {
return (Byte) getValue(12, (byte) 0) == 0;
}
public boolean isVillager() {
return (Byte) getValue(13, (byte) 0) == 1;
}
public void setAdult(boolean adult) {
setValue(12, (byte) (adult ? 0 : 1));
sendData(12);
}
public void setVillager(boolean villager) {
setValue(13, (byte) (villager ? 1 : 0));
sendData(13);
}
}

View File

@@ -0,0 +1,50 @@
package me.libraryaddict.disguise.events;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class DisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() {
return handlers;
}
private Disguise disguise;
private Entity disguised;
private boolean isCancelled;
public DisguiseEvent(Entity entity, Disguise disguise) {
this.disguised = entity;
this.disguise = disguise;
}
public Disguise getDisguise() {
return disguise;
}
public Entity getEntity() {
return disguised;
}
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancelled) {
isCancelled = cancelled;
}
}

View File

@@ -0,0 +1,50 @@
package me.libraryaddict.disguise.events;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class UndisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() {
return handlers;
}
private Disguise disguise;
private Entity disguised;
private boolean isCancelled;
public UndisguiseEvent(Entity entity, Disguise disguise) {
this.disguised = entity;
this.disguise = disguise;
}
public Disguise getDisguise() {
return disguise;
}
public Entity getEntity() {
return disguised;
}
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancelled) {
isCancelled = cancelled;
}
}