3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-17 21:40:08 +01:00
Paper/src/main/java/net/minecraft/server/NetServerHandler.java

902 Zeilen
35 KiB
Java

package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
// CraftBukkit start
2011-02-23 13:56:36 +01:00
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandException;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
2011-03-24 23:27:40 +01:00
import org.bukkit.event.Event;
import org.bukkit.event.block.*;
import org.bukkit.event.player.*;
// CraftBukkit end
public class NetServerHandler extends NetHandler implements ICommandListener {
private static final int PLACE_DISTANCE_SQUARED = 6 * 6; // CraftBukkit here for now
public static Logger a = Logger.getLogger("Minecraft");
public NetworkManager networkManager;
public boolean disconnected = false;
private MinecraftServer minecraftServer;
public EntityPlayer player; // CraftBukkit - private->public
2011-02-23 03:37:56 +01:00
private int f;
private int g;
2011-04-20 22:47:26 +02:00
private int h;
private boolean i;
private double x;
private double y;
private double z;
2011-04-20 22:47:26 +02:00
private boolean m = true;
private Map n = new HashMap();
2011-01-29 22:50:29 +01:00
public NetServerHandler(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
this.minecraftServer = minecraftserver;
this.networkManager = networkmanager;
2011-01-29 22:50:29 +01:00
networkmanager.a((NetHandler) this);
this.player = entityplayer;
entityplayer.netServerHandler = this;
2011-01-29 22:50:29 +01:00
// CraftBukkit start
server = minecraftserver.server;
}
private final CraftServer server;
2011-01-29 22:50:29 +01:00
// 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;
// For the packet15 hack :(
Long lastPacket;
2011-01-29 22:50:29 +01:00
// Store the last block right clicked and what type it was
private int lastMaterial;
2011-04-20 22:47:26 +02:00
public Player getPlayer() {
return (this.player == null) ? null : (CraftPlayer) player.getBukkitEntity();
}
// CraftBukkit end
public void a() {
2011-04-20 22:47:26 +02:00
this.i = false;
this.networkManager.a();
2011-02-23 03:37:56 +01:00
if (this.f - this.g > 20) {
this.sendPacket(new Packet0KeepAlive());
}
}
public void disconnect(String s) {
// CraftBukkit start
String leaveMessage = "\u00A7e" + this.player.name + " left the game.";
PlayerKickEvent event = new PlayerKickEvent(server.getPlayer(this.player), s, leaveMessage);
2011-02-23 13:56:36 +01:00
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
// Do not kick the player
return;
}
// Send the possibly modified leave message
this.sendPacket(new Packet255KickDisconnect( event.getReason() ));
this.networkManager.c();
leaveMessage = event.getLeaveMessage();
if (leaveMessage != null) {
this.minecraftServer.serverConfigurationManager.sendAll(new Packet3Chat(leaveMessage));
}
2011-02-23 03:37:56 +01:00
// CraftBukkit end
this.minecraftServer.serverConfigurationManager.disconnect(this.player);
this.disconnected = true;
}
2011-02-23 03:37:56 +01:00
public void a(Packet27 packet27) {
this.player.a(packet27.c(), packet27.e(), packet27.g(), packet27.h(), packet27.d(), packet27.f());
2011-02-23 03:37:56 +01:00
}
public void a(Packet10Flying packet10flying) {
2011-04-20 22:47:26 +02:00
this.i = true;
2011-01-29 22:50:29 +01:00
double d0;
2011-04-20 22:47:26 +02:00
if (!this.m) {
d0 = packet10flying.y - this.y;
if (packet10flying.x == this.x && d0 * d0 < 0.01D && packet10flying.z == this.z) {
2011-04-20 22:47:26 +02:00
this.m = true;
}
}
// CraftBukkit start
Player player = getPlayer();
Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch);
Location to = player.getLocation();
// Prevent 40 event-calls for less than a single pixel of movement >.>
double delta = Math.pow( this.lastPosX - this.x, 2) + Math.pow( this.lastPosY - this.y, 2) + Math.pow( this.lastPosZ - this.z, 2);
float deltaAngle = Math.abs(this.lastYaw - this.player.yaw) + Math.abs(this.lastPitch - this.player.pitch);
if (delta > 1f/256 || deltaAngle > 10f) {
// Skip the first time we do this
if (lastPosX != Double.MAX_VALUE) {
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
server.getPluginManager().callEvent(event);
2011-03-27 00:34:33 +01:00
from = event.getFrom();
to = event.isCancelled() ? from : event.getTo();
this.player.locX = to.getX();
this.player.locY = to.getY();
this.player.locZ = to.getZ();
this.player.yaw = to.getYaw();
this.player.pitch = to.getPitch();
}
this.lastPosX = this.player.locX;
this.lastPosY = this.player.locY;
this.lastPosZ = this.player.locZ;
this.lastYaw = this.player.yaw;
this.lastPitch = this.player.pitch;
}
if (Math.abs(packet10flying.x) > 32000000 || Math.abs(packet10flying.z) > 32000000) {
System.err.println(player.getName() + " was caught trying to crash the server with an invalid position.");
player.kickPlayer("Nope!");
return;
}
if (Double.isNaN(packet10flying.x) || packet10flying.x == Double.POSITIVE_INFINITY || packet10flying.x == Double.NEGATIVE_INFINITY) {
System.err.println(player.getName() + " was caught trying to set an invalid position.");
player.kickPlayer("Nope!");
return;
}
if (Double.isNaN(packet10flying.y) || packet10flying.y == Double.POSITIVE_INFINITY || packet10flying.y == Double.NEGATIVE_INFINITY) {
System.err.println(player.getName() + " was caught trying to set an invalid position.");
player.kickPlayer("Nope!");
return;
}
if (Double.isNaN(packet10flying.z) || packet10flying.z == Double.POSITIVE_INFINITY || packet10flying.z == Double.NEGATIVE_INFINITY) {
System.err.println(player.getName() + " was caught trying to set an invalid position.");
player.kickPlayer("Nope!");
return;
}
if (Double.isNaN(packet10flying.stance) || packet10flying.stance == Double.POSITIVE_INFINITY || packet10flying.stance == Double.NEGATIVE_INFINITY) {
System.err.println(player.getName() + " was caught trying to set an invalid position.");
player.kickPlayer("Nope!");
return;
}
// CraftBukkit end
2011-04-20 22:47:26 +02:00
if (this.m) {
2011-01-29 22:50:29 +01:00
double d1;
double d2;
double d3;
double d4;
if (this.player.vehicle != null) {
float f = this.player.yaw;
float f1 = this.player.pitch;
2011-04-20 22:47:26 +02:00
this.player.vehicle.f();
d1 = this.player.locX;
d2 = this.player.locY;
d3 = this.player.locZ;
2011-01-29 22:50:29 +01:00
double d5 = 0.0D;
d4 = 0.0D;
if (packet10flying.hasLook) {
f = packet10flying.yaw;
f1 = packet10flying.pitch;
}
2011-01-29 22:50:29 +01:00
if (packet10flying.h && packet10flying.y == -999.0D && packet10flying.stance == -999.0D) {
d5 = packet10flying.x;
d4 = packet10flying.z;
}
2011-01-29 22:50:29 +01:00
this.player.onGround = packet10flying.g;
this.player.a(true);
this.player.move(d5, 0.0D, d4);
this.player.setLocation(d1, d2, d3, f, f1);
this.player.motX = d5;
this.player.motZ = d4;
if (this.player.vehicle != null) {
2011-02-23 13:56:36 +01:00
// CraftBukkit
((WorldServer) this.player.world).vehicleEnteredWorld(this.player.vehicle, true);
}
2011-01-29 22:50:29 +01:00
if (this.player.vehicle != null) {
2011-04-20 22:47:26 +02:00
this.player.vehicle.f();
}
2011-01-29 22:50:29 +01:00
this.minecraftServer.serverConfigurationManager.b(this.player);
this.x = this.player.locX;
this.y = this.player.locY;
this.z = this.player.locZ;
2011-02-23 13:56:36 +01:00
// CraftBukkit
((WorldServer) this.player.world).playerJoinedWorld(this.player);
return;
}
d0 = this.player.locY;
this.x = this.player.locX;
this.y = this.player.locY;
this.z = 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;
2011-01-29 22:50:29 +01:00
if (packet10flying.h && packet10flying.y == -999.0D && packet10flying.stance == -999.0D) {
packet10flying.h = false;
}
2011-01-29 22:50:29 +01:00
if (packet10flying.h) {
d1 = packet10flying.x;
d2 = packet10flying.y;
d3 = packet10flying.z;
d4 = packet10flying.stance - packet10flying.y;
2011-04-20 22:47:26 +02:00
if (!this.player.isSleeping() && (d4 > 1.65D || d4 < 0.1D)) {
this.disconnect("Illegal stance");
a.warning(this.player.name + " had an illegal stance: " + d4);
2011-04-20 22:47:26 +02:00
return;
}
if (Math.abs(packet10flying.x) > 3.2E7D || Math.abs(packet10flying.z) > 3.2E7D) {
this.disconnect("Illegal position");
return;
}
}
2011-01-29 22:50:29 +01:00
2011-04-20 22:47:26 +02:00
if (packet10flying.hasLook) {
f2 = packet10flying.yaw;
f3 = packet10flying.pitch;
}
this.player.a(true);
this.player.bn = 0.0F;
this.player.setLocation(this.x, this.y, this.z, f2, f3);
d4 = d1 - this.player.locX;
double d6 = d2 - this.player.locY;
double d7 = d3 - this.player.locZ;
double d8 = d4 * d4 + d6 * d6 + d7 * d7;
2011-04-20 22:47:26 +02:00
if (d8 > 100.0D) {
a.warning(this.player.name + " moved too quickly!");
this.disconnect("You moved too quickly :( (Hacking?)");
return;
}
2011-01-29 22:50:29 +01:00
2011-04-20 22:47:26 +02:00
float f4 = 0.0625F;
// CraftBukkit
boolean flag = ((WorldServer) this.player.world).getEntities(this.player, this.player.boundingBox.clone().shrink((double) f4, (double) f4, (double) f4)).size() == 0;
this.player.move(d4, d6, d7);
d4 = d1 - this.player.locX;
d6 = d2 - this.player.locY;
2011-01-29 22:50:29 +01:00
if (d6 > -0.5D || d6 < 0.5D) {
d6 = 0.0D;
}
d7 = d3 - this.player.locZ;
2011-04-20 22:47:26 +02:00
d8 = d4 * d4 + d6 * d6 + d7 * d7;
boolean flag1 = false;
2011-04-20 22:47:26 +02:00
if (d8 > 0.0625D && !this.player.isSleeping()) {
flag1 = true;
a.warning(this.player.name + " moved wrongly!");
System.out.println("Got position " + d1 + ", " + d2 + ", " + d3);
System.out.println("Expected " + this.player.locX + ", " + this.player.locY + ", " + this.player.locZ);
}
2011-01-29 22:50:29 +01:00
this.player.setLocation(d1, d2, d3, f2, f3);
2011-02-23 13:56:36 +01:00
// CraftBukkit
boolean flag2 = ((WorldServer) this.player.world).getEntities(this.player, this.player.boundingBox.clone().shrink((double) f4, (double) f4, (double) f4)).size() == 0;
if (flag && (flag1 || !flag2) && !this.player.isSleeping()) {
this.a(this.x, this.y, this.z, f2, f3);
return;
}
2011-01-29 22:50:29 +01:00
2011-04-20 22:47:26 +02:00
AxisAlignedBB axisalignedbb = this.player.boundingBox.clone().b((double) f4, (double) f4, (double) f4).a(0.0D, -0.55D, 0.0D);
// CraftBukkit
if (!this.minecraftServer.o && !((WorldServer) this.player.world).b(axisalignedbb)) {
if (d6 >= -0.03125D) {
++this.h;
if (this.h > 80) {
a.warning(this.player.name + " was kicked for floating too long!");
this.disconnect("Flying is not enabled on this server");
return;
}
}
} else {
this.h = 0;
}
this.player.onGround = packet10flying.g;
this.minecraftServer.serverConfigurationManager.b(this.player);
this.player.b(this.player.locY - d0, packet10flying.g);
}
}
2011-03-23 18:42:36 +01:00
public void a(double d0, double d1, double d2, float f, float f1) {
// CraftBukkit start -- Delegate to teleport(Location)
teleport(new Location(getPlayer().getWorld(), d0, d1, d2, f, f1));
}
public boolean teleport(Location dest) {
// Note: the world in location is used only for the event
// Inter-world teleportation is handled in CraftPlayer.teleport()
Player player = getPlayer();
Location from = player.getLocation();
Location to = dest.clone();
2011-03-27 00:34:33 +01:00
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
server.getPluginManager().callEvent(event);
from = event.getFrom();
to = event.isCancelled() ? from : event.getTo();
double d0, d1, d2;
float f, f1;
2011-01-29 22:50:29 +01:00
d0 = to.getX();
d1 = to.getY();
d2 = to.getZ();
f = to.getYaw();
f1 = to.getPitch();
2011-03-23 18:42:36 +01:00
// CraftBukkit end
2011-04-20 22:47:26 +02:00
this.m = false;
this.x = d0;
this.y = d1;
this.z = d2;
this.player.setLocation(d0, d1, d2, f, f1);
this.player.netServerHandler.sendPacket(new Packet13PlayerLookMove(d0, d1 + 1.6200000047683716D, d1, d2, f, f1, false));
2011-03-23 18:42:36 +01:00
// CraftBukkit -- Returns TRUE if the teleport was successful
return !event.isCancelled();
}
public void a(Packet14BlockDig packet14blockdig) {
if (packet14blockdig.e == 4) {
2011-04-20 22:47:26 +02:00
this.player.C();
2011-01-29 22:50:29 +01:00
} else {
2011-02-23 13:56:36 +01:00
// CraftBukkit
boolean flag = ((WorldServer) this.player.world).weirdIsOpCache = this.minecraftServer.serverConfigurationManager.isOp(this.player.name);
2011-01-29 22:50:29 +01:00
boolean flag1 = false;
2011-01-29 22:50:29 +01:00
if (packet14blockdig.e == 0) {
flag1 = true;
}
2011-02-23 03:37:56 +01:00
if (packet14blockdig.e == 2) {
2011-01-29 22:50:29 +01:00
flag1 = true;
}
2011-01-29 22:50:29 +01:00
int i = packet14blockdig.a;
int j = packet14blockdig.b;
int k = packet14blockdig.c;
if (flag1) {
double d0 = this.player.locX - ((double) i + 0.5D);
double d1 = this.player.locY - ((double) j + 0.5D);
double d2 = this.player.locZ - ((double) k + 0.5D);
2011-01-29 22:50:29 +01:00
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
if (d3 > 36.0D) {
return;
}
}
2011-02-23 13:56:36 +01:00
// CraftBukkit
ChunkCoordinates chunkcoordinates = ((WorldServer) this.player.world).getSpawn();
int l = (int) MathHelper.abs((float) (i - chunkcoordinates.x));
int i1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z));
2011-02-23 03:37:56 +01:00
if (l > i1) {
i1 = l;
2011-01-29 22:50:29 +01:00
}
2011-01-10 02:36:19 +01:00
2011-01-29 22:50:29 +01:00
if (packet14blockdig.e == 0) {
2011-03-23 16:38:42 +01:00
// CraftBukkit
if (i1 > this.minecraftServer.spawnProtection || flag) {
2011-03-26 09:56:16 +01:00
// CraftBukkit add face argument
this.player.itemInWorldManager.dig(i, j, k, packet14blockdig.face);
2011-01-29 22:50:29 +01:00
}
} else if (packet14blockdig.e == 2) {
this.player.itemInWorldManager.b(i, j, k);
2011-01-29 22:50:29 +01:00
} else if (packet14blockdig.e == 3) {
double d4 = this.player.locX - ((double) i + 0.5D);
double d5 = this.player.locY - ((double) j + 0.5D);
double d6 = this.player.locZ - ((double) k + 0.5D);
2011-02-23 03:37:56 +01:00
double d7 = d4 * d4 + d5 * d5 + d6 * d6;
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
if (d7 < 256.0D) {
2011-02-23 13:56:36 +01:00
// CraftBukkit
this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.player.world));
2011-01-10 02:36:19 +01:00
}
}
2011-03-23 16:38:42 +01:00
// CraftBukkit
((WorldServer) this.player.world).weirdIsOpCache = false;
2011-01-29 22:50:29 +01:00
}
}
public void a(Packet15Place packet15place) {
2011-03-24 12:11:28 +01:00
// CraftBukkit start
// This is a horrible hack needed because the client sends 2 packets on 'right mouse click'
// aimed at a block. We shouldn't need to get the second packet if the data is handled
// but we cannot know what the client will do, so we might still get it
//
// 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
2011-01-10 02:36:19 +01:00
if (packet15place.face == 255) {
if (packet15place.itemstack != null && packet15place.itemstack.id == lastMaterial && lastPacket != null && packet15place.timestamp - lastPacket < 100) {
lastPacket = null;
return;
}
} else {
lastMaterial = packet15place.itemstack == null ? -1 : packet15place.itemstack.id;
lastPacket = packet15place.timestamp;
}
2011-01-10 02:36:19 +01:00
// 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
2011-01-10 02:36:19 +01:00
ItemStack itemstack = this.player.inventory.getItemInHand();
// boolean flag = this.minecraftServer.worldServer.weirdIsOpCache = this.minecraftServer.serverConfigurationManager.isOp(this.player.name);
if (packet15place.face == 255) {
if (itemstack == null) {
return;
}
2011-01-10 02:36:19 +01:00
2011-03-24 12:11:28 +01:00
// CraftBukkit start
2011-03-24 23:27:40 +01:00
int itemstackAmount = itemstack.count;
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
if (event.useItemInHand() != Event.Result.DENY) {
this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack);
}
2011-03-24 23:27:40 +01:00
// CraftBukkit notch decrements the counter by 1 in the above method with food,
// snowballs and so forth, but he does it in a place that doesn't cause the
// inventory update packet to get sent
always = (itemstack.count != itemstackAmount);
// CraftBukkit end
} else {
2011-01-29 22:50:29 +01:00
int i = packet15place.a;
int j = packet15place.b;
int k = packet15place.c;
int l = packet15place.face;
ChunkCoordinates chunkcoordinates = ((WorldServer) this.player.world).getSpawn(); // CraftBukkit
int i1 = (int) MathHelper.abs((float) (i - chunkcoordinates.x));
int j1 = (int) MathHelper.abs((float) (k - chunkcoordinates.z));
2011-01-29 22:50:29 +01:00
if (i1 > j1) {
j1 = i1;
}
2011-01-29 22:50:29 +01:00
// CraftBukkit start - spawn protection moved to ItemBlock!!!
// Check if we can actually do something over this large a distance
Location eyeLoc = getPlayer().getEyeLocation();
if (Math.pow(eyeLoc.getX() - i, 2) + Math.pow(eyeLoc.getY() - j, 2) + Math.pow(eyeLoc.getZ() - k, 2) > PLACE_DISTANCE_SQUARED) {
return;
}
2011-01-10 02:36:19 +01:00
this.player.itemInWorldManager.interact(this.player, this.player.world, itemstack, i, j, k, l);
this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.player.world));
// CraftBukkit end
2011-01-29 22:50:29 +01:00
if (l == 0) {
--j;
}
2011-01-29 22:50:29 +01:00
if (l == 1) {
++j;
}
2011-01-29 22:50:29 +01:00
if (l == 2) {
--k;
}
2011-01-29 22:50:29 +01:00
if (l == 3) {
++k;
}
2011-01-29 22:50:29 +01:00
if (l == 4) {
--i;
}
2011-01-29 22:50:29 +01:00
if (l == 5) {
++i;
}
2011-01-29 22:50:29 +01:00
2011-02-23 13:56:36 +01:00
// CraftBukkit
this.player.netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.player.world));
}
2011-01-29 22:50:29 +01:00
if (itemstack != null && itemstack.count == 0) {
this.player.inventory.items[this.player.inventory.itemInHandIndex] = null;
}
this.player.h = true;
this.player.inventory.items[this.player.inventory.itemInHandIndex] = ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]);
Slot slot = this.player.activeContainer.a(this.player.inventory, this.player.inventory.itemInHandIndex);
2011-01-29 22:50:29 +01:00
this.player.activeContainer.a();
this.player.h = false;
if (!ItemStack.equals(this.player.inventory.getItemInHand(), packet15place.itemstack) || always) { // CraftBukkit
this.sendPacket(new Packet103SetSlot(this.player.activeContainer.f, slot.a, this.player.inventory.getItemInHand()));
}
2011-01-29 22:50:29 +01:00
2011-02-23 13:56:36 +01:00
// CraftBukkit
((WorldServer) this.player.world).weirdIsOpCache = false;
}
2011-01-10 02:36:19 +01:00
2011-01-29 22:50:29 +01:00
public void a(String s, Object[] aobject) {
if (this.disconnected) return; // CraftBukkit -- rarely it would send a disconnect line twice
a.info(this.player.name + " lost connection: " + s);
this.minecraftServer.serverConfigurationManager.sendAll(new Packet3Chat("\u00A7e" + this.player.name + " left the game."));
this.minecraftServer.serverConfigurationManager.disconnect(this.player);
this.disconnected = true;
}
public void a(Packet packet) {
2011-01-29 22:50:29 +01:00
a.warning(this.getClass() + " wasn\'t prepared to deal with a " + packet.getClass());
this.disconnect("Protocol error, unexpected packet");
}
public void sendPacket(Packet packet) {
2011-03-25 21:22:03 +01:00
// CraftBukkit
if (packet instanceof Packet6SpawnPosition) {
Packet6SpawnPosition packet6 = (Packet6SpawnPosition) packet;
this.player.compassTarget = new Location(getPlayer().getWorld(), packet6.x, packet6.y, packet6.z);
2011-03-25 21:22:03 +01:00
}
// CraftBukkit
this.networkManager.a(packet);
2011-02-23 03:37:56 +01:00
this.g = this.f;
}
public void a(Packet16BlockItemSwitch packet16blockitemswitch) {
if (packet16blockitemswitch.itemInHandIndex >= 0 && packet16blockitemswitch.itemInHandIndex <= InventoryPlayer.e()) {
// CraftBukkit start
PlayerItemHeldEvent event = new PlayerItemHeldEvent(getPlayer(), this.player.inventory.itemInHandIndex, packet16blockitemswitch.itemInHandIndex);
server.getPluginManager().callEvent(event);
// CraftBukkit end
this.player.inventory.itemInHandIndex = packet16blockitemswitch.itemInHandIndex;
} else {
a.warning(this.player.name + " tried to set an invalid carried item");
}
}
public void a(Packet3Chat packet3chat) {
String s = packet3chat.a;
if (s.length() > 100) {
this.disconnect("Chat message too long");
} else {
2011-01-29 22:50:29 +01:00
s = s.trim();
for (int i = 0; i < s.length(); ++i) {
if (FontAllowedCharacters.a.indexOf(s.charAt(i)) < 0) {
this.disconnect("Illegal characters in chat");
2011-01-29 22:50:29 +01:00
return;
}
2011-01-10 02:36:19 +01:00
}
2011-02-23 13:56:36 +01:00
// CraftBukkit start
chat(s);
2011-02-17 06:46:01 +01:00
}
}
2011-02-17 06:46:01 +01:00
public boolean chat(String msg) {
if (msg.startsWith("/")) {
this.handleCommand(msg);
2011-02-17 06:46:01 +01:00
return true;
} else {
// CraftBukkit start
Player player = getPlayer();
PlayerChatEvent event = new PlayerChatEvent(player, msg);
2011-02-17 06:46:01 +01:00
server.getPluginManager().callEvent(event);
2011-02-23 13:56:36 +01:00
2011-02-17 06:46:01 +01:00
if (event.isCancelled()) {
return true;
2011-01-29 22:50:29 +01:00
}
2011-02-17 06:46:01 +01:00
2011-02-23 13:56:36 +01:00
msg = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
2011-02-17 06:46:01 +01:00
a.info(msg);
2011-02-26 20:37:19 +01:00
for (Player recipient : event.getRecipients()) {
recipient.sendMessage(msg);
}
// CraftBukkit end
}
2011-02-17 06:46:01 +01:00
return false;
}
2011-02-17 06:46:01 +01:00
// CraftBukkit end
private void handleCommand(String s) {
// CraftBukkit start
2011-04-20 22:47:26 +02:00
CraftPlayer player = (CraftPlayer) getPlayer();
2011-01-29 22:50:29 +01:00
2011-03-27 00:34:33 +01:00
PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s);
server.getPluginManager().callEvent(event);
2011-01-10 02:36:19 +01:00
if (event.isCancelled()) {
return;
}
boolean targetPluginFound = false;
try {
targetPluginFound = server.dispatchCommand(player, s.substring(1));
} catch (CommandException ex) {
player.sendMessage(ChatColor.RED + "An internal error occured while attempting to perform this command");
Logger.getLogger(NetServerHandler.class.getName()).log(Level.SEVERE, null, ex);
return;
}
2011-02-17 06:46:01 +01:00
if (targetPluginFound) {
return;
}
// CraftBukkit stop
if (s.toLowerCase().startsWith("/me ")) {
s = "* " + this.player.name + " " + s.substring(s.indexOf(" ")).trim();
a.info(s);
this.minecraftServer.serverConfigurationManager.sendAll(new Packet3Chat(s));
} else if (s.toLowerCase().startsWith("/kill")) {
this.player.damageEntity((Entity) null, 1000);
} else if (s.toLowerCase().startsWith("/tell ")) {
2011-01-29 22:50:29 +01:00
String[] astring = s.split(" ");
2011-01-29 22:50:29 +01:00
if (astring.length >= 3) {
s = s.substring(s.indexOf(" ")).trim();
s = s.substring(s.indexOf(" ")).trim();
s = "\u00A77" + this.player.name + " whispers " + s;
2011-01-29 22:50:29 +01:00
a.info(s + " to " + astring[1]);
if (!this.minecraftServer.serverConfigurationManager.a(astring[1], (Packet) (new Packet3Chat(s)))) {
this.sendPacket(new Packet3Chat("\u00A7cThere\'s no player by that name online."));
}
}
} else {
2011-01-29 22:50:29 +01:00
String s1;
if (this.minecraftServer.serverConfigurationManager.isOp(this.player.name)) {
2011-01-29 22:50:29 +01:00
s1 = s.substring(1);
a.info(this.player.name + " issued server command: " + s1);
this.minecraftServer.issueCommand(s1, this);
2011-01-29 22:50:29 +01:00
} else {
s1 = s.substring(1);
a.info(this.player.name + " tried command: " + s1);
2011-01-29 22:50:29 +01:00
}
}
}
public void a(Packet18ArmAnimation packet18armanimation) {
if (packet18armanimation.b == 1) {
// CraftBukkit -- raytrace to look for 'rogue armswings'
float f = 1.0F;
float f1 = this.player.lastPitch + (this.player.pitch - this.player.lastPitch) * f;
float f2 = this.player.lastYaw + (this.player.yaw - this.player.lastYaw) * f;
double d0 = this.player.lastX + (this.player.locX - this.player.lastX) * (double) f;
double d1 = this.player.lastY + (this.player.locY - this.player.lastY) * (double) f + 1.62D - (double) this.player.height;
double d2 = this.player.lastZ + (this.player.locZ - this.player.lastZ) * (double) f;
Vec3D vec3d = Vec3D.create(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 = 5.0D;
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) {
CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getItemInHand());
}
// Arm swing animation
Player player = getPlayer();
PlayerAnimationEvent event = new PlayerAnimationEvent(player);
server.getPluginManager().callEvent(event);
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2011-04-20 22:47:26 +02:00
this.player.k_();
2011-01-14 14:31:10 +01:00
}
}
2011-01-29 22:50:29 +01:00
public void a(Packet19EntityAction packet19entityaction) {
// CraftBukkit start
if (packet19entityaction.animation == 1 || packet19entityaction.animation == 2) {
2011-01-25 19:08:54 +01:00
Player player = getPlayer();
PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(player);
2011-01-25 19:08:54 +01:00
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
}
// CraftBukkit end
2011-01-25 19:08:54 +01:00
if (packet19entityaction.animation == 1) {
this.player.setSneak(true);
} else if (packet19entityaction.animation == 2) {
this.player.setSneak(false);
} else if (packet19entityaction.animation == 3) {
this.player.a(false, true, true);
2011-04-20 22:47:26 +02:00
this.m = false;
}
}
public void a(Packet255KickDisconnect packet255kickdisconnect) {
this.networkManager.a("disconnect.quitting", new Object[0]);
}
public int b() {
return this.networkManager.d();
}
public void sendMessage(String s) {
this.sendPacket(new Packet3Chat("\u00A77" + s));
}
public String getName() {
return this.player.name;
}
2011-01-29 22:50:29 +01:00
public void a(Packet7UseEntity packet7useentity) {
2011-02-23 13:56:36 +01:00
// CraftBukkit
Entity entity = ((WorldServer) this.player.world).getEntity(packet7useentity.target);
if (entity != null && this.player.e(entity) && this.player.f(entity) < 4.0F) {
2011-01-29 22:50:29 +01:00
if (packet7useentity.c == 0) {
this.player.c(entity);
2011-01-29 22:50:29 +01:00
} else if (packet7useentity.c == 1) {
this.player.d(entity);
}
}
}
2011-01-29 22:50:29 +01:00
public void a(Packet9Respawn packet9respawn) {
if (this.player.health <= 0) {
this.player = this.minecraftServer.serverConfigurationManager.d(this.player);
2011-01-29 22:50:29 +01:00
// CraftBukkit start
2011-04-20 22:47:26 +02:00
CraftPlayer player = (CraftPlayer) getPlayer();
player.setHandle(this.player);
2011-01-29 22:50:29 +01:00
// CraftBukkit end
}
}
2011-01-29 22:50:29 +01:00
public void a(Packet101CloseWindow packet101closewindow) {
2011-04-20 22:47:26 +02:00
this.player.z();
}
2011-01-29 22:50:29 +01:00
public void a(Packet102WindowClick packet102windowclick) {
if (this.player.activeContainer.f == packet102windowclick.a && this.player.activeContainer.c(this.player)) {
2011-04-20 22:47:26 +02:00
ItemStack itemstack = this.player.activeContainer.a(packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player);
if (ItemStack.equals(packet102windowclick.e, itemstack)) {
this.player.netServerHandler.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true));
this.player.h = true;
this.player.activeContainer.a();
2011-04-20 22:47:26 +02:00
this.player.y();
this.player.h = false;
} else {
2011-04-20 22:47:26 +02:00
this.n.put(Integer.valueOf(this.player.activeContainer.f), Short.valueOf(packet102windowclick.d));
this.player.netServerHandler.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, false));
this.player.activeContainer.a(this.player, false);
ArrayList arraylist = new ArrayList();
for (int i = 0; i < this.player.activeContainer.e.size(); ++i) {
arraylist.add(((Slot) this.player.activeContainer.e.get(i)).getItem());
}
this.player.a(this.player.activeContainer, arraylist);
}
}
}
2011-01-29 22:50:29 +01:00
public void a(Packet106Transaction packet106transaction) {
2011-04-20 22:47:26 +02:00
Short oshort = (Short) this.n.get(Integer.valueOf(this.player.activeContainer.f));
if (oshort != null && packet106transaction.b == oshort.shortValue() && this.player.activeContainer.f == packet106transaction.a && !this.player.activeContainer.c(this.player)) {
this.player.activeContainer.a(this.player, true);
}
}
2011-01-29 22:50:29 +01:00
public void a(Packet130UpdateSign packet130updatesign) {
2011-02-23 13:56:36 +01:00
// CraftBukkit start
if (((WorldServer) this.player.world).isLoaded(packet130updatesign.x, packet130updatesign.y, packet130updatesign.z)) {
TileEntity tileentity = ((WorldServer) this.player.world).getTileEntity(packet130updatesign.x, packet130updatesign.y, packet130updatesign.z);
// CraftBukkit end
2011-03-09 00:18:14 +01:00
if (tileentity instanceof TileEntitySign) {
TileEntitySign tileentitysign = (TileEntitySign) tileentity;
2011-03-31 22:40:00 +02:00
if (!tileentitysign.a()) {
this.minecraftServer.c("Player " + this.player.name + " just tried to change non-editable sign");
2011-03-09 00:18:14 +01:00
return;
}
}
2011-01-29 22:50:29 +01:00
int i;
int j;
2011-03-31 22:40:00 +02:00
for (j = 0; j < 4; ++j) {
boolean flag = true;
if (packet130updatesign.lines[j].length() > 15) {
flag = false;
} else {
for (i = 0; i < packet130updatesign.lines[j].length(); ++i) {
if (FontAllowedCharacters.a.indexOf(packet130updatesign.lines[j].charAt(i)) < 0) {
flag = false;
}
}
}
2011-01-29 22:50:29 +01:00
if (!flag) {
packet130updatesign.lines[j] = "!?";
}
}
if (tileentity instanceof TileEntitySign) {
j = packet130updatesign.x;
int k = packet130updatesign.y;
2011-01-29 22:50:29 +01:00
i = packet130updatesign.z;
2011-03-31 22:40:00 +02:00
TileEntitySign tileentitysign1 = (TileEntitySign) tileentity;
2011-02-11 03:15:59 +01:00
// CraftBukkit start - SIGN_CHANGE hook
Player player = server.getPlayer(this.player);
SignChangeEvent event = new SignChangeEvent((CraftBlock) player.getWorld().getBlockAt(j, k, i), server.getPlayer(this.player), packet130updatesign.lines);
2011-02-23 13:56:36 +01:00
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
2011-02-11 03:15:59 +01:00
// Normally we would return here, but we have to update the sign with blank text if it's been cancelled
// Otherwise the client will have bad text on their sign (client shows text changes as they type)
2011-02-23 13:56:36 +01:00
for (int l = 0; l < 4; ++l) {
event.setLine(l, "");
2011-02-11 03:15:59 +01:00
}
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
for (int l = 0; l < 4; ++l) {
tileentitysign1.lines[l] = event.getLine(l);
2011-02-23 13:56:36 +01:00
// CraftBukkit
}
tileentitysign1.update();
2011-03-23 16:39:25 +01:00
// CraftBukkit
((WorldServer) this.player.world).notify(j, k, i);
}
}
}
2011-04-20 22:47:26 +02:00
public boolean c() {
return true;
}
}