diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/Message.java b/src/main/java/io/tofpu/speedbridge2/domain/common/Message.java index 1481f482..7d52d7fb 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/Message.java +++ b/src/main/java/io/tofpu/speedbridge2/domain/common/Message.java @@ -105,8 +105,11 @@ public final class Message { public final String somethingWentWrong = error + "Something went wrong... check " + "your console"; public final String inASetup = error + "You're already in a setup."; - public final String notLoaded = error + "Your data has not been loaded yet. Please " + - "try again later!"; + public final String notLoaded = + error + "Your data has not been loaded yet. Please " + "try again later!"; + + public final String islandReset = + error.replace("red", "yellow") + "The island has " + "been " + "reset!"; private static String runCommand(final String command) { return "Click to run " + diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java b/src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java index f1dad282..80996855 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java +++ b/src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java @@ -240,4 +240,9 @@ public static void whenComplete(final CompletableFuture completableFuture, whenComplete.run(); }); } + + public static void runBukkitSync(final Runnable runnable, final int delay) { + Bukkit.getScheduler().runTaskLater(JavaPlugin.getPlugin(SpeedBridgePlugin.class), + runnable, delay); + } } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java b/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java index 76ed564c..0ec237a0 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java +++ b/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java @@ -1,5 +1,6 @@ package io.tofpu.speedbridge2.domain.island.object.extra; +import io.tofpu.speedbridge2.domain.common.Message; import io.tofpu.speedbridge2.domain.common.config.category.LobbyCategory; import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; @@ -17,10 +18,6 @@ import org.bukkit.inventory.ItemStack; public final class GameIsland { - private static final String STYLE = - "" + MessageUtil.Symbols.WARNING.getSymbol() + " "; - private static final String ISLAND_RESET = STYLE + "The island has been reset!"; - private final Island island; private final GamePlayer gamePlayer; private IslandPlot islandPlot; @@ -75,7 +72,7 @@ public void resetGame(final boolean notify) { 64)); if (notify) { - BridgeUtil.sendMessage(player, ISLAND_RESET); + BridgeUtil.sendMessage(player, Message.INSTANCE.islandReset); } } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java b/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java index a8403a09..dc3fbf68 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java +++ b/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java @@ -82,11 +82,13 @@ private void protectWorld(final @NotNull World world) { // setting the player island slot gamePlayer.setCurrentGame(gameIsland); - // teleports the player to plot + // teleport the player to the island plot gamePlayer.teleport(availablePlot); + // execute the on join method on game island gameIsland.onJoin(); + // return the available plot return availablePlot; } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java b/src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java index c6b7537d..0025139d 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java @@ -1,5 +1,6 @@ package io.tofpu.speedbridge2.domain.player.object; +import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; import io.tofpu.speedbridge2.domain.island.plot.IslandPlot; import org.bukkit.Location; @@ -59,9 +60,16 @@ public void removeBlock(final Block block) { * It iterates through the list of block locations and sets each block to air */ public void resetBlocks() { + BridgeUtil.debug("GamePlayer(): Resetting the blocks now!"); for (final Location blockLocation : this.blockLocations) { - blockLocation.getBlock().setType(Material.AIR); + final Block block = blockLocation.getBlock(); + BridgeUtil.debug("GamePlayer(): Resetting " + block.getType() + " at " + block.getX() + + ", " + block.getY() + ", " + block.getZ() + " location!"); + block.setType(Material.AIR); } + BridgeUtil.debug("GamePlayer(): Finished resetting the blocks! clearing the " + + "block locations " + + "immediately!"); this.blockLocations.clear(); } @@ -165,14 +173,9 @@ public boolean hasTimerStarted() { /** * Remove the player from the game - * - * @return The GamePlayer object that was removed. */ - public GamePlayer remove() { - resetBlocks(); - + public void remove() { GAME_PLAYER_MAP.remove(this.getBridgePlayer().getPlayerUid()); - return this; } public Collection getPlacedBlocks() { diff --git a/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java b/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java index f0494ac9..b952e54d 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java @@ -26,9 +26,6 @@ private void onPlayerJoin(final @NotNull PlayerJoinEvent event) { // from breaking final Player player = event.getPlayer(); - // clears the player's inventory. in-case the PlayerQuitEvent missed it. - player.getInventory().clear(); - playerService.internalRefresh(player); if (player.isOp()) { UpdateChecker.get().updateNotification(player); @@ -40,10 +37,10 @@ private void onPlayerJoin(final @NotNull PlayerJoinEvent event) { private void teleportToLobby(final Player player) { final LobbyCategory lobbyCategory = ConfigurationManager.INSTANCE.getLobbyCategory(); + final Location location = lobbyCategory.getLobbyLocation(); // if teleport_on_join is set to true, teleport the player to the lobby location if (lobbyCategory.isTeleportOnJoin()) { - final Location location = lobbyCategory.getLobbyLocation(); if (location != null) { player.teleport(location); return; @@ -51,6 +48,11 @@ private void teleportToLobby(final Player player) { BridgeUtil.sendMessage(player, Message.INSTANCE.lobbyMissing); } + + if (location != null && player.getWorld().equals(location.getWorld())) { + // clears the player's inventory. in-case the PlayerQuitEvent missed it. + player.getInventory().clear(); + } } @EventHandler(priority = EventPriority.LOWEST) // skipcq: JAVA-W0324