@@ -1668,8 +1668,8 @@ public boolean onUpdate(int currentTick) {
16681668
16691669 this .lastUpdate = currentTick ;
16701670
1671- if (this .fishing != null ) {
1672- if (this .distance (fishing ) > 80 ) {
1671+ if (this .fishing != null && this . server . getTick () % 20 == 0 ) {
1672+ if (this .distance (fishing ) > 33 ) {
16731673 this .stopFishing (false );
16741674 }
16751675 }
@@ -1729,7 +1729,7 @@ public boolean onUpdate(int currentTick) {
17291729 boolean ignore = block == Block .LADDER || block == Block .VINES || block == Block .COBWEB ;
17301730
17311731 if (!this .hasEffect (Effect .JUMP ) && diff > 0.6 && expectedVelocity < this .speed .y && !ignore ) {
1732- if (this .inAirTicks < 100 ) {
1732+ if (this .inAirTicks < 150 ) {
17331733 this .setMotion (new Vector3 (0 , expectedVelocity , 0 ));
17341734 } else if (this .kick (PlayerKickEvent .Reason .FLYING_DISABLED , "Flying is not enabled on this server" )) {
17351735 return false ;
@@ -2435,7 +2435,7 @@ public void onCompletion(Server server) {
24352435 }
24362436 Block block = target .getSide (face );
24372437 if (block .getId () == Block .FIRE ) {
2438- this .level .setBlock (block , new BlockAir ( ), true );
2438+ this .level .setBlock (block , Block . get ( BlockID . AIR ), true );
24392439 this .level .addLevelSoundEvent (block , LevelSoundEventPacket .SOUND_EXTINGUISH_FIRE );
24402440 break ;
24412441 }
@@ -2793,7 +2793,13 @@ public void onCompletion(Server server) {
27932793 TextPacket textPacket = (TextPacket ) packet ;
27942794
27952795 if (textPacket .type == TextPacket .TYPE_CHAT ) {
2796- this .chat (textPacket .message );
2796+ String chatMessage = textPacket .message ;
2797+ int breakLine = chatMessage .indexOf ('\n' );
2798+ // Chat messages shouldn't contain break lines so ignore text afterwards
2799+ if (breakLine != -1 ) {
2800+ chatMessage = chatMessage .substring (0 , breakLine );
2801+ }
2802+ this .chat (chatMessage );
27972803 }
27982804 break ;
27992805 case ProtocolInfo .CONTAINER_CLOSE_PACKET :
@@ -2879,7 +2885,7 @@ public void onCompletion(Server server) {
28792885 if (itemDrop .getId () != Item .AIR ) {
28802886 vector3 = this .temporalVector .setComponents (itemFrame .x + 0.5 , itemFrame .y , itemFrame .z + 0.5 );
28812887 this .level .dropItem (vector3 , itemDrop );
2882- itemFrame .setItem (new ItemBlock (new BlockAir ( )));
2888+ itemFrame .setItem (new ItemBlock (Block . get ( BlockID . AIR )));
28832889 itemFrame .setItemRotation (0 );
28842890 this .getLevel ().addSound (this , Sound .BLOCK_ITEMFRAME_REMOVE_ITEM );
28852891 }
@@ -3149,13 +3155,13 @@ public void onCompletion(Server server) {
31493155 if (target .onInteract (this , item , useItemOnEntityData .clickPos ) && this .isSurvival ()) {
31503156 if (item .isTool ()) {
31513157 if (item .useOn (target ) && item .getDamage () >= item .getMaxDurability ()) {
3152- item = new ItemBlock (new BlockAir ( ));
3158+ item = new ItemBlock (Block . get ( BlockID . AIR ));
31533159 }
31543160 } else {
31553161 if (item .count > 1 ) {
31563162 item .count --;
31573163 } else {
3158- item = new ItemBlock (new BlockAir ( ));
3164+ item = new ItemBlock (Block . get ( BlockID . AIR ));
31593165 }
31603166 }
31613167
@@ -3201,7 +3207,7 @@ public void onCompletion(Server server) {
32013207
32023208 if (item .isTool () && this .isSurvival ()) {
32033209 if (item .useOn (target ) && item .getDamage () >= item .getMaxDurability ()) {
3204- this .inventory .setItemInHand (new ItemBlock (new BlockAir ( )));
3210+ this .inventory .setItemInHand (new ItemBlock (Block . get ( BlockID . AIR )));
32053211 } else {
32063212 this .inventory .setItemInHand (item );
32073213 }
@@ -3286,6 +3292,45 @@ public void onCompletion(Server server) {
32863292 respawn1 .respawnState = RespawnPacket .STATE_READY_TO_SPAWN ;
32873293 this .dataPacket (respawn1 );
32883294 }
3295+ break ;
3296+ case ProtocolInfo .BOOK_EDIT_PACKET :
3297+ BookEditPacket bookEditPacket = (BookEditPacket ) packet ;
3298+ Item oldBook = this .inventory .getItem (bookEditPacket .inventorySlot );
3299+ if (oldBook .getId () != Item .BOOK_AND_QUILL ) {
3300+ return ;
3301+ }
3302+
3303+ Item newBook = oldBook .clone ();
3304+ boolean success ;
3305+ switch (bookEditPacket .action ) {
3306+ case REPLACE_PAGE :
3307+ success = ((ItemBookAndQuill ) newBook ).setPageText (bookEditPacket .pageNumber , bookEditPacket .text );
3308+ break ;
3309+ case ADD_PAGE :
3310+ success = ((ItemBookAndQuill ) newBook ).insertPage (bookEditPacket .pageNumber , bookEditPacket .text );
3311+ break ;
3312+ case DELETE_PAGE :
3313+ success = ((ItemBookAndQuill ) newBook ).deletePage (bookEditPacket .pageNumber );
3314+ break ;
3315+ case SWAP_PAGES :
3316+ success = ((ItemBookAndQuill ) newBook ).swapPages (bookEditPacket .pageNumber , bookEditPacket .secondaryPageNumber );
3317+ break ;
3318+ case SIGN_BOOK :
3319+ newBook = Item .get (Item .WRITTEN_BOOK , 0 , 1 , oldBook .getCompoundTag ());
3320+ success = ((ItemBookWritten ) newBook ).signBook (bookEditPacket .title , bookEditPacket .author , bookEditPacket .xuid , ItemBookWritten .GENERATION_ORIGINAL );
3321+ break ;
3322+ default :
3323+ return ;
3324+ }
3325+
3326+ if (success ) {
3327+ PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent (this , oldBook , newBook , bookEditPacket .action );
3328+ this .server .getPluginManager ().callEvent (editBookEvent );
3329+ if (!editBookEvent .isCancelled ()) {
3330+ this .inventory .setItem (bookEditPacket .inventorySlot , editBookEvent .getNewBook ());
3331+ }
3332+ }
3333+ break ;
32893334 default :
32903335 break ;
32913336 }
@@ -3818,37 +3863,38 @@ public void kill() {
38183863 PlayerDeathEvent ev = new PlayerDeathEvent (this , this .getDrops (), new TranslationContainer (message , params .toArray (new String [0 ])), this .expLevel );
38193864 ev .setKeepExperience (this .level .gameRules .getBoolean (GameRule .KEEP_INVENTORY ));
38203865 ev .setKeepInventory (ev .getKeepExperience ());
3821- this .server .getPluginManager ().callEvent (ev );
38223866
3823- if (!ev .isCancelled ()) {
3824- if (cause != null && cause .getCause () != DamageCause .VOID ) {
3825- PlayerOffhandInventory offhandInventory = this .getOffhandInventory ();
3826- PlayerInventory playerInventory = this .getInventory ();
3827- if (offhandInventory .getItem (0 ).getId () == Item .TOTEM || playerInventory .getItemInHand ().getId () == Item .TOTEM ) {
3828- this .getLevel ().addLevelEvent (this , LevelEventPacket .EVENT_SOUND_TOTEM );
3829- this .extinguish ();
3830- this .removeAllEffects ();
3831- this .setHealth (1 );
3867+ if (cause != null && cause .getCause () != DamageCause .VOID ) {
3868+ PlayerOffhandInventory offhandInventory = this .getOffhandInventory ();
3869+ PlayerInventory playerInventory = this .getInventory ();
3870+ if (offhandInventory .getItem (0 ).getId () == Item .TOTEM || playerInventory .getItemInHand ().getId () == Item .TOTEM ) {
3871+ this .getLevel ().addLevelEvent (this , LevelEventPacket .EVENT_SOUND_TOTEM );
3872+ this .extinguish ();
3873+ this .removeAllEffects ();
3874+ this .setHealth (1 );
38323875
3833- this .addEffect (Effect .getEffect (Effect .REGENERATION ).setDuration (800 ).setAmplifier (1 ));
3834- this .addEffect (Effect .getEffect (Effect .FIRE_RESISTANCE ).setDuration (800 ).setAmplifier (1 ));
3835- this .addEffect (Effect .getEffect (Effect .ABSORPTION ).setDuration (100 ).setAmplifier (1 ));
3876+ this .addEffect (Effect .getEffect (Effect .REGENERATION ).setDuration (800 ).setAmplifier (1 ));
3877+ this .addEffect (Effect .getEffect (Effect .FIRE_RESISTANCE ).setDuration (800 ).setAmplifier (1 ));
3878+ this .addEffect (Effect .getEffect (Effect .ABSORPTION ).setDuration (100 ).setAmplifier (1 ));
38363879
3837- EntityEventPacket pk = new EntityEventPacket ();
3838- pk .eid = this .getId ();
3839- pk .event = EntityEventPacket .CONSUME_TOTEM ;
3840- this .dataPacket (pk );
3880+ EntityEventPacket pk = new EntityEventPacket ();
3881+ pk .eid = this .getId ();
3882+ pk .event = EntityEventPacket .CONSUME_TOTEM ;
3883+ this .dataPacket (pk );
38413884
3842- if (offhandInventory .getItem (0 ).getId () == Item .TOTEM ) {
3843- offhandInventory .clear (0 );
3844- } else {
3845- playerInventory .clear (playerInventory .getHeldItemIndex ());
3846- }
3847- ev .setCancelled (true );
3848- return ;
3885+ if (offhandInventory .getItem (0 ).getId () == Item .TOTEM ) {
3886+ offhandInventory .clear (0 );
3887+ } else {
3888+ playerInventory .clear (playerInventory .getHeldItemIndex ());
38493889 }
3890+
3891+ ev .setCancelled (true );
38503892 }
3893+ }
38513894
3895+ this .server .getPluginManager ().callEvent (ev );
3896+
3897+ if (!ev .isCancelled ()) {
38523898 if (this .fishing != null ) {
38533899 this .stopFishing (false );
38543900 }
0 commit comments