Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.server.v1_7_R4;
- import java.io.DataInputStream;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.ExecutionException;
- import net.badlion.gspigot.protocol107.PacketPlayInVehicleMove;
- import net.minecraft.util.com.google.common.primitives.Doubles;
- import net.minecraft.util.io.netty.buffer.Unpooled;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.craftbukkit.v1_7_R4.SpigotTimings;
- import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
- import org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory;
- import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryView;
- import org.bukkit.craftbukkit.v1_7_R4.util.CraftChatMessage;
- import org.bukkit.craftbukkit.v1_7_R4.util.LazyPlayerSet;
- import org.bukkit.craftbukkit.v1_7_R4.util.Waitable;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Event;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.SignChangeEvent;
- import org.bukkit.event.inventory.ClickType;
- import org.bukkit.event.inventory.CraftItemEvent;
- import org.bukkit.event.inventory.InventoryAction;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryCreativeEvent;
- import org.bukkit.event.inventory.InventoryType;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.GCheatEvent;
- import org.bukkit.event.player.PlayerAnimationEvent;
- import org.bukkit.event.player.PlayerAttackEvent;
- import org.bukkit.event.player.PlayerChatEvent;
- import org.bukkit.event.player.PlayerCommandPreprocessEvent;
- import org.bukkit.event.player.PlayerInteractEntityEvent;
- import org.bukkit.event.player.PlayerItemHeldEvent;
- import org.bukkit.event.player.PlayerKickEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.event.player.PlayerTeleportEvent;
- import org.bukkit.event.player.PlayerToggleFlightEvent;
- import org.bukkit.event.player.PlayerToggleSneakEvent;
- import org.bukkit.event.player.PlayerToggleSprintEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.InventoryView;
- import org.bukkit.inventory.Recipe;
- import org.bukkit.util.NumberConversions;
- import org.spigotmc.SpigotConfig;
- public class PlayerConnection implements PacketPlayInListener {
- private static final Logger c = LogManager.getLogger();
- public final NetworkManager networkManager;
- private final MinecraftServer minecraftServer;
- public EntityPlayer player;
- private int e;
- private int f;
- private boolean g;
- private int h;
- private long i;
- private static Random j = new Random();
- private long k;
- private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle"); private int x; private IntHashMap n; private double y; private double z; private double q; public boolean checkMovement; private boolean processedDisconnect; private final CraftServer server; private int lastTick; private int lastDropTick; private int dropCount; private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 36; private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 49; private double lastPosX; private double lastPosY; private double lastPosZ; private float lastPitch; private float lastYaw; private boolean justTeleported; private boolean hasMoved; Long lastPacket; private Item lastMaterial;
- public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) { this.n = new IntHashMap();
- this.checkMovement = true;
- this.lastTick = MinecraftServer.currentTick;
- this.lastDropTick = MinecraftServer.currentTick;
- this.dropCount = 0;
- this.lastPosX = Double.MAX_VALUE;
- this.lastPosY = Double.MAX_VALUE;
- this.lastPosZ = Double.MAX_VALUE;
- this.lastPitch = Float.MAX_VALUE;
- this.lastYaw = Float.MAX_VALUE;
- this.justTeleported = false;
- this.hackDebug = false;
- this.lastKickTimestamp = 0L;
- this.realPing = 0.0D;
- this.totalPing = 0L;
- this.packetsNotReceived = 0;
- this.lastKeepAlivePacketReceivedTime = -1L;
- this.lastPacketTypeReceived = '.';
- this.lastGroundYValue = -1.0D;
- this.tickToKickOn = -1L;
- this.kickLocationX = -1.0D;
- this.kickLocationY = -1.0D;
- this.kickLocationZ = -1.0D;
- this.explosionHitTime = 0;
- this.highestYValueBeforeOnGroundSafely = -1.0D;
- this.checkNextTickForFallDamage = false;
- this.lastGroundYValueForGlideHackDetection = -1.0D;
- this.numOfHoverPacketsCounted = 0;
- this.numOfSpeedPacketsCounted = 0;
- this.numOfConsistentSpeedPacketsCounted = 0;
- this.lastSpeedMoved = -1.0D;
- this.lastHitTime = -1L;
- this.numOfNotHitPackets = 3;
- this.maxHitSpeedPacketCount = 10;
- this.maxNotHitSpeedPacketCount = 5;
- this.lastSpeedTime = -1L;
- this.maxSpeed = -1.0D;
- this.numOfMovePacketsReceived = 0;
- this.packetCountReset = false;
- this.critFlag = false;
- this.critDeltaY = -1.0D;
- this.lastCritStrike = -1L;
- this.lastAttackTime = -1L;
- this.lastMovementPacketTick = MinecraftServer.currentTick;
- this.lastMajorPacketProcessed = MinecraftServer.currentTick;
- this.numberOfPacketsReceivedSinceLastMajorTick = 0L;
- this.averageMaxPacketsPerSecond = 2.5D;
- this.lastFuckedUpPacketReceivedTick = 0L;
- this.lastHasPos = false;
- this.lastHasLook = false;
- this.lastCheckedFuckedUpPacketReceivedTick = 0L;
- this.numberOfMorePacketStrikes = 0L;
- this.processedMajorTick = false;
- this.lastHitAccuracyTick = 0L;
- this.highestHitAccuracy = 0.0F;
- this.highestHits = 0;
- this.highestSwings = 0;
- this.lastBlockGlitchFromX = 0.0D;
- this.lastBlockGlitchFromZ = 0.0D;
- this.lastBlockGlitchToX = 0.0D;
- this.lastBlockGlitchToZ = 0.0D;
- this.movesReceived = 0L;
- this.lastValidX = -1.0D;
- this.lastValidY = -1.0D;
- this.lastValidZ = -1.0D;
- this.lastPacketsQueue = new LinkedList();
- this.killAuraViolationsTypeA = 0;
- this.killAuraViolationsTypeB = 0;
- this.killAuraViolationsTypeC = new HashMap();
- this.killAuraViolationsTypeD = new HashMap();
- this.setOffTypeE = false;
- this.lastCalculatedHalfSecondTime = 0L;
- this.lastHalfSecondX = 0.0D;
- this.lastHalfSecondY = -1.0D;
- this.lastHalfSecondZ = 0.0D;
- this.keepAlives = new HashSet();
- this.lastHitMotionX = 10000.0D;
- this.lastHitMotionY = 10000.0D;
- this.lastHitMotionZ = 10000.0D;
- this.lastMotionTick = 0L;
- this.antiKBViolations = 0;
- this.lastKAPacketTick = MinecraftServer.currentTick;
- this.lastKAMovementPacket = MinecraftServer.currentTick;
- this.lastNotificationTick = MinecraftServer.currentTick;
- this.lastAttackPlayerTime = 0L;
- this.isDigging = false;
- this.digHorizontalMovement = 0;
- this.typeRStage = 0;
- this.typeRThreshold = 0;
- this.typeOStage = 0;
- this.typeOThreshold = 0;
- this.typePStage = 0;
- this.typePThreshold = 0;
- this.typePOther = 0;
- this.typeQStage = 0;
- this.typeQThreshold = 0;
- this.typeE2Swing = false;
- this.velocitiesSent = new ArrayList();
- this.velocitySentTimes = new ArrayList();
- this.positionSentTime = System.currentTimeMillis();
- this.reducedKbAmount = 0;
- this.miniJumpAmount = 0;
- this.horizontalSpeed = 1.0D;
- this.newHorizontalSpeed = 0.0D;
- this.blockFriction = 0.0D;
- this.blockFrictionX = Integer.MAX_VALUE;
- this.blockFrictionY = Integer.MAX_VALUE;
- this.blockFrictionZ = Integer.MAX_VALUE;
- this.previousHorizontalMove = 0.0D;
- this.flyTypeDAmount = 0;
- this.speedTypeDAmount = 0;
- this.criticalTypeBStage = 0;
- this.criticalTypeBHeight = 0.0D;
- this.justSentSprint = false;
- this.lastSprintViolationTime = System.currentTimeMillis();
- this.lastPlace = -1L;
- this.packets = 0;
- this.lastPlayerHitIdTypeS = 0;
- this.playerHitsTypeS = 0;
- this.lastTypeSViolationTick = 0;
- this.fakePlayerHitsTypeS = new HashMap();
- this.prplzTypeB8 = System.currentTimeMillis();
- this.prplzTypeB9 = System.currentTimeMillis(); this.minecraftServer = minecraftserver; this.networkManager = networkmanager; networkmanager.a(this); this.player = entityplayer; entityplayer.playerConnection = this; this.server = minecraftserver.server; } public CraftPlayer getPlayer() { return (this.player == null) ? null : this.player.getBukkitEntity(); } private static final HashSet<Integer> invalidItems = new HashSet(Arrays.asList(new Integer[] { null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, (new Integer[38][36] = (new Integer[38][35] = (new Integer[38][34] = (new Integer[38][33] = (new Integer[38][32] = (new Integer[38][31] = (new Integer[38][30] = (new Integer[38][29] = (new Integer[38][28] = (new Integer[38][27] = (new Integer[38][26] = (new Integer[38][25] = (new Integer[38][24] = (new Integer[38][23] = (new Integer[38][22] = (new Integer[38][21] = (new Integer[38][20] = (new Integer[38][19] = (new Integer[38][18] = (new Integer[38][17] = (new Integer[38][16] = (new Integer[38][15] = (new Integer[38][14] = (new Integer[38][13] = (new Integer[38][12] = (new Integer[38][11] = (new Integer[38][10] = (new Integer[38][9] = (new Integer[38][8] = (new Integer[38][7] = (new Integer[38][6] = (new Integer[38][5] = (new Integer[38][4] = (new Integer[38][3] = (new Integer[38][2] = (new Integer[38][1] = (new Integer[38][0] = Integer.valueOf(8)).valueOf(9)).valueOf(10)).valueOf(11)).valueOf(26)).valueOf(34)).valueOf(36)).valueOf(43)).valueOf(51)).valueOf(52)).valueOf(55)).valueOf(59)).valueOf(60)).valueOf(62)).valueOf(63)).valueOf(64)).valueOf(68)).valueOf(71)).valueOf(74)).valueOf(75)).valueOf(83)).valueOf(90)).valueOf(92)).valueOf(93)).valueOf(94)).valueOf(104)).valueOf(105)).valueOf(115)).valueOf(117)).valueOf(118)).valueOf(119)).valueOf(125)).valueOf(127)).valueOf(132)).valueOf(140)).valueOf(141)).valueOf(142)).valueOf(144) })); public boolean hackDebug; private long lastKickTimestamp; private double realPing; private long totalPing; private int packetsNotReceived; private long lastKeepAlivePacketReceivedTime; private char lastPacketTypeReceived; public double lastGroundYValue; private long tickToKickOn; private double kickLocationX; private double kickLocationY; private double kickLocationZ; public int explosionHitTime; public double highestYValueBeforeOnGroundSafely; public boolean checkNextTickForFallDamage; private double lastGroundYValueForGlideHackDetection; private int numOfHoverPacketsCounted; public int numOfSpeedPacketsCounted; public int numOfConsistentSpeedPacketsCounted; public double lastSpeedMoved; public long lastHitTime; public int numOfNotHitPackets; private int maxHitSpeedPacketCount; private int maxNotHitSpeedPacketCount; private long lastSpeedTime; private double maxSpeed; private int numOfMovePacketsReceived; private boolean packetCountReset; private boolean critFlag; private double critDeltaY; private long lastCritStrike; public long lastAttackTime; public long lastMovementPacketTick; public long lastMajorPacketProcessed; public long numberOfPacketsReceivedSinceLastMajorTick; public double averageMaxPacketsPerSecond; public long lastFuckedUpPacketReceivedTick; public boolean lastHasPos; public boolean lastHasLook; public long lastCheckedFuckedUpPacketReceivedTick; public long numberOfMorePacketStrikes; public boolean processedMajorTick; public long lastHitAccuracyTick; public float highestHitAccuracy; public int highestHits; public int highestSwings; private double lastBlockGlitchFromX; private double lastBlockGlitchFromZ; private double lastBlockGlitchToX; private double lastBlockGlitchToZ; public long movesReceived; private double lastValidX; private double lastValidY; private double lastValidZ; public Deque<Packet> lastPacketsQueue; public int killAuraViolationsTypeA; public int killAuraViolationsTypeB; public Map<Integer, List<Long>> killAuraViolationsTypeC; public Map<Integer, List<Long>> killAuraViolationsTypeD; public boolean setOffTypeE; public long lastCalculatedHalfSecondTime; public double lastHalfSecondX; public double lastHalfSecondY; public double lastHalfSecondZ; public boolean hasMovedInHalfSecond; public long playerTime; public Set<Integer> keepAlives; public double lastHitMotionX; public void a(PacketPlayInUseEntity packetplayinuseentity) { if (packetplayinuseentity.c() == null)
- return; if (!this.player.isAlive())
- return; WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
- Entity entity = packetplayinuseentity.a(worldserver);
- if (entity == this.player) {
- disconnect("Cannot interact with self!");
- return;
- }
- this.player.v();
- if (entity == null) {
- Integer realId = (Integer)(this.player.server.getPlayerList()).fakePlayerMap.get(Integer.valueOf(packetplayinuseentity.a));
- if (realId != null) {
- entity = this.player.world.getEntity(realId.intValue());
- long now = System.currentTimeMillis();
- Iterator<Long> iter = this.fakePlayerHitsTypeS.values().iterator();
- while (iter.hasNext()) {
- if (now - ((Long)iter.next()).longValue() > 3000L) {
- iter.remove();
- }
- }
- this.fakePlayerHitsTypeS.put(Long.valueOf(packetplayinuseentity.a << 32 | realId.intValue()), Long.valueOf(now));
- int count = 0;
- for (Iterator iterator = this.fakePlayerHitsTypeS.keySet().iterator(); iterator.hasNext(); ) { long l = ((Long)iterator.next()).longValue();
- if ((l & 0xFFFFFFFFL) == realId.intValue()) {
- count++;
- } }
- if (count == 8 &&
- now - this.prplzTypeB8 > 1000L) {
- Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, this.player.getName() + " is using Kill Aura Type T (" + count + ")"));
- this.prplzTypeB8 = now;
- }
- if (count == 9 &&
- now - this.prplzTypeB9 > 1000L) {
- Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, this.player.getName() + " is using Kill Aura Type T (" + count + ")"));
- this.prplzTypeB9 = now;
- }
- }
- }
- if (entity != null) {
- if (entity instanceof EntityPlayer && !(entity instanceof net.badlion.gspigot.EntityNPC)) {
- EntityPlayer targetPlayer = (EntityPlayer)(this.minecraftServer.getPlayerList()).uuidMap.get(((EntityPlayer)entity).uniqueID);
- if (targetPlayer == null) {
- return;
- }
- }
- boolean flag = this.player.hasLineOfSight(entity);
- double d0 = 36.0D;
- if (!flag) {
- d0 = 9.0D;
- }
- if (this.player.f(entity) < d0) {
- ItemStack itemInHand = this.player.inventory.getItemInHand();
- if (packetplayinuseentity.c() == EnumEntityUseAction.INTERACT) {
- boolean triggerTagUpdate = (itemInHand != null && itemInHand.getItem() == Items.NAME_TAG && entity instanceof EntityInsentient);
- boolean triggerChestUpdate = (itemInHand != null && itemInHand.getItem() == Item.getItemOf(Blocks.CHEST) && entity instanceof EntityHorse);
- boolean triggerLeashUpdate = (itemInHand != null && itemInHand.getItem() == Items.LEASH && entity instanceof EntityInsentient);
- PlayerInteractEntityEvent event = new PlayerInteractEntityEvent(getPlayer(), entity.getBukkitEntity());
- this.server.getPluginManager().callEvent(event);
- if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.LEASH))
- {
- sendPacket(new PacketPlayOutAttachEntity(true, entity, ((EntityInsentient)entity).getLeashHolder()));
- }
- if (triggerTagUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.NAME_TAG))
- {
- sendPacket(new PacketPlayOutEntityMetadata(entity, true));
- }
- if (triggerChestUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Item.getItemOf(Blocks.CHEST))) {
- sendPacket(new PacketPlayOutEntityMetadata(entity, true));
- }
- if (event.isCancelled()) {
- return;
- }
- this.player.q(entity);
- if (itemInHand != null && itemInHand.count <= -1) {
- this.player.updateInventory(this.player.activeContainer);
- }
- }
- else if (packetplayinuseentity.c() == EnumEntityUseAction.ATTACK) {
- if (entity instanceof EntityItem || entity instanceof EntityExperienceOrb || entity instanceof EntityArrow || entity == this.player) {
- disconnect("Attempting to attack an invalid entity");
- this.minecraftServer.warning("Player " + this.player.getName() + " tried to attack an invalid entity");
- return;
- }
- PlayerAttackEvent event = new PlayerAttackEvent(this.player.getBukkitEntity());
- this.server.getPluginManager().callEvent(event);
- if (this.player.isBlocking()) {
- this.player.bA();
- }
- this.player.attack(entity);
- if (packetplayinuseentity.a == this.lastPlayerHitIdTypeS && packetplayinuseentity.a == entity.getId() && entity instanceof EntityPlayer && ((EntityPlayer)entity).fakePlayerGCheatEnabled() && entity.vehicle == null && this.playerTime - ((EntityPlayer)entity).fakeEntitySpawnTime > 0L && this.player.world.spigotConfig.fakePlayerGCheatEnabled) {
- if (this.lastTypeSViolationTick + 20 < MinecraftServer.currentTick &&
- ++this.playerHitsTypeS == 5) {
- Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, this.player.getName() + " is using Kill Aura Type U (" + this.playerHitsTypeS + ")"));
- this.playerHitsTypeS = 0;
- this.lastTypeSViolationTick = MinecraftServer.currentTick;
- }
- } else {
- this.lastPlayerHitIdTypeS = packetplayinuseentity.a;
- this.playerHitsTypeS = 0;
- }
- if (itemInHand != null && itemInHand.count <= -1)
- this.player.updateInventory(this.player.activeContainer);
- }
- }
- } }
- public double lastHitMotionY; public double lastHitMotionZ; public long lastMotionTick; public int antiKBViolations; public long lastKAPacketTick; public long lastKAMovementPacket; public long lastNotificationTick; public long lastAttackPlayerTime; public boolean isDigging; public int digHorizontalMovement; public int typeRStage; public int typeRThreshold; public int typeOStage; public int typeOThreshold; public int typePStage; public int typePThreshold; public int typePOther; public int typeQStage; public int typeQThreshold; public boolean typeE2Swing; public final List<PacketPlayOutEntityVelocity> velocitiesSent; public final List<Long> velocitySentTimes; public long positionSentTime; public int reducedKbAmount; public int miniJumpAmount; public double horizontalSpeed; public double newHorizontalSpeed; public long newHorizontalSpeedTime; public double blockFriction; public int blockFrictionX; public int blockFrictionY; public int blockFrictionZ; public double previousHorizontalMove; public int flyTypeDAmount;
- public int speedTypeDAmount;
- public void a(PacketPlayInClientCommand packetplayinclientcommand) { this.player.v();
- EnumClientCommand enumclientcommand = packetplayinclientcommand.c();
- switch (ClientCommandOrdinalWrapper.a[enumclientcommand.ordinal()])
- { case 1:
- if (this.player.viewingCredits) {
- this.minecraftServer.getPlayerList().changeDimension(this.player, 0, PlayerTeleportEvent.TeleportCause.END_PORTAL); break;
- } if (this.player.r().getWorldData().isHardcore()) {
- if (this.minecraftServer.N() && this.player.getName().equals(this.minecraftServer.M())) {
- this.player.playerConnection.disconnect("You have died. Game over, man, it's game over!");
- this.minecraftServer.U(); break;
- }
- GameProfileBanEntry gameprofilebanentry = new GameProfileBanEntry(this.player.getProfile(), (Date)null, "(You just lost the game)", (Date)null, "Death in Hardcore");
- this.minecraftServer.getPlayerList().getProfileBans().add(gameprofilebanentry);
- this.player.playerConnection.disconnect("You have died. Game over, man, it's game over!");
- break;
- }
- if (this.player.getHealth() > 0.0F) {
- return;
- }
- this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, false);
- break;
- case 2:
- this.player.getStatisticManager().a(this.player);
- break;
- case 3:
- this.player.a(AchievementList.f); break; } } public int criticalTypeBStage; public double criticalTypeBY; public double criticalTypeBHeight; public boolean justSentSprint; public long lastSprintViolationTime; private long lastPlace; private int packets; public int lastPlayerHitIdTypeS; public int playerHitsTypeS; public int lastTypeSViolationTick; public final Map<Long, Long> fakePlayerHitsTypeS; public long prplzTypeB8; public long prplzTypeB9; private boolean isSameSign(double d1, double d2) { return (((d1 < 0.0D) ? 1 : 0) == ((d2 < 0.0D) ? 1 : 0)); } private boolean isValidMotion(double d1, double d2) { return (Math.abs(d1 - d2) < 0.15D); } public void a() { if (this.networkManager.getVersion() >= 107) { double x = this.player.locX; double y = this.player.locY; double z = this.player.locZ; boolean onGround = this.player.onGround; this.player.i(); this.player.setLocation(x, y, z, this.player.yaw, this.player.pitch); this.player.onGround = onGround; } this.g = false; this.e++; this.minecraftServer.methodProfiler.a("keepAlive"); if (this.e - this.k > 10L) { this.k = this.e; this.i = d(); this.h = (int)this.i; this.packetsNotReceived++; this.keepAlives.add(Integer.valueOf(this.h)); if (this.keepAlives.size() > 120 && isAntiCheatActivated()) { disconnect("Disconnected due to lag", true); return; } sendPacket(new PacketPlayOutKeepAlive(this.h)); } if (this.packetsNotReceived >= 40 && isAntiCheatActivated()) { disconnect("Disconnected due to lag", true); return; } int spam; while ((spam = this.chatThrottle) > 0 && !chatSpamField.compareAndSet(this, spam, spam - 1)); if (this.x > 0) this.x--; if (this.player.x() > 0L && this.minecraftServer.getIdleTimeout() > 0 && MinecraftServer.ar() - this.player.x() > (this.minecraftServer.getIdleTimeout() * 1000 * 60)) disconnect("You have been idle for too long!"); } public NetworkManager b() { return this.networkManager; } public void disconnect(String s) { disconnect(s, false); } public boolean isAntiCheatActivated() { return (SpigotConfig.enableAntiCheat && MinecraftServer.tps1Above19 && !this.player.getBukkitEntity().isBypassingGCheat()); } public void disconnect(String s, boolean anticheat) { if (anticheat) if ((MinecraftServer.getServer()).tps1.getAverage() <= 19.0D) return; String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game."; PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage); if (this.server.getServer().isRunning()) this.server.getPluginManager().callEvent(event); if (event.isCancelled()) return; s = event.getReason(); ChatComponentText chatcomponenttext = new ChatComponentText(s); this.networkManager.handle(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener[] { new PlayerConnectionFuture(this, chatcomponenttext) }); a(chatcomponenttext); this.networkManager.g(); } public void a(PacketPlayInSteerVehicle packetplayinsteervehicle) { this.player.a(packetplayinsteervehicle.c(), packetplayinsteervehicle.d(), packetplayinsteervehicle.e(), packetplayinsteervehicle.f()); } public void a(PacketPlayInFlying packetplayinflying) { if (Double.isNaN(packetplayinflying.x) || Double.isNaN(packetplayinflying.y) || Double.isNaN(packetplayinflying.z) || Double.isNaN(packetplayinflying.stance)) { c.warn(this.player.getName() + " was caught trying to crash the server with an invalid position."); getPlayer().kickPlayer("NaN in position (Hacking?)"); return; } WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); boolean isAntiCheatActivated = isAntiCheatActivated(); if (isAntiCheatActivated && this.tickToKickOn != -1L && MinecraftServer.currentTick >= this.tickToKickOn) { disconnect("Flying is not enabled on this server", true); if (isDisconnected()) { String msg = String.format("%s was caught flying (Type B) at %.1f %.1f %.1f", new Object[] { this.player.getName(), Double.valueOf(this.kickLocationX), Double.valueOf(this.kickLocationY), Double.valueOf(this.kickLocationZ) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.FLY, GCheatEvent.Level.ADMIN, msg)); c.warn(this.player.getName() + " was kicked for flying!"); return; } } long numOfTicksSinceLastPacket = this.networkManager.ticksSinceLastPacket; if (isAntiCheatActivated && !this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly && this.player.vehicle == null) if (SpigotConfig.enableMassPacketHacking && this.networkManager.currentTime - this.positionSentTime > 1000L) { if (this.lastFuckedUpPacketReceivedTick == MinecraftServer.currentTick && this.lastCheckedFuckedUpPacketReceivedTick != MinecraftServer.currentTick && packetplayinflying.hasPos != this.lastHasPos && packetplayinflying.hasLook != this.lastHasLook) { if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " has some double packet bug"); this.lastCheckedFuckedUpPacketReceivedTick = MinecraftServer.currentTick; } else { this.numberOfPacketsReceivedSinceLastMajorTick++; this.lastFuckedUpPacketReceivedTick = MinecraftServer.currentTick; this.lastHasPos = packetplayinflying.hasPos; this.lastHasLook = packetplayinflying.hasLook; } if (this.hackDebug) { Bukkit.getLogger().info(numOfTicksSinceLastPacket + " " + this.numberOfPacketsReceivedSinceLastMajorTick); Bukkit.getLogger().info(packetplayinflying.x + " " + packetplayinflying.y + " " + packetplayinflying.z + " " + packetplayinflying.yaw + " " + packetplayinflying.pitch + packetplayinflying.hasPos + " " + packetplayinflying.hasLook + " " + packetplayinflying.stance); } if (!this.processedMajorTick && this.lastMajorPacketProcessed + 20L < MinecraftServer.currentTick) { long diff = MinecraftServer.currentTick - this.lastMajorPacketProcessed; this.lastMajorPacketProcessed = MinecraftServer.currentTick; this.processedMajorTick = true; if (numOfTicksSinceLastPacket > 20L) { if (this.hackDebug) Bukkit.getLogger().info("Reset because we got a flood of packets."); this.numberOfPacketsReceivedSinceLastMajorTick = 0L; this.lastFuckedUpPacketReceivedTick = 0L; this.lastCheckedFuckedUpPacketReceivedTick = 0L; this.lastHasPos = false; this.lastHasLook = false; } if (numOfTicksSinceLastPacket <= 20L && this.numberOfPacketsReceivedSinceLastMajorTick / diff >= this.averageMaxPacketsPerSecond) { if (this.hackDebug) Bukkit.getLogger().info("Increased by 1 for timer."); if (++this.numberOfMorePacketStrikes >= 3L) Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.TIMER, GCheatEvent.Level.ADMIN, this.player.getName() + " is mass packet hacking Type B VL" + this.numberOfPacketsReceivedSinceLastMajorTick)); } else if (this.numberOfMorePacketStrikes > 0L) { if (this.hackDebug) Bukkit.getLogger().info("Reduced by 1 for timer."); this.numberOfMorePacketStrikes--; } if (this.hackDebug) Bukkit.getLogger().info("Reset " + this.numberOfPacketsReceivedSinceLastMajorTick); this.numberOfPacketsReceivedSinceLastMajorTick = 0L; this.lastFuckedUpPacketReceivedTick = 0L; this.lastCheckedFuckedUpPacketReceivedTick = 0L; this.lastHasPos = false; this.lastHasLook = false; } else if (MinecraftServer.currentTick % 20 != 0) { this.processedMajorTick = false; } } this.g = true; if (!this.player.viewingCredits) { if (!this.checkMovement) { double d0 = packetplayinflying.d() - this.z; if (packetplayinflying.c() == this.y && d0 * d0 < 0.01D && packetplayinflying.e() == this.q) this.checkMovement = true; } this.lastKAMovementPacket = MinecraftServer.currentTick; CraftPlayer craftPlayer = getPlayer(); if (!this.hasMoved) { Location curPos = craftPlayer.getLocation(); this.lastPosX = curPos.getX(); this.lastPosY = curPos.getY(); this.lastPosZ = curPos.getZ(); this.lastYaw = curPos.getYaw(); this.lastPitch = curPos.getPitch(); this.hasMoved = true; } Location from = new Location(craftPlayer.getWorld(), this.lastPosX, this.lastPosY, this.lastPosZ, this.lastYaw, this.lastPitch); Location to = craftPlayer.getLocation().clone(); if (packetplayinflying.hasPos && (!packetplayinflying.hasPos || packetplayinflying.y != -999.0D || packetplayinflying.stance != -999.0D)) { to.setX(packetplayinflying.x); to.setY(packetplayinflying.y); to.setZ(packetplayinflying.z); } if (packetplayinflying.hasLook) { to.setYaw(packetplayinflying.yaw); to.setPitch(packetplayinflying.pitch); } if (isAntiCheatActivated && !this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly && this.player.vehicle == null) { if (this.lastMotionTick != 0L) if (this.lastMotionTick + 20L < MinecraftServer.currentTick) { this.lastMotionTick = 0L; this.lastHitMotionX = this.lastHitMotionY = this.lastHitMotionZ = 0.0D; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " reset kb check because long time"); if (this.lastKeepAlivePacketReceivedTime + 800L > this.networkManager.currentTime) { if (++this.antiKBViolations >= 3) { String msg = String.format("%s was caught using Anti-KB at %.1f %.1f %.1f", new Object[] { this.player.getName(), Double.valueOf(to.getX()), Double.valueOf(to.getY()), Double.valueOf(to.getZ()) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.ANTI_KB, GCheatEvent.Level.ADMIN, msg)); this.antiKBViolations = 0; } } else if (this.hackDebug) { Bukkit.getLogger().info(this.player.getName() + " is lagging too much"); } } else if (!packetplayinflying.i()) { this.lastMotionTick = 0L; this.lastHitMotionX = this.lastHitMotionY = this.lastHitMotionZ = 0.0D; if (this.antiKBViolations > 0) this.antiKBViolations--; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " reset because valid KB"); } } else { this.lastMotionTick = 0L; this.lastHitMotionX = this.lastHitMotionY = this.lastHitMotionZ = 0.0D; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " reset because creative mode"); } double delta = Math.pow(this.lastPosX - to.getX(), 2.0D) + Math.pow(this.lastPosY - to.getY(), 2.0D) + Math.pow(this.lastPosZ - to.getZ(), 2.0D); float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch()); float f4 = 0.0625F; AxisAlignedBB axisalignedbb = this.player.boundingBox.clone().grow(f4, f4, f4).a(0.0D, -0.55D, 0.0D); boolean touchingAir = !worldserver.c(axisalignedbb); if ((delta > 0.00390625D || deltaAngle > 10.0F) && this.checkMovement && !this.player.dead) { this.lastPosX = to.getX(); this.lastPosY = to.getY(); this.lastPosZ = to.getZ(); this.lastYaw = to.getYaw(); this.lastPitch = to.getPitch(); if (isAntiCheatActivated) { if (this.lastCalculatedHalfSecondTime + 500L < this.networkManager.currentTime) { this.lastCalculatedHalfSecondTime = this.networkManager.currentTime; this.lastHalfSecondX = to.getX(); this.lastHalfSecondY = to.getY(); this.lastHalfSecondZ = to.getZ(); double distanceSqrd = NumberConversions.square(to.getX() - from.getX()) + NumberConversions.square(to.getZ() - from.getZ()); if (this.hackDebug) Bukkit.getLogger().info("Distance moved " + Math.sqrt(distanceSqrd)); this.hasMovedInHalfSecond = (distanceSqrd >= 0.0225D); } boolean justTeleported = (this.lastGroundYValue == -1.0D); if (!this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly && this.player.vehicle == null) { if (this.player.onGround) { this.lastGroundYValue = from.getY(); this.numOfHoverPacketsCounted = 0; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " y position on ground: " + this.lastGroundYValue); } else { if (worldserver.containsLiquidOrClimable(axisalignedbb)) { this.lastGroundYValue = from.getY(); if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " moved in the water/ladder/vine " + from.getY()); } if (packetplayinflying.hasPos && to.getY() > 0.0D && to.getY() == from.getY() && touchingAir && this.networkManager.lastVehicleTick + 100L < MinecraftServer.currentTick) { this.numOfHoverPacketsCounted++; if (this.numOfHoverPacketsCounted >= 5) { String msg = String.format("%s is hovering. %.1f %.1f %.1f", new Object[] { this.player.getName(), Double.valueOf(to.getX()), Double.valueOf(to.getY()), Double.valueOf(to.getZ()) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.HOVER, GCheatEvent.Level.ADMIN, msg)); this.numOfHoverPacketsCounted = 0; } } else { this.numOfHoverPacketsCounted = 0; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " reset hover."); } if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " is not on the ground and has y position " + from.getY()); } if (this.lastHitTime + 1500L < this.networkManager.currentTime && this.explosionHitTime + 200 < MinecraftServer.currentTick && this.lastGroundYValue != -1.0D && to.getY() > this.lastGroundYValue + 6.0D && touchingAir) { String msg = String.format("%s was caught flying (Type C) at %.1f %.1f %.1f", new Object[] { this.player.getName(), Double.valueOf(to.getX()), Double.valueOf(to.getY()), Double.valueOf(to.getZ()) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.FLY, GCheatEvent.Level.ADMIN, msg)); } } if (this.lastGroundYValue + 1.0D < to.getY()) { this.killAuraViolationsTypeA = 0; this.killAuraViolationsTypeB = 0; } if (!this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly && this.player.vehicle == null) if (this.lastGroundYValue != -1.0D) { if (this.explosionHitTime + 200 < MinecraftServer.currentTick) { long packetDiff = (numOfTicksSinceLastPacket == 0L) ? 1L : numOfTicksSinceLastPacket; if (this.hackDebug) { Bukkit.getLogger().info(getPlayer().getName() + " moved " + Math.sqrt(NumberConversions.square(to.getX() - from.getX()) + NumberConversions.square(to.getZ() - from.getZ()))); Bukkit.getLogger().info(getPlayer().getName() + " deltaY " + Math.abs(to.getY() - from.getY())); Bukkit.getLogger().info(getPlayer().getName() + " num of ticks " + packetDiff); } double limit = 0.42D; MobEffect mobeffect = this.player.getEffect(MobEffectList.FASTER_MOVEMENT); int amplification = (mobeffect != null) ? (mobeffect.getAmplifier() + 1) : 0; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " has speed " + amplification); boolean speedIsActive = false; switch (amplification) { case 0: limit = 0.35D; break;case 1: limit = 0.39D; this.lastSpeedTime = this.networkManager.currentTime; speedIsActive = true; break;case 2: limit = 0.42D; this.lastSpeedTime = this.networkManager.currentTime; speedIsActive = true; break;default: limit = 0.35D + 0.05D * amplification; this.lastSpeedTime = this.networkManager.currentTime; speedIsActive = true; break; } double speed = Math.sqrt(NumberConversions.square(to.getX() - from.getX()) + NumberConversions.square(to.getZ() - from.getZ())); if (this.lastKeepAlivePacketReceivedTime + 1000L > this.networkManager.currentTime) { double speedWithLag = speed / packetDiff; if (speedWithLag > limit) { if (speedWithLag >= this.lastSpeedMoved) { if (!speedIsActive && this.networkManager.currentTime < this.lastSpeedTime + 2000L) { if (this.hackDebug) Bukkit.getLogger().severe("[" + this.networkManager.currentTime + "] " + this.player.getName() + " was given grace period."); } else { boolean isFalsePositive = false; double roundedFromX = Math.round(from.getX() * 10000.0D) / 10000.0D; double roundedFromZ = Math.round(from.getZ() * 10000.0D) / 10000.0D; double roundedToX = Math.round(to.getX() * 10000.0D) / 10000.0D; double roundedToZ = Math.round(to.getZ() * 10000.0D) / 10000.0D; if (roundedFromX == roundedToX || roundedFromZ == roundedToZ) { isFalsePositive = true; if (this.hackDebug) Bukkit.getLogger().severe("[" + this.networkManager.currentTime + "] " + this.player.getName() + " false positive 1"); } else if (this.lastBlockGlitchFromX == roundedFromX || this.lastBlockGlitchFromZ == roundedFromZ || this.lastBlockGlitchFromX == roundedToX || this.lastBlockGlitchFromZ == roundedToX) { isFalsePositive = true; if (this.hackDebug) Bukkit.getLogger().severe("[" + this.networkManager.currentTime + "] " + this.player.getName() + " false positive 2"); } else if (this.lastBlockGlitchToX == roundedFromX || this.lastBlockGlitchToZ == roundedFromZ || this.lastBlockGlitchToX == roundedToX || this.lastBlockGlitchToZ == roundedToX) { isFalsePositive = true; if (this.hackDebug) Bukkit.getLogger().severe("[" + this.networkManager.currentTime + "] " + this.player.getName() + " false positive 2"); } if (!isFalsePositive) { this.lastBlockGlitchFromX = roundedFromX; this.lastBlockGlitchFromZ = roundedFromZ; this.lastBlockGlitchToX = roundedToX; this.lastBlockGlitchToZ = roundedToZ; if (this.hackDebug) Bukkit.getLogger().severe("[" + this.networkManager.currentTime + "] " + this.player.getName() + " was caught sprint hacking with distance " + (speed / packetDiff)); if (++this.numOfSpeedPacketsCounted >= ((this.lastHitTime + 1500L > this.networkManager.currentTime) ? this.maxHitSpeedPacketCount : this.maxNotHitSpeedPacketCount)) { Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.DEBUG, GCheatEvent.Level.ADMIN, this.player.getName() + " is speed hacking. ADebug " + from.getX() + " " + from.getY() + " " + from.getZ())); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.DEBUG, GCheatEvent.Level.ADMIN, this.player.getName() + " is speed hacking. ADebug2 " + to.getX() + " " + to.getY() + " " + to.getZ())); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.SPEED, GCheatEvent.Level.ADMIN, this.player.getName() + " is speed hacking. Type C VL " + (Math.round(speedWithLag / limit * 10.0D) / 10.0D))); this.numOfSpeedPacketsCounted = 0; } } else { this.numOfSpeedPacketsCounted = 0; } } } else if (++this.numOfNotHitPackets >= 3) { this.numOfSpeedPacketsCounted = 0; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " was reset to not being hit 1."); } } else { if (++this.numOfNotHitPackets >= 3) { this.numOfSpeedPacketsCounted = 0; if (this.hackDebug) Bukkit.getLogger().info(this.player.getName() + " was reset to not being hit 2."); } if (this.lastHitTime + 1500L < this.networkManager.currentTime) this.lastHitTime = -1L; } } else if (this.hackDebug) { Bukkit.getLogger().info(this.player.getName() + " is lagging."); } this.lastSpeedMoved = speed / packetDiff; } else if (this.hackDebug) { Bukkit.getLogger().info(getPlayer().getName() + " is immune from explosion."); } } else if (this.hackDebug) { Bukkit.getLogger().info(getPlayer().getName() + " just teleported."); } this.lastPacketTypeReceived = 'f'; if (this.lastValidX == -1.0D) { this.lastValidX = from.getX(); this.lastValidY = from.getY(); this.lastValidZ = from.getZ(); } } if ((this.isDigging && to.getX() != this.player.locX) || to.getZ() != this.player.locZ) this.digHorizontalMovement++; if (SpigotConfig.playerMoveEventEnabled) { PlayerMoveEvent event = new PlayerMoveEvent(craftPlayer, from, to); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { this.player.playerConnection.sendPacket(new PacketPlayOutPosition(from.getX(), from.getY() + 1.6200000047683716D, from.getZ(), from.getYaw(), from.getPitch(), false)); return; } if (!to.equals(event.getTo()) && !event.isCancelled()) { this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.UNKNOWN); return; } } if (!from.equals(getPlayer().getLocation()) && this.justTeleported) { this.justTeleported = false; return; } } else if (this.lastCalculatedHalfSecondTime + 500L < this.networkManager.currentTime) { this.lastCalculatedHalfSecondTime = this.networkManager.currentTime; this.hasMovedInHalfSecond = false; } if (this.checkMovement && !this.player.dead) { if (this.player.frozen) { float yaw = this.player.yaw; float pitch = this.player.pitch; if (packetplayinflying.hasLook) { yaw = packetplayinflying.yaw; pitch = packetplayinflying.pitch; } this.player.setLocation(this.player.locX, this.player.locY, this.player.locZ, yaw, pitch); this.minecraftServer.getPlayerList().d(this.player); return; } if (this.player.vehicle != null) { float f = this.player.yaw; float f1 = this.player.pitch; this.player.vehicle.ac(); double d1 = this.player.locX; double d2 = this.player.locY; double d3 = this.player.locZ; if (packetplayinflying.k()) { f = packetplayinflying.g(); f1 = packetplayinflying.h(); } this.player.onGround = packetplayinflying.i(); if (this.networkManager.getVersion() < 107) this.player.i(); this.player.V = 0.0F; this.player.setLocation(d1, d2, d3, f, f1); if (this.player.vehicle != null) this.player.vehicle.ac(); this.minecraftServer.getPlayerList().d(this.player); if (this.checkMovement) { this.y = this.player.locX; this.z = this.player.locY; this.q = this.player.locZ; } worldserver.playerJoinedWorld(this.player); return; } if (this.player.isSleeping()) { if (this.networkManager.getVersion() < 107) this.player.i(); this.player.setLocation(this.y, this.z, this.q, this.player.yaw, this.player.pitch); worldserver.playerJoinedWorld(this.player); return; } double d0 = this.player.locY; this.y = this.player.locX; this.z = this.player.locY; this.q = this.player.locZ; double d1 = this.player.locX; double d2 = this.player.locY; double d3 = this.player.locZ; float f2 = this.player.yaw; float f3 = this.player.pitch; boolean onGround = this.player.onGround; if (packetplayinflying.j() && packetplayinflying.d() == -999.0D && packetplayinflying.f() == -999.0D) packetplayinflying.a(false); if (packetplayinflying.j()) { d1 = packetplayinflying.c(); d2 = packetplayinflying.d(); d3 = packetplayinflying.e(); double d4 = packetplayinflying.f() - packetplayinflying.d(); if (!this.player.isSleeping() && (d4 > 1.65D || d4 < 0.1D)) { disconnect("Illegal stance"); c.warn(this.player.getName() + " had an illegal stance: " + d4); return; } if (Math.abs(packetplayinflying.c()) > 3.2E7D || Math.abs(packetplayinflying.e()) > 3.2E7D) { disconnect("Illegal position"); return; } } if (packetplayinflying.k()) { f2 = packetplayinflying.g(); f3 = packetplayinflying.h(); } if (this.networkManager.getVersion() < 107) this.player.i(); this.player.V = 0.0F; this.player.setLocation(this.y, this.z, this.q, f2, f3); if (!this.checkMovement) return; double d4 = d1 - this.player.locX; double d5 = d2 - this.player.locY; double d6 = d3 - this.player.locZ; double d7 = Math.max(Math.abs(d4), Math.abs(this.player.motX)); double d8 = Math.max(Math.abs(d5), Math.abs(this.player.motY)); double d9 = Math.max(Math.abs(d6), Math.abs(this.player.motZ)); double d10 = d7 * d7 + d8 * d8 + d9 * d9; if (d10 > SpigotConfig.movedTooQuicklyThreshold && this.checkMovement && (!this.minecraftServer.N() || !this.minecraftServer.M().equals(this.player.getName()))) { c.warn(this.player.getName() + " moved too quickly! " + d4 + "," + d5 + "," + d6 + " (" + d7 + ", " + d8 + ", " + d9 + ")"); a(this.y, this.z, this.q, this.player.yaw, this.player.pitch); return; } AxisAlignedBB preBB = getBoundingBoxRounded(); boolean flag = worldserver.getCubes(this.player, preBB).isEmpty(); if (this.player.onGround && !packetplayinflying.i() && d5 > 0.0D) this.player.applyExhaustion(0.2F); if (!this.player.abilities.canFly && !this.minecraftServer.getAllowFlight()) { boolean teleport = (this.networkManager.currentTime - this.positionSentTime < 5000L); double horizontalSpeed = this.horizontalSpeed; double blockFriction = this.blockFriction; if (onGround) { horizontalSpeed *= 1.3D; blockFriction *= 0.91D; horizontalSpeed *= 0.16277136D / blockFriction * blockFriction * blockFriction; if (isAntiCheatActivated && !packetplayinflying.i() && d5 > 1.0E-4D) { horizontalSpeed += 0.2D; MobEffect jumpBoost = this.player.getEffect(MobEffectList.JUMP); if (!teleport && !this.player.world.c(this.player.boundingBox.grow(0.5D, 0.249D, 0.5D).d(0.0D, 0.25D, 0.0D)) && jumpBoost == null) { double kb = 0.0D; for (PacketPlayOutEntityVelocity packet : this.velocitiesSent) { double packetY = packet.c / 8000.0D; if (packetY > 0.0D && (kb == 0.0D || packetY < kb)) kb = packetY; } if (kb == 0.0D && d5 < 0.15D) { if (this.miniJumpAmount += 20 > 70) { this.miniJumpAmount = 0; String msg = String.format("%s uses minijumps (%.3f) at %.1f,%.1f,%.1f", new Object[] { this.player.getName(), Double.valueOf(d5), Double.valueOf(d1), Double.valueOf(d2), Double.valueOf(d3) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.CRIT, GCheatEvent.Level.ADMIN, msg)); } } else if (d5 < 0.41999998688697815D) { if (kb > 0.1D && d5 < kb * 0.99D && this.reducedKbAmount += 30 > 35) { long percent = Math.round(100.0D * d5 / kb); String msg = String.format("%s reduces their KB (%d%% %.2f/%.2f)", new Object[] { this.player.getName(), Long.valueOf(percent), Double.valueOf(d5), Double.valueOf(kb) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.ANTI_KB, GCheatEvent.Level.ADMIN, msg)); } } } } } else { horizontalSpeed = 0.026D; blockFriction = 0.91D; } if (d4 != 0.0D || d6 != 0.0D) { double horizontalMove = Math.sqrt(d4 * d4 + d6 * d6); if (this.player.inWater) horizontalSpeed *= 3.0D; if (isAntiCheatActivated && !teleport) { double speedup = (horizontalMove - this.previousHorizontalMove) / horizontalSpeed; if (speedup > 1.1D) { double kbSqrd = 0.0D; for (PacketPlayOutEntityVelocity packet : this.velocitiesSent) { double x = packet.b / 8000.0D; double z = packet.d / 8000.0D; double xz = x * x + z * z; if (xz > kbSqrd) kbSqrd = xz; } if (kbSqrd != 0.0D) { horizontalSpeed += Math.sqrt(kbSqrd); speedup = (horizontalMove - this.previousHorizontalMove) / horizontalSpeed; } } if (speedup > 1.1D) { boolean blocksNear = this.player.world.c(this.player.boundingBox.grow(1.5D, 1.5D, 1.5D)); if (!blocksNear) { if (this.flyTypeDAmount += 20 > 90) { this.flyTypeDAmount = 0; String msg = String.format("%s was caught flying Type D (%d%%) at %.1f,%.1f,%.1f", new Object[] { this.player.getName(), Integer.valueOf((int)(100.0D * speedup)), Double.valueOf(d1), Double.valueOf(d2), Double.valueOf(d3) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.FLY, GCheatEvent.Level.ADMIN, msg)); } } else if (speedup > 1.5D && this.speedTypeDAmount += 20 > 90) { this.speedTypeDAmount = 0; String msg = String.format("%s was caught speeding Type D (%d%%) at %.1f,%.1f,%.1f", new Object[] { this.player.getName(), Integer.valueOf((int)(100.0D * speedup)), Double.valueOf(d1), Double.valueOf(d2), Double.valueOf(d3) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.SPEED, GCheatEvent.Level.ADMIN, msg)); } } } this.previousHorizontalMove = horizontalMove * blockFriction; int blockX = NumberConversions.floor(d1); int blockY = NumberConversions.floor(d2); int blockZ = NumberConversions.floor(d3); if (blockX != this.blockFrictionX || blockY != this.blockFrictionY || blockZ != this.blockFrictionZ) { this.blockFriction = (this.player.world.getType(blockX, blockY - 1, blockZ)).frictionFactor; this.blockFrictionX = blockX; this.blockFrictionY = blockY; this.blockFrictionZ = blockZ; } } } this.player.move(d4, d5, d6); this.player.onGround = packetplayinflying.i(); this.player.checkMovement(d4, d5, d6); double d11 = d5; d4 = d1 - this.player.locX; d5 = d2 - this.player.locY; if (d5 > -0.5D || d5 < 0.5D) d5 = 0.0D; d6 = d3 - this.player.locZ; d10 = d4 * d4 + d5 * d5 + d6 * d6; boolean flag1 = false; if (d10 > SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.playerInteractManager.isCreative()) { flag1 = true; c.warn(this.player.getName() + " moved wrongly!"); } this.player.setLocation(d1, d2, d3, f2, f3); double dx = this.y - d1; double dy = this.z - d2; double dz = this.q - d3; if (!this.player.playerInteractManager.isCreative() && (dx != 0.0D || dy != 0.0D || dz != 0.0D)) { double m = Math.max(Math.max(Math.abs(dx) / 0.6000000238418579D, Math.abs(dy) / 1.6200000047683716D), Math.abs(dz) / 0.6000000238418579D) / 0.99D; dx /= m; dy /= m; dz /= m; AxisAlignedBB bb = getBoundingBoxRounded(); for (int i = 0; i < m; i++) { List<AxisAlignedBB> list = worldserver.getCubes(this.player, bb); if (!list.isEmpty()) for (AxisAlignedBB collision : list) { if (!preBB.b(collision)) { if (i > 0 && m > 2.0D) if (dx == 0.0D && dz == 0.0D) { String msg = String.format("%s tries to VClip %.1f blocks at %.1f,%.1f,%.1f", new Object[] { this.player.getName(), Double.valueOf(d2 - this.z), Double.valueOf(this.y), Double.valueOf(this.z), Double.valueOf(this.q) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.PHASE, GCheatEvent.Level.ADMIN, msg)); } else { String msg = String.format("%s is trying to phase at %.1f,%.1f,%.1f", new Object[] { this.player.getName(), Double.valueOf(this.y), Double.valueOf(this.z), Double.valueOf(this.q) }); Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.PHASE, GCheatEvent.Level.ADMIN, msg)); } a(this.y, this.z, this.q, f2, f3); return; } } bb.d(dx, dy, dz); } } if (this.flyTypeDAmount > 0) this.flyTypeDAmount--; if (this.speedTypeDAmount > 0) this.speedTypeDAmount--; if (this.miniJumpAmount > 0) this.miniJumpAmount--; if (this.reducedKbAmount > 0) this.reducedKbAmount--; if (!this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly && touchingAir && !this.player.frozen) { if (d11 >= -0.03125D) { this.f++; if (this.f > 80) { Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.HOVER, GCheatEvent.Level.ADMIN, this.player.getName() + " was kicked for floating too long!")); c.warn(this.player.getName() + " was kicked for floating too long!"); disconnect("Flying is not enabled on this server"); return; } } } else { this.f = 0; } this.player.onGround = packetplayinflying.i(); this.minecraftServer.getPlayerList().d(this.player); this.player.b(this.player.locY - d0, packetplayinflying.i()); } else if (this.e % 20 == 0) { a(this.y, this.z, this.q, this.player.yaw, this.player.pitch); } } } private AxisAlignedBB getBoundingBoxRounded() { AxisAlignedBB bb = this.player.boundingBox.clone(); bb.a = Math.round(bb.a * 1000000.0D) / 1000000.0D; bb.b = Math.round(bb.b * 1000000.0D) / 1000000.0D; bb.c = Math.round(bb.c * 1000000.0D) / 1000000.0D; bb.d = Math.round(bb.d * 1000000.0D) / 1000000.0D; bb.e = Math.round(bb.e * 1000000.0D) / 1000000.0D; bb.f = Math.round(bb.f * 1000000.0D) / 1000000.0D; return bb; } public void a(double d0, double d1, double d2, float f, float f1) { CraftPlayer craftPlayer = getPlayer(); Location from = craftPlayer.getLocation(); Location to = new Location(getPlayer().getWorld(), d0, d1, d2, f, f1); PlayerTeleportEvent event = new PlayerTeleportEvent(craftPlayer, from, to, PlayerTeleportEvent.TeleportCause.UNKNOWN); this.server.getPluginManager().callEvent(event); from = event.getFrom(); to = event.isCancelled() ? from : event.getTo(); teleport(to); } public void teleport(Location dest) { double d0 = dest.getX(); double d1 = dest.getY(); double d2 = dest.getZ(); float f = dest.getYaw(); float f1 = dest.getPitch(); if (Float.isNaN(f)) f = 0.0F; if (Float.isNaN(f1)) f1 = 0.0F; this.lastPosX = d0; this.lastPosY = d1; this.lastPosZ = d2; this.lastYaw = f; this.lastPitch = f1; this.justTeleported = true; this.checkMovement = false; this.y = d0; this.z = d1; this.q = d2; this.player.setLocation(d0, d1, d2, f, f1); if (this.player.frozen) { this.player.playerConnection.sendPacket(new PacketPlayOutEntityTeleport(this.player.freezeEntityId, MathHelper.floor(d0 * 32.0D), MathHelper.floor(d1 * 32.0D), MathHelper.floor(d2 * 32.0D), false, false, true, null)); this.checkMovement = true; } else { this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0, d1 + 1.6200000047683716D, d2, f, f1, false)); } this.lastGroundYValue = -1.0D; if (this.player.bossBarMessage != null) { String message = this.player.bossBarMessage; this.player.removeBossBar(); this.player.setBossBar(message, this.player.bossBarHealth); } } public void a(PacketPlayInBlockDig packetplayinblockdig) { if (!this.player.isAlive()) return; WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); if (this.hackDebug) Bukkit.getLogger().info(getPlayer().getName() + " sent dig value " + packetplayinblockdig.g()); if (getPlayer().getGameMode() == GameMode.SURVIVAL) if (packetplayinblockdig.g() == 0) { this.isDigging = true; this.typeRThreshold = 0; this.digHorizontalMovement = 0; } else if (packetplayinblockdig.g() == 1 || packetplayinblockdig.g() == 2) { this.isDigging = false; } this.player.v(); if (packetplayinblockdig.g() == 4) { if (this.lastDropTick != MinecraftServer.currentTick) { this.dropCount = 0; this.lastDropTick = MinecraftServer.currentTick; } else { this.dropCount++; if (this.dropCount >= 20) { Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.INVENTORY, GCheatEvent.Level.ADMIN, this.player.getName() + " dropped their items too quickly!")); c.warn(this.player.getName() + " dropped their items too quickly!"); disconnect("You dropped your items too quickly (Hacking?)"); return; } } this.player.a(false); } else if (packetplayinblockdig.g() == 3) { this.player.a(true); } else if (packetplayinblockdig.g() == 5) { this.player.bA(); } else { boolean flag = false; if (packetplayinblockdig.g() == 0) flag = true; if (packetplayinblockdig.g() == 1) flag = true; if (packetplayinblockdig.g() == 2) flag = true; int i = packetplayinblockdig.c(); int j = packetplayinblockdig.d(); int k = packetplayinblockdig.e(); if (flag) { double d0 = this.player.locX - i + 0.5D; double d1 = this.player.locY - j + 0.5D + 1.5D; double d2 = this.player.locZ - k + 0.5D; double d3 = d0 * d0 + d1 * d1 + d2 * d2; if (d3 > 36.0D) return; if (j >= this.minecraftServer.getMaxBuildHeight()) return; } if (packetplayinblockdig.g() == 0) { if (!this.minecraftServer.a(worldserver, i, j, k, this.player)) { this.player.playerInteractManager.dig(i, j, k, packetplayinblockdig.f()); } else { CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, i, j, k, packetplayinblockdig.f(), this.player.inventory.getItemInHand()); this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver)); TileEntity tileentity = worldserver.getTileEntity(i, j, k); if (tileentity != null) this.player.playerConnection.sendPacket(tileentity.getUpdatePacket()); } } else if (packetplayinblockdig.g() == 2) { this.player.playerInteractManager.a(i, j, k); if (worldserver.getType(i, j, k).getMaterial() != Material.AIR) this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver)); } else if (packetplayinblockdig.g() == 1) { this.player.playerInteractManager.c(i, j, k); if (worldserver.getType(i, j, k).getMaterial() != Material.AIR) this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver)); } } } public void a(PacketPlayInBlockPlace packetplayinblockplace) { if (packetplayinblockplace.hand == 1) return; boolean throttled = false; if (this.lastPlace != -1L && packetplayinblockplace.timestamp - this.lastPlace < 30L && this.packets++ >= 4) { throttled = true; } else if (packetplayinblockplace.timestamp - this.lastPlace >= 30L || this.lastPlace == -1L) { this.lastPlace = packetplayinblockplace.timestamp; this.packets = 0; } WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); if (!this.player.isAlive()) return; if (packetplayinblockplace.getFace() == 255) { if (packetplayinblockplace.getItemStack() != null && packetplayinblockplace.getItemStack().getItem() == this.lastMaterial && this.lastPacket != null && packetplayinblockplace.timestamp - this.lastPacket.longValue() < 100L) { this.lastPacket = null; return; } if (this.networkManager.getVersion() >= 107 && this.lastPacket != null && packetplayinblockplace.timestamp - this.lastPacket.longValue() < 100L) { this.lastPacket = null; return; } } else { this.lastMaterial = (packetplayinblockplace.getItemStack() == null) ? null : packetplayinblockplace.getItemStack().getItem(); this.lastPacket = Long.valueOf(packetplayinblockplace.timestamp); } boolean always = false; ItemStack itemstack = this.player.inventory.getItemInHand(); boolean flag = false; int i = packetplayinblockplace.c(); int j = packetplayinblockplace.d(); int k = packetplayinblockplace.e(); int l = packetplayinblockplace.getFace(); this.player.v(); if (packetplayinblockplace.getFace() == 255) { if (itemstack == null) return; int itemstackAmount = itemstack.count; if (!throttled) { PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack); if (event.useItemInHand() != Event.Result.DENY) this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack); } always = (itemstack.count != itemstackAmount || itemstack.getItem() == Item.getItemOf(Blocks.WATER_LILY)); } else if (packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight() - 1 && (packetplayinblockplace.getFace() == 1 || packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight())) { ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight()) }); chatmessage.getChatModifier().setColor(EnumChatFormat.RED); this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutChat(chatmessage)); flag = true; } else { Location eyeLoc = getPlayer().getEyeLocation(); double reachDistance = NumberConversions.square(eyeLoc.getX() - i) + NumberConversions.square(eyeLoc.getY() - j) + NumberConversions.square(eyeLoc.getZ() - k); if (reachDistance > ((getPlayer().getGameMode() == GameMode.CREATIVE) ? 49 : 36)) return; if (throttled || !this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l, packetplayinblockplace.h(), packetplayinblockplace.i(), packetplayinblockplace.j())) always = true; flag = true; } if (flag) { this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver)); if (l == 0) j--; if (l == 1) j++; if (l == 2) k--; if (l == 3) k++; if (l == 4) i--; if (l == 5) i++; this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver)); } itemstack = this.player.inventory.getItemInHand(); if (itemstack != null && itemstack.count <= 0) { this.player.inventory.items[this.player.inventory.itemInHandIndex] = null; itemstack = null; } if (itemstack == null || itemstack.n() == 0) { this.player.g = true; this.player.inventory.items[this.player.inventory.itemInHandIndex] = ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]); Slot slot = this.player.activeContainer.getSlot(this.player.inventory, this.player.inventory.itemInHandIndex); this.player.activeContainer.b(); this.player.g = false; if (!ItemStack.matches(this.player.inventory.getItemInHand(), packetplayinblockplace.getItemStack()) || always) sendPacketProtocolHack(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, slot.rawSlotIndex, this.player.inventory.getItemInHand())); } } public void a(IChatBaseComponent ichatbasecomponent) { if (this.processedDisconnect) return; this.processedDisconnect = true; c.info(this.player.getName() + " lost connection: " + ichatbasecomponent.c()); this.minecraftServer.az(); this.player.n(); String quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player); if (quitMessage != null && quitMessage.length() > 0) this.minecraftServer.getPlayerList().sendMessage(CraftChatMessage.fromString(quitMessage)); if (this.minecraftServer.N() && this.player.getName().equals(this.minecraftServer.M())) { c.info("Stopping singleplayer server as player logged out"); this.minecraftServer.safeShutdown(); } } public void sendPacketProtocolHack(Packet packet) { if (this.networkManager.getVersion() >= 17) { if (packet instanceof PacketPlayOutWindowItems) { PacketPlayOutWindowItems items = (PacketPlayOutWindowItems)packet; if (this.player.activeContainer instanceof ContainerEnchantTable && this.player.activeContainer.windowId == items.a) { ItemStack[] old = items.b; items.b = new ItemStack[old.length + 1]; items.b[0] = old[0]; System.arraycopy(old, 1, items.b, 2, old.length - 1); items.b[1] = new ItemStack(Items.INK_SACK, 3, 4); } } else if (packet instanceof PacketPlayOutSetSlot) { PacketPlayOutSetSlot items = (PacketPlayOutSetSlot)packet; if (this.player.activeContainer instanceof ContainerEnchantTable && this.player.activeContainer.windowId == items.a) if (items.b >= 1) items.b++; } if (this.networkManager.getVersion() >= 107) if (packet instanceof PacketPlayOutWindowItems) { PacketPlayOutWindowItems items = (PacketPlayOutWindowItems)packet; if (this.player.activeContainer instanceof ContainerBrewingStand && this.player.activeContainer.windowId == items.a) { ItemStack[] old = items.b; items.b = new ItemStack[old.length + 1]; System.arraycopy(old, 0, items.b, 0, 4); System.arraycopy(old, 4, items.b, 5, old.length - 4); items.b[4] = new ItemStack(Items.BLAZE_POWDER); } } else if (packet instanceof PacketPlayOutSetSlot) { PacketPlayOutSetSlot items = (PacketPlayOutSetSlot)packet; if (this.player.activeContainer instanceof ContainerBrewingStand && this.player.activeContainer.windowId == items.a && items.b >= 4) items.b++; } } if (packet instanceof PacketPlayOutChat) { PacketPlayOutChat packetplayoutchat = (PacketPlayOutChat)packet; EnumChatVisibility enumchatvisibility = this.player.getChatFlags(); if (enumchatvisibility == EnumChatVisibility.HIDDEN) return; if (enumchatvisibility == EnumChatVisibility.SYSTEM && !packetplayoutchat.d()) return; } if (packet == null) return; if (packet instanceof PacketPlayOutSpawnPosition) { PacketPlayOutSpawnPosition packet6 = (PacketPlayOutSpawnPosition)packet; this.player.compassTarget = new Location(getPlayer().getWorld(), packet6.x, packet6.y, packet6.z); } try { this.networkManager.handle(packet, new GenericFutureListener[0]); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.a(throwable, "Sending packet"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent"); crashreportsystemdetails.a("Packet class", new CrashReportConnectionPacketClass(this, packet)); throw new ReportedException(crashreport); } } public void sendPacket(Packet packet) { if (packet == null) return; if (packet instanceof PacketPlayOutEntityVelocity && ((PacketPlayOutEntityVelocity)packet).a == this.player.getId()) { this.velocitiesSent.add((PacketPlayOutEntityVelocity)packet); this.velocitySentTimes.add(Long.valueOf(System.currentTimeMillis())); } if (packet instanceof PacketPlayOutPosition) this.positionSentTime = System.currentTimeMillis(); try { this.networkManager.handle(packet, new GenericFutureListener[0]); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.a(throwable, "Sending packet"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent"); crashreportsystemdetails.a("Packet class", new CrashReportConnectionPacketClass(this, packet)); throw new ReportedException(crashreport); } } public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) { if (!this.player.isAlive()) return; if (packetplayinhelditemslot.c() >= 0 && packetplayinhelditemslot.c() < PlayerInventory.getHotbarSize()) { PlayerItemHeldEvent event = new PlayerItemHeldEvent(getPlayer(), this.player.inventory.itemInHandIndex, packetplayinhelditemslot.c()); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex)); this.player.v(); return; } this.player.inventory.itemInHandIndex = packetplayinhelditemslot.c(); this.player.v(); } else { Bukkit.getPluginManager().callEvent(new GCheatEvent(this.player.getBukkitEntity(), GCheatEvent.Type.INVENTORY, GCheatEvent.Level.ADMIN, this.player.getName() + " invalid hotbar selection.")); c.warn(this.player.getName() + " tried to set an invalid carried item"); disconnect("Invalid hotbar selection (Hacking?)"); } } public void a(PacketPlayInChat packetplayinchat) { if (!this.player.isAlive() || this.player.getChatFlags() == EnumChatVisibility.HIDDEN) { ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]); chatmessage.getChatModifier().setColor(EnumChatFormat.RED); sendPacketProtocolHack(new PacketPlayOutChat(chatmessage)); } else { this.player.v(); String s = packetplayinchat.c(); s = StringUtils.normalizeSpace(s); for (int i = 0; i < s.length(); i++) { if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) { if (packetplayinchat.a()) { Waitable waitable = new Waitable() { protected Object evaluate() { PlayerConnection.this.disconnect("Illegal characters in chat"); return null; } }
- ; this.minecraftServer.processQueue.add(waitable); try { waitable.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException e) { throw new RuntimeException(e); } } else { disconnect("Illegal characters in chat"); } return; } } if (!packetplayinchat.a()) { try { this.minecraftServer.server.playerCommandState = true; handleCommand(s); } finally { this.minecraftServer.server.playerCommandState = false; } } else if (s.isEmpty()) { c.warn(this.player.getName() + " tried to send an empty message"); } else if (getPlayer().isConversing()) { final String message = s; this.minecraftServer.processQueue.add(new Waitable() { protected Object evaluate() { PlayerConnection.this.getPlayer().acceptConversationInput(message); return null; } }
- ); } else if (this.player.getChatFlags() == EnumChatVisibility.SYSTEM) { ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]); chatmessage.getChatModifier().setColor(EnumChatFormat.RED); sendPacketProtocolHack(new PacketPlayOutChat(chatmessage)); } else { chat(s, true); } boolean counted = true; for (String exclude : SpigotConfig.spamExclusions) { if (exclude != null && s.startsWith(exclude)) { counted = false; break; } } if (counted && chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) if (packetplayinchat.a()) { Waitable waitable = new Waitable() { protected Object evaluate() { PlayerConnection.this.disconnect("disconnect.spam"); return null; } }
- ; this.minecraftServer.processQueue.add(waitable); try { waitable.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException e) { throw new RuntimeException(e); } } else { disconnect("disconnect.spam"); } } } public void chat(String s, boolean async) { if (s.isEmpty() || this.player.getChatFlags() == EnumChatVisibility.HIDDEN) return; if (!async && s.startsWith("/")) { handleCommand(s); } else if (this.player.getChatFlags() != EnumChatVisibility.SYSTEM) { CraftPlayer craftPlayer = getPlayer(); AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, craftPlayer, s, new LazyPlayerSet()); this.server.getPluginManager().callEvent(event); if (PlayerChatEvent.getHandlerList().getRegisteredListeners().length != 0) { final PlayerChatEvent queueEvent = new PlayerChatEvent(craftPlayer, event.getMessage(), event.getFormat(), event.getRecipients()); queueEvent.setCancelled(event.isCancelled()); Waitable waitable = new Waitable() {
- protected Object evaluate() { Bukkit.getPluginManager().callEvent(queueEvent); if (queueEvent.isCancelled()) return null; String message = String.format(queueEvent.getFormat(), new Object[] { queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage() }); this.this$0.minecraftServer.console.sendMessage(message); if (((LazyPlayerSet)queueEvent.getRecipients()).isLazy()) { for (Object player : (this.this$0.minecraftServer.getPlayerList()).players) ((EntityPlayer)player).sendMessage(CraftChatMessage.fromString(message)); } else { for (Player player : queueEvent.getRecipients()) player.sendMessage(message); } return null; }
- }; if (async) { this.minecraftServer.processQueue.add(waitable); } else { waitable.run(); } try { waitable.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException e) { throw new RuntimeException("Exception processing chat event", e.getCause()); } } else { if (event.isCancelled()) return; s = String.format(event.getFormat(), new Object[] { event.getPlayer().getDisplayName(), event.getMessage() }); this.minecraftServer.console.sendMessage(s); if (((LazyPlayerSet)event.getRecipients()).isLazy()) { for (Object recipient : (this.minecraftServer.getPlayerList()).players) ((EntityPlayer)recipient).sendMessage(CraftChatMessage.fromString(s)); } else { for (Player recipient : event.getRecipients()) recipient.sendMessage(s); } } } } private void handleCommand(String s) { SpigotTimings.playerCommandTimer.startTiming(); if (SpigotConfig.logCommands) { this; c.info(this.player.getName() + " issued server command: " + s); } CraftPlayer player = getPlayer(); PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s, new LazyPlayerSet()); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { SpigotTimings.playerCommandTimer.stopTiming(); return; } try { if (this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) { SpigotTimings.playerCommandTimer.stopTiming(); return; } } catch (CommandException ex) { player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command"); Logger.getLogger(PlayerConnection.class.getName()).log(Level.SEVERE, null, ex); SpigotTimings.playerCommandTimer.stopTiming(); return; } SpigotTimings.playerCommandTimer.stopTiming(); } public void a(PacketPlayInArmAnimation packetplayinarmanimation) { if (!this.player.isAlive()) return; this.player.v(); if (packetplayinarmanimation.d() == 1) { float f = 1.0F; float f1 = this.player.lastPitch + (this.player.pitch - this.player.lastPitch) * f; float f2 = this.player.lastYaw + (this.player.yaw - this.player.lastYaw) * f; double d0 = this.player.lastX + (this.player.locX - this.player.lastX) * f; double d1 = this.player.lastY + (this.player.locY - this.player.lastY) * f + 1.62D - this.player.height; double d2 = this.player.lastZ + (this.player.locZ - this.player.lastZ) * f; Vec3D vec3d = Vec3D.a(d0, d1, d2); float f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F); float f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F); float f5 = -MathHelper.cos(-f1 * 0.017453292F); float f6 = MathHelper.sin(-f1 * 0.017453292F); float f7 = f4 * f5; float f8 = f3 * f5; double d3 = (this.player.playerInteractManager.getGameMode() == EnumGamemode.CREATIVE) ? 5.0D : 4.5D; Vec3D vec3d1 = vec3d.add(f7 * d3, f6 * d3, f8 * d3); MovingObjectPosition movingobjectposition = this.player.world.rayTrace(vec3d, vec3d1, false); if (movingobjectposition == null || movingobjectposition.type != EnumMovingObjectType.BLOCK) CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getItemInHand()); PlayerAnimationEvent event = new PlayerAnimationEvent(getPlayer()); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) return; this.player.ba(); } } public void a(PacketPlayInEntityAction packetplayinentityaction) { if (!this.player.isAlive()) return; this.player.v(); if (packetplayinentityaction.d() == 1 || packetplayinentityaction.d() == 2) { PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(getPlayer(), (packetplayinentityaction.d() == 1) ? 1 : 0); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) return; } if (packetplayinentityaction.d() == 4 || packetplayinentityaction.d() == 5) { PlayerToggleSprintEvent event = new PlayerToggleSprintEvent(getPlayer(), (packetplayinentityaction.d() == 4) ? 1 : 0); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) return; } if (packetplayinentityaction.d() == 1) { this.player.setSneaking(true); } else if (packetplayinentityaction.d() == 2) { this.player.setSneaking(false); } else if (packetplayinentityaction.d() == 4) { this.player.setSprinting(true); if (this.player.isBlocking()) this.player.bA(); } else if (packetplayinentityaction.d() == 5) { this.player.setSprinting(false); } else if (packetplayinentityaction.d() == 3) { this.player.a(false, true, true); } else if (packetplayinentityaction.d() == 6) { if (this.player.vehicle != null && this.player.vehicle instanceof EntityHorse) ((EntityHorse)this.player.vehicle).w(packetplayinentityaction.e()); } else if (packetplayinentityaction.d() == 7 && this.player.vehicle != null && this.player.vehicle instanceof EntityHorse) { ((EntityHorse)this.player.vehicle).g(this.player); } } public void a(PacketPlayInCloseWindow packetplayinclosewindow) { if (!this.player.isAlive())
- return;
- CraftEventFactory.handleInventoryCloseEvent(this.player);
- this.player.m(); }
- public void a(PacketPlayInWindowClick packetplayinwindowclick) {
- if (!this.player.isAlive())
- return;
- this.player.v();
- if (!this.player.activeContainer.a(this.player))
- return; if (this.player.activeContainer.windowId == packetplayinwindowclick.c() && this.player.activeContainer.c(this.player)) {
- if (packetplayinwindowclick.d() < -1 && packetplayinwindowclick.d() != -999) {
- return;
- }
- InventoryView inventory = this.player.activeContainer.getBukkitView();
- if (this.networkManager.getVersion() >= 17)
- {
- if (this.player.activeContainer instanceof ContainerEnchantTable) {
- if (packetplayinwindowclick.slot == 1) {
- this.player.updateInventory(this.player.activeContainer); return;
- }
- if (packetplayinwindowclick.slot > 1)
- {
- packetplayinwindowclick.slot--;
- }
- }
- }
- if (this.networkManager.getVersion() >= 107) {
- if (this.player.activeContainer instanceof ContainerBrewingStand) {
- if (packetplayinwindowclick.slot == 4) {
- this.player.updateInventory(this.player.activeContainer);
- return;
- }
- if (packetplayinwindowclick.slot > 4) {
- packetplayinwindowclick.slot--;
- }
- }
- if (packetplayinwindowclick.c() == 0 && packetplayinwindowclick.slot == 45) {
- this.player.updateInventory(this.player.activeContainer);
- return;
- }
- }
- InventoryType.SlotType type = CraftInventoryView.getSlotType(inventory, packetplayinwindowclick.d());
- InventoryClickEvent event = null;
- ClickType click = ClickType.UNKNOWN;
- InventoryAction action = InventoryAction.UNKNOWN;
- ItemStack itemstack = null;
- if (packetplayinwindowclick.d() == -1) {
- type = InventoryType.SlotType.OUTSIDE;
- click = (packetplayinwindowclick.e() == 0) ? ClickType.WINDOW_BORDER_LEFT : ClickType.WINDOW_BORDER_RIGHT;
- action = InventoryAction.NOTHING;
- } else if (packetplayinwindowclick.h() == 0) {
- if (packetplayinwindowclick.e() == 0) {
- click = ClickType.LEFT;
- } else if (packetplayinwindowclick.e() == 1) {
- click = ClickType.RIGHT;
- }
- if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
- action = InventoryAction.NOTHING;
- if (packetplayinwindowclick.d() == -999) {
- if (this.player.inventory.getCarried() != null) {
- action = (packetplayinwindowclick.e() == 0) ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR;
- }
- } else {
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null) {
- ItemStack clickedItem = slot.getItem();
- ItemStack cursor = this.player.inventory.getCarried();
- if (clickedItem == null) {
- if (cursor != null) {
- action = (packetplayinwindowclick.e() == 0) ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE;
- }
- } else if (slot.isAllowed(this.player)) {
- if (cursor == null) {
- action = (packetplayinwindowclick.e() == 0) ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF;
- } else if (slot.isAllowed(cursor)) {
- if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) {
- int toPlace = (packetplayinwindowclick.e() == 0) ? cursor.count : 1;
- toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.count);
- toPlace = Math.min(toPlace, slot.inventory.getMaxStackSize() - clickedItem.count);
- if (toPlace == 1) {
- action = InventoryAction.PLACE_ONE;
- } else if (toPlace == cursor.count) {
- action = InventoryAction.PLACE_ALL;
- } else if (toPlace < 0) {
- action = (toPlace != -1) ? InventoryAction.PICKUP_SOME : InventoryAction.PICKUP_ONE;
- } else if (toPlace != 0) {
- action = InventoryAction.PLACE_SOME;
- }
- } else if (cursor.count <= slot.getMaxStackSize()) {
- action = InventoryAction.SWAP_WITH_CURSOR;
- }
- } else if (cursor.getItem() == clickedItem.getItem() && (!cursor.usesData() || cursor.getData() == clickedItem.getData()) && ItemStack.equals(cursor, clickedItem) &&
- clickedItem.count >= 0 &&
- clickedItem.count + cursor.count <= cursor.getMaxStackSize()) {
- action = InventoryAction.PICKUP_ALL;
- }
- }
- }
- }
- }
- } else if (packetplayinwindowclick.h() == 1) {
- if (packetplayinwindowclick.e() == 0) {
- click = ClickType.SHIFT_LEFT;
- } else if (packetplayinwindowclick.e() == 1) {
- click = ClickType.SHIFT_RIGHT;
- }
- if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
- if (packetplayinwindowclick.d() < 0) {
- action = InventoryAction.NOTHING;
- } else {
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.isAllowed(this.player) && slot.hasItem()) {
- action = InventoryAction.MOVE_TO_OTHER_INVENTORY;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- }
- } else if (packetplayinwindowclick.h() == 2) {
- if (packetplayinwindowclick.e() >= 0 && packetplayinwindowclick.e() < 9) {
- click = ClickType.NUMBER_KEY;
- Slot clickedSlot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (clickedSlot.isAllowed(this.player)) {
- ItemStack hotbar = this.player.inventory.getItem(packetplayinwindowclick.e());
- boolean canCleanSwap = (hotbar == null || (clickedSlot.inventory == this.player.inventory && clickedSlot.isAllowed(hotbar)));
- if (clickedSlot.hasItem()) {
- if (canCleanSwap) {
- action = InventoryAction.HOTBAR_SWAP;
- } else {
- int firstEmptySlot = this.player.inventory.getFirstEmptySlotIndex();
- if (firstEmptySlot > -1) {
- action = InventoryAction.HOTBAR_MOVE_AND_READD;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- } else if (!clickedSlot.hasItem() && hotbar != null && clickedSlot.isAllowed(hotbar)) {
- action = InventoryAction.HOTBAR_SWAP;
- } else {
- action = InventoryAction.NOTHING;
- }
- } else {
- action = InventoryAction.NOTHING;
- }
- event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
- }
- } else if (packetplayinwindowclick.h() == 3) {
- if (packetplayinwindowclick.e() == 2) {
- click = ClickType.MIDDLE;
- if (packetplayinwindowclick.d() == -999) {
- action = InventoryAction.NOTHING;
- } else {
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.hasItem() && this.player.abilities.canInstantlyBuild && this.player.inventory.getCarried() == null) {
- action = InventoryAction.CLONE_STACK;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- } else {
- click = ClickType.UNKNOWN;
- action = InventoryAction.UNKNOWN;
- }
- } else if (packetplayinwindowclick.h() == 4) {
- if (packetplayinwindowclick.d() >= 0) {
- if (packetplayinwindowclick.e() == 0) {
- click = ClickType.DROP;
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.hasItem() && slot.isAllowed(this.player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
- action = InventoryAction.DROP_ONE_SLOT;
- } else {
- action = InventoryAction.NOTHING;
- }
- } else if (packetplayinwindowclick.e() == 1) {
- click = ClickType.CONTROL_DROP;
- Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
- if (slot != null && slot.hasItem() && slot.isAllowed(this.player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
- action = InventoryAction.DROP_ALL_SLOT;
- } else {
- action = InventoryAction.NOTHING;
- }
- }
- } else {
- click = ClickType.LEFT;
- if (packetplayinwindowclick.e() == 1) {
- click = ClickType.RIGHT;
- }
- action = InventoryAction.NOTHING;
- }
- } else if (packetplayinwindowclick.h() == 5) {
- itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), 5, this.player);
- } else if (packetplayinwindowclick.h() == 6) {
- click = ClickType.DOUBLE_CLICK;
- action = InventoryAction.NOTHING;
- if (packetplayinwindowclick.d() >= 0 && this.player.inventory.getCarried() != null) {
- ItemStack cursor = this.player.inventory.getCarried();
- action = InventoryAction.NOTHING;
- if (inventory.getTopInventory().contains(Material.getMaterial(Item.getId(cursor.getItem()))) || inventory.getBottomInventory().contains(Material.getMaterial(Item.getId(cursor.getItem())))) {
- action = InventoryAction.COLLECT_TO_CURSOR;
- }
- }
- }
- if (packetplayinwindowclick.h() != 5) {
- CraftItemEvent craftItemEvent; if (click == ClickType.NUMBER_KEY) {
- event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
- } else {
- event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action);
- }
- Inventory top = inventory.getTopInventory();
- if (packetplayinwindowclick.d() == 0 && top instanceof CraftingInventory) {
- Recipe recipe = ((CraftingInventory)top).getRecipe();
- if (recipe != null) {
- if (click == ClickType.NUMBER_KEY) {
- craftItemEvent = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
- } else {
- craftItemEvent = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.d(), click, action);
- }
- }
- }
- this.server.getPluginManager().callEvent(craftItemEvent);
- switch (craftItemEvent.getResult()) {
- case ALLOW:
- case DEFAULT:
- itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), packetplayinwindowclick.h(), this.player);
- break;
- case DENY:
- switch (action) {
- case ALLOW:
- case DEFAULT:
- case DENY:
- case null:
- case null:
- case null:
- this.player.updateInventory(this.player.activeContainer);
- break;
- case null:
- case null:
- case null:
- case null:
- case null:
- case null:
- case null:
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(-1, -1, this.player.inventory.getCarried()));
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, packetplayinwindowclick.d(), this.player.activeContainer.getSlot(packetplayinwindowclick.d()).getItem()));
- break;
- case null:
- case null:
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, packetplayinwindowclick.d(), this.player.activeContainer.getSlot(packetplayinwindowclick.d()).getItem()));
- break;
- case null:
- case null:
- case null:
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(-1, -1, this.player.inventory.getCarried()));
- break;
- }
- return;
- }
- }
- if (ItemStack.matches(packetplayinwindowclick.g(), itemstack)) {
- this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.c(), packetplayinwindowclick.f(), true));
- this.player.g = true;
- this.player.activeContainer.b();
- this.player.broadcastCarriedItem();
- this.player.g = false;
- } else {
- this.n.a(this.player.activeContainer.windowId, Short.valueOf(packetplayinwindowclick.f()));
- this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.c(), packetplayinwindowclick.f(), false));
- this.player.activeContainer.a(this.player, false);
- ArrayList arraylist = new ArrayList();
- for (int i = 0; i < this.player.activeContainer.c.size(); i++) {
- arraylist.add(((Slot)this.player.activeContainer.c.get(i)).getItem());
- }
- this.player.a(this.player.activeContainer, arraylist);
- if (type == InventoryType.SlotType.RESULT && itemstack != null) {
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, false, itemstack));
- }
- }
- }
- }
- public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
- this.player.v();
- if (this.player.activeContainer.windowId == packetplayinenchantitem.c() && this.player.activeContainer.c(this.player)) {
- this.player.activeContainer.a(this.player, packetplayinenchantitem.d());
- this.player.activeContainer.b();
- }
- }
- public void a(PacketPlayInSetCreativeSlot packetplayinsetcreativeslot) {
- if (this.player.playerInteractManager.isCreative()) {
- boolean flag = (packetplayinsetcreativeslot.c() < 0);
- ItemStack itemstack = packetplayinsetcreativeslot.getItemStack();
- boolean flag1 = (packetplayinsetcreativeslot.c() >= 1 && packetplayinsetcreativeslot.c() < 36 + PlayerInventory.getHotbarSize());
- boolean flag2 = (itemstack == null || (itemstack.getItem() != null && (!invalidItems.contains(Integer.valueOf(Item.getId(itemstack.getItem()))) || !SpigotConfig.filterCreativeItems)));
- boolean flag3 = (itemstack == null || (itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0));
- if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.c()).getItem(), packetplayinsetcreativeslot.getItemStack()))) {
- CraftPlayer craftPlayer = this.player.getBukkitEntity();
- CraftInventoryView craftInventoryView = new CraftInventoryView(craftPlayer, craftPlayer.getInventory(), this.player.defaultContainer);
- ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getItemStack());
- InventoryType.SlotType type = InventoryType.SlotType.QUICKBAR;
- if (flag) {
- type = InventoryType.SlotType.OUTSIDE;
- } else if (packetplayinsetcreativeslot.c() < 36) {
- if (packetplayinsetcreativeslot.c() >= 5 && packetplayinsetcreativeslot.c() < 9) {
- type = InventoryType.SlotType.ARMOR;
- } else {
- type = InventoryType.SlotType.CONTAINER;
- }
- }
- InventoryCreativeEvent event = new InventoryCreativeEvent(craftInventoryView, type, flag ? -999 : packetplayinsetcreativeslot.c(), item);
- this.server.getPluginManager().callEvent(event);
- itemstack = CraftItemStack.asNMSCopy(event.getCursor());
- switch (event.getResult()) {
- case ALLOW:
- flag2 = flag3 = true;
- break;
- case DENY:
- if (packetplayinsetcreativeslot.c() >= 0) {
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(this.player.defaultContainer.windowId, packetplayinsetcreativeslot.c(), this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.c()).getItem()));
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(-1, -1, null));
- }
- return;
- }
- }
- if (flag1 && flag2 && flag3) {
- if (itemstack == null) {
- this.player.defaultContainer.setItem(packetplayinsetcreativeslot.c(), (ItemStack)null);
- } else {
- this.player.defaultContainer.setItem(packetplayinsetcreativeslot.c(), itemstack);
- }
- this.player.defaultContainer.a(this.player, true);
- } else if (flag && flag2 && flag3 && this.x < 200) {
- this.x += 20;
- EntityItem entityitem = this.player.drop(itemstack, true);
- if (entityitem != null) {
- entityitem.e();
- }
- }
- else if (flag1) {
- this.player.playerConnection.sendPacketProtocolHack(new PacketPlayOutSetSlot(false, packetplayinsetcreativeslot
- .c(), this.player.defaultContainer
- .getSlot(packetplayinsetcreativeslot.c()).getItem()));
- }
- }
- }
- public void a(PacketPlayInTransaction packetplayintransaction) {
- if (!this.player.isAlive())
- return; if (!this.player.activeContainer.a(this.player))
- return; Short oshort = (Short)this.n.get(this.player.activeContainer.windowId);
- if (oshort != null && packetplayintransaction.d() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.c() && !this.player.activeContainer.c(this.player)) {
- this.player.activeContainer.a(this.player, true);
- }
- }
- public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
- if (!this.player.isAlive())
- return;
- this.player.v();
- WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
- if (worldserver.isLoaded(packetplayinupdatesign.c(), packetplayinupdatesign.d(), packetplayinupdatesign.e())) {
- TileEntity tileentity = worldserver.getTileEntity(packetplayinupdatesign.c(), packetplayinupdatesign.d(), packetplayinupdatesign.e());
- if (tileentity instanceof TileEntitySign) {
- TileEntitySign tileentitysign = (TileEntitySign)tileentity;
- if (!tileentitysign.a() || tileentitysign.b() != this.player) {
- this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
- sendPacket(new PacketPlayOutUpdateSign(packetplayinupdatesign.c(), packetplayinupdatesign.d(), packetplayinupdatesign.e(), tileentitysign.lines));
- return;
- }
- }
- int j;
- for (j = 0; j < 4; j++) {
- boolean flag = true;
- packetplayinupdatesign.f()[j] = packetplayinupdatesign.f()[j].replaceAll("���", "").replaceAll("���", "");
- if (packetplayinupdatesign.f()[j].length() > 15) {
- flag = false;
- } else {
- for (int i = 0; i < packetplayinupdatesign.f()[j].length(); i++) {
- if (!SharedConstants.isAllowedChatCharacter(packetplayinupdatesign.f()[j].charAt(i))) {
- flag = false;
- }
- }
- }
- if (!flag) {
- packetplayinupdatesign.f()[j] = "!?";
- }
- }
- if (tileentity instanceof TileEntitySign) {
- j = packetplayinupdatesign.c();
- int k = packetplayinupdatesign.d();
- int i = packetplayinupdatesign.e();
- TileEntitySign tileentitysign1 = (TileEntitySign)tileentity;
- Player player = this.server.getPlayer(this.player);
- SignChangeEvent event = new SignChangeEvent((CraftBlock)player.getWorld().getBlockAt(j, k, i), this.server.getPlayer(this.player), packetplayinupdatesign.f());
- this.server.getPluginManager().callEvent(event);
- if (!event.isCancelled()) {
- tileentitysign1.lines = CraftSign.sanitizeLines(event.getLines());
- tileentitysign1.isEditable = false;
- }
- tileentitysign1.update();
- worldserver.notify(j, k, i);
- }
- }
- }
- public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
- this.lastPacketTypeReceived = 'k';
- boolean catchingUp = false;
- if (this.lastKeepAlivePacketReceivedTime == -1L) {
- this.lastKeepAlivePacketReceivedTime = this.networkManager.currentTime;
- } else if (this.lastKeepAlivePacketReceivedTime + 2000L < this.networkManager.currentTime) {
- catchingUp = true;
- this.lastKeepAlivePacketReceivedTime += 550L;
- } else {
- this.lastKeepAlivePacketReceivedTime = this.networkManager.currentTime;
- }
- this.packetsNotReceived--;
- if (this.player.isAlive() && !this.player.sleeping && this.lastKAPacketTick + 20L > MinecraftServer.currentTick && this.lastKAMovementPacket + 100L < MinecraftServer.currentTick &&
- this.lastNotificationTick + 20L < MinecraftServer.currentTick) {
- this.lastNotificationTick = MinecraftServer.currentTick;
- }
- this.lastKAPacketTick = MinecraftServer.currentTick;
- if (packetplayinkeepalive.c() == this.h) {
- int i = (int)(d() - this.i);
- this.player.ping = (this.player.ping * 3 + i) / 4;
- }
- }
- private long d() { return System.nanoTime() / 1000000L; }
- public void a(PacketPlayInAbilities packetplayinabilities) {
- if (this.player.abilities.canFly && this.player.abilities.isFlying != packetplayinabilities.isFlying()) {
- PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(this.server.getPlayer(this.player), packetplayinabilities.isFlying());
- this.server.getPluginManager().callEvent(event);
- if (!event.isCancelled()) {
- this.player.abilities.isFlying = packetplayinabilities.isFlying();
- } else {
- this.player.updateAbilities();
- }
- }
- }
- public void a(PacketPlayInTabComplete packetplayintabcomplete) {
- if (chatSpamField.addAndGet(this, 20) > 400 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) {
- disconnect("disconnect.spam");
- return;
- }
- ArrayList arraylist = Lists.newArrayList();
- Iterator iterator = this.minecraftServer.a(this.player, packetplayintabcomplete.c()).iterator();
- while (iterator.hasNext()) {
- String s = (String)iterator.next();
- arraylist.add(s);
- }
- this.player.playerConnection.sendPacket(new PacketPlayOutTabComplete((String[])arraylist.toArray(new String[arraylist.size()])));
- }
- public void a(PacketPlayInSettings packetplayinsettings) { this.player.a(packetplayinsettings); }
- public void a(PacketPlayInCustomPayload packetplayincustompayload) {
- if (packetplayincustompayload.length <= 0) {
- return;
- }
- if ("MC|BEdit".equals(packetplayincustompayload.c())) {
- packetdataserializer = new PacketDataSerializer(Unpooled.wrappedBuffer(packetplayincustompayload.e()), this.networkManager.getVersion());
- try {
- ItemStack itemstack = packetdataserializer.c();
- if (itemstack != null) {
- if (!ItemBookAndQuill.a(itemstack.getTag())) {
- throw new IOException("Invalid book tag!");
- }
- ItemStack itemstack1 = this.player.inventory.getItemInHand();
- if (itemstack1 == null) {
- return;
- }
- if (itemstack.getItem() == Items.BOOK_AND_QUILL && itemstack.getItem() == itemstack1.getItem()) {
- CraftEventFactory.handleEditBookEvent(this.player, itemstack);
- }
- return;
- }
- } catch (Exception exception) {
- c.error("Couldn't handle book info", exception);
- disconnect("Invalid book data!");
- return;
- } finally {
- packetdataserializer.release();
- }
- return;
- }
- if ("MC|BSign".equals(packetplayincustompayload.c())) {
- packetdataserializer = new PacketDataSerializer(Unpooled.wrappedBuffer(packetplayincustompayload.e()), this.networkManager.getVersion());
- try {
- ItemStack itemstack = packetdataserializer.c();
- if (itemstack != null) {
- if (!ItemWrittenBook.a(itemstack.getTag())) {
- throw new IOException("Invalid book tag!");
- }
- ItemStack itemstack1 = this.player.inventory.getItemInHand();
- if (itemstack1 == null) {
- return;
- }
- if (itemstack.getItem() == Items.WRITTEN_BOOK && itemstack1.getItem() == Items.BOOK_AND_QUILL) {
- CraftEventFactory.handleEditBookEvent(this.player, itemstack);
- }
- return;
- }
- } catch (Throwable exception1) {
- c.error("Couldn't sign book", exception1);
- disconnect("Invalid book data!");
- return;
- } finally {
- packetdataserializer.release();
- }
- return;
- }
- if ("MC|TrSel".equals(packetplayincustompayload.c())) {
- try {
- DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(packetplayincustompayload.e()));
- int i = datainputstream.readInt();
- Container container = this.player.activeContainer;
- if (container instanceof ContainerMerchant) {
- ((ContainerMerchant)container).e(i);
- }
- }
- catch (Throwable exception2) {
- c.error("Couldn't select trade", exception2);
- disconnect("Invalid trade data!");
- }
- } else if ("MC|AdvCdm".equals(packetplayincustompayload.c())) {
- if (!this.minecraftServer.getEnableCommandBlock()) {
- this.player.sendMessage(new ChatMessage("advMode.notEnabled", new Object[0]));
- } else if (this.player.a(2, "") && this.player.abilities.canInstantlyBuild) {
- packetdataserializer = new PacketDataSerializer(Unpooled.wrappedBuffer(packetplayincustompayload.e()));
- try {
- byte b0 = packetdataserializer.readByte();
- CommandBlockListenerAbstract commandblocklistenerabstract = null;
- if (b0 == 0) {
- TileEntity tileentity = this.player.world.getTileEntity(packetdataserializer.readInt(), packetdataserializer.readInt(), packetdataserializer.readInt());
- if (tileentity instanceof TileEntityCommand) {
- commandblocklistenerabstract = ((TileEntityCommand)tileentity).getCommandBlock();
- }
- } else if (b0 == 1) {
- Entity entity = this.player.world.getEntity(packetdataserializer.readInt());
- if (entity instanceof EntityMinecartCommandBlock) {
- commandblocklistenerabstract = ((EntityMinecartCommandBlock)entity).getCommandBlock();
- }
- }
- String s = packetdataserializer.c(packetdataserializer.readableBytes());
- if (commandblocklistenerabstract != null) {
- commandblocklistenerabstract.setCommand(s);
- commandblocklistenerabstract.e();
- this.player.sendMessage(new ChatMessage("advMode.setCommand.success", new Object[] { s }));
- }
- } catch (Throwable exception3) {
- c.error("Couldn't set command block", exception3);
- disconnect("Invalid CommandBlock data!");
- } finally {
- packetdataserializer.release();
- }
- } else {
- this.player.sendMessage(new ChatMessage("advMode.notAllowed", new Object[0]));
- }
- } else if ("MC|Beacon".equals(packetplayincustompayload.c())) {
- if (this.player.activeContainer instanceof ContainerBeacon) {
- try {
- DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(packetplayincustompayload.e()));
- int i = datainputstream.readInt();
- int j = datainputstream.readInt();
- ContainerBeacon containerbeacon = (ContainerBeacon)this.player.activeContainer;
- Slot slot = containerbeacon.getSlot(0);
- if (slot.hasItem()) {
- slot.a(1);
- TileEntityBeacon tileentitybeacon = containerbeacon.e();
- tileentitybeacon.d(i);
- tileentitybeacon.e(j);
- tileentitybeacon.update();
- }
- } catch (Throwable exception4) {
- c.error("Couldn't set beacon", exception4);
- disconnect("Invalid beacon data!");
- }
- }
- } else if ("MC|ItemName".equals(packetplayincustompayload.c()) && this.player.activeContainer instanceof ContainerAnvil) {
- ContainerAnvil containeranvil = (ContainerAnvil)this.player.activeContainer;
- if (packetplayincustompayload.e() != null && packetplayincustompayload.e().length >= 1) {
- String s1 = SharedConstants.a(new String(packetplayincustompayload.e(), Charsets.UTF_8));
- if (s1.length() <= 30) {
- containeranvil.a(s1);
- }
- } else {
- containeranvil.a("");
- }
- }
- else if (packetplayincustompayload.c().equals("REGISTER")) {
- try {
- String channels = new String(packetplayincustompayload.e(), "UTF8");
- for (String channel : channels.split("\000")) {
- getPlayer().addChannel(channel);
- }
- } catch (UnsupportedEncodingException ex) {
- throw new AssertionError(ex);
- }
- } else if (packetplayincustompayload.c().equals("UNREGISTER")) {
- try {
- String channels = new String(packetplayincustompayload.e(), "UTF8");
- for (String channel : channels.split("\000")) {
- getPlayer().removeChannel(channel);
- }
- } catch (UnsupportedEncodingException ex) {
- throw new AssertionError(ex);
- }
- } else {
- this.server.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), packetplayincustompayload.c(), packetplayincustompayload.e());
- }
- }
- public void a(EnumProtocol enumprotocol, EnumProtocol enumprotocol1) {
- if (enumprotocol1 != EnumProtocol.PLAY) {
- throw new IllegalStateException("Unexpected change in protocol!");
- }
- }
- public boolean isDisconnected() { return (!this.player.joining && !NetworkManager.a(this.networkManager).config().isAutoRead()); }
- public void handleKeepAliveSync(PacketPlayInKeepAlive packet) {
- this.keepAlives.remove(Integer.valueOf(packet.c()));
- long latency = (1000 + this.keepAlives.size() * 1000);
- this.playerTime = this.networkManager.currentTime - latency;
- Iterator it = this.velocitySentTimes.iterator();
- int i = 0;
- while (it.hasNext()) {
- long ts = ((Long)it.next()).longValue();
- if (this.hackDebug) {
- Bukkit.getLogger().info("KA velocity - ts " + ts);
- Bukkit.getLogger().info("KA velocity - latency " + latency);
- }
- if (this.networkManager.currentTime - ts > latency) {
- it.remove();
- this.velocitiesSent.remove(i);
- continue;
- }
- i++;
- }
- if (this.newHorizontalSpeed != 0.0D &&
- this.networkManager.currentTime - this.newHorizontalSpeedTime > latency) {
- this.horizontalSpeed = this.newHorizontalSpeed;
- this.newHorizontalSpeed = 0.0D;
- }
- }
- public void updateMovementSpeed() {
- AttributeModifiable moveSpeed = (AttributeModifiable)this.player.getAttributeMap().a(GenericAttributes.d);
- double base = moveSpeed.b();
- double value = base;
- for (AttributeModifier modifier : moveSpeed.a(0)) {
- value += modifier.d();
- }
- for (AttributeModifier modifier : moveSpeed.a(1)) {
- value += modifier.d() * base;
- }
- for (AttributeModifier modifier : moveSpeed.a(2)) {
- if (modifier != EntityLiving.c) {
- value *= (1.0D + modifier.d());
- }
- }
- if (value < this.horizontalSpeed) {
- this.newHorizontalSpeed = value;
- this.newHorizontalSpeedTime = System.currentTimeMillis();
- } else {
- this.horizontalSpeed = value;
- this.newHorizontalSpeed = 0.0D;
- }
- }
- public void handleVehicleMove(PacketPlayInVehicleMove packet) {
- if (!Doubles.isFinite(packet.x) || !Doubles.isFinite(packet.y) || !Doubles.isFinite(packet.z) || !Floats.isFinite(packet.yaw) || !Floats.isFinite(packet.pitch)) {
- disconnect("Invalid move vehicle packet received");
- return;
- }
- Entity vehicle = this.player.vehicle;
- if (vehicle == null) {
- return;
- }
- double currentX = vehicle.locX;
- double currentY = vehicle.locY;
- double currentZ = vehicle.locZ;
- double dx = packet.x - currentX;
- double dy = packet.y - currentY;
- double dz = packet.z - currentZ;
- double moveSquared = dx * dx + dy * dy + dz * dz;
- if (moveSquared > SpigotConfig.movedTooQuicklyThreshold) {
- c.warn(this.player.getName() + " moves their vehicle (" + vehicle.getClass().getSimpleName() + ") too quickly! " + dx + ", " + dy + ", " + dz);
- sendPacket(new PacketPlayOutVehicleMove(vehicle));
- return;
- }
- boolean currentlyInBlock = !vehicle.world.getCubes(vehicle, vehicle.boundingBox.shrink(0.0625D, 0.0625D, 0.0625D)).isEmpty();
- boolean movedWrongly = false;
- vehicle.move(dx, dy, dz);
- if (vehicle.e(packet.x, packet.y, packet.z) > SpigotConfig.movedWronglyThreshold) {
- c.warn(this.player.getName() + " moves their vehicle (" + vehicle.getClass().getSimpleName() + ") wrongly!");
- movedWrongly = true;
- }
- vehicle.setLocation(packet.x, packet.y, packet.z, packet.yaw, packet.pitch);
- boolean destInBlock = !vehicle.world.getCubes(vehicle, vehicle.boundingBox.shrink(0.0625D, 0.0625D, 0.0625D)).isEmpty();
- if (!currentlyInBlock && (movedWrongly || destInBlock)) {
- vehicle.setLocation(currentX, currentY, currentZ, packet.yaw, packet.pitch);
- sendPacket(new PacketPlayOutVehicleMove(vehicle));
- return;
- }
- this.minecraftServer.getPlayerList().d(this.player);
- }
- public void handleUseItem(PacketPlayInUseItem packet) {
- if (packet.hand == 1) {
- if (this.player.isBlocking())
- {
- this.player.shieldBlocking = true;
- }
- } else {
- PacketPlayInBlockPlace place = new PacketPlayInBlockPlace();
- place.a = -1;
- place.b = -1;
- place.c = -1;
- place.d = 255;
- a(place);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement