Added disable metadata packet - Aka cached
This commit is contained in:
parent
eb712a06b9
commit
ae06e527be
@ -86,9 +86,15 @@ PacketsEnabled:
|
||||
# Entity enquipment is the packets that are sent to ensure that a disguise has or doesn't have armor, and their held item.
|
||||
# Disabling this means that any disguises which can wear armor or hold items will show the armor/held item that the disguised is wearing.
|
||||
Enquipment: true
|
||||
# This doesn't actually disable the packet. It would introduce problems. Instead it does the next best thing and caches the data.
|
||||
# This means that entity metadata will not change, and will only be sent in the spawn packet.
|
||||
# This is good if performance is extremely in need.
|
||||
# This is bad to disable unless you are ONLY going to use the disguises for decorations.
|
||||
# To be honest. This is basically "Disable entity animations". That option is called 'AddEntityAnimations' in the config but unlike that, this is always in effect.
|
||||
Metadata: true
|
||||
# Movement packets are the biggest cpu hit. These are majorly used to ensure that the disguises facing direction isn't bugged up
|
||||
Movement: true
|
||||
# Disable this if you don't mind crashing everytime you see someone riding something disguised as a non-living entity
|
||||
Riding: true
|
||||
# When disguised as a wither skull, it sends a look packet every tick so that the wither skull is facing the right way.
|
||||
WitherSkull: true
|
||||
WitherSkull: true
|
@ -22,6 +22,7 @@ public class DisguiseConfig {
|
||||
private static boolean movementEnabled;
|
||||
private static boolean removeUnseenDisguises;
|
||||
private static boolean ridingEnabled;
|
||||
private static boolean sendsEntityMetadata;
|
||||
private static boolean sendVelocity;
|
||||
private static boolean showNameAboveHead;
|
||||
private static boolean showNameAboveHeadAlwaysVisible;
|
||||
@ -86,6 +87,10 @@ public class DisguiseConfig {
|
||||
return keepDisguisePlayerLogout;
|
||||
}
|
||||
|
||||
public static boolean isMetadataPacketsEnabled() {
|
||||
return sendsEntityMetadata;
|
||||
}
|
||||
|
||||
public static boolean isMiscDisguisesForLivingEnabled() {
|
||||
return miscDisguisesForLivingEnabled;
|
||||
}
|
||||
@ -235,6 +240,10 @@ public class DisguiseConfig {
|
||||
keepDisguisePlayerLogout = keepDisguise;
|
||||
}
|
||||
|
||||
public static void setMetadataPacketsEnabled(boolean enabled) {
|
||||
sendsEntityMetadata = enabled;
|
||||
}
|
||||
|
||||
public static void setMiscDisguisesForLivingEnabled(boolean enabled) {
|
||||
if (enabled != isMiscDisguisesForLivingEnabled()) {
|
||||
miscDisguisesForLivingEnabled = enabled;
|
||||
|
@ -106,6 +106,7 @@ public class LibsDisguises extends JavaPlugin {
|
||||
DisguiseConfig.setRidingPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Riding"));
|
||||
DisguiseConfig.setEntityStatusPacketsEnabled(getConfig().getBoolean("PacketsEnabled.EntityStatus"));
|
||||
DisguiseConfig.setCollectPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Collect"));
|
||||
DisguiseConfig.setMetadataPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Metadata"));
|
||||
try {
|
||||
// Here I use reflection to set the plugin for Disguise..
|
||||
// Kind of stupid but I don't want open API calls for a commonly used object.
|
||||
|
@ -48,6 +48,7 @@ public class FlagWatcher {
|
||||
private boolean hasDied;
|
||||
private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5];
|
||||
private HashSet<Integer> modifiedEntityAnimations = new HashSet<Integer>();
|
||||
private List<WrappedWatchableObject> watchableObjects;
|
||||
|
||||
public FlagWatcher(Disguise disguise) {
|
||||
this.disguise = (TargetedDisguise) disguise;
|
||||
@ -179,6 +180,13 @@ public class FlagWatcher {
|
||||
return backup;
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> getWatchableObjects() {
|
||||
if (watchableObjects == null) {
|
||||
rebuildWatchableObjects();
|
||||
}
|
||||
return watchableObjects;
|
||||
}
|
||||
|
||||
protected boolean hasValue(int no) {
|
||||
return entityValues.containsKey(no);
|
||||
}
|
||||
@ -207,6 +215,21 @@ public class FlagWatcher {
|
||||
return getFlag(3);
|
||||
}
|
||||
|
||||
public void rebuildWatchableObjects() {
|
||||
watchableObjects = new ArrayList<WrappedWatchableObject>();
|
||||
for (int i = 0; i <= 31; i++) {
|
||||
WrappedWatchableObject watchable = null;
|
||||
if (this.entityValues.containsKey(i) && this.entityValues.get(i) != null) {
|
||||
watchable = new WrappedWatchableObject(i, entityValues.get(i));
|
||||
} else if (this.backupEntityValues.containsKey(i) && this.backupEntityValues.get(i) != null) {
|
||||
watchable = new WrappedWatchableObject(i, backupEntityValues.get(i));
|
||||
}
|
||||
if (watchable != null) {
|
||||
watchableObjects.add(watchable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendData(int data) {
|
||||
if (getDisguise().getWatcher() == null || !DisguiseAPI.isDisguiseInUse(getDisguise()))
|
||||
return;
|
||||
@ -330,6 +353,9 @@ public class FlagWatcher {
|
||||
|
||||
protected void setValue(int no, Object value) {
|
||||
entityValues.put(no, value);
|
||||
if (!DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
this.rebuildWatchableObjects();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ public class PacketsManager {
|
||||
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
|
||||
*/
|
||||
private static boolean cancelSound;
|
||||
private static PacketListener clientInteractEntityListener;
|
||||
private static PacketListener inventoryListenerClient;
|
||||
private static PacketListener inventoryListenerServer;
|
||||
private static boolean inventoryModifierEnabled;
|
||||
@ -59,7 +60,6 @@ public class PacketsManager {
|
||||
private static PacketListener mainListener;
|
||||
private static PacketListener soundsListener;
|
||||
private static boolean soundsListenerEnabled;
|
||||
private static PacketListener clientInteractEntityListener;
|
||||
private static PacketListener viewDisguisesListener;
|
||||
private static boolean viewDisguisesListenerEnabled;
|
||||
|
||||
@ -304,8 +304,9 @@ public class PacketsManager {
|
||||
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||
try {
|
||||
List<WrappedWatchableObject> list = watcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watchableObject : flagWatcher.convert(list)) {
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher
|
||||
.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watchableObject : list) {
|
||||
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -1186,12 +1187,16 @@ public class PacketsManager {
|
||||
|
||||
// Else if the packet is sending entity metadata
|
||||
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_METADATA) {
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
packets[0].getWatchableCollectionModifier().read(0));
|
||||
packets[0] = new PacketContainer(sentPacket.getType());
|
||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
||||
newMods.write(0, entity.getEntityId());
|
||||
packets[0].getWatchableCollectionModifier().write(0, watchableObjects);
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
packets[0].getWatchableCollectionModifier().read(0));
|
||||
packets[0] = new PacketContainer(sentPacket.getType());
|
||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
||||
newMods.write(0, entity.getEntityId());
|
||||
packets[0].getWatchableCollectionModifier().write(0, watchableObjects);
|
||||
} else {
|
||||
packets = new PacketContainer[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Else if the packet is spawning..
|
||||
@ -1269,9 +1274,10 @@ public class PacketsManager {
|
||||
for (WrappedWatchableObject value : dataWatcher.getWatchableObjects()) {
|
||||
if (value.getIndex() == 0) {
|
||||
list.add(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
list = disguise.getWatcher().convert(list);
|
||||
list = DisguiseConfig.isMetadataPacketsEnabled() ? disguise.getWatcher().convert(list) : list;
|
||||
// Construct the packets to return
|
||||
PacketContainer packetBlock = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packetBlock.getModifier().write(0, entity.getEntityId());
|
||||
|
Loading…
Reference in New Issue
Block a user