Minor code cleanup, cancel velocity packets the player shouldn't see. Fixes #331
This commit is contained in:
@@ -81,6 +81,25 @@ public class DisguiseUtilities {
|
||||
private static Gson gson;
|
||||
private static boolean pluginsUsed, commandsUsed;
|
||||
private static long libsDisguisesCalled;
|
||||
/**
|
||||
* Keeps track of what tick this occured
|
||||
*/
|
||||
private static long velocityTime;
|
||||
private static int velocityID;
|
||||
|
||||
public static void setPlayerVelocity(Player player) {
|
||||
velocityID = player.getEntityId();
|
||||
velocityTime = player.getWorld().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this velocity is due to a PlayerVelocityEvent
|
||||
*/
|
||||
public static boolean isPlayerVelocity(Player player) {
|
||||
// Be generous with how many ticks they have until they jump, the server could be lagging and the player
|
||||
// would effectively have anti-knockback
|
||||
return player.getEntityId() == velocityID && (player.getWorld().getTime() - velocityTime) < 3;
|
||||
}
|
||||
|
||||
public static void setPluginsUsed() {
|
||||
if (libsDisguisesCalled > System.currentTimeMillis()) {
|
||||
|
@@ -12,6 +12,7 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
@@ -168,6 +169,11 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
packet.getBytes().read(0) == 2) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (event.getPacketType() == Server.ENTITY_VELOCITY &&
|
||||
!DisguiseUtilities.isPlayerVelocity(observer)) {
|
||||
// The player only sees velocity changes when there is a velocity event. As the method claims there
|
||||
// was no velocity event...
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
Reference in New Issue
Block a user