diff --git a/src/main/java/de/fanta/challenges/challenges/WorldBorderLevelChallenge.java b/src/main/java/de/fanta/challenges/challenges/WorldBorderLevelChallenge.java index 288dcbe..7ffc109 100644 --- a/src/main/java/de/fanta/challenges/challenges/WorldBorderLevelChallenge.java +++ b/src/main/java/de/fanta/challenges/challenges/WorldBorderLevelChallenge.java @@ -18,6 +18,7 @@ import org.bukkit.event.player.PlayerLevelChangeEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.event.world.SpawnChangeEvent; import org.bukkit.generator.structure.Structure; @@ -60,7 +61,6 @@ plugin.saveConfig(); xpSync(e.getPlayer(), true); - if (e.getOldLevel() < e.getNewLevel()) { for (Player pp : Bukkit.getOnlinePlayers()) { pp.playSound(pp.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 0.03f, 1); @@ -120,24 +120,11 @@ World nether = Bukkit.getWorld("world_nether"); if (nether != null) { if (e.getTo().getWorld() == nether) { - if (!Config.getBoolean("worldborderlevelnether")) { - Location fortress = Objects.requireNonNull(nether.locateNearestStructure(nether.getSpawnLocation().set(e.getFrom().getX(), e.getFrom().getY(), e.getFrom().getZ()), Structure.FORTRESS, 10000, false).getLocation()); - nether.setSpawnLocation(fortress); - Config.setValue("worldborderlevelnether", true); - plugin.saveConfig(); - } - Location spawnLocation = nether.getSpawnLocation(); - - if (Config.getString("worldborderlevelnetherspawnlocation.world") == null) { - Config.setValue("worldborderlevelnetherspawnlocation.world", spawnLocation.getWorld().getName()); - Config.setValue("worldborderlevelnetherspawnlocation.X", spawnLocation.getBlockX()); - Config.setValue("worldborderlevelnetherspawnlocation.Z", spawnLocation.getBlockZ()); - plugin.saveConfig(); + if (!Config.getBoolean("worldborderlevelnether")) { + spawnLocation = Objects.requireNonNull(nether.locateNearestStructure(nether.getSpawnLocation().set(e.getFrom().getX(), e.getFrom().getY(), e.getFrom().getZ()), Structure.FORTRESS, 10000, false).getLocation()); } - e.setTo(spawnLocation); - borderSync(); } } World world = Bukkit.getWorld("world"); @@ -147,9 +134,33 @@ e.setTo(spawnLocation); } } + borderSync(); } } + @EventHandler + public void onPortalCreate(PortalCreateEvent e) { + if (Config.getBoolean("worldborderlevel") && plugin.getTimer().isRunning()) { + if (!Config.getBoolean("worldborderlevelnether")) { + World nether = Bukkit.getWorld("world_nether"); + if (e.getWorld() == nether) { + Location spawnLocation = e.getBlocks().get(1).getLocation(); + nether.setSpawnLocation(spawnLocation); + if (Config.getString("worldborderlevelnetherspawnlocation.world") == null) { + Config.setValue("worldborderlevelnetherspawnlocation.world", spawnLocation.getWorld().getName()); + Config.setValue("worldborderlevelnetherspawnlocation.X", spawnLocation.getBlockX()); + Config.setValue("worldborderlevelnetherspawnlocation.Z", spawnLocation.getBlockZ()); + } + Config.setValue("worldborderlevelnether", true); + + borderSync(); + } + + } + } + + } + private void xpSync(Player p, Boolean borderupdate) { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { for (Player player : Bukkit.getOnlinePlayers()) { @@ -166,37 +177,31 @@ public static void borderSync() { int level = Config.getInt("worldborderlevellevel"); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { - Location netherspawnlocation = new Location(Bukkit.getWorld("world_nether"), Config.getDouble("worldborderlevelnetherspawnlocation.X", 0.0), 0, Config.getDouble("worldborderlevelnetherspawnlocation.Z", 0.0)); - Bukkit.getLogger().info("Spawn " + netherspawnlocation.getWorld().getName() + ": " + netherspawnlocation.getX() + " " + netherspawnlocation.getY() + " " + netherspawnlocation.getZ()); - netherBorder.setCenter(netherspawnlocation); - Bukkit.getLogger().info("Border: " + netherBorder.getCenter().getX() + " " + netherBorder.getCenter().getY() + " " + netherBorder.getCenter().getZ()); - - endBorder.setCenter(new Location(Bukkit.getWorld("world_the_end"), 0, 0, 0)); - worldBorder.setCenter(Bukkit.getWorld("world").getSpawnLocation()); - - for (Player player : Bukkit.getOnlinePlayers()) { - if (level > 0) { - worldBorder.setSize(level * 2); - netherBorder.setSize(level * 2); - endBorder.setSize(level * 2); - } else { - worldBorder.setSize(1); - netherBorder.setSize(1); - endBorder.setSize(1); - } - if (player.getWorld().getName().equals("world")) { - player.setWorldBorder(worldBorder); - Bukkit.getLogger().info("world"); - } else if (player.getWorld().getName().equals("world_nether")) { - player.setWorldBorder(netherBorder); - Bukkit.getLogger().info("nether"); - } else { - player.setWorldBorder(endBorder); - Bukkit.getLogger().info("other"); - } + for (Player player : Bukkit.getOnlinePlayers()) { + if (level > 0) { + worldBorder.setSize(level * 2); + netherBorder.setSize(level * 2); + endBorder.setSize(level * 2); + } else { + worldBorder.setSize(1); + netherBorder.setSize(1); + endBorder.setSize(1); } - }, 1L); + if (player.getWorld().getName().equals("world")) { + player.setWorldBorder(worldBorder); + } else if (player.getWorld().getName().equals("world_nether")) { + player.setWorldBorder(netherBorder); + } else { + player.setWorldBorder(endBorder); + } + } + + World world = Bukkit.getWorld("world"); + world.getWorldBorder().setCenter(world.getSpawnLocation()); + + World nether = Bukkit.getWorld("world_nether"); + nether.getWorldBorder().setCenter(nether.getSpawnLocation()); + } }