summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/PlayerConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/minecraft/server/PlayerConnection.java')
-rw-r--r--src/main/java/net/minecraft/server/PlayerConnection.java1107
1 files changed, 535 insertions, 572 deletions
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index e4cb5c76..2419ac29 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1,7 +1,6 @@
package net.minecraft.server;
import java.io.ByteArrayInputStream;
-import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -9,7 +8,13 @@ import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.Callable;
-import org.apache.commons.lang3.StringUtils;
+import net.minecraft.util.com.google.common.base.Charsets;
+import net.minecraft.util.com.google.common.collect.Lists;
+import net.minecraft.util.io.netty.buffer.Unpooled;
+import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
+import net.minecraft.util.org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
// CraftBukkit start
import java.io.UnsupportedEncodingException;
@@ -17,12 +22,13 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.HashSet;
+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.craftbukkit.entity.CraftPlayer;
-import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -51,11 +57,11 @@ import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.InventoryView;
// CraftBukkit end
-public class PlayerConnection extends Connection {
+public class PlayerConnection implements PacketPlayInListener {
- public final INetworkManager networkManager;
+ private static final Logger c = LogManager.getLogger();
+ public final NetworkManager networkManager;
private final MinecraftServer minecraftServer;
- public boolean disconnected;
public EntityPlayer player;
private int e;
private int f;
@@ -65,17 +71,17 @@ public class PlayerConnection extends Connection {
private static Random j = new Random();
private long k;
private volatile int chatThrottle; private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle"); // CraftBukkit - multithreaded field
- private int x = 0;
+ private int x;
+ private IntHashMap n = new IntHashMap();
private double y;
private double z;
- private double p;
+ private double q;
public boolean checkMovement = true; // CraftBukkit - private -> public
- private IntHashMap r = new IntHashMap();
- public PlayerConnection(MinecraftServer minecraftserver, INetworkManager inetworkmanager, EntityPlayer entityplayer) {
+ public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
this.minecraftServer = minecraftserver;
- this.networkManager = inetworkmanager;
- inetworkmanager.a(this);
+ this.networkManager = networkmanager;
+ networkmanager.a((PacketListener) this);
this.player = entityplayer;
entityplayer.playerConnection = this;
@@ -97,36 +103,34 @@ public class PlayerConnection extends Connection {
private float lastYaw = Float.MAX_VALUE;
private boolean justTeleported = false;
- // For the packet15 hack :(
+ // For the PacketPlayOutBlockPlace hack :(
Long lastPacket;
// Store the last block right clicked and what type it was
- private int lastMaterial;
+ private Item lastMaterial;
public CraftPlayer getPlayer() {
return (this.player == null) ? null : (CraftPlayer) this.player.getBukkitEntity();
}
- private final static HashSet<Integer> invalidItems = new HashSet<Integer>(java.util.Arrays.asList(8, 9, 10, 11, 26, 34, 36, 43, 51, 52, 55, 59, 60, 62, 63, 64, 68, 71, 74, 75, 83, 90, 92, 93, 94, 95, 104, 105, 115, 117, 118, 119, 125, 127, 132, 137, 140, 141, 142, 144)); // TODO: Check after every update.
+ private final static HashSet<Integer> invalidItems = new HashSet<Integer>(java.util.Arrays.asList(8, 9, 10, 11, 26, 34, 36, 43, 51, 52, 55, 59, 60, 62, 63, 64, 68, 71, 74, 75, 83, 90, 92, 93, 94, 104, 105, 115, 117, 118, 119, 125, 127, 132, 137, 140, 141, 142, 144)); // TODO: Check after every update.
// CraftBukkit end
- public void e() {
+ public void a() {
this.g = false;
++this.e;
- this.minecraftServer.methodProfiler.a("packetflow");
- this.networkManager.b();
- this.minecraftServer.methodProfiler.c("keepAlive");
- if ((long) this.e - this.k > 20L) {
+ this.minecraftServer.methodProfiler.a("keepAlive");
+ if ((long) this.e - this.k > 40L) {
this.k = (long) this.e;
- this.i = System.nanoTime() / 1000000L;
- this.h = j.nextInt();
- this.sendPacket(new Packet0KeepAlive(this.h));
+ this.i = this.d();
+ this.h = (int) this.i;
+ this.sendPacket(new PacketPlayOutKeepAlive(this.h));
}
// CraftBukkit start
for (int spam; (spam = this.chatThrottle) > 0 && !chatSpamField.compareAndSet(this, spam, spam - 1); ) ;
/* Use thread-safe field access instead
- if (this.m > 0) {
- --this.m;
+ if (this.chatThrottle > 0) {
+ --this.chatThrottle;
}
*/
// CraftBukkit end
@@ -139,46 +143,38 @@ public class PlayerConnection extends Connection {
this.minecraftServer.methodProfiler.b();
}
- public void disconnect(String s) {
- if (!this.disconnected) {
- // CraftBukkit start
- 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);
- }
+ public NetworkManager b() {
+ return this.networkManager;
+ }
- if (event.isCancelled()) {
- // Do not kick the player
- return;
- }
- // Send the possibly modified leave message
- s = event.getReason();
- // CraftBukkit end
+ public void disconnect(String s) {
+ // CraftBukkit start
+ String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";
- this.player.l();
- this.sendPacket(new Packet255KickDisconnect(s));
- this.networkManager.d();
+ PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);
- // CraftBukkit start
- leaveMessage = event.getLeaveMessage();
- if (leaveMessage != null && leaveMessage.length() > 0) {
- this.minecraftServer.getPlayerList().sendMessage(ChatMessage.d(leaveMessage));
- }
- // CraftBukkit end
+ if (this.server.getServer().isRunning()) {
+ this.server.getPluginManager().callEvent(event);
+ }
- this.minecraftServer.getPlayerList().disconnect(this.player);
- this.disconnected = true;
+ if (event.isCancelled()) {
+ // Do not kick the player
+ return;
}
+ // Send the possibly modified leave message
+ s = event.getReason();
+ // CraftBukkit end
+ ChatComponentText chatcomponenttext = new ChatComponentText(s);
+
+ this.networkManager.handle(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener[] { new PlayerConnectionFuture(this, chatcomponenttext)});
+ this.networkManager.g();
}
- public void a(Packet27PlayerInput packet27playerinput) {
- this.player.a(packet27playerinput.d(), packet27playerinput.f(), packet27playerinput.g(), packet27playerinput.h());
+ public void a(PacketPlayInSteerVehicle packetplayinsteervehicle) {
+ this.player.a(packetplayinsteervehicle.c(), packetplayinsteervehicle.d(), packetplayinsteervehicle.e(), packetplayinsteervehicle.f());
}
- public void a(Packet10Flying packet10flying) {
+ public void a(PacketPlayInFlying packetplayinflying) {
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
this.g = true;
@@ -186,8 +182,8 @@ public class PlayerConnection extends Connection {
double d0;
if (!this.checkMovement) {
- d0 = packet10flying.y - this.z;
- if (packet10flying.x == this.y && d0 * d0 < 0.01D && packet10flying.z == this.p) {
+ d0 = packetplayinflying.d() - this.z;
+ if (packetplayinflying.c() == this.y && d0 * d0 < 0.01D && packetplayinflying.e() == this.q) {
this.checkMovement = true;
}
}
@@ -198,16 +194,16 @@ public class PlayerConnection extends Connection {
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 (packet10flying.hasPos && !(packet10flying.hasPos && packet10flying.y == -999.0D && packet10flying.stance == -999.0D)) {
- to.setX(packet10flying.x);
- to.setY(packet10flying.y);
- to.setZ(packet10flying.z);
+ if (packetplayinflying.hasPos && !(packetplayinflying.hasPos && packetplayinflying.y == -999.0D && packetplayinflying.stance == -999.0D)) {
+ to.setX(packetplayinflying.x);
+ to.setY(packetplayinflying.y);
+ to.setZ(packetplayinflying.z);
}
// If the packet contains look information then we update the To location with the correct Yaw & Pitch.
- if (packet10flying.hasLook) {
- to.setYaw(packet10flying.yaw);
- to.setPitch(packet10flying.pitch);
+ if (packetplayinflying.hasLook) {
+ to.setYaw(packetplayinflying.yaw);
+ to.setPitch(packetplayinflying.pitch);
}
// Prevent 40 event-calls for less than a single pixel of movement >.>
@@ -228,7 +224,7 @@ public class PlayerConnection extends Connection {
// If the event is cancelled we move the player back to their old location.
if (event.isCancelled()) {
- this.player.playerConnection.sendPacket(new Packet13PlayerLookMove(from.getX(), from.getY() + 1.6200000047683716D, from.getY(), from.getZ(), from.getYaw(), from.getPitch(), false));
+ this.player.playerConnection.sendPacket(new PacketPlayOutPosition(from.getX(), from.getY() + 1.6200000047683716D, from.getZ(), from.getYaw(), from.getPitch(), false));
return;
}
@@ -249,7 +245,7 @@ public class PlayerConnection extends Connection {
}
}
- if (Double.isNaN(packet10flying.x) || Double.isNaN(packet10flying.y) || Double.isNaN(packet10flying.z) || Double.isNaN(packet10flying.stance)) {
+ if (Double.isNaN(packetplayinflying.x) || Double.isNaN(packetplayinflying.y) || Double.isNaN(packetplayinflying.z) || Double.isNaN(packetplayinflying.stance)) {
player.teleport(player.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
System.err.println(player.getName() + " was caught trying to crash the server with an invalid position.");
player.kickPlayer("Nope!");
@@ -266,28 +262,28 @@ public class PlayerConnection extends Connection {
float f = this.player.yaw;
float f1 = this.player.pitch;
- this.player.vehicle.W();
+ this.player.vehicle.ac();
d1 = this.player.locX;
d2 = this.player.locY;
d3 = this.player.locZ;
- if (packet10flying.hasLook) {
- f = packet10flying.yaw;
- f1 = packet10flying.pitch;
+ if (packetplayinflying.k()) {
+ f = packetplayinflying.g();
+ f1 = packetplayinflying.h();
}
- this.player.onGround = packet10flying.g;
- this.player.h();
- this.player.X = 0.0F;
+ this.player.onGround = packetplayinflying.i();
+ this.player.i();
+ this.player.W = 0.0F;
this.player.setLocation(d1, d2, d3, f, f1);
if (this.player.vehicle != null) {
- this.player.vehicle.W();
+ this.player.vehicle.ac();
}
this.minecraftServer.getPlayerList().d(this.player);
if (this.checkMovement) {
this.y = this.player.locX;
this.z = this.player.locY;
- this.p = this.player.locZ;
+ this.q = this.player.locZ;
}
worldserver.playerJoinedWorld(this.player);
@@ -295,8 +291,8 @@ public class PlayerConnection extends Connection {
}
if (this.player.isSleeping()) {
- this.player.h();
- this.player.setLocation(this.y, this.z, this.p, this.player.yaw, this.player.pitch);
+ this.player.i();
+ this.player.setLocation(this.y, this.z, this.q, this.player.yaw, this.player.pitch);
worldserver.playerJoinedWorld(this.player);
return;
}
@@ -304,45 +300,44 @@ public class PlayerConnection extends Connection {
d0 = this.player.locY;
this.y = this.player.locX;
this.z = this.player.locY;
- this.p = this.player.locZ;
+ this.q = this.player.locZ;
d1 = this.player.locX;
d2 = this.player.locY;
d3 = this.player.locZ;
float f2 = this.player.yaw;
float f3 = this.player.pitch;
- if (packet10flying.hasPos && packet10flying.y == -999.0D && packet10flying.stance == -999.0D) {
- packet10flying.hasPos = false;
+ if (packetplayinflying.j() && packetplayinflying.d() == -999.0D && packetplayinflying.f() == -999.0D) {
+ packetplayinflying.a(false);
}
double d4;
- if (packet10flying.hasPos) {
- d1 = packet10flying.x;
- d2 = packet10flying.y;
- d3 = packet10flying.z;
- d4 = packet10flying.stance - packet10flying.y;
+ if (packetplayinflying.j()) {
+ d1 = packetplayinflying.c();
+ d2 = packetplayinflying.d();
+ d3 = packetplayinflying.e();
+ d4 = packetplayinflying.f() - packetplayinflying.d();
if (!this.player.isSleeping() && (d4 > 1.65D || d4 < 0.1D)) {
this.disconnect("Illegal stance");
- this.minecraftServer.getLogger().warning(this.player.getName() + " had an illegal stance: " + d4);
+ c.warn(this.player.getName() + " had an illegal stance: " + d4);
return;
}
- if (Math.abs(packet10flying.x) > 3.2E7D || Math.abs(packet10flying.z) > 3.2E7D) {
- // CraftBukkit - teleport to previous position instead of kicking, players get stuck
- this.a(this.y, this.z, this.p, this.player.yaw, this.player.pitch);
+ if (Math.abs(packetplayinflying.c()) > 3.2E7D || Math.abs(packetplayinflying.e()) > 3.2E7D) {
+ this.disconnect("Illegal position");
return;
}
}
- if (packet10flying.hasLook) {
- f2 = packet10flying.yaw;
- f3 = packet10flying.pitch;
+ if (packetplayinflying.k()) {
+ f2 = packetplayinflying.g();
+ f3 = packetplayinflying.h();
}
- this.player.h();
- this.player.X = 0.0F;
- this.player.setLocation(this.y, this.z, this.p, f2, f3);
+ this.player.i();
+ this.player.W = 0.0F;
+ this.player.setLocation(this.y, this.z, this.q, f2, f3);
if (!this.checkMovement) {
return;
}
@@ -357,21 +352,21 @@ public class PlayerConnection extends Connection {
// CraftBukkit end
double d10 = d7 * d7 + d8 * d8 + d9 * d9;
- if (d10 > 100.0D && this.checkMovement && (!this.minecraftServer.K() || !this.minecraftServer.J().equals(this.player.getName()))) { // CraftBukkit - Added this.checkMovement condition to solve this check being triggered by teleports
- this.minecraftServer.getLogger().warning(this.player.getName() + " moved too quickly! " + d4 + "," + d5 + "," + d6 + " (" + d7 + ", " + d8 + ", " + d9 + ")");
- this.a(this.y, this.z, this.p, this.player.yaw, this.player.pitch);
+ if (d10 > 100.0D && this.checkMovement && (!this.minecraftServer.L() || !this.minecraftServer.K().equals(this.player.getName()))) { // CraftBukkit - Added this.checkMovement condition to solve this check being triggered by teleports
+ c.warn(this.player.getName() + " moved too quickly! " + d4 + "," + d5 + "," + d6 + " (" + d7 + ", " + d8 + ", " + d9 + ")");
+ this.a(this.y, this.z, this.q, this.player.yaw, this.player.pitch);
return;
}
float f4 = 0.0625F;
boolean flag = worldserver.getCubes(this.player, this.player.boundingBox.clone().shrink((double) f4, (double) f4, (double) f4)).isEmpty();
- if (this.player.onGround && !packet10flying.g && d5 > 0.0D) {
- this.player.a(0.2F);
+ if (this.player.onGround && !packetplayinflying.i() && d5 > 0.0D) {
+ this.player.bj();
}
this.player.move(d4, d5, d6);
- this.player.onGround = packet10flying.g;
+ this.player.onGround = packetplayinflying.i();
this.player.checkMovement(d4, d5, d6);
double d11 = d5;
@@ -387,14 +382,14 @@ public class PlayerConnection extends Connection {
if (d10 > 0.0625D && !this.player.isSleeping() && !this.player.playerInteractManager.isCreative()) {
flag1 = true;
- this.minecraftServer.getLogger().warning(this.player.getName() + " moved wrongly!");
+ c.warn(this.player.getName() + " moved wrongly!");
}
this.player.setLocation(d1, d2, d3, f2, f3);
boolean flag2 = worldserver.getCubes(this.player, this.player.boundingBox.clone().shrink((double) f4, (double) f4, (double) f4)).isEmpty();
if (flag && (flag1 || !flag2) && !this.player.isSleeping()) {
- this.a(this.y, this.z, this.p, f2, f3);
+ this.a(this.y, this.z, this.q, f2, f3);
return;
}
@@ -404,7 +399,7 @@ public class PlayerConnection extends Connection {
if (d11 >= -0.03125D) {
++this.f;
if (this.f > 80) {
- this.minecraftServer.getLogger().warning(this.player.getName() + " was kicked for floating too long!");
+ c.warn(this.player.getName() + " was kicked for floating too long!");
this.disconnect("Flying is not enabled on this server");
return;
}
@@ -413,12 +408,12 @@ public class PlayerConnection extends Connection {
this.f = 0;
}
- this.player.onGround = packet10flying.g;
+ this.player.onGround = packetplayinflying.i();
this.minecraftServer.getPlayerList().d(this.player);
if (this.player.playerInteractManager.isCreative()) return; // CraftBukkit - fixed fall distance accumulating while being in Creative mode.
- this.player.b(this.player.locY - d0, packet10flying.g);
+ this.player.b(this.player.locY - d0, packetplayinflying.i());
} else if (this.e % 20 == 0) {
- this.a(this.y, this.z, this.p, this.player.yaw, this.player.pitch);
+ this.a(this.y, this.z, this.q, this.player.yaw, this.player.pitch);
}
}
}
@@ -467,18 +462,17 @@ public class PlayerConnection extends Connection {
this.checkMovement = false;
this.y = d0;
this.z = d1;
- this.p = d2;
+ this.q = d2;
this.player.setLocation(d0, d1, d2, f, f1);
- this.player.playerConnection.sendPacket(new Packet13PlayerLookMove(d0, d1 + 1.6200000047683716D, d1, d2, f, f1, false));
+ this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0, d1 + 1.6200000047683716D, d2, f, f1, false));
}
- public void a(Packet14BlockDig packet14blockdig) {
+ public void a(PacketPlayInBlockDig packetplayinblockdig) {
if (this.player.dead) return; // CraftBukkit
-
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
- this.player.u();
- if (packet14blockdig.e == 4) {
+ this.player.w();
+ if (packetplayinblockdig.g() == 4) {
// CraftBukkit start
// If the ticks aren't the same then the count starts from 0 and we update the lastDropTick.
if (this.lastDropTick != MinecraftServer.currentTick) {
@@ -488,35 +482,35 @@ public class PlayerConnection extends Connection {
// Else we increment the drop count and check the amount.
this.dropCount++;
if (this.dropCount >= 20) {
- this.minecraftServer.getLogger().warning(this.player.getName() + " dropped their items too quickly!");
+ this.c.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);
- } else if (packet14blockdig.e == 3) {
+ } else if (packetplayinblockdig.g() == 3) {
this.player.a(true);
- } else if (packet14blockdig.e == 5) {
- this.player.bt();
+ } else if (packetplayinblockdig.g() == 5) {
+ this.player.by();
} else {
boolean flag = false;
- if (packet14blockdig.e == 0) {
+ if (packetplayinblockdig.g() == 0) {
flag = true;
}
- if (packet14blockdig.e == 1) {
+ if (packetplayinblockdig.g() == 1) {
flag = true;
}
- if (packet14blockdig.e == 2) {
+ if (packetplayinblockdig.g() == 2) {
flag = true;
}
- int i = packet14blockdig.a;
- int j = packet14blockdig.b;
- int k = packet14blockdig.c;
+ int i = packetplayinblockdig.c();
+ int j = packetplayinblockdig.d();
+ int k = packetplayinblockdig.e();
if (flag) {
double d0 = this.player.locX - ((double) i + 0.5D);
@@ -533,13 +527,13 @@ public class PlayerConnection extends Connection {
}
}
- if (packet14blockdig.e == 0) {
- // CraftBukkit start
+ if (packetplayinblockdig.g() == 0) {
if (!this.minecraftServer.a(worldserver, i, j, k, this.player)) {
- this.player.playerInteractManager.dig(i, j, k, packet14blockdig.face);
+ this.player.playerInteractManager.dig(i, j, k, packetplayinblockdig.f());
} else {
- CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, i, j, k, packet14blockdig.face, this.player.inventory.getItemInHand());
- this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
+ // CraftBukkit start
+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, i, j, k, packetplayinblockdig.f(), this.player.inventory.getItemInHand());
+ this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver));
// Update any tile entity data for this block
TileEntity tileentity = worldserver.getTileEntity(i, j, k);
if (tileentity != null) {
@@ -547,21 +541,21 @@ public class PlayerConnection extends Connection {
}
// CraftBukkit end
}
- } else if (packet14blockdig.e == 2) {
+ } else if (packetplayinblockdig.g() == 2) {
this.player.playerInteractManager.a(i, j, k);
- if (worldserver.getTypeId(i, j, k) != 0) {
- this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
+ if (worldserver.getType(i, j, k).getMaterial() != Material.AIR) {
+ this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver));
}
- } else if (packet14blockdig.e == 1) {
+ } else if (packetplayinblockdig.g() == 1) {
this.player.playerInteractManager.c(i, j, k);
- if (worldserver.getTypeId(i, j, k) != 0) {
- this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
+ if (worldserver.getType(i, j, k).getMaterial() != Material.AIR) {
+ this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver));
}
}
}
}
- public void a(Packet15Place packet15place) {
+ public void a(PacketPlayInBlockPlace packetplayinblockplace) {
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
// CraftBukkit start
@@ -574,33 +568,30 @@ public class PlayerConnection extends Connection {
// If the time between packets is small enough, and the 'signature' similar, we discard the
// second one. This sadly has to remain until Mojang makes their packets saner. :(
// -- Grum
-
- this.player.u();
- if (packet15place.getFace() == 255) {
- if (packet15place.getItemStack() != null && packet15place.getItemStack().id == this.lastMaterial && this.lastPacket != null && packet15place.timestamp - this.lastPacket < 100) {
+ if (packetplayinblockplace.getFace() == 255) {
+ if (packetplayinblockplace.getItemStack() != null && packetplayinblockplace.getItemStack().getItem() == this.lastMaterial && this.lastPacket != null && packetplayinblockplace.timestamp - this.lastPacket < 100) {
this.lastPacket = null;
return;
}
} else {
- this.lastMaterial = packet15place.getItemStack() == null ? -1 : packet15place.getItemStack().id;
- this.lastPacket = packet15place.timestamp;
+ this.lastMaterial = packetplayinblockplace.getItemStack() == null ? null : packetplayinblockplace.getItemStack().getItem();
+ this.lastPacket = packetplayinblockplace.timestamp;
}
-
- // CraftBukkit - if rightclick decremented the item, always send the update packet.
+ // CraftBukkit - if rightclick decremented the item, always send the update packet. */
// this is not here for CraftBukkit's own functionality; rather it is to fix
// a notch bug where the item doesn't update correctly.
boolean always = false;
-
// CraftBukkit end
ItemStack itemstack = this.player.inventory.getItemInHand();
boolean flag = false;
- int i = packet15place.d();
- int j = packet15place.f();
- int k = packet15place.g();
- int l = packet15place.getFace();
+ int i = packetplayinblockplace.c();
+ int j = packetplayinblockplace.d();
+ int k = packetplayinblockplace.e();
+ int l = packetplayinblockplace.getFace();
- if (packet15place.getFace() == 255) {
+ this.player.w();
+ if (packetplayinblockplace.getFace() == 255) {
if (itemstack == null) {
return;
}
@@ -617,8 +608,11 @@ public class PlayerConnection extends Connection {
// inventory update packet to get sent
always = (itemstack.count != itemstackAmount);
// CraftBukkit end
- } else if (packet15place.f() >= this.minecraftServer.getMaxBuildHeight() - 1 && (packet15place.getFace() == 1 || packet15place.f() >= this.minecraftServer.getMaxBuildHeight())) {
- this.player.playerConnection.sendPacket(new Packet3Chat(ChatMessage.b("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())}).a(EnumChatFormat.RED)));
+ } else if (packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight() - 1 && (packetplayinblockplace.getFace() == 1 || packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight())) {
+ ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())});
+
+ chatmessage.b().setColor(EnumChatFormat.RED);
+ this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage));
flag = true;
} else {
// CraftBukkit start - Check if we can actually do something over this large a distance
@@ -627,14 +621,14 @@ public class PlayerConnection extends Connection {
return;
}
- this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l, packet15place.j(), packet15place.k(), packet15place.l());
+ this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l, packetplayinblockplace.h(), packetplayinblockplace.i(), packetplayinblockplace.j());
// CraftBukkit end
flag = true;
}
if (flag) {
- this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
+ this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver));
if (l == 0) {
--j;
}
@@ -659,7 +653,7 @@ public class PlayerConnection extends Connection {
++i;
}
- this.player.playerConnection.sendPacket(new Packet53BlockChange(i, j, k, worldserver));
+ this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(i, j, k, worldserver));
}
itemstack = this.player.inventory.getItemInHand();
@@ -676,45 +670,45 @@ public class PlayerConnection extends Connection {
this.player.activeContainer.b();
this.player.h = false;
// CraftBukkit - TODO CHECK IF NEEDED -- new if structure might not need 'always'. Kept it in for now, but may be able to remove in future
- if (!ItemStack.matches(this.player.inventory.getItemInHand(), packet15place.getItemStack()) || always) {
- this.sendPacket(new Packet103SetSlot(this.player.activeContainer.windowId, slot.g, this.player.inventory.getItemInHand()));
+ if (!ItemStack.matches(this.player.inventory.getItemInHand(), packetplayinblockplace.getItemStack()) || always) {
+ this.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, slot.rawSlotIndex, this.player.inventory.getItemInHand()));
}
}
}
- public void a(String s, Object[] aobject) {
- if (this.disconnected) return; // CraftBukkit - Rarely it would send a disconnect line twice
+ public void a(IChatBaseComponent ichatbasecomponent) {
+ c.info(this.player.getName() + " lost connection: " + ichatbasecomponent.c()); // CraftBukkit - Don't toString the component
+ this.minecraftServer.au();
+ // CraftBukkit start - Replace vanilla quit message handling with our own.
+ /*
+ ChatMessage chatmessage = new ChatMessage("multiplayer.player.left", new Object[] { this.player.getScoreboardDisplayName()});
- this.minecraftServer.getLogger().info(this.player.getName() + " lost connection: " + s);
- // CraftBukkit start - We need to handle custom quit messages
+ chatmessage.b().setColor(EnumChatFormat.YELLOW);
+ this.minecraftServer.getPlayerList().sendMessage(chatmessage);
+ */
+
+ this.player.n();
String quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player);
if ((quitMessage != null) && (quitMessage.length() > 0)) {
- this.minecraftServer.getPlayerList().sendMessage(ChatMessage.d(quitMessage));
+ this.minecraftServer.getPlayerList().sendMessage(CraftChatMessage.fromString(quitMessage));
}
// CraftBukkit end
- this.disconnected = true;
- if (this.minecraftServer.K() && this.player.getName().equals(this.minecraftServer.J())) {
- this.minecraftServer.getLogger().info("Stopping singleplayer server as player logged out");
+ if (this.minecraftServer.L() && this.player.getName().equals(this.minecraftServer.K())) {
+ c.info("Stopping singleplayer server as player logged out");
this.minecraftServer.safeShutdown();
}
}
- public void onUnhandledPacket(Packet packet) {
- if (this.disconnected) return; // CraftBukkit
- this.minecraftServer.getLogger().warning(this.getClass() + " wasn\'t prepared to deal with a " + packet.getClass());
- this.disconnect("Protocol error, unexpected packet");
- }
-
public void sendPacket(Packet packet) {
- if (packet instanceof Packet3Chat) {
- Packet3Chat packet3chat = (Packet3Chat) packet;
- int i = this.player.getChatFlags();
+ if (packet instanceof PacketPlayOutChat) {
+ PacketPlayOutChat packetplayoutchat = (PacketPlayOutChat) packet;
+ EnumChatVisibility enumchatvisibility = this.player.getChatFlags();
- if (i == 2) {
+ if (enumchatvisibility == EnumChatVisibility.HIDDEN) {
return;
}
- if (i == 1 && !packet3chat.isServer()) {
+ if (enumchatvisibility == EnumChatVisibility.SYSTEM && !packetplayoutchat.d()) {
return;
}
}
@@ -722,133 +716,65 @@ public class PlayerConnection extends Connection {
// CraftBukkit start
if (packet == null) {
return;
- } else if (packet instanceof Packet6SpawnPosition) {
- Packet6SpawnPosition packet6 = (Packet6SpawnPosition) packet;
+ } else if (packet instanceof PacketPlayOutSpawnPosition) {
+ PacketPlayOutSpawnPosition packet6 = (PacketPlayOutSpawnPosition) packet;
this.player.compassTarget = new Location(this.getPlayer().getWorld(), packet6.x, packet6.y, packet6.z);
}
// CraftBukkit end
try {
- this.networkManager.queue(packet);
+ this.networkManager.handle(packet, new GenericFutureListener[0]);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Sending packet");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent");
- crashreportsystemdetails.a("Packet ID", (Callable) (new CrashReportConnectionPacketID(this, packet)));
crashreportsystemdetails.a("Packet class", (Callable) (new CrashReportConnectionPacketClass(this, packet)));
throw new ReportedException(crashreport);
}
}
- public void a(Packet16BlockItemSwitch packet16blockitemswitch) {
+ public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
// CraftBukkit start
if (this.player.dead) return;
- if (packet16blockitemswitch.itemInHandIndex >= 0 && packet16blockitemswitch.itemInHandIndex < PlayerInventory.getHotbarSize()) {
- PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.inventory.itemInHandIndex, packet16blockitemswitch.itemInHandIndex);
+ if (packetplayinhelditemslot.c() >= 0 && packetplayinhelditemslot.c() < PlayerInventory.getHotbarSize()) {
+ PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.inventory.itemInHandIndex, packetplayinhelditemslot.c());
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
- this.sendPacket(new Packet16BlockItemSwitch(this.player.inventory.itemInHandIndex));
- this.player.u();
+ this.sendPacket(new PacketPlayOutHeldItemSlot(this.player.inventory.itemInHandIndex));
+ this.player.w();
return;
}
// CraftBukkit end
- this.player.inventory.itemInHandIndex = packet16blockitemswitch.itemInHandIndex;
- this.player.u();
+ this.player.inventory.itemInHandIndex = packetplayinhelditemslot.c();
+ this.player.w();
} else {
- this.minecraftServer.getLogger().warning(this.player.getName() + " tried to set an invalid carried item");
+ c.warn(this.player.getName() + " tried to set an invalid carried item");
this.disconnect("Nope!"); // CraftBukkit
}
}
- public void a(Packet3Chat packet3chat) {
- if (this.player.getChatFlags() == 2) {
- this.sendPacket(new Packet3Chat(ChatMessage.e("chat.cannotSend").a(EnumChatFormat.RED)));
- } else {
- this.player.u();
- String s = packet3chat.message;
+ public void a(PacketPlayInChat packetplayinchat) {
+ if (this.player.getChatFlags() == EnumChatVisibility.HIDDEN) {
+ ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]);
- if (s.length() > 100) {
- // CraftBukkit start
- if (packet3chat.a_()) {
- Waitable waitable = new Waitable() {
- @Override
- protected Object evaluate() {
- PlayerConnection.this.disconnect("Chat message too long");
- 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("Chat message too long");
- }
- // CraftBukkit end
- } else {
- s = StringUtils.normalizeSpace(s);
-
- for (int i = 0; i < s.length(); ++i) {
- if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
- // CraftBukkit start
- if (packet3chat.a_()) {
- Waitable waitable = new Waitable() {
- @Override
- protected Object evaluate() {
- PlayerConnection.this.disconnect("Illegal characters in chat");
- return null;
- }
- };
-
- this.minecraftServer.processQueue.add(waitable);
-
- try {
- waitable.get();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
- } else {
- this.disconnect("Illegal characters in chat");
- }
- // CraftBukkit end
- return;
- }
- }
-
- // CraftBukkit start
- if (this.player.getChatFlags() == 1 && !s.startsWith("/")) {
- this.sendPacket(new Packet3Chat(ChatMessage.e("chat.cannotSend").a(EnumChatFormat.RED)));
- return;
- }
+ chatmessage.b().setColor(EnumChatFormat.RED);
+ this.sendPacket(new PacketPlayOutChat(chatmessage));
+ } else {
+ this.player.w();
+ String s = packetplayinchat.c();
- if (!packet3chat.a_()) {
- try {
- this.minecraftServer.server.playerCommandState = true;
- this.chat(s, packet3chat.a_());
- } finally {
- this.minecraftServer.server.playerCommandState = false;
- }
- } else {
- this.chat(s, packet3chat.a_());
- }
+ s = StringUtils.normalizeSpace(s);
- // This section stays because it is only applicable to packets
- if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getName())) { // CraftBukkit use thread-safe spam
- if (packet3chat.a_()) {
+ for (int i = 0; i < s.length(); ++i) {
+ if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
+ // CraftBukkit start - threadsafety
+ if (packetplayinchat.a()) {
Waitable waitable = new Waitable() {
@Override
protected Object evaluate() {
- PlayerConnection.this.disconnect("disconnect.spam");
+ PlayerConnection.this.disconnect("Illegal characters in chat");
return null;
}
};
@@ -863,28 +789,59 @@ public class PlayerConnection extends Connection {
throw new RuntimeException(e);
}
} else {
- this.disconnect("disconnect.spam");
+ this.disconnect("Illegal characters in chat");
}
+ // CraftBukkit end
+ return;
}
}
- }
- }
- public void chat(String s, boolean async) {
- if (!this.player.dead) {
- if (s.length() == 0) {
- this.minecraftServer.getLogger().warning(this.player.getName() + " tried to send an empty message");
- return;
+ if (s.startsWith("/")) {
+ // CraftBukkit start
+ try {
+ this.minecraftServer.server.playerCommandState = true;
+ this.handleCommand(s);
+ } finally {
+ this.minecraftServer.server.playerCommandState = false;
+ }
+ } else if (s.isEmpty()) {
+ c.warn(this.player.getName() + " tried to send an empty message");
+ } else if (getPlayer().isConversing()) {
+ getPlayer().acceptConversationInput(s);
+ } else if (this.player.getChatFlags() == EnumChatVisibility.SYSTEM) { // Re-add "Command Only" flag check
+ ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]);
+
+ chatmessage.b().setColor(EnumChatFormat.RED);
+ this.sendPacket(new PacketPlayOutChat(chatmessage));
+ } else if (true) {
+ this.chat(s, packetplayinchat.a());
+ // 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);
}
- if (getPlayer().isConversing()) {
- getPlayer().acceptConversationInput(s);
- return;
+ // CraftBukkit start - replaced with thread safe throttle
+ // this.chatThrottle += 20;
+ if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getName())) {
+ // CraftBukkit end
+ this.disconnect("disconnect.spam");
}
+ }
+ }
+
+ // CraftBukkit start
+ public void chat(String s, boolean async) {
+ if (s.isEmpty()) {
+ return;
+ }
+ if (!this.player.dead) {
if (s.startsWith("/")) {
this.handleCommand(s);
- return;
+ } else if (this.player.getChatFlags() != EnumChatVisibility.FULL) {
+ // Do nothing, this is coming from a plugin
} else {
Player player = this.getPlayer();
AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet());
@@ -907,7 +864,7 @@ public class PlayerConnection extends Connection {
PlayerConnection.this.minecraftServer.console.sendMessage(message);
if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) {
for (Object player : PlayerConnection.this.minecraftServer.getPlayerList().players) {
- ((EntityPlayer) player).sendMessage(ChatMessage.d(message));
+ ((EntityPlayer) player).sendMessage(CraftChatMessage.fromString(message));
}
} else {
for (Player player : queueEvent.getRecipients()) {
@@ -937,7 +894,7 @@ public class PlayerConnection extends Connection {
minecraftServer.console.sendMessage(s);
if (((LazyPlayerSet) event.getRecipients()).isLazy()) {
for (Object recipient : minecraftServer.getPlayerList().players) {
- ((EntityPlayer) recipient).sendMessage(ChatMessage.d(s));
+ ((EntityPlayer) recipient).sendMessage(CraftChatMessage.fromString(s));
}
} else {
for (Player recipient : event.getRecipients()) {
@@ -947,8 +904,6 @@ public class PlayerConnection extends Connection {
}
}
}
-
- return;
}
// CraftBukkit end
@@ -964,7 +919,7 @@ public class PlayerConnection extends Connection {
}
try {
- this.minecraftServer.getLogger().info(event.getPlayer().getName() + " issued server command: " + event.getMessage()); // CraftBukkit
+ this.c.info(event.getPlayer().getName() + " issued server command: " + event.getMessage()); // CraftBukkit
if (this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1))) {
return;
}
@@ -973,18 +928,14 @@ public class PlayerConnection extends Connection {
java.util.logging.Logger.getLogger(PlayerConnection.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
return;
}
+ //this.minecraftServer.getCommandHandler().a(this.player, s);
// CraftBukkit end
-
- /* CraftBukkit start - No longer needed as we have already handled it in server.dispatchServerCommand above.
- this.minecraftServer.getCommandHandler().a(this.player, s);
- // CraftBukkit end */
}
- public void a(Packet18ArmAnimation packet18armanimation) {
+ public void a(PacketPlayInArmAnimation packetplayinarmanimation) {
if (this.player.dead) return; // CraftBukkit
-
- this.player.u();
- if (packet18armanimation.b == 1) {
+ this.player.w();
+ if (packetplayinarmanimation.d() == 1) {
// CraftBukkit start - Raytrace to look for 'rogue armswings'
float f = 1.0F;
float f1 = this.player.lastPitch + (this.player.pitch - this.player.lastPitch) * f;
@@ -1004,7 +955,7 @@ public class PlayerConnection extends Connection {
Vec3D vec3d1 = vec3d.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
MovingObjectPosition movingobjectposition = this.player.world.rayTrace(vec3d, vec3d1, true);
- if (movingobjectposition == null || movingobjectposition.type != EnumMovingObjectType.TILE) {
+ if (movingobjectposition == null || movingobjectposition.type != EnumMovingObjectType.BLOCK) {
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getItemInHand());
}
@@ -1015,17 +966,17 @@ public class PlayerConnection extends Connection {
if (event.isCancelled()) return;
// CraftBukkit end
- this.player.aV();
+ this.player.ba();
}
}
- public void a(Packet19EntityAction packet19entityaction) {
+ public void a(PacketPlayInEntityAction packetplayinentityaction) {
// CraftBukkit start
if (this.player.dead) return;
- this.player.u();
- if (packet19entityaction.animation == 1 || packet19entityaction.animation == 2) {
- PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getPlayer(), packet19entityaction.animation == 1);
+ this.player.w();
+ if (packetplayinentityaction.d() == 1 || packetplayinentityaction.d() == 2) {
+ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getPlayer(), packetplayinentityaction.d() == 1);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
@@ -1033,8 +984,8 @@ public class PlayerConnection extends Connection {
}
}
- if (packet19entityaction.animation == 4 || packet19entityaction.animation == 5) {
- PlayerToggleSprintEvent event = new PlayerToggleSprintEvent(this.getPlayer(), packet19entityaction.animation == 4);
+ if (packetplayinentityaction.d() == 4 || packetplayinentityaction.d() == 5) {
+ PlayerToggleSprintEvent event = new PlayerToggleSprintEvent(this.getPlayer(), packetplayinentityaction.d() == 4);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
@@ -1043,41 +994,32 @@ public class PlayerConnection extends Connection {
}
// CraftBukkit end
- if (packet19entityaction.animation == 1) {
+ if (packetplayinentityaction.d() == 1) {
this.player.setSneaking(true);
- } else if (packet19entityaction.animation == 2) {
+ } else if (packetplayinentityaction.d() == 2) {
this.player.setSneaking(false);
- } else if (packet19entityaction.animation == 4) {
+ } else if (packetplayinentityaction.d() == 4) {
this.player.setSprinting(true);
- } else if (packet19entityaction.animation == 5) {
+ } else if (packetplayinentityaction.d() == 5) {
this.player.setSprinting(false);
- } else if (packet19entityaction.animation == 3) {
+ } else if (packetplayinentityaction.d() == 3) {
this.player.a(false, true, true);
- // this.checkMovement = false; // CraftBukkit - this is handled in teleport
- } else if (packet19entityaction.animation == 6) {
+ //this.checkMovement = false; // CraftBukkit - this is handled in teleport
+ } else if (packetplayinentityaction.d() == 6) {
if (this.player.vehicle != null && this.player.vehicle instanceof EntityHorse) {
- ((EntityHorse) this.player.vehicle).u(packet19entityaction.c);
+ ((EntityHorse) this.player.vehicle).w(packetplayinentityaction.e());
}
- } else if (packet19entityaction.animation == 7 && this.player.vehicle != null && this.player.vehicle instanceof EntityHorse) {
- ((EntityHorse) this.player.vehicle).f(this.player);
+ } else if (packetplayinentityaction.d() == 7 && this.player.vehicle != null && this.player.vehicle instanceof EntityHorse) {
+ ((EntityHorse) this.player.vehicle).g(this.player);
}
}
- public void a(Packet255KickDisconnect packet255kickdisconnect) {
- this.networkManager.a("disconnect.quitting", new Object[0]);
- }
-
- public int lowPriorityCount() {
- return this.networkManager.e();
- }
-
- public void a(Packet7UseEntity packet7useentity) {
+ public void a(PacketPlayInUseEntity packetplayinuseentity) {
if (this.player.dead) return; // CraftBukkit
-
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
- Entity entity = worldserver.getEntity(packet7useentity.target);
+ Entity entity = packetplayinuseentity.a((World) worldserver);
- this.player.u();
+ this.player.w();
if (entity != null) {
boolean flag = this.player.o(entity);
double d0 = 36.0D;
@@ -1088,47 +1030,49 @@ public class PlayerConnection extends Connection {
if (this.player.e(entity) < d0) {
ItemStack itemInHand = this.player.inventory.getItemInHand(); // CraftBukkit
- if (packet7useentity.action == 0) {
+ if (packetplayinuseentity.c() == EnumEntityUseAction.INTERACT) {
// CraftBukkit start
- boolean triggerTagUpdate = itemInHand != null && itemInHand.id == Item.NAME_TAG.id && entity instanceof EntityInsentient;
- boolean triggerChestUpdate = itemInHand != null && itemInHand.id == Block.CHEST.id && entity instanceof EntityHorse;
- boolean triggerLeashUpdate = itemInHand != null && itemInHand.id == Item.LEASH.id && entity instanceof EntityInsentient;
+ boolean triggerTagUpdate = itemInHand != null && itemInHand.getItem() == Items.NAME_TAG && entity instanceof EntityInsentient;
+ boolean triggerChestUpdate = itemInHand != null && itemInHand.getItem() == Item.getItemOf(Blocks.CHEST) && entity instanceof EntityHorse;
+ boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEASH && entity instanceof EntityInsentient;
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) this.getPlayer(), entity.getBukkitEntity());
this.server.getPluginManager().callEvent(event);
- if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Item.LEASH.id)) {
+ if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.LEASH)) {
// Refresh the current leash state
- this.sendPacket(new Packet39AttachEntity(1, entity, ((EntityInsentient) entity).getLeashHolder()));
+ this.sendPacket(new PacketPlayOutAttachEntity(1, entity, ((EntityInsentient) entity).getLeashHolder()));
}
- if (triggerTagUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Item.NAME_TAG.id)) {
+ if (triggerTagUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Items.NAME_TAG)) {
// Refresh the current entity metadata
- this.sendPacket(new Packet40EntityMetadata(entity.id, entity.datawatcher, true));
+ this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true));
}
- if (triggerChestUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Block.CHEST.id)) {
- this.sendPacket(new Packet40EntityMetadata(entity.id, entity.datawatcher, true));
+ if (triggerChestUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != Item.getItemOf(Blocks.CHEST))) {
+ this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true));
}
if (event.isCancelled()) {
return;
}
// CraftBukkit end
+
this.player.p(entity);
- // CraftBukkit start - Update the client if the item is an infinite one
+
+ // CraftBukkit start
if (itemInHand != null && itemInHand.count <= -1) {
this.player.updateInventory(this.player.activeContainer);
}
- } else if (packet7useentity.action == 1) {
- // CraftBukkit - Check for player
- if ((entity instanceof EntityItem) || (entity instanceof EntityExperienceOrb) || (entity instanceof EntityArrow) || (entity == this.player)) {
- String type = entity.getClass().getSimpleName();
- disconnect("Attacking an " + type + " is not permitted");
- System.out.println("Player " + player.getName() + " tried to attack an " + type + ", so I have disconnected them for exploiting.");
+ // CraftBukkit end
+ } else if (packetplayinuseentity.c() == EnumEntityUseAction.ATTACK) {
+ if (entity instanceof EntityItem || entity instanceof EntityExperienceOrb || entity instanceof EntityArrow || entity == this.player) {
+ this.disconnect("Attempting to attack an invalid entity");
+ this.minecraftServer.warning("Player " + this.player.getName() + " tried to attack an invalid entity");
return;
}
this.player.attack(entity);
+ // CraftBukkit start
if (itemInHand != null && itemInHand.count <= -1) {
this.player.updateInventory(this.player.activeContainer);
}
@@ -1138,15 +1082,18 @@ public class PlayerConnection extends Connection {
}
}
- public void a(Packet205ClientCommand packet205clientcommand) {
- this.player.u();
- if (packet205clientcommand.a == 1) {
+ public void a(PacketPlayInClientCommand packetplayinclientcommand) {
+ this.player.w();
+ EnumClientCommand enumclientcommand = packetplayinclientcommand.c();
+
+ switch (ClientCommandOrdinalWrapper.a[enumclientcommand.ordinal()]) {
+ case 1:
if (this.player.viewingCredits) {
this.minecraftServer.getPlayerList().changeDimension(this.player, 0, PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit - reroute logic through custom portal management
- } else if (this.player.p().getWorldData().isHardcore()) {
- if (this.minecraftServer.K() && this.player.getName().equals(this.minecraftServer.J())) {
+ } else if (this.player.r().getWorldData().isHardcore()) {
+ if (this.minecraftServer.L() && this.player.getName().equals(this.minecraftServer.K())) {
this.player.playerConnection.disconnect("You have died. Game over, man, it\'s game over!");
- this.minecraftServer.R();
+ this.minecraftServer.S();
} else {
BanEntry banentry = new BanEntry(this.player.getName());
@@ -1161,35 +1108,37 @@ public class PlayerConnection extends Connection {
this.player = this.minecraftServer.getPlayerList().moveToWorld(this.player, 0, false);
}
- }
- }
+ break;
- public boolean b() {
- return true;
- }
+ case 2:
+ this.player.x().a(this.player);
+ break;
- public void a(Packet9Respawn packet9respawn) {}
+ case 3:
+ this.player.a((Statistic) AchievementList.f);
+ }
+ }
- public void handleContainerClose(Packet101CloseWindow packet101closewindow) {
+ public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
if (this.player.dead) return; // CraftBukkit
CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit
- this.player.k();
+ this.player.m();
}
- public void a(Packet102WindowClick packet102windowclick) {
+ public void a(PacketPlayInWindowClick packetplayinwindowclick) {
if (this.player.dead) return; // CraftBukkit
- this.player.u();
- if (this.player.activeContainer.windowId == packet102windowclick.a && this.player.activeContainer.c(this.player)) {
+ this.player.w();
+ if (this.player.activeContainer.windowId == packetplayinwindowclick.c() && this.player.activeContainer.c(this.player)) {
// CraftBukkit start - Call InventoryClickEvent
- if (packet102windowclick.slot < -1 && packet102windowclick.slot != -999) {
+ if (packetplayinwindowclick.d() < -1 && packetplayinwindowclick.d() != -999) {
return;
}
InventoryView inventory = this.player.activeContainer.getBukkitView();
- SlotType type = CraftInventoryView.getSlotType(inventory, packet102windowclick.slot);
+ SlotType type = CraftInventoryView.getSlotType(inventory, packetplayinwindowclick.d());
InventoryClickEvent event = null;
ClickType click = ClickType.UNKNOWN;
@@ -1197,37 +1146,37 @@ public class PlayerConnection extends Connection {
ItemStack itemstack = null;
- if (packet102windowclick.slot == -1) {
+ if (packetplayinwindowclick.d() == -1) {
type = SlotType.OUTSIDE; // override
- click = packet102windowclick.button == 0 ? ClickType.WINDOW_BORDER_LEFT : ClickType.WINDOW_BORDER_RIGHT;
+ click = packetplayinwindowclick.e() == 0 ? ClickType.WINDOW_BORDER_LEFT : ClickType.WINDOW_BORDER_RIGHT;
action = InventoryAction.NOTHING;
- } else if (packet102windowclick.shift == 0) {
- if (packet102windowclick.button == 0) {
+ } else if (packetplayinwindowclick.h() == 0) {
+ if (packetplayinwindowclick.e() == 0) {
click = ClickType.LEFT;
- } else if (packet102windowclick.button == 1) {
+ } else if (packetplayinwindowclick.e() == 1) {
click = ClickType.RIGHT;
}
- if (packet102windowclick.button == 0 || packet102windowclick.button == 1) {
+ if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
action = InventoryAction.NOTHING; // Don't want to repeat ourselves
- if (packet102windowclick.slot == -999) {
+ if (packetplayinwindowclick.d() == -999) {
if (player.inventory.getCarried() != null) {
- action = packet102windowclick.button == 0 ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR;
+ action = packetplayinwindowclick.e() == 0 ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR;
}
} else {
- Slot slot = this.player.activeContainer.getSlot(packet102windowclick.slot);
+ Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
if (slot != null) {
ItemStack clickedItem = slot.getItem();
ItemStack cursor = player.inventory.getCarried();
if (clickedItem == null) {
if (cursor != null) {
- action = packet102windowclick.button == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE;
+ action = packetplayinwindowclick.e() == 0 ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE;
}
} else if (slot.a(player)) { // Should be Slot.isPlayerAllowed
if (cursor == null) {
- action = packet102windowclick.button == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF;
+ action = packetplayinwindowclick.e() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF;
} else if (slot.isAllowed(cursor)) { // Should be Slot.isItemAllowed
if (clickedItem.doMaterialsMatch(cursor) && ItemStack.equals(clickedItem, cursor)) {
- int toPlace = packet102windowclick.button == 0 ? cursor.count : 1;
+ int toPlace = packetplayinwindowclick.e() == 0 ? cursor.count : 1;
toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.count);
toPlace = Math.min(toPlace, slot.inventory.getMaxStackSize() - clickedItem.count);
if (toPlace == 1) {
@@ -1242,7 +1191,7 @@ public class PlayerConnection extends Connection {
} else if (cursor.count <= slot.a()) { // Should be Slot.getMaxStackSize()
action = InventoryAction.SWAP_WITH_CURSOR;
}
- } else if (cursor.id == clickedItem.id && (!cursor.usesData() || cursor.getData() == clickedItem.getData()) && ItemStack.equals(cursor, clickedItem)) {
+ } else if (cursor.getItem() == clickedItem.getItem() && (!cursor.usesData() || cursor.getData() == clickedItem.getData()) && ItemStack.equals(cursor, clickedItem)) {
if (clickedItem.count >= 0) {
if (clickedItem.count + cursor.count <= cursor.getMaxStackSize()) {
// As of 1.5, this is result slots only
@@ -1254,17 +1203,17 @@ public class PlayerConnection extends Connection {
}
}
}
- } else if (packet102windowclick.shift == 1) {
- if (packet102windowclick.button == 0) {
+ } else if (packetplayinwindowclick.h() == 1) {
+ if (packetplayinwindowclick.e() == 0) {
click = ClickType.SHIFT_LEFT;
- } else if (packet102windowclick.button == 1) {
+ } else if (packetplayinwindowclick.e() == 1) {
click = ClickType.SHIFT_RIGHT;
}
- if (packet102windowclick.button == 0 || packet102windowclick.button == 1) {
- if (packet102windowclick.slot < 0) {
+ if (packetplayinwindowclick.e() == 0 || packetplayinwindowclick.e() == 1) {
+ if (packetplayinwindowclick.d() < 0) {
action = InventoryAction.NOTHING;
} else {
- Slot slot = this.player.activeContainer.getSlot(packet102windowclick.slot);
+ Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
if (slot != null && slot.a(this.player) && slot.e()) { // Should be Slot.hasItem()
action = InventoryAction.MOVE_TO_OTHER_INVENTORY;
} else {
@@ -1272,12 +1221,12 @@ public class PlayerConnection extends Connection {
}
}
}
- } else if (packet102windowclick.shift == 2) {
- if (packet102windowclick.button >= 0 && packet102windowclick.button < 9) {
+ } else if (packetplayinwindowclick.h() == 2) {
+ if (packetplayinwindowclick.e() >= 0 && packetplayinwindowclick.e() < 9) {
click = ClickType.NUMBER_KEY;
- Slot clickedSlot = this.player.activeContainer.getSlot(packet102windowclick.slot);
+ Slot clickedSlot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
if (clickedSlot.a(player)) {
- ItemStack hotbar = this.player.inventory.getItem(packet102windowclick.button);
+ ItemStack hotbar = this.player.inventory.getItem(packetplayinwindowclick.e());
boolean canCleanSwap = hotbar == null || (clickedSlot.inventory == player.inventory && clickedSlot.isAllowed(hotbar)); // the slot will accept the hotbar item
if (clickedSlot.e()) {
if (canCleanSwap) {
@@ -1299,15 +1248,15 @@ public class PlayerConnection extends Connection {
action = InventoryAction.NOTHING;
}
// Special constructor for number key
- event = new InventoryClickEvent(inventory, type, packet102windowclick.slot, click, action, packet102windowclick.button);
+ event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
}
- } else if (packet102windowclick.shift == 3) {
- if (packet102windowclick.button == 2) {
+ } else if (packetplayinwindowclick.h() == 3) {
+ if (packetplayinwindowclick.e() == 2) {
click = ClickType.MIDDLE;
- if (packet102windowclick.slot == -999) {
+ if (packetplayinwindowclick.d() == -999) {
action = InventoryAction.NOTHING;
} else {
- Slot slot = this.player.activeContainer.getSlot(packet102windowclick.slot);
+ Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
if (slot != null && slot.e() && player.abilities.canInstantlyBuild && player.inventory.getCarried() == null) {
action = InventoryAction.CLONE_STACK;
} else {
@@ -1318,20 +1267,20 @@ public class PlayerConnection extends Connection {
click = ClickType.UNKNOWN;
action = InventoryAction.UNKNOWN;
}
- } else if (packet102windowclick.shift == 4) {
- if (packet102windowclick.slot >= 0) {
- if (packet102windowclick.button == 0) {
+ } else if (packetplayinwindowclick.h() == 4) {
+ if (packetplayinwindowclick.d() >= 0) {
+ if (packetplayinwindowclick.e() == 0) {
click = ClickType.DROP;
- Slot slot = this.player.activeContainer.getSlot(packet102windowclick.slot);
- if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().id != 0) {
+ Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
+ if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
action = InventoryAction.DROP_ONE_SLOT;
} else {
action = InventoryAction.NOTHING;
}
- } else if (packet102windowclick.button == 1) {
+ } else if (packetplayinwindowclick.e() == 1) {
click = ClickType.CONTROL_DROP;
- Slot slot = this.player.activeContainer.getSlot(packet102windowclick.slot);
- if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().id != 0) {
+ Slot slot = this.player.activeContainer.getSlot(packetplayinwindowclick.d());
+ if (slot != null && slot.e() && slot.a(player) && slot.getItem() != null && slot.getItem().getItem() != Item.getItemOf(Blocks.AIR)) {
action = InventoryAction.DROP_ALL_SLOT;
} else {
action = InventoryAction.NOTHING;
@@ -1340,42 +1289,42 @@ public class PlayerConnection extends Connection {
} else {
// Sane default (because this happens when they are holding nothing. Don't ask why.)
click = ClickType.LEFT;
- if (packet102windowclick.button == 1) {
+ if (packetplayinwindowclick.e() == 1) {
click = ClickType.RIGHT;
}
action = InventoryAction.NOTHING;
}
- } else if (packet102windowclick.shift == 5) {
- itemstack = this.player.activeContainer.clickItem(packet102windowclick.slot, packet102windowclick.button, 5, this.player);
- } else if (packet102windowclick.shift == 6) {
+ } else if (packetplayinwindowclick.h() == 5) {
+ itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), 5, this.player);
+ } else if (packetplayinwindowclick.h() == 6) {
click = ClickType.DOUBLE_CLICK;
action = InventoryAction.NOTHING;
- if (packet102windowclick.slot >= 0 && this.player.inventory.getCarried() != null) {
+ if (packetplayinwindowclick.d() >= 0 && this.player.inventory.getCarried() != null) {
ItemStack cursor = this.player.inventory.getCarried();
action = InventoryAction.NOTHING;
// Quick check for if we have any of the item
- if (inventory.getTopInventory().contains(cursor.id) || inventory.getBottomInventory().contains(cursor.id)) {
+ if (inventory.getTopInventory().contains(org.bukkit.Material.getMaterial(Item.b(cursor.getItem()))) || inventory.getBottomInventory().contains(org.bukkit.Material.getMaterial(Item.b(cursor.getItem())))) {
action = InventoryAction.COLLECT_TO_CURSOR;
}
}
}
// TODO check on updates
- if (packet102windowclick.shift != 5) {
+ if (packetplayinwindowclick.h() != 5) {
if (click == ClickType.NUMBER_KEY) {
- event = new InventoryClickEvent(inventory, type, packet102windowclick.slot, click, action, packet102windowclick.button);
+ event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
} else {
- event = new InventoryClickEvent(inventory, type, packet102windowclick.slot, click, action);
+ event = new InventoryClickEvent(inventory, type, packetplayinwindowclick.d(), click, action);
}
org.bukkit.inventory.Inventory top = inventory.getTopInventory();
- if (packet102windowclick.slot == 0 && top instanceof CraftingInventory) {
+ if (packetplayinwindowclick.d() == 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, packet102windowclick.slot, click, action, packet102windowclick.button);
+ event = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.d(), click, action, packetplayinwindowclick.e());
} else {
- event = new CraftItemEvent(recipe, inventory, type, packet102windowclick.slot, click, action);
+ event = new CraftItemEvent(recipe, inventory, type, packetplayinwindowclick.d(), click, action);
}
}
}
@@ -1385,7 +1334,7 @@ public class PlayerConnection extends Connection {
switch (event.getResult()) {
case ALLOW:
case DEFAULT:
- itemstack = this.player.activeContainer.clickItem(packet102windowclick.slot, packet102windowclick.button, packet102windowclick.shift, this.player);
+ itemstack = this.player.activeContainer.clickItem(packetplayinwindowclick.d(), packetplayinwindowclick.e(), packetplayinwindowclick.h(), this.player);
break;
case DENY:
/* Needs enum constructor in InventoryAction
@@ -1417,19 +1366,19 @@ public class PlayerConnection extends Connection {
case PLACE_SOME:
case PLACE_ONE:
case SWAP_WITH_CURSOR:
- this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried()));
- this.player.playerConnection.sendPacket(new Packet103SetSlot(this.player.activeContainer.windowId, packet102windowclick.slot, this.player.activeContainer.getSlot(packet102windowclick.slot).getItem()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.player.inventory.getCarried()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, packetplayinwindowclick.d(), this.player.activeContainer.getSlot(packetplayinwindowclick.d()).getItem()));
break;
// Modified clicked only
case DROP_ALL_SLOT:
case DROP_ONE_SLOT:
- this.player.playerConnection.sendPacket(new Packet103SetSlot(this.player.activeContainer.windowId, packet102windowclick.slot, this.player.activeContainer.getSlot(packet102windowclick.slot).getItem()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, packetplayinwindowclick.d(), this.player.activeContainer.getSlot(packetplayinwindowclick.d()).getItem()));
break;
// Modified cursor only
case DROP_ALL_CURSOR:
case DROP_ONE_CURSOR:
case CLONE_STACK:
- this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, this.player.inventory.getCarried()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.player.inventory.getCarried()));
break;
// Nothing
case NOTHING:
@@ -1440,15 +1389,15 @@ public class PlayerConnection extends Connection {
}
// CraftBukkit end
- if (ItemStack.matches(packet102windowclick.item, itemstack)) {
- this.player.playerConnection.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true));
+ if (ItemStack.matches(packetplayinwindowclick.g(), itemstack)) {
+ this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.c(), packetplayinwindowclick.f(), true));
this.player.h = true;
this.player.activeContainer.b();
this.player.broadcastCarriedItem();
this.player.h = false;
} else {
- this.r.a(this.player.activeContainer.windowId, Short.valueOf(packet102windowclick.d));
- this.player.playerConnection.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, false));
+ this.n.a(this.player.activeContainer.windowId, Short.valueOf(packetplayinwindowclick.f()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.c(), packetplayinwindowclick.f(), false));
this.player.activeContainer.a(this.player, false);
ArrayList arraylist = new ArrayList();
@@ -1460,48 +1409,48 @@ public class PlayerConnection extends Connection {
// CraftBukkit start - Send a Set Slot to update the crafting result slot
if (type == SlotType.RESULT && itemstack != null) {
- this.player.playerConnection.sendPacket((Packet) (new Packet103SetSlot(this.player.activeContainer.windowId, 0, itemstack)));
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, 0, itemstack));
}
// CraftBukkit end
}
}
}
- public void a(Packet108ButtonClick packet108buttonclick) {
- this.player.u();
- if (this.player.activeContainer.windowId == packet108buttonclick.a && this.player.activeContainer.c(this.player)) {
- this.player.activeContainer.a((EntityHuman) this.player, packet108buttonclick.b);
+ public void a(PacketPlayInEnchantItem packetplayinenchantitem) {
+ this.player.w();
+ if (this.player.activeContainer.windowId == packetplayinenchantitem.c() && this.player.activeContainer.c(this.player)) {
+ this.player.activeContainer.a((EntityHuman) this.player, packetplayinenchantitem.d());
this.player.activeContainer.b();
}
}
- public void a(Packet107SetCreativeSlot packet107setcreativeslot) {
+ public void a(PacketPlayInSetCreativeSlot packetplayinsetcreativeslot) {
if (this.player.playerInteractManager.isCreative()) {
- boolean flag = packet107setcreativeslot.slot < 0;
- ItemStack itemstack = packet107setcreativeslot.b;
- boolean flag1 = packet107setcreativeslot.slot >= 1 && packet107setcreativeslot.slot < 36 + PlayerInventory.getHotbarSize();
- // CraftBukkit
- boolean flag2 = itemstack == null || itemstack.id < Item.byId.length && itemstack.id >= 0 && Item.byId[itemstack.id] != null && !invalidItems.contains(itemstack.id);
- boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0;
+ boolean flag = packetplayinsetcreativeslot.c() < 0;
+ ItemStack itemstack = packetplayinsetcreativeslot.d();
+ boolean flag1 = packetplayinsetcreativeslot.c() >= 1 && packetplayinsetcreativeslot.c() < 36 + PlayerInventory.getHotbarSize();
+ // CraftBukkit - Add invalidItems check
+ boolean flag2 = itemstack == null || itemstack.getItem() != null && !invalidItems.contains(Item.b(itemstack.getItem()));
+ boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0;
// CraftBukkit start - Call click event
- if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packet107setcreativeslot.slot).getItem(), packet107setcreativeslot.b))) { // Insist on valid slot
+ if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.c()).getItem(), packetplayinsetcreativeslot.d()))) { // Insist on valid slot
org.bukkit.entity.HumanEntity player = this.player.getBukkitEntity();
InventoryView inventory = new CraftInventoryView(player, player.getInventory(), this.player.defaultContainer);
- org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packet107setcreativeslot.b); // Should be packet107setcreativeslot.newitem
+ org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.d()); // Should be packet107setcreativeslot.newitem
SlotType type = SlotType.QUICKBAR;
if (flag) {
type = SlotType.OUTSIDE;
- } else if (packet107setcreativeslot.slot < 36) {
- if (packet107setcreativeslot.slot >= 5 && packet107setcreativeslot.slot < 9) {
+ } else if (packetplayinsetcreativeslot.c() < 36) {
+ if (packetplayinsetcreativeslot.c() >= 5 && packetplayinsetcreativeslot.c() < 9) {
type = SlotType.ARMOR;
} else {
type = SlotType.CONTAINER;
}
}
- InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packet107setcreativeslot.slot, item);
+ InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.c(), item);
server.getPluginManager().callEvent(event);
itemstack = CraftItemStack.asNMSCopy(event.getCursor());
@@ -1515,9 +1464,9 @@ public class PlayerConnection extends Connection {
break;
case DENY:
// Reset the slot
- if (packet107setcreativeslot.slot >= 0) {
- this.player.playerConnection.sendPacket(new Packet103SetSlot(this.player.defaultContainer.windowId, packet107setcreativeslot.slot, this.player.defaultContainer.getSlot(packet107setcreativeslot.slot).getItem()));
- this.player.playerConnection.sendPacket(new Packet103SetSlot(-1, -1, null));
+ if (packetplayinsetcreativeslot.c() >= 0) {
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(this.player.defaultContainer.windowId, packetplayinsetcreativeslot.c(), this.player.defaultContainer.getSlot(packetplayinsetcreativeslot.c()).getItem()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, null));
}
return;
}
@@ -1526,47 +1475,47 @@ public class PlayerConnection extends Connection {
if (flag1 && flag2 && flag3) {
if (itemstack == null) {
- this.player.defaultContainer.setItem(packet107setcreativeslot.slot, (ItemStack) null);
+ this.player.defaultContainer.setItem(packetplayinsetcreativeslot.c(), (ItemStack) null);
} else {
- this.player.defaultContainer.setItem(packet107setcreativeslot.slot, itemstack);
+ this.player.defaultContainer.setItem(packetplayinsetcreativeslot.c(), itemstack);
}
this.player.defaultContainer.a(this.player, true);
} else if (flag && flag2 && flag3 && this.x < 200) {
this.x += 20;
- EntityItem entityitem = this.player.drop(itemstack);
+ EntityItem entityitem = this.player.drop(itemstack, true);
if (entityitem != null) {
- entityitem.c();
+ entityitem.e();
}
}
}
}
- public void a(Packet106Transaction packet106transaction) {
+ public void a(PacketPlayInTransaction packetplayintransaction) {
if (this.player.dead) return; // CraftBukkit
- Short oshort = (Short) this.r.get(this.player.activeContainer.windowId);
+ Short oshort = (Short) this.n.get(this.player.activeContainer.windowId);
- if (oshort != null && packet106transaction.b == oshort.shortValue() && this.player.activeContainer.windowId == packet106transaction.a && !this.player.activeContainer.c(this.player)) {
+ if (oshort != null && packetplayintransaction.d() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.c() && !this.player.activeContainer.c(this.player)) {
this.player.activeContainer.a(this.player, true);
}
}
- public void a(Packet130UpdateSign packet130updatesign) {
+ public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
if (this.player.dead) return; // CraftBukkit
- this.player.u();
+ this.player.w();
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
- if (worldserver.isLoaded(packet130updatesign.x, packet130updatesign.y, packet130updatesign.z)) {
- TileEntity tileentity = worldserver.getTileEntity(packet130updatesign.x, packet130updatesign.y, packet130updatesign.z);
+ if (worldserver.isLoaded(packetplayinupdatesign.c(), packetplayinupdatesign.d(), packetplayinupdatesign.e())) {
+ TileEntity tileentity = worldserver.getTileEntity(packetplayinupdatesign.c(), packetplayinupdatesign.d(), packetplayinupdatesign.e());
if (tileentity instanceof TileEntitySign) {
TileEntitySign tileentitysign = (TileEntitySign) tileentity;
if (!tileentitysign.a() || tileentitysign.b() != this.player) {
this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
- this.sendPacket(new Packet130UpdateSign(packet130updatesign.x, packet130updatesign.y, packet130updatesign.z, tileentitysign.lines)); // CraftBukkit
+ this.sendPacket(new PacketPlayOutUpdateSign(packetplayinupdatesign.c(), packetplayinupdatesign.d(), packetplayinupdatesign.e(), tileentitysign.lines)); // CraftBukkit
return;
}
}
@@ -1577,31 +1526,31 @@ public class PlayerConnection extends Connection {
for (j = 0; j < 4; ++j) {
boolean flag = true;
- if (packet130updatesign.lines[j].length() > 15) {
+ if (packetplayinupdatesign.f()[j].length() > 15) {
flag = false;
} else {
- for (i = 0; i < packet130updatesign.lines[j].length(); ++i) {
- if (SharedConstants.allowedCharacters.indexOf(packet130updatesign.lines[j].charAt(i)) < 0) {
+ for (i = 0; i < packetplayinupdatesign.f()[j].length(); ++i) {
+ if (!SharedConstants.isAllowedChatCharacter(packetplayinupdatesign.f()[j].charAt(i))) {
flag = false;
}
}
}
if (!flag) {
- packet130updatesign.lines[j] = "!?";
+ packetplayinupdatesign.f()[j] = "!?";
}
}
if (tileentity instanceof TileEntitySign) {
- j = packet130updatesign.x;
- int k = packet130updatesign.y;
+ j = packetplayinupdatesign.c();
+ int k = packetplayinupdatesign.d();
- i = packet130updatesign.z;
+ i = packetplayinupdatesign.e();
TileEntitySign tileentitysign1 = (TileEntitySign) tileentity;
// CraftBukkit start
Player player = this.server.getPlayer(this.player);
- SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(j, k, i), this.server.getPlayer(this.player), packet130updatesign.lines);
+ SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(j, k, i), this.server.getPlayer(this.player), packetplayinupdatesign.f());
this.server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@@ -1613,6 +1562,7 @@ public class PlayerConnection extends Connection {
}
tileentitysign1.isEditable = false;
}
+ // System.arraycopy(packetplayinupdatesign.f(), 0, tileentitysign1.lines, 0, 4);
// CraftBukkit end
tileentitysign1.update();
@@ -1621,25 +1571,25 @@ public class PlayerConnection extends Connection {
}
}
- public void a(Packet0KeepAlive packet0keepalive) {
- if (packet0keepalive.a == this.h) {
- int i = (int) (System.nanoTime() / 1000000L - this.i);
+ public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
+ if (packetplayinkeepalive.c() == this.h) {
+ int i = (int) (this.d() - this.i);
this.player.ping = (this.player.ping * 3 + i) / 4;
}
}
- public boolean a() {
- return true;
+ private long d() {
+ return System.nanoTime() / 1000000L;
}
- public void a(Packet202Abilities packet202abilities) {
+ public void a(PacketPlayInAbilities packetplayinabilities) {
// CraftBukkit start
- if (this.player.abilities.canFly && this.player.abilities.isFlying != packet202abilities.f()) {
- PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(this.server.getPlayer(this.player), packet202abilities.f());
+ if (this.player.abilities.canFly && this.player.abilities.isFlying != packetplayinabilities.f()) {
+ PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(this.server.getPlayer(this.player), packetplayinabilities.f());
this.server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
- this.player.abilities.isFlying = packet202abilities.f(); // Actually set the player's flying status
+ this.player.abilities.isFlying = packetplayinabilities.f(); // Actually set the player's flying status
}
else {
this.player.updateAbilities(); // Tell the player their ability was reverted
@@ -1648,78 +1598,74 @@ public class PlayerConnection extends Connection {
// CraftBukkit end
}
- public void a(Packet203TabComplete packet203tabcomplete) {
- StringBuilder stringbuilder = new StringBuilder();
+ public void a(PacketPlayInTabComplete packetplayintabcomplete) {
+ ArrayList arraylist = Lists.newArrayList();
+ Iterator iterator = this.minecraftServer.a(this.player, packetplayintabcomplete.c()).iterator();
- String s;
+ while (iterator.hasNext()) {
+ String s = (String) iterator.next();
- for (Iterator iterator = this.minecraftServer.a(this.player, packet203tabcomplete.d()).iterator(); iterator.hasNext(); stringbuilder.append(s)) {
- s = (String) iterator.next();
- if (stringbuilder.length() > 0) {
- stringbuilder.append('\0'); // CraftBukkit - fix decompile issue
- }
+ arraylist.add(s);
}
- this.player.playerConnection.sendPacket(new Packet203TabComplete(stringbuilder.toString()));
+ this.player.playerConnection.sendPacket(new PacketPlayOutTabComplete((String[]) arraylist.toArray(new String[arraylist.size()])));
}
- public void a(Packet204LocaleAndViewDistance packet204localeandviewdistance) {
- this.player.a(packet204localeandviewdistance);
+ public void a(PacketPlayInSettings packetplayinsettings) {
+ this.player.a(packetplayinsettings);
}
- public void a(Packet250CustomPayload packet250custompayload) {
- DataInputStream datainputstream;
+ public void a(PacketPlayInCustomPayload packetplayincustompayload) {
ItemStack itemstack;
ItemStack itemstack1;
// CraftBukkit start - Ignore empty payloads
- if (packet250custompayload.length <= 0) {
+ if (packetplayincustompayload.length <= 0) {
return;
}
// CraftBukkit end
- if ("MC|BEdit".equals(packet250custompayload.tag)) {
+ if ("MC|BEdit".equals(packetplayincustompayload.c())) {
try {
- datainputstream = new DataInputStream(new ByteArrayInputStream(packet250custompayload.data));
- itemstack = Packet.c(datainputstream);
+ itemstack = (new PacketDataSerializer(Unpooled.wrappedBuffer(packetplayincustompayload.e()))).c();
if (!ItemBookAndQuill.a(itemstack.getTag())) {
throw new IOException("Invalid book tag!");
}
itemstack1 = this.player.inventory.getItemInHand();
- if (itemstack != null && itemstack.id == Item.BOOK_AND_QUILL.id && itemstack.id == itemstack1.id) {
+ if (itemstack.getItem() == Items.BOOK_AND_QUILL && itemstack.getItem() == itemstack1.getItem()) {
CraftEventFactory.handleEditBookEvent(player, itemstack); // CraftBukkit
}
// CraftBukkit start
- } catch (Throwable exception) {
- this.minecraftServer.getLogger().warning(this.player.getName() + " sent invalid MC|BEdit data", exception);
+ } catch (Exception exception) {
+ c.error("Couldn\'t handle book info", exception);
this.disconnect("Invalid book data!");
// CraftBukkit end
}
- } else if ("MC|BSign".equals(packet250custompayload.tag)) {
+ } else if ("MC|BSign".equals(packetplayincustompayload.c())) {
try {
- datainputstream = new DataInputStream(new ByteArrayInputStream(packet250custompayload.data));
- itemstack = Packet.c(datainputstream);
+ itemstack = (new PacketDataSerializer(Unpooled.wrappedBuffer(packetplayincustompayload.e()))).c();
if (!ItemWrittenBook.a(itemstack.getTag())) {
throw new IOException("Invalid book tag!");
}
itemstack1 = this.player.inventory.getItemInHand();
- if (itemstack != null && itemstack.id == Item.WRITTEN_BOOK.id && itemstack1.id == Item.BOOK_AND_QUILL.id) {
+ if (itemstack.getItem() == Items.WRITTEN_BOOK && itemstack1.getItem() == Items.BOOK_AND_QUILL) {
CraftEventFactory.handleEditBookEvent(player, itemstack); // CraftBukkit
}
// CraftBukkit start
- } catch (Throwable exception1) {
- this.minecraftServer.getLogger().warning(this.player.getName() + " sent invalid MC|BSign data", exception1);
+ } catch (Exception exception1) {
+ c.error("Couldn\'t sign book", exception1);
this.disconnect("Invalid book data!");
// CraftBukkit end
}
} else {
+ DataInputStream datainputstream;
int i;
- if ("MC|TrSel".equals(packet250custompayload.tag)) {
+ if ("MC|TrSel".equals(packetplayincustompayload.c())) {
try {
- datainputstream = new DataInputStream(new ByteArrayInputStream(packet250custompayload.data));
+ datainputstream = new DataInputStream(new ByteArrayInputStream(packetplayincustompayload.e()));
i = datainputstream.readInt();
Container container = this.player.activeContainer;
@@ -1728,104 +1674,121 @@ public class PlayerConnection extends Connection {
}
} catch (Exception exception2) {
// CraftBukkit start
- this.minecraftServer.getLogger().warning(this.player.getName() + " sent invalid MC|TrSel data", exception2);
+ c.error("Couldn\'t select trade", exception2);
this.disconnect("Invalid trade data!");
// CraftBukkit end
}
- } else {
- int j;
+ } else if ("MC|AdvCdm".equals(packetplayincustompayload.c())) {
+ if (!this.minecraftServer.getEnableCommandBlock()) {
+ this.player.sendMessage(new ChatMessage("advMode.notEnabled", new Object[0]));
+ } else if (this.player.a(2, "") && this.player.abilities.canInstantlyBuild) {
+ try {
+ PacketDataSerializer packetdataserializer = new PacketDataSerializer(Unpooled.wrappedBuffer(packetplayincustompayload.e()));
+ byte b0 = packetdataserializer.readByte();
+ CommandBlockListenerAbstract commandblocklistenerabstract = null;
- if ("MC|AdvCdm".equals(packet250custompayload.tag)) {
- if (!this.minecraftServer.getEnableCommandBlock()) {
- this.player.sendMessage(ChatMessage.e("advMode.notEnabled"));
- } else if (this.player.a(2, "") && this.player.abilities.canInstantlyBuild) {
- try {
- datainputstream = new DataInputStream(new ByteArrayInputStream(packet250custompayload.data));
- i = datainputstream.readInt();
- j = datainputstream.readInt();
- int k = datainputstream.readInt();
- String s = Packet.a((DataInput) datainputstream, 256);
- TileEntity tileentity = this.player.world.getTileEntity(i, j, k);
-
- if (tileentity != null && tileentity instanceof TileEntityCommand) {
- ((TileEntityCommand) tileentity).a(s);
- this.player.world.notify(i, j, k);
- this.player.sendMessage(ChatMessage.b("advMode.setCommand.success", new Object[] { s}));
+ if (b0 == 0) {
+ TileEntity tileentity = this.player.world.getTileEntity(packetdataserializer.readInt(), packetdataserializer.readInt(), packetdataserializer.readInt());
+
+ if (tileentity instanceof TileEntityCommand) {
+ commandblocklistenerabstract = ((TileEntityCommand) tileentity).a();
}
- } catch (Exception exception3) {
- // CraftBukkit start
- this.minecraftServer.getLogger().warning(this.player.getName() + " sent invalid MC|AdvCdm data", exception3);
- this.disconnect("Invalid CommandBlock data!");
- // CraftBukkit end
- }
- } else {
- this.player.sendMessage(ChatMessage.e("advMode.notAllowed"));
- }
- } else if ("MC|Beacon".equals(packet250custompayload.tag)) {
- if (this.player.activeContainer instanceof ContainerBeacon) {
- try {
- datainputstream = new DataInputStream(new ByteArrayInputStream(packet250custompayload.data));
- i = datainputstream.readInt();
- j = datainputstream.readInt();
- ContainerBeacon containerbeacon = (ContainerBeacon) this.player.activeContainer;
- Slot slot = containerbeacon.getSlot(0);
-
- if (slot.e()) {
- slot.a(1);
- TileEntityBeacon tileentitybeacon = containerbeacon.e();
-
- tileentitybeacon.d(i);
- tileentitybeacon.e(j);
- tileentitybeacon.update();
+ } else if (b0 == 1) {
+ Entity entity = this.player.world.getEntity(packetdataserializer.readInt());
+
+ if (entity instanceof EntityMinecartCommandBlock) {
+ commandblocklistenerabstract = ((EntityMinecartCommandBlock) entity).e();
}
- } catch (Exception exception4) {
- // CraftBukkit start
- this.minecraftServer.getLogger().warning(this.player.getName() + " sent invalid MC|Beacon data", exception4);
- this.disconnect("Invalid beacon data!");
- // CraftBukkit end
}
- }
- } else if ("MC|ItemName".equals(packet250custompayload.tag) && this.player.activeContainer instanceof ContainerAnvil) {
- ContainerAnvil containeranvil = (ContainerAnvil) this.player.activeContainer;
- if (packet250custompayload.data != null && packet250custompayload.data.length >= 1) {
- String s1 = SharedConstants.a(new String(packet250custompayload.data));
+ String s = packetdataserializer.c(packetdataserializer.readableBytes());
- if (s1.length() <= 30) {
- containeranvil.a(s1);
+ if (commandblocklistenerabstract != null) {
+ commandblocklistenerabstract.a(s);
+ commandblocklistenerabstract.e();
+ this.player.sendMessage(new ChatMessage("advMode.setCommand.success", new Object[] { s}));
}
- } else {
- containeranvil.a("");
+ } catch (Exception exception3) {
+ // CraftBukkit start
+ c.error("Couldn\'t set command block", exception3);
+ this.disconnect("Invalid CommandBlock data!");
+ // CraftBukkit end
}
+ } else {
+ this.player.sendMessage(new ChatMessage("advMode.notAllowed", new Object[0]));
}
- // CraftBukkit start
- else if (packet250custompayload.tag.equals("REGISTER")) {
+ } else if ("MC|Beacon".equals(packetplayincustompayload.c())) {
+ if (this.player.activeContainer instanceof ContainerBeacon) {
try {
- String channels = new String(packet250custompayload.data, "UTF8");
- for (String channel : channels.split("\0")) {
- getPlayer().addChannel(channel);
+ datainputstream = new DataInputStream(new ByteArrayInputStream(packetplayincustompayload.e()));
+ i = datainputstream.readInt();
+ int j = datainputstream.readInt();
+ ContainerBeacon containerbeacon = (ContainerBeacon) this.player.activeContainer;
+ Slot slot = containerbeacon.getSlot(0);
+
+ if (slot.e()) {
+ slot.a(1);
+ TileEntityBeacon tileentitybeacon = containerbeacon.e();
+
+ tileentitybeacon.d(i);
+ tileentitybeacon.e(j);
+ tileentitybeacon.update();
}
- } catch (UnsupportedEncodingException ex) {
- throw new AssertionError(ex);
+ } catch (Exception exception4) {
+ // CraftBukkit start
+ c.error("Couldn\'t set beacon", exception4);
+ this.disconnect("Invalid beacon data!");
+ // CraftBukkit end
}
- } else if (packet250custompayload.tag.equals("UNREGISTER")) {
- try {
- String channels = new String(packet250custompayload.data, "UTF8");
- for (String channel : channels.split("\0")) {
- getPlayer().removeChannel(channel);
- }
- } catch (UnsupportedEncodingException ex) {
- throw new AssertionError(ex);
+ }
+ } else if ("MC|ItemName".equals(packetplayincustompayload.c()) && this.player.activeContainer instanceof ContainerAnvil) {
+ ContainerAnvil containeranvil = (ContainerAnvil) this.player.activeContainer;
+
+ if (packetplayincustompayload.e() != null && packetplayincustompayload.e().length >= 1) {
+ String s1 = SharedConstants.a(new String(packetplayincustompayload.e(), Charsets.UTF_8));
+
+ if (s1.length() <= 30) {
+ containeranvil.a(s1);
}
} else {
- server.getMessenger().dispatchIncomingMessage(player.getBukkitEntity(), packet250custompayload.tag, packet250custompayload.data);
+ containeranvil.a("");
}
- // CraftBukkit end
}
+ // CraftBukkit start
+ else if (packetplayincustompayload.c().equals("REGISTER")) {
+ try {
+ String channels = new String(packetplayincustompayload.e(), "UTF8");
+ for (String channel : channels.split("\0")) {
+ getPlayer().addChannel(channel);
+ }
+ } catch (UnsupportedEncodingException ex) {
+ throw new AssertionError(ex);
+ }
+ } else if (packetplayincustompayload.c().equals("UNREGISTER")) {
+ try {
+ String channels = new String(packetplayincustompayload.e(), "UTF8");
+ for (String channel : channels.split("\0")) {
+ getPlayer().removeChannel(channel);
+ }
+ } catch (UnsupportedEncodingException ex) {
+ throw new AssertionError(ex);
+ }
+ } else {
+ server.getMessenger().dispatchIncomingMessage(player.getBukkitEntity(), packetplayincustompayload.c(), packetplayincustompayload.e());
+ }
+ // CraftBukkit end
}
}
- public boolean c() {
- return this.disconnected;
+ public void a(EnumProtocol enumprotocol, EnumProtocol enumprotocol1) {
+ if (enumprotocol1 != EnumProtocol.PLAY) {
+ throw new IllegalStateException("Unexpected change in protocol!");
+ }
}
+
+ // CraftBukkit start - Add "isDisconnected" method
+ public final boolean isDisconnected() {
+ return !NetworkManager.a(this.networkManager).config().isAutoRead();
+ }
+ // CraftBukkit end
}