mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Improve spawn-on-join with ability to specify groups.
This commit is contained in:
parent
d41af02ade
commit
27ab90ab2a
@ -250,6 +250,10 @@ public interface ISettings extends IConf {
|
|||||||
|
|
||||||
boolean isSpawnOnJoin();
|
boolean isSpawnOnJoin();
|
||||||
|
|
||||||
|
List<String> getSpawnOnJoinGroups();
|
||||||
|
|
||||||
|
boolean isUserInSpawnOnJoinGroup(IUser user);
|
||||||
|
|
||||||
boolean isTeleportToCenterLocation();
|
boolean isTeleportToCenterLocation();
|
||||||
|
|
||||||
boolean isCommandCooldownsEnabled();
|
boolean isCommandCooldownsEnabled();
|
||||||
|
@ -546,6 +546,7 @@ public class Settings implements net.ess3.api.ISettings {
|
|||||||
customQuitMessage = _getCustomQuitMessage();
|
customQuitMessage = _getCustomQuitMessage();
|
||||||
isCustomQuitMessage = !customQuitMessage.equals("none");
|
isCustomQuitMessage = !customQuitMessage.equals("none");
|
||||||
muteCommands = _getMuteCommands();
|
muteCommands = _getMuteCommands();
|
||||||
|
spawnOnJoinGroups = _getSpawnOnJoinGroups();
|
||||||
commandCooldowns = _getCommandCooldowns();
|
commandCooldowns = _getCommandCooldowns();
|
||||||
npcsInBalanceRanking = _isNpcsInBalanceRanking();
|
npcsInBalanceRanking = _isNpcsInBalanceRanking();
|
||||||
currencyFormat = _getCurrencyFormat();
|
currencyFormat = _getCurrencyFormat();
|
||||||
@ -1184,7 +1185,41 @@ public class Settings implements net.ess3.api.ISettings {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSpawnOnJoin() {
|
public boolean isSpawnOnJoin() {
|
||||||
return config.getBoolean("spawn-on-join", false);
|
return !this.spawnOnJoinGroups.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> spawnOnJoinGroups;
|
||||||
|
|
||||||
|
public List<String> _getSpawnOnJoinGroups() {
|
||||||
|
List<String> def = Collections.emptyList();
|
||||||
|
if (config.isSet("spawn-on-join")) {
|
||||||
|
if (config.isList("spawn-on-join")) {
|
||||||
|
return new ArrayList<>(config.getStringList("spawn-on-join"));
|
||||||
|
} else if (config.isBoolean("spawn-on-join")) { // List of [*] to make all groups go to spawn on join.
|
||||||
|
// This also maintains backwards compatibility with initial impl of single boolean value.
|
||||||
|
return config.getBoolean("spawn-on-join") ? Collections.singletonList("*") : def;
|
||||||
|
}
|
||||||
|
// Take whatever the value is, convert to string and add it to a list as a single value.
|
||||||
|
String val = config.get("spawn-on-join").toString();
|
||||||
|
return !val.isEmpty() ? Collections.singletonList(val) : def;
|
||||||
|
} else {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getSpawnOnJoinGroups() {
|
||||||
|
return this.spawnOnJoinGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUserInSpawnOnJoinGroup(IUser user) {
|
||||||
|
for (String group : this.spawnOnJoinGroups) {
|
||||||
|
if (group.equals("*") || user.inGroup(group)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -71,10 +72,11 @@ public class EssentialsSpawnPlayerListener implements Listener {
|
|||||||
public void delayedJoin(final 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");
|
||||||
|
List<String> spawnOnJoinGroups = ess.getSettings().getSpawnOnJoinGroups();
|
||||||
if (ess.getSettings().isSpawnOnJoin()) {
|
if (!spawnOnJoinGroups.isEmpty()) {
|
||||||
final User user = ess.getUser(player);
|
final User user = ess.getUser(player);
|
||||||
if (!user.isAuthorized("essentials.spawn-on-join.exempt")) {
|
|
||||||
|
if (ess.getSettings().isUserInSpawnOnJoinGroup(user) && !user.isAuthorized("essentials.spawn-on-join.exempt")) {
|
||||||
ess.scheduleSyncDelayedTask(new Runnable() {
|
ess.scheduleSyncDelayedTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Loading…
Reference in New Issue
Block a user