Skip to content

Commit

Permalink
Prevent essentials home replace
Browse files Browse the repository at this point in the history
Prevent essentials home replace with players with old player data. This also prevents home replacement sometimes with players who player before but the server is still busy fetching the data. This happened multiple times in quiquelhappy's server, when a server went down and they got moved back to it, they all got their homes replaced because the server had a wrong response on fetching data, teleporting them as if they were new players. This will force-check if the player already has a home.
  • Loading branch information
Dreeam-qwq committed Jun 28, 2022
1 parent 1b90e26 commit de49f0a
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de49f0a

Please sign in to comment.