diff --git a/src/main/java/dev/efnilite/witp/ParkourPlayer.java b/src/main/java/dev/efnilite/witp/ParkourPlayer.java index f8fddb65..0d778bec 100644 --- a/src/main/java/dev/efnilite/witp/ParkourPlayer.java +++ b/src/main/java/dev/efnilite/witp/ParkourPlayer.java @@ -15,6 +15,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; @@ -70,10 +71,12 @@ public ParkourPlayer(@NotNull Player player, int highScore, String time, String this.previousLocation = player.getLocation().clone(); this.previousInventory = new HashMap<>(); int index = 0; - for (ItemStack item : player.getInventory().getContents()) { + Inventory inventory = player.getInventory(); + for (ItemStack item : inventory.getContents()) { if (item != null) { previousInventory.put(index, item); } + index++; } this.useSpecial = showScoreboard; this.showDeathMsg = showDeathMsg; @@ -522,13 +525,17 @@ public static void unregister(@NotNull ParkourPlayer player, boolean sendBack) t player.save(); WITP.getDivider().leave(player); players.remove(player.getPlayer()); - if (WITP.getConfiguration().getFile("config").getBoolean("bungeecord.enabled")) { - Util.sendPlayer(player.getPlayer(), WITP.getConfiguration().getString("config", "bungeecord.return_server")); - } else { - player.getPlayer().getInventory().clear(); - player.getPlayer().teleport(player.getPreviousLocation()); - for (int slot : player.getPreviousInventory().keySet()){ - player.getPlayer().getInventory().setItem(slot, player.getPreviousInventory().get(slot)); + if (sendBack) { + if (WITP.getConfiguration().getFile("config").getBoolean("bungeecord.enabled")) { + Util.sendPlayer(player.getPlayer(), WITP.getConfiguration().getString("config", "bungeecord.return_server")); + } else { + Player pl = player.getPlayer(); + pl.getInventory().clear(); + pl.teleport(player.getPreviousLocation()); + for (int slot : player.getPreviousInventory().keySet()) { + pl.getInventory().setItem(slot, player.getPreviousInventory().get(slot)); + } + pl.resetPlayerTime(); } } } diff --git a/src/main/java/dev/efnilite/witp/generator/ParkourGenerator.java b/src/main/java/dev/efnilite/witp/generator/ParkourGenerator.java index 9c9205e7..0aeb420d 100644 --- a/src/main/java/dev/efnilite/witp/generator/ParkourGenerator.java +++ b/src/main/java/dev/efnilite/witp/generator/ParkourGenerator.java @@ -400,7 +400,7 @@ public void generateNext() { break; case 1: // slab material = Material.SMOOTH_QUARTZ_SLAB.createBlockData(); - height = Math.min(height, 0); + height = 0; // todo allow multiple heights ((Slab) material).setType(Slab.Type.BOTTOM); break; case 2: // pane @@ -413,7 +413,7 @@ public void generateNext() { Location local = lastSpawn.clone(); List possible = getPossible(gap - height, height); if (possible.size() == 0) { - lastSpawn = local; + lastSpawn = local.clone(); return; } @@ -435,7 +435,15 @@ public void generateNext() { case 1: File folder = new File(WITP.getInstance().getDataFolder() + "/structures/"); List files = Arrays.asList(folder.listFiles((dir, name) -> name.contains("parkour-"))); - File structure = files.get(random.nextInt(files.size() - 1)); + File structure; + if (files.size() > 1) { + structure = files.get(random.nextInt(files.size())); + } else if (files.size() == 1) { + structure = files.get(0); + } else { + Verbose.error("No structures to choose from!"); + return; + } structureCooldown = 20; int gapStructure = distanceChances.get(random.nextInt(distanceChances.size())) + 1; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index eae68b90..4b6248a0 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: 1.5 +version: 1.5a api-version: 1.16 main: dev.efnilite.witp.WITP softdepend: [Vault, PlaceholderAPI]