Skip to content

Commit

Permalink
V1.0.7 patch (#19)
Browse files Browse the repository at this point in the history
- added a missing message; islandReset

- added a world check before clearing the player's inventory

- delayed the island teleportation by half a second

- added additional debug messages to resetBlocks() method

- potentially fixes a bug related to blocks not resetting in certain servers

- reverted the island teleportation delay as it wasn't needed anymore
  • Loading branch information
Tofpu authored Mar 19, 2022
1 parent 674f9b1 commit 249c8ca
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<hover:show_text:'<yellow>Click to run " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,10 +18,6 @@
import org.bukkit.inventory.ItemStack;

public final class GameIsland {
private static final String STYLE =
"<gold>" + MessageUtil.Symbols.WARNING.getSymbol() + "<yellow> ";
private static final String ISLAND_RESET = STYLE + "The island has been reset!";

private final Island island;
private final GamePlayer gamePlayer;
private IslandPlot islandPlot;
Expand Down Expand Up @@ -75,7 +72,7 @@ public void resetGame(final boolean notify) {
64));

if (notify) {
BridgeUtil.sendMessage(player, ISLAND_RESET);
BridgeUtil.sendMessage(player, Message.INSTANCE.islandReset);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<Location> getPlacedBlocks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,17 +37,22 @@ 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;
}

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
Expand Down

0 comments on commit 249c8ca

Please sign in to comment.