From af017f341236fabc49f903bdffe7e62c5bd01b2d Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Thu, 6 Dec 2012 15:19:56 -0500 Subject: [PATCH] Half-way through permissions rewrite. --- pom.xml | 14 ++++ .../onarandombox/MultiverseCore/MVWorld.java | 68 +------------------ .../MultiverseCore/MultiverseCore.java | 4 ++ .../MultiverseCore/api/MVDestination.java | 9 +++ .../MultiverseCore/api/MultiverseWorld.java | 4 ++ .../MultiverseCore/commands/ListCommand.java | 3 +- .../destination/AnchorDestination.java | 12 +++- .../destination/BedDestination.java | 15 +++- .../destination/CannonDestination.java | 12 +++- .../destination/ExactDestination.java | 12 +++- .../destination/WorldDestination.java | 14 +++- .../listeners/MVPlayerListener.java | 27 ++++---- .../MultiverseCore/utils/AnchorManager.java | 2 +- .../MultiverseCore/utils/MVPermissions.java | 23 ++----- .../MultiverseCore/utils/PermissionTools.java | 24 +++++-- .../MultiverseCore/utils/Permissions.java | 60 ++++++++++++++++ .../MultiverseCore/utils/WorldManager.java | 30 -------- 17 files changed, 196 insertions(+), 137 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/Permissions.java diff --git a/pom.xml b/pom.xml index b80e2e6d..03c08373 100644 --- a/pom.xml +++ b/pom.xml @@ -185,6 +185,7 @@ com.dumptruckman.minecraft:buscript org.mcstats:metrics com.dumptruckman.minecraft:Logging + com.dumptruckman.minecraft:Permissions-Bukkit com.fernferret.allpay:AllPay @@ -213,6 +214,10 @@ com.dumptruckman.minecraft.util.Logging com.onarandombox.MultiverseCore.utils.CoreLogging + + com.dumptruckman.minecraft.pluginbase + com.onarandombox.MultiverseCore.pluginbase + com.dumptruckman.minecraft.util.DebugLog com.onarandombox.MultiverseCore.utils.DebugFileLogger @@ -305,6 +310,15 @@ compile + + + com.dumptruckman.minecraft + Permissions-Bukkit + 1.5-SNAPSHOT + jar + compile + + junit diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 1a566426..2811339c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -16,6 +16,7 @@ import com.onarandombox.MultiverseCore.configuration.WorldPropertyValidator; import com.onarandombox.MultiverseCore.enums.AllowedPortalType; import com.onarandombox.MultiverseCore.enums.EnglishChatColor; import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; +import com.onarandombox.MultiverseCore.utils.Permissions; import me.main__.util.SerializationConfig.ChangeDeniedException; import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.VirtualProperty; @@ -30,7 +31,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; import org.bukkit.util.Vector; import org.json.simple.JSONObject; @@ -84,8 +84,6 @@ public class MVWorld implements MultiverseWorld { this.props.environment = world.getEnvironment(); this.props.seed = world.getSeed(); - this.initPerms(); - this.props.flushChanges(); validateProperties(); @@ -322,10 +320,7 @@ public class MVWorld implements MultiverseWorld { } } - private Permission permission; private Permission exempt; - private Permission ignoreperm; - private Permission limitbypassperm; /** * Null-location. @@ -371,37 +366,6 @@ public class MVWorld implements MultiverseWorld { }; } - /** - * Initializes permissions. - */ - private void initPerms() { - this.permission = new Permission("multiverse.access." + this.getName(), "Allows access to " + this.getName(), PermissionDefault.OP); - // This guy is special. He shouldn't be added to any parent perms. - this.ignoreperm = new Permission("mv.bypass.gamemode." + this.getName(), - "Allows players with this permission to ignore gamemode changes.", PermissionDefault.FALSE); - - this.exempt = new Permission("multiverse.exempt." + this.getName(), - "A player who has this does not pay to enter this world, or use any MV portals in it " + this.getName(), PermissionDefault.OP); - - this.limitbypassperm = new Permission("mv.bypass.playerlimit." + this.getName(), - "A player who can enter this world regardless of wether its full", PermissionDefault.OP); - try { - this.plugin.getServer().getPluginManager().addPermission(this.permission); - this.plugin.getServer().getPluginManager().addPermission(this.exempt); - this.plugin.getServer().getPluginManager().addPermission(this.ignoreperm); - this.plugin.getServer().getPluginManager().addPermission(this.limitbypassperm); - // Add the permission and exempt to parents. - this.addToUpperLists(this.permission); - - // Add ignore to it's parent: - this.ignoreperm.addParent("mv.bypass.gamemode.*", true); - // Add limit bypass to it's parent - this.limitbypassperm.addParent("mv.bypass.playerlimit.*", true); - } catch (IllegalArgumentException e) { - this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name); - } - } - private Location readSpawnFromWorld(World w) { Location location = w.getSpawnLocation(); // Set the worldspawn to our configspawn @@ -444,32 +408,6 @@ public class MVWorld implements MultiverseWorld { return location; } - private void addToUpperLists(Permission perm) { - Permission all = this.plugin.getServer().getPluginManager().getPermission("multiverse.*"); - Permission allWorlds = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*"); - Permission allExemption = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*"); - - if (allWorlds == null) { - allWorlds = new Permission("multiverse.access.*"); - this.plugin.getServer().getPluginManager().addPermission(allWorlds); - } - allWorlds.getChildren().put(perm.getName(), true); - if (allExemption == null) { - allExemption = new Permission("multiverse.exempt.*"); - this.plugin.getServer().getPluginManager().addPermission(allExemption); - } - allExemption.getChildren().put(this.exempt.getName(), true); - if (all == null) { - all = new Permission("multiverse.*"); - this.plugin.getServer().getPluginManager().addPermission(all); - } - all.getChildren().put("multiverse.access.*", true); - all.getChildren().put("multiverse.exempt.*", true); - - this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(all); - this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds); - } - public void copyValues(MVWorld other) { props.copyValues(other.props); } @@ -916,7 +854,7 @@ public class MVWorld implements MultiverseWorld { */ @Override public Permission getAccessPermission() { - return this.permission; + return Permissions.ACCESS.getPermission(getName()); } /** @@ -956,7 +894,7 @@ public class MVWorld implements MultiverseWorld { */ @Override public Permission getExemptPermission() { - return this.exempt; + return Permissions.COST_EXEMPT.getPermission(getName()); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 313be3fe..88a79cc9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -8,6 +8,7 @@ package com.onarandombox.MultiverseCore; import buscript.Buscript; +import com.dumptruckman.minecraft.pluginbase.permission.BukkitPermFactory; import com.dumptruckman.minecraft.util.Logging; import com.fernferret.allpay.AllPay; import com.fernferret.allpay.GenericBank; @@ -223,6 +224,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { @Override public void onLoad() { + // Register permission handler + BukkitPermFactory.registerPermissionName(getClass(), "multiverse"); + BukkitPermFactory.registerPermissionName(Core.class, "multiverse"); // Register our config SerializationConfig.registerAll(MultiverseCoreConfiguration.class); // Register our world diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java index c4e64de8..1149e402 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java @@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.api; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.permissions.Permissible; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -130,6 +131,14 @@ public interface MVDestination { */ String getRequiredPermission(); + /** + * Checks whether the given permissible has the permission to go to this destination. + * + * @param permissible Whoever we need to check permissions for. + * @return True if they are allowed to go to this destination based on permissions. + */ + boolean hasRequiredPermission(Permissible permissible); + /** * Should the Multiverse SafeTeleporter be used? *

diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 5ddffafb..a7b899cf 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -245,14 +245,18 @@ public interface MultiverseWorld { * Gets the permission required to enter this world. * * @return The permission required to be exempt from charges to/from this world. + * @deprecated Now using {@link com.onarandombox.MultiverseCore.utils.Permissions#ACCESS}. */ + @Deprecated Permission getAccessPermission(); /** * Gets the permission required to be exempt when entering. * * @return The permission required to be exempt when entering. + * @deprecated Now using {@link com.onarandombox.MultiverseCore.utils.Permissions#COST_EXEMPT}. */ + @Deprecated Permission getExemptPermission(); // end of permission stuff diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java index e63ea4f2..e3562e85 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java @@ -9,6 +9,7 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.ChatColor; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; @@ -65,7 +66,7 @@ public class ListCommand extends PaginatedCoreCommand { } } for (String name : this.plugin.getMVWorldManager().getUnloadedWorlds()) { - if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + name, true)) { + if (p == null || Permissions.ACCESS.hasPermission(p, name)) { worldList.add(ChatColor.GRAY + name + " - UNLOADED"); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java index 0efea017..1813a8cd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java @@ -9,8 +9,10 @@ package com.onarandombox.MultiverseCore.destination; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.permissions.Permissible; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -134,7 +136,15 @@ public class AnchorDestination implements MVDestination { */ @Override public String getRequiredPermission() { - return "multiverse.access." + this.location.getWorld().getName(); + return Permissions.ACCESS.getName(this.location.getWorld().getName()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasRequiredPermission(Permissible permissible) { + return Permissions.ACCESS.hasPermission(permissible, this.location.getWorld().getName()); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java index 5b73d0a9..6c29502c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java @@ -9,10 +9,12 @@ package com.onarandombox.MultiverseCore.destination; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -104,11 +106,22 @@ public class BedDestination implements MVDestination { @Override public String getRequiredPermission() { if (knownBedLoc != null) { - return "multiverse.access." + knownBedLoc.getWorld().getName(); + return Permissions.ACCESS.getName(knownBedLoc.getWorld().getName()); } return ""; } + /** + * {@inheritDoc} + */ + @Override + public boolean hasRequiredPermission(Permissible permissible) { + if (knownBedLoc != null) { + Permissions.ACCESS.hasPermission(permissible, knownBedLoc.getWorld().getName()); + } + return true; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java index e26acec3..230b1b6b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java @@ -9,8 +9,10 @@ package com.onarandombox.MultiverseCore.destination; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.permissions.Permissible; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -205,7 +207,15 @@ public class CannonDestination implements MVDestination { */ @Override public String getRequiredPermission() { - return "multiverse.access." + this.location.getWorld().getName(); + return Permissions.ACCESS.getName(this.location.getWorld().getName()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasRequiredPermission(Permissible permissible) { + return Permissions.ACCESS.hasPermission(permissible, this.location.getWorld().getName()); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java index c8baf41d..2b5fc577 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java @@ -9,8 +9,10 @@ package com.onarandombox.MultiverseCore.destination; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.permissions.Permissible; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -208,7 +210,15 @@ public class ExactDestination implements MVDestination { */ @Override public String getRequiredPermission() { - return "multiverse.access." + this.location.getWorld().getName(); + return Permissions.ACCESS.getName(this.location.getWorld().getName()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasRequiredPermission(Permissible permissible) { + return Permissions.ACCESS.hasPermission(permissible, this.location.getWorld().getName()); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java index 6cbc0351..eabbe0dc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java @@ -11,8 +11,10 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.Core; import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.permissions.Permissible; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -149,9 +151,15 @@ public class WorldDestination implements MVDestination { */ @Override public String getRequiredPermission() { - // TODO: Potenitally replace spaces wiht tabs for friendlier yaml. - // this.world.getName().replace(" ","_"); - return "multiverse.access." + this.world.getName(); + return Permissions.ACCESS.getName(this.world.getName()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasRequiredPermission(Permissible permissible) { + return Permissions.ACCESS.hasPermission(permissible, this.world.getName()); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index cc7aabbe..78ea4b80 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -13,6 +13,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.utils.PermissionTools; +import com.onarandombox.MultiverseCore.utils.Permissions; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -120,7 +121,7 @@ public class MVPlayerListener implements Listener { } else { this.plugin.log(Level.FINER, "Player joined AGAIN!"); if (this.plugin.getMVConfig().getEnforceAccess() // check this only if we're enforcing access! - && !this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) { + && !Permissions.ACCESS.hasPermission(p, p.getWorld().getName())) { p.sendMessage("[MV] - Sorry you can't be in this world anymore!"); this.sendPlayerToDefaultWorld(p); } @@ -201,8 +202,8 @@ public class MVPlayerListener implements Listener { if (event.isCancelled() && teleporter != null) { this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + toWorld.getAlias() - + "' because '" + teleporter.getName() - + "' don't have: multiverse.access." + event.getTo().getWorld().getName()); + + "' because '" + teleporter.getName() + "' don't have: " + + Permissions.ACCESS.getName(event.getTo().getWorld().getName())); return; } } else { @@ -216,11 +217,9 @@ public class MVPlayerListener implements Listener { if (toWorld.getCBWorld().getPlayers().size() >= toWorld.getPlayerLimit()) { // Ouch the world is full, lets see if the player can bypass that limitation if (!pt.playerCanBypassPlayerLimit(toWorld, teleporter, teleportee)) { - this.plugin.log(Level.FINE, "Player '" + teleportee.getName() - + "' was DENIED ACCESS to '" + toWorld.getAlias() - + "' because the world is full and '" + teleporter.getName() - + "' doesn't have: mv.bypass.playerlimit." + event.getTo().getWorld().getName()); - event.setCancelled(true); + Logging.fine("Player '%s' was DENIED ACCESS to '%s' because the world is full and '%s' doesn't have: %s.%s", + teleportee.getName(), toWorld.getAlias(), teleporter.getName(), + Permissions.BYPASS_PLAYERLIMIT.getName(), event.getTo().getWorld().getName()); return; } } @@ -291,9 +290,11 @@ public class MVPlayerListener implements Listener { if (plugin.getMVConfig().getEnforceAccess()) { event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer())); if (event.isCancelled()) { + // this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() - + "' because they don't have: multiverse.access." + event.getTo().getWorld().getName()); + + "' because they don't have: " + + Permissions.ACCESS.getName(event.getTo().getWorld().getName())); } } else { this.plugin.log(Level.FINE, "Player '" + event.getPlayer().getName() @@ -358,9 +359,11 @@ public class MVPlayerListener implements Listener { } // TODO need a override permission for this if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) { - player.setAllowFlight(false); - if (player.isFlying()) { - player.setFlying(false); + if (!this.pt.playerCanIgnoreAllowFlightRestriction(world, player)) { + player.setAllowFlight(false); + if (player.isFlying()) { + player.setFlying(false); + } } } else if (world.getAllowFlight()) { if (player.getGameMode() == GameMode.CREATIVE) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java index e7b904f9..6a41e20c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/AnchorManager.java @@ -140,7 +140,7 @@ public class AnchorManager { if (ancLoc == null) { continue; } - if (p.hasPermission("multiverse.access." + ancLoc.getWorld().getName())) { + if (Permissions.ACCESS.hasPermission(p, ancLoc.getWorld().getName())) { myAnchors.add(anchor); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java index 2ea79357..d609ea9f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java @@ -36,17 +36,6 @@ public class MVPermissions implements PermissionsInterface { } - /** - * Check if a Player can ignore GameMode restrictions for world they travel to. - * - * @param p The {@link Player} to check. - * @param w The {@link MultiverseWorld} the player wants to teleport to. - * @return True if they should bypass restrictions. - */ - public boolean canIgnoreGameModeRestriction(Player p, MultiverseWorld w) { - return p.hasPermission("mv.bypass.gamemode." + w.getName()); - } - /** * Check if a Player can teleport to the Destination world from there current world. * @@ -103,7 +92,7 @@ public class MVPermissions implements PermissionsInterface { this.plugin.log(Level.FINEST, "EnforceAccess is OFF. Player was allowed in " + w.getAlias()); return true; } - return this.hasPermission(p, "multiverse.access." + w.getName(), false); + return Permissions.ACCESS.hasPermission(p, w.getName()); } private boolean canEnterLocation(Player p, Location l) { @@ -114,7 +103,7 @@ public class MVPermissions implements PermissionsInterface { if (!this.plugin.getMVWorldManager().isMVWorld(worldName)) { return false; } - return this.hasPermission(p, "multiverse.access." + worldName, false); + return Permissions.ACCESS.hasPermission(p, worldName); } /** @@ -141,7 +130,7 @@ public class MVPermissions implements PermissionsInterface { if (!canEnterLocation(p, d.getLocation(p))) { return false; } - return this.hasPermission(p, d.getRequiredPermission(), false); + return d.hasRequiredPermission(p); } /** @@ -177,14 +166,14 @@ public class MVPermissions implements PermissionsInterface { ChatColor.DARK_AQUA, ChatColor.WHITE)); cango = false; } - if (!this.hasPermission(p, "multiverse.access." + worldName, false)) { + if (!Permissions.ACCESS.hasPermission(p, worldName)) { asker.sendMessage(String.format("The player (%s%s%s) does not have the required world entry permission (%s%s%s) to go to the destination (%s%s%s).", ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, - ChatColor.GREEN, "multiverse.access." + worldName, ChatColor.WHITE, + ChatColor.GREEN, Permissions.ACCESS.getName(worldName), ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); cango = false; } - if (!this.hasPermission(p, d.getRequiredPermission(), false)) { + if (d.hasRequiredPermission(p)) { asker.sendMessage(String.format("The player (%s%s%s) does not have the required entry permission (%s%s%s) to go to the destination (%s%s%s).", ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, ChatColor.GREEN, d.getRequiredPermission(), ChatColor.WHITE, diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index f243365a..61b5ec59 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -140,7 +140,7 @@ public class PermissionTools { return true; } // If the player does not have to pay, return now. - if (this.plugin.getMVPerms().hasPermission(teleporter, toWorld.getExemptPermission().getName(), true)) { + if (Permissions.COST_EXEMPT.hasPermission(teleporter, toWorld.getName())) { return true; } final boolean usingVault; @@ -275,8 +275,7 @@ public class PermissionTools { return true; } - MVPermissions perms = plugin.getMVPerms(); - if (perms.hasPermission(teleportee, "mv.bypass.playerlimit." + toWorld.getName(), false)) { + if (Permissions.BYPASS_PLAYERLIMIT.hasPermission(teleportee, toWorld.getName())) { return true; } else { teleporter.sendMessage("The world " + toWorld.getColoredWorldString() + " is full"); @@ -293,7 +292,24 @@ public class PermissionTools { */ public boolean playerCanIgnoreGameModeRestriction(MultiverseWorld toWorld, Player teleportee) { if (toWorld != null) { - return this.plugin.getMVPerms().canIgnoreGameModeRestriction(teleportee, toWorld); + return Permissions.BYPASS_GAMEMODE.hasPermission(teleportee, toWorld.getName()); + } else { + // TODO: Determine if this value is false because a world didn't exist + // or if it was because a world wasn't imported. + return true; + } + } + + /** + * Checks to see if a player should bypass allow flight restrictions. + * + * @param toWorld world travelling to. + * @param teleportee player travelling. + * @return True if they should bypass restrictions + */ + public boolean playerCanIgnoreAllowFlightRestriction(MultiverseWorld toWorld, Player teleportee) { + if (toWorld != null) { + return Permissions.BYPASS_ALLOWFLY.hasPermission(teleportee, toWorld.getName()); } else { // TODO: Determine if this value is false because a world didn't exist // or if it was because a world wasn't imported. diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/Permissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/Permissions.java new file mode 100644 index 00000000..0600c84d --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/Permissions.java @@ -0,0 +1,60 @@ +package com.onarandombox.MultiverseCore.utils; + +import com.dumptruckman.minecraft.pluginbase.permission.BukkitPerm; +import com.dumptruckman.minecraft.pluginbase.permission.BukkitPermFactory; +import com.dumptruckman.minecraft.pluginbase.permission.PermDefault; +import com.onarandombox.MultiverseCore.api.Core; + +public class Permissions { + + // ============ Multiverse Bypass Permissions ============ + + private static final BukkitPerm MV = BukkitPermFactory.newBukkitPerm(Core.class, "mv.*") + .def(PermDefault.FALSE).build(); + + private static final BukkitPerm BYPASS_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "mv.bypass.*") + .def(PermDefault.FALSE).parent(MV).build(); + + private static final BukkitPerm BYPASS_GAMEMODE_ALL = BukkitPermFactory.newBukkitPerm(Core.class, + "mv.bypass.gamemode.*").desc("Allows a player to ignore gamemode changes for all worlds.") + .def(PermDefault.FALSE).parent(BYPASS_ALL).build(); + + private static final BukkitPerm BYPASS_PLAYERLIMIT_ALL = BukkitPermFactory.newBukkitPerm(Core.class, + "mv.bypass.playerlimit.*").desc("Allows a player to ignore the player limit for all worlds.") + .def(PermDefault.FALSE).parent(BYPASS_ALL).build(); + + private static final BukkitPerm BYPASS_ALLOWFLY_ALL = BukkitPermFactory.newBukkitPerm(Core.class, + "mv.bypass.allowfly.*").desc("Allows a player to ignore the flight restrictions for all worlds.") + .def(PermDefault.FALSE).parent(BYPASS_ALL).build(); + + /** Used for bypassing the gamemode of specific worlds. */ + public static final BukkitPerm BYPASS_GAMEMODE = BukkitPermFactory.newBukkitPerm(Core.class, + "mv.bypass.gamemode").desc("Allows a player to ignore gamemode changes for a specific world.") + .specificOnly().def(PermDefault.FALSE).parent(BYPASS_GAMEMODE_ALL).build(); + + /** Used for bypassing the player limit of specific worlds. */ + public static final BukkitPerm BYPASS_PLAYERLIMIT = BukkitPermFactory.newBukkitPerm(Core.class, + "mv.bypass.playerlimit").desc("Allows a player to ignore the player limit for a specific world.") + .specificOnly().def(PermDefault.FALSE).parent(BYPASS_PLAYERLIMIT_ALL).build(); + + /** Used for bypassing the allow fly setting of specific worlds. */ + public static final BukkitPerm BYPASS_ALLOWFLY = BukkitPermFactory.newBukkitPerm(Core.class, + "mv.bypass.allowfly").desc("Allows a player to ignore the flight restrictions for a specific world.") + .specificOnly().def(PermDefault.FALSE).parent(BYPASS_ALLOWFLY_ALL).build(); + + + // ============ Multiverse Normal Permissions ============ + + private static final BukkitPerm ACCESS_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "access.*") + .desc("Allows a player to access all worlds.").addToAll().build(); + + private static final BukkitPerm COST_EXEMPT_ALL = BukkitPermFactory.newBukkitPerm(Core.class, "exempt.*") + .desc("Allows a player to bypass the costs for worlds and MV portals.").addToAll().build(); + + public static final BukkitPerm ACCESS = BukkitPermFactory.newBukkitPerm(Core.class, "access") + .desc("Allows a player to access a specific world.").specificOnly().parent(ACCESS_ALL).build(); + + public static final BukkitPerm COST_EXEMPT = BukkitPermFactory.newBukkitPerm(Core.class, "exempt") + .desc("Allows a player to bypass the costs for a specific world and MV portals in that world.") + .specificOnly().parent(COST_EXEMPT_ALL).build(); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 63c786f8..6c083620 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -27,8 +27,6 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.Plugin; import java.io.File; @@ -614,29 +612,9 @@ public class WorldManager implements MVWorldManager { // Basic Counter to count how many Worlds we are loading. int count = 0; this.ensureConfigIsPrepared(); - this.ensureSecondNamespaceIsPrepared(); // Force the worlds to be loaded, ie don't just load new worlds. if (forceLoad) { - // Remove all world permissions. - Permission allAccess = this.plugin.getServer().getPluginManager().getPermission("multiverse.access.*"); - Permission allExempt = this.plugin.getServer().getPluginManager().getPermission("multiverse.exempt.*"); - for (MultiverseWorld w : this.worlds.values()) { - // Remove this world from the master list - if (allAccess != null) { - allAccess.getChildren().remove(w.getAccessPermission().getName()); - } - if (allExempt != null) { - allExempt.getChildren().remove(w.getAccessPermission().getName()); - } - this.plugin.getServer().getPluginManager().removePermission(w.getAccessPermission().getName()); - this.plugin.getServer().getPluginManager().removePermission(w.getExemptPermission().getName()); - // Special namespace for gamemodes - this.plugin.getServer().getPluginManager().removePermission("mv.bypass.gamemode." + w.getName()); - } - // Recalc the all permission - this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allAccess); - this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allExempt); this.worlds.clear(); } @@ -656,14 +634,6 @@ public class WorldManager implements MVWorldManager { this.saveWorldsConfig(); } - private void ensureSecondNamespaceIsPrepared() { - Permission special = this.plugin.getServer().getPluginManager().getPermission("mv.bypass.gamemode.*"); - if (special == null) { - special = new Permission("mv.bypass.gamemode.*", PermissionDefault.FALSE); - this.plugin.getServer().getPluginManager().addPermission(special); - } - } - /** * {@inheritDoc} * @deprecated This is deprecated!