From 491e426ce919ada52adc2417efae58e5a7e91267 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 16 May 2022 18:06:45 -0400 Subject: [PATCH] mapsave bug fixes for windows servers --- .../game/listener/events/PlayerJumpEvent.java | 9 ++++++- .../hideAndSeek/util/PAPIExpansion.java | 3 +++ .../hideAndSeek/world/WorldLoader.java | 26 +++++++++---------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/events/PlayerJumpEvent.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/events/PlayerJumpEvent.java index f42a33c..49920f2 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/events/PlayerJumpEvent.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/events/PlayerJumpEvent.java @@ -26,6 +26,7 @@ import org.bukkit.event.player.PlayerEvent; public class PlayerJumpEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); private boolean cancel = false; public PlayerJumpEvent(Player player) { @@ -44,6 +45,12 @@ public class PlayerJumpEvent extends PlayerEvent implements Cancellable { @Override public HandlerList getHandlers() { - return null; + return handlers; } + + @SuppressWarnings("unused") + public static HandlerList getHandlerList() { + return handlers; + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java b/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java index 896fa61..c1f8c2a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/PAPIExpansion.java @@ -41,6 +41,7 @@ public class PAPIExpansion extends PlaceholderExpansion { if (args.length < 1) return null; if (args[0].equals("stats") && args.length == 2) { PlayerInfo info = database.getGameData().getInfo(player.getUniqueId()); + if (info == null) return placeholderNoData; return getValue(info, args[1]); } else if (args[0].equals("stats") && args.length == 3) { UUID uuid; @@ -62,6 +63,7 @@ public class PAPIExpansion extends PlaceholderExpansion { } else if (args[0].equals("rank-place") && args.length == 2) { if (getRanking(args[1]) == null) { return placeholderError; } PlayerInfo info = database.getGameData().getInfo(player.getUniqueId()); + if (info == null) return placeholderNoData; if (getValue(info, args[1]).equals("0")) { return "-"; } Integer count = database.getGameData().getRanking(getRanking(args[1]), player.getUniqueId()); if (count == null) { return placeholderNoData; } @@ -71,6 +73,7 @@ public class PAPIExpansion extends PlaceholderExpansion { try { uuid = Main.getInstance().getServer().getOfflinePlayer(args[2]).getUniqueId(); } catch (Exception e) { return placeholderError; } if (getRanking(args[1]) == null) { return placeholderError; } PlayerInfo info = database.getGameData().getInfo(player.getUniqueId()); + if (info == null) return placeholderNoData; if (getValue(info, args[1]).equals("0")) { return "-"; } Integer count = database.getGameData().getRanking(getRanking(args[1]), uuid); if (count == null) { return placeholderNoData; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 21b6a76..ebfedcd 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -78,28 +78,28 @@ public class WorldLoader { } public String save() { + World world = Bukkit.getServer().getWorld(mapName); + if(world == null){ + throw new RuntimeException("Invalid world to save: " + mapName); + } File current = new File(Main.getInstance().getWorldContainer()+File.separator+ mapName); if (current.exists()) { try { - File destenation = new File(Main.getInstance().getWorldContainer()+File.separator+ saveName); - File temp_destenation = new File(Main.getInstance().getWorldContainer()+File.separator+"temp_"+ saveName); + File destination = new File(Main.getInstance().getWorldContainer()+File.separator+ saveName); + File temp_destination = new File(Main.getInstance().getWorldContainer()+File.separator+"temp_"+ saveName); copyFileFolder("region",true); copyFileFolder("entities",true); copyFileFolder("datapacks",false); + copyFileFolder("data",false); File srcFile = new File(current, "level.dat"); - File destFile = new File(temp_destenation, "level.dat"); + File destFile = new File(temp_destination, "level.dat"); copyFile(srcFile,destFile); - if (destenation.exists()) { - deleteDirectory(destenation); - if (!destenation.mkdir()) { - throw new RuntimeException("Failed to create directory: "+destenation.getPath()); - } + if (destination.exists()) { + deleteDirectory(destination); } - if(!destenation.delete()){ - throw new RuntimeException("Unable to delete folder: "+destenation.getPath()); - } - if (!temp_destenation.renameTo(destenation)) { - throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath()); + + if (!temp_destination.renameTo(destination)) { + throw new RuntimeException("Failed to rename directory: "+temp_destination.getPath()); } } catch(IOException e) { e.printStackTrace();