Read desc
Removed a few classes to a new package Renamed methods and deprecated them as retarded names. Fixed DisguiseAPI instance opening new calls and just moved that into a new class
This commit is contained in:
parent
81933b90bd
commit
93ef0a26d4
@ -1,38 +1,24 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||
import me.libraryaddict.disguise.utils.PacketsManager;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utils.DisguiseUtilities;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
|
||||
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;
|
||||
|
||||
// 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;
|
||||
|
||||
@Deprecated
|
||||
public static boolean canHearSelfDisguise() {
|
||||
return hearSelfDisguise;
|
||||
}
|
||||
@ -43,14 +29,14 @@ public class DisguiseAPI {
|
||||
public static void disguiseNextEntity(Disguise disguise) {
|
||||
if (disguise == null)
|
||||
return;
|
||||
if (disguise.getEntity() != null || disguises.containsValue(disguise)) {
|
||||
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
try {
|
||||
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
||||
field.setAccessible(true);
|
||||
int id = field.getInt(null);
|
||||
disguises.put(id, disguise);
|
||||
DisguiseUtilities.getDisguises().put(id, disguise);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -84,11 +70,11 @@ public class DisguiseAPI {
|
||||
} // If there was a old disguise
|
||||
Disguise oldDisguise = getDisguise(entity);
|
||||
// Stick the disguise in the disguises bin
|
||||
disguises.put(entity.getEntityId(), disguise);
|
||||
DisguiseUtilities.getDisguises().put(entity.getEntityId(), disguise);
|
||||
// Resend the disguised entity's packet
|
||||
refreshTrackers(entity);
|
||||
DisguiseUtilities.refreshTrackers(entity);
|
||||
// If he is a player, then self disguise himself
|
||||
setupPlayerFakeDisguise(disguise);
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
// Discard the disguise
|
||||
if (oldDisguise != null)
|
||||
oldDisguise.removeDisguise();
|
||||
@ -97,28 +83,28 @@ public class DisguiseAPI {
|
||||
/**
|
||||
* Get the disguise of a entity
|
||||
*/
|
||||
public static Disguise getDisguise(Entity disguiser) {
|
||||
if (disguiser == null)
|
||||
public static Disguise getDisguise(Entity disguised) {
|
||||
if (disguised == null)
|
||||
return null;
|
||||
if (disguises.containsKey(disguiser.getEntityId()))
|
||||
return disguises.get(disguiser.getEntityId());
|
||||
if (DisguiseUtilities.getDisguises().containsKey(disguised.getEntityId()))
|
||||
return DisguiseUtilities.getDisguises().get(disguised.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);
|
||||
public static int getFakeDisguise(int entityId) {
|
||||
if (DisguiseUtilities.getSelfDisguisesIds().containsKey(entityId))
|
||||
return DisguiseUtilities.getSelfDisguisesIds().get(entityId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this entity disguised
|
||||
*/
|
||||
public static boolean isDisguised(Entity disguiser) {
|
||||
return getDisguise(disguiser) != null;
|
||||
public static boolean isDisguised(Entity disguised) {
|
||||
return getDisguise(disguised) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,6 +125,10 @@ public class DisguiseAPI {
|
||||
return PacketsManager.isInventoryListenerEnabled();
|
||||
}
|
||||
|
||||
public static boolean isSelfDisguisesSoundsReplaced() {
|
||||
return hearSelfDisguise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the sound packets caught and modified
|
||||
*/
|
||||
@ -160,79 +150,6 @@ public class DisguiseAPI {
|
||||
return PacketsManager.isViewDisguisesListenerEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Resends
|
||||
* the entity to all the watching players, which is where the magic begins
|
||||
*/
|
||||
private static void refreshTrackers(Entity entity) {
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(entity.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, entity.getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
||||
Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
HashSet cloned = (HashSet) trackedPlayers.clone();
|
||||
for (Object player : cloned) {
|
||||
if (entity instanceof Player && !((Player) getBukkitEntity.invoke(player)).canSee((Player) entity))
|
||||
continue;
|
||||
clear.invoke(entityTrackerEntry, player);
|
||||
updatePlayer.invoke(entityTrackerEntry, player);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(player.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, player.getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
// If the tracker exists. Remove himself from his tracker
|
||||
trackedPlayers.remove(ReflectionManager.getNmsEntity(player));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}// 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());
|
||||
packetMetadata.getWatchableCollectionModifier().write(0,
|
||||
WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects());
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can players hear their own disguises
|
||||
*/
|
||||
@ -273,38 +190,6 @@ public class DisguiseAPI {
|
||||
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() || !PacketsManager.isViewDisguisesListenerEnabled() || player.getVehicle() != null)
|
||||
return;
|
||||
try {
|
||||
// Grab the entity ID the fake disguise will use
|
||||
Field field = ReflectionManager.getNmsClass("Entity").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);
|
||||
if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
|
||||
if (PacketsManager.isInventoryListenerEnabled()) {
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
|
||||
*/
|
||||
@ -331,19 +216,6 @@ public class DisguiseAPI {
|
||||
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);
|
||||
private DisguiseAPI() {
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package me.libraryaddict.disguise;
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utils.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utils.UpdateChecker;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -19,7 +21,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
public class DisguiseListener implements Listener {
|
||||
|
||||
private String currentVersion;
|
||||
private DisguiseAPI disguiseAPI = new DisguiseAPI();
|
||||
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<String, BukkitRunnable>();
|
||||
private HashMap<String, Disguise> disguiseSlap = new HashMap<String, Disguise>();
|
||||
private String latestVersion;
|
||||
@ -93,7 +94,7 @@ public class DisguiseListener implements Listener {
|
||||
return;
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getEntered());
|
||||
if (disguise != null && event.getEntered() instanceof Player) {
|
||||
disguiseAPI.removeVisibleDisguise((Player) event.getEntered());
|
||||
DisguiseUtilities.removeSelfDisguise((Player) event.getEntered());
|
||||
((Player) event.getEntered()).updateInventory();
|
||||
}
|
||||
}
|
||||
@ -106,7 +107,7 @@ public class DisguiseListener implements Listener {
|
||||
if (disguise != null && event.getExited() instanceof Player) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
disguiseAPI.setupFakeDisguise(disguise);
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
((Player) disguise.getEntity()).updateInventory();
|
||||
}
|
||||
});
|
||||
|
@ -17,6 +17,8 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
import me.libraryaddict.disguise.utils.PacketsManager;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -122,11 +124,11 @@ public class LibsDisguises extends JavaPlugin {
|
||||
break;
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
// There is no explict watcher for this entity.
|
||||
Class c = disguiseType.getEntityType().getEntityClass();
|
||||
if (Ageable.class.isAssignableFrom(c)) {
|
||||
// There is no explicit watcher for this entity.
|
||||
Class entityClass = disguiseType.getEntityType().getEntityClass();
|
||||
if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||
watcherClass = AgeableWatcher.class;
|
||||
} else if (LivingEntity.class.isAssignableFrom(c)) {
|
||||
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
||||
watcherClass = LivingWatcher.class;
|
||||
} else {
|
||||
watcherClass = FlagWatcher.class;
|
||||
@ -176,19 +178,19 @@ public class LibsDisguises extends JavaPlugin {
|
||||
Object entity = ReflectionManager.createEntityInstance(name);
|
||||
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity")
|
||||
.invoke(entity);
|
||||
int size = 0;
|
||||
int enumEntitySize = 0;
|
||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||
Enum a = (Enum) field.get(entity);
|
||||
size = a.ordinal();
|
||||
enumEntitySize = a.ordinal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Values value = new Values(disguiseType, entity.getClass(), size);
|
||||
Values disguiseValues = new Values(disguiseType, entity.getClass(), enumEntitySize);
|
||||
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
||||
List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watch : watchers)
|
||||
value.setMetaValue(watch.getIndex(), watch.getValue());
|
||||
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
|
||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||
if (sound != null) {
|
||||
Float soundStrength = ReflectionManager.getSoundModifier(entity);
|
||||
|
@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utils.BaseDisguiseCommand;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||
import me.libraryaddict.disguise.DisguiseListener;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utils.BaseDisguiseCommand;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -3,9 +3,10 @@ package me.libraryaddict.disguise.commands;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.utils.BaseDisguiseCommand;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -15,8 +16,8 @@ import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||
private class EnumHelp {
|
||||
private String enumName;
|
||||
private String enumDescription;
|
||||
private String enumName;
|
||||
private String[] enums;
|
||||
private String readableEnum;
|
||||
|
||||
@ -38,21 +39,21 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||
this.readableEnum = enumReadable;
|
||||
}
|
||||
|
||||
public String getEnumName() {
|
||||
return enumName;
|
||||
}
|
||||
|
||||
public String getReadableEnum() {
|
||||
return readableEnum;
|
||||
}
|
||||
|
||||
public String getEnumDescription() {
|
||||
return enumDescription;
|
||||
}
|
||||
|
||||
public String getEnumName() {
|
||||
return enumName;
|
||||
}
|
||||
|
||||
public String[] getEnums() {
|
||||
return enums;
|
||||
}
|
||||
|
||||
public String getReadableEnum() {
|
||||
return readableEnum;
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<EnumHelp> enumHelp = new ArrayList<EnumHelp>();
|
||||
|
@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utils.BaseDisguiseCommand;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import me.libraryaddict.disguise.BaseDisguiseCommand;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utils.BaseDisguiseCommand;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -8,11 +8,13 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.PacketsManager;
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
import me.libraryaddict.disguise.utils.PacketsManager;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utils.DisguiseUtilities;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Horse.Variant;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,18 +28,14 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
|
||||
public abstract 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 hearSelfDisguise = DisguiseAPI.isSelfDisguisesSoundsReplaced();
|
||||
private boolean hideArmorFromSelf = DisguiseAPI.isHidingArmorFromSelf();
|
||||
private boolean hideHeldItemFromSelf = DisguiseAPI.isHidingHeldItemFromSelf();
|
||||
private boolean replaceSounds = DisguiseAPI.isSoundEnabled();
|
||||
private BukkitRunnable runnable;
|
||||
private BukkitRunnable velocityRunnable;
|
||||
private boolean velocitySent = DisguiseAPI.isVelocitySent();
|
||||
private boolean viewSelfDisguise = DisguiseAPI.isViewDisguises();
|
||||
private FlagWatcher watcher;
|
||||
@ -175,7 +173,7 @@ public abstract class Disguise {
|
||||
final double vectorY = fallSpeed;
|
||||
final boolean alwaysSendVelocity = alwaysSend;
|
||||
// A scheduler to clean up any unused disguises.
|
||||
runnable = new BukkitRunnable() {
|
||||
velocityRunnable = new BukkitRunnable() {
|
||||
private int i = 0;
|
||||
|
||||
public void run() {
|
||||
@ -220,7 +218,7 @@ public abstract class Disguise {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
if (entity == player) {
|
||||
if (!viewSelfDisguise())
|
||||
if (!isSelfDisguiseVisible())
|
||||
continue;
|
||||
if (selfLookPacket != null) {
|
||||
try {
|
||||
@ -334,6 +332,17 @@ public abstract class Disguise {
|
||||
return this instanceof PlayerDisguise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the disguised view himself as the disguise
|
||||
*/
|
||||
public boolean isSelfDisguiseVisible() {
|
||||
return viewSelfDisguise;
|
||||
}
|
||||
|
||||
public boolean isSoundsReplaced() {
|
||||
return replaceSounds;
|
||||
}
|
||||
|
||||
public boolean isVelocitySent() {
|
||||
return velocitySent;
|
||||
}
|
||||
@ -344,10 +353,10 @@ public abstract class Disguise {
|
||||
public void removeDisguise() {
|
||||
// Why the hell can't I safely check if its running?!?!
|
||||
try {
|
||||
runnable.cancel();
|
||||
velocityRunnable.cancel();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
HashMap<Integer, Disguise> disguises = disguiseAPI.getDisguises();
|
||||
HashMap<Integer, Disguise> disguises = DisguiseUtilities.getDisguises();
|
||||
// If this disguise has a entity set
|
||||
if (getEntity() != null) {
|
||||
// If the entity is valid
|
||||
@ -359,10 +368,10 @@ public abstract class Disguise {
|
||||
// Gotta do reflection, copy code or open up calls.
|
||||
// Reflection is the cleanest?
|
||||
if (getEntity() instanceof Player) {
|
||||
disguiseAPI.removeVisibleDisguise((Player) entity);
|
||||
DisguiseUtilities.removeSelfDisguise((Player) entity);
|
||||
}
|
||||
// Better refresh the entity to undisguise it
|
||||
disguiseAPI.refreshWatchingPlayers(getEntity());
|
||||
DisguiseUtilities.refreshTrackers(getEntity());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -377,6 +386,7 @@ public abstract class Disguise {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean replaceSounds() {
|
||||
return replaceSounds;
|
||||
}
|
||||
@ -389,7 +399,7 @@ public abstract class Disguise {
|
||||
throw new RuntimeException("This disguise is already in use! Try .clone()");
|
||||
this.entity = entity;
|
||||
setupWatcher();
|
||||
runnable.runTaskTimer(plugin, 1, 1);
|
||||
velocityRunnable.runTaskTimer(plugin, 1, 1);
|
||||
}
|
||||
|
||||
public void setHearSelfDisguise(boolean hearSelfDisguise) {
|
||||
@ -529,9 +539,9 @@ public abstract class Disguise {
|
||||
if (getEntity() != null && getEntity() instanceof Player) {
|
||||
if (DisguiseAPI.getDisguise(getEntity()) == this) {
|
||||
if (viewSelfDisguise) {
|
||||
disguiseAPI.setupFakeDisguise(this);
|
||||
DisguiseUtilities.setupFakeDisguise(this);
|
||||
} else
|
||||
disguiseAPI.removeVisibleDisguise((Player) getEntity());
|
||||
DisguiseUtilities.removeSelfDisguise((Player) getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -541,9 +551,7 @@ public abstract class Disguise {
|
||||
watcher = newWatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the disguised view himself as the disguise
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean viewSelfDisguise() {
|
||||
return viewSelfDisguise;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
|
||||
|
@ -174,10 +174,6 @@ public enum DisguiseType {
|
||||
private EntityType entityType;
|
||||
private Class watcherClass;
|
||||
|
||||
private void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
private DisguiseType(int... obj) {
|
||||
for (int i = 0; i < obj.length; i++) {
|
||||
int value = obj[i];
|
||||
@ -229,6 +225,10 @@ public enum DisguiseType {
|
||||
return entityType == EntityType.PLAYER;
|
||||
}
|
||||
|
||||
private void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public void setWatcherClass(Class c) {
|
||||
watcherClass = c;
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.PacketsManager;
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utils.PacketsManager;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
|
||||
public class FlagWatcher {
|
||||
public enum SlotType {
|
||||
@ -110,7 +110,7 @@ public class FlagWatcher {
|
||||
}
|
||||
}
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) {
|
||||
if (disguise.isSelfDisguiseVisible() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
// Its a health packet
|
||||
if (watch.getIndex() == 6) {
|
||||
|
@ -83,8 +83,8 @@ public class MiscDisguise extends Disguise {
|
||||
|
||||
@Override
|
||||
public MiscDisguise clone() {
|
||||
MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getData());
|
||||
disguise.setViewSelfDisguise(viewSelfDisguise());
|
||||
MiscDisguise disguise = new MiscDisguise(getType(), isSoundsReplaced(), getData());
|
||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||
disguise.setHearSelfDisguise(canHearSelfDisguise());
|
||||
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
|
||||
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
|
||||
|
@ -40,8 +40,8 @@ public class MobDisguise extends Disguise {
|
||||
|
||||
@Override
|
||||
public MobDisguise clone() {
|
||||
MobDisguise disguise = new MobDisguise(getType(), isAdult(), replaceSounds());
|
||||
disguise.setViewSelfDisguise(viewSelfDisguise());
|
||||
MobDisguise disguise = new MobDisguise(getType(), isAdult(), isSoundsReplaced());
|
||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||
disguise.setHearSelfDisguise(canHearSelfDisguise());
|
||||
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
|
||||
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
|
||||
|
@ -16,8 +16,8 @@ public class PlayerDisguise extends Disguise {
|
||||
|
||||
@Override
|
||||
public PlayerDisguise clone() {
|
||||
PlayerDisguise disguise = new PlayerDisguise(getName(), replaceSounds());
|
||||
disguise.setViewSelfDisguise(viewSelfDisguise());
|
||||
PlayerDisguise disguise = new PlayerDisguise(getName(), isSoundsReplaced());
|
||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||
disguise.setHearSelfDisguise(canHearSelfDisguise());
|
||||
disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
|
||||
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -2,15 +2,14 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utils.ReflectionManager;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class LivingWatcher extends FlagWatcher {
|
||||
private HashSet<Integer> potionEffects = new HashSet<Integer>();
|
||||
static Object[] list;
|
||||
static Method potionNo;
|
||||
static {
|
||||
@ -33,6 +32,7 @@ public class LivingWatcher extends FlagWatcher {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
private HashSet<Integer> potionEffects = new HashSet<Integer>();
|
||||
|
||||
public LivingWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
@ -72,35 +72,6 @@ public class LivingWatcher extends FlagWatcher {
|
||||
return (Byte) getValue(8, (byte) 0) == 1;
|
||||
}
|
||||
|
||||
public boolean hasCustomName() {
|
||||
return getCustomName().length() > 0;
|
||||
}
|
||||
|
||||
public boolean hasPotionEffect(PotionEffectType type) {
|
||||
return potionEffects.contains(type.getId());
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
return (Byte) getValue(11, (byte) 0) == 1;
|
||||
}
|
||||
|
||||
public void removePotionEffect(PotionEffectType type) {
|
||||
if (potionEffects.contains(type.getId())) {
|
||||
potionEffects.remove(type.getId());
|
||||
sendPotionEffects();
|
||||
}
|
||||
}
|
||||
|
||||
public void removePotionParticles(boolean particles) {
|
||||
setValue(8, (byte) (particles ? 1 : 0));
|
||||
sendData(8);
|
||||
}
|
||||
|
||||
private void sendPotionEffects() {
|
||||
setValue(7, getPotions());
|
||||
sendData(7);
|
||||
}
|
||||
|
||||
private int getPotions() {
|
||||
int m = 3694022;
|
||||
|
||||
@ -131,6 +102,35 @@ public class LivingWatcher extends FlagWatcher {
|
||||
return (int) f1 << 16 | (int) f2 << 8 | (int) f3;
|
||||
}
|
||||
|
||||
public boolean hasCustomName() {
|
||||
return getCustomName().length() > 0;
|
||||
}
|
||||
|
||||
public boolean hasPotionEffect(PotionEffectType type) {
|
||||
return potionEffects.contains(type.getId());
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
return (Byte) getValue(11, (byte) 0) == 1;
|
||||
}
|
||||
|
||||
public void removePotionEffect(PotionEffectType type) {
|
||||
if (potionEffects.contains(type.getId())) {
|
||||
potionEffects.remove(type.getId());
|
||||
sendPotionEffects();
|
||||
}
|
||||
}
|
||||
|
||||
public void removePotionParticles(boolean particles) {
|
||||
setValue(8, (byte) (particles ? 1 : 0));
|
||||
sendData(8);
|
||||
}
|
||||
|
||||
private void sendPotionEffects() {
|
||||
setValue(7, getPotions());
|
||||
sendData(7);
|
||||
}
|
||||
|
||||
public void setCustomName(String name) {
|
||||
if (name.length() > 64)
|
||||
name = name.substring(0, 64);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.libraryaddict.disguise;
|
||||
package me.libraryaddict.disguise.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
138
src/me/libraryaddict/disguise/utils/DisguiseUtilities.java
Normal file
138
src/me/libraryaddict/disguise/utils/DisguiseUtilities.java
Normal file
@ -0,0 +1,138 @@
|
||||
package me.libraryaddict.disguise.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
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;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
|
||||
public class DisguiseUtilities {
|
||||
// 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>();
|
||||
// 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>();
|
||||
|
||||
public static HashMap<Integer, Disguise> getDisguises() {
|
||||
return disguises;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Integer> getSelfDisguisesIds() {
|
||||
return selfDisguisesIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Resends
|
||||
* the entity to all the watching players, which is where the magic begins
|
||||
*/
|
||||
public static void refreshTrackers(Entity entity) {
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(entity.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, entity.getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
||||
Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
HashSet cloned = (HashSet) trackedPlayers.clone();
|
||||
for (Object player : cloned) {
|
||||
if (entity instanceof Player && !((Player) getBukkitEntity.invoke(player)).canSee((Player) entity))
|
||||
continue;
|
||||
clear.invoke(entityTrackerEntry, player);
|
||||
updatePlayer.invoke(entityTrackerEntry, player);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public 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
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(player.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, player.getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
// If the tracker exists. Remove himself from his tracker
|
||||
trackedPlayers.remove(ReflectionManager.getNmsEntity(player));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}// 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());
|
||||
packetMetadata.getWatchableCollectionModifier().write(0,
|
||||
WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects());
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup it so he can see himself when disguised
|
||||
*/
|
||||
public static void setupFakeDisguise(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
|
||||
DisguiseUtilities.removeSelfDisguise(player);
|
||||
// If the disguised player can't see himself. Return
|
||||
if (!disguise.isSelfDisguiseVisible() || !PacketsManager.isViewDisguisesListenerEnabled() || player.getVehicle() != null)
|
||||
return;
|
||||
try {
|
||||
// Grab the entity ID the fake disguise will use
|
||||
Field field = ReflectionManager.getNmsClass("Entity").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);
|
||||
if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
|
||||
if (PacketsManager.isInventoryListenerEnabled()) {
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.libraryaddict.disguise;
|
||||
package me.libraryaddict.disguise.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -8,6 +8,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseSound;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
@ -50,7 +52,6 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
public class PacketsManager {
|
||||
private static boolean cancelSound;
|
||||
private static DisguiseAPI disguiseAPI = new DisguiseAPI();
|
||||
private static PacketListener inventoryListenerClient;
|
||||
private static PacketListener inventoryListenerServer;
|
||||
private static boolean inventoryModifierEnabled;
|
||||
@ -60,7 +61,7 @@ public class PacketsManager {
|
||||
private static PacketListener viewDisguisesListener;
|
||||
private static boolean viewDisguisesListenerEnabled;
|
||||
|
||||
protected static void addPacketListeners(final JavaPlugin libsDisguises) {
|
||||
public static void addPacketListeners(JavaPlugin libsDisguises) {
|
||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||
manager.addPacketListener(new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGH,
|
||||
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ENTITY_METADATA, Packets.Server.ARM_ANIMATION,
|
||||
@ -385,7 +386,7 @@ public class PacketsManager {
|
||||
/**
|
||||
* Creates the packet listeners
|
||||
*/
|
||||
protected static void init(LibsDisguises plugin) {
|
||||
public static void init(LibsDisguises plugin) {
|
||||
libsDisguises = plugin;
|
||||
soundsListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL,
|
||||
Packets.Server.NAMED_SOUND_EFFECT, Packets.Server.ENTITY_STATUS) {
|
||||
@ -451,7 +452,7 @@ public class PacketsManager {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(disguisedEntity);
|
||||
if (disguise != null) {
|
||||
if (disguise.canHearSelfDisguise() || disguisedEntity != event.getPlayer()) {
|
||||
if (disguise.replaceSounds()) {
|
||||
if (disguise.isSoundsReplaced()) {
|
||||
String sound = null;
|
||||
DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name());
|
||||
if (dSound != null && soundType != null)
|
||||
@ -694,7 +695,7 @@ public class PacketsManager {
|
||||
if (event.getPlayer().getVehicle() == null && event.getPacket().getIntegers().read(0) == 0) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
|
||||
// If the player is disguised, views self disguises and is hiding a item.
|
||||
if (disguise != null && disguise.viewSelfDisguise()
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
switch (event.getPacketID()) {
|
||||
// If the server is setting the slot
|
||||
@ -785,7 +786,7 @@ public class PacketsManager {
|
||||
if (event.getPlayer().getVehicle() == null) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
|
||||
// If player is disguised, views self disguises and has a inventory modifier
|
||||
if (disguise != null && disguise.viewSelfDisguise()
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
switch (event.getPacketID()) {
|
||||
// If they are in creative and clicked on a slot
|
||||
@ -1089,7 +1090,7 @@ public class PacketsManager {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player);
|
||||
if (disguise != null) {
|
||||
if (viewDisguisesListenerEnabled && disguise.viewSelfDisguise()
|
||||
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
player.updateInventory();
|
||||
}
|
||||
@ -1109,11 +1110,11 @@ public class PacketsManager {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player);
|
||||
if (disguise != null) {
|
||||
if (disguise.viewSelfDisguise()) {
|
||||
if (disguise.isSelfDisguiseVisible()) {
|
||||
if (enabled) {
|
||||
disguiseAPI.setupFakeDisguise(disguise);
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
} else {
|
||||
disguiseAPI.removeVisibleDisguise(player);
|
||||
DisguiseUtilities.removeSelfDisguise(player);
|
||||
}
|
||||
if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
player.updateInventory();
|
@ -1,4 +1,4 @@
|
||||
package me.libraryaddict.disguise;
|
||||
package me.libraryaddict.disguise.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@ -45,40 +45,6 @@ public class ReflectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getEnumArt(Art art) {
|
||||
try {
|
||||
Class craftArt = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftArt");
|
||||
Object enumArt = craftArt.getMethod("BukkitToNotch", Art.class).invoke(null, art);
|
||||
for (Field field : enumArt.getClass().getFields()) {
|
||||
if (field.getType() == String.class) {
|
||||
return (String) field.get(enumArt);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getNmsEntity(Entity entity) {
|
||||
try {
|
||||
return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCraftSound(Sound sound) {
|
||||
try {
|
||||
Class c = getCraftClass("CraftSound");
|
||||
return (String) c.getMethod("getSound", Sound.class).invoke(null, sound);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object createEntityInstance(String entityName) {
|
||||
try {
|
||||
Class entityClass = getNmsClass("Entity" + entityName);
|
||||
@ -101,6 +67,49 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getBukkitItem(Object nmsItem) {
|
||||
try {
|
||||
return (ItemStack) itemClass.getMethod("asBukkitCopy", getNmsClass("ItemStack")).invoke(null, nmsItem);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Class getCraftClass(String className) {
|
||||
try {
|
||||
return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + "." + className);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getCraftSound(Sound sound) {
|
||||
try {
|
||||
Class c = getCraftClass("CraftSound");
|
||||
return (String) c.getMethod("getSound", Sound.class).invoke(null, sound);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getEnumArt(Art art) {
|
||||
try {
|
||||
Class craftArt = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftArt");
|
||||
Object enumArt = craftArt.getMethod("BukkitToNotch", Art.class).invoke(null, art);
|
||||
for (Field field : enumArt.getClass().getFields()) {
|
||||
if (field.getType() == String.class) {
|
||||
return (String) field.get(enumArt);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Class getNmsClass(String className) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + bukkitVersion + "." + className);
|
||||
@ -110,9 +119,18 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Class getCraftClass(String className) {
|
||||
public static Object getNmsEntity(Entity entity) {
|
||||
try {
|
||||
return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + "." + className);
|
||||
return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getNmsItem(ItemStack itemstack) {
|
||||
try {
|
||||
return itemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemstack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -137,22 +155,4 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getNmsItem(ItemStack itemstack) {
|
||||
try {
|
||||
return itemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemstack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getBukkitItem(Object nmsItem) {
|
||||
try {
|
||||
return (ItemStack) itemClass.getMethod("asBukkitCopy", getNmsClass("ItemStack")).invoke(null, nmsItem);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.libraryaddict.disguise;
|
||||
package me.libraryaddict.disguise.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
Loading…
Reference in New Issue
Block a user