Fix "Blah, Blah" in delete command, abs class Dest -> interface MVDest, restrict teleports based on MVDest.getPermissionString.

This commit is contained in:
Eric Stokes 2011-08-03 18:59:21 -06:00
parent 1671a8163d
commit 1cc47ff1ba
9 changed files with 76 additions and 25 deletions

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.onarandombox.utils.MVDestination;
import com.pneumaticraft.commandhandler.PermissionsInterface;
public class MVPermissions implements PermissionsInterface {
@ -81,6 +82,20 @@ public class MVPermissions implements PermissionsInterface {
return this.hasPermission(p, "multiverse.access." + worldName, false);
}
public Boolean canEnterDestination(Player p, MVDestination d) {
if (d == null || d.getLocation() == null) {
return false;
}
String worldName = d.getLocation().getWorld().getName();
if (!this.plugin.isMVWorld(worldName)) {
return false;
}
if(!canEnterLocation(p, d.getLocation())) {
return false;
}
return this.hasPermission(p, d.getRequiredPermission(), false);
}
public void setPermissions(PermissionHandler handler) {
this.permissions = handler;
}
@ -90,24 +105,29 @@ public class MVPermissions implements PermissionsInterface {
if (!(sender instanceof Player)) {
return true;
}
// NO one can access a null permission (mainly used for destinations):w
if(node == null) {
return false;
}
Player player = (Player) sender;
boolean opFallback = this.plugin.getConfig().getBoolean("opfallback", true);
if (this.permissions != null && this.permissions.has(player, node)) {
// If Permissions is enabled we check against them.
//this.plugin.log(Level.WARNING, "Allowed by P3/P2 ");
// this.plugin.log(Level.WARNING, "Allowed by P3/P2 ");
return true;
} else if (sender.hasPermission(node)) {
// If Now check the bukkit permissions
//this.plugin.log(Level.WARNING, "Allowed by BukkitPerms");
// this.plugin.log(Level.WARNING, "Allowed by BukkitPerms");
return true;
} else if (player.isOp() && opFallback) {
// If Player is Op we always let them use it if they have the fallback enabled!
//this.plugin.log(Level.WARNING, "Allowed by OP");
// this.plugin.log(Level.WARNING, "Allowed by OP");
return true;
}
// If the Player doesn't have Permissions and isn't an Op then
// we return true if OP is not required, otherwise we return false
// This allows us to act as a default permission guidance

View File

@ -25,7 +25,7 @@ public class DeleteCommand extends MultiverseCommand {
public void runCommand(CommandSender sender, List<String> args) {
Class<?> paramTypes[] = { String.class };
List<Object> objectArgs = new ArrayList<Object>(args);
//this.plugin.getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", objectArgs, paramTypes, "World Deleted!", "World was not deleted!");
this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "deleteWorld", objectArgs, paramTypes, "Blah", "Blah", "Success", "Fail", 15);
this.plugin.getCommandHandler().queueCommand(sender, "mvdelete", "deleteWorld", objectArgs, paramTypes, "World Deleted!", "World was not deleted!");
//this.plugin.getCommandHandler().queueCommand(sender, "mvteleport", "deleteWorld", objectArgs, paramTypes, "Blah", "Blah", "Success", "Fail", 15);
}
}

View File

@ -12,7 +12,7 @@ import org.bukkit.permissions.PermissionDefault;
import com.onarandombox.MultiverseCore.MVTeleport;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.utils.Destination;
import com.onarandombox.utils.MVDestination;
import com.onarandombox.utils.DestinationFactory;
import com.onarandombox.utils.InvalidDestination;
@ -74,13 +74,13 @@ public class TeleportCommand extends MultiverseCommand {
}
DestinationFactory df = this.plugin.getDestinationFactory();// .parseDestination(worldName, (MultiverseCore) this.plugin);
Destination d = df.getDestination(worldName);
MVDestination d = df.getDestination(worldName);
if (d != null && d instanceof InvalidDestination) {
sender.sendMessage("Multiverse does not know how to take you to: " + ChatColor.RED + worldName);
return;
}
if (teleporter != null && !this.plugin.getPermissions().canEnterLocation(teleporter, d.getLocation())) {
if (teleporter != null && !this.plugin.getPermissions().canEnterDestination(teleporter, d)) {
if (teleportee.equals(teleporter)) {
teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there...");
} else {

View File

@ -3,16 +3,16 @@ package com.onarandombox.MultiverseCore.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import com.onarandombox.utils.Destination;
import com.onarandombox.utils.MVDestination;
public class MVTeleportEvent extends Event {
private static final long serialVersionUID = 854826818438649269L;
private Player player;
private Destination dest;
private MVDestination dest;
private String teleportString;
public MVTeleportEvent(Destination dest, Player p, String teleportString) {
public MVTeleportEvent(MVDestination dest, Player p, String teleportString) {
super("MVTeleport");
this.player = p;
this.dest = dest;
@ -27,7 +27,7 @@ public class MVTeleportEvent extends Event {
return this.teleportString;
}
public Class<? extends Destination> getDestType() {
public Class<? extends MVDestination> getDestType() {
return this.dest.getClass();
}
}

View File

@ -7,23 +7,23 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
public class DestinationFactory {
private MultiverseCore plugin;
private Map<String, Class<? extends Destination>> destList;
private Map<String, Class<? extends MVDestination>> destList;
public DestinationFactory(MultiverseCore plugin) {
this.plugin = plugin;
this.destList = new HashMap<String, Class<? extends Destination>>();
this.destList = new HashMap<String, Class<? extends MVDestination>>();
}
public Destination getDestination(String dest) {
public MVDestination getDestination(String dest) {
String idenChar = "";
if(dest.split(":").length > 1) {
idenChar = dest.substring(0, 1);
}
if (this.destList.containsKey(idenChar)) {
Class<? extends Destination> myClass = this.destList.get(idenChar);
Class<? extends MVDestination> myClass = this.destList.get(idenChar);
try {
Destination mydest = myClass.newInstance();
MVDestination mydest = myClass.newInstance();
if(!mydest.isThisType((MultiverseCore) this.plugin, dest)) {
return new InvalidDestination();
}
@ -36,7 +36,7 @@ public class DestinationFactory {
return new InvalidDestination();
}
public boolean registerDestinationType(Class<? extends Destination> c, String identifier) {
public boolean registerDestinationType(Class<? extends MVDestination> c, String identifier) {
if (this.destList.containsKey(identifier)) {
return false;
}

View File

@ -8,7 +8,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class ExactDestination extends Destination {
public class ExactDestination implements MVDestination {
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
private boolean isValid;
private Location location;
@ -36,7 +36,7 @@ public class ExactDestination extends Destination {
}
// If it's not a MV world
if (!((MultiverseCore)plugin).isMVWorld(parsed.get(1))) {
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
return false;
}
@ -92,11 +92,11 @@ public class ExactDestination extends Destination {
return;
}
if (!((MultiverseCore)plugin).isMVWorld(parsed.get(1))) {
if (!((MultiverseCore) plugin).isMVWorld(parsed.get(1))) {
this.isValid = false;
return;
}
this.location = new Location(((MultiverseCore)plugin).getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
this.location = new Location(((MultiverseCore) plugin).getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
if (!parsed.get(2).matches(this.coordRegex)) {
this.isValid = false;
@ -157,4 +157,9 @@ public class ExactDestination extends Destination {
}
return "i:Invalid Destination";
}
@Override
public String getRequiredPermission() {
return "multiverse.access." + this.location.getWorld().getName();
}
}

View File

@ -4,7 +4,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
public class InvalidDestination extends Destination {
public class InvalidDestination implements MVDestination {
@Override
public String getIdentifer() {
@ -46,4 +46,9 @@ public class InvalidDestination extends Destination {
return "i:Invalid Destination";
}
@Override
public String getRequiredPermission() {
return null;
}
}

View File

@ -0,0 +1,16 @@
package com.onarandombox.utils;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
public interface MVDestination {
public String getIdentifer();
public boolean isThisType(JavaPlugin plugin, String dest);
public Location getLocation();
public boolean isValid();
public void setDestination(JavaPlugin plugin, String dest);
public String getType();
public String getName();
public String toString();
public String getRequiredPermission();
}

View File

@ -6,7 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class WorldDestination extends Destination {
public class WorldDestination implements MVDestination {
private boolean isValid;
private MVWorld world;
float yaw = -1;
@ -99,4 +99,9 @@ public class WorldDestination extends Destination {
return this.world.getCBWorld().getName();
}
@Override
public String getRequiredPermission() {
return this.world.getName();
}
}