mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
[Feature] Add world specific /back dest. perms (#1948) @Ichbinjoe
Adds world specific perms for whether a player may use /back to teleport back to a given world. Adds logic to default essentials.back.into.<world> permissions for loaded worlds to true to maintain backwards compatibility.
This commit is contained in:
parent
b2a5280971
commit
b29f98c525
2 changed files with 29 additions and 2 deletions
|
@ -60,6 +60,8 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
import org.bukkit.event.world.WorldUnloadEvent;
|
import org.bukkit.event.world.WorldUnloadEvent;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.InvalidDescriptionException;
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
@ -246,6 +248,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
Economy.setEss(this);
|
Economy.setEss(this);
|
||||||
execTimer.mark("RegHandler");
|
execTimer.mark("RegHandler");
|
||||||
|
|
||||||
|
for (World w : Bukkit.getWorlds())
|
||||||
|
addDefaultBackPermissionsToWorld(w);
|
||||||
|
|
||||||
metrics = new Metrics(this);
|
metrics = new Metrics(this);
|
||||||
if (!metrics.isOptOut()) {
|
if (!metrics.isOptOut()) {
|
||||||
getLogger().info("Starting Metrics. Opt-out using the global bStats config.");
|
getLogger().info("Starting Metrics. Opt-out using the global bStats config.");
|
||||||
|
@ -867,6 +872,18 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
return potionMetaProvider;
|
return potionMetaProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addDefaultBackPermissionsToWorld(World w) {
|
||||||
|
String permName = "essentials.back.into." + w.getName();
|
||||||
|
|
||||||
|
Permission p = Bukkit.getPluginManager().getPermission(permName);
|
||||||
|
if (p == null) {
|
||||||
|
p = new Permission(permName,
|
||||||
|
"Allows access to /back when the destination location is within world " + w.getName(),
|
||||||
|
PermissionDefault.TRUE);
|
||||||
|
Bukkit.getPluginManager().addPermission(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class EssentialsWorldListener implements Listener, Runnable {
|
private static class EssentialsWorldListener implements Listener, Runnable {
|
||||||
private transient final IEssentials ess;
|
private transient final IEssentials ess;
|
||||||
|
|
||||||
|
@ -876,6 +893,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onWorldLoad(final WorldLoadEvent event) {
|
public void onWorldLoad(final WorldLoadEvent event) {
|
||||||
|
addDefaultBackPermissionsToWorld(event.getWorld());
|
||||||
|
|
||||||
ess.getJails().onReload();
|
ess.getJails().onReload();
|
||||||
ess.getWarps().reloadConfig();
|
ess.getWarps().reloadConfig();
|
||||||
for (IConf iConf : ((Essentials) ess).confList) {
|
for (IConf iConf : ((Essentials) ess).confList) {
|
||||||
|
|
|
@ -17,9 +17,17 @@ public class Commandback extends EssentialsCommand {
|
||||||
if (user.getLastLocation() == null) {
|
if (user.getLastLocation() == null) {
|
||||||
throw new Exception(tl("noLocationFound"));
|
throw new Exception(tl("noLocationFound"));
|
||||||
}
|
}
|
||||||
if (user.getWorld() != user.getLastLocation().getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getLastLocation().getWorld().getName())) {
|
|
||||||
throw new Exception(tl("noPerm", "essentials.worlds." + user.getLastLocation().getWorld().getName()));
|
String lastWorldName = user.getLastLocation().getWorld().getName();
|
||||||
|
|
||||||
|
if (user.getWorld() != user.getLastLocation().getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + lastWorldName)) {
|
||||||
|
throw new Exception(tl("noPerm", "essentials.worlds." + lastWorldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!user.isAuthorized("essentials.back.into." + lastWorldName)) {
|
||||||
|
throw new Exception(tl("noPerm", "essentials.back.into." + lastWorldName));
|
||||||
|
}
|
||||||
|
|
||||||
final Trade charge = new Trade(this.getName(), ess);
|
final Trade charge = new Trade(this.getName(), ess);
|
||||||
charge.isAffordableFor(user);
|
charge.isAffordableFor(user);
|
||||||
user.getTeleport().back(charge);
|
user.getTeleport().back(charge);
|
||||||
|
|
Loading…
Reference in a new issue