diff --git a/sources/src/main/java/io/akarin/api/Akari.java b/sources/src/main/java/io/akarin/api/Akari.java index 93d580c3f..42bbcfa2a 100644 --- a/sources/src/main/java/io/akarin/api/Akari.java +++ b/sources/src/main/java/io/akarin/api/Akari.java @@ -15,7 +15,6 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import co.aikar.timings.Timing; import co.aikar.timings.Timings; -import io.netty.channel.Channel.Unsafe; public abstract class Akari { /** diff --git a/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java b/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java index a0aeb5432..071135aaf 100644 --- a/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java +++ b/sources/src/main/java/io/akarin/server/mixin/core/MixinMinecraftServer.java @@ -140,10 +140,6 @@ public class MixinMinecraftServer { this.an().c(); MinecraftTimings.connectionTimer.stopTiming(); - Akari.callbackTiming().startTiming(); - while ((runnable = Akari.callbackQueue.poll()) != null) runnable.run(); - Akari.callbackTiming().stopTiming(); - MinecraftTimings.playerListTimer.startTiming(); this.v.tick(); MinecraftTimings.playerListTimer.stopTiming(); diff --git a/sources/src/main/java/io/akarin/server/mixin/core/MixinNetworkManager.java b/sources/src/main/java/io/akarin/server/mixin/core/MixinNetworkManager.java deleted file mode 100644 index d700900d0..000000000 --- a/sources/src/main/java/io/akarin/server/mixin/core/MixinNetworkManager.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.akarin.server.mixin.core; - -import org.spongepowered.asm.mixin.Mixin; -import net.minecraft.server.NetworkManager; - -@Mixin(value = NetworkManager.class, remap = false) -public class MixinNetworkManager { - -} diff --git a/sources/src/main/java/io/akarin/server/mixin/core/NonblockingServerConnection.java b/sources/src/main/java/io/akarin/server/mixin/core/NonblockingServerConnection.java index 34b26a5c6..80b6bca86 100644 --- a/sources/src/main/java/io/akarin/server/mixin/core/NonblockingServerConnection.java +++ b/sources/src/main/java/io/akarin/server/mixin/core/NonblockingServerConnection.java @@ -31,6 +31,7 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.server.ChatComponentText; +import net.minecraft.server.ITickable; import net.minecraft.server.MinecraftServer; import net.minecraft.server.NetworkManager; import net.minecraft.server.PacketPlayOutKickDisconnect; @@ -135,15 +136,13 @@ public class NonblockingServerConnection { Collections.shuffle(h); } - int submitted = 0; Iterator it = h.iterator(); while (it.hasNext()) { NetworkManager manager = it.next(); if (manager.h()) continue; // PAIL: NetworkManager::hasNoChannel if (manager.isConnected()) { - Akari.STAGE_TICK.submit(() -> processPackets(manager), null); - submitted++; + processPackets(manager); } else { // Spigot - Fix a race condition where a NetworkManager could be unregistered just before connection. if (manager.preparing) continue; @@ -152,10 +151,6 @@ public class NonblockingServerConnection { manager.handleDisconnection(); } } - - for (int i = 0; i < submitted; i++) { - Akari.STAGE_TICK.take(); - } } } } diff --git a/sources/src/main/java/net/minecraft/server/EntityPlayer.java b/sources/src/main/java/net/minecraft/server/EntityPlayer.java deleted file mode 100644 index 6c7ead9fc..000000000 --- a/sources/src/main/java/net/minecraft/server/EntityPlayer.java +++ /dev/null @@ -1,1615 +0,0 @@ -package net.minecraft.server; - -import com.google.common.collect.Lists; -import com.mojang.authlib.GameProfile; - -import io.akarin.api.Akari; -import io.netty.buffer.Unpooled; -import java.util.ArrayDeque; // Paper -import java.util.ArrayList; -import java.util.Collection; -import java.util.Deque; // Paper -import java.util.Iterator; -import java.util.List; -import javax.annotation.Nullable; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -// CraftBukkit start -import com.google.common.base.Preconditions; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.WeatherType; -import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.event.CraftEventFactory; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerChangedMainHandEvent; -import org.bukkit.event.player.PlayerGameModeChangeEvent; -import org.bukkit.event.player.PlayerLocaleChangeEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.MainHand; -// CraftBukkit end - -public class EntityPlayer extends EntityHuman implements ICrafting { - - private static final Logger bV = LogManager.getLogger(); - public String locale = null; // PAIL: private -> public // Paper - default to null - public long lastSave = MinecraftServer.currentTick; // Paper - public PlayerConnection playerConnection; - public final MinecraftServer server; - public final PlayerInteractManager playerInteractManager; - public double d; - public double e; - public final Deque removeQueue = new ArrayDeque<>(); // Paper - private final AdvancementDataPlayer bY; - private final ServerStatisticManager bZ; - private float ca = Float.MIN_VALUE; - private int cb = Integer.MIN_VALUE; - private int cc = Integer.MIN_VALUE; - private int cd = Integer.MIN_VALUE; - private int ce = Integer.MIN_VALUE; - private int cf = Integer.MIN_VALUE; - private float lastHealthSent = -1.0E8F; - private int ch = -99999999; - private boolean ci = true; - public int lastSentExp = -99999999; - public int invulnerableTicks = 60; - private EntityHuman.EnumChatVisibility cl; - private boolean cm = true; - private long cn = System.currentTimeMillis(); - private Entity co; - public boolean worldChangeInvuln; - private boolean cq; private void setHasSeenCredits(boolean has) { this.cq = has; } // Paper - OBFHELPER - private final RecipeBookServer cr = new RecipeBookServer(); - private Vec3D cs; - private int ct; - private boolean cu; - private Vec3D cv; - private int containerCounter; - public boolean f; - public int ping; - public boolean viewingCredits; - // Paper start - Player view distance API - private int viewDistance = -1; - public int getViewDistance() { - return viewDistance == -1 ? ((WorldServer) world).getPlayerChunkMap().getViewDistance() : viewDistance; - } - public void setViewDistance(int viewDistance) { - this.viewDistance = viewDistance; - } - // Paper end - private int containerUpdateDelay; // Paper - - // CraftBukkit start - public String displayName; - public IChatBaseComponent listName; - public org.bukkit.Location compassTarget; - public int newExp = 0; - public int newLevel = 0; - public int newTotalExp = 0; - public boolean keepLevel = false; - public double maxHealthCache; - public boolean joining = true; - public boolean sentListPacket = false; - // CraftBukkit end - - public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) { - super(worldserver, gameprofile); - playerinteractmanager.player = this; - this.playerInteractManager = playerinteractmanager; - // CraftBukkit start - BlockPosition blockposition = getSpawnPoint(minecraftserver, worldserver); - - this.server = minecraftserver; - this.bZ = minecraftserver.getPlayerList().getStatisticManager(this); - this.bY = minecraftserver.getPlayerList().h(this); - this.P = 1.0F; - this.setPositionRotation(blockposition, 0.0F, 0.0F); - // CraftBukkit end - - while (!worldserver.getCubes(this, this.getBoundingBox()).isEmpty() && this.locY < 255.0D) { - this.setPosition(this.locX, this.locY + 1.0D, this.locZ); - } - - // CraftBukkit start - this.displayName = this.getName(); - this.canPickUpLoot = true; - this.maxHealthCache = this.getMaxHealth(); - // CraftBukkit end - } - - public final BlockPosition getSpawnPoint(MinecraftServer minecraftserver, WorldServer worldserver) { - BlockPosition blockposition = worldserver.getSpawn(); - - if (worldserver.worldProvider.m() && worldserver.getWorldData().getGameType() != EnumGamemode.ADVENTURE) { - int i = Math.max(0, minecraftserver.a(worldserver)); - int j = MathHelper.floor(worldserver.getWorldBorder().b(blockposition.getX(), blockposition.getZ())); - - if (j < i) { - i = j; - } - - if (j <= 1) { - i = 1; - } - - blockposition = worldserver.q(blockposition.a(this.random.nextInt(i * 2 + 1) - i, 0, this.random.nextInt(i * 2 + 1) - i)); - } - - return blockposition; - } - // CraftBukkit end - - @Override - public void a(NBTTagCompound nbttagcompound) { - super.a(nbttagcompound); - if (this.locY > 300) this.locY = 257; // Paper - bring down to a saner Y level if out of world - if (nbttagcompound.hasKeyOfType("playerGameType", 99)) { - if (this.C_().getForceGamemode()) { - this.playerInteractManager.setGameMode(this.C_().getGamemode()); - } else { - this.playerInteractManager.setGameMode(EnumGamemode.getById(nbttagcompound.getInt("playerGameType"))); - } - } - - if (nbttagcompound.hasKeyOfType("enteredNetherPosition", 10)) { - NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("enteredNetherPosition"); - - this.cv = new Vec3D(nbttagcompound1.getDouble("x"), nbttagcompound1.getDouble("y"), nbttagcompound1.getDouble("z")); - } - - this.cq = nbttagcompound.getBoolean("seenCredits"); - if (nbttagcompound.hasKeyOfType("recipeBook", 10)) { - this.cr.a(nbttagcompound.getCompound("recipeBook")); - } - this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit - - } - - public static void a(DataConverterManager dataconvertermanager) { - dataconvertermanager.a(DataConverterTypes.PLAYER, new DataInspector() { - @Override - public NBTTagCompound a(DataConverter dataconverter, NBTTagCompound nbttagcompound, int i) { - if (nbttagcompound.hasKeyOfType("RootVehicle", 10)) { - NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("RootVehicle"); - - if (nbttagcompound1.hasKeyOfType("Entity", 10)) { - nbttagcompound1.set("Entity", dataconverter.a(DataConverterTypes.ENTITY, nbttagcompound1.getCompound("Entity"), i)); - } - } - - return nbttagcompound; - } - }); - } - - @Override - public void b(NBTTagCompound nbttagcompound) { - super.b(nbttagcompound); - nbttagcompound.setInt("playerGameType", this.playerInteractManager.getGameMode().getId()); - nbttagcompound.setBoolean("seenCredits", this.cq); - if (this.cv != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - - nbttagcompound1.setDouble("x", this.cv.x); - nbttagcompound1.setDouble("y", this.cv.y); - nbttagcompound1.setDouble("z", this.cv.z); - nbttagcompound.set("enteredNetherPosition", nbttagcompound1); - } - - Entity entity = this.getVehicle(); - Entity entity1 = this.bJ(); - - if (entity1 != null && entity != this && entity.b(EntityPlayer.class).size() == 1) { - NBTTagCompound nbttagcompound2 = new NBTTagCompound(); - NBTTagCompound nbttagcompound3 = new NBTTagCompound(); - - entity.d(nbttagcompound3); - nbttagcompound2.a("Attach", entity1.getUniqueID()); - nbttagcompound2.set("Entity", nbttagcompound3); - nbttagcompound.set("RootVehicle", nbttagcompound2); - } - - nbttagcompound.set("recipeBook", this.cr.c()); - this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit - } - - // CraftBukkit start - World fallback code, either respawn location or global spawn - @Override - public void spawnIn(World world) { - super.spawnIn(world); - if (world == null) { - this.dead = false; - BlockPosition position = null; - if (this.spawnWorld != null && !this.spawnWorld.equals("")) { - CraftWorld cworld = (CraftWorld) Bukkit.getServer().getWorld(this.spawnWorld); - if (cworld != null && this.getBed() != null) { - world = cworld.getHandle(); - position = EntityHuman.getBed(cworld.getHandle(), this.getBed(), false); - } - } - if (world == null || position == null) { - world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle(); - position = world.getSpawn(); - } - this.world = world; - this.setPosition(position.getX() + 0.5, position.getY(), position.getZ() + 0.5); - } - this.dimension = ((WorldServer) this.world).dimension; - this.playerInteractManager.a((WorldServer) world); - } - // CraftBukkit end - - @Override - public void levelDown(int i) { - super.levelDown(i); - this.lastSentExp = -1; - } - - @Override - public void enchantDone(ItemStack itemstack, int i) { - super.enchantDone(itemstack, i); - this.lastSentExp = -1; - } - - public void syncInventory() { - this.activeContainer.addSlotListener(this); - } - - @Override - public void enterCombat() { - super.enterCombat(); - this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTER_COMBAT)); - } - - @Override - public void exitCombat() { - super.exitCombat(); - this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.END_COMBAT)); - } - - @Override - protected void a(IBlockData iblockdata) { - CriterionTriggers.d.a(this, iblockdata); - } - - @Override - protected ItemCooldown l() { - return new ItemCooldownPlayer(this); - } - - @Override - public void B_() { - // CraftBukkit start - if (this.joining) { - this.joining = false; - } - // CraftBukkit end - this.playerInteractManager.a(); - --this.invulnerableTicks; - if (this.noDamageTicks > 0) { - --this.noDamageTicks; - } - - // Paper start - Configurable container update tick rate - if (--containerUpdateDelay <= 0) { - this.activeContainer.b(); - containerUpdateDelay = world.paperConfig.containerUpdateTickRate; - } - // Paper end - if (!this.world.isClientSide && !this.activeContainer.canUse(this)) { - this.closeInventory(); - this.activeContainer = this.defaultContainer; - } - - while (!this.removeQueue.isEmpty()) { - int i = Math.min(this.removeQueue.size(), Integer.MAX_VALUE); - int[] aint = new int[i]; - Iterator iterator = this.removeQueue.iterator(); - int j = 0; - - // Paper start - /* while (iterator.hasNext() && j < i) { - aint[j++] = ((Integer) iterator.next()).intValue(); - iterator.remove(); - } */ - - Integer integer; - while (j < i && (integer = this.removeQueue.poll()) != null) { - aint[j++] = integer.intValue(); - } - // Paper end - - this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(aint)); - } - - Entity entity = this.getSpecatorTarget(); - - if (entity != this) { - if (entity.isAlive()) { - this.setLocation(entity.locX, entity.locY, entity.locZ, entity.yaw, entity.pitch); - this.server.getPlayerList().d(this); - if (this.isSneaking()) { - this.setSpectatorTarget(this); - } - } else { - this.setSpectatorTarget(this); - } - } - - CriterionTriggers.v.a(this); - if (this.cs != null) { - CriterionTriggers.t.a(this, this.cs, this.ticksLived - this.ct); - } - - this.bY.b(this); - } - - public void playerTick() { - try { - super.B_(); - - for (int i = 0; i < this.inventory.getSize(); ++i) { - ItemStack itemstack = this.inventory.getItem(i); - - if (!itemstack.isEmpty() && itemstack.getItem().f()) { - Packet packet = ((ItemWorldMapBase) itemstack.getItem()).a(itemstack, this.world, this); - - if (packet != null) { - this.playerConnection.sendPacket(packet); - } - } - } - - if (this.getHealth() != this.lastHealthSent || this.ch != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.ci) { - this.playerConnection.sendPacket(new PacketPlayOutUpdateHealth(this.getBukkitEntity().getScaledHealth(), this.foodData.getFoodLevel(), this.foodData.getSaturationLevel())); // CraftBukkit - this.lastHealthSent = this.getHealth(); - this.ch = this.foodData.getFoodLevel(); - this.ci = this.foodData.getSaturationLevel() == 0.0F; - } - - if (this.getHealth() + this.getAbsorptionHearts() != this.ca) { - this.ca = this.getHealth() + this.getAbsorptionHearts(); - this.a(IScoreboardCriteria.g, MathHelper.f(this.ca)); - } - - if (this.foodData.getFoodLevel() != this.cb) { - this.cb = this.foodData.getFoodLevel(); - this.a(IScoreboardCriteria.h, MathHelper.f((float) this.cb)); - } - - if (this.getAirTicks() != this.cc) { - this.cc = this.getAirTicks(); - this.a(IScoreboardCriteria.i, MathHelper.f((float) this.cc)); - } - - // CraftBukkit start - Force max health updates - if (this.maxHealthCache != this.getMaxHealth()) { - this.getBukkitEntity().updateScaledHealth(); - } - // CraftBukkit end - - if (this.getArmorStrength() != this.cd) { - this.cd = this.getArmorStrength(); - this.a(IScoreboardCriteria.j, MathHelper.f((float) this.cd)); - } - - if (this.expTotal != this.cf) { - this.cf = this.expTotal; - this.a(IScoreboardCriteria.k, MathHelper.f((float) this.cf)); - } - - if (this.expLevel != this.ce) { - this.ce = this.expLevel; - this.a(IScoreboardCriteria.l, MathHelper.f((float) this.ce)); - } - - if (this.expTotal != this.lastSentExp) { - this.lastSentExp = this.expTotal; - this.playerConnection.sendPacket(new PacketPlayOutExperience(this.exp, this.expTotal, this.expLevel)); - } - - if (this.ticksLived % 20 == 0) { - CriterionTriggers.o.a(this); - } - - // CraftBukkit start - initialize oldLevel and fire PlayerLevelChangeEvent - if (this.oldLevel == -1) { - this.oldLevel = this.expLevel; - } - - if (this.oldLevel != this.expLevel) { - Akari.callbackQueue.add(() -> { - CraftEventFactory.callPlayerLevelChangeEvent(this.world.getServer().getPlayer(this), this.oldLevel, this.expLevel); - this.oldLevel = this.expLevel; - }); // Akarin - } - // CraftBukkit end - } catch (Throwable throwable) { - CrashReport crashreport = CrashReport.a(throwable, "Ticking player"); - CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked"); - - this.appendEntityCrashDetails(crashreportsystemdetails); - throw new ReportedException(crashreport); - } - } - - private void a(IScoreboardCriteria iscoreboardcriteria, int i) { - Collection collection = this.world.getServer().getScoreboardManager().getScoreboardScores(iscoreboardcriteria, this.getName(), new java.util.ArrayList()); // CraftBukkit - Use our scores instead - Iterator iterator = collection.iterator(); - - while (iterator.hasNext()) { - ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next(); // CraftBukkit - Use our scores instead - - scoreboardscore.setScore(i); - } - - } - - @Override - public void die(DamageSource damagesource) { - boolean flag = this.world.getGameRules().getBoolean("showDeathMessages"); - - this.playerConnection.sendPacket(new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, flag)); - // CraftBukkit start - fire PlayerDeathEvent - if (this.dead) { - return; - } - java.util.List loot = new java.util.ArrayList(this.inventory.getSize()); - boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory") || this.isSpectator(); - - if (!keepInventory) { - for (ItemStack item : this.inventory.getContents()) { - if (!item.isEmpty() && !EnchantmentManager.shouldNotDrop(item)) { - loot.add(CraftItemStack.asCraftMirror(item)); - } - } - } - - IChatBaseComponent chatmessage = this.getCombatTracker().getDeathMessage(); - - String deathmessage = chatmessage.toPlainText(); - org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory); - - String deathMessage = event.getDeathMessage(); - - if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override? - if (deathMessage.equals(deathmessage)) { - ScoreboardTeamBase scoreboardteambase = this.aY(); - - if (scoreboardteambase != null && scoreboardteambase.getDeathMessageVisibility() != ScoreboardTeamBase.EnumNameTagVisibility.ALWAYS) { - if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OTHER_TEAMS) { - this.server.getPlayerList().a(this, chatmessage); - } else if (scoreboardteambase.getDeathMessageVisibility() == ScoreboardTeamBase.EnumNameTagVisibility.HIDE_FOR_OWN_TEAM) { - this.server.getPlayerList().b(this, chatmessage); - } - } else { - this.server.getPlayerList().sendMessage(chatmessage); - } - } else { - this.server.getPlayerList().sendMessage(org.bukkit.craftbukkit.util.CraftChatMessage.fromString(deathMessage)); - } - } - - this.releaseShoulderEntities(); - // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory. - if (!event.getKeepInventory()) { - this.inventory.clear(); - } - - this.closeInventory(); - this.setSpectatorTarget(this); // Remove spectated target - // CraftBukkit end - - // CraftBukkit - Get our scores instead - Collection collection = this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.d, this.getName(), new java.util.ArrayList()); - Iterator iterator = collection.iterator(); - - while (iterator.hasNext()) { - ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next(); // CraftBukkit - Use our scores instead - - scoreboardscore.incrementScore(); - } - - EntityLiving entityliving = this.ci(); - - if (entityliving != null) { - EntityTypes.MonsterEggInfo entitytypes_monsteregginfo = EntityTypes.eggInfo.get(EntityTypes.a(entityliving)); - - if (entitytypes_monsteregginfo != null) { - this.b(entitytypes_monsteregginfo.killedByEntityStatistic); - } - - entityliving.a(this, this.bb, damagesource); - } - - this.b(StatisticList.A); - this.a(StatisticList.h); - this.extinguish(); - this.setFlag(0, false); - this.getCombatTracker().g(); - } - - @Override - public void a(Entity entity, int i, DamageSource damagesource) { - if (entity != this) { - super.a(entity, i, damagesource); - this.addScore(i); - // CraftBukkit - Get our scores instead - Collection collection = this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.f, this.getName(), new java.util.ArrayList()); - - if (entity instanceof EntityHuman) { - this.b(StatisticList.D); - // CraftBukkit - Get our scores instead - this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.e, this.getName(), collection); - // collection.addAll(this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.e)); - // CraftBukkit end - } else { - this.b(StatisticList.B); - } - - collection.addAll(this.E(entity)); - Iterator iterator = collection.iterator(); // CraftBukkit - - while (iterator.hasNext()) { - // CraftBukkit start - // ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next(); - - // this.getScoreboard().getPlayerScoreForObjective(this.getName(), scoreboardobjective).incrementScore(); - iterator.next().incrementScore(); - // CraftBukkit end - } - - CriterionTriggers.b.a(this, entity, damagesource); - } - } - - private Collection E(Entity entity) { // CraftBukkit - String s = entity instanceof EntityHuman ? entity.getName() : entity.bn(); - ScoreboardTeam scoreboardteam = this.getScoreboard().getPlayerTeam(this.getName()); - - if (scoreboardteam != null) { - int i = scoreboardteam.getColor().b(); - - if (i >= 0 && i < IScoreboardCriteria.n.length) { - Iterator iterator = this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.n[i]).iterator(); - - while (iterator.hasNext()) { - ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next(); - ScoreboardScore scoreboardscore = this.getScoreboard().getPlayerScoreForObjective(s, scoreboardobjective); - - scoreboardscore.incrementScore(); - } - } - } - - ScoreboardTeam scoreboardteam1 = this.getScoreboard().getPlayerTeam(s); - - if (scoreboardteam1 != null) { - int j = scoreboardteam1.getColor().b(); - - if (j >= 0 && j < IScoreboardCriteria.m.length) { - // CraftBukkit - Get our scores instead - return this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.m[j], this.getName(), new java.util.ArrayList()); - // return this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.m[j]); - // CraftBukkit end - } - } - - return Lists.newArrayList(); - } - - @Override - public boolean damageEntity(DamageSource damagesource, float f) { - if (this.isInvulnerable(damagesource)) { - return false; - } else { - boolean flag = this.server.aa() && this.canPvP() && "fall".equals(damagesource.translationIndex); - - if (!flag && this.invulnerableTicks > 0 && damagesource != DamageSource.OUT_OF_WORLD) { - return false; - } else { - if (damagesource instanceof EntityDamageSource) { - Entity entity = damagesource.getEntity(); - - if (entity instanceof EntityHuman && !this.a((EntityHuman) entity)) { - return false; - } - - if (entity instanceof EntityArrow) { - EntityArrow entityarrow = (EntityArrow) entity; - - if (entityarrow.shooter instanceof EntityHuman && !this.a((EntityHuman) entityarrow.shooter)) { - return false; - } - } - } - - return super.damageEntity(damagesource, f); - } - } - } - - @Override - public boolean a(EntityHuman entityhuman) { - return !this.canPvP() ? false : super.a(entityhuman); - } - - private boolean canPvP() { - // CraftBukkit - this.server.getPvP() -> this.world.pvpMode - return this.world.pvpMode; - } - - @Override - @Nullable - public Entity b(int i) { - if (this.isSleeping()) return this; // CraftBukkit - SPIGOT-3154 - // this.worldChangeInvuln = true; // CraftBukkit - Moved down and into PlayerList#changeDimension - if (this.dimension == 0 && i == -1) { - this.cv = new Vec3D(this.locX, this.locY, this.locZ); - } else if (this.dimension != -1 && i != 0) { - this.cv = null; - } - - if (this.dimension == 1 && i == 1) { - this.worldChangeInvuln = true; // CraftBukkit - Moved down from above - this.world.kill(this); - if (!this.viewingCredits) { - this.viewingCredits = true; - if (world.paperConfig.disableEndCredits) this.setHasSeenCredits(true); // Paper - Toggle to always disable end credits - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(4, this.cq ? 0.0F : 1.0F)); - this.cq = true; - } - - return this; - } else { - if (this.dimension == 0 && i == 1) { - i = 1; - } - - // CraftBukkit start - TeleportCause cause = (this.dimension == 1 || i == 1) ? TeleportCause.END_PORTAL : TeleportCause.NETHER_PORTAL; - this.server.getPlayerList().changeDimension(this, i, cause); // PAIL: check all this - // CraftBukkit end - this.playerConnection.sendPacket(new PacketPlayOutWorldEvent(1032, BlockPosition.ZERO, 0, false)); - this.lastSentExp = -1; - this.lastHealthSent = -1.0F; - this.ch = -1; - return this; - } - } - - @Override - public boolean a(EntityPlayer entityplayer) { - return entityplayer.isSpectator() ? this.getSpecatorTarget() == this : (this.isSpectator() ? false : super.a(entityplayer)); - } - - private void a(TileEntity tileentity) { - if (tileentity != null) { - PacketPlayOutTileEntityData packetplayouttileentitydata = tileentity.getUpdatePacket(); - - if (packetplayouttileentitydata != null) { - this.playerConnection.sendPacket(packetplayouttileentitydata); - } - } - - } - - @Override - public void receive(Entity entity, int i) { - super.receive(entity, i); - this.activeContainer.b(); - } - - @Override - public EntityHuman.EnumBedResult a(BlockPosition blockposition) { - EntityHuman.EnumBedResult entityhuman_enumbedresult = super.a(blockposition); - - if (entityhuman_enumbedresult == EntityHuman.EnumBedResult.OK) { - this.b(StatisticList.ab); - PacketPlayOutBed packetplayoutbed = new PacketPlayOutBed(this, blockposition); - - this.x().getTracker().a(this, packetplayoutbed); - this.playerConnection.a(this.locX, this.locY, this.locZ, this.yaw, this.pitch); - this.playerConnection.sendPacket(packetplayoutbed); - CriterionTriggers.p.a(this); - } - - return entityhuman_enumbedresult; - } - - @Override - public void a(boolean flag, boolean flag1, boolean flag2) { - if (!this.sleeping) return; // CraftBukkit - Can't leave bed if not in one! - if (this.isSleeping()) { - this.x().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(this, 2)); - } - - super.a(flag, flag1, flag2); - if (this.playerConnection != null) { - this.playerConnection.a(this.locX, this.locY, this.locZ, this.yaw, this.pitch); - } - - } - - @Override - public boolean a(Entity entity, boolean flag) { - Entity entity1 = this.bJ(); - - if (!super.a(entity, flag)) { - return false; - } else { - Entity entity2 = this.bJ(); - - if (entity2 != entity1 && this.playerConnection != null) { - this.playerConnection.a(this.locX, this.locY, this.locZ, this.yaw, this.pitch); - } - - return true; - } - } - - @Override - public void stopRiding() { - Entity entity = this.bJ(); - - super.stopRiding(); - Entity entity1 = this.bJ(); - - if (entity1 != entity && this.playerConnection != null) { - this.playerConnection.a(this.locX, this.locY, this.locZ, this.yaw, this.pitch); - } - // Paper start - "Fixes" an issue in which the vehicle player would not be notified that the passenger dismounted - if (entity instanceof EntityPlayer) { - WorldServer worldServer = (WorldServer) entity.getWorld(); - worldServer.tracker.untrackEntity(this); - worldServer.tracker.track(this); - } - // Paper end - - } - - @Override - public boolean isInvulnerable(DamageSource damagesource) { - return super.isInvulnerable(damagesource) || this.L(); - } - - @Override - protected void a(double d0, boolean flag, IBlockData iblockdata, BlockPosition blockposition) {} - - @Override - protected void b(BlockPosition blockposition) { - if (!this.isSpectator()) { - super.b(blockposition); - } - - } - - public void a(double d0, boolean flag) { - int i = MathHelper.floor(this.locX); - int j = MathHelper.floor(this.locY - 0.20000000298023224D); - int k = MathHelper.floor(this.locZ); - BlockPosition blockposition = new BlockPosition(i, j, k); - IBlockData iblockdata = this.world.getType(blockposition); - - if (iblockdata.getMaterial() == Material.AIR) { - BlockPosition blockposition1 = blockposition.down(); - IBlockData iblockdata1 = this.world.getType(blockposition1); - Block block = iblockdata1.getBlock(); - - if (block instanceof BlockFence || block instanceof BlockCobbleWall || block instanceof BlockFenceGate) { - blockposition = blockposition1; - iblockdata = iblockdata1; - } - } - - super.a(d0, flag, iblockdata, blockposition); - } - - @Override - public void openSign(TileEntitySign tileentitysign) { - tileentitysign.a(this); - this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition())); - } - - public int nextContainerCounter() { // CraftBukkit - void -> int - this.containerCounter = this.containerCounter % 100 + 1; - return containerCounter; // CraftBukkit - } - - @Override - public void openTileEntity(ITileEntityContainer itileentitycontainer) { - // CraftBukkit start - Inventory open hook - if (false && itileentitycontainer instanceof ILootable && ((ILootable) itileentitycontainer).b() != null && this.isSpectator()) { - this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).setChatModifier((new ChatModifier()).setColor(EnumChatFormat.RED)), true); - } else { - boolean cancelled = itileentitycontainer instanceof ILootable && ((ILootable) itileentitycontainer).b() != null && this.isSpectator(); - Container container = CraftEventFactory.callInventoryOpenEvent(this, itileentitycontainer.createContainer(this.inventory, this), cancelled); - if (container == null) { - return; - } - this.nextContainerCounter(); - this.activeContainer = container; - this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, itileentitycontainer.getContainerName(), itileentitycontainer.getScoreboardDisplayName())); - // CraftBukkit end - this.activeContainer.windowId = this.containerCounter; - this.activeContainer.addSlotListener(this); - } - } - - @Override - public void openContainer(IInventory iinventory) { - // CraftBukkit start - Inventory open hook - // Copied from below - boolean cancelled = false; - if (iinventory instanceof ITileInventory) { - ITileInventory itileinventory = (ITileInventory) iinventory; - cancelled = itileinventory.isLocked() && !this.a(itileinventory.getLock()) && !this.isSpectator(); - } - - Container container; - if (iinventory instanceof ITileEntityContainer) { - if (iinventory instanceof TileEntity) { - Preconditions.checkArgument(((TileEntity) iinventory).getWorld() != null, "Container must have world to be opened"); - } - container = ((ITileEntityContainer) iinventory).createContainer(this.inventory, this); - } else { - container = new ContainerChest(this.inventory, iinventory, this); - } - container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled); - if (container == null && !cancelled) { // Let pre-cancelled events fall through - iinventory.closeContainer(this); - return; - } - // CraftBukkit end - - if (iinventory instanceof ILootable && ((ILootable) iinventory).b() != null && this.isSpectator()) { - this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).setChatModifier((new ChatModifier()).setColor(EnumChatFormat.RED)), true); - } else { - if (this.activeContainer != this.defaultContainer) { - this.closeInventory(); - } - - if (iinventory instanceof ITileInventory) { - ITileInventory itileinventory = (ITileInventory) iinventory; - - if (itileinventory.isLocked() && !this.a(itileinventory.getLock()) && !this.isSpectator()) { - this.playerConnection.sendPacket(new PacketPlayOutChat(new ChatMessage("container.isLocked", new Object[] { iinventory.getScoreboardDisplayName()}), ChatMessageType.GAME_INFO)); - this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ab, SoundCategory.BLOCKS, this.locX, this.locY, this.locZ, 1.0F, 1.0F)); - iinventory.closeContainer(this); // CraftBukkit - return; - } - } - - this.nextContainerCounter(); - // CraftBukkit start - if (iinventory instanceof ITileEntityContainer) { - this.activeContainer = container; - this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, ((ITileEntityContainer) iinventory).getContainerName(), iinventory.getScoreboardDisplayName(), iinventory.getSize())); - } else { - this.activeContainer = container; - this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, "minecraft:container", iinventory.getScoreboardDisplayName(), iinventory.getSize())); - } - // CraftBukkit end - - this.activeContainer.windowId = this.containerCounter; - this.activeContainer.addSlotListener(this); - } - } - - @Override - public void openTrade(IMerchant imerchant) { - // CraftBukkit start - Inventory open hook - Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerMerchant(this.inventory, imerchant, this.world)); - if (container == null) { - return; - } - // CraftBukkit end - this.nextContainerCounter(); - this.activeContainer = container; // CraftBukkit - this.activeContainer.windowId = this.containerCounter; - this.activeContainer.addSlotListener(this); - InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).e(); - IChatBaseComponent ichatbasecomponent = imerchant.getScoreboardDisplayName(); - - this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, "minecraft:villager", ichatbasecomponent, inventorymerchant.getSize())); - MerchantRecipeList merchantrecipelist = imerchant.getOffers(this); - - if (merchantrecipelist != null) { - PacketDataSerializer packetdataserializer = new PacketDataSerializer(Unpooled.buffer()); - - packetdataserializer.writeInt(this.containerCounter); - merchantrecipelist.a(packetdataserializer); - this.playerConnection.sendPacket(new PacketPlayOutCustomPayload("MC|TrList", packetdataserializer)); - } - - } - - @Override - public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { - // CraftBukkit start - Inventory open hook - Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerHorse(this.inventory, iinventory, entityhorseabstract, this)); - if (container == null) { - iinventory.closeContainer(this); - return; - } - // CraftBukkit end - if (this.activeContainer != this.defaultContainer) { - this.closeInventory(); - } - - this.nextContainerCounter(); - this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, "EntityHorse", iinventory.getScoreboardDisplayName(), iinventory.getSize(), entityhorseabstract.getId())); - this.activeContainer = container; // CraftBukkit - this.activeContainer.windowId = this.containerCounter; - this.activeContainer.addSlotListener(this); - } - - @Override - public void a(ItemStack itemstack, EnumHand enumhand) { - Item item = itemstack.getItem(); - - if (item == Items.WRITTEN_BOOK) { - PacketDataSerializer packetdataserializer = new PacketDataSerializer(Unpooled.buffer()); - - packetdataserializer.a(enumhand); - this.playerConnection.sendPacket(new PacketPlayOutCustomPayload("MC|BOpen", packetdataserializer)); - } - - } - - @Override - public void a(TileEntityCommand tileentitycommand) { - tileentitycommand.c(true); - this.a((TileEntity) tileentitycommand); - } - - @Override - public void a(Container container, int i, ItemStack itemstack) { - if (!(container.getSlot(i) instanceof SlotResult)) { - if (container == this.defaultContainer) { - CriterionTriggers.e.a(this, this.inventory); - } - - if (!this.f) { - this.playerConnection.sendPacket(new PacketPlayOutSetSlot(container.windowId, i, itemstack)); - } - } - } - - public void updateInventory(Container container) { - this.a(container, container.a()); - } - - @Override - public void a(Container container, NonNullList nonnulllist) { - this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, nonnulllist)); - this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried())); - // CraftBukkit start - Send a Set Slot to update the crafting result slot - if (java.util.EnumSet.of(InventoryType.CRAFTING,InventoryType.WORKBENCH).contains(container.getBukkitView().getType())) { - this.playerConnection.sendPacket(new PacketPlayOutSetSlot(container.windowId, 0, container.getSlot(0).getItem())); - } - // CraftBukkit end - } - - @Override - public void setContainerData(Container container, int i, int j) { - this.playerConnection.sendPacket(new PacketPlayOutWindowData(container.windowId, i, j)); - } - - @Override - public void setContainerData(Container container, IInventory iinventory) { - for (int i = 0; i < iinventory.h(); ++i) { - this.playerConnection.sendPacket(new PacketPlayOutWindowData(container.windowId, i, iinventory.getProperty(i))); - } - - } - - @Override - public void closeInventory() { - CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit - this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId)); - this.r(); - } - - public void broadcastCarriedItem() { - if (!this.f) { - this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried())); - } - } - - public void r() { - this.activeContainer.b(this); - this.activeContainer = this.defaultContainer; - } - - public void a(float f, float f1, boolean flag, boolean flag1) { - if (this.isPassenger()) { - if (f >= -1.0F && f <= 1.0F) { - this.be = f; - } - - if (f1 >= -1.0F && f1 <= 1.0F) { - this.bg = f1; - } - - this.bd = flag; - this.setSneaking(flag1); - } - - } - - @Override - public void a(Statistic statistic, int i) { - if (statistic != null) { - this.bZ.b(this, statistic, i); - Iterator iterator = this.getScoreboard().getObjectivesForCriteria(statistic.f()).iterator(); - - while (iterator.hasNext()) { - ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next(); - - this.getScoreboard().getPlayerScoreForObjective(this.getName(), scoreboardobjective).addScore(i); - } - - } - } - - @Override - public void a(Statistic statistic) { - if (statistic != null) { - this.bZ.setStatistic(this, statistic, 0); - Iterator iterator = this.getScoreboard().getObjectivesForCriteria(statistic.f()).iterator(); - - while (iterator.hasNext()) { - ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next(); - - this.getScoreboard().getPlayerScoreForObjective(this.getName(), scoreboardobjective).setScore(0); - } - - } - } - - @Override - public void a(List list) { - this.cr.a(list, this); - } - - @Override - public void a(MinecraftKey[] aminecraftkey) { - ArrayList arraylist = Lists.newArrayList(); - MinecraftKey[] aminecraftkey1 = aminecraftkey; - int i = aminecraftkey.length; - - for (int j = 0; j < i; ++j) { - MinecraftKey minecraftkey = aminecraftkey1[j]; - - // CraftBukkit start - if (CraftingManager.a(minecraftkey) == null) { - Bukkit.getLogger().warning("Ignoring grant of non existent recipe " + minecraftkey); - continue; - } - // CraftBukit end - arraylist.add(CraftingManager.a(minecraftkey)); - } - - this.a((List) arraylist); // CraftBukkit - decompile error - } - - @Override - public void b(List list) { - this.cr.b(list, this); - } - - public void s() { - this.cu = true; - this.ejectPassengers(); - if (this.sleeping) { - this.a(true, false, false); - } - - } - - public boolean t() { - return this.cu; - } - - public void triggerHealthUpdate() { - this.lastHealthSent = -1.0E8F; - this.lastSentExp = -1; // CraftBukkit - Added to reset - } - - // CraftBukkit start - Support multi-line messages - public void sendMessage(IChatBaseComponent[] ichatbasecomponent) { - for (IChatBaseComponent component : ichatbasecomponent) { - this.sendMessage(component); - } - } - // CraftBukkit end - - @Override - public void a(IChatBaseComponent ichatbasecomponent, boolean flag) { - this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent, flag ? ChatMessageType.GAME_INFO : ChatMessageType.CHAT)); - } - - @Override - protected void v() { - if (!this.activeItem.isEmpty() && this.isHandRaised()) { - this.playerConnection.sendPacket(new PacketPlayOutEntityStatus(this, (byte) 9)); - super.v(); - } - - } - - public void copyFrom(EntityPlayer entityplayer, boolean flag) { - if (flag) { - this.inventory.a(entityplayer.inventory); - this.setHealth(entityplayer.getHealth()); - this.foodData = entityplayer.foodData; - this.expLevel = entityplayer.expLevel; - this.expTotal = entityplayer.expTotal; - this.exp = entityplayer.exp; - this.setScore(entityplayer.getScore()); - this.an = entityplayer.an; - this.ao = entityplayer.ao; - this.ap = entityplayer.ap; - } else if (this.world.getGameRules().getBoolean("keepInventory") || entityplayer.isSpectator()) { - this.inventory.a(entityplayer.inventory); - this.expLevel = entityplayer.expLevel; - this.expTotal = entityplayer.expTotal; - this.exp = entityplayer.exp; - this.setScore(entityplayer.getScore()); - } - - this.bS = entityplayer.bS; - this.enderChest = entityplayer.enderChest; - this.getDataWatcher().set(EntityPlayer.br, entityplayer.getDataWatcher().get(EntityPlayer.br)); - this.lastSentExp = -1; - this.lastHealthSent = -1.0F; - this.ch = -1; - // this.cr.a((RecipeBook) entityplayer.cr); // CraftBukkit - // Paper start - Optimize remove queue - //this.removeQueue.addAll(entityplayer.removeQueue); - if (this.removeQueue != entityplayer.removeQueue) { - this.removeQueue.addAll(entityplayer.removeQueue); - } - this.cq = entityplayer.cq; - this.cv = entityplayer.cv; - this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft()); - this.setShoulderEntityRight(entityplayer.getShoulderEntityRight()); - } - - @Override - protected void a(MobEffect mobeffect) { - super.a(mobeffect); - this.playerConnection.sendPacket(new PacketPlayOutEntityEffect(this.getId(), mobeffect)); - if (mobeffect.getMobEffect() == MobEffects.LEVITATION) { - this.ct = this.ticksLived; - this.cs = new Vec3D(this.locX, this.locY, this.locZ); - } - - CriterionTriggers.z.a(this); - } - - @Override - protected void a(MobEffect mobeffect, boolean flag) { - super.a(mobeffect, flag); - this.playerConnection.sendPacket(new PacketPlayOutEntityEffect(this.getId(), mobeffect)); - CriterionTriggers.z.a(this); - } - - @Override - protected void b(MobEffect mobeffect) { - super.b(mobeffect); - this.playerConnection.sendPacket(new PacketPlayOutRemoveEntityEffect(this.getId(), mobeffect.getMobEffect())); - if (mobeffect.getMobEffect() == MobEffects.LEVITATION) { - this.cs = null; - } - - CriterionTriggers.z.a(this); - } - - @Override - public void enderTeleportTo(double d0, double d1, double d2) { - this.playerConnection.a(d0, d1, d2, this.yaw, this.pitch); - } - - @Override - public void a(Entity entity) { - this.x().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(entity, 4)); - } - - @Override - public void b(Entity entity) { - this.x().getTracker().sendPacketToEntity(this, new PacketPlayOutAnimation(entity, 5)); - } - - @Override - public void updateAbilities() { - if (this.playerConnection != null) { - this.playerConnection.sendPacket(new PacketPlayOutAbilities(this.abilities)); - this.G(); - } - } - - public WorldServer x() { - return (WorldServer) this.world; - } - - @Override - public void a(EnumGamemode enumgamemode) { - // CraftBukkit start - if (enumgamemode == this.playerInteractManager.getGameMode()) { - return; - } - - PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(getBukkitEntity(), GameMode.getByValue(enumgamemode.getId())); - world.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - // CraftBukkit end - - this.playerInteractManager.setGameMode(enumgamemode); - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, enumgamemode.getId())); - if (enumgamemode == EnumGamemode.SPECTATOR) { - this.releaseShoulderEntities(); - this.stopRiding(); - } else { - this.setSpectatorTarget(this); - } - - this.updateAbilities(); - this.cE(); - } - - @Override - public boolean isSpectator() { - return this.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR; - } - - @Override - public boolean z() { - return this.playerInteractManager.getGameMode() == EnumGamemode.CREATIVE; - } - - @Override - public void sendMessage(IChatBaseComponent ichatbasecomponent) { - this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent)); - } - - @Override - public boolean a(int i, String s) { - /* CraftBukkit start - if ("seed".equals(s) && !this.server.aa()) { - return true; - } else if (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) && !"trigger".equals(s)) { - if (this.server.getPlayerList().isOp(this.getProfile())) { - OpListEntry oplistentry = (OpListEntry) this.server.getPlayerList().getOPs().get(this.getProfile()); - - return oplistentry != null ? oplistentry.a() >= i : this.server.q() >= i; - } else { - return false; - } - } else { - return true; - } - */ - if ("@".equals(s)) { - return getBukkitEntity().hasPermission("minecraft.command.selector"); - } - if ("".equals(s)) { - return getBukkitEntity().isOp(); - } - return getBukkitEntity().hasPermission("minecraft.command." + s); - // CraftBukkit end - } - - public String A() { - String s = this.playerConnection.networkManager.getSocketAddress().toString(); - - s = s.substring(s.indexOf("/") + 1); - s = s.substring(0, s.indexOf(":")); - return s; - } - - public void a(PacketPlayInSettings packetplayinsettings) { - // CraftBukkit start - if (getMainHand() != packetplayinsettings.getMainHand()) { - PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT); - this.server.server.getPluginManager().callEvent(event); - } - - // Paper start - add PlayerLocaleChangeEvent - // Since the field is initialized to null, this event should always fire the first time the packet is received - String oldLocale = this.locale; - this.locale = packetplayinsettings.a(); - if (!this.locale.equals(oldLocale)) { - new com.destroystokyo.paper.event.player.PlayerLocaleChangeEvent(this.getBukkitEntity(), oldLocale, this.locale).callEvent(); - } - - // Compat with Bukkit - oldLocale = oldLocale != null ? oldLocale : "en_us"; - // Paper end - - if (!oldLocale.equals(packetplayinsettings.a())) { - PlayerLocaleChangeEvent event = new PlayerLocaleChangeEvent(getBukkitEntity(), packetplayinsettings.a()); - this.server.server.getPluginManager().callEvent(event); - } - // CraftBukkit end - this.cl = packetplayinsettings.c(); - this.cm = packetplayinsettings.d(); - this.getDataWatcher().set(EntityPlayer.br, Byte.valueOf((byte) packetplayinsettings.e())); - this.getDataWatcher().set(EntityPlayer.bs, Byte.valueOf((byte) (packetplayinsettings.getMainHand() == EnumMainHand.LEFT ? 0 : 1))); - } - - public EntityHuman.EnumChatVisibility getChatFlags() { - return this.cl; - } - - public void setResourcePack(String s, String s1) { - this.playerConnection.sendPacket(new PacketPlayOutResourcePackSend(s, s1)); - } - - @Override - public BlockPosition getChunkCoordinates() { - return new BlockPosition(this.locX, this.locY + 0.5D, this.locZ); - } - - public void resetIdleTimer() { - this.cn = MinecraftServer.aw(); - } - - public ServerStatisticManager getStatisticManager() { - return this.bZ; - } - - public RecipeBookServer F() { - return this.cr; - } - - public void c(Entity entity) { - if (entity instanceof EntityHuman) { - this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(new int[] { entity.getId()})); - } else { - this.removeQueue.add(Integer.valueOf(entity.getId())); - } - - } - - public void d(Entity entity) { - this.removeQueue.remove(Integer.valueOf(entity.getId())); - } - - @Override - protected void G() { - if (this.isSpectator()) { - this.bY(); - this.setInvisible(true); - } else { - super.G(); - } - - this.x().getTracker().a(this); - } - - public Entity getSpecatorTarget() { - return this.co == null ? this : this.co; - } - - public void setSpectatorTarget(Entity entity) { - Entity entity1 = this.getSpecatorTarget(); - - this.co = entity == null ? this : entity; - if (entity1 != this.co) { - this.playerConnection.sendPacket(new PacketPlayOutCamera(this.co)); - this.playerConnection.a(this.co.locX, this.co.locY, this.co.locZ, this.yaw, this.pitch, TeleportCause.SPECTATE); // CraftBukkit - } - - } - - @Override - protected void I() { - if (this.portalCooldown > 0 && !this.worldChangeInvuln) { - --this.portalCooldown; - } - - } - - @Override - public void attack(Entity entity) { - if (this.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) { - this.setSpectatorTarget(entity); - } else { - super.attack(entity); - } - - } - - public long J() { - return this.cn; - } - - @Nullable - public IChatBaseComponent getPlayerListName() { - return listName; // CraftBukkit - } - - @Override - public void a(EnumHand enumhand) { - super.a(enumhand); - this.ds(); - } - - public boolean L() { - return this.worldChangeInvuln; - } - - public void M() { - this.worldChangeInvuln = false; - } - - public void N() { - if (!CraftEventFactory.callToggleGlideEvent(this, true).isCancelled()) // CraftBukkit - this.setFlag(7, true); - } - - public void O() { - // CraftBukkit start - if (!CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) { - this.setFlag(7, true); - this.setFlag(7, false); - } - // CraftBukkit end - } - - public AdvancementDataPlayer getAdvancementData() { - return this.bY; - } - - @Nullable - public Vec3D Q() { - return this.cv; - } - - // CraftBukkit start - Add per-player time and weather. - public long timeOffset = 0; - public boolean relativeTime = true; - - public long getPlayerTime() { - if (this.relativeTime) { - // Adds timeOffset to the current server time. - return this.world.getDayTime() + this.timeOffset; - } else { - // Adds timeOffset to the beginning of this day. - return this.world.getDayTime() - (this.world.getDayTime() % 24000) + this.timeOffset; - } - } - - public WeatherType weather = null; - - public WeatherType getPlayerWeather() { - return this.weather; - } - - public void setPlayerWeather(WeatherType type, boolean plugin) { - if (!plugin && this.weather != null) { - return; - } - - if (plugin) { - this.weather = type; - } - - if (type == WeatherType.DOWNFALL) { - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(2, 0)); - } else { - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0)); - } - } - - private float pluginRainPosition; - private float pluginRainPositionPrevious; - - public void updateWeather(float oldRain, float newRain, float oldThunder, float newThunder) { - if (this.weather == null) { - // Vanilla - if (oldRain != newRain) { - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, newRain)); - } - } else { - // Plugin - if (pluginRainPositionPrevious != pluginRainPosition) { - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, pluginRainPosition)); - } - } - - if (oldThunder != newThunder) { - if (weather == WeatherType.DOWNFALL || weather == null) { - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, newThunder)); - } else { - this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, 0)); - } - } - } - - public void tickWeather() { - if (this.weather == null) return; - - pluginRainPositionPrevious = pluginRainPosition; - if (weather == WeatherType.DOWNFALL) { - pluginRainPosition += 0.01; - } else { - pluginRainPosition -= 0.01; - } - - pluginRainPosition = MathHelper.a(pluginRainPosition, 0.0F, 1.0F); - } - - public void resetPlayerWeather() { - this.weather = null; - this.setPlayerWeather(this.world.getWorldData().hasStorm() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false); - } - - @Override - public String toString() { - return super.toString() + "(" + this.getName() + " at " + this.locX + "," + this.locY + "," + this.locZ + ")"; - } - - // SPIGOT-1903, MC-98153 - public void forceSetPositionRotation(double x, double y, double z, float yaw, float pitch) { - this.setPositionRotation(x, y, z, yaw, pitch); - this.playerConnection.syncPosition(); - } - - @Override - protected boolean isFrozen() { - return super.isFrozen() || (this.playerConnection != null && this.playerConnection.isDisconnected()); // Paper - } - - @Override - public Scoreboard getScoreboard() { - return getBukkitEntity().getScoreboard().getHandle(); - } - - public void reset() { - float exp = 0; - boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory"); - - if (this.keepLevel || keepInventory) { - exp = this.exp; - this.newTotalExp = this.expTotal; - this.newLevel = this.expLevel; - } - - this.setHealth(this.getMaxHealth()); - this.fireTicks = 0; - this.fallDistance = 0; - this.foodData = new FoodMetaData(this); - this.expLevel = this.newLevel; - this.expTotal = this.newTotalExp; - this.exp = 0; - this.deathTicks = 0; - this.setArrowCount(0); - this.removeAllEffects(); - this.updateEffects = true; - this.activeContainer = this.defaultContainer; - this.killer = null; - this.lastDamager = null; - this.combatTracker = new CombatTracker(this); - this.lastSentExp = -1; - if (this.keepLevel || keepInventory) { - this.exp = exp; - } else { - this.giveExp(this.newExp); - } - this.keepLevel = false; - } - - @Override - public CraftPlayer getBukkitEntity() { - return (CraftPlayer) super.getBukkitEntity(); - } - // CraftBukkit end -} diff --git a/sources/src/main/java/net/minecraft/server/NetworkManager.java b/sources/src/main/java/net/minecraft/server/NetworkManager.java index e1fd739f8..73bfd3aa7 100644 --- a/sources/src/main/java/net/minecraft/server/NetworkManager.java +++ b/sources/src/main/java/net/minecraft/server/NetworkManager.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import com.google.common.collect.Queues; import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.akarin.api.CheckedConcurrentLinkedQueue; diff --git a/sources/src/main/java/net/minecraft/server/PlayerConnection.java b/sources/src/main/java/net/minecraft/server/PlayerConnection.java deleted file mode 100644 index 4c98dbcb3..000000000 --- a/sources/src/main/java/net/minecraft/server/PlayerConnection.java +++ /dev/null @@ -1,2755 +0,0 @@ -package net.minecraft.server; - -import com.google.common.primitives.Doubles; -import com.google.common.primitives.Floats; -import io.akarin.api.Akari; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -// CraftBukkit start -import java.util.HashSet; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.event.CraftEventFactory; -import org.bukkit.craftbukkit.inventory.CraftInventoryView; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.craftbukkit.util.CraftChatMessage; -import org.bukkit.craftbukkit.util.LazyPlayerSet; -import org.bukkit.craftbukkit.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.SlotType; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -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.PlayerResourcePackStatusEvent; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; -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.CraftingInventory; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.InventoryView; -import org.bukkit.util.NumberConversions; -import com.destroystokyo.paper.event.player.IllegalPacketEvent; // Paper -import com.destroystokyo.paper.event.player.PlayerJumpEvent; // Paper -import co.aikar.timings.MinecraftTimings; // Paper -// CraftBukkit end - -public class PlayerConnection implements PacketListenerPlayIn, ITickable { - - private static final Logger LOGGER = LogManager.getLogger(); - public final NetworkManager networkManager; - private final MinecraftServer minecraftServer; - public EntityPlayer player; - private int e; - private long f = getCurrentMillis(); private void setLastPing(long lastPing) { this.f = lastPing;}; private long getLastPing() { return this.f;}; // Paper - OBFHELPER - set ping to delay initial - private boolean g; private void setPendingPing(boolean isPending) { this.g = isPending;}; private boolean isPendingPing() { return this.g;}; // Paper - OBFHELPER - private long h; private void setKeepAliveID(long keepAliveID) { this.h = keepAliveID;}; private long getKeepAliveID() {return this.h; }; // Paper - OBFHELPER - // CraftBukkit start - multithreaded fields - private volatile int chatThrottle; - private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle"); - // CraftBukkit end - private int j; - private final IntHashMap k = new IntHashMap(); - private double l; - private double m; - private double n; - private double o; - private double p; - private double q; - private Entity r; - private double s; - private double t; - private double u; - private double v; - private double w; - private double x; - private Vec3D teleportPos; - private int teleportAwait; - private int A; - private boolean B; - private int C; - private boolean D; - private int E; - private int receivedMovePackets; - private int processedMovePackets; - private AutoRecipe H = new AutoRecipe(); - private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit - - public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) { - this.minecraftServer = minecraftserver; - this.networkManager = networkmanager; - networkmanager.setPacketListener(this); - this.player = entityplayer; - entityplayer.playerConnection = this; - - // CraftBukkit start - add fields and methods - this.server = minecraftserver.server; - } - - private final org.bukkit.craftbukkit.CraftServer server; - private boolean processedDisconnect; - private int lastTick = MinecraftServer.currentTick; - private int allowedPlayerTicks = 1; - private int lastDropTick = MinecraftServer.currentTick; - private int lastBookTick = MinecraftServer.currentTick; - private int dropCount = 0; - private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6; - private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7; - - // Get position of last block hit for BlockDamageLevel.STOPPED - private double lastPosX = Double.MAX_VALUE; - private double lastPosY = Double.MAX_VALUE; - private double lastPosZ = Double.MAX_VALUE; - private float lastPitch = Float.MAX_VALUE; - private float lastYaw = Float.MAX_VALUE; - private boolean justTeleported = false; - private boolean hasMoved; // Spigot - - public CraftPlayer getPlayer() { - return (this.player == null) ? null : (CraftPlayer) this.player.getBukkitEntity(); - } - private final static HashSet invalidItems = new HashSet(java.util.Arrays.asList(8, 9, 10, 11, 26, 34, 36, 43, 51, 55, 59, 62, 63, 64, 68, 71, 74, 75, 83, 90, 92, 93, 94, 104, 105, 115, 117, 118, 119, 125, 127, 132, 140, 141, 142, 144)); // TODO: Check after every update. - // CraftBukkit end - - @Override - public void e() { - this.syncPosition(); - this.player.playerTick(); - this.player.setLocation(this.l, this.m, this.n, this.player.yaw, this.player.pitch); - ++this.e; - this.processedMovePackets = this.receivedMovePackets; - if (this.B) { - if (++this.C > 80) { - Akari.callbackQueue.add(() -> { - PlayerConnection.LOGGER.warn("{} was kicked for floating too long!", this.player.getName()); - this.disconnect(com.destroystokyo.paper.PaperConfig.flyingKickPlayerMessage); // Paper - use configurable kick message - }); // Akarin - post to main thread - return; - } - } else { - this.B = false; - this.C = 0; - } - - this.r = this.player.getVehicle(); - if (this.r != this.player && this.r.bE() == this.player) { - this.s = this.r.locX; - this.t = this.r.locY; - this.u = this.r.locZ; - this.v = this.r.locX; - this.w = this.r.locY; - this.x = this.r.locZ; - if (this.D && this.player.getVehicle().bE() == this.player) { - if (++this.E > 80) { - Akari.callbackQueue.add(() -> { - PlayerConnection.LOGGER.warn("{} was kicked for floating a vehicle too long!", this.player.getName()); - this.disconnect(com.destroystokyo.paper.PaperConfig.flyingKickVehicleMessage); // Paper - use configurable kick message - }); // Akarin - post to main thread - return; - } - } else { - this.D = false; - this.E = 0; - } - } else { - this.r = null; - this.D = false; - this.E = 0; - } - - this.minecraftServer.methodProfiler.a("keepAlive"); - // Paper Start - give clients a longer time to respond to pings as per pre 1.12.2 timings - // This should effectively place the keepalive handling back to "as it was" before 1.12.2 - long currentTime = this.getCurrentMillis(); - long elapsedTime = currentTime - this.getLastPing(); - if (this.isPendingPing()) { - // We're pending a ping from the client - if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected - Akari.callbackQueue.add(() -> { - PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getName()); // more info - this.disconnect(new ChatMessage("disconnect.timeout")); - }); // Akarin - post to main thread - } - } else { - if (elapsedTime >= 15000L) { // 15 seconds - this.setPendingPing(true); - this.setLastPing(currentTime); - this.setKeepAliveID(currentTime); - this.sendPacket(new PacketPlayOutKeepAlive(this.getKeepAliveID())); - } - } - // Paper end - - this.minecraftServer.methodProfiler.b(); - // CraftBukkit start - for (int spam; (spam = this.chatThrottle) > 0 && !chatSpamField.compareAndSet(this, spam, spam - 1); ) ; - /* Use thread-safe field access instead - if (this.chatThrottle > 0) { - --this.chatThrottle; - } - */ - // CraftBukkit end - - if (this.j > 0) { - --this.j; - } - - if (this.player.J() > 0L && this.minecraftServer.getIdleTimeout() > 0 && MinecraftServer.aw() - this.player.J() > this.minecraftServer.getIdleTimeout() * 1000 * 60) { - Akari.callbackQueue.add(() -> { - this.player.resetIdleTimer(); // CraftBukkit - SPIGOT-854 - this.disconnect(new ChatMessage("multiplayer.disconnect.idling", new Object[0])); - }); // Akarin - post to main thread - } - - } - - public void syncPosition() { - this.l = this.player.locX; - this.m = this.player.locY; - this.n = this.player.locZ; - this.o = this.player.locX; - this.p = this.player.locY; - this.q = this.player.locZ; - } - - public NetworkManager a() { - return this.networkManager; - } - - // CraftBukkit start - @Deprecated - public void disconnect(IChatBaseComponent ichatbasecomponent) { - disconnect(CraftChatMessage.fromComponent(ichatbasecomponent, EnumChatFormat.WHITE)); - } - // CraftBukkit end - - public void disconnect(String s) { - // CraftBukkit start - fire PlayerKickEvent - if (this.processedDisconnect) { - 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()) { - // Do not kick the player - return; - } - // Send the possibly modified leave message - s = event.getReason(); - // CraftBukkit end - final ChatComponentText chatcomponenttext = new ChatComponentText(s); - - this.networkManager.sendPacket(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener() { - @Override - public void operationComplete(Future future) throws Exception { // CraftBukkit - decompile error - PlayerConnection.this.networkManager.close(chatcomponenttext); - } - }, new GenericFutureListener[0]); - this.a(chatcomponenttext); // CraftBukkit - fire quit instantly - this.networkManager.stopReading(); - // CraftBukkit - Don't wait - this.minecraftServer.postToMainThread(new Runnable() { - @Override - public void run() { - PlayerConnection.this.networkManager.handleDisconnection(); - } - }); - } - - @Override - public void a(PacketPlayInSteerVehicle packetplayinsteervehicle) { - PlayerConnectionUtils.ensureMainThread(packetplayinsteervehicle, this, this.player.x()); - this.player.a(packetplayinsteervehicle.a(), packetplayinsteervehicle.b(), packetplayinsteervehicle.c(), packetplayinsteervehicle.d()); - } - - private static boolean b(PacketPlayInFlying packetplayinflying) { - return Doubles.isFinite(packetplayinflying.a(0.0D)) && Doubles.isFinite(packetplayinflying.b(0.0D)) && Doubles.isFinite(packetplayinflying.c(0.0D)) && Floats.isFinite(packetplayinflying.b(0.0F)) && Floats.isFinite(packetplayinflying.a(0.0F)) ? Math.abs(packetplayinflying.a(0.0D)) > 3.0E7D || Math.abs(packetplayinflying.b(0.0D)) > 3.0E7D || Math.abs(packetplayinflying.c(0.0D)) > 3.0E7D : true; - } - - private static boolean b(PacketPlayInVehicleMove packetplayinvehiclemove) { - return !Doubles.isFinite(packetplayinvehiclemove.getX()) || !Doubles.isFinite(packetplayinvehiclemove.getY()) || !Doubles.isFinite(packetplayinvehiclemove.getZ()) || !Floats.isFinite(packetplayinvehiclemove.getPitch()) || !Floats.isFinite(packetplayinvehiclemove.getYaw()); - } - - @Override - public void a(PacketPlayInVehicleMove packetplayinvehiclemove) { - PlayerConnectionUtils.ensureMainThread(packetplayinvehiclemove, this, this.player.x()); - if (b(packetplayinvehiclemove)) { - this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_vehicle_movement", new Object[0])); - } else { - Entity entity = this.player.getVehicle(); - - if (entity != this.player && entity.bE() == this.player && entity == this.r) { - WorldServer worldserver = this.player.x(); - double d0 = entity.locX; - double d1 = entity.locY; - double d2 = entity.locZ; - double d3 = packetplayinvehiclemove.getX(); - double d4 = packetplayinvehiclemove.getY(); - double d5 = packetplayinvehiclemove.getZ(); - float f = packetplayinvehiclemove.getYaw(); - float f1 = packetplayinvehiclemove.getPitch(); - double d6 = d3 - this.s; - double d7 = d4 - this.t; - double d8 = d5 - this.u; - double d9 = entity.motX * entity.motX + entity.motY * entity.motY + entity.motZ * entity.motZ; - double d10 = d6 * d6 + d7 * d7 + d8 * d8; - - - // CraftBukkit start - handle custom speeds and skipped ticks - this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick; - this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1); - this.lastTick = (int) (System.currentTimeMillis() / 50); - - ++this.receivedMovePackets; - int i = this.receivedMovePackets - this.processedMovePackets; - if (i > Math.max(this.allowedPlayerTicks, 5)) { - PlayerConnection.LOGGER.debug(this.player.getName() + " is sending move packets too frequently (" + i + " packets since last tick)"); - i = 1; - } - - if (d10 > 0) { - allowedPlayerTicks -= 1; - } else { - allowedPlayerTicks = 20; - } - float speed; - if (player.abilities.isFlying) { - speed = player.abilities.flySpeed * 20f; - } else { - speed = player.abilities.walkSpeed * 10f; - } - speed *= 2f; // TODO: Get the speed of the vehicle instead of the player - - if (d10 - d9 > Math.max(100.0D, Math.pow(org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * i * speed, 2)) && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(entity.getName()))) { // Spigot - // CraftBukkit end - PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName(), this.player.getName(), Double.valueOf(d6), Double.valueOf(d7), Double.valueOf(d8)); - this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity)); - return; - } - - boolean flag = worldserver.getCubes(entity, entity.getBoundingBox().shrink(0.0625D)).isEmpty(); - - d6 = d3 - this.v; - d7 = d4 - this.w - 1.0E-6D; - d8 = d5 - this.x; - entity.move(EnumMoveType.PLAYER, d6, d7, d8); - double d11 = d7; - - d6 = d3 - entity.locX; - d7 = d4 - entity.locY; - if (d7 > -0.5D || d7 < 0.5D) { - d7 = 0.0D; - } - - d8 = d5 - entity.locZ; - d10 = d6 * d6 + d7 * d7 + d8 * d8; - boolean flag1 = false; - - if (d10 > org.spigotmc.SpigotConfig.movedWronglyThreshold) { // Spigot - flag1 = true; - PlayerConnection.LOGGER.warn(entity.getName() + " (vehicle of " + this.player.getName() + ") moved wrongly!"); // Paper - More informative - } - - entity.setLocation(d3, d4, d5, f, f1); - boolean flag2 = worldserver.getCubes(entity, entity.getBoundingBox().shrink(0.0625D)).isEmpty(); - - if (flag && (flag1 || !flag2)) { - entity.setLocation(d0, d1, d2, f, f1); - this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity)); - return; - } - - // CraftBukkit start - fire PlayerMoveEvent - Player player = this.getPlayer(); - // Spigot Start - if ( !hasMoved ) - { - Location curPos = player.getLocation(); - lastPosX = curPos.getX(); - lastPosY = curPos.getY(); - lastPosZ = curPos.getZ(); - lastYaw = curPos.getYaw(); - lastPitch = curPos.getPitch(); - hasMoved = true; - } - // Spigot End - Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location. - Location to = player.getLocation().clone(); // Start off the To location as the Players current location. - - // If the packet contains movement information then we update the To location with the correct XYZ. - to.setX(packetplayinvehiclemove.getX()); - to.setY(packetplayinvehiclemove.getY()); - to.setZ(packetplayinvehiclemove.getZ()); - - - // If the packet contains look information then we update the To location with the correct Yaw & Pitch. - to.setYaw(packetplayinvehiclemove.getYaw()); - to.setPitch(packetplayinvehiclemove.getPitch()); - - // Prevent 40 event-calls for less than a single pixel of movement >.> - double delta = Math.pow(this.lastPosX - to.getX(), 2) + Math.pow(this.lastPosY - to.getY(), 2) + Math.pow(this.lastPosZ - to.getZ(), 2); - float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch()); - - if ((delta > 1f / 256 || deltaAngle > 10f) && !this.player.isFrozen()) { - this.lastPosX = to.getX(); - this.lastPosY = to.getY(); - this.lastPosZ = to.getZ(); - this.lastYaw = to.getYaw(); - this.lastPitch = to.getPitch(); - - // Skip the first time we do this - if (true) { // Spigot - don't skip any move events - Location oldTo = to.clone(); - PlayerMoveEvent event = new PlayerMoveEvent(player, from, to); - this.server.getPluginManager().callEvent(event); - - // If the event is cancelled we move the player back to their old location. - if (event.isCancelled()) { - teleport(from); - return; - } - - // If a Plugin has changed the To destination then we teleport the Player - // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors. - // We only do this if the Event was not cancelled. - if (!oldTo.equals(event.getTo()) && !event.isCancelled()) { - this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN); - return; - } - - // Check to see if the Players Location has some how changed during the call of the event. - // This can happen due to a plugin teleporting the player instead of using .setTo() - if (!from.equals(this.getPlayer().getLocation()) && this.justTeleported) { - this.justTeleported = false; - return; - } - } - } - // CraftBukkit end - - this.minecraftServer.getPlayerList().d(this.player); - this.player.checkMovement(this.player.locX - d0, this.player.locY - d1, this.player.locZ - d2); - this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && !worldserver.c(entity.getBoundingBox().g(0.0625D).b(0.0D, -0.55D, 0.0D)); - this.v = entity.locX; - this.w = entity.locY; - this.x = entity.locZ; - } - - } - } - - @Override - public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) { - PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.x()); - if (packetplayinteleportaccept.a() == this.teleportAwait && this.teleportPos != null) { // CraftBukkit - this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); - if (this.player.L()) { - this.o = this.teleportPos.x; - this.p = this.teleportPos.y; - this.q = this.teleportPos.z; - this.player.M(); - } - - this.teleportPos = null; - } - - } - - @Override - public void a(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { - PlayerConnectionUtils.ensureMainThread(packetplayinrecipedisplayed, this, this.player.x()); - if (packetplayinrecipedisplayed.a() == PacketPlayInRecipeDisplayed.Status.SHOWN) { - this.player.F().f(packetplayinrecipedisplayed.b()); - } else if (packetplayinrecipedisplayed.a() == PacketPlayInRecipeDisplayed.Status.SETTINGS) { - this.player.F().a(packetplayinrecipedisplayed.c()); - this.player.F().b(packetplayinrecipedisplayed.d()); - } - - } - - @Override - public void a(PacketPlayInAdvancements packetplayinadvancements) { - PlayerConnectionUtils.ensureMainThread(packetplayinadvancements, this, this.player.x()); - if (packetplayinadvancements.b() == PacketPlayInAdvancements.Status.OPENED_TAB) { - MinecraftKey minecraftkey = packetplayinadvancements.c(); - Advancement advancement = this.minecraftServer.getAdvancementData().a(minecraftkey); - - if (advancement != null) { - this.player.getAdvancementData().a(advancement); - } - } - - } - - @Override - public void a(PacketPlayInFlying packetplayinflying) { - PlayerConnectionUtils.ensureMainThread(packetplayinflying, this, this.player.x()); - if (b(packetplayinflying)) { - this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_player_movement", new Object[0])); - } else { - WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); - - if (!this.player.viewingCredits && !this.player.isFrozen()) { // CraftBukkit - if (this.e == 0) { - this.syncPosition(); - } - - if (this.teleportPos != null) { - if (this.e - this.A > 20) { - this.A = this.e; - this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); - } - this.allowedPlayerTicks = 20; // CraftBukkit - } else { - this.A = this.e; - if (this.player.isPassenger()) { - this.player.setLocation(this.player.locX, this.player.locY, this.player.locZ, packetplayinflying.a(this.player.yaw), packetplayinflying.b(this.player.pitch)); - this.minecraftServer.getPlayerList().d(this.player); - this.allowedPlayerTicks = 20; // CraftBukkit - } else { - // CraftBukkit - Make sure the move is valid but then reset it for plugins to modify - double prevX = player.locX; - double prevY = player.locY; - double prevZ = player.locZ; - float prevYaw = player.yaw; - float prevPitch = player.pitch; - // CraftBukkit end - double d0 = this.player.locX; - double d1 = this.player.locY; - double d2 = this.player.locZ; - double d3 = this.player.locY; - double d4 = packetplayinflying.a(this.player.locX); - double d5 = packetplayinflying.b(this.player.locY); - double d6 = packetplayinflying.c(this.player.locZ); - float f = packetplayinflying.a(this.player.yaw); - float f1 = packetplayinflying.b(this.player.pitch); - double d7 = d4 - this.l; - double d8 = d5 - this.m; - double d9 = d6 - this.n; - double d10 = this.player.motX * this.player.motX + this.player.motY * this.player.motY + this.player.motZ * this.player.motZ; - double d11 = d7 * d7 + d8 * d8 + d9 * d9; - - if (this.player.isSleeping()) { - if (d11 > 1.0D) { - this.a(this.player.locX, this.player.locY, this.player.locZ, packetplayinflying.a(this.player.yaw), packetplayinflying.b(this.player.pitch)); - } - - } else { - ++this.receivedMovePackets; - int i = this.receivedMovePackets - this.processedMovePackets; - - // CraftBukkit start - handle custom speeds and skipped ticks - this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick; - this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1); - this.lastTick = (int) (System.currentTimeMillis() / 50); - - if (i > Math.max(this.allowedPlayerTicks, 5)) { - PlayerConnection.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName(), Integer.valueOf(i)); - i = 1; - } - - if (packetplayinflying.hasLook || d11 > 0) { - allowedPlayerTicks -= 1; - } else { - allowedPlayerTicks = 20; - } - float speed; - if (player.abilities.isFlying) { - speed = player.abilities.flySpeed * 20f; - } else { - speed = player.abilities.walkSpeed * 10f; - } - - if (!this.player.L() && (!this.player.x().getGameRules().getBoolean("disableElytraMovementCheck") || !this.player.cP())) { - float f2 = this.player.cP() ? 300.0F : 100.0F; - - if (d11 - d10 > Math.max(f2, Math.pow(org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * i * speed, 2)) && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(this.player.getName()))) { // Spigot - // CraftBukkit end - PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getName(), Double.valueOf(d7), Double.valueOf(d8), Double.valueOf(d9)); - this.a(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch); - return; - } - } - - boolean flag = worldserver.getCubes(this.player, this.player.getBoundingBox().shrink(0.0625D)).isEmpty(); - - d7 = d4 - this.o; - d8 = d5 - this.p; - d9 = d6 - this.q; - if (this.player.onGround && !packetplayinflying.a() && d8 > 0.0D) { - // Paper start - Add player jump event - Player player = this.getPlayer(); - Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location. - Location to = player.getLocation().clone(); // Start off the To location as the Players current location. - - // If the packet contains movement information then we update the To location with the correct XYZ. - if (packetplayinflying.hasPos) { - to.setX(packetplayinflying.x); - to.setY(packetplayinflying.y); - to.setZ(packetplayinflying.z); - } - - // If the packet contains look information then we update the To location with the correct Yaw & Pitch. - if (packetplayinflying.hasLook) { - to.setYaw(packetplayinflying.yaw); - to.setPitch(packetplayinflying.pitch); - } - - PlayerJumpEvent event = new PlayerJumpEvent(player, from, to); - - if (event.callEvent()) { - this.player.jump(); - } else { - from = event.getFrom(); - this.internalTeleport(from.getX(), from.getY(), from.getZ(), from.getYaw(), from.getPitch(), Collections.emptySet()); - return; - } - // Paper end - } - - this.player.move(EnumMoveType.PLAYER, d7, d8, d9); - this.player.onGround = packetplayinflying.a(); - double d12 = d8; - - d7 = d4 - this.player.locX; - d8 = d5 - this.player.locY; - if (d8 > -0.5D || d8 < 0.5D) { - d8 = 0.0D; - } - - d9 = d6 - this.player.locZ; - d11 = d7 * d7 + d8 * d8 + d9 * d9; - boolean flag1 = false; - - if (!this.player.L() && d11 > org.spigotmc.SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.playerInteractManager.isCreative() && this.player.playerInteractManager.getGameMode() != EnumGamemode.SPECTATOR) { // Spigot - flag1 = true; - PlayerConnection.LOGGER.warn("{} moved wrongly!", this.player.getName()); - } - - this.player.setLocation(d4, d5, d6, f, f1); - this.player.checkMovement(this.player.locX - d0, this.player.locY - d1, this.player.locZ - d2); - if (!this.player.noclip && !this.player.isSleeping()) { - boolean flag2 = worldserver.getCubes(this.player, this.player.getBoundingBox().shrink(0.0625D)).isEmpty(); - - if (flag && (flag1 || !flag2)) { - this.a(d0, d1, d2, f, f1); - return; - } - } - - // CraftBukkit start - fire PlayerMoveEvent - // Rest to old location first - this.player.setLocation(prevX, prevY, prevZ, prevYaw, prevPitch); - - Player player = this.getPlayer(); - Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location. - Location to = player.getLocation().clone(); // Start off the To location as the Players current location. - - // If the packet contains movement information then we update the To location with the correct XYZ. - if (packetplayinflying.hasPos) { - to.setX(packetplayinflying.x); - to.setY(packetplayinflying.y); - to.setZ(packetplayinflying.z); - } - - // If the packet contains look information then we update the To location with the correct Yaw & Pitch. - if (packetplayinflying.hasLook) { - to.setYaw(packetplayinflying.yaw); - to.setPitch(packetplayinflying.pitch); - } - - // Prevent 40 event-calls for less than a single pixel of movement >.> - double delta = Math.pow(this.lastPosX - to.getX(), 2) + Math.pow(this.lastPosY - to.getY(), 2) + Math.pow(this.lastPosZ - to.getZ(), 2); - float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch()); - - if ((delta > 1f / 256 || deltaAngle > 10f) && !this.player.isFrozen()) { - this.lastPosX = to.getX(); - this.lastPosY = to.getY(); - this.lastPosZ = to.getZ(); - this.lastYaw = to.getYaw(); - this.lastPitch = to.getPitch(); - - // Skip the first time we do this - if (from.getX() != Double.MAX_VALUE) { - Location oldTo = to.clone(); - PlayerMoveEvent event = new PlayerMoveEvent(player, from, to); - this.server.getPluginManager().callEvent(event); - - // If the event is cancelled we move the player back to their old location. - if (event.isCancelled()) { - teleport(from); - return; - } - - // If a Plugin has changed the To destination then we teleport the Player - // there to avoid any 'Moved wrongly' or 'Moved too quickly' errors. - // We only do this if the Event was not cancelled. - if (!oldTo.equals(event.getTo()) && !event.isCancelled()) { - this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN); - return; - } - - // Check to see if the Players Location has some how changed during the call of the event. - // This can happen due to a plugin teleporting the player instead of using .setTo() - if (!from.equals(this.getPlayer().getLocation()) && this.justTeleported) { - this.justTeleported = false; - return; - } - } - } - this.player.setLocation(d4, d5, d6, f, f1); // Copied from above - // CraftBukkit end - - this.B = d12 >= -0.03125D; - this.B &= !this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly; - this.B &= !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.cP() && !worldserver.c(this.player.getBoundingBox().g(0.0625D).b(0.0D, -0.55D, 0.0D)); - this.player.onGround = packetplayinflying.a(); - this.minecraftServer.getPlayerList().d(this.player); - this.player.a(this.player.locY - d3, packetplayinflying.a()); - this.o = this.player.locX; - this.p = this.player.locY; - this.q = this.player.locZ; - } - } - } - } - } - } - - public void a(double d0, double d1, double d2, float f, float f1) { - this.a(d0, d1, d2, f, f1, Collections.emptySet()); - } - - // CraftBukkit start - Delegate to teleport(Location) - public void a(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) { - this.a(d0, d1, d2, f, f1, Collections.emptySet(), cause); - } - - public void a(double d0, double d1, double d2, float f, float f1, Set set) { - this.a(d0, d1, d2, f, f1, set, PlayerTeleportEvent.TeleportCause.UNKNOWN); - } - - public void a(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { - Player player = this.getPlayer(); - Location from = player.getLocation(); - - double x = d0; - double y = d1; - double z = d2; - float yaw = f; - float pitch = f1; - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X)) { - x += from.getX(); - } - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y)) { - y += from.getY(); - } - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z)) { - z += from.getZ(); - } - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)) { - yaw += from.getYaw(); - } - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT)) { - pitch += from.getPitch(); - } - - - Location to = new Location(this.getPlayer().getWorld(), x, y, z, yaw, pitch); - PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause); - this.server.getPluginManager().callEvent(event); - - if (event.isCancelled() || !to.equals(event.getTo())) { - set.clear(); // Can't relative teleport - to = event.isCancelled() ? event.getFrom() : event.getTo(); - d0 = to.getX(); - d1 = to.getY(); - d2 = to.getZ(); - f = to.getYaw(); - f1 = to.getPitch(); - } - - this.internalTeleport(d0, d1, d2, f, f1, set); - } - - public void teleport(Location dest) { - internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet()); - } - - private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set set) { - // CraftBukkit start - if (Float.isNaN(f)) { - f = 0; - } - if (Float.isNaN(f1)) { - f1 = 0; - } - - this.justTeleported = true; - // CraftBukkit end - double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.locX : 0.0D; - double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.locY : 0.0D; - double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.locZ : 0.0D; - - this.teleportPos = new Vec3D(d0 + d3, d1 + d4, d2 + d5); - float f2 = f; - float f3 = f1; - - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)) { - f2 = f + this.player.yaw; - } - - if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT)) { - f3 = f1 + this.player.pitch; - } - - // CraftBukkit start - update last location - this.lastPosX = this.teleportPos.x; - this.lastPosY = this.teleportPos.y; - this.lastPosZ = this.teleportPos.z; - this.lastYaw = f2; - this.lastPitch = f3; - // CraftBukkit end - - if (++this.teleportAwait == Integer.MAX_VALUE) { - this.teleportAwait = 0; - } - - this.A = this.e; - this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, f2, f3); - this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0, d1, d2, f, f1, set, this.teleportAwait)); - } - - @Override - public void a(PacketPlayInBlockDig packetplayinblockdig) { - PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); - BlockPosition blockposition = packetplayinblockdig.a(); - - this.player.resetIdleTimer(); - switch (packetplayinblockdig.c()) { - case SWAP_HELD_ITEMS: - if (!this.player.isSpectator()) { - ItemStack itemstack = this.player.b(EnumHand.OFF_HAND); - - // CraftBukkit start - PlayerSwapHandItemsEvent swapItemsEvent = new PlayerSwapHandItemsEvent(getPlayer(), CraftItemStack.asBukkitCopy(itemstack), CraftItemStack.asBukkitCopy(this.player.b(EnumHand.MAIN_HAND))); - this.server.getPluginManager().callEvent(swapItemsEvent); - if (swapItemsEvent.isCancelled()) { - return; - } - itemstack = CraftItemStack.asNMSCopy(swapItemsEvent.getMainHandItem()); - this.player.a(EnumHand.OFF_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getOffHandItem())); - // CraftBukkit end - this.player.a(EnumHand.MAIN_HAND, itemstack); - } - - return; - - case DROP_ITEM: - if (!this.player.isSpectator()) { - // limit how quickly items can be dropped - // If the ticks aren't the same then the count starts from 0 and we update the lastDropTick. - if (this.lastDropTick != MinecraftServer.currentTick) { - this.dropCount = 0; - this.lastDropTick = MinecraftServer.currentTick; - } else { - // Else we increment the drop count and check the amount. - this.dropCount++; - if (this.dropCount >= 20) { - LOGGER.warn(this.player.getName() + " dropped their items too quickly!"); - this.disconnect("You dropped your items too quickly (Hacking?)"); - return; - } - } - // CraftBukkit end - this.player.a(false); - } - - return; - - case DROP_ALL_ITEMS: - if (!this.player.isSpectator()) { - this.player.a(true); - } - - return; - - case RELEASE_USE_ITEM: - this.player.clearActiveItem(); - return; - - case START_DESTROY_BLOCK: - case ABORT_DESTROY_BLOCK: - case STOP_DESTROY_BLOCK: - double d0 = this.player.locX - (blockposition.getX() + 0.5D); - double d1 = this.player.locY - (blockposition.getY() + 0.5D) + 1.5D; - double d2 = this.player.locZ - (blockposition.getZ() + 0.5D); - double d3 = d0 * d0 + d1 * d1 + d2 * d2; - - if (d3 > 36.0D) { - this.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition)); // Paper - Fix block break desync - return; - } else if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight()) { - return; - } else { - if (packetplayinblockdig.c() == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) { - if (!this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) { - this.player.playerInteractManager.a(blockposition, packetplayinblockdig.b()); - } else { - // CraftBukkit start - fire PlayerInteractEvent - CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockposition, packetplayinblockdig.b(), this.player.inventory.getItemInHand(), EnumHand.MAIN_HAND); - this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition)); - // Update any tile entity data for this block - TileEntity tileentity = worldserver.getTileEntity(blockposition); - if (tileentity != null) { - this.player.playerConnection.sendPacket(tileentity.getUpdatePacket()); - } - // CraftBukkit end - } - } else { - if (packetplayinblockdig.c() == PacketPlayInBlockDig.EnumPlayerDigType.STOP_DESTROY_BLOCK) { - this.player.playerInteractManager.a(blockposition); - } else if (packetplayinblockdig.c() == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) { - this.player.playerInteractManager.e(); - } - - if (worldserver.getType(blockposition).getMaterial() != Material.AIR) { - this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition)); - } - } - - return; - } - - default: - throw new IllegalArgumentException("Invalid player action"); - } - // CraftBukkit end - } - - // Spigot start - limit place/interactions - private int limitedPackets; - private long lastLimitedPacket = -1; - private static final int THRESHOLD = com.destroystokyo.paper.PaperConfig.packetInSpamThreshold; // Paper - Configurable threshold - - private boolean checkLimit(long timestamp) { - if (lastLimitedPacket != -1 && timestamp - lastLimitedPacket < THRESHOLD && limitedPackets++ >= 8) { // Paper - Use threshold, raise packet limit to 8 - return false; - } - - if (lastLimitedPacket == -1 || timestamp - lastLimitedPacket >= THRESHOLD) { // Paper - lastLimitedPacket = timestamp; - limitedPackets = 0; - return true; - } - - return true; - } - // Spigot end - - @Override - public void a(PacketPlayInUseItem packetplayinuseitem) { - PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - if (!checkLimit(packetplayinuseitem.timestamp)) return; // Spigot - check limit - WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); - EnumHand enumhand = packetplayinuseitem.c(); - ItemStack itemstack = this.player.b(enumhand); - BlockPosition blockposition = packetplayinuseitem.a(); - EnumDirection enumdirection = packetplayinuseitem.b(); - - this.player.resetIdleTimer(); - if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && (enumdirection == EnumDirection.UP || blockposition.getY() >= this.minecraftServer.getMaxBuildHeight())) { - ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())}); - - chatmessage.getChatModifier().setColor(EnumChatFormat.RED); - this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage, ChatMessageType.GAME_INFO)); - } else if (this.teleportPos == null && this.player.d(blockposition.getX() + 0.5D, blockposition.getY() + 0.5D, blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) { - // CraftBukkit start - Check if we can actually do something over this large a distance - Location eyeLoc = this.getPlayer().getEyeLocation(); - double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ()); - if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) { - return; - } - // CraftBukkit end - this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, blockposition, enumdirection, packetplayinuseitem.d(), packetplayinuseitem.e(), packetplayinuseitem.f()); - } - - this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition)); - this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition.shift(enumdirection))); - } - - @Override - public void a(PacketPlayInBlockPlace packetplayinblockplace) { - PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - if (!checkLimit(packetplayinblockplace.timestamp)) return; // Spigot - check limit - WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); - EnumHand enumhand = packetplayinblockplace.a(); - ItemStack itemstack = this.player.b(enumhand); - - this.player.resetIdleTimer(); - if (!itemstack.isEmpty()) { - // CraftBukkit start - // Raytrace to look for 'rogue armswings' - float f1 = this.player.pitch; - float f2 = this.player.yaw; - double d0 = this.player.locX; - double d1 = this.player.locY + this.player.getHeadHeight(); - double d2 = this.player.locZ; - Vec3D vec3d = new Vec3D(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 = 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); - - boolean cancelled; - if (movingobjectposition == null || movingobjectposition.type != MovingObjectPosition.EnumMovingObjectType.BLOCK) { - org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack, enumhand); - cancelled = event.useItemInHand() == Event.Result.DENY; - } else { - if (player.playerInteractManager.firedInteract) { - player.playerInteractManager.firedInteract = false; - cancelled = player.playerInteractManager.interactResult; - } else { - org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectposition.a(), movingobjectposition.direction, itemstack, true, enumhand); - cancelled = event.useItemInHand() == Event.Result.DENY; - } - } - - if (cancelled) { - this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524 - } else { - this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand); - } - // CraftBukkit end - } - } - - @Override - public void a(PacketPlayInSpectate packetplayinspectate) { - PlayerConnectionUtils.ensureMainThread(packetplayinspectate, this, this.player.x()); - if (this.player.isSpectator()) { - Entity entity = null; - WorldServer[] aworldserver = this.minecraftServer.worldServer; - int i = aworldserver.length; - - // CraftBukkit - use the worlds array list - for (WorldServer worldserver : minecraftServer.worlds) { - - if (worldserver != null) { - entity = packetplayinspectate.a(worldserver); - if (entity != null) { - break; - } - } - } - - if (entity != null) { - this.player.setSpectatorTarget(this.player); - this.player.stopRiding(); - - /* CraftBukkit start - replace with bukkit handling for multi-world - if (entity.world == this.player.world) { - this.player.enderTeleportTo(entity.locX, entity.locY, entity.locZ); - } else { - WorldServer worldserver1 = this.player.x(); - WorldServer worldserver2 = (WorldServer) entity.world; - - this.player.dimension = entity.dimension; - this.sendPacket(new PacketPlayOutRespawn(this.player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldData().getType(), this.player.playerInteractManager.getGameMode())); - this.minecraftServer.getPlayerList().f(this.player); - worldserver1.removeEntity(this.player); - this.player.dead = false; - this.player.setPositionRotation(entity.locX, entity.locY, entity.locZ, entity.yaw, entity.pitch); - if (this.player.isAlive()) { - worldserver1.entityJoinedWorld(this.player, false); - worldserver2.addEntity(this.player); - worldserver2.entityJoinedWorld(this.player, false); - } - - this.player.spawnIn(worldserver2); - this.minecraftServer.getPlayerList().a(this.player, worldserver1); - this.player.enderTeleportTo(entity.locX, entity.locY, entity.locZ); - this.player.playerInteractManager.a(worldserver2); - this.minecraftServer.getPlayerList().b(this.player, worldserver2); - this.minecraftServer.getPlayerList().updateClient(this.player); - } - */ - this.player.getBukkitEntity().teleport(entity.getBukkitEntity(), PlayerTeleportEvent.TeleportCause.SPECTATE); - // CraftBukkit end - } - } - - } - - // CraftBukkit start - @Override - public void a(PacketPlayInResourcePackStatus packetplayinresourcepackstatus) { - PlayerConnectionUtils.ensureMainThread(packetplayinresourcepackstatus, this, this.player.x()); - // Paper start - //this.server.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(getPlayer(), PlayerResourcePackStatusEvent.Status.values()[packetplayinresourcepackstatus.status.ordinal()])); - final PlayerResourcePackStatusEvent.Status status = PlayerResourcePackStatusEvent.Status.values()[packetplayinresourcepackstatus.status.ordinal()]; - this.getPlayer().setResourcePackStatus(status); - this.server.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(getPlayer(), status)); - // Paper end - } - // CraftBukkit end - - @Override - public void a(PacketPlayInBoatMove packetplayinboatmove) { - PlayerConnectionUtils.ensureMainThread(packetplayinboatmove, this, this.player.x()); - Entity entity = this.player.bJ(); - - if (entity instanceof EntityBoat) { - ((EntityBoat) entity).a(packetplayinboatmove.a(), packetplayinboatmove.b()); - } - - } - - @Override - public void a(IChatBaseComponent ichatbasecomponent) { - // CraftBukkit start - Rarely it would send a disconnect line twice - if (this.processedDisconnect) { - return; - } else { - this.processedDisconnect = true; - } - // CraftBukkit end - PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName(), ichatbasecomponent.toPlainText()); - // CraftBukkit start - Replace vanilla quit message handling with our own. - /* - this.minecraftServer.aD(); - ChatMessage chatmessage = new ChatMessage("multiplayer.player.left", new Object[] { this.player.getScoreboardDisplayName()}); - - chatmessage.getChatModifier().setColor(EnumChatFormat.YELLOW); - this.minecraftServer.getPlayerList().sendMessage(chatmessage); - */ - - this.player.s(); - String quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player); - if ((quitMessage != null) && (quitMessage.length() > 0)) { - this.minecraftServer.getPlayerList().sendMessage(CraftChatMessage.fromString(quitMessage)); - } - // CraftBukkit end - if (this.minecraftServer.R() && this.player.getName().equals(this.minecraftServer.Q())) { - PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out"); - this.minecraftServer.safeShutdown(); - } - - } - - public void sendPacket(final Packet packet) { - if (packet instanceof PacketPlayOutChat) { - PacketPlayOutChat packetplayoutchat = (PacketPlayOutChat) packet; - EntityHuman.EnumChatVisibility entityhuman_enumchatvisibility = this.player.getChatFlags(); - - if (entityhuman_enumchatvisibility == EntityHuman.EnumChatVisibility.HIDDEN && packetplayoutchat.c() != ChatMessageType.GAME_INFO) { - return; - } - - if (entityhuman_enumchatvisibility == EntityHuman.EnumChatVisibility.SYSTEM && !packetplayoutchat.b()) { - return; - } - } - - // CraftBukkit start - if (packet == null || this.processedDisconnect) { // Spigot - return; - } else if (packet instanceof PacketPlayOutSpawnPosition) { - PacketPlayOutSpawnPosition packet6 = (PacketPlayOutSpawnPosition) packet; - this.player.compassTarget = new Location(this.getPlayer().getWorld(), packet6.position.getX(), packet6.position.getY(), packet6.position.getZ()); - } - // CraftBukkit end - - try { - this.networkManager.sendPacket(packet); - } catch (Throwable throwable) { - CrashReport crashreport = CrashReport.a(throwable, "Sending packet"); - CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent"); - - crashreportsystemdetails.a("Packet class", new CrashReportCallable() { - public String a() throws Exception { - return packet.getClass().getCanonicalName(); - } - - @Override - public Object call() throws Exception { - return this.a(); - } - }); - throw new ReportedException(crashreport); - } - } - - @Override - public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) { - PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - if (packetplayinhelditemslot.a() >= 0 && packetplayinhelditemslot.a() < PlayerInventory.getHotbarSize()) { - PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.inventory.itemInHandIndex, packetplayinhelditemslot.a()); - this.server.getPluginManager().callEvent(event); - if (event.isCancelled()) { - this.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex)); - this.player.resetIdleTimer(); - return; - } - // CraftBukkit end - this.player.inventory.itemInHandIndex = packetplayinhelditemslot.a(); - this.player.resetIdleTimer(); - } else { - PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName()); - this.disconnect("Invalid hotbar selection (Hacking?)"); // CraftBukkit //Spigot "Nope" -> Descriptive reason - } - } - - @Override - public void a(PacketPlayInChat packetplayinchat) { - // CraftBukkit start - async chat - // SPIGOT-3638 - if (this.minecraftServer.isStopped()) { - return; - } - - boolean isSync = packetplayinchat.a().startsWith("/"); - if (packetplayinchat.a().startsWith("/")) { - PlayerConnectionUtils.ensureMainThread(packetplayinchat, this, this.player.x()); - } - // CraftBukkit end - if (this.player.dead || this.player.getChatFlags() == EntityHuman.EnumChatVisibility.HIDDEN) { // CraftBukkit - dead men tell no tales - ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]); - - chatmessage.getChatModifier().setColor(EnumChatFormat.RED); - this.sendPacket(new PacketPlayOutChat(chatmessage)); - } else { - this.player.resetIdleTimer(); - String s = packetplayinchat.a(); - - s = StringUtils.normalizeSpace(s); - - for (int i = 0; i < s.length(); ++i) { - if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) { - // CraftBukkit start - threadsafety - if (!isSync) { - Waitable waitable = new Waitable() { - @Override - protected Object evaluate() { - PlayerConnection.this.disconnect(new ChatMessage("multiplayer.disconnect.illegal_characters", new Object[0])); - return null; - } - }; - - this.minecraftServer.processQueue.add(waitable); - - try { - waitable.get(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } - } else { - this.disconnect(new ChatMessage("multiplayer.disconnect.illegal_characters", new Object[0])); - } - // CraftBukkit end - return; - } - } - - // CraftBukkit start - if (isSync) { - try { - this.minecraftServer.server.playerCommandState = true; - this.handleCommand(s); - } finally { - this.minecraftServer.server.playerCommandState = false; - } - } else if (s.isEmpty()) { - LOGGER.warn(this.player.getName() + " tried to send an empty message"); - } else if (getPlayer().isConversing()) { - // Spigot start - final String message = s; - this.minecraftServer.processQueue.add( new Waitable() - { - @Override - protected Object evaluate() - { - getPlayer().acceptConversationInput( message ); - return null; - } - } ); - // Spigot end - } else if (this.player.getChatFlags() == EntityHuman.EnumChatVisibility.SYSTEM) { // Re-add "Command Only" flag check - ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]); - - chatmessage.getChatModifier().setColor(EnumChatFormat.RED); - this.sendPacket(new PacketPlayOutChat(chatmessage)); - } else if (true) { - this.chat(s, true); - // CraftBukkit end - the below is for reference. :) - } else { - ChatMessage chatmessage1 = new ChatMessage("chat.type.text", new Object[] { this.player.getScoreboardDisplayName(), s}); - - this.minecraftServer.getPlayerList().sendMessage(chatmessage1, false); - } - - // Spigot start - spam exclusions - boolean counted = true; - for ( String exclude : org.spigotmc.SpigotConfig.spamExclusions ) - { - if ( exclude != null && s.startsWith( exclude ) ) - { - counted = false; - break; - } - } - // Spigot end - // CraftBukkit start - replaced with thread safe throttle - // this.chatThrottle += 20; - if (counted && chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) { // Spigot - if (!isSync) { - Waitable waitable = new Waitable() { - @Override - protected Object evaluate() { - PlayerConnection.this.disconnect(new ChatMessage("disconnect.spam", new Object[0])); - return null; - } - }; - - this.minecraftServer.processQueue.add(waitable); - - try { - waitable.get(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } - } else { - this.disconnect(new ChatMessage("disconnect.spam", new Object[0])); - } - // CraftBukkit end - } - - } - } - - // CraftBukkit start - add method - public void chat(String s, boolean async) { - if (s.isEmpty() || this.player.getChatFlags() == EntityHuman.EnumChatVisibility.HIDDEN) { - return; - } - - if (!async && s.startsWith("/")) { - // Paper Start - if (!org.spigotmc.AsyncCatcher.shuttingDown && !org.bukkit.Bukkit.isPrimaryThread()) { - final String fCommandLine = s; - MinecraftServer.LOGGER.log(org.apache.logging.log4j.Level.ERROR, "Command Dispatched Async: " + fCommandLine); - MinecraftServer.LOGGER.log(org.apache.logging.log4j.Level.ERROR, "Please notify author of plugin causing this execution to fix this bug! see: http://bit.ly/1oSiM6C", new Throwable()); - Waitable wait = new Waitable() { - @Override - protected Object evaluate() { - chat(fCommandLine, false); - return null; - } - }; - minecraftServer.processQueue.add(wait); - try { - wait.get(); - return; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); // This is proper habit for java. If we aren't handling it, pass it on! - } catch (Exception e) { - throw new RuntimeException("Exception processing chat command", e.getCause()); - } - } - // Paper End - this.handleCommand(s); - } else if (this.player.getChatFlags() == EntityHuman.EnumChatVisibility.SYSTEM) { - // Do nothing, this is coming from a plugin - } else { - Player player = this.getPlayer(); - AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(minecraftServer)); - this.server.getPluginManager().callEvent(event); - - if (PlayerChatEvent.getHandlerList().getRegisteredListeners().length != 0) { - // Evil plugins still listening to deprecated event - final PlayerChatEvent queueEvent = new PlayerChatEvent(player, event.getMessage(), event.getFormat(), event.getRecipients()); - queueEvent.setCancelled(event.isCancelled()); - Waitable waitable = new Waitable() { - @Override - protected Object evaluate() { - org.bukkit.Bukkit.getPluginManager().callEvent(queueEvent); - - if (queueEvent.isCancelled()) { - return null; - } - - String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage()); - PlayerConnection.this.minecraftServer.console.sendMessage(message); - if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) { - for (Object player : PlayerConnection.this.minecraftServer.getPlayerList().players) { - ((EntityPlayer) player).sendMessage(CraftChatMessage.fromString(message)); - } - } else { - for (Player player : queueEvent.getRecipients()) { - player.sendMessage(message); - } - } - return null; - }}; - if (async) { - minecraftServer.processQueue.add(waitable); - } else { - waitable.run(); - } - try { - waitable.get(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); // This is proper habit for java. If we aren't handling it, pass it on! - } catch (ExecutionException e) { - throw new RuntimeException("Exception processing chat event", e.getCause()); - } - } else { - if (event.isCancelled()) { - return; - } - - // Paper Start - (Meh) Support for vanilla world scoreboard name coloring - String displayName = event.getPlayer().getDisplayName(); - if (this.player.getWorld().paperConfig.useVanillaScoreboardColoring) { - displayName = ScoreboardTeam.getPlayerDisplayName(this.player.getTeam(), player.getDisplayName()); - } - - s = String.format(event.getFormat(), displayName, event.getMessage()); - // Paper end - minecraftServer.console.sendMessage(s); - if (((LazyPlayerSet) event.getRecipients()).isLazy()) { - for (Object recipient : minecraftServer.getPlayerList().players) { - ((EntityPlayer) recipient).sendMessage(CraftChatMessage.fromString(s)); - } - } else { - for (Player recipient : event.getRecipients()) { - recipient.sendMessage(s); - } - } - } - } - } - // CraftBukkit end - - private void handleCommand(String s) { - MinecraftTimings.playerCommandTimer.startTiming(); // Paper - // CraftBukkit start - whole method - if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot - this.LOGGER.info(this.player.getName() + " issued server command: " + s); - - CraftPlayer player = this.getPlayer(); - - PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s, new LazyPlayerSet(minecraftServer)); - this.server.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - MinecraftTimings.playerCommandTimer.stopTiming(); // Paper - return; - } - - try { - if (this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) { - MinecraftTimings.playerCommandTimer.stopTiming(); // Paper - return; - } - } catch (org.bukkit.command.CommandException ex) { - player.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command"); - java.util.logging.Logger.getLogger(PlayerConnection.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - MinecraftTimings.playerCommandTimer.stopTiming(); // Paper - return; - } - MinecraftTimings.playerCommandTimer.stopTiming(); // Paper - // this.minecraftServer.getCommandHandler().a(this.player, s); - // CraftBukkit end - } - - @Override - public void a(PacketPlayInArmAnimation packetplayinarmanimation) { - PlayerConnectionUtils.ensureMainThread(packetplayinarmanimation, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - this.player.resetIdleTimer(); - // CraftBukkit start - Raytrace to look for 'rogue armswings' - float f1 = this.player.pitch; - float f2 = this.player.yaw; - double d0 = this.player.locX; - double d1 = this.player.locY + this.player.getHeadHeight(); - double d2 = this.player.locZ; - Vec3D vec3d = new Vec3D(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 = 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 != MovingObjectPosition.EnumMovingObjectType.BLOCK) { - CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getItemInHand(), EnumHand.MAIN_HAND); - } - - // Arm swing animation - PlayerAnimationEvent event = new PlayerAnimationEvent(this.getPlayer()); - this.server.getPluginManager().callEvent(event); - - if (event.isCancelled()) return; - // CraftBukkit end - this.player.a(packetplayinarmanimation.a()); - } - - @Override - public void a(PacketPlayInEntityAction packetplayinentityaction) { - PlayerConnectionUtils.ensureMainThread(packetplayinentityaction, this, this.player.x()); - // CraftBukkit start - if (this.player.dead) return; - switch (packetplayinentityaction.b()) { - case START_SNEAKING: - case STOP_SNEAKING: - PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getPlayer(), packetplayinentityaction.b() == PacketPlayInEntityAction.EnumPlayerAction.START_SNEAKING); - this.server.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } - break; - case START_SPRINTING: - case STOP_SPRINTING: - PlayerToggleSprintEvent e2 = new PlayerToggleSprintEvent(this.getPlayer(), packetplayinentityaction.b() == PacketPlayInEntityAction.EnumPlayerAction.START_SPRINTING); - this.server.getPluginManager().callEvent(e2); - - if (e2.isCancelled()) { - return; - } - break; - } - // CraftBukkit end - this.player.resetIdleTimer(); - IJumpable ijumpable; - - switch (packetplayinentityaction.b()) { - case START_SNEAKING: - this.player.setSneaking(true); - - // Paper start - Hang on! - if (this.player.world.paperConfig.parrotsHangOnBetter) { - this.player.releaseShoulderEntities(); - } - // Paper end - - break; - - case STOP_SNEAKING: - this.player.setSneaking(false); - break; - - case START_SPRINTING: - this.player.setSprinting(true); - break; - - case STOP_SPRINTING: - this.player.setSprinting(false); - break; - - case STOP_SLEEPING: - if (this.player.isSleeping()) { - this.player.a(false, true, true); - this.teleportPos = new Vec3D(this.player.locX, this.player.locY, this.player.locZ); - } - break; - - case START_RIDING_JUMP: - if (this.player.bJ() instanceof IJumpable) { - ijumpable = (IJumpable) this.player.bJ(); - int i = packetplayinentityaction.c(); - - if (ijumpable.a() && i > 0) { - ijumpable.b_(i); - } - } - break; - - case STOP_RIDING_JUMP: - if (this.player.bJ() instanceof IJumpable) { - ijumpable = (IJumpable) this.player.bJ(); - ijumpable.r_(); - } - break; - - case OPEN_INVENTORY: - if (this.player.bJ() instanceof EntityHorseAbstract) { - ((EntityHorseAbstract) this.player.bJ()).c((EntityHuman) this.player); - } - break; - - case START_FALL_FLYING: - if (!this.player.onGround && this.player.motY < 0.0D && !this.player.cP() && !this.player.isInWater()) { - ItemStack itemstack = this.player.getEquipment(EnumItemSlot.CHEST); - - if (itemstack.getItem() == Items.cS && ItemElytra.d(itemstack)) { - this.player.N(); - } - } else { - this.player.O(); - } - break; - - default: - throw new IllegalArgumentException("Invalid client command!"); - } - - } - - @Override - public void a(PacketPlayInUseEntity packetplayinuseentity) { - PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); - Entity entity = packetplayinuseentity.a(worldserver); - // Spigot Start - if ( entity == player && !player.isSpectator() ) - { - disconnect( "Cannot interact with self!" ); - return; - } - // Spigot End - - this.player.resetIdleTimer(); - if (entity != null) { - boolean flag = this.player.hasLineOfSight(entity); - double d0 = 36.0D; - - if (!flag) { - d0 = 9.0D; - } - - if (this.player.h(entity) < d0) { - EnumHand enumhand; - - ItemStack itemInHand = this.player.b(packetplayinuseentity.b() == null ? EnumHand.MAIN_HAND : packetplayinuseentity.b()); // CraftBukkit - - if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT - || packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT_AT) { - // CraftBukkit start - boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof EntityInsentient; - Item origItem = this.player.inventory.getItemInHand() == null ? null : this.player.inventory.getItemInHand().getItem(); - PlayerInteractEntityEvent event; - if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) { - event = new PlayerInteractEntityEvent(this.getPlayer(), entity.getBukkitEntity(), (packetplayinuseentity.b() == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); - } else { - Vec3D target = packetplayinuseentity.c(); - event = new PlayerInteractAtEntityEvent(this.getPlayer(), entity.getBukkitEntity(), new org.bukkit.util.Vector(target.x, target.y, target.z), (packetplayinuseentity.b() == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); - } - this.server.getPluginManager().callEvent(event); - - if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.LEAD)) { - // Refresh the current leash state - this.sendPacket(new PacketPlayOutAttachEntity(entity, ((EntityInsentient) entity).getLeashHolder())); - } - - if (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != origItem) { - // Refresh the current entity metadata - this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true)); - } - - if (event.isCancelled()) { - return; - } - // CraftBukkit end - } - - if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) { - enumhand = packetplayinuseentity.b(); - this.player.a(entity, enumhand); - // CraftBukkit start - if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - this.player.updateInventory(this.player.activeContainer); - } - // CraftBukkit end - } else if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT_AT) { - enumhand = packetplayinuseentity.b(); - entity.a(this.player, packetplayinuseentity.c(), enumhand); - // CraftBukkit start - if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - this.player.updateInventory(this.player.activeContainer); - } - // CraftBukkit end - } else if (packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.ATTACK) { - if (entity instanceof EntityItem || entity instanceof EntityExperienceOrb || entity instanceof EntityArrow || (entity == this.player && !player.isSpectator())) { // CraftBukkit - this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_entity_attacked", new Object[0])); - this.minecraftServer.warning("Player " + this.player.getName() + " tried to attack an invalid entity"); - return; - } - - this.player.attack(entity); - - // CraftBukkit start - if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - this.player.updateInventory(this.player.activeContainer); - } - // CraftBukkit end - } - } - } - // Paper start - fire event - else { - this.server.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent( - this.getPlayer(), - packetplayinuseentity.getEntityId(), - packetplayinuseentity.a() == PacketPlayInUseEntity.EnumEntityUseAction.ATTACK, - packetplayinuseentity.b() == EnumHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND - )); - } - // Paper end - - } - - @Override - public void a(PacketPlayInClientCommand packetplayinclientcommand) { - PlayerConnectionUtils.ensureMainThread(packetplayinclientcommand, this, this.player.x()); - this.player.resetIdleTimer(); - PacketPlayInClientCommand.EnumClientCommand packetplayinclientcommand_enumclientcommand = packetplayinclientcommand.a(); - - switch (packetplayinclientcommand_enumclientcommand) { - case PERFORM_RESPAWN: - if (this.player.viewingCredits) { - this.player.viewingCredits = false; - // this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, true); - this.minecraftServer.getPlayerList().changeDimension(this.player, 0, PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit - reroute logic through custom portal management - CriterionTriggers.u.a(this.player, DimensionManager.THE_END, DimensionManager.OVERWORLD); - } else { - if (this.player.getHealth() > 0.0F) { - return; - } - - this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, false); - if (this.minecraftServer.isHardcore()) { - this.player.a(EnumGamemode.SPECTATOR); - this.player.x().getGameRules().set("spectatorsGenerateChunks", "false"); - } - } - break; - - case REQUEST_STATS: - this.player.getStatisticManager().a(this.player); - } - - } - - @Override - public void a(PacketPlayInCloseWindow packetplayinclosewindow) { - PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.x()); - - if (this.player.isFrozen()) return; // CraftBukkit - CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit - - this.player.r(); - } - - @Override - public void a(PacketPlayInWindowClick packetplayinwindowclick) { - PlayerConnectionUtils.ensureMainThread(packetplayinwindowclick, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - this.player.resetIdleTimer(); - if (this.player.activeContainer.windowId == packetplayinwindowclick.a() && this.player.activeContainer.c(this.player) && this.player.activeContainer.canUse(this.player)) { // CraftBukkit - boolean cancelled = this.player.isSpectator(); // CraftBukkit - see below if - if (false/*this.player.isSpectator()*/) { // CraftBukkit - NonNullList nonnulllist = NonNullList.a(); - - for (int i = 0; i < this.player.activeContainer.slots.size(); ++i) { - nonnulllist.add(this.player.activeContainer.slots.get(i).getItem()); - } - - this.player.a(this.player.activeContainer, nonnulllist); - } else { - // CraftBukkit start - Call InventoryClickEvent - if (packetplayinwindowclick.b() < -1 && packetplayinwindowclick.b() != -999) { - return; - } - - InventoryView inventory = this.player.activeContainer.getBukkitView(); - SlotType type = CraftInventoryView.getSlotType(inventory, packetplayinwindowclick.b()); - - InventoryClickEvent event; - ClickType click = ClickType.UNKNOWN; - InventoryAction action = InventoryAction.UNKNOWN; - - ItemStack itemstack = ItemStack.a; - - switch (packetplayinwindowclick.f()) { - case PICKUP: - if (packetplayinwindowclick.c() == 0) { - click = ClickType.LEFT; - } else if (packetplayinwindowclick.c() == 1) { - click = ClickType.RIGHT; - } - if (packetplayinwindowclick.c() == 0 || packetplayinwindowclick.c() == 1) { - action = InventoryAction.NOTHING; // Don't want to repeat ourselves - if (packetplayinwindowclick.b() == -999) { - if (!player.inventory.getCarried().isEmpty()) { - action = packetplayinwindowclick.c() == 0 ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR; - } - } else if (packetplayinwindowclick.b() < 0) { - action = InventoryAction.NOTHING; - } else { - Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.b()); - if (slot != null) { - ItemStack clickedItem = slot.getItem(); - ItemStack cursor = player.inventory.getCarried(); - if (clickedItem.isEmpty()) { - if (!cursor.isEmpty()) { - action = packetplayinwindowclick.c() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE; - } - } else if (slot.isAllowed(player)) { - if (cursor.isEmpty()) { - action = packetplayinwindowclick.c() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF; - } else if (slot.isAllowed(cursor)) { - if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) { - int toPlace = packetplayinwindowclick.c() == 0 ? cursor.getCount() : 1; - toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount()); - toPlace = Math.min(toPlace, slot.inventory.getMaxStackSize() - clickedItem.getCount()); - if (toPlace == 1) { - action = InventoryAction.PLACE_ONE; - } else if (toPlace == cursor.getCount()) { - action = InventoryAction.PLACE_ALL; - } else if (toPlace < 0) { - action = toPlace != -1 ? InventoryAction.PICKUP_SOME : InventoryAction.PICKUP_ONE; // this happens with oversized stacks - } else if (toPlace != 0) { - action = InventoryAction.PLACE_SOME; - } - } else if (cursor.getCount() <= slot.getMaxStackSize()) { - action = InventoryAction.SWAP_WITH_CURSOR; - } - } else if (cursor.getItem() == clickedItem.getItem() && (!cursor.usesData() || cursor.getData() == clickedItem.getData()) && ItemStack.equals(cursor, clickedItem)) { - if (clickedItem.getCount() >= 0) { - if (clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) { - // As of 1.5, this is result slots only - action = InventoryAction.PICKUP_ALL; - } - } - } - } - } - } - } - break; - // TODO check on updates - case QUICK_MOVE: - if (packetplayinwindowclick.c() == 0) { - click = ClickType.SHIFT_LEFT; - } else if (packetplayinwindowclick.c() == 1) { - click = ClickType.SHIFT_RIGHT; - } - if (packetplayinwindowclick.c() == 0 || packetplayinwindowclick.c() == 1) { - if (packetplayinwindowclick.b() < 0) { - action = InventoryAction.NOTHING; - } else { - Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.b()); - if (slot != null && slot.isAllowed(this.player) && slot.hasItem()) { - action = InventoryAction.MOVE_TO_OTHER_INVENTORY; - } else { - action = InventoryAction.NOTHING; - } - } - } - break; - case SWAP: - if (packetplayinwindowclick.c() >= 0 && packetplayinwindowclick.c() < 9) { - click = ClickType.NUMBER_KEY; - Slot clickedSlot = this.player.activeContainer.getSlot(packetplayinwindowclick.b()); - if (clickedSlot.isAllowed(player)) { - ItemStack hotbar = this.player.inventory.getItem(packetplayinwindowclick.c()); - boolean canCleanSwap = hotbar.isEmpty() || (clickedSlot.inventory == player.inventory && clickedSlot.isAllowed(hotbar)); // the slot will accept the hotbar item - if (clickedSlot.hasItem()) { - if (canCleanSwap) { - action = InventoryAction.HOTBAR_SWAP; - } else { - action = InventoryAction.HOTBAR_MOVE_AND_READD; - } - } else if (!clickedSlot.hasItem() && !hotbar.isEmpty() && clickedSlot.isAllowed(hotbar)) { - action = InventoryAction.HOTBAR_SWAP; - } else { - action = InventoryAction.NOTHING; - } - } else { - action = InventoryAction.NOTHING; - } - } - break; - case CLONE: - if (packetplayinwindowclick.c() == 2) { - click = ClickType.MIDDLE; - if (packetplayinwindowclick.b() < 0) { // Paper - GH-404 - action = InventoryAction.NOTHING; - } else { - Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.b()); - if (slot != null && slot.hasItem() && player.abilities.canInstantlyBuild && player.inventory.getCarried().isEmpty()) { - action = InventoryAction.CLONE_STACK; - } else { - action = InventoryAction.NOTHING; - } - } - } else { - click = ClickType.UNKNOWN; - action = InventoryAction.UNKNOWN; - } - break; - case THROW: - if (packetplayinwindowclick.b() >= 0) { - if (packetplayinwindowclick.c() == 0) { - click = ClickType.DROP; - Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.b()); - if (slot != null && slot.hasItem() && slot.isAllowed(player) && !slot.getItem().isEmpty() && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) { - action = InventoryAction.DROP_ONE_SLOT; - } else { - action = InventoryAction.NOTHING; - } - } else if (packetplayinwindowclick.c() == 1) { - click = ClickType.CONTROL_DROP; - Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.b()); - if (slot != null && slot.hasItem() && slot.isAllowed(player) && !slot.getItem().isEmpty() && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) { - action = InventoryAction.DROP_ALL_SLOT; - } else { - action = InventoryAction.NOTHING; - } - } - } else { - // Sane default (because this happens when they are holding nothing. Don't ask why.) - click = ClickType.LEFT; - if (packetplayinwindowclick.c() == 1) { - click = ClickType.RIGHT; - } - action = InventoryAction.NOTHING; - } - break; - case QUICK_CRAFT: - itemstack = this.player.activeContainer.a(packetplayinwindowclick.b(), packetplayinwindowclick.c(), packetplayinwindowclick.f(), this.player); - break; - case PICKUP_ALL: - click = ClickType.DOUBLE_CLICK; - action = InventoryAction.NOTHING; - if (packetplayinwindowclick.b() >= 0 && !this.player.inventory.getCarried().isEmpty()) { - ItemStack cursor = this.player.inventory.getCarried(); - action = InventoryAction.NOTHING; - // Quick check for if we have any of the item - if (inventory.getTopInventory().contains(org.bukkit.Material.getMaterial(Item.getId(cursor.getItem()))) || inventory.getBottomInventory().contains(org.bukkit.Material.getMaterial(Item.getId(cursor.getItem())))) { - action = InventoryAction.COLLECT_TO_CURSOR; - } - } - break; - default: - break; - } - - if (packetplayinwindowclick.f() != InventoryClickType.QUICK_CRAFT) { - if (click == ClickType.NUMBER_KEY) { - event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.b(), click, action, packetplayinwindowclick.c()); - } else { - event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.b(), click, action); - } - - org.bukkit.inventory.Inventory top = inventory.getTopInventory(); - if (packetplayinwindowclick.b() == 0 && top instanceof CraftingInventory) { - org.bukkit.inventory.Recipe recipe = ((CraftingInventory) top).getRecipe(); - if (recipe != null) { - if (click == ClickType.NUMBER_KEY) { - event = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.b(), click, action, packetplayinwindowclick.c()); - } else { - event = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.b(), click, action); - } - } - } - - event.setCancelled(cancelled); - Container oldContainer = this.player.activeContainer; // SPIGOT-1224 - server.getPluginManager().callEvent(event); - if (this.player.activeContainer != oldContainer) { - return; - } - - switch (event.getResult()) { - case ALLOW: - case DEFAULT: - itemstack = this.player.activeContainer.a(packetplayinwindowclick.b(), packetplayinwindowclick.c(), packetplayinwindowclick.f(), this.player); - break; - case DENY: - /* Needs enum constructor in InventoryAction - if (action.modifiesOtherSlots()) { - - } else { - if (action.modifiesCursor()) { - this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried())); - } - if (action.modifiesClicked()) { - this.player.playerConnection.sendPacket(new Packet103SetSlot(this.player.activeContainer.windowId, packet102windowclick.slot, this.player.activeContainer.getSlot(packet102windowclick.slot).getItem())); - } - }*/ - switch (action) { - // Modified other slots - case PICKUP_ALL: - case MOVE_TO_OTHER_INVENTORY: - case HOTBAR_MOVE_AND_READD: - case HOTBAR_SWAP: - case COLLECT_TO_CURSOR: - case UNKNOWN: - this.player.updateInventory(this.player.activeContainer); - break; - // Modified cursor and clicked - case PICKUP_SOME: - case PICKUP_HALF: - case PICKUP_ONE: - case PLACE_ALL: - case PLACE_SOME: - case PLACE_ONE: - case SWAP_WITH_CURSOR: - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.player.inventory.getCarried())); - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, packetplayinwindowclick.b(), this.player.activeContainer.getSlot(packetplayinwindowclick.b()).getItem())); - break; - // Modified clicked only - case DROP_ALL_SLOT: - case DROP_ONE_SLOT: - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, packetplayinwindowclick.b(), this.player.activeContainer.getSlot(packetplayinwindowclick.b()).getItem())); - break; - // Modified cursor only - case DROP_ALL_CURSOR: - case DROP_ONE_CURSOR: - case CLONE_STACK: - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.player.inventory.getCarried())); - break; - // Nothing - case NOTHING: - break; - } - return; - } - - if (event instanceof CraftItemEvent) { - // Need to update the inventory on crafting to - // correctly support custom recipes - player.updateInventory(player.activeContainer); - } - } - // CraftBukkit end - if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) { - this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true)); - this.player.f = true; - this.player.activeContainer.b(); - this.player.broadcastCarriedItem(); - this.player.f = false; - } else { - this.k.a(this.player.activeContainer.windowId, Short.valueOf(packetplayinwindowclick.d())); - this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), false)); - this.player.activeContainer.a(this.player, false); - NonNullList nonnulllist1 = NonNullList.a(); - - for (int j = 0; j < this.player.activeContainer.slots.size(); ++j) { - ItemStack itemstack1 = this.player.activeContainer.slots.get(j).getItem(); - ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.a : itemstack1; - - nonnulllist1.add(itemstack2); - } - - this.player.a(this.player.activeContainer, nonnulllist1); - } - } - } - - } - - @Override - public void a(PacketPlayInAutoRecipe packetplayinautorecipe) { - PlayerConnectionUtils.ensureMainThread(packetplayinautorecipe, this, this.player.x()); - this.player.resetIdleTimer(); - if (!this.player.isSpectator() && this.player.activeContainer.windowId == packetplayinautorecipe.a() && this.player.activeContainer.c(this.player)) { - this.H.a(this.player, packetplayinautorecipe.b(), packetplayinautorecipe.c()); - } - } - - @Override - public void a(PacketPlayInEnchantItem packetplayinenchantitem) { - PlayerConnectionUtils.ensureMainThread(packetplayinenchantitem, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - this.player.resetIdleTimer(); - if (this.player.activeContainer.windowId == packetplayinenchantitem.a() && this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { - this.player.activeContainer.a(this.player, packetplayinenchantitem.b()); - this.player.activeContainer.b(); - } - - } - - @Override - public void a(PacketPlayInSetCreativeSlot packetplayinsetcreativeslot) { - PlayerConnectionUtils.ensureMainThread(packetplayinsetcreativeslot, this, this.player.x()); - if (this.player.playerInteractManager.isCreative()) { - boolean flag = packetplayinsetcreativeslot.a() < 0; - ItemStack itemstack = packetplayinsetcreativeslot.getItemStack(); - - if (!itemstack.isEmpty() && itemstack.hasTag() && itemstack.getTag().hasKeyOfType("BlockEntityTag", 10)) { - NBTTagCompound nbttagcompound = itemstack.getTag().getCompound("BlockEntityTag"); - - if (nbttagcompound.hasKey("x") && nbttagcompound.hasKey("y") && nbttagcompound.hasKey("z")) { - BlockPosition blockposition = new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z")); - TileEntity tileentity = this.player.world.getTileEntity(blockposition); - - if (tileentity != null) { - NBTTagCompound nbttagcompound1 = tileentity.save(new NBTTagCompound()); - - nbttagcompound1.remove("x"); - nbttagcompound1.remove("y"); - nbttagcompound1.remove("z"); - itemstack.a("BlockEntityTag", nbttagcompound1); - } - } - } - - boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() <= 45; - // CraftBukkit - Add invalidItems check - boolean flag2 = itemstack.isEmpty() || itemstack.getData() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty() && (!invalidItems.contains(Item.getId(itemstack.getItem())) || !org.spigotmc.SpigotConfig.filterCreativeItems); // Spigot - if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.a()).getItem(), packetplayinsetcreativeslot.getItemStack()))) { // Insist on valid slot - // CraftBukkit start - Call click event - InventoryView inventory = this.player.defaultContainer.getBukkitView(); - org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getItemStack()); - - SlotType type = SlotType.QUICKBAR; - if (flag) { - type = SlotType.OUTSIDE; - } else if (packetplayinsetcreativeslot.a() < 36) { - if (packetplayinsetcreativeslot.a() >= 5 && packetplayinsetcreativeslot.a() < 9) { - type = SlotType.ARMOR; - } else { - type = SlotType.CONTAINER; - } - } - InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.a(), item); - server.getPluginManager().callEvent(event); - - itemstack = CraftItemStack.asNMSCopy(event.getCursor()); - - switch (event.getResult()) { - case ALLOW: - // Plugin cleared the id / stacksize checks - flag2 = true; - break; - case DEFAULT: - break; - case DENY: - // Reset the slot - if (packetplayinsetcreativeslot.a() >= 0) { - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.defaultContainer.windowId, packetplayinsetcreativeslot.a(), this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.a()).getItem())); - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, ItemStack.a)); - } - return; - } - } - // CraftBukkit end - - if (flag1 && flag2) { - if (itemstack.isEmpty()) { - this.player.defaultContainer.setItem(packetplayinsetcreativeslot.a(), ItemStack.a); - } else { - this.player.defaultContainer.setItem(packetplayinsetcreativeslot.a(), itemstack); - } - - this.player.defaultContainer.a(this.player, true); - } else if (flag && flag2 && this.j < 200) { - this.j += 20; - EntityItem entityitem = this.player.drop(itemstack, true); - - if (entityitem != null) { - entityitem.j(); - } - } - } - - } - - @Override - public void a(PacketPlayInTransaction packetplayintransaction) { - PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - Short oshort = this.k.get(this.player.activeContainer.windowId); - - if (oshort != null && packetplayintransaction.b() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.a() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) { - this.player.activeContainer.a(this.player, true); - } - - } - - @Override - public void a(PacketPlayInUpdateSign packetplayinupdatesign) { - PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.x()); - if (this.player.isFrozen()) return; // CraftBukkit - this.player.resetIdleTimer(); - WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension); - BlockPosition blockposition = packetplayinupdatesign.a(); - - if (worldserver.isLoaded(blockposition)) { - IBlockData iblockdata = worldserver.getType(blockposition); - TileEntity tileentity = worldserver.getTileEntity(blockposition); - - if (!(tileentity instanceof TileEntitySign)) { - return; - } - - TileEntitySign tileentitysign = (TileEntitySign) tileentity; - - if (!tileentitysign.a() || tileentitysign.e() != this.player) { - this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign"); - this.sendPacket(tileentity.getUpdatePacket()); // CraftBukkit - return; - } - - String[] astring = packetplayinupdatesign.b(); - - // CraftBukkit start - Player player = this.server.getPlayer(this.player); - int x = packetplayinupdatesign.a().getX(); - int y = packetplayinupdatesign.a().getY(); - int z = packetplayinupdatesign.a().getZ(); - String[] lines = new String[4]; - - for (int i = 0; i < astring.length; ++i) { - lines[i] = SharedConstants.a(astring[i]); //Paper - Replaced with anvil color stripping method to stop exploits that allow colored signs to be created. - } - SignChangeEvent event = new SignChangeEvent(player.getWorld().getBlockAt(x, y, z), this.server.getPlayer(this.player), lines); - this.server.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - System.arraycopy(org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines()), 0, tileentitysign.lines, 0, 4); - tileentitysign.isEditable = false; - } - // CraftBukkit end - - tileentitysign.update(); - worldserver.notify(blockposition, iblockdata, iblockdata, 3); - } - - } - - @Override - public void a(PacketPlayInKeepAlive packetplayinkeepalive) { - //PlayerConnectionUtils.ensureMainThread(packetplayinkeepalive, this, this.player.x()); // CraftBukkit // Paper - This shouldn't be on the main thread - if (this.g && packetplayinkeepalive.a() == this.h) { - int i = (int) (this.d() - this.f); - - this.player.ping = (this.player.ping * 3 + i) / 4; - this.g = false; - } else if (!this.player.getName().equals(this.minecraftServer.Q())) { - // Paper start - This needs to be handled on the main thread for plugins - PlayerConnection.LOGGER.warn("{} sent an invalid keepalive! pending keepalive: {} got id: {} expected id: {}", - this.player.getName(), this.isPendingPing(), packetplayinkeepalive.a(), this.getKeepAliveID()); - minecraftServer.postToMainThread(() -> { - this.disconnect(new ChatMessage("disconnect.timeout", new Object[0])); - }); - // Paper end - } - - } - - private long getCurrentMillis() { return d(); } // Paper - OBFHELPER - private long d() { - return System.currentTimeMillis(); // Akarin - } - - @Override - public void a(PacketPlayInAbilities packetplayinabilities) { - PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.x()); - // CraftBukkit start - 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(); // Actually set the player's flying status - } else { - this.player.updateAbilities(); // Tell the player their ability was reverted - } - } - // CraftBukkit end - } - - // Paper start - async tab completion - @Override - public void a(PacketPlayInTabComplete packet) { - // CraftBukkit start - if (chatSpamField.addAndGet(this, 10) > 500 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) { - minecraftServer.postToMainThread(() -> this.disconnect(new ChatMessage("disconnect.spam", new Object[0]))); - return; - } - // CraftBukkit end - - com.destroystokyo.paper.event.server.AsyncTabCompleteEvent event; - java.util.List completions = new ArrayList<>(); - BlockPosition blockpos = packet.b(); - String buffer = packet.a(); - boolean isCommand = buffer.startsWith("/") || packet.c(); - event = new com.destroystokyo.paper.event.server.AsyncTabCompleteEvent(this.getPlayer(), completions, - buffer, isCommand, blockpos != null ? MCUtil.toLocation(player.world, blockpos) : null); - event.callEvent(); - completions = event.isCancelled() ? com.google.common.collect.ImmutableList.of() : event.getCompletions(); - if (event.isCancelled() || event.isHandled()) { - // Still fire sync event with the provided completions, if someone is listening - if (!event.isCancelled() && org.bukkit.event.server.TabCompleteEvent.getHandlerList().getRegisteredListeners().length > 0) { - java.util.List finalCompletions = completions; - Waitable> syncCompletions = new Waitable>() { - @Override - protected java.util.List evaluate() { - org.bukkit.event.server.TabCompleteEvent syncEvent = new org.bukkit.event.server.TabCompleteEvent(PlayerConnection.this.getPlayer(), buffer, finalCompletions, isCommand, blockpos != null ? MCUtil.toLocation(player.world, blockpos) : null); - return syncEvent.callEvent() ? syncEvent.getCompletions() : com.google.common.collect.ImmutableList.of(); - } - }; - server.getServer().processQueue.add(syncCompletions); - try { - completions = syncCompletions.get(); - } catch (InterruptedException | ExecutionException e1) { - e1.printStackTrace(); - } - } - - this.player.playerConnection.sendPacket(new PacketPlayOutTabComplete(completions.toArray(new String[completions.size()]))); - return; - } - minecraftServer.postToMainThread(() -> { - java.util.List syncCompletions = this.minecraftServer.tabCompleteCommand(this.player, buffer, blockpos, isCommand); - this.player.playerConnection.sendPacket(new PacketPlayOutTabComplete(syncCompletions.toArray(new String[syncCompletions.size()]))); - }); - // Paper end - } - - @Override - public void a(PacketPlayInSettings packetplayinsettings) { - PlayerConnectionUtils.ensureMainThread(packetplayinsettings, this, this.player.x()); - this.player.a(packetplayinsettings); - } - - @Override - public void a(PacketPlayInCustomPayload packetplayincustompayload) { - PlayerConnectionUtils.ensureMainThread(packetplayincustompayload, this, this.player.x()); - String s = packetplayincustompayload.a(); - PacketDataSerializer packetdataserializer; - ItemStack itemstack; - ItemStack itemstack1; - - if ("MC|BEdit".equals(s)) { - // CraftBukkit start - if (this.lastBookTick + 20 > MinecraftServer.currentTick) { - this.disconnect("Book edited too quickly!"); - return; - } - this.lastBookTick = MinecraftServer.currentTick; - // CraftBukkit end - packetdataserializer = packetplayincustompayload.b(); - - try { - itemstack = packetdataserializer.k(); - if (itemstack.isEmpty()) { - return; - } - - if (!ItemBookAndQuill.b(itemstack.getTag())) { - throw new IOException("Invalid book tag!"); - } - - itemstack1 = this.player.getItemInMainHand(); - if (itemstack1.isEmpty()) { - return; - } - - if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) { - itemstack1 = new ItemStack(Items.WRITABLE_BOOK); // CraftBukkit - itemstack1.a("pages", itemstack.getTag().getList("pages", 8)); - CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit - } - } catch (Exception exception) { - IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidBookEdit", "Invalid book data!", exception); // Paper - } - } else { - String s1; - - if ("MC|BSign".equals(s)) { - // CraftBukkit start - if (this.lastBookTick + 20 > MinecraftServer.currentTick) { - this.disconnect("Book edited too quickly!"); - return; - } - this.lastBookTick = MinecraftServer.currentTick; - // CraftBukkit end - packetdataserializer = packetplayincustompayload.b(); - - try { - itemstack = packetdataserializer.k(); - if (itemstack.isEmpty()) { - return; - } - - if (!ItemWrittenBook.b(itemstack.getTag())) { - throw new IOException("Invalid book tag!"); - } - - itemstack1 = this.player.getItemInMainHand(); - if (itemstack1.isEmpty()) { - return; - } - - if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack1.getItem() == Items.WRITABLE_BOOK) { - ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK); - - itemstack2.a("author", (new NBTTagString(this.player.getName()))); - itemstack2.a("title", (new NBTTagString(itemstack.getTag().getString("title")))); - NBTTagList nbttaglist = itemstack.getTag().getList("pages", 8); - - for (int i = 0; i < nbttaglist.size(); ++i) { - s1 = nbttaglist.getString(i); - ChatComponentText chatcomponenttext = new ChatComponentText(s1); - - s1 = IChatBaseComponent.ChatSerializer.a(chatcomponenttext); - nbttaglist.a(i, new NBTTagString(s1)); - } - - itemstack2.a("pages", nbttaglist); - CraftEventFactory.handleEditBookEvent(player, itemstack2); // CraftBukkit - } - } catch (Exception exception1) { - IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidBookSign", "Invalid book data!", exception1); // Paper - } - } else if ("MC|TrSel".equals(s)) { - try { - int j = packetplayincustompayload.b().readInt(); - Container container = this.player.activeContainer; - - if (container instanceof ContainerMerchant) { - ((ContainerMerchant) container).d(j); - } - } catch (Exception exception2) { - IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidTrade", "Invalid trade data!", exception2); // Paper - } - } else { - TileEntity tileentity; - - if ("MC|AdvCmd".equals(s)) { - if (!this.minecraftServer.getEnableCommandBlock()) { - this.player.sendMessage(new ChatMessage("advMode.notEnabled", new Object[0])); - return; - } - - if (!this.player.isCreativeAndOp()) { - this.player.sendMessage(new ChatMessage("advMode.notAllowed", new Object[0])); - return; - } - - packetdataserializer = packetplayincustompayload.b(); - - try { - byte b0 = packetdataserializer.readByte(); - CommandBlockListenerAbstract commandblocklistenerabstract = null; - - if (b0 == 0) { - tileentity = this.player.world.getTileEntity(new BlockPosition(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 s2 = packetdataserializer.e(packetdataserializer.readableBytes()); - boolean flag = packetdataserializer.readBoolean(); - - if (commandblocklistenerabstract != null) { - commandblocklistenerabstract.setCommand(s2); - commandblocklistenerabstract.a(flag); - if (!flag) { - commandblocklistenerabstract.b((IChatBaseComponent) null); - } - - commandblocklistenerabstract.i(); - this.player.sendMessage(new ChatMessage("advMode.setCommand.success", new Object[] { s2})); - } - } catch (Exception exception3) { - PlayerConnection.LOGGER.error("Couldn\'t set command block", exception3); - this.disconnect("Invalid command data!"); // CraftBukkit - } - } else if ("MC|AutoCmd".equals(s)) { - if (!this.minecraftServer.getEnableCommandBlock()) { - this.player.sendMessage(new ChatMessage("advMode.notEnabled", new Object[0])); - return; - } - - if (!this.player.isCreativeAndOp()) { - this.player.sendMessage(new ChatMessage("advMode.notAllowed", new Object[0])); - return; - } - - packetdataserializer = packetplayincustompayload.b(); - - try { - CommandBlockListenerAbstract commandblocklistenerabstract1 = null; - TileEntityCommand tileentitycommand = null; - BlockPosition blockposition = new BlockPosition(packetdataserializer.readInt(), packetdataserializer.readInt(), packetdataserializer.readInt()); - TileEntity tileentity1 = this.player.world.getTileEntity(blockposition); - - if (tileentity1 instanceof TileEntityCommand) { - tileentitycommand = (TileEntityCommand) tileentity1; - commandblocklistenerabstract1 = tileentitycommand.getCommandBlock(); - } - - String s3 = packetdataserializer.e(packetdataserializer.readableBytes()); - boolean flag1 = packetdataserializer.readBoolean(); - TileEntityCommand.Type tileentitycommand_type = TileEntityCommand.Type.valueOf(packetdataserializer.e(16)); - boolean flag2 = packetdataserializer.readBoolean(); - boolean flag3 = packetdataserializer.readBoolean(); - - if (commandblocklistenerabstract1 != null) { - EnumDirection enumdirection = this.player.world.getType(blockposition).get(BlockCommand.a); - IBlockData iblockdata; - - switch (tileentitycommand_type) { - case SEQUENCE: - iblockdata = Blocks.dd.getBlockData(); - this.player.world.setTypeAndData(blockposition, iblockdata.set(BlockCommand.a, enumdirection).set(BlockCommand.b, Boolean.valueOf(flag2)), 2); - break; - - case AUTO: - iblockdata = Blocks.dc.getBlockData(); - this.player.world.setTypeAndData(blockposition, iblockdata.set(BlockCommand.a, enumdirection).set(BlockCommand.b, Boolean.valueOf(flag2)), 2); - break; - - case REDSTONE: - iblockdata = Blocks.COMMAND_BLOCK.getBlockData(); - this.player.world.setTypeAndData(blockposition, iblockdata.set(BlockCommand.a, enumdirection).set(BlockCommand.b, Boolean.valueOf(flag2)), 2); - } - - tileentity1.A(); - this.player.world.setTileEntity(blockposition, tileentity1); - commandblocklistenerabstract1.setCommand(s3); - commandblocklistenerabstract1.a(flag1); - if (!flag1) { - commandblocklistenerabstract1.b((IChatBaseComponent) null); - } - - tileentitycommand.b(flag3); - commandblocklistenerabstract1.i(); - if (!UtilColor.b(s3)) { - this.player.sendMessage(new ChatMessage("advMode.setCommand.success", new Object[] { s3})); - } - } - } catch (Exception exception4) { - PlayerConnection.LOGGER.error("Couldn\'t set command block", exception4); - this.disconnect("Invalid command data!"); // CraftBukkit - } - } else { - int k; - - if ("MC|Beacon".equals(s)) { - if (this.player.activeContainer instanceof ContainerBeacon) { - try { - packetdataserializer = packetplayincustompayload.b(); - k = packetdataserializer.readInt(); - int l = packetdataserializer.readInt(); - ContainerBeacon containerbeacon = (ContainerBeacon) this.player.activeContainer; - Slot slot = containerbeacon.getSlot(0); - - if (slot.hasItem()) { - slot.a(1); - IInventory iinventory = containerbeacon.e(); - - iinventory.setProperty(1, k); - iinventory.setProperty(2, l); - iinventory.update(); - } - } catch (Exception exception5) { - IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidBeacon", "Invalid beacon data!", exception5); // Paper - } - } - } else if ("MC|ItemName".equals(s)) { - if (this.player.activeContainer instanceof ContainerAnvil) { - ContainerAnvil containeranvil = (ContainerAnvil) this.player.activeContainer; - - if (packetplayincustompayload.b() != null && packetplayincustompayload.b().readableBytes() >= 1) { - String s4 = SharedConstants.a(packetplayincustompayload.b().e(32767)); - - if (s4.length() <= 35) { - containeranvil.a(s4); - } - } else { - containeranvil.a(""); - } - } - } else if ("MC|Struct".equals(s)) { - if (!this.player.isCreativeAndOp()) { - return; - } - - packetdataserializer = packetplayincustompayload.b(); - - try { - BlockPosition blockposition1 = new BlockPosition(packetdataserializer.readInt(), packetdataserializer.readInt(), packetdataserializer.readInt()); - IBlockData iblockdata1 = this.player.world.getType(blockposition1); - - tileentity = this.player.world.getTileEntity(blockposition1); - if (tileentity instanceof TileEntityStructure) { - TileEntityStructure tileentitystructure = (TileEntityStructure) tileentity; - byte b1 = packetdataserializer.readByte(); - - s1 = packetdataserializer.e(32); - tileentitystructure.a(TileEntityStructure.UsageMode.valueOf(s1)); - tileentitystructure.a(packetdataserializer.e(64)); - int i1 = MathHelper.clamp(packetdataserializer.readInt(), -32, 32); - int j1 = MathHelper.clamp(packetdataserializer.readInt(), -32, 32); - int k1 = MathHelper.clamp(packetdataserializer.readInt(), -32, 32); - - tileentitystructure.b(new BlockPosition(i1, j1, k1)); - int l1 = MathHelper.clamp(packetdataserializer.readInt(), 0, 32); - int i2 = MathHelper.clamp(packetdataserializer.readInt(), 0, 32); - int j2 = MathHelper.clamp(packetdataserializer.readInt(), 0, 32); - - tileentitystructure.c(new BlockPosition(l1, i2, j2)); - String s5 = packetdataserializer.e(32); - - tileentitystructure.b(EnumBlockMirror.valueOf(s5)); - String s6 = packetdataserializer.e(32); - - tileentitystructure.b(EnumBlockRotation.valueOf(s6)); - tileentitystructure.b(packetdataserializer.e(128)); - tileentitystructure.a(packetdataserializer.readBoolean()); - tileentitystructure.e(packetdataserializer.readBoolean()); - tileentitystructure.f(packetdataserializer.readBoolean()); - tileentitystructure.a(MathHelper.a(packetdataserializer.readFloat(), 0.0F, 1.0F)); - tileentitystructure.a(packetdataserializer.h()); - String s7 = tileentitystructure.a(); - - if (b1 == 2) { - if (tileentitystructure.q()) { - this.player.a((new ChatMessage("structure_block.save_success", new Object[] { s7})), false); - } else { - this.player.a((new ChatMessage("structure_block.save_failure", new Object[] { s7})), false); - } - } else if (b1 == 3) { - if (!tileentitystructure.E()) { - this.player.a((new ChatMessage("structure_block.load_not_found", new Object[] { s7})), false); - } else if (tileentitystructure.r()) { - this.player.a((new ChatMessage("structure_block.load_success", new Object[] { s7})), false); - } else { - this.player.a((new ChatMessage("structure_block.load_prepare", new Object[] { s7})), false); - } - } else if (b1 == 4) { - if (tileentitystructure.p()) { - this.player.a((new ChatMessage("structure_block.size_success", new Object[] { s7})), false); - } else { - this.player.a((new ChatMessage("structure_block.size_failure", new Object[0])), false); - } - } - - tileentitystructure.update(); - this.player.world.notify(blockposition1, iblockdata1, iblockdata1, 3); - } - } catch (Exception exception6) { - PlayerConnection.LOGGER.error("Couldn\'t set structure block", exception6); - this.disconnect("Invalid structure data!"); // CraftBukkit - } - } else if ("MC|PickItem".equals(s)) { - packetdataserializer = packetplayincustompayload.b(); - - try { - k = packetdataserializer.g(); - this.player.inventory.d(k); - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, this.player.inventory.itemInHandIndex, this.player.inventory.getItem(this.player.inventory.itemInHandIndex))); - this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, k, this.player.inventory.getItem(k))); - this.player.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex)); - } catch (Exception exception7) { - IllegalPacketEvent.process(player.getBukkitEntity(), "InvalidPickItem", "Invalid PickItem", exception7); // Paper - } - } - // CraftBukkit start - else if (packetplayincustompayload.a().equals("REGISTER")) { - try { - String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8); - for (String channel : channels.split("\0")) { - getPlayer().addChannel(channel); - } - } catch (Exception ex) { - PlayerConnection.LOGGER.error("Couldn\'t register custom payload", ex); - this.disconnect("Invalid payload REGISTER!"); - } - } else if (packetplayincustompayload.a().equals("UNREGISTER")) { - try { - String channels = packetplayincustompayload.b().toString(com.google.common.base.Charsets.UTF_8); - for (String channel : channels.split("\0")) { - getPlayer().removeChannel(channel); - } - } catch (Exception ex) { - PlayerConnection.LOGGER.error("Couldn\'t unregister custom payload", ex); - this.disconnect("Invalid payload UNREGISTER!"); - } - } else { - try { - byte[] data = new byte[packetplayincustompayload.b().readableBytes()]; - packetplayincustompayload.b().readBytes(data); - server.getMessenger().dispatchIncomingMessage(player.getBukkitEntity(), packetplayincustompayload.a(), data); - } catch (Exception ex) { - PlayerConnection.LOGGER.error("Couldn\'t dispatch custom payload", ex); - this.disconnect("Invalid custom payload!"); - } - } - // CraftBukkit end - } - } - } - - } - - // CraftBukkit start - Add "isDisconnected" method - public final boolean isDisconnected() { - return (!this.player.joining && !this.networkManager.isConnected()) || this.processedDisconnect; // Paper - } -}