Clean a fair bit of reflection calls, still some left over.. Performance boost. Also fixed /disguise not spacing the disguises you can use

This commit is contained in:
libraryaddict 2020-08-13 11:51:32 +12:00
parent 7a3f764581
commit 15b4a6e935
4 changed files with 273 additions and 317 deletions

View File

@ -24,6 +24,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.Art;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@ -305,13 +306,14 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
if (NmsVersion.v1_13.isSupported()) {
BlockData block = ((FallingBlockWatcher) disguise.getWatcher()).getBlockData();
data = ReflectionManager.getCombinedIdByBlockData(block);
} else {
ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock();
data = ReflectionManager.getCombinedIdByItemStack(block);
}
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
// Center the block
x = loc.getBlockX() + 0.5;

View File

@ -22,6 +22,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;
public class PacketListenerSounds extends PacketAdapter {
@ -31,6 +32,7 @@ public class PacketListenerSounds extends PacketAdapter {
*/
private static boolean cancelSound;
private Object stepSoundEffect;
private Method getHealth, getSomething;
public PacketListenerSounds(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
@ -95,25 +97,7 @@ public class PacketListenerSounds extends PacketAdapter {
continue;
}
Object obj = null;
if (entity instanceof LivingEntity) {
try {
// Use reflection so that this works for either int or double methods
obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
soundType = SoundType.DEATH;
} else {
obj = null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
if (obj == null) {
if ((!(entity instanceof LivingEntity)) || ((LivingEntity) entity).getHealth() > 0) {
boolean hasInvun = false;
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
@ -134,6 +118,8 @@ public class PacketListenerSounds extends PacketAdapter {
}
soundType = entitySound.getType(soundEffectObj, !hasInvun);
} else {
soundType = SoundType.DEATH;
}
if (soundType != null) {

View File

@ -18,7 +18,7 @@ public enum LibsMsg {
BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"),
EXPIRED_DISGUISE(ChatColor.RED + "Your disguise has expired!"),
CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises:" + ChatColor.GREEN + " %s"),
CAN_USE_DISGS_SEPERATOR(ChatColor.RED + "," + ChatColor.GREEN),
CAN_USE_DISGS_SEPERATOR(ChatColor.RED + ", " + ChatColor.GREEN),
CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player/uuid '%s'"),
CANNOT_FIND_PLAYER_NAME(ChatColor.RED + "Cannot find the player '%s'"),
CANNOT_FIND_PLAYER_UUID(ChatColor.RED + "Cannot find the uuid '%s'"),