Skip to content

Commit

Permalink
Prepare for v2.1a
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Feb 17, 2021
1 parent 099ccbc commit a6285cd
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.efnilite</groupId>
<artifactId>WITP</artifactId>
<version>2.1</version>
<version>2.1a</version>
<build>
<plugins>
<plugin>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/efnilite/witp/WITP.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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!");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/efnilite/witp/api/WITPAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/efnilite/witp/command/MainCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/dev/efnilite/witp/player/ParkourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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");
Expand All @@ -449,15 +449,20 @@ public void save() {
file.createNewFile();
}
FileWriter writer = new FileWriter(file);
gson.toJson(this, writer);
gson.toJson(ParkourPlayer.this, writer);
writer.flush();
writer.close();
}
} catch (IOException | InvalidStatementException ex) {
ex.printStackTrace();
Verbose.error("Error while trying to save the player's data..");
}
});
};
if (async) {
Tasks.asyncTask(runnable);
} else {
runnable.run();
}
}

/**
Expand Down Expand Up @@ -641,10 +646,6 @@ public int getTime(String time) {
}
}

public void nullify() {
generator = null;
}

/**
* Gets the player's {@link ParkourGenerator}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/dev/efnilite/witp/player/ParkourUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ 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()) {
player.getBoard().delete();
}
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()) {
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/efnilite/witp/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/dev/efnilite/witp/util/config/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class Option {
public static List<String> 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;
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit a6285cd

Please sign in to comment.