diff --git a/src/main/java/systems/kscott/randomspawnplus/listeners/RSPFirstJoinListener.java b/src/main/java/systems/kscott/randomspawnplus/listeners/RSPFirstJoinListener.java index 433522e..f214562 100644 --- a/src/main/java/systems/kscott/randomspawnplus/listeners/RSPFirstJoinListener.java +++ b/src/main/java/systems/kscott/randomspawnplus/listeners/RSPFirstJoinListener.java @@ -41,21 +41,31 @@ public void firstJoinHandler(PlayerJoinEvent event) { } else { try { Location spawnLoc = SpawnFinder.getInstance().findSpawn(true); + //by quiquelhappy - Prevent essentials home replace + boolean prevent = false; if (config.getBoolean("essentials-home-on-first-spawn")) { User user = plugin.getEssentials().getUser(player); - user.setHome("home", spawnLoc); - user.save(); + if(!user.hasHome()){ + user.setHome("home", spawnLoc); + user.save(); + } else { + prevent = true; + } } - new BukkitRunnable() { - @Override - public void run() { - RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(spawnLoc, player, SpawnType.FIRST_JOIN); + if(!prevent){ + new BukkitRunnable() { + @Override + public void run() { + RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(spawnLoc, player, SpawnType.FIRST_JOIN); - Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent); - PaperLib.teleportAsync(player, spawnLoc.add(0.5, 0, 0.5)); + Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent); + PaperLib.teleportAsync(player, spawnLoc.add(0.5, 0, 0.5)); - } - }.runTaskLater(plugin, 3); + } + }.runTaskLater(plugin, 3); + } else { + plugin.getLogger().warning("The spawn finder prevented a teleport for " + player.getUniqueId() + ", since essentials sethome is enabled and the player already had a home (perhaps old player data?)."); + } } catch (FinderTimedOutException e) { plugin.getLogger().warning("The spawn finder failed to find a valid spawn, and has not given " + player.getUniqueId() + " a random spawn. If you find this happening a lot, then raise the 'spawn-finder-tries-before-timeout' key in the config."); return;