Minor code cleanup, cancel velocity packets the player shouldn't see. Fixes #331
This commit is contained in:
parent
f883e96028
commit
23e63a5a63
@ -244,6 +244,11 @@ public class DisguiseListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onVelocity(PlayerVelocityEvent event) {
|
||||||
|
DisguiseUtilities.setPlayerVelocity(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onAttack(EntityDamageByEntityEvent event) {
|
public void onAttack(EntityDamageByEntityEvent event) {
|
||||||
if (DisguiseConfig.isDisguiseBlownWhenAttacked() && event.getEntity() instanceof Player) {
|
if (DisguiseConfig.isDisguiseBlownWhenAttacked() && event.getEntity() instanceof Player) {
|
||||||
|
@ -44,19 +44,19 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity player = Bukkit.getPlayer(args[0]);
|
Entity entity = Bukkit.getPlayer(args[0]);
|
||||||
|
|
||||||
if (player == null) {
|
if (entity == null) {
|
||||||
if (args[0].contains("-")) {
|
if (args[0].contains("-")) {
|
||||||
try {
|
try {
|
||||||
player = Bukkit.getEntity(UUID.fromString(args[0]));
|
entity = Bukkit.getEntity(UUID.fromString(args[0]));
|
||||||
}
|
}
|
||||||
catch (Exception ignored) {
|
catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null) {
|
if (entity == null) {
|
||||||
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
|
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -95,14 +95,14 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
|
|
||||||
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
disguise.getWatcher().setCustomName(getDisplayName(player));
|
disguise.getWatcher().setCustomName(getDisplayName(entity));
|
||||||
|
|
||||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||||
disguise.getWatcher().setCustomNameVisible(true);
|
disguise.getWatcher().setCustomNameVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
disguise.setEntity(player);
|
disguise.setEntity(entity);
|
||||||
|
|
||||||
if (!setViewDisguise(args)) {
|
if (!setViewDisguise(args)) {
|
||||||
// They prefer to have the opposite of whatever the view disguises option is
|
// They prefer to have the opposite of whatever the view disguises option is
|
||||||
@ -115,11 +115,11 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
|
|
||||||
if (disguise.isDisguiseInUse()) {
|
if (disguise.isDisguiseInUse()) {
|
||||||
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG
|
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG
|
||||||
.get(player instanceof Player ? player.getName() : DisguiseType.getType(player).toReadable(),
|
.get(entity instanceof Player ? entity.getName() : DisguiseType.getType(entity).toReadable(),
|
||||||
disguise.getType().toReadable()));
|
disguise.getType().toReadable()));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL
|
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL
|
||||||
.get(player instanceof Player ? player.getName() : DisguiseType.getType(player).toReadable(),
|
.get(entity instanceof Player ? entity.getName() : DisguiseType.getType(entity).toReadable(),
|
||||||
disguise.getType().toReadable()));
|
disguise.getType().toReadable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,18 +257,24 @@ public abstract class Disguise {
|
|||||||
|
|
||||||
StructureModifier<Integer> mods = velocityPacket.getIntegers();
|
StructureModifier<Integer> mods = velocityPacket.getIntegers();
|
||||||
|
|
||||||
|
// Write entity ID
|
||||||
|
mods.write(0, getEntity().getEntityId());
|
||||||
mods.write(1, (int) (vector.getX() * 8000));
|
mods.write(1, (int) (vector.getX() * 8000));
|
||||||
mods.write(3, (int) (vector.getZ() * 8000));
|
mods.write(3, (int) (vector.getZ() * 8000));
|
||||||
|
|
||||||
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
|
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
|
||||||
|
PacketContainer tempVelocityPacket = velocityPacket.shallowClone();
|
||||||
|
mods = tempVelocityPacket.getIntegers();
|
||||||
|
|
||||||
|
// If the viewing player is the disguised player
|
||||||
if (getEntity() == player) {
|
if (getEntity() == player) {
|
||||||
|
// If not using self disguise, continue
|
||||||
if (!isSelfDisguiseVisible()) {
|
if (!isSelfDisguiseVisible()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write self disguise ID
|
||||||
mods.write(0, DisguiseAPI.getSelfDisguiseId());
|
mods.write(0, DisguiseAPI.getSelfDisguiseId());
|
||||||
} else {
|
|
||||||
mods.write(0, getEntity().getEntityId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mods.write(2,
|
mods.write(2,
|
||||||
@ -280,7 +286,7 @@ public abstract class Disguise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProtocolLibrary.getProtocolManager()
|
ProtocolLibrary.getProtocolManager()
|
||||||
.sendServerPacket(player, velocityPacket.shallowClone(), false);
|
.sendServerPacket(player, tempVelocityPacket, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -81,6 +81,25 @@ public class DisguiseUtilities {
|
|||||||
private static Gson gson;
|
private static Gson gson;
|
||||||
private static boolean pluginsUsed, commandsUsed;
|
private static boolean pluginsUsed, commandsUsed;
|
||||||
private static long libsDisguisesCalled;
|
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() {
|
public static void setPluginsUsed() {
|
||||||
if (libsDisguisesCalled > System.currentTimeMillis()) {
|
if (libsDisguisesCalled > System.currentTimeMillis()) {
|
||||||
|
@ -12,6 +12,7 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
|||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
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.LibsPackets;
|
||||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
@ -168,6 +169,11 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
|||||||
packet.getBytes().read(0) == 2) {
|
packet.getBytes().read(0) == 2) {
|
||||||
event.setCancelled(true);
|
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) {
|
catch (Exception ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user