Skip to content

Commit b673630

Browse files
committed
Implement spawn-on-join configuration.
Admins can now specify whether all joining players should be teleported to the user's group spawn when joining the server. Players can be assigned the essentials.spawn-on-join.exempt permission to become exempt from this feature.
1 parent a267fb1 commit b673630

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

Essentials/src/com/earth2me/essentials/ISettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,6 @@ public interface ISettings extends IConf {
243243
boolean isSendFlyEnableOnJoin();
244244

245245
boolean isWorldTimePermissions();
246+
247+
boolean isSpawnOnJoin();
246248
}

Essentials/src/com/earth2me/essentials/Settings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,4 +1163,9 @@ public int getMaxUserCacheCount() {
11631163
public boolean isWorldTimePermissions() {
11641164
return config.getBoolean("world-time-permissions", false);
11651165
}
1166+
1167+
@Override
1168+
public boolean isSpawnOnJoin() {
1169+
return config.getBoolean("spawn-on-join", false);
1170+
}
11661171
}

Essentials/src/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,7 @@ respawn-listener-priority: high
801801
# When users die, should they respawn at their first home or bed, instead of the spawnpoint?
802802
respawn-at-home: false
803803

804+
# Teleport all joining players to the spawnpoint
805+
spawn-on-join: false
806+
804807
# End of file <-- No seriously, you're done with configuration.

EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,27 @@ public void run() {
6868
});
6969
}
7070

71-
public void delayedJoin(Player player) {
71+
public void delayedJoin(final Player player) {
7272
if (player.hasPlayedBefore()) {
7373
LOGGER.log(Level.FINE, "Old player join");
74+
75+
if (ess.getSettings().isSpawnOnJoin()) {
76+
final User user = ess.getUser(player);
77+
if (!user.isAuthorized("essentials.spawn-on-join.exempt")) {
78+
ess.scheduleSyncDelayedTask(new Runnable() {
79+
@Override
80+
public void run() {
81+
Location spawn = spawns.getSpawn(user.getGroup());
82+
try {
83+
user.getTeleport().now(spawn, false, TeleportCause.PLUGIN);
84+
} catch (Exception e) {
85+
ess.showError(user.getSource(), e, "spawn-on-join");
86+
}
87+
}
88+
});
89+
}
90+
}
91+
7492
return;
7593
}
7694

EssentialsSpawn/src/plugin.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ commands:
1515
spawn:
1616
description: Teleport to the spawnpoint.
1717
usage: /<command> [player]
18-
aliases: [espawn]
18+
aliases: [espawn]
19+
permissions:
20+
essentials.spawn-on-join.exempt:
21+
default: false
22+
description: "Bypass spawn teleportation on join when spawn-on-join is true."

0 commit comments

Comments
 (0)