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.
This commit is contained in:
Ali Moghnieh 2016-06-19 21:07:45 +01:00
parent a267fb16b8
commit b673630a7e
5 changed files with 34 additions and 2 deletions

View File

@ -243,4 +243,6 @@ public interface ISettings extends IConf {
boolean isSendFlyEnableOnJoin(); boolean isSendFlyEnableOnJoin();
boolean isWorldTimePermissions(); boolean isWorldTimePermissions();
boolean isSpawnOnJoin();
} }

View File

@ -1163,4 +1163,9 @@ public class Settings implements net.ess3.api.ISettings {
public boolean isWorldTimePermissions() { public boolean isWorldTimePermissions() {
return config.getBoolean("world-time-permissions", false); return config.getBoolean("world-time-permissions", false);
} }
@Override
public boolean isSpawnOnJoin() {
return config.getBoolean("spawn-on-join", false);
}
} }

View File

@ -801,4 +801,7 @@ respawn-listener-priority: high
# When users die, should they respawn at their first home or bed, instead of the spawnpoint? # When users die, should they respawn at their first home or bed, instead of the spawnpoint?
respawn-at-home: false respawn-at-home: false
# Teleport all joining players to the spawnpoint
spawn-on-join: false
# End of file <-- No seriously, you're done with configuration. # End of file <-- No seriously, you're done with configuration.

View File

@ -68,9 +68,27 @@ public class EssentialsSpawnPlayerListener implements Listener {
}); });
} }
public void delayedJoin(Player player) { public void delayedJoin(final Player player) {
if (player.hasPlayedBefore()) { if (player.hasPlayedBefore()) {
LOGGER.log(Level.FINE, "Old player join"); LOGGER.log(Level.FINE, "Old player join");
if (ess.getSettings().isSpawnOnJoin()) {
final User user = ess.getUser(player);
if (!user.isAuthorized("essentials.spawn-on-join.exempt")) {
ess.scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
Location spawn = spawns.getSpawn(user.getGroup());
try {
user.getTeleport().now(spawn, false, TeleportCause.PLUGIN);
} catch (Exception e) {
ess.showError(user.getSource(), e, "spawn-on-join");
}
}
});
}
}
return; return;
} }

View File

@ -15,4 +15,8 @@ commands:
spawn: spawn:
description: Teleport to the spawnpoint. description: Teleport to the spawnpoint.
usage: /<command> [player] usage: /<command> [player]
aliases: [espawn] aliases: [espawn]
permissions:
essentials.spawn-on-join.exempt:
default: false
description: "Bypass spawn teleportation on join when spawn-on-join is true."