8989import com .sk89q .worldedit .world .entity .EntityType ;
9090import com .sk89q .worldedit .world .entity .EntityTypes ;
9191import net .fabricmc .fabric .api .entity .event .v1 .ServerEntityWorldChangeEvents ;
92- import net .fabricmc .fabric .api .entity .event .v1 .ServerLivingEntityEvents ;
9392import net .fabricmc .fabric .api .entity .event .v1 .ServerPlayerEvents ;
94- import net .fabricmc .fabric .api .event .lifecycle .v1 .ServerEntityEvents ;
9593import net .fabricmc .fabric .api .event .player .PlayerBlockBreakEvents ;
9694import net .fabricmc .fabric .api .event .player .UseBlockCallback ;
9795import net .fabricmc .fabric .api .networking .v1 .ServerLoginConnectionEvents ;
@@ -280,8 +278,11 @@ public PlayerEventListener(
280278 PlayerBlockBreakEvents .AFTER .register (this ::afterBlockBreak );
281279 UseBlockCallback .EVENT .register (PlayerEventListener ::interact );
282280 Stimuli .global ().listen (PlayerCommandEvent .EVENT , PlayerEventListener ::onPlayerCommand );
281+
283282 ServerPlayConnectionEvents .INIT .register (PlayerEventListener ::onLoginInit );
283+
284284 Stimuli .global ().listen (BlockUseEvent .EVENT , this ::onHangingPlace );
285+
285286 Stimuli .global ().listen (EntitySpawnEvent .EVENT , entity -> {
286287 Location location = FabricUtil .adapt (GlobalPos .of (entity .level ().dimension (), entity .blockPosition ()));
287288 PlotArea area = location .getPlotArea ();
@@ -296,50 +297,14 @@ public PlayerEventListener(
296297 }
297298 return InteractionResult .PASS ;
298299 });
300+
299301 Stimuli .global ().listen (EntityDeathEvent .EVENT , this ::onHangingBreakByEntity );
300302 Stimuli .global ().listen (EntityUseEvent .EVENT , this ::onPlayerInteractEntity );
301303 Stimuli .global ().listen (EntityDeathEvent .EVENT , this ::onVehicleDestroy );
302304 Stimuli .global ().listen (EndPortalOpenEvent .EVENT , this ::onEndPortalCreation );
303305 BaseFireBlockOnPlaceCallback .EVENT .register (this ::onNetherPortalCreation );
304306 EntityHandleInsidePortalCallback .EVENT .register (this ::onPortalEnter );
305307 LecternTakeButtonCallback .EVENT .register (this ::onPlayerTakeLecternBook );
306- ServerEntityEvents .ENTITY_LOAD .register ((entity , world ) -> {
307- TaskManager .runTaskLater (() -> {
308- if (entity instanceof ServerPlayer serverPlayer ) {
309- final ServerPlayer player = serverPlayer ;
310- PlotSquared .platform ().playerManager ().removePlayer (player .getUUID ());
311- final PlotPlayer <ServerPlayer > pp = FabricUtil .adapt (player );
312-
313- // we're stripping the country code as we don't want to differ between countries
314- //pp.setLocale(Locale.forLanguageTag(player.getLocale().substring(0, 2)));
315-
316- Location location = pp .getLocation ();
317- PlotArea area = location .getPlotArea ();
318- if (area != null ) {
319- Plot plot = area .getPlot (location );
320- if (plot != null ) {
321- plotListener .plotEntry (pp , plot );
322- }
323- }
324- // Async
325- TaskManager .runTaskLaterAsync (() -> {
326- /* TODO CHECK ON THIS */
327- /*if (!player.hasPlayedBefore() && player.isLocalPlayer()) {
328- player.saveData();
329- }*/
330- this .eventDispatcher .doJoinTask (pp );
331- }, TaskTime .seconds (1L ));
332- }
333- }, TaskTime .seconds (3L ));
334-
335- });
336- ServerLoginConnectionEvents .DISCONNECT .register (this ::onLeave );
337- ServerPlayerEvents .AFTER_RESPAWN .register ((oldPlayer , newPlayer , alive ) -> {
338- ServerPlayer player = newPlayer ;
339- PlotPlayer <ServerPlayer > pp = FabricUtil .adapt (player );
340- this .eventDispatcher .doRespawnTask (pp );
341- });
342-
343308 HandlePlayerMoveCallback .EVENT .register ((serverboundMovePlayerPacket , serverPlayer ) -> {
344309 if (!serverboundMovePlayerPacket .hasPosition ()) {
345310 return InteractionResult .PASS ;
@@ -361,11 +326,11 @@ public PlayerEventListener(
361326 if (MathMan .roundInt (from .pos ().getX ()) != (x2 = MathMan .roundInt (to .pos ().getX ()))) {
362327 ServerPlayer player = serverPlayer ;
363328 FabricPlayer pp ;
364- try {
365- pp = FabricUtil .adapt (player );
366- } catch (Exception e ) {
367- return InteractionResult .PASS ;
368- }
329+ try {
330+ pp = FabricUtil .adapt (player );
331+ } catch (Exception e ) {
332+ return InteractionResult .PASS ;
333+ }
369334 // Cancel teleport
370335 if (TaskManager .removeFromTeleportQueue (pp .getName ())) {
371336 pp .sendMessage (TranslatableCaption .of ("teleport.teleport_failed" ));
@@ -562,6 +527,43 @@ public PlayerEventListener(
562527 }
563528 return InteractionResult .PASS ;
564529 });
530+
531+ ServerPlayConnectionEvents .JOIN .register ((handler , sender , server ) -> {
532+ TaskManager .runTaskLater (() -> {
533+ final ServerPlayer player = handler .player ;
534+ PlotSquared .platform ().playerManager ().removePlayer (player .getUUID ());
535+ final PlotPlayer <ServerPlayer > pp = FabricUtil .adapt (player );
536+
537+ // we're stripping the country code as we don't want to differ between countries
538+ //pp.setLocale(Locale.forLanguageTag(player.getLocale().substring(0, 2)));
539+
540+ Location location = pp .getLocation ();
541+ PlotArea area = location .getPlotArea ();
542+ if (area != null ) {
543+ Plot plot = area .getPlot (location );
544+ if (plot != null ) {
545+ plotListener .plotEntry (pp , plot );
546+ }
547+ }
548+ // Async
549+ TaskManager .runTaskLaterAsync (() -> {
550+ /* TODO CHECK ON THIS */
551+ /*if (!player.hasPlayedBefore() && player.isLocalPlayer()) {
552+ player.saveData();
553+ }*/
554+ this .eventDispatcher .doJoinTask (pp );
555+ }, TaskTime .seconds (1L ));
556+ }, TaskTime .seconds (3L ));
557+
558+ });
559+ ServerPlayConnectionEvents .DISCONNECT .register (this ::onLeave );
560+
561+ ServerPlayerEvents .AFTER_RESPAWN .register ((oldPlayer , newPlayer , alive ) -> {
562+ PlotPlayer <ServerPlayer > pp = FabricUtil .adapt (newPlayer );
563+ this .eventDispatcher .doRespawnTask (pp );
564+ });
565+
566+
565567 ServerPlayerTeleportToCallback .EVENT .register ((serverLevel , x , y , z , set , g , h , serverPlayer ) -> {
566568 ServerPlayer player = serverPlayer ;
567569 //We need to account for bad plugins like NoCheatPlus that teleports player on/before login -_-
@@ -749,8 +751,10 @@ public PlayerEventListener(
749751 //cancel the original message
750752 return InteractionResult .FAIL ;
751753 });
754+
752755 ServerEntityWorldChangeEvents .AFTER_PLAYER_CHANGE_WORLD .register ((player , origin , destination ) -> {
753- TaskManager .runTaskLater (() -> {FabricPlayer pp = FabricUtil .adapt (player );
756+ TaskManager .runTaskLater (() -> {
757+ FabricPlayer pp = FabricUtil .adapt (player );
754758 // Delete last location
755759 Plot plot ;
756760 try (final MetaDataAccess <Plot > lastPlotAccess =
@@ -778,7 +782,8 @@ public PlayerEventListener(
778782 if (plot != null ) {
779783 plotListener .plotEntry (pp , plot );
780784 }
781- }}, TaskTime .seconds (3 ));
785+ }
786+ }, TaskTime .seconds (3 ));
782787
783788 });
784789 Stimuli .global ().listen (PlayerInventoryActionEvent .EVENT , (serverPlayer , i , clickType , i1 ) -> {
@@ -1529,9 +1534,9 @@ public InteractionResult onInventoryClose(
15291534 return InteractionResult .PASS ;
15301535 }
15311536
1532- public void onLeave (ServerLoginPacketListenerImpl handler , MinecraftServer server ) {
1533- TaskManager .removeFromTeleportQueue (handler .getUserName ());
1534- FabricPlayer pp = FabricUtil .adapt (FabricPlatform . SERVER . getPlayerList (). getPlayerByName ( handler .getUserName ()) );
1537+ public void onLeave (ServerGamePacketListenerImpl handler , MinecraftServer server ) {
1538+ TaskManager .removeFromTeleportQueue (handler .player . getName (). getString ());
1539+ FabricPlayer pp = FabricUtil .adapt (handler .player );
15351540 pp .unregister ();
15361541 plotListener .logout (pp .getUUID ());
15371542 }
@@ -1594,7 +1599,10 @@ public InteractionResult onBucketFill(Player player, Level level, InteractionHan
15941599 }
15951600
15961601 public InteractionResult onHangingPlace (ServerPlayer player , InteractionHand hand , BlockHitResult hitResult ) {
1597- if (player .getUseItem ().getItem () instanceof HangingEntityItem || player .getUseItem ().getItem ().equals (Items .PAINTING ) || player .getUseItem ().getItem () instanceof LeadItem ) {
1602+ if (player .getUseItem ().getItem () instanceof HangingEntityItem || player
1603+ .getUseItem ()
1604+ .getItem ()
1605+ .equals (Items .PAINTING ) || player .getUseItem ().getItem () instanceof LeadItem ) {
15981606 Block block = player .serverLevel ().getBlockState (hitResult .getBlockPos ()).getBlock ();
15991607 Location location = FabricUtil .adapt (GlobalPos .of (player .serverLevel ().dimension (), hitResult .getBlockPos ()));
16001608 PlotArea area = location .getPlotArea ();
@@ -1786,7 +1794,9 @@ public InteractionResult onPlayerInteractEntity(
17861794 }
17871795 } else if ((plot != null && !plot .isAdded (pp .getUUID ())) || (plot == null && area
17881796 .isRoadFlags ())) {
1789- final com .sk89q .worldedit .world .entity .EntityType entityType = EntityType .REGISTRY .get (entity .getType ().toShortString ());
1797+ final com .sk89q .worldedit .world .entity .EntityType entityType = EntityType .REGISTRY .get (entity
1798+ .getType ()
1799+ .toShortString ());
17901800
17911801 FlagContainer flagContainer ;
17921802 if (plot == null ) {
0 commit comments