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:
parent
7a3f764581
commit
15b4a6e935
@ -24,6 +24,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
|||||||
import org.bukkit.Art;
|
import org.bukkit.Art;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.entity.Damageable;
|
import org.bukkit.entity.Damageable;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -305,13 +306,14 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
|||||||
|
|
||||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||||
if (NmsVersion.v1_13.isSupported()) {
|
if (NmsVersion.v1_13.isSupported()) {
|
||||||
|
BlockData block = ((FallingBlockWatcher) disguise.getWatcher()).getBlockData();
|
||||||
|
|
||||||
|
data = ReflectionManager.getCombinedIdByBlockData(block);
|
||||||
} else {
|
} else {
|
||||||
ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock();
|
ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock();
|
||||||
data = ReflectionManager.getCombinedIdByItemStack(block);
|
data = ReflectionManager.getCombinedIdByItemStack(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
|
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
|
||||||
// Center the block
|
// Center the block
|
||||||
x = loc.getBlockX() + 0.5;
|
x = loc.getBlockX() + 0.5;
|
||||||
|
@ -22,6 +22,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class PacketListenerSounds extends PacketAdapter {
|
public class PacketListenerSounds extends PacketAdapter {
|
||||||
@ -31,6 +32,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
*/
|
*/
|
||||||
private static boolean cancelSound;
|
private static boolean cancelSound;
|
||||||
private Object stepSoundEffect;
|
private Object stepSoundEffect;
|
||||||
|
private Method getHealth, getSomething;
|
||||||
|
|
||||||
public PacketListenerSounds(LibsDisguises plugin) {
|
public PacketListenerSounds(LibsDisguises plugin) {
|
||||||
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
|
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
|
||||||
@ -95,25 +97,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object obj = null;
|
if ((!(entity instanceof LivingEntity)) || ((LivingEntity) entity).getHealth() > 0) {
|
||||||
|
|
||||||
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) {
|
|
||||||
boolean hasInvun = false;
|
boolean hasInvun = false;
|
||||||
|
|
||||||
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
||||||
@ -134,6 +118,8 @@ public class PacketListenerSounds extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
soundType = entitySound.getType(soundEffectObj, !hasInvun);
|
soundType = entitySound.getType(soundEffectObj, !hasInvun);
|
||||||
|
} else {
|
||||||
|
soundType = SoundType.DEATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soundType != null) {
|
if (soundType != null) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@ public enum LibsMsg {
|
|||||||
BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"),
|
BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"),
|
||||||
EXPIRED_DISGUISE(ChatColor.RED + "Your disguise has expired!"),
|
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(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(ChatColor.RED + "Cannot find the player/uuid '%s'"),
|
||||||
CANNOT_FIND_PLAYER_NAME(ChatColor.RED + "Cannot find the player '%s'"),
|
CANNOT_FIND_PLAYER_NAME(ChatColor.RED + "Cannot find the player '%s'"),
|
||||||
CANNOT_FIND_PLAYER_UUID(ChatColor.RED + "Cannot find the uuid '%s'"),
|
CANNOT_FIND_PLAYER_UUID(ChatColor.RED + "Cannot find the uuid '%s'"),
|
||||||
|
Loading…
Reference in New Issue
Block a user