Skip to content

Commit de49f0a

Browse files
committed
Prevent essentials home replace
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.
1 parent 1b90e26 commit de49f0a

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/main/java/systems/kscott/randomspawnplus/listeners/RSPFirstJoinListener.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,31 @@ public void firstJoinHandler(PlayerJoinEvent event) {
4141
} else {
4242
try {
4343
Location spawnLoc = SpawnFinder.getInstance().findSpawn(true);
44+
//by quiquelhappy - Prevent essentials home replace
45+
boolean prevent = false;
4446
if (config.getBoolean("essentials-home-on-first-spawn")) {
4547
User user = plugin.getEssentials().getUser(player);
46-
user.setHome("home", spawnLoc);
47-
user.save();
48+
if(!user.hasHome()){
49+
user.setHome("home", spawnLoc);
50+
user.save();
51+
} else {
52+
prevent = true;
53+
}
4854
}
49-
new BukkitRunnable() {
50-
@Override
51-
public void run() {
52-
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(spawnLoc, player, SpawnType.FIRST_JOIN);
55+
if(!prevent){
56+
new BukkitRunnable() {
57+
@Override
58+
public void run() {
59+
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(spawnLoc, player, SpawnType.FIRST_JOIN);
5360

54-
Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);
55-
PaperLib.teleportAsync(player, spawnLoc.add(0.5, 0, 0.5));
61+
Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);
62+
PaperLib.teleportAsync(player, spawnLoc.add(0.5, 0, 0.5));
5663

57-
}
58-
}.runTaskLater(plugin, 3);
64+
}
65+
}.runTaskLater(plugin, 3);
66+
} else {
67+
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?).");
68+
}
5969
} catch (FinderTimedOutException e) {
6070
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.");
6171
return;

0 commit comments

Comments
 (0)