diff --git a/pom.xml b/pom.xml index 1ca0a357..eaed5f53 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.efnilite WITP - 2.1 + 2.1a diff --git a/src/main/java/dev/efnilite/witp/WITP.java b/src/main/java/dev/efnilite/witp/WITP.java index fa53d75f..a82f3fa4 100644 --- a/src/main/java/dev/efnilite/witp/WITP.java +++ b/src/main/java/dev/efnilite/witp/WITP.java @@ -117,7 +117,7 @@ public void onDisable() { for (ParkourUser user : ParkourUser.getUsers()) { try { - ParkourUser.unregister(user, true, true); + ParkourUser.unregister(user, true, true, false); } catch (IOException | InvalidStatementException ex) { ex.printStackTrace(); Verbose.error("Error while unregistering"); @@ -260,7 +260,7 @@ public void onSwitch(PlayerChangedWorldEvent event) { ParkourUser user = ParkourUser.getUser(event.getPlayer()); if (event.getFrom().getUID() == WITP.getDivider().getWorld().getUID() && user != null && user.getPlayer().getTicksLived() > 100) { try { - ParkourUser.unregister(user, true, false); + ParkourUser.unregister(user, true, false, true); } catch (IOException | InvalidStatementException ex) { ex.printStackTrace(); Verbose.error("Error while trying to unregister player"); @@ -279,7 +279,7 @@ public void leave(PlayerQuitEvent event) { } } try { - ParkourPlayer.unregister(player, true, false); + ParkourPlayer.unregister(player, true, false, true); } catch (IOException | InvalidStatementException ex) { ex.printStackTrace(); Verbose.error("There was an error while trying to handle player " + player.getPlayer().getName() + " quitting!"); diff --git a/src/main/java/dev/efnilite/witp/api/WITPAPI.java b/src/main/java/dev/efnilite/witp/api/WITPAPI.java index 6509e873..1d2bc91b 100644 --- a/src/main/java/dev/efnilite/witp/api/WITPAPI.java +++ b/src/main/java/dev/efnilite/witp/api/WITPAPI.java @@ -57,7 +57,7 @@ public static void unregisterPlayer(@NotNull Player player, boolean sendBack) th Verbose.error("Player " + player.getName() + " isn't registered!"); return; } - ParkourPlayer.unregister(pp, sendBack, false); + ParkourPlayer.unregister(pp, sendBack, false, true); } /** @@ -72,7 +72,7 @@ public static void unregisterPlayer(@NotNull Player player, boolean sendBack) th * @throws IOException If saving the file of the player goes wrong */ public static void unregisterPlayer(@NotNull ParkourPlayer player, boolean sendBack) throws IOException, InvalidStatementException { - ParkourPlayer.unregister(player, sendBack, false); + ParkourPlayer.unregister(player, sendBack, false, true); } /** diff --git a/src/main/java/dev/efnilite/witp/command/MainCommand.java b/src/main/java/dev/efnilite/witp/command/MainCommand.java index 7db303fb..d963f201 100644 --- a/src/main/java/dev/efnilite/witp/command/MainCommand.java +++ b/src/main/java/dev/efnilite/witp/command/MainCommand.java @@ -75,7 +75,7 @@ public boolean execute(CommandSender sender, String[] args) { ParkourPlayer from = gson.fromJson(reader, ParkourPlayer.class); String name = file.getName(); from.uuid = UUID.fromString(name.substring(0, name.lastIndexOf('.'))); - from.save(); + from.save(true); } sender.sendMessage(Util.color("&a&l(!) &7Your players' data has been migrated!")); } else { @@ -104,7 +104,7 @@ public boolean execute(CommandSender sender, String[] args) { if (pp != null) { try { pp.sendTranslated("left"); - ParkourUser.unregister(pp, true, true); + ParkourUser.unregister(pp, true, true, true); } catch (IOException | InvalidStatementException ex) { ex.printStackTrace(); Verbose.error("Error while leaving"); diff --git a/src/main/java/dev/efnilite/witp/player/ParkourPlayer.java b/src/main/java/dev/efnilite/witp/player/ParkourPlayer.java index 576bb37e..2fd97527 100644 --- a/src/main/java/dev/efnilite/witp/player/ParkourPlayer.java +++ b/src/main/java/dev/efnilite/witp/player/ParkourPlayer.java @@ -386,7 +386,7 @@ public void menu() { player.closeInventory(); try { sendTranslated("left"); - ParkourPlayer.unregister(this, true, true); + ParkourPlayer.unregister(this, true, true, true); } catch (IOException | InvalidStatementException ex) { ex.printStackTrace(); Verbose.error("Error while trying to quit player " + player.getName()); @@ -416,14 +416,14 @@ public void menu() { } private void saveStats() { - save(); + save(true); } /** * Saves the player's data to their file */ - public void save() { - Tasks.asyncTask(() -> { + public void save(boolean async) { + Runnable runnable = () -> { try { if (Option.SQL) { Verbose.verbose("Writing player's data to SQL server"); @@ -449,7 +449,7 @@ public void save() { file.createNewFile(); } FileWriter writer = new FileWriter(file); - gson.toJson(this, writer); + gson.toJson(ParkourPlayer.this, writer); writer.flush(); writer.close(); } @@ -457,7 +457,12 @@ public void save() { ex.printStackTrace(); Verbose.error("Error while trying to save the player's data.."); } - }); + }; + if (async) { + Tasks.asyncTask(runnable); + } else { + runnable.run(); + } } /** @@ -641,10 +646,6 @@ public int getTime(String time) { } } - public void nullify() { - generator = null; - } - /** * Gets the player's {@link ParkourGenerator} * diff --git a/src/main/java/dev/efnilite/witp/player/ParkourSpectator.java b/src/main/java/dev/efnilite/witp/player/ParkourSpectator.java index 1e9f0a61..ea3cde0c 100644 --- a/src/main/java/dev/efnilite/witp/player/ParkourSpectator.java +++ b/src/main/java/dev/efnilite/witp/player/ParkourSpectator.java @@ -31,7 +31,7 @@ public ParkourSpectator(@NotNull ParkourUser player, @NotNull ParkourPlayer watc if (player instanceof ParkourPlayer) { try { - ParkourPlayer.unregister(player, false, false); + ParkourPlayer.unregister(player, false, false, true); } catch (IOException | InvalidStatementException ex) { ex.printStackTrace(); Verbose.error("Error while trying to unregister"); diff --git a/src/main/java/dev/efnilite/witp/player/ParkourUser.java b/src/main/java/dev/efnilite/witp/player/ParkourUser.java index b28293b5..a22a4427 100644 --- a/src/main/java/dev/efnilite/witp/player/ParkourUser.java +++ b/src/main/java/dev/efnilite/witp/player/ParkourUser.java @@ -69,7 +69,7 @@ public ParkourUser(@NotNull Player player) { * @throws IOException * When saving the player's file goes wrong */ - public static void unregister(@NotNull ParkourUser player, boolean sendBack, boolean kickIfBungee) throws IOException, InvalidStatementException { + public static void unregister(@NotNull ParkourUser player, boolean sendBack, boolean kickIfBungee, boolean saveAsync) throws IOException, InvalidStatementException { new PlayerLeaveEvent(player).call(); Player pl = player.getPlayer(); if (!player.getBoard().isDeleted()) { @@ -77,8 +77,12 @@ public static void unregister(@NotNull ParkourUser player, boolean sendBack, boo } if (player instanceof ParkourPlayer) { ParkourPlayer pp = (ParkourPlayer) player; - pp.getGenerator().reset(false); - pp.save(); + if (pp.getGenerator() != null) { + pp.getGenerator().reset(false); + } else { + Verbose.error("Generator of player is null while trying to unregister!"); + } + pp.save(saveAsync); WITP.getDivider().leave(pp); players.remove(pl); for (ParkourSpectator spectator : pp.spectators.values()) { @@ -90,7 +94,6 @@ public static void unregister(@NotNull ParkourUser player, boolean sendBack, boo } } pp.spectators.clear(); - pp.nullify(); } else if (player instanceof ParkourSpectator) { ParkourSpectator spectator = (ParkourSpectator) player; spectator.watching.removeSpectators(spectator); @@ -102,7 +105,8 @@ public static void unregister(@NotNull ParkourUser player, boolean sendBack, boo Util.sendPlayer(pl, WITP.getConfiguration().getString("config", "bungeecord.return_server")); } else { if (Option.GO_BACK) { - player.teleport(Option.GO_BACK_LOC); + Location to = Util.parseLocation(WITP.getConfiguration().getString("config", "bungeecord.go-back")); + player.teleport(to); } else { player.teleport(player.previousLocation); } diff --git a/src/main/java/dev/efnilite/witp/util/Util.java b/src/main/java/dev/efnilite/witp/util/Util.java index ab6311fb..da2e453d 100644 --- a/src/main/java/dev/efnilite/witp/util/Util.java +++ b/src/main/java/dev/efnilite/witp/util/Util.java @@ -457,6 +457,11 @@ public static String toString(Location location, boolean formatted) { */ public static Location parseLocation(String location) { String[] values = location.replaceAll("[()]", "").replaceAll(", ", " ").replaceAll(",", " ").split(" "); + World world = Bukkit.getWorld(values[3]); + if (world == null) { + Verbose.error("Detected an invalid world: " + values[3]); + return new Location(Bukkit.getWorlds().get(0), Double.parseDouble(values[0]), Double.parseDouble(values[1]), Double.parseDouble(values[2])); + } return new Location(Bukkit.getWorld(values[3]), Double.parseDouble(values[0]), Double.parseDouble(values[1]), Double.parseDouble(values[2])); } diff --git a/src/main/java/dev/efnilite/witp/util/config/Option.java b/src/main/java/dev/efnilite/witp/util/config/Option.java index 27bbd5a6..5d79789a 100644 --- a/src/main/java/dev/efnilite/witp/util/config/Option.java +++ b/src/main/java/dev/efnilite/witp/util/config/Option.java @@ -57,7 +57,6 @@ public class Option { public static List FOCUS_MODE_WHITELIST; public static boolean GO_BACK; public static boolean BUNGEECORD; - public static Location GO_BACK_LOC; public static boolean JOIN_LEAVE; public static boolean LEAD; @@ -155,7 +154,6 @@ public static void init(boolean init) { FOCUS_MODE_WHITELIST = config.getStringList("focus-mode.whitelist"); GO_BACK = config.getBoolean("bungeecord.go-back-enabled"); - GO_BACK_LOC = Util.parseLocation(config.getString("bungeecord.go-back")); SOUND_TYPE = Sound.valueOf(config.getString("particles.sound-type").toUpperCase()); SOUND_PITCH = config.getInt("particles.sound-pitch"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6d8e9e4b..d8a8ff6e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,7 +22,7 @@ verbose: false bungeecord: # Enabling this will make players who join the server (that's running this plugin) automatically join the game on that server # !! If this is disabled, you have to use /witp join to join and /witp leave to leave. !! - enabled: true + enabled: false # The server the players will be returned to after the game is done return_server: Lobby diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9329338d..32f0dc87 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: 'WITP' description: 'Automatically generating, infinitely long parkour plugin. The sky, and your time, is the limit. The further you go, the harder it gets. Should be a walk in the park, right?' author: Efnilite, Ice_Pancake -version: 2.1 +version: 2.1a api-version: 1.16 main: dev.efnilite.witp.WITP softdepend: [Vault, PlaceholderAPI]