World whitelist
This commit is contained in:
1 parent
5920510901
commit
4ffbd5e8b3
7 files changed
+67
-14
No files matched your search
@@ -2,8 +2,9 @@
|
||||
|
||||
The [TrueOG Network](https://trueog.net) fork of [Duels](https://github.com/Realizedd/Duels) - a duel plugin for Spigot. <a href="https://www.spigotmc.org/resources/duels.20171/">Spigot Project Page</a>
|
||||
|
||||
Includes the following proposed changes that have yet to be merged into Duels upstream:
|
||||
Changes from Duels:
|
||||
|
||||
- Only start Duels from one world, configurable in config.yml by @NotAlexNoyle
|
||||
- Inventory loss bug fixes by @szumielxd
|
||||
- Essentials API NPE fix by @skbeh
|
||||
- Update deprecated pickup API by @NotAlexNoyle
|
||||
|
||||
@@ -82,7 +82,7 @@ public class DuelCommand extends BaseCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (config.getBlacklistedWorlds().contains(player.getWorld().getName())) {
|
||||
if (!config.isDuelingWorld(player) || config.getBlacklistedWorlds().contains(player.getWorld().getName())) {
|
||||
lang.sendMessage(sender, "ERROR.duel.in-blacklisted-world");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,8 @@ public class Config extends AbstractConfiguration<DuelsPlugin> {
|
||||
@Getter
|
||||
private boolean cancelIfMoved;
|
||||
@Getter
|
||||
private String enabledWorld;
|
||||
@Getter
|
||||
private List<String> blacklistedWorlds;
|
||||
@Getter
|
||||
private boolean teleportToLastLocation;
|
||||
@@ -317,6 +319,10 @@ public class Config extends AbstractConfiguration<DuelsPlugin> {
|
||||
preventTpToMatchPlayers = configuration.getBoolean("duel.prevent-teleport-to-match-players", true);
|
||||
forceAllowCombat = configuration.getBoolean("duel.force-allow-combat", true);
|
||||
cancelIfMoved = configuration.getBoolean("duel.cancel-if-moved", false);
|
||||
final String configuredEnabledWorld = configuration.getString("duel.enabled-world", "world");
|
||||
enabledWorld = configuredEnabledWorld != null && !configuredEnabledWorld.trim().isEmpty()
|
||||
? configuredEnabledWorld.trim()
|
||||
: "world";
|
||||
blacklistedWorlds = configuration.getStringList("duel.blacklisted-worlds");
|
||||
teleportToLastLocation = configuration.getBoolean("duel.teleport-to-last-location", false);
|
||||
teleportDelay = configuration.getInt("duel.teleport-delay", 5);
|
||||
@@ -414,6 +420,11 @@ public class Config extends AbstractConfiguration<DuelsPlugin> {
|
||||
return sounds.keySet();
|
||||
}
|
||||
|
||||
public boolean isDuelingWorld(final Player player) {
|
||||
return player != null && player.getWorld() != null
|
||||
&& enabledWorld.equalsIgnoreCase(player.getWorld().getName());
|
||||
}
|
||||
|
||||
public class MessageSound {
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -376,7 +376,7 @@ public class DuelManager implements Loadable {
|
||||
}
|
||||
|
||||
private boolean isBlacklistedWorld(final Player player) {
|
||||
return config.getBlacklistedWorlds().contains(player.getWorld().getName());
|
||||
return !config.isDuelingWorld(player) || config.getBlacklistedWorlds().contains(player.getWorld().getName());
|
||||
}
|
||||
|
||||
private boolean isTagged(final Player player) {
|
||||
@@ -712,4 +712,4 @@ public class DuelManager implements Loadable {
|
||||
lang.sendMessage(player, "DUEL.prevent.inventory-open");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,11 +97,13 @@ public class PlayerInfoManager implements Loadable {
|
||||
}
|
||||
}
|
||||
|
||||
// If lobby is not found or invalid, use the default world's spawn location for lobby.
|
||||
if (lobby == null || lobby.getWorld() == null) {
|
||||
final World world = Bukkit.getWorlds().get(0);
|
||||
this.lobby = world.getSpawnLocation();
|
||||
Log.warn(this, String.format(ERROR_LOBBY_DEFAULT, world.getName()));
|
||||
// If lobby is not found or points at a disabled/unloaded world, use the
|
||||
// configured dueling world's spawn location for lobby.
|
||||
if (!isEnabledWorld(lobby)) {
|
||||
this.lobby = getFallbackLocation();
|
||||
final World world = this.lobby != null ? this.lobby.getWorld() : null;
|
||||
Log.warn(this,
|
||||
String.format(ERROR_LOBBY_DEFAULT, world != null ? world.getName() : config.getEnabledWorld()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +114,7 @@ public class PlayerInfoManager implements Loadable {
|
||||
|
||||
if (info != null) {
|
||||
player.spigot().respawn();
|
||||
teleport.tryTeleport(player, info.getLocation());
|
||||
teleport.tryTeleport(player, safeReturnLocation(info.getLocation()));
|
||||
PlayerUtil.reset(player);
|
||||
info.restore(player);
|
||||
}
|
||||
@@ -143,6 +145,10 @@ public class PlayerInfoManager implements Loadable {
|
||||
* @return true if setting lobby was successful, false otherwise
|
||||
*/
|
||||
public boolean setLobby(final Player player) {
|
||||
if (!config.isDuelingWorld(player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Location lobby = player.getLocation().clone();
|
||||
|
||||
try (final Writer writer = new OutputStreamWriter(new FileOutputStream(lobbyFile), Charsets.UTF_8)) {
|
||||
@@ -176,7 +182,9 @@ public class PlayerInfoManager implements Loadable {
|
||||
final PlayerInfo info = new PlayerInfo(player, excludeInventory);
|
||||
|
||||
if (!config.isTeleportToLastLocation()) {
|
||||
info.setLocation(lobby.clone());
|
||||
info.setLocation(safeReturnLocation(lobby));
|
||||
} else if (!isEnabledWorld(info.getLocation())) {
|
||||
info.setLocation(safeReturnLocation(info.getLocation()));
|
||||
}
|
||||
|
||||
cache.put(player.getUniqueId(), info);
|
||||
@@ -201,6 +209,30 @@ public class PlayerInfoManager implements Loadable {
|
||||
return cache.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
private boolean isEnabledWorld(final Location location) {
|
||||
return location != null && location.getWorld() != null
|
||||
&& config.getEnabledWorld().equalsIgnoreCase(location.getWorld().getName());
|
||||
}
|
||||
|
||||
private Location getFallbackLocation() {
|
||||
World world = Bukkit.getWorld(config.getEnabledWorld());
|
||||
|
||||
if (world == null && !Bukkit.getWorlds().isEmpty()) {
|
||||
world = Bukkit.getWorlds().get(0);
|
||||
}
|
||||
|
||||
return world != null ? world.getSpawnLocation() : null;
|
||||
}
|
||||
|
||||
private Location safeReturnLocation(final Location location) {
|
||||
if (isEnabledWorld(location)) {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
final Location fallback = getFallbackLocation();
|
||||
return fallback != null ? fallback.clone() : null;
|
||||
}
|
||||
|
||||
private class PlayerInfoListener implements Listener {
|
||||
|
||||
// Handles case of some players causing respawn to skip somehow.
|
||||
@@ -218,7 +250,7 @@ public class PlayerInfoManager implements Loadable {
|
||||
return;
|
||||
}
|
||||
|
||||
teleport.tryTeleport(player, info.getLocation());
|
||||
teleport.tryTeleport(player, safeReturnLocation(info.getLocation()));
|
||||
info.restore(player);
|
||||
}
|
||||
|
||||
@@ -231,7 +263,7 @@ public class PlayerInfoManager implements Loadable {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setRespawnLocation(info.getLocation());
|
||||
event.setRespawnLocation(safeReturnLocation(info.getLocation()));
|
||||
|
||||
if (essentials != null) {
|
||||
essentials.setBackLocation(player, event.getRespawnLocation());
|
||||
|
||||
@@ -361,6 +361,11 @@ public class QueueManager implements Loadable, DQueueManager, Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!config.isDuelingWorld(player) || config.getBlacklistedWorlds().contains(player.getWorld().getName())) {
|
||||
lang.sendMessage(player, "ERROR.duel.in-blacklisted-world");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((combatTagPlus != null && combatTagPlus.isTagged(player)) || (pvpManager != null && pvpManager.isTagged(player))) {
|
||||
lang.sendMessage(player, "ERROR.duel.is-tagged");
|
||||
return false;
|
||||
|
||||
@@ -231,6 +231,10 @@ duel:
|
||||
# default: false
|
||||
cancel-if-moved: false
|
||||
|
||||
# Only allow duels to be started from this world.
|
||||
# default: world
|
||||
enabled-world: 'world'
|
||||
|
||||
# List of worlds to disable dueling.
|
||||
blacklisted-worlds:
|
||||
- 'world_name_here'
|
||||
@@ -603,4 +607,4 @@ sounds:
|
||||
pitch: 1.9
|
||||
volume: 1.0
|
||||
trigger-messages:
|
||||
- '&7Now in a match against &f%opponent%&7(&a%opponent_rating%&7) with kit &3%kit% &7in arena &e%arena%&7.'
|
||||
- '&7Now in a match against &f%opponent%&7(&a%opponent_rating%&7) with kit &3%kit% &7in arena &e%arena%&7.'
|
||||
Reference in new issue
Block a user