mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Half-way through permissions rewrite.
This commit is contained in:
parent
841f6f05df
commit
af017f3412
14
pom.xml
14
pom.xml
@ -185,6 +185,7 @@
|
||||
<include>com.dumptruckman.minecraft:buscript</include>
|
||||
<include>org.mcstats:metrics</include>
|
||||
<include>com.dumptruckman.minecraft:Logging</include>
|
||||
<include>com.dumptruckman.minecraft:Permissions-Bukkit</include>
|
||||
<include>com.fernferret.allpay:AllPay</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
@ -213,6 +214,10 @@
|
||||
<pattern>com.dumptruckman.minecraft.util.Logging</pattern>
|
||||
<shadedPattern>com.onarandombox.MultiverseCore.utils.CoreLogging</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.dumptruckman.minecraft.pluginbase</pattern>
|
||||
<shadedPattern>com.onarandombox.MultiverseCore.pluginbase</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.dumptruckman.minecraft.util.DebugLog</pattern>
|
||||
<shadedPattern>com.onarandombox.MultiverseCore.utils.DebugFileLogger</shadedPattern>
|
||||
@ -305,6 +310,15 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of Logging Dependency -->
|
||||
<!-- Start of Permissions lib Dependency -->
|
||||
<dependency>
|
||||
<groupId>com.dumptruckman.minecraft</groupId>
|
||||
<artifactId>Permissions-Bukkit</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of Permissions lib Dependency -->
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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?
|
||||
* <p>
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<String> {
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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}
|
||||
*/
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,10 +359,12 @@ public class MVPlayerListener implements Listener {
|
||||
}
|
||||
// TODO need a override permission for this
|
||||
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
|
||||
if (!this.pt.playerCanIgnoreAllowFlightRestriction(world, player)) {
|
||||
player.setAllowFlight(false);
|
||||
if (player.isFlying()) {
|
||||
player.setFlying(false);
|
||||
}
|
||||
}
|
||||
} else if (world.getAllowFlight()) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
player.setAllowFlight(true);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
}
|
@ -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!
|
||||
|
Loading…
Reference in New Issue
Block a user