2010-12-28 22:52:39 +01:00
package net.minecraft.server ;
2012-07-29 09:33:13 +02:00
import java.io.ByteArrayInputStream ;
import java.io.DataInputStream ;
import java.io.IOException ;
2011-01-29 22:50:29 +01:00
import java.util.ArrayList ;
2012-07-29 09:33:13 +02:00
import java.util.Iterator ;
2011-09-15 02:23:52 +02:00
import java.util.Random ;
2010-12-28 22:52:39 +01:00
import java.util.logging.Logger ;
2011-01-08 11:49:42 +01:00
2011-01-11 09:25:13 +01:00
// CraftBukkit start
2012-02-29 22:31:04 +01:00
import java.io.UnsupportedEncodingException ;
import java.util.logging.Level ;
2012-01-15 10:45:16 +01:00
import java.util.HashSet ;
2012-02-29 19:56:35 +01:00
2012-10-07 22:08:21 +02:00
import org.bukkit.Bukkit ;
2010-12-29 02:25:32 +01:00
import org.bukkit.Location ;
2012-08-04 10:35:53 +02:00
import org.bukkit.craftbukkit.CraftWorld ;
2012-02-29 19:56:35 +01:00
import org.bukkit.craftbukkit.inventory.CraftInventoryView ;
import org.bukkit.craftbukkit.inventory.CraftItemStack ;
2012-08-03 13:24:55 +02:00
import org.bukkit.craftbukkit.util.LazyPlayerSet ;
2012-10-07 22:08:21 +02:00
import org.bukkit.craftbukkit.util.Waitable ;
2011-01-15 22:23:28 +01:00
import org.bukkit.craftbukkit.entity.CraftPlayer ;
2011-03-23 12:22:13 +01:00
import org.bukkit.craftbukkit.event.CraftEventFactory ;
2011-01-23 13:23:13 +01:00
import org.bukkit.entity.Player ;
2011-03-24 23:27:40 +01:00
import org.bukkit.event.Event ;
2011-06-27 00:25:01 +02:00
import org.bukkit.event.block.Action ;
import org.bukkit.event.block.SignChangeEvent ;
2012-08-03 13:24:55 +02:00
import org.bukkit.event.player.AsyncPlayerChatEvent ;
2011-06-27 00:25:01 +02:00
import org.bukkit.event.player.PlayerAnimationEvent ;
import org.bukkit.event.player.PlayerChatEvent ;
import org.bukkit.event.player.PlayerCommandPreprocessEvent ;
import org.bukkit.event.player.PlayerInteractEntityEvent ;
import org.bukkit.event.player.PlayerItemHeldEvent ;
import org.bukkit.event.player.PlayerKickEvent ;
import org.bukkit.event.player.PlayerMoveEvent ;
import org.bukkit.event.player.PlayerTeleportEvent ;
import org.bukkit.event.player.PlayerToggleSneakEvent ;
2011-09-21 12:48:24 +02:00
import org.bukkit.event.player.PlayerToggleSprintEvent ;
2012-02-29 19:56:35 +01:00
import org.bukkit.event.inventory.* ;
import org.bukkit.event.inventory.InventoryType.SlotType ;
2012-08-04 10:35:53 +02:00
import org.bukkit.event.player.PlayerPortalEvent ;
2012-05-25 23:38:03 +02:00
import org.bukkit.event.player.PlayerToggleFlightEvent ;
2012-02-29 19:56:35 +01:00
import org.bukkit.inventory.CraftingInventory ;
import org.bukkit.inventory.InventoryView ;
2011-01-11 09:25:13 +01:00
// CraftBukkit end
2010-12-28 22:52:39 +01:00
2012-07-29 09:33:13 +02:00
public class NetServerHandler extends NetHandler {
2010-12-28 22:52:39 +01:00
2012-01-14 21:03:48 +01:00
public static Logger logger = Logger . getLogger ( " Minecraft " ) ;
2012-07-29 09:33:13 +02:00
public INetworkManager networkManager ;
2011-04-20 19:05:14 +02:00
public boolean disconnected = false ;
private MinecraftServer minecraftServer ;
2011-05-14 16:29:42 +02:00
public EntityPlayer player ; // CraftBukkit - private -> public
2011-02-23 03:37:56 +01:00
private int f ;
private int g ;
2011-09-15 02:23:52 +02:00
private boolean h ;
private int i ;
private long j ;
private static Random k = new Random ( ) ;
private long l ;
2012-01-12 23:10:13 +01:00
private int m = 0 ;
2012-03-01 11:49:23 +01:00
private int x = 0 ;
2011-04-20 19:05:14 +02:00
private double y ;
private double z ;
2012-03-01 11:49:23 +01:00
private double q ;
2012-07-29 09:33:13 +02:00
public boolean checkMovement = true ; // CraftBukkit - private -> public
2012-03-01 11:49:23 +01:00
private IntHashMap s = new IntHashMap ( ) ;
2011-01-11 09:25:13 +01:00
2012-07-29 09:33:13 +02:00
public NetServerHandler ( MinecraftServer minecraftserver , INetworkManager inetworkmanager , EntityPlayer entityplayer ) {
2011-04-20 19:05:14 +02:00
this . minecraftServer = minecraftserver ;
2012-07-29 09:33:13 +02:00
this . networkManager = inetworkmanager ;
inetworkmanager . a ( this ) ;
2011-04-20 19:05:14 +02:00
this . player = entityplayer ;
entityplayer . netServerHandler = this ;
2011-01-29 22:50:29 +01:00
// CraftBukkit start
2011-06-27 00:25:01 +02:00
this . server = minecraftserver . server ;
2011-01-29 22:50:29 +01:00
}
2012-01-14 23:02:10 +01:00
2012-07-22 08:18:00 +02:00
private final org . bukkit . craftbukkit . CraftServer server ;
2011-05-14 16:29:42 +02:00
private int lastTick = MinecraftServer . currentTick ;
2011-08-09 05:01:33 +02:00
private int lastDropTick = MinecraftServer . currentTick ;
private int dropCount = 0 ;
2011-05-14 16:29:42 +02:00
private static final int PLACE_DISTANCE_SQUARED = 6 * 6 ;
2010-12-28 22:52:39 +01:00
2011-01-29 22:50:29 +01:00
// Get position of last block hit for BlockDamageLevel.STOPPED
2011-03-08 00:06:50 +01:00
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 ;
2011-07-26 22:30:34 +02:00
private boolean justTeleported = false ;
2011-02-25 22:40:06 +01:00
2011-03-24 00:10:05 +01:00
// 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-06-27 00:25:01 +02:00
public CraftPlayer getPlayer ( ) {
return ( this . player = = null ) ? null : ( CraftPlayer ) this . player . getBukkitEntity ( ) ;
2011-01-11 09:25:13 +01:00
}
2012-07-22 08:18:00 +02:00
private final static HashSet < Integer > invalidItems = new HashSet < Integer > ( java . util . Arrays . asList ( 8 , 9 , 10 , 11 , 26 , 34 , 36 , 51 , 52 , 55 , 59 , 60 , 63 , 64 , 68 , 71 , 75 , 78 , 83 , 90 , 92 , 93 , 94 , 95 ) ) ;
2011-01-11 09:25:13 +01:00
// CraftBukkit end
2012-07-29 09:33:13 +02:00
public void d ( ) {
2011-09-15 02:23:52 +02:00
this . h = false ;
+ + this . f ;
2012-09-10 06:19:28 +02:00
this . minecraftServer . methodProfiler . a ( " packetflow " ) ;
this . networkManager . b ( ) ;
this . minecraftServer . methodProfiler . c ( " keepAlive " ) ;
2011-09-15 02:23:52 +02:00
if ( ( long ) this . f - this . l > 20L ) {
this . l = ( long ) this . f ;
this . j = System . nanoTime ( ) / 1000000L ;
this . i = k . nextInt ( ) ;
this . sendPacket ( new Packet0KeepAlive ( this . i ) ) ;
2010-12-28 22:52:39 +01:00
}
2012-01-12 23:10:13 +01:00
if ( this . m > 0 ) {
- - this . m ;
}
2012-03-01 11:49:23 +01:00
if ( this . x > 0 ) {
- - this . x ;
}
2012-07-29 09:33:13 +02:00
2012-09-10 06:19:28 +02:00
this . minecraftServer . methodProfiler . c ( " playerTick " ) ;
2012-07-29 09:33:13 +02:00
if ( ! this . h & & ! this . player . viewingCredits ) {
this . player . g ( ) ;
2012-08-25 02:51:51 +02:00
if ( this . player . vehicle = = null ) {
this . player . setPositionRotation ( this . y , this . z , this . q , this . player . yaw , this . player . pitch ) ;
}
2012-07-29 09:33:13 +02:00
}
2012-09-10 06:19:28 +02:00
this . minecraftServer . methodProfiler . b ( ) ;
2010-12-28 22:52:39 +01:00
}
2011-04-20 19:05:14 +02:00
public void disconnect ( String s ) {
2012-01-12 23:10:13 +01:00
if ( ! this . disconnected ) {
// CraftBukkit start
String leaveMessage = " \ u00A7e " + this . player . name + " left the game. " ;
2011-06-27 00:25:01 +02:00
2012-01-12 23:10:13 +01:00
PlayerKickEvent event = new PlayerKickEvent ( this . server . getPlayer ( this . player ) , s , leaveMessage ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-05-28 22:50:08 +02:00
2012-01-12 23:10:13 +01:00
if ( event . isCancelled ( ) ) {
// Do not kick the player
return ;
}
// Send the possibly modified leave message
s = event . getReason ( ) ;
// CraftBukkit end
2011-05-28 22:50:08 +02:00
2012-10-25 05:53:23 +02:00
this . player . l ( ) ;
2012-01-12 23:10:13 +01:00
this . sendPacket ( new Packet255KickDisconnect ( s ) ) ;
this . networkManager . d ( ) ;
2011-03-23 12:22:13 +01:00
2012-01-12 23:10:13 +01:00
// CraftBukkit start
leaveMessage = event . getLeaveMessage ( ) ;
2012-06-13 08:44:02 +02:00
if ( leaveMessage ! = null & & leaveMessage . length ( ) > 0 ) {
2012-07-29 09:33:13 +02:00
this . minecraftServer . getServerConfigurationManager ( ) . sendAll ( new Packet3Chat ( leaveMessage ) ) ;
2012-01-12 23:10:13 +01:00
}
2012-01-19 09:32:05 +01:00
getPlayer ( ) . disconnect ( s ) ;
2012-01-12 23:10:13 +01:00
// CraftBukkit end
2010-12-28 22:52:39 +01:00
2012-07-29 09:33:13 +02:00
this . minecraftServer . getServerConfigurationManager ( ) . disconnect ( this . player ) ;
2012-01-12 23:10:13 +01:00
this . disconnected = true ;
}
2011-02-23 03:37:56 +01:00
}
2010-12-28 22:52:39 +01:00
public void a ( Packet10Flying packet10flying ) {
2011-06-27 00:25:01 +02:00
WorldServer worldserver = this . minecraftServer . getWorldServer ( this . player . dimension ) ;
2011-05-26 14:48:22 +02:00
2011-09-15 02:23:52 +02:00
this . h = true ;
2012-01-14 21:03:48 +01:00
if ( ! this . player . viewingCredits ) {
2011-11-20 09:01:14 +01:00
double d0 ;
2010-12-28 22:52:39 +01:00
2011-11-20 09:01:14 +01:00
if ( ! this . checkMovement ) {
2012-03-01 11:49:23 +01:00
d0 = packet10flying . y - this . z ;
if ( packet10flying . x = = this . y & & d0 * d0 < 0 . 01D & & packet10flying . z = = this . q ) {
2011-11-20 09:01:14 +01:00
this . checkMovement = true ;
}
2010-12-28 22:52:39 +01:00
}
2011-06-30 07:26:18 +02:00
2011-11-20 09:01:14 +01:00
// CraftBukkit start
Player player = this . getPlayer ( ) ;
Location from = new Location ( player . getWorld ( ) , lastPosX , lastPosY , lastPosZ , lastYaw , lastPitch ) ; // Get the Players previous Event location.
Location to = player . getLocation ( ) . clone ( ) ; // Start off the To location as the Players current location.
// If the packet contains movement information then we update the To location with the correct XYZ.
2012-01-14 21:03:48 +01:00
if ( packet10flying . hasPos & & ! ( packet10flying . hasPos & & packet10flying . y = = - 999 . 0D & & packet10flying . stance = = - 999 . 0D ) ) {
2011-11-20 09:01:14 +01:00
to . setX ( packet10flying . x ) ;
to . setY ( packet10flying . y ) ;
to . setZ ( packet10flying . z ) ;
}
2011-03-08 00:06:50 +01:00
2011-11-20 09:01:14 +01:00
// 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 ) ;
}
2011-03-27 00:34:33 +01:00
2011-11-20 09:01:14 +01:00
// Prevent 40 event-calls for less than a single pixel of movement >.>
double delta = Math . pow ( this . lastPosX - to . getX ( ) , 2 ) + Math . pow ( this . lastPosY - to . getY ( ) , 2 ) + Math . pow ( this . lastPosZ - to . getZ ( ) , 2 ) ;
float deltaAngle = Math . abs ( this . lastYaw - to . getYaw ( ) ) + Math . abs ( this . lastPitch - to . getPitch ( ) ) ;
if ( ( delta > 1f / 256 | | deltaAngle > 10f ) & & ( this . checkMovement & & ! this . player . dead ) ) {
this . lastPosX = to . getX ( ) ;
this . lastPosY = to . getY ( ) ;
this . lastPosZ = to . getZ ( ) ;
this . lastYaw = to . getYaw ( ) ;
this . lastPitch = to . getPitch ( ) ;
// Skip the first time we do this
if ( from . getX ( ) ! = Double . MAX_VALUE ) {
PlayerMoveEvent event = new PlayerMoveEvent ( player , from , to ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
// If the event is cancelled we move the player back to their old location.
if ( event . isCancelled ( ) ) {
this . player . netServerHandler . sendPacket ( new Packet13PlayerLookMove ( from . getX ( ) , from . getY ( ) + 1 . 6200000047683716D , from . getY ( ) , from . getZ ( ) , from . getYaw ( ) , from . getPitch ( ) , false ) ) ;
return ;
}
2011-06-18 01:19:11 +02:00
2011-11-20 09:01:14 +01:00
/ * If a Plugin has changed the To destination then we teleport the Player
there to avoid any ' Moved wrongly ' or ' Moved too quickly ' errors .
We only do this if the Event was not cancelled . * /
if ( ! to . equals ( event . getTo ( ) ) & & ! event . isCancelled ( ) ) {
2011-12-04 12:04:14 +01:00
this . player . getBukkitEntity ( ) . teleport ( event . getTo ( ) , PlayerTeleportEvent . TeleportCause . UNKNOWN ) ;
2011-11-20 09:01:14 +01:00
return ;
}
2011-03-24 00:52:10 +01:00
2011-11-20 09:01:14 +01:00
/ * Check to see if the Players Location has some how changed during the call of the event .
This can happen due to a plugin teleporting the player instead of using . setTo ( ) * /
if ( ! from . equals ( this . getPlayer ( ) . getLocation ( ) ) & & this . justTeleported ) {
this . justTeleported = false ;
return ;
}
2011-06-30 07:26:18 +02:00
}
2011-03-24 00:52:10 +01:00
}
2011-04-13 04:03:43 +02:00
2011-11-20 09:01:14 +01:00
if ( Double . isNaN ( packet10flying . x ) | | Double . isNaN ( packet10flying . y ) | | Double . isNaN ( packet10flying . z ) | | Double . isNaN ( packet10flying . stance ) ) {
2011-12-04 12:04:14 +01:00
player . teleport ( player . getWorld ( ) . getSpawnLocation ( ) , PlayerTeleportEvent . TeleportCause . UNKNOWN ) ;
2011-11-20 09:01:14 +01:00
System . err . println ( player . getName ( ) + " was caught trying to crash the server with an invalid position. " ) ;
player . kickPlayer ( " Nope! " ) ;
return ;
}
2010-12-29 02:25:32 +01:00
2011-11-20 09:01:14 +01:00
if ( this . checkMovement & & ! this . player . dead ) {
// CraftBukkit end
double d1 ;
double d2 ;
double d3 ;
double d4 ;
2010-12-28 22:52:39 +01:00
2011-11-20 09:01:14 +01:00
if ( this . player . vehicle ! = null ) {
float f = this . player . yaw ;
float f1 = this . player . pitch ;
2012-07-29 09:33:13 +02:00
this . player . vehicle . V ( ) ;
2011-11-20 09:01:14 +01:00
d1 = this . player . locX ;
d2 = this . player . locY ;
d3 = this . player . locZ ;
double d5 = 0 . 0D ;
d4 = 0 . 0D ;
if ( packet10flying . hasLook ) {
f = packet10flying . yaw ;
f1 = packet10flying . pitch ;
}
2010-12-28 22:52:39 +01:00
2012-01-14 21:03:48 +01:00
if ( packet10flying . hasPos & & packet10flying . y = = - 999 . 0D & & packet10flying . stance = = - 999 . 0D ) {
2012-08-25 02:51:51 +02:00
if ( Math . abs ( packet10flying . x ) > 1 . 0D | | Math . abs ( packet10flying . z ) > 1 . 0D ) {
2012-02-13 06:40:32 +01:00
System . err . println ( player . getName ( ) + " was caught trying to crash the server with an invalid position. " ) ;
player . kickPlayer ( " Nope! " ) ;
return ;
}
2012-07-29 09:33:13 +02:00
2011-11-20 09:01:14 +01:00
d5 = packet10flying . x ;
d4 = packet10flying . z ;
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
this . player . onGround = packet10flying . g ;
2012-07-29 09:33:13 +02:00
this . player . g ( ) ;
2011-11-20 09:01:14 +01:00
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 ) {
worldserver . vehicleEnteredWorld ( this . player . vehicle , true ) ;
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
if ( this . player . vehicle ! = null ) {
2012-07-29 09:33:13 +02:00
this . player . vehicle . V ( ) ;
2011-11-20 09:01:14 +01:00
}
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
this . minecraftServer . getServerConfigurationManager ( ) . d ( this . player ) ;
2012-03-01 11:49:23 +01:00
this . y = this . player . locX ;
this . z = this . player . locY ;
this . q = this . player . locZ ;
2011-11-20 09:01:14 +01:00
worldserver . playerJoinedWorld ( this . player ) ;
return ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
if ( this . player . isSleeping ( ) ) {
2012-07-29 09:33:13 +02:00
this . player . g ( ) ;
2012-03-01 11:49:23 +01:00
this . player . setLocation ( this . y , this . z , this . q , this . player . yaw , this . player . pitch ) ;
2011-11-20 09:01:14 +01:00
worldserver . playerJoinedWorld ( this . player ) ;
return ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
d0 = this . player . locY ;
2012-03-01 11:49:23 +01:00
this . y = this . player . locX ;
this . z = this . player . locY ;
this . q = this . player . locZ ;
2011-11-20 09:01:14 +01:00
d1 = this . player . locX ;
d2 = this . player . locY ;
d3 = this . player . locZ ;
float f2 = this . player . yaw ;
float f3 = this . player . pitch ;
2011-05-31 15:55:45 +02:00
2012-01-14 21:03:48 +01:00
if ( packet10flying . hasPos & & packet10flying . y = = - 999 . 0D & & packet10flying . stance = = - 999 . 0D ) {
packet10flying . hasPos = false ;
2011-11-20 09:01:14 +01:00
}
2010-12-28 22:52:39 +01:00
2012-01-14 21:03:48 +01:00
if ( packet10flying . hasPos ) {
2011-11-20 09:01:14 +01:00
d1 = packet10flying . x ;
d2 = packet10flying . y ;
d3 = packet10flying . z ;
d4 = packet10flying . stance - packet10flying . y ;
if ( ! this . player . isSleeping ( ) & & ( d4 > 1 . 65D | | d4 < 0 . 1D ) ) {
this . disconnect ( " Illegal stance " ) ;
2012-01-14 21:03:48 +01:00
logger . warning ( this . player . name + " had an illegal stance: " + d4 ) ;
2011-11-20 09:01:14 +01:00
return ;
}
if ( Math . abs ( packet10flying . x ) > 3 . 2E7D | | Math . abs ( packet10flying . z ) > 3 . 2E7D ) {
this . disconnect ( " Illegal position " ) ;
return ;
}
2011-04-20 22:47:26 +02:00
}
2011-11-20 09:01:14 +01:00
if ( packet10flying . hasLook ) {
f2 = packet10flying . yaw ;
f3 = packet10flying . pitch ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
this . player . g ( ) ;
2012-10-25 05:53:23 +02:00
this . player . W = 0 . 0F ;
2012-03-01 11:49:23 +01:00
this . player . setLocation ( this . y , this . z , this . q , f2 , f3 ) ;
2011-11-20 09:01:14 +01:00
if ( ! this . checkMovement ) {
return ;
}
2011-04-20 22:47:26 +02:00
2011-11-20 09:01:14 +01:00
d4 = d1 - this . player . locX ;
double d6 = d2 - this . player . locY ;
double d7 = d3 - this . player . locZ ;
2012-08-06 06:45:38 +02:00
// CraftBukkit start - min to max
double d8 = Math . max ( Math . abs ( d4 ) , Math . abs ( this . player . motX ) ) ;
double d9 = Math . max ( Math . abs ( d6 ) , Math . abs ( this . player . motY ) ) ;
double d10 = Math . max ( Math . abs ( d7 ) , Math . abs ( this . player . motZ ) ) ;
// CraftBukkit end
2012-07-29 09:33:13 +02:00
double d11 = d8 * d8 + d9 * d9 + d10 * d10 ;
2012-10-25 05:53:23 +02:00
if ( d11 > 100 . 0D & & this . checkMovement & & ( ! this . minecraftServer . I ( ) | | ! this . minecraftServer . H ( ) . equals ( this . player . name ) ) ) { // CraftBukkit - Added this.checkMovement condition to solve this check being triggered by teleports
2012-07-29 09:33:13 +02:00
logger . warning ( this . player . name + " moved too quickly! " + d4 + " , " + d6 + " , " + d7 + " ( " + d8 + " , " + d9 + " , " + d10 + " ) " ) ;
2012-08-06 06:45:38 +02:00
this . a ( this . y , this . z , this . q , this . player . yaw , this . player . pitch ) ;
2011-11-20 09:01:14 +01:00
return ;
}
2011-04-19 07:04:13 +02:00
2011-11-20 09:01:14 +01:00
float f4 = 0 . 0625F ;
2012-07-29 09:33:13 +02:00
boolean flag = worldserver . getCubes ( this . player , this . player . boundingBox . clone ( ) . shrink ( ( double ) f4 , ( double ) f4 , ( double ) f4 ) ) . isEmpty ( ) ;
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
if ( this . player . onGround & & ! packet10flying . g & & d6 > 0 . 0D ) {
2012-07-29 09:33:13 +02:00
this . player . j ( 0 . 2F ) ;
2011-11-20 09:01:14 +01:00
}
2011-04-20 22:47:26 +02:00
2011-11-20 09:01:14 +01:00
this . player . move ( d4 , d6 , d7 ) ;
this . player . onGround = packet10flying . g ;
2012-02-29 22:31:04 +01:00
this . player . checkMovement ( d4 , d6 , d7 ) ;
2012-07-29 09:33:13 +02:00
double d12 = d6 ;
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
d4 = d1 - this . player . locX ;
d6 = d2 - this . player . locY ;
if ( d6 > - 0 . 5D | | d6 < 0 . 5D ) {
d6 = 0 . 0D ;
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
d7 = d3 - this . player . locZ ;
2012-07-29 09:33:13 +02:00
d11 = d4 * d4 + d6 * d6 + d7 * d7 ;
2011-11-20 09:01:14 +01:00
boolean flag1 = false ;
2010-12-28 22:52:39 +01:00
2012-07-29 09:33:13 +02:00
if ( d11 > 0 . 0625D & & ! this . player . isSleeping ( ) & & ! this . player . itemInWorldManager . isCreative ( ) ) {
2011-11-20 09:01:14 +01:00
flag1 = true ;
2012-01-14 21:03:48 +01:00
logger . warning ( this . player . name + " moved wrongly! " ) ;
2011-11-20 09:01:14 +01:00
}
2011-01-29 22:50:29 +01:00
2011-11-20 09:01:14 +01:00
this . player . setLocation ( d1 , d2 , d3 , f2 , f3 ) ;
2012-07-29 09:33:13 +02:00
boolean flag2 = worldserver . getCubes ( this . player , this . player . boundingBox . clone ( ) . shrink ( ( double ) f4 , ( double ) f4 , ( double ) f4 ) ) . isEmpty ( ) ;
2010-12-28 22:52:39 +01:00
2011-11-20 09:01:14 +01:00
if ( flag & & ( flag1 | | ! flag2 ) & & ! this . player . isSleeping ( ) ) {
2012-03-01 11:49:23 +01:00
this . a ( this . y , this . z , this . q , f2 , f3 ) ;
2011-11-20 09:01:14 +01:00
return ;
}
2011-01-29 22:50:29 +01:00
2012-01-12 16:27:39 +01:00
AxisAlignedBB axisalignedbb = this . player . boundingBox . clone ( ) . grow ( ( double ) f4 , ( double ) f4 , ( double ) f4 ) . a ( 0 . 0D , - 0 . 55D , 0 . 0D ) ;
2011-04-20 22:47:26 +02:00
2012-07-29 09:33:13 +02:00
if ( ! this . minecraftServer . getAllowFlight ( ) & & ! this . player . abilities . canFly & & ! worldserver . c ( axisalignedbb ) ) { // CraftBukkit - check abilities instead of creative mode
if ( d12 > = - 0 . 03125D ) {
2011-11-20 09:01:14 +01:00
+ + this . g ;
if ( this . g > 80 ) {
2012-01-14 21:03:48 +01:00
logger . warning ( this . player . name + " was kicked for floating too long! " ) ;
2011-11-20 09:01:14 +01:00
this . disconnect ( " Flying is not enabled on this server " ) ;
return ;
}
2011-04-20 22:47:26 +02:00
}
2011-11-20 09:01:14 +01:00
} else {
this . g = 0 ;
2011-04-20 22:47:26 +02:00
}
2011-11-20 09:01:14 +01:00
this . player . onGround = packet10flying . g ;
2012-07-29 09:33:13 +02:00
this . minecraftServer . getServerConfigurationManager ( ) . d ( this . player ) ;
2012-01-14 21:03:48 +01:00
if ( this . player . itemInWorldManager . isCreative ( ) ) return ; // CraftBukkit - fixed fall distance accumulating while being in Creative mode.
2011-11-20 09:01:14 +01:00
this . player . b ( this . player . locY - d0 , packet10flying . g ) ;
}
2010-12-28 22:52:39 +01:00
}
}
2011-03-23 18:42:36 +01:00
public void a ( double d0 , double d1 , double d2 , float f , float f1 ) {
2011-05-14 16:29:42 +02:00
// CraftBukkit start - Delegate to teleport(Location)
2011-06-27 00:25:01 +02:00
Player player = this . getPlayer ( ) ;
2010-12-29 02:25:32 +01:00
Location from = player . getLocation ( ) ;
2011-06-27 00:25:01 +02:00
Location to = new Location ( this . getPlayer ( ) . getWorld ( ) , d0 , d1 , d2 , f , f1 ) ;
2011-12-04 12:04:14 +01:00
PlayerTeleportEvent event = new PlayerTeleportEvent ( player , from , to , PlayerTeleportEvent . TeleportCause . UNKNOWN ) ;
2011-06-27 00:25:01 +02:00
this . server . getPluginManager ( ) . callEvent ( event ) ;
2010-12-29 02:25:32 +01:00
from = event . getFrom ( ) ;
to = event . isCancelled ( ) ? from : event . getTo ( ) ;
2011-06-27 00:25:01 +02:00
this . teleport ( to ) ;
2011-06-11 04:59:54 +02:00
}
public void teleport ( Location dest ) {
2011-03-23 07:50:14 +01:00
double d0 , d1 , d2 ;
float f , f1 ;
2011-06-11 04:59:54 +02:00
d0 = dest . getX ( ) ;
d1 = dest . getY ( ) ;
d2 = dest . getZ ( ) ;
f = dest . getYaw ( ) ;
f1 = dest . getPitch ( ) ;
2011-04-25 02:14:33 +02:00
// TODO: make sure this is the best way to address this.
if ( Float . isNaN ( f ) ) {
f = 0 ;
}
if ( Float . isNaN ( f1 ) ) {
f1 = 0 ;
}
2011-07-26 22:30:34 +02:00
this . lastPosX = d0 ;
this . lastPosY = d1 ;
this . lastPosZ = d2 ;
this . lastYaw = f ;
this . lastPitch = f1 ;
this . justTeleported = true ;
2011-03-23 18:42:36 +01:00
// CraftBukkit end
2010-12-29 02:25:32 +01:00
2011-06-27 00:25:01 +02:00
this . checkMovement = false ;
2012-03-01 11:49:23 +01:00
this . y = d0 ;
this . z = d1 ;
this . q = d2 ;
2011-04-20 19:05:14 +02:00
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 07:50:14 +01:00
}
2010-12-28 22:52:39 +01:00
public void a ( Packet14BlockDig packet14blockdig ) {
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ; // CraftBukkit
2011-05-12 16:22:52 +02:00
2011-06-27 00:25:01 +02:00
WorldServer worldserver = this . minecraftServer . getWorldServer ( this . player . dimension ) ;
2011-05-26 14:48:22 +02:00
2010-12-28 22:52:39 +01:00
if ( packet14blockdig . e = = 4 ) {
2011-08-09 05:01:33 +02:00
// 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 ) {
this . dropCount = 0 ;
this . lastDropTick = MinecraftServer . currentTick ;
} else {
// Else we increment the drop count and check the amount.
this . dropCount + + ;
if ( this . dropCount > = 20 ) {
2012-01-14 21:03:48 +01:00
logger . warning ( this . player . name + " dropped their items too quickly! " ) ;
2011-08-09 05:01:33 +02:00
this . disconnect ( " You dropped your items too quickly (Hacking?) " ) ;
2011-09-15 04:22:56 +02:00
return ;
2011-08-09 05:01:33 +02:00
}
}
// CraftBukkit end
2012-10-25 05:53:23 +02:00
this . player . bN ( ) ;
2011-09-15 04:22:56 +02:00
} else if ( packet14blockdig . e = = 5 ) {
2012-10-25 05:53:23 +02:00
this . player . bK ( ) ;
2011-01-29 22:50:29 +01:00
} else {
2012-10-25 05:53:23 +02:00
boolean flag = worldserver . worldProvider . dimension ! = 0 | | this . minecraftServer . getServerConfigurationManager ( ) . getOPs ( ) . isEmpty ( ) | | this . minecraftServer . getServerConfigurationManager ( ) . isOp ( this . player . name ) | | this . minecraftServer . I ( ) ;
2011-01-29 22:50:29 +01:00
boolean flag1 = false ;
2010-12-28 22:52:39 +01:00
2011-01-29 22:50:29 +01:00
if ( packet14blockdig . e = = 0 ) {
flag1 = true ;
}
2010-12-28 22:52:39 +01:00
2011-02-23 03:37:56 +01:00
if ( packet14blockdig . e = = 2 ) {
2011-01-29 22:50:29 +01:00
flag1 = true ;
}
2010-12-28 22:52:39 +01:00
2011-01-29 22:50:29 +01:00
int i = packet14blockdig . a ;
int j = packet14blockdig . b ;
int k = packet14blockdig . c ;
if ( flag1 ) {
2011-04-20 19:05:14 +02:00
double d0 = this . player . locX - ( ( double ) i + 0 . 5D ) ;
2011-11-20 09:01:14 +01:00
double d1 = this . player . locY - ( ( double ) j + 0 . 5D ) + 1 . 5D ;
2011-04-20 19:05:14 +02:00
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 ;
}
2012-03-01 11:49:23 +01:00
2012-07-29 09:33:13 +02:00
if ( j > = this . minecraftServer . getMaxBuildHeight ( ) ) {
2012-03-01 11:49:23 +01:00
return ;
}
2010-12-28 22:52:39 +01:00
}
2011-05-26 14:48:22 +02:00
ChunkCoordinates chunkcoordinates = worldserver . getSpawn ( ) ;
2011-09-15 02:23:52 +02:00
int l = MathHelper . a ( i - chunkcoordinates . x ) ;
int i1 = MathHelper . a ( k - chunkcoordinates . z ) ;
2010-12-28 22:52:39 +01:00
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 ) {
2012-07-22 08:18:00 +02:00
// CraftBukkit start
2011-06-27 00:25:01 +02:00
if ( i1 < this . server . getSpawnRadius ( ) & & ! flag ) {
2012-03-13 20:35:20 +01:00
CraftEventFactory . callPlayerInteractEvent ( this . player , Action . LEFT_CLICK_BLOCK , i , j , k , l , this . player . inventory . getItemInHand ( ) ) ;
2012-07-22 08:18:00 +02:00
// CraftBukkit end
2011-05-26 14:48:22 +02:00
this . player . netServerHandler . sendPacket ( new Packet53BlockChange ( i , j , k , worldserver ) ) ;
} else {
2012-01-11 04:19:23 +01:00
this . player . itemInWorldManager . dig ( i , j , k , packet14blockdig . face ) ;
2011-01-29 22:50:29 +01:00
}
} else if ( packet14blockdig . e = = 2 ) {
2011-05-26 14:48:22 +02:00
this . player . itemInWorldManager . a ( i , j , k ) ;
if ( worldserver . getTypeId ( i , j , k ) ! = 0 ) {
this . player . netServerHandler . sendPacket ( new Packet53BlockChange ( i , j , k , worldserver ) ) ;
}
2012-07-29 09:33:13 +02:00
} else if ( packet14blockdig . e = = 1 ) {
this . player . itemInWorldManager . c ( i , j , k ) ;
if ( worldserver . getTypeId ( i , j , k ) ! = 0 ) {
this . player . netServerHandler . sendPacket ( new Packet53BlockChange ( i , j , k , worldserver ) ) ;
}
2011-01-29 22:50:29 +01:00
} else if ( packet14blockdig . e = = 3 ) {
2011-04-20 19:05:14 +02:00
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-05-26 14:48:22 +02:00
this . player . netServerHandler . sendPacket ( new Packet53BlockChange ( i , j , k , worldserver ) ) ;
2011-01-10 02:36:19 +01:00
}
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
}
2010-12-28 22:52:39 +01:00
}
2011-01-11 09:25:13 +01:00
2010-12-28 22:52:39 +01:00
public void a ( Packet15Place packet15place ) {
2011-06-27 00:25:01 +02:00
WorldServer worldserver = this . minecraftServer . getWorldServer ( this . player . dimension ) ;
2011-05-26 14:48:22 +02:00
2011-03-24 12:11:28 +01:00
// CraftBukkit start
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ;
2011-05-12 16:22:52 +02:00
2011-06-27 00:25:01 +02:00
// 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
2011-03-24 00:10:05 +01:00
// 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
2012-07-29 09:33:13 +02:00
if ( packet15place . getFace ( ) = = 255 ) {
if ( packet15place . getItemStack ( ) ! = null & & packet15place . getItemStack ( ) . id = = this . lastMaterial & & this . lastPacket ! = null & & packet15place . timestamp - this . lastPacket < 100 ) {
2011-06-27 00:25:01 +02:00
this . lastPacket = null ;
2011-03-24 00:10:05 +01:00
return ;
2011-01-08 11:49:42 +01:00
}
} else {
2012-07-29 09:33:13 +02:00
this . lastMaterial = packet15place . getItemStack ( ) = = null ? - 1 : packet15place . getItemStack ( ) . id ;
2011-06-27 00:25:01 +02:00
this . lastPacket = packet15place . timestamp ;
2011-01-08 11:49:42 +01:00
}
2011-01-10 02:36:19 +01:00
2011-05-14 16:29:42 +02:00
// CraftBukkit - if rightclick decremented the item, always send the update packet.
2011-01-11 09:25:13 +01:00
// this is not here for CraftBukkit's own functionality; rather it is to fix
2011-06-27 00:25:01 +02:00
// a notch bug where the item doesn't update correctly.
2011-01-07 11:46:11 +01:00
boolean always = false ;
2011-03-24 00:10:05 +01:00
2011-01-11 09:25:13 +01:00
// CraftBukkit end
2011-01-10 02:36:19 +01:00
2011-04-20 19:05:14 +02:00
ItemStack itemstack = this . player . inventory . getItemInHand ( ) ;
2012-03-01 11:49:23 +01:00
boolean flag = false ;
2012-07-29 09:33:13 +02:00
int i = packet15place . d ( ) ;
int j = packet15place . f ( ) ;
int k = packet15place . g ( ) ;
int l = packet15place . getFace ( ) ;
2012-10-25 05:53:23 +02:00
boolean flag1 = worldserver . worldProvider . dimension ! = 0 | | this . minecraftServer . getServerConfigurationManager ( ) . getOPs ( ) . isEmpty ( ) | | this . minecraftServer . getServerConfigurationManager ( ) . isOp ( this . player . name ) | | this . minecraftServer . I ( ) ;
2011-03-24 00:10:05 +01:00
2012-07-29 09:33:13 +02:00
if ( packet15place . getFace ( ) = = 255 ) {
2010-12-28 22:52:39 +01:00
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 ;
2012-07-22 08:18:00 +02:00
org . bukkit . event . player . PlayerInteractEvent event = CraftEventFactory . callPlayerInteractEvent ( this . player , Action . RIGHT_CLICK_AIR , itemstack ) ;
2011-03-25 07:35:47 +01:00
if ( event . useItemInHand ( ) ! = Event . Result . DENY ) {
2011-04-20 19:05:14 +02:00
this . player . itemInWorldManager . useItem ( this . player , this . player . world , itemstack ) ;
2011-03-25 07:35:47 +01:00
}
2011-01-08 11:49:42 +01:00
2011-05-14 16:29:42 +02:00
// CraftBukkit - notch decrements the counter by 1 in the above method with food,
2011-06-27 00:25:01 +02:00
// snowballs and so forth, but he does it in a place that doesn't cause the
2011-03-24 23:27:40 +01:00
// inventory update packet to get sent
always = ( itemstack . count ! = itemstackAmount ) ;
2011-01-11 09:25:13 +01:00
// CraftBukkit end
2012-07-29 09:33:13 +02:00
} else if ( packet15place . f ( ) > = this . minecraftServer . getMaxBuildHeight ( ) - 1 & & ( packet15place . getFace ( ) = = 1 | | packet15place . f ( ) > = this . minecraftServer . getMaxBuildHeight ( ) ) ) {
this . player . netServerHandler . sendPacket ( new Packet3Chat ( " \ u00A77Height limit for building is " + this . minecraftServer . getMaxBuildHeight ( ) ) ) ;
2012-03-01 11:49:23 +01:00
flag = true ;
2010-12-28 22:52:39 +01:00
} else {
2011-05-26 14:48:22 +02:00
ChunkCoordinates chunkcoordinates = worldserver . getSpawn ( ) ;
2011-09-15 02:23:52 +02:00
int i1 = MathHelper . a ( i - chunkcoordinates . x ) ;
int j1 = MathHelper . a ( k - chunkcoordinates . z ) ;
2011-01-29 22:50:29 +01:00
if ( i1 > j1 ) {
j1 = i1 ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
2011-05-26 14:48:22 +02:00
// CraftBukkit start - Check if we can actually do something over this large a distance
2011-06-27 00:25:01 +02:00
Location eyeLoc = this . getPlayer ( ) . getEyeLocation ( ) ;
2011-03-09 20:43:49 +01:00
if ( Math . pow ( eyeLoc . getX ( ) - i , 2 ) + Math . pow ( eyeLoc . getY ( ) - j , 2 ) + Math . pow ( eyeLoc . getZ ( ) - k , 2 ) > PLACE_DISTANCE_SQUARED ) {
return ;
}
2012-03-01 11:49:23 +01:00
flag1 = true ; // spawn protection moved to ItemBlock!!!
2012-10-25 05:53:23 +02:00
if ( j1 > this . minecraftServer . getSpawnProtection ( ) | | flag1 ) {
2012-07-29 09:33:13 +02:00
// CraftBukkit end
this . player . itemInWorldManager . interact ( this . player , worldserver , itemstack , i , j , k , l , packet15place . j ( ) , packet15place . l ( ) , packet15place . m ( ) ) ;
2011-05-26 14:48:22 +02:00
}
2012-03-01 11:49:23 +01:00
flag = true ;
}
if ( flag ) {
2011-05-26 14:48:22 +02:00
this . player . netServerHandler . sendPacket ( new Packet53BlockChange ( i , j , k , worldserver ) ) ;
2011-01-29 22:50:29 +01:00
if ( l = = 0 ) {
- - j ;
2011-01-08 11:49:42 +01:00
}
2011-01-29 22:50:29 +01:00
if ( l = = 1 ) {
+ + j ;
2011-01-08 11:49:42 +01:00
}
2011-01-29 22:50:29 +01:00
if ( l = = 2 ) {
- - k ;
2011-01-08 11:49:42 +01:00
}
2011-01-29 22:50:29 +01:00
if ( l = = 3 ) {
+ + k ;
2011-01-08 11:49:42 +01:00
}
2011-01-29 22:50:29 +01:00
if ( l = = 4 ) {
- - i ;
2011-01-08 11:49:42 +01:00
}
2011-01-29 22:50:29 +01:00
if ( l = = 5 ) {
+ + i ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
2011-05-26 14:48:22 +02:00
this . player . netServerHandler . sendPacket ( new Packet53BlockChange ( i , j , k , worldserver ) ) ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
2011-05-26 14:48:22 +02:00
itemstack = this . player . inventory . getItemInHand ( ) ;
2011-01-29 22:50:29 +01:00
if ( itemstack ! = null & & itemstack . count = = 0 ) {
2011-04-20 19:05:14 +02:00
this . player . inventory . items [ this . player . inventory . itemInHandIndex ] = null ;
2011-09-15 02:23:52 +02:00
itemstack = null ;
2010-12-28 22:52:39 +01:00
}
2012-07-29 09:33:13 +02:00
if ( itemstack = = null | | itemstack . m ( ) = = 0 ) {
2011-09-15 02:23:52 +02:00
this . player . h = true ;
this . player . inventory . items [ this . player . inventory . itemInHandIndex ] = ItemStack . b ( this . player . inventory . items [ this . player . inventory . itemInHandIndex ] ) ;
2011-11-20 09:01:14 +01:00
Slot slot = this . player . activeContainer . a ( ( IInventory ) this . player . inventory , this . player . inventory . itemInHandIndex ) ;
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
this . player . activeContainer . b ( ) ;
2011-09-15 02:23:52 +02:00
this . player . h = false ;
2012-01-12 12:02:39 +01:00
// 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
2012-07-29 09:33:13 +02:00
if ( ! ItemStack . matches ( this . player . inventory . getItemInHand ( ) , packet15place . getItemStack ( ) ) | | always ) {
2012-10-25 05:53:23 +02:00
this . sendPacket ( new Packet103SetSlot ( this . player . activeContainer . windowId , slot . g , this . player . inventory . getItemInHand ( ) ) ) ;
2011-09-15 02:23:52 +02:00
}
2010-12-28 22:52:39 +01:00
}
}
2011-01-10 02:36:19 +01:00
2011-01-29 22:50:29 +01:00
public void a ( String s , Object [ ] aobject ) {
2011-06-27 00:25:01 +02:00
if ( this . disconnected ) return ; // CraftBukkit - rarely it would send a disconnect line twice
2011-04-20 19:05:14 +02:00
2012-01-14 21:03:48 +01:00
logger . info ( this . player . name + " lost connection: " + s ) ;
2011-04-26 04:36:55 +02:00
// CraftBukkit start - we need to handle custom quit messages
2012-07-29 09:33:13 +02:00
String quitMessage = this . minecraftServer . getServerConfigurationManager ( ) . disconnect ( this . player ) ;
2011-11-28 07:21:35 +01:00
if ( ( quitMessage ! = null ) & & ( quitMessage . length ( ) > 0 ) ) {
2012-07-29 09:33:13 +02:00
this . minecraftServer . getServerConfigurationManager ( ) . sendAll ( new Packet3Chat ( quitMessage ) ) ;
2011-04-26 04:36:55 +02:00
}
// CraftBukkit end
2011-04-20 19:05:14 +02:00
this . disconnected = true ;
2012-10-25 05:53:23 +02:00
if ( this . minecraftServer . I ( ) & & this . player . name . equals ( this . minecraftServer . H ( ) ) ) {
2012-07-29 09:33:13 +02:00
logger . info ( " Stopping singleplayer server as player logged out " ) ;
this . minecraftServer . safeShutdown ( ) ;
}
2010-12-28 22:52:39 +01:00
}
2012-02-29 22:31:04 +01:00
public void onUnhandledPacket ( Packet packet ) {
2011-12-28 01:57:54 +01:00
if ( this . disconnected ) return ; // CraftBukkit
2012-01-14 21:03:48 +01:00
logger . warning ( this . getClass ( ) + " wasn \ 't prepared to deal with a " + packet . getClass ( ) ) ;
2011-04-20 19:05:14 +02:00
this . disconnect ( " Protocol error, unexpected packet " ) ;
2010-12-28 22:52:39 +01:00
}
2011-04-20 19:05:14 +02:00
public void sendPacket ( Packet packet ) {
2012-07-29 09:33:13 +02:00
if ( packet instanceof Packet3Chat ) {
Packet3Chat packet3chat = ( Packet3Chat ) packet ;
int i = this . player . getChatFlags ( ) ;
if ( i = = 2 ) {
return ;
}
if ( i = = 1 & & ! packet3chat . isServer ( ) ) {
return ;
}
// CraftBukkit start
String message = packet3chat . message ;
2012-07-22 08:18:00 +02:00
for ( final String line : org . bukkit . craftbukkit . TextWrapper . wrapText ( message ) ) {
2011-06-27 00:25:01 +02:00
this . networkManager . queue ( new Packet3Chat ( line ) ) ;
2011-04-25 18:14:06 +02:00
}
2012-07-29 09:33:13 +02:00
return ;
// CraftBukkit end
}
// CraftBukkit start
if ( packet = = null ) {
return ;
} else if ( packet instanceof Packet6SpawnPosition ) {
Packet6SpawnPosition packet6 = ( Packet6SpawnPosition ) packet ;
this . player . compassTarget = new Location ( this . getPlayer ( ) . getWorld ( ) , packet6 . x , packet6 . y , packet6 . z ) ;
} else if ( packet . lowPriority = = true ) {
2011-07-26 18:03:52 +02:00
// Reroute all low-priority packets through to compression thread.
2012-07-22 08:18:00 +02:00
org . bukkit . craftbukkit . ChunkCompressionThread . sendPacket ( this . player , packet ) ;
2012-07-29 09:33:13 +02:00
return ;
2011-03-25 21:22:03 +01:00
}
2011-05-14 16:29:42 +02:00
// CraftBukkit end
2012-07-29 09:33:13 +02:00
this . networkManager . queue ( packet ) ;
2010-12-28 22:52:39 +01:00
}
public void a ( Packet16BlockItemSwitch packet16blockitemswitch ) {
2011-10-01 06:15:45 +02:00
// CraftBukkit start
if ( this . player . dead ) return ;
2011-05-12 16:22:52 +02:00
2012-01-14 21:03:48 +01:00
if ( packet16blockitemswitch . itemInHandIndex > = 0 & & packet16blockitemswitch . itemInHandIndex < PlayerInventory . getHotbarSize ( ) ) {
2011-06-27 00:25:01 +02:00
PlayerItemHeldEvent event = new PlayerItemHeldEvent ( this . getPlayer ( ) , this . player . inventory . itemInHandIndex , packet16blockitemswitch . itemInHandIndex ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-04-20 19:05:14 +02:00
// CraftBukkit end
2011-05-14 16:29:42 +02:00
2011-04-20 19:05:14 +02:00
this . player . inventory . itemInHandIndex = packet16blockitemswitch . itemInHandIndex ;
} else {
2012-01-14 21:03:48 +01:00
logger . warning ( this . player . name + " tried to set an invalid carried item " ) ;
2012-03-22 07:55:50 +01:00
this . disconnect ( " Nope! " ) ; // CraftBukkit
2011-04-20 19:05:14 +02:00
}
2010-12-28 22:52:39 +01:00
}
public void a ( Packet3Chat packet3chat ) {
2012-07-29 09:33:13 +02:00
if ( this . player . getChatFlags ( ) = = 2 ) {
this . sendPacket ( new Packet3Chat ( " Cannot send chat message. " ) ) ;
2010-12-28 22:52:39 +01:00
} else {
2012-07-29 09:33:13 +02:00
String s = packet3chat . message ;
if ( s . length ( ) > 100 ) {
this . disconnect ( " Chat message too long " ) ;
} else {
s = s . trim ( ) ;
for ( int i = 0 ; i < s . length ( ) ; + + i ) {
if ( ! SharedConstants . isAllowedChatCharacter ( s . charAt ( i ) ) ) {
this . disconnect ( " Illegal characters in chat " ) ;
return ;
}
}
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
// CraftBukkit start
if ( this . player . getChatFlags ( ) = = 1 ) {
this . sendPacket ( new Packet3Chat ( " Cannot send chat message. " ) ) ;
2011-01-29 22:50:29 +01:00
return ;
}
2011-01-01 14:06:04 +01:00
2012-08-03 13:24:55 +02:00
this . chat ( s , packet3chat . a_ ( ) ) ;
2012-07-29 09:33:13 +02:00
}
2011-02-17 06:46:01 +01:00
}
}
2011-02-20 13:38:27 +01:00
2012-08-04 12:44:16 +02:00
public void chat ( String s , boolean async ) {
2011-05-26 14:48:22 +02:00
if ( ! this . player . dead ) {
2012-01-15 06:52:46 +01:00
if ( s . length ( ) = = 0 ) {
2012-01-14 21:03:48 +01:00
logger . warning ( this . player . name + " tried to send an empty message " ) ;
2012-08-04 12:44:16 +02:00
return ;
2012-01-15 06:52:46 +01:00
}
2012-01-19 09:32:05 +01:00
if ( getPlayer ( ) . isConversing ( ) ) {
getPlayer ( ) . acceptConversationInput ( s ) ;
2012-08-04 12:44:16 +02:00
return ;
2012-01-19 09:32:05 +01:00
}
2011-05-26 14:48:22 +02:00
if ( s . startsWith ( " / " ) ) {
this . handleCommand ( s ) ;
2012-08-04 12:44:16 +02:00
return ;
2011-05-26 14:48:22 +02:00
} else {
2011-06-27 00:25:01 +02:00
Player player = this . getPlayer ( ) ;
2012-08-03 13:24:55 +02:00
AsyncPlayerChatEvent event = new AsyncPlayerChatEvent ( async , player , s , new LazyPlayerSet ( ) ) ;
2011-06-27 00:25:01 +02:00
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-05-26 14:48:22 +02:00
2012-08-03 13:24:55 +02:00
if ( PlayerChatEvent . getHandlerList ( ) . getRegisteredListeners ( ) . length ! = 0 ) {
// Evil plugins still listening to deprecated event
2012-10-07 22:08:21 +02:00
final PlayerChatEvent queueEvent = new PlayerChatEvent ( player , event . getMessage ( ) , event . getFormat ( ) , event . getRecipients ( ) ) ;
2012-08-03 13:24:55 +02:00
queueEvent . setCancelled ( event . isCancelled ( ) ) ;
2012-10-07 22:08:21 +02:00
Waitable waitable = new Waitable ( ) {
@Override
protected Object evaluate ( ) {
Bukkit . getPluginManager ( ) . callEvent ( queueEvent ) ;
if ( queueEvent . isCancelled ( ) ) {
return null ;
}
String message = String . format ( queueEvent . getFormat ( ) , queueEvent . getPlayer ( ) . getDisplayName ( ) , queueEvent . getMessage ( ) ) ;
NetServerHandler . this . minecraftServer . console . sendMessage ( message ) ;
if ( ( ( LazyPlayerSet ) queueEvent . getRecipients ( ) ) . isLazy ( ) ) {
for ( Object player : NetServerHandler . this . minecraftServer . getServerConfigurationManager ( ) . players ) {
( ( EntityPlayer ) player ) . sendMessage ( message ) ;
}
} else {
for ( Player player : queueEvent . getRecipients ( ) ) {
player . sendMessage ( message ) ;
}
}
return null ;
} } ;
if ( async ) {
minecraftServer . processQueue . add ( waitable ) ;
} else {
waitable . run ( ) ;
}
try {
waitable . get ( ) ;
} catch ( InterruptedException e ) {
Thread . currentThread ( ) . interrupt ( ) ; // This is proper habit for java. If we aren't handling it, pass it on!
} catch ( java . util . concurrent . ExecutionException e ) {
throw new RuntimeException ( " Exception processing chat event " , e . getCause ( ) ) ;
}
2012-08-03 13:24:55 +02:00
} else {
2012-08-04 12:44:16 +02:00
if ( event . isCancelled ( ) ) {
return ;
}
2012-08-03 13:24:55 +02:00
s = String . format ( event . getFormat ( ) , event . getPlayer ( ) . getDisplayName ( ) , event . getMessage ( ) ) ;
minecraftServer . console . sendMessage ( s ) ;
if ( ( ( LazyPlayerSet ) event . getRecipients ( ) ) . isLazy ( ) ) {
for ( Object recipient : minecraftServer . getServerConfigurationManager ( ) . players ) {
( ( EntityPlayer ) recipient ) . sendMessage ( s ) ;
}
} else {
2012-09-14 07:03:47 +02:00
for ( Player recipient : event . getRecipients ( ) ) {
2012-08-03 13:24:55 +02:00
recipient . sendMessage ( s ) ;
}
}
2011-05-26 14:48:22 +02:00
}
2012-01-12 23:10:13 +01:00
}
this . m + = 20 ;
2012-07-29 09:33:13 +02:00
if ( this . m > 200 & & ! this . minecraftServer . getServerConfigurationManager ( ) . isOp ( this . player . name ) ) {
2012-01-12 23:10:13 +01:00
this . disconnect ( " disconnect.spam " ) ;
2011-02-20 13:38:27 +01:00
}
2010-12-28 22:52:39 +01:00
}
2011-02-20 13:38:27 +01:00
2012-08-04 12:44:16 +02:00
return ;
2010-12-28 22:52:39 +01:00
}
2012-07-29 09:33:13 +02:00
// CraftBukkit end
2010-12-28 22:52:39 +01:00
2011-04-20 19:05:14 +02:00
private void handleCommand ( String s ) {
2010-12-28 22:52:39 +01:00
// CraftBukkit start
2011-06-27 00:25:01 +02:00
CraftPlayer player = this . getPlayer ( ) ;
2011-01-29 22:50:29 +01:00
2012-08-03 13:24:55 +02:00
PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent ( player , s , new LazyPlayerSet ( ) ) ;
2011-06-27 00:25:01 +02:00
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-01-10 02:36:19 +01:00
if ( event . isCancelled ( ) ) {
return ;
}
2011-02-18 17:25:56 +01:00
try {
2012-08-25 02:51:51 +02:00
logger . info ( event . getPlayer ( ) . getName ( ) + " issued server command: " + event . getMessage ( ) ) ; // CraftBukkit
2012-08-03 13:24:55 +02:00
if ( this . server . dispatchCommand ( event . getPlayer ( ) , event . getMessage ( ) . substring ( 1 ) ) ) {
2011-05-22 21:24:44 +02:00
return ;
}
2012-07-22 08:18:00 +02:00
} catch ( org . bukkit . command . CommandException ex ) {
player . sendMessage ( org . bukkit . ChatColor . RED + " An internal error occurred while attempting to perform this command " ) ;
Logger . getLogger ( NetServerHandler . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ;
2011-02-18 17:25:56 +01:00
return ;
}
2011-05-14 16:29:42 +02:00
// CraftBukkit end
2010-12-28 22:52:39 +01:00
2012-07-22 08:18:00 +02:00
/ * CraftBukkit start - No longer needed as we have already handled it in server . dispatchServerCommand above .
2012-08-25 02:51:51 +02:00
this . minecraftServer . getCommandHandler ( ) . a ( this . player , s ) ;
2011-08-13 03:13:35 +02:00
// CraftBukkit end */
2010-12-28 22:52:39 +01:00
}
public void a ( Packet18ArmAnimation packet18armanimation ) {
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ; // CraftBukkit
2011-05-12 16:22:52 +02:00
2010-12-28 22:52:39 +01:00
if ( packet18armanimation . b = = 1 ) {
2011-05-14 16:29:42 +02:00
// CraftBukkit start - raytrace to look for 'rogue armswings'
2011-03-23 12:22:13 +01:00
float f = 1 . 0F ;
2011-04-20 19:05:14 +02:00
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 ;
2012-10-25 05:53:23 +02:00
Vec3D vec3d = this . player . world . getVec3DPool ( ) . create ( d0 , d1 , d2 ) ;
2011-04-20 19:05:14 +02:00
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 ) ;
2011-03-23 12:22:13 +01:00
float f7 = f4 * f5 ;
float f8 = f3 * f5 ;
double d3 = 5 . 0D ;
2011-04-20 19:05:14 +02:00
Vec3D vec3d1 = vec3d . add ( ( double ) f7 * d3 , ( double ) f6 * d3 , ( double ) f8 * d3 ) ;
MovingObjectPosition movingobjectposition = this . player . world . rayTrace ( vec3d , vec3d1 , true ) ;
2011-03-23 12:22:13 +01:00
2011-04-20 19:05:14 +02:00
if ( movingobjectposition = = null | | movingobjectposition . type ! = EnumMovingObjectType . TILE ) {
CraftEventFactory . callPlayerInteractEvent ( this . player , Action . LEFT_CLICK_AIR , this . player . inventory . getItemInHand ( ) ) ;
2011-03-23 12:22:13 +01:00
}
// Arm swing animation
2011-06-27 00:25:01 +02:00
PlayerAnimationEvent event = new PlayerAnimationEvent ( this . getPlayer ( ) ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-07-28 16:53:55 +02:00
if ( event . isCancelled ( ) ) return ;
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2012-10-25 05:53:23 +02:00
this . player . bE ( ) ;
2011-01-14 14:31:10 +01:00
}
}
2011-01-29 22:50:29 +01:00
public void a ( Packet19EntityAction packet19entityaction ) {
2011-04-20 19:05:14 +02:00
// CraftBukkit start
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ;
2011-05-12 16:22:52 +02:00
2011-04-20 19:05:14 +02:00
if ( packet19entityaction . animation = = 1 | | packet19entityaction . animation = = 2 ) {
2011-06-27 00:25:01 +02:00
PlayerToggleSneakEvent event = new PlayerToggleSneakEvent ( this . getPlayer ( ) , packet19entityaction . animation = = 1 ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-09-21 12:48:24 +02:00
if ( event . isCancelled ( ) ) {
return ;
}
}
if ( packet19entityaction . animation = = 4 | | packet19entityaction . animation = = 5 ) {
PlayerToggleSprintEvent event = new PlayerToggleSprintEvent ( this . getPlayer ( ) , packet19entityaction . animation = = 4 ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-01-25 19:08:54 +01:00
if ( event . isCancelled ( ) ) {
return ;
}
}
2011-04-20 19:05:14 +02:00
// CraftBukkit end
2011-01-25 19:08:54 +01:00
2011-04-20 19:05:14 +02:00
if ( packet19entityaction . animation = = 1 ) {
2012-07-29 09:33:13 +02:00
this . player . setSneaking ( true ) ;
2011-04-20 19:05:14 +02:00
} else if ( packet19entityaction . animation = = 2 ) {
2012-07-29 09:33:13 +02:00
this . player . setSneaking ( false ) ;
2011-09-15 02:23:52 +02:00
} else if ( packet19entityaction . animation = = 4 ) {
2011-09-24 23:03:31 +02:00
this . player . setSprinting ( true ) ;
2011-09-15 02:23:52 +02:00
} else if ( packet19entityaction . animation = = 5 ) {
2011-09-24 23:03:31 +02:00
this . player . setSprinting ( false ) ;
2011-04-20 19:05:14 +02:00
} else if ( packet19entityaction . animation = = 3 ) {
this . player . a ( false , true , true ) ;
2012-08-06 06:45:38 +02:00
// this.checkMovement = false; // CraftBukkit - this is handled in teleport
2010-12-28 22:52:39 +01:00
}
}
public void a ( Packet255KickDisconnect packet255kickdisconnect ) {
2012-01-19 09:32:05 +01:00
// CraftBukkit start
getPlayer ( ) . disconnect ( " disconnect.quitting " ) ;
// CraftBukkit end
2011-04-20 19:05:14 +02:00
this . networkManager . a ( " disconnect.quitting " , new Object [ 0 ] ) ;
2010-12-28 22:52:39 +01:00
}
2012-01-14 21:03:48 +01:00
public int lowPriorityCount ( ) {
2011-05-26 14:48:22 +02:00
return this . networkManager . e ( ) ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
public void a ( Packet7UseEntity packet7useentity ) {
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ; // CraftBukkit
2011-05-12 16:22:52 +02:00
2011-06-27 00:25:01 +02:00
WorldServer worldserver = this . minecraftServer . getWorldServer ( this . player . dimension ) ;
2011-05-26 14:48:22 +02:00
Entity entity = worldserver . getEntity ( packet7useentity . target ) ;
2010-12-28 22:52:39 +01:00
2012-03-01 11:49:23 +01:00
if ( entity ! = null ) {
2012-10-25 05:53:23 +02:00
boolean flag = this . player . m ( entity ) ;
2012-03-01 11:49:23 +01:00
double d0 = 36 . 0D ;
2011-06-27 00:25:01 +02:00
2012-03-01 11:49:23 +01:00
if ( ! flag ) {
d0 = 9 . 0D ;
}
2012-07-29 09:33:13 +02:00
if ( this . player . e ( entity ) < d0 ) {
2012-03-01 11:49:23 +01:00
ItemStack itemInHand = this . player . inventory . getItemInHand ( ) ; // CraftBukkit
if ( packet7useentity . action = = 0 ) {
// CraftBukkit start
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent ( ( Player ) this . getPlayer ( ) , entity . getBukkitEntity ( ) ) ;
this . server . getPluginManager ( ) . callEvent ( event ) ;
if ( event . isCancelled ( ) ) {
return ;
}
// CraftBukkit end
2012-10-25 05:53:23 +02:00
this . player . o ( entity ) ;
2012-03-01 11:49:23 +01:00
// CraftBukkit start - update the client if the item is an infinite one
if ( itemInHand ! = null & & itemInHand . count < = - 1 ) {
this . player . updateInventory ( this . player . activeContainer ) ;
}
} else if ( packet7useentity . action = = 1 ) {
if ( ( entity instanceof EntityItem ) | | ( entity instanceof EntityExperienceOrb ) | | ( entity instanceof EntityArrow ) ) {
String type = entity . getClass ( ) . getSimpleName ( ) ;
disconnect ( " Attacking an " + type + " is not permitted " ) ;
System . out . println ( " Player " + player . name + " tried to attack an " + type + " , so I have disconnected them for exploiting. " ) ;
return ;
}
2012-01-14 21:03:48 +01:00
2012-03-01 11:49:23 +01:00
this . player . attack ( entity ) ;
2012-01-14 14:27:15 +01:00
2012-03-01 11:49:23 +01:00
if ( itemInHand ! = null & & itemInHand . count < = - 1 ) {
this . player . updateInventory ( this . player . activeContainer ) ;
}
// CraftBukkit end
2011-06-19 07:44:57 +02:00
}
2010-12-28 22:52:39 +01:00
}
}
}
2012-07-29 09:33:13 +02:00
public void a ( Packet205ClientCommand packet205clientcommand ) {
if ( packet205clientcommand . a = = 1 ) {
if ( this . player . viewingCredits ) {
2012-08-04 10:35:53 +02:00
// CraftBukkit start
org . bukkit . craftbukkit . PortalTravelAgent pta = new org . bukkit . craftbukkit . PortalTravelAgent ( ) ;
Location toLocation ;
if ( this . player . getBukkitEntity ( ) . getBedSpawnLocation ( ) = = null ) {
CraftWorld cworld = ( CraftWorld ) this . server . getWorlds ( ) . get ( 0 ) ;
ChunkCoordinates chunkcoordinates = cworld . getHandle ( ) . getSpawn ( ) ;
toLocation = new Location ( cworld , chunkcoordinates . x + 0 . 5 , chunkcoordinates . y , chunkcoordinates . z + 0 . 5 ) ;
this . player . netServerHandler . sendPacket ( new Packet70Bed ( 0 , 0 ) ) ;
} else {
toLocation = this . player . getBukkitEntity ( ) . getBedSpawnLocation ( ) ;
toLocation = new Location ( toLocation . getWorld ( ) , toLocation . getX ( ) + 0 . 5 , toLocation . getY ( ) , toLocation . getZ ( ) + 0 . 5 ) ;
}
PlayerPortalEvent event = new PlayerPortalEvent ( this . player . getBukkitEntity ( ) , this . player . getBukkitEntity ( ) . getLocation ( ) , toLocation , pta , PlayerPortalEvent . TeleportCause . END_PORTAL ) ;
event . useTravelAgent ( false ) ;
2012-10-07 22:08:21 +02:00
Bukkit . getServer ( ) . getPluginManager ( ) . callEvent ( event ) ;
2012-08-04 10:35:53 +02:00
this . player = this . minecraftServer . getServerConfigurationManager ( ) . moveToWorld ( this . player , 0 , true , event . getTo ( ) ) ;
// CraftBukkit end
2012-10-25 05:53:23 +02:00
} else if ( this . player . p ( ) . getWorldData ( ) . isHardcore ( ) ) {
if ( this . minecraftServer . I ( ) & & this . player . name . equals ( this . minecraftServer . H ( ) ) ) {
2012-07-29 09:33:13 +02:00
this . player . netServerHandler . disconnect ( " You have died. Game over, man, it \ 's game over! " ) ;
2012-10-25 05:53:23 +02:00
this . minecraftServer . P ( ) ;
2012-07-29 09:33:13 +02:00
} else {
BanEntry banentry = new BanEntry ( this . player . name ) ;
2012-03-10 06:36:11 +01:00
2012-07-29 09:33:13 +02:00
banentry . setReason ( " Death in Hardcore " ) ;
this . minecraftServer . getServerConfigurationManager ( ) . getNameBans ( ) . add ( banentry ) ;
this . player . netServerHandler . disconnect ( " You have died. Game over, man, it \ 's game over! " ) ;
}
} else {
if ( this . player . getHealth ( ) > 0 ) {
return ;
}
2012-03-09 01:50:01 +01:00
2012-07-29 09:33:13 +02:00
this . player = this . minecraftServer . getServerConfigurationManager ( ) . moveToWorld ( this . player , 0 , false ) ;
2011-11-20 09:01:14 +01:00
}
2010-12-28 22:52:39 +01:00
}
}
2012-07-29 09:33:13 +02:00
public boolean b ( ) {
return true ;
}
2011-05-12 16:22:52 +02:00
2012-07-29 09:33:13 +02:00
public void a ( Packet9Respawn packet9respawn ) { }
2012-02-29 19:56:35 +01:00
2012-07-29 09:33:13 +02:00
public void handleContainerClose ( Packet101CloseWindow packet101closewindow ) {
2012-08-03 09:18:48 +02:00
if ( this . player . dead ) return ; // CraftBukkit
// CraftBukkit start - INVENTORY_CLOSE hook
InventoryCloseEvent event = new InventoryCloseEvent ( this . player . activeContainer . getBukkitView ( ) ) ;
server . getPluginManager ( ) . callEvent ( event ) ;
this . player . activeContainer . transferTo ( this . player . defaultContainer , getPlayer ( ) ) ;
// CraftBukkit end
2012-10-25 05:53:23 +02:00
this . player . k ( ) ;
2010-12-28 22:52:39 +01:00
}
2011-01-29 22:50:29 +01:00
public void a ( Packet102WindowClick packet102windowclick ) {
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ; // CraftBukkit
2011-05-12 16:22:52 +02:00
2012-07-29 09:33:13 +02:00
if ( this . player . activeContainer . windowId = = packet102windowclick . a & & this . player . activeContainer . b ( this . player ) ) {
2012-02-29 19:56:35 +01:00
// CraftBukkit start - fire InventoryClickEvent
InventoryView inventory = this . player . activeContainer . getBukkitView ( ) ;
2012-02-29 22:31:04 +01:00
SlotType type = CraftInventoryView . getSlotType ( inventory , packet102windowclick . slot ) ;
2012-02-29 19:56:35 +01:00
2012-10-25 05:53:23 +02:00
InventoryClickEvent event = new InventoryClickEvent ( inventory , type , packet102windowclick . slot , packet102windowclick . button ! = 0 , packet102windowclick . shift = = 1 ) ;
2012-07-22 08:18:00 +02:00
org . bukkit . inventory . Inventory top = inventory . getTopInventory ( ) ;
2012-03-18 17:25:39 +01:00
if ( packet102windowclick . slot = = 0 & & top instanceof CraftingInventory ) {
2012-07-22 08:18:00 +02:00
org . bukkit . inventory . Recipe recipe = ( ( CraftingInventory ) top ) . getRecipe ( ) ;
2012-03-18 17:25:39 +01:00
if ( recipe ! = null ) {
2012-10-25 05:53:23 +02:00
event = new CraftItemEvent ( recipe , inventory , type , packet102windowclick . slot , packet102windowclick . button ! = 0 , packet102windowclick . shift = = 1 ) ;
2012-03-18 17:25:39 +01:00
}
2012-02-29 19:56:35 +01:00
}
server . getPluginManager ( ) . callEvent ( event ) ;
ItemStack itemstack = null ;
boolean defaultBehaviour = false ;
switch ( event . getResult ( ) ) {
case DEFAULT :
2012-02-29 22:31:04 +01:00
itemstack = this . player . activeContainer . clickItem ( packet102windowclick . slot , packet102windowclick . button , packet102windowclick . shift , this . player ) ;
2012-02-29 19:56:35 +01:00
defaultBehaviour = true ;
break ;
case DENY : // Deny any change, including changes from the event
break ;
case ALLOW : // Allow changes unconditionally
org . bukkit . inventory . ItemStack cursor = event . getCursor ( ) ;
if ( cursor = = null ) {
2012-02-29 22:31:04 +01:00
this . player . inventory . setCarried ( ( ItemStack ) null ) ;
2012-02-29 19:56:35 +01:00
} else {
2012-02-29 22:31:04 +01:00
this . player . inventory . setCarried ( CraftItemStack . createNMSItemStack ( cursor ) ) ;
2012-02-29 19:56:35 +01:00
}
org . bukkit . inventory . ItemStack item = event . getCurrentItem ( ) ;
if ( item ! = null ) {
itemstack = CraftItemStack . createNMSItemStack ( item ) ;
2012-02-29 22:31:04 +01:00
if ( packet102windowclick . slot = = - 999 ) {
this . player . drop ( itemstack ) ;
2012-02-29 19:56:35 +01:00
} else {
2012-02-29 22:31:04 +01:00
this . player . activeContainer . getSlot ( packet102windowclick . slot ) . set ( itemstack ) ;
2012-02-29 19:56:35 +01:00
}
2012-02-29 22:31:04 +01:00
} else if ( packet102windowclick . slot ! = - 999 ) {
this . player . activeContainer . getSlot ( packet102windowclick . slot ) . set ( ( ItemStack ) null ) ;
2012-02-29 19:56:35 +01:00
}
break ;
}
// CraftBukkit end
2011-05-14 16:29:42 +02:00
2012-07-29 09:33:13 +02:00
if ( ItemStack . matches ( packet102windowclick . item , itemstack ) ) {
this . player . netServerHandler . sendPacket ( new Packet106Transaction ( packet102windowclick . a , packet102windowclick . d , true ) ) ;
2011-04-20 19:05:14 +02:00
this . player . h = true ;
2012-07-29 09:33:13 +02:00
this . player . activeContainer . b ( ) ;
2012-02-29 22:31:04 +01:00
this . player . broadcastCarriedItem ( ) ;
2011-04-20 19:05:14 +02:00
this . player . h = false ;
2010-12-28 22:52:39 +01:00
} else {
2012-03-01 11:49:23 +01:00
this . s . a ( this . player . activeContainer . windowId , Short . valueOf ( packet102windowclick . d ) ) ;
2011-04-20 19:05:14 +02:00
this . player . netServerHandler . sendPacket ( new Packet106Transaction ( packet102windowclick . a , packet102windowclick . d , false ) ) ;
this . player . activeContainer . a ( this . player , false ) ;
2011-01-11 09:25:13 +01:00
ArrayList arraylist = new ArrayList ( ) ;
2010-12-28 22:52:39 +01:00
2012-07-29 09:33:13 +02:00
for ( int i = 0 ; i < this . player . activeContainer . b . size ( ) ; + + i ) {
arraylist . add ( ( ( Slot ) this . player . activeContainer . b . get ( i ) ) . getItem ( ) ) ;
2010-12-28 22:52:39 +01:00
}
2011-04-20 19:05:14 +02:00
this . player . a ( this . player . activeContainer , arraylist ) ;
2012-02-29 19:56:35 +01:00
// CraftBukkit start - send a Set Slot to update the crafting result slot
if ( type = = SlotType . RESULT & & itemstack ! = null )
this . player . netServerHandler . sendPacket ( ( Packet ) ( new Packet103SetSlot ( this . player . activeContainer . windowId , 0 , itemstack ) ) ) ;
// CraftBukkit end
2010-12-28 22:52:39 +01:00
}
}
}
2011-11-30 00:17:43 +01:00
public void a ( Packet108ButtonClick packet108buttonclick ) {
2012-07-29 09:33:13 +02:00
if ( this . player . activeContainer . windowId = = packet108buttonclick . a & & this . player . activeContainer . b ( this . player ) ) {
2011-11-30 00:17:43 +01:00
this . player . activeContainer . a ( ( EntityHuman ) this . player , packet108buttonclick . b ) ;
2012-07-29 09:33:13 +02:00
this . player . activeContainer . b ( ) ;
2011-11-20 09:01:14 +01:00
}
}
2011-09-15 02:23:52 +02:00
public void a ( Packet107SetCreativeSlot packet107setcreativeslot ) {
2012-01-14 21:03:48 +01:00
if ( this . player . itemInWorldManager . isCreative ( ) ) {
2012-02-29 22:31:04 +01:00
boolean flag = packet107setcreativeslot . slot < 0 ;
2011-11-20 09:01:14 +01:00
ItemStack itemstack = packet107setcreativeslot . b ;
2012-07-29 09:33:13 +02:00
boolean flag1 = packet107setcreativeslot . slot > = 1 & & packet107setcreativeslot . slot < 36 + PlayerInventory . getHotbarSize ( ) ;
2012-02-29 22:31:04 +01:00
// CraftBukkit
boolean flag2 = itemstack = = null | | itemstack . id < Item . byId . length & & itemstack . id > = 0 & & Item . byId [ itemstack . id ] ! = null & & ! invalidItems . contains ( itemstack . id ) ;
2011-11-20 09:01:14 +01:00
boolean flag3 = itemstack = = null | | itemstack . getData ( ) > = 0 & & itemstack . getData ( ) > = 0 & & itemstack . count < = 64 & & itemstack . count > 0 ;
2012-02-29 19:56:35 +01:00
// CraftBukkit start - Fire INVENTORY_CLICK event
2012-07-22 08:18:00 +02:00
org . bukkit . entity . HumanEntity player = this . player . getBukkitEntity ( ) ;
2012-02-29 19:56:35 +01:00
InventoryView inventory = new CraftInventoryView ( player , player . getInventory ( ) , this . player . defaultContainer ) ;
SlotType slot = SlotType . QUICKBAR ;
2012-02-29 22:31:04 +01:00
if ( packet107setcreativeslot . slot = = - 1 ) {
2012-02-29 19:56:35 +01:00
slot = SlotType . OUTSIDE ;
}
2012-02-29 22:31:04 +01:00
InventoryClickEvent event = new InventoryClickEvent ( inventory , slot , slot = = SlotType . OUTSIDE ? - 999 : packet107setcreativeslot . slot , false , false ) ;
2012-02-29 19:56:35 +01:00
server . getPluginManager ( ) . callEvent ( event ) ;
org . bukkit . inventory . ItemStack item = event . getCurrentItem ( ) ;
2012-02-29 22:31:04 +01:00
switch ( event . getResult ( ) ) {
case ALLOW :
2012-02-29 19:56:35 +01:00
if ( slot = = SlotType . QUICKBAR ) {
if ( item = = null ) {
2012-02-29 22:31:04 +01:00
this . player . defaultContainer . setItem ( packet107setcreativeslot . slot , ( ItemStack ) null ) ;
2012-02-29 19:56:35 +01:00
} else {
2012-02-29 22:31:04 +01:00
this . player . defaultContainer . setItem ( packet107setcreativeslot . slot , CraftItemStack . createNMSItemStack ( item ) ) ;
2012-02-29 19:56:35 +01:00
}
} else if ( item ! = null ) {
2012-02-29 22:31:04 +01:00
this . player . drop ( CraftItemStack . createNMSItemStack ( item ) ) ;
2011-09-15 02:23:52 +02:00
}
2012-02-29 22:31:04 +01:00
return ;
case DENY :
2012-02-29 19:56:35 +01:00
// TODO: Will this actually work?
2012-02-29 22:31:04 +01:00
if ( packet107setcreativeslot . slot > - 1 ) {
this . player . netServerHandler . sendPacket ( new Packet103SetSlot ( this . player . defaultContainer . windowId , packet107setcreativeslot . slot , CraftItemStack . createNMSItemStack ( item ) ) ) ;
2012-02-29 19:56:35 +01:00
}
2012-02-29 22:31:04 +01:00
return ;
case DEFAULT :
// We do the stuff below
break ;
default :
return ;
}
// CraftBukkit end
if ( flag1 & & flag2 & & flag3 ) {
if ( itemstack = = null ) {
this . player . defaultContainer . setItem ( packet107setcreativeslot . slot , ( ItemStack ) null ) ;
} else {
this . player . defaultContainer . setItem ( packet107setcreativeslot . slot , itemstack ) ;
2012-02-29 19:56:35 +01:00
}
2012-02-29 22:31:04 +01:00
this . player . defaultContainer . a ( this . player , true ) ;
2012-03-01 11:49:23 +01:00
} else if ( flag & & flag2 & & flag3 & & this . x < 200 ) {
this . x + = 20 ;
EntityItem entityitem = this . player . drop ( itemstack ) ;
if ( entityitem ! = null ) {
2012-10-25 05:53:23 +02:00
entityitem . c ( ) ;
2012-03-01 11:49:23 +01:00
}
2012-02-29 22:31:04 +01:00
}
2011-09-15 02:23:52 +02:00
}
}
2011-01-29 22:50:29 +01:00
public void a ( Packet106Transaction packet106transaction ) {
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ; // CraftBukkit
2012-03-01 11:49:23 +01:00
Short oshort = ( Short ) this . s . get ( this . player . activeContainer . windowId ) ;
2010-12-28 22:52:39 +01:00
2012-07-29 09:33:13 +02:00
if ( oshort ! = null & & packet106transaction . b = = oshort . shortValue ( ) & & this . player . activeContainer . windowId = = packet106transaction . a & & ! this . player . activeContainer . b ( this . player ) ) {
2011-04-20 19:05:14 +02:00
this . player . activeContainer . a ( this . player , true ) ;
2010-12-28 22:52:39 +01:00
}
}
2011-01-29 22:50:29 +01:00
public void a ( Packet130UpdateSign packet130updatesign ) {
2011-06-27 00:25:01 +02:00
if ( this . player . dead ) return ; // CraftBukkit
WorldServer worldserver = this . minecraftServer . getWorldServer ( this . player . dimension ) ;
2011-05-12 16:22:52 +02:00
2011-05-26 14:48:22 +02:00
if ( worldserver . isLoaded ( packet130updatesign . x , packet130updatesign . y , packet130updatesign . z ) ) {
TileEntity tileentity = worldserver . getTileEntity ( packet130updatesign . x , packet130updatesign . y , packet130updatesign . z ) ;
2011-04-20 19:05:14 +02:00
2011-03-09 00:18:14 +01:00
if ( tileentity instanceof TileEntitySign ) {
2011-04-20 19:05:14 +02:00
TileEntitySign tileentitysign = ( TileEntitySign ) tileentity ;
2012-07-29 09:33:13 +02:00
if ( ! tileentitysign . a ( ) ) {
2011-11-20 09:01:14 +01:00
this . minecraftServer . warning ( " Player " + this . player . name + " just tried to change non-editable sign " ) ;
2012-07-22 08:18:00 +02:00
this . sendPacket ( new Packet130UpdateSign ( packet130updatesign . x , packet130updatesign . y , packet130updatesign . z , tileentitysign . lines ) ) ; // CraftBukkit
2011-03-09 00:18:14 +01:00
return ;
}
2011-05-14 16:29:42 +02:00
}
2011-01-29 22:50:29 +01:00
2011-05-14 16:29:42 +02:00
int i ;
int j ;
2010-12-28 22:52:39 +01:00
2011-05-14 16:29:42 +02:00
for ( j = 0 ; j < 4 ; + + j ) {
boolean flag = true ;
2010-12-28 22:52:39 +01:00
2011-05-14 16:29:42 +02:00
if ( packet130updatesign . lines [ j ] . length ( ) > 15 ) {
flag = false ;
} else {
for ( i = 0 ; i < packet130updatesign . lines [ j ] . length ( ) ; + + i ) {
2011-11-30 00:17:43 +01:00
if ( SharedConstants . allowedCharacters . indexOf ( packet130updatesign . lines [ j ] . charAt ( i ) ) < 0 ) {
2011-05-14 16:29:42 +02:00
flag = false ;
2010-12-28 22:52:39 +01:00
}
}
2011-05-14 16:29:42 +02:00
}
2011-01-29 22:50:29 +01:00
2011-05-14 16:29:42 +02:00
if ( ! flag ) {
packet130updatesign . lines [ j ] = " !? " ;
2010-12-28 22:52:39 +01:00
}
2011-05-14 16:29:42 +02:00
}
2011-01-29 22:50:29 +01:00
2011-05-14 16:29:42 +02:00
if ( tileentity instanceof TileEntitySign ) {
j = packet130updatesign . x ;
int k = packet130updatesign . y ;
2010-12-28 22:52:39 +01:00
2011-05-14 16:29:42 +02:00
i = packet130updatesign . z ;
TileEntitySign tileentitysign1 = ( TileEntitySign ) tileentity ;
2011-02-23 13:56:36 +01:00
2011-05-14 16:29:42 +02:00
// CraftBukkit start
2011-06-27 00:25:01 +02:00
Player player = this . server . getPlayer ( this . player ) ;
2012-07-22 08:18:00 +02:00
SignChangeEvent event = new SignChangeEvent ( ( org . bukkit . craftbukkit . block . CraftBlock ) player . getWorld ( ) . getBlockAt ( j , k , i ) , this . server . getPlayer ( this . player ) , packet130updatesign . lines ) ;
2011-06-27 00:25:01 +02:00
this . server . getPluginManager ( ) . callEvent ( event ) ;
2011-02-11 03:15:59 +01:00
2011-05-14 16:29:42 +02:00
if ( ! event . isCancelled ( ) ) {
for ( int l = 0 ; l < 4 ; + + l ) {
tileentitysign1 . lines [ l ] = event . getLine ( l ) ;
2012-08-18 14:50:09 +02:00
if ( tileentitysign1 . lines [ l ] = = null ) {
tileentitysign1 . lines [ l ] = " " ;
}
2011-05-14 16:29:42 +02:00
}
2011-12-20 22:44:08 +01:00
tileentitysign1 . isEditable = false ;
2010-12-28 22:52:39 +01:00
}
2011-05-14 16:29:42 +02:00
// CraftBukkit end
tileentitysign1 . update ( ) ;
2011-05-26 14:48:22 +02:00
worldserver . notify ( j , k , i ) ;
2010-12-28 22:52:39 +01:00
}
}
}
2011-04-20 22:47:26 +02:00
2011-09-15 02:23:52 +02:00
public void a ( Packet0KeepAlive packet0keepalive ) {
if ( packet0keepalive . a = = this . i ) {
2011-09-15 05:13:14 +02:00
int i = ( int ) ( System . nanoTime ( ) / 1000000L - this . j ) ;
2011-09-15 02:23:52 +02:00
2012-01-12 16:27:39 +01:00
this . player . ping = ( this . player . ping * 3 + i ) / 4 ;
2011-09-15 02:23:52 +02:00
}
}
2012-07-29 09:33:13 +02:00
public boolean a ( ) {
2011-04-20 22:47:26 +02:00
return true ;
}
2012-01-13 09:52:26 +01:00
2012-03-22 21:39:39 +01:00
public void a ( Packet202Abilities packet202abilities ) {
2012-05-25 23:38:03 +02:00
// CraftBukkit start
2012-07-29 09:33:13 +02:00
if ( this . player . abilities . canFly & & this . player . abilities . isFlying ! = packet202abilities . f ( ) ) {
PlayerToggleFlightEvent event = new PlayerToggleFlightEvent ( this . server . getPlayer ( this . player ) , packet202abilities . f ( ) ) ;
2012-05-25 23:38:03 +02:00
this . server . getPluginManager ( ) . callEvent ( event ) ;
if ( ! event . isCancelled ( ) ) {
2012-07-29 09:33:13 +02:00
this . player . abilities . isFlying = packet202abilities . f ( ) ; // Actually set the player's flying status
2012-05-25 23:38:03 +02:00
}
else {
this . player . updateAbilities ( ) ; // Tell the player their ability was reverted
}
}
// CraftBukkit end
2012-03-22 21:39:39 +01:00
}
2012-07-29 09:33:13 +02:00
public void a ( Packet203TabComplete packet203tabcomplete ) {
StringBuilder stringbuilder = new StringBuilder ( ) ;
String s ;
for ( Iterator iterator = this . minecraftServer . a ( ( ICommandListener ) 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
}
}
this . player . netServerHandler . sendPacket ( new Packet203TabComplete ( stringbuilder . toString ( ) ) ) ;
}
public void a ( Packet204LocaleAndViewDistance packet204localeandviewdistance ) {
this . player . a ( packet204localeandviewdistance ) ;
}
public void a ( Packet250CustomPayload packet250custompayload ) {
DataInputStream datainputstream ;
ItemStack itemstack ;
ItemStack itemstack1 ;
if ( " MC|BEdit " . equals ( packet250custompayload . tag ) ) {
try {
datainputstream = new DataInputStream ( new ByteArrayInputStream ( packet250custompayload . data ) ) ;
itemstack = Packet . c ( datainputstream ) ;
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 ) {
itemstack1 . setTag ( itemstack . getTag ( ) ) ;
}
} catch ( Exception exception ) {
exception . printStackTrace ( ) ;
}
} else if ( " MC|BSign " . equals ( packet250custompayload . tag ) ) {
2012-01-13 09:52:26 +01:00
try {
2012-07-29 09:33:13 +02:00
datainputstream = new DataInputStream ( new ByteArrayInputStream ( packet250custompayload . data ) ) ;
itemstack = Packet . c ( datainputstream ) ;
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 ) {
2012-10-28 02:44:11 +02:00
// CraftBukkit start
itemstack1 . a ( " author " , new NBTTagString ( " author " , this . player . name ) ) ;
itemstack1 . a ( " title " , new NBTTagString ( " title " , itemstack . getTag ( ) . getString ( " title " ) ) ) ;
itemstack1 . a ( " pages " , itemstack . getTag ( ) . getList ( " pages " ) ) ;
// CraftBukkit end
2012-07-29 09:33:13 +02:00
itemstack1 . id = Item . WRITTEN_BOOK . id ;
}
} catch ( Exception exception1 ) {
// CraftBukkit start
// exception1.printStackTrace();
// CraftBukkit end
}
2012-10-25 05:53:23 +02:00
} else {
int i ;
if ( " MC|TrSel " . equals ( packet250custompayload . tag ) ) {
try {
datainputstream = new DataInputStream ( new ByteArrayInputStream ( packet250custompayload . data ) ) ;
i = datainputstream . readInt ( ) ;
Container container = this . player . activeContainer ;
if ( container instanceof ContainerMerchant ) {
( ( ContainerMerchant ) container ) . b ( i ) ;
}
} catch ( Exception exception2 ) {
exception2 . printStackTrace ( ) ;
}
} else {
int j ;
if ( " MC|AdvCdm " . equals ( packet250custompayload . tag ) ) {
if ( ! this . minecraftServer . getEnableCommandBlock ( ) ) {
this . player . sendMessage ( this . player . a ( " advMode.notEnabled " , new Object [ 0 ] ) ) ;
} 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 ( datainputstream , 256 ) ;
TileEntity tileentity = this . player . world . getTileEntity ( i , j , k ) ;
if ( tileentity ! = null & & tileentity instanceof TileEntityCommand ) {
( ( TileEntityCommand ) tileentity ) . b ( s ) ;
this . player . world . notify ( i , j , k ) ;
this . player . sendMessage ( " Command set: " + s ) ;
}
} catch ( Exception exception3 ) {
exception3 . printStackTrace ( ) ;
}
} else {
this . player . sendMessage ( this . player . a ( " advMode.notAllowed " , new Object [ 0 ] ) ) ;
}
} 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 . d ( ) ) {
slot . a ( 1 ) ;
TileEntityBeacon tileentitybeacon = containerbeacon . d ( ) ;
tileentitybeacon . d ( i ) ;
tileentitybeacon . e ( j ) ;
tileentitybeacon . update ( ) ;
}
} catch ( Exception exception4 ) {
exception4 . printStackTrace ( ) ;
}
}
} 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 ) ) ;
2012-07-29 09:33:13 +02:00
2012-10-25 05:53:23 +02:00
if ( s1 . length ( ) < = 30 ) {
containeranvil . a ( s1 ) ;
}
} else {
containeranvil . a ( " " ) ;
}
2012-07-29 09:33:13 +02:00
}
2012-10-28 05:21:10 +01:00
// CraftBukkit start
else if ( packet250custompayload . tag . equals ( " REGISTER " ) ) {
try {
String channels = new String ( packet250custompayload . data , " UTF8 " ) ;
for ( String channel : channels . split ( " \ 0 " ) ) {
getPlayer ( ) . addChannel ( channel ) ;
}
} catch ( UnsupportedEncodingException ex ) {
Logger . getLogger ( NetServerHandler . class . getName ( ) ) . log ( Level . SEVERE , " Could not parse REGISTER payload in plugin message packet " , ex ) ;
}
} 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 ) {
Logger . getLogger ( NetServerHandler . class . getName ( ) ) . log ( Level . SEVERE , " Could not parse UNREGISTER payload in plugin message packet " , ex ) ;
}
} else {
server . getMessenger ( ) . dispatchIncomingMessage ( player . getBukkitEntity ( ) , packet250custompayload . tag , packet250custompayload . data ) ;
2012-01-13 09:52:26 +01:00
}
2012-10-28 05:21:10 +01:00
// CraftBukkit end
2012-01-13 09:52:26 +01:00
}
}
}
2012-02-29 19:56:35 +01:00
}