Cleaner way to handle per-world teleport permissions. Also provides a

nice error message now to explain WHY a player can't teleport.
This commit is contained in:
GJ 2013-02-20 11:43:23 -05:00
parent 1d87de0a3e
commit 918d81198f
4 changed files with 32 additions and 21 deletions

View File

@ -50,6 +50,7 @@ import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.runnables.SkillMonitor; import com.gmail.nossr50.skills.runnables.SkillMonitor;
import com.gmail.nossr50.spout.SpoutConfig; import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.SpoutTools; import com.gmail.nossr50.spout.SpoutTools;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.UpdateCheck; import com.gmail.nossr50.util.UpdateCheck;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -131,6 +132,10 @@ public class mcMMO extends JavaPlugin {
placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager
checkForUpdates(); checkForUpdates();
if (Config.getInstance().getPTPCommandWorldPermissions()) {
Permissions.generateWorldTeleportPermissions();
}
} }
/** /**

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.party.commands; package com.gmail.nossr50.party.commands;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -118,15 +119,17 @@ public class PtpCommand implements CommandExecutor {
return true; return true;
} }
//TODO: Someone want to clarify what's going on with these dynamic permissions?
if (Config.getInstance().getPTPCommandWorldPermissions()) { if (Config.getInstance().getPTPCommandWorldPermissions()) {
String perm = "mcmmo.commands.ptp.world."; World targetWorld = target.getWorld();
World playerWorld = player.getWorld();
if (!Permissions.hasDynamicPermission(target, perm + "all", "op")) { if (!Permissions.partyTeleportAllWorlds(target)) {
if (!Permissions.hasDynamicPermission(target, perm + target.getWorld().getName(), "op")) { if (!Permissions.partyTeleportWorld(target, targetWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", targetWorld.getName()));
return true; return true;
} }
else if (target.getWorld() != player.getWorld() && !Permissions.hasDynamicPermission(target, perm + player.getWorld().getName(), "op")) { else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(target, playerWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", playerWorld.getName()));
return true; return true;
} }
} }

View File

@ -1,15 +1,14 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.commands.PartySubcommandType; import com.gmail.nossr50.party.commands.PartySubcommandType;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
@ -216,20 +215,23 @@ public final class Permissions {
public static boolean partyTeleportAcceptAll(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.ptp.acceptall"); } public static boolean partyTeleportAcceptAll(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.ptp.acceptall"); }
public static boolean partyTeleportToggle(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.ptp.toggle"); } public static boolean partyTeleportToggle(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.ptp.toggle"); }
// TODO: Still think there's a better way to handle this public static boolean partyTeleportAllWorlds(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.ptp.world.all"); }
public static boolean hasDynamicPermission(CommandSender sender, String perm, String defaultType) { public static boolean partyTeleportWorld(Permissible permissible, World world) { return permissible.hasPermission("mcmmo.commands.ptp.world." + world.getName()); }
Map<String, Object> m = new HashMap<String, Object>();
if(defaultType != null) { public static void generateWorldTeleportPermissions() {
m.put("default", defaultType); Server server = mcMMO.p.getServer();
PluginManager pluginManager = server.getPluginManager();
for (World world : server.getWorlds()) {
addDynamicPermission("mcmmo.commands.ptp.world." + world.getName(), PermissionDefault.OP, pluginManager);
} }
PluginManager manager = Bukkit.getPluginManager(); addDynamicPermission("mcmmo.commands.ptp.world.all", PermissionDefault.OP, pluginManager);
if (manager.getPermission(perm) == null) {
Permission.loadPermission(perm, m);
} }
return sender.hasPermission(perm); private static void addDynamicPermission(String permissionName, PermissionDefault permissionDefault, PluginManager pluginManager) {
Permission permission = new Permission(permissionName);
permission.setDefault(permissionDefault);
pluginManager.addPermission(permission);
} }
} }

View File

@ -470,6 +470,7 @@ Commands.Party2=[[RED]]- Join a players party
Commands.ptp.Enabled=Party teleporting [[GREEN]]enabled Commands.ptp.Enabled=Party teleporting [[GREEN]]enabled
Commands.ptp.Disabled=Party teleporting [[RED]]disabled Commands.ptp.Disabled=Party teleporting [[RED]]disabled
Commands.ptp.NoRequests=[[RED]]You have no teleport requests at this time Commands.ptp.NoRequests=[[RED]]You have no teleport requests at this time
Commands.ptp.NoWorldPermissions=[[RED]][mcMMO] You do not have permission to teleport to the world {0}.
Commands.ptp.Request1=[[YELLOW]]{0} [[GREEN]]has requested to teleport to you. Commands.ptp.Request1=[[YELLOW]]{0} [[GREEN]]has requested to teleport to you.
Commands.ptp.Request2=[[GREEN]]To teleport, type [[YELLOW]]/ptp accept. [[GREEN]]Request expires in [[RED]]{0} [[GREEN]]seconds. Commands.ptp.Request2=[[GREEN]]To teleport, type [[YELLOW]]/ptp accept. [[GREEN]]Request expires in [[RED]]{0} [[GREEN]]seconds.
Commands.ptp.AcceptAny.Enabled=Party teleport request confirmation [[GREEN]]enabled Commands.ptp.AcceptAny.Enabled=Party teleport request confirmation [[GREEN]]enabled