mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-09-28 23:27:27 +02:00
Implement Check Command
This commit is contained in:
parent
c7e5816b2e
commit
c7c73e7094
@ -324,6 +324,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new EnvironmentCommand(this));
|
||||
this.commandHandler.registerCommand(new DebugCommand(this));
|
||||
this.commandHandler.registerCommand(new GeneratorCommand(this));
|
||||
this.commandHandler.registerCommand(new CheckCommand(this));
|
||||
}
|
||||
|
||||
/** Deprecated, please use WorldManager.loadWorlds(Boolean forceLoad) now. */
|
||||
|
@ -0,0 +1,63 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.WorldManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CheckCommand extends MultiverseCommand {
|
||||
private WorldManager worldManager;
|
||||
|
||||
public CheckCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Help you validate your multiverse settings");
|
||||
this.setCommandUsage("/mv check " + ChatColor.GREEN + "{PLAYER} {DESTINATION}");
|
||||
this.setArgRange(2, 2);
|
||||
this.addKey("mv check");
|
||||
this.addKey("mvcheck");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "fernferret " + ChatColor.LIGHT_PURPLE + "w:MyWorld");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "Rigby90 " + ChatColor.LIGHT_PURPLE + "p:MyPortal");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "lithium3141 " + ChatColor.LIGHT_PURPLE + "ow:WarpName");
|
||||
this.setPermission("multiverse.core.debug", "Checks to see if a player can go to a destination. Prints debug if false.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = this.plugin.getServer().getPlayer(args.get(0));
|
||||
if (p == null) {
|
||||
sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0));
|
||||
sender.sendMessage("Are they online?");
|
||||
return;
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
sender.sendMessage("You asked if '" + args.get(0) + "' could go to " + ChatColor.GREEN + args.get(0) + ChatColor.WHITE + ",");
|
||||
sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?");
|
||||
return;
|
||||
}
|
||||
|
||||
MVPermissions perms = this.plugin.getMVPerms();
|
||||
if (perms.canEnterDestination(p, dest)) {
|
||||
sender.sendMessage(ChatColor.GREEN + args.get(0) + ChatColor.WHITE + " can travel to " + ChatColor.GREEN + args.get(1));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.AQUA + args.get(0) + ChatColor.RED + " CANNOT travel to " + ChatColor.AQUA + args.get(1));
|
||||
sender.sendMessage("Please turn debug mode to 3 then watch the console to find out why!");
|
||||
sender.sendMessage("Use: " + ChatColor.GREEN + "/mv debug 3");
|
||||
}
|
||||
}
|
||||
}
|
@ -22,12 +22,15 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
public ConfigCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Configuration");
|
||||
this.setCommandUsage("/mv config");
|
||||
this.setCommandUsage("/mv config " + ChatColor.GREEN + "{PROPERTY} {VALUE}");
|
||||
this.setArgRange(2, 2);
|
||||
this.addKey("mv config");
|
||||
this.addKey("mvconfig");
|
||||
this.addKey("mv conf");
|
||||
this.addKey("mvconf");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false");
|
||||
this.addCommandExample("/mv config " + ChatColor.GREEN + "bedrespawn" + ChatColor.AQUA + " true");
|
||||
this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP);
|
||||
this.worldManager = this.plugin.getMVWorldManager();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** A factory class that will create destinations from specific strings. */
|
||||
public class DestinationFactory {
|
||||
private MultiverseCore plugin;
|
||||
private Map<String, Class<? extends MVDestination>> destList;
|
||||
@ -35,6 +36,14 @@ public class DestinationFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new destination from a string.
|
||||
* Returns a new InvalidDestination if the string could not be parsed.
|
||||
*
|
||||
* @param destination The destination in string format.
|
||||
*
|
||||
* @return A non-null MVDestination
|
||||
*/
|
||||
public MVDestination getDestination(String destination) {
|
||||
String idenChar = "";
|
||||
if (destination.split(":").length > 1) {
|
||||
|
@ -117,6 +117,8 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import sun.security.util.Debug;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
@ -38,12 +39,12 @@ public class MVPermissions implements PermissionsInterface {
|
||||
/**
|
||||
* Check if a Player can teleport to the Destination world from there current world.
|
||||
*
|
||||
* @param p
|
||||
* @param p The player to check.
|
||||
* @param w
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean canTravelFromWorld(Player p, MultiverseWorld w) {
|
||||
public boolean canTravelFromWorld(Player p, MultiverseWorld w) {
|
||||
List<String> blackList = w.getWorldBlacklist();
|
||||
|
||||
boolean returnValue = true;
|
||||
@ -77,11 +78,11 @@ public class MVPermissions implements PermissionsInterface {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean canEnterWorld(Player p, MultiverseWorld w) {
|
||||
public boolean canEnterWorld(Player p, MultiverseWorld w) {
|
||||
return this.hasPermission(p, "multiverse.access." + w.getName(), false);
|
||||
}
|
||||
|
||||
public Boolean canEnterLocation(Player p, Location l) {
|
||||
public boolean canEnterLocation(Player p, Location l) {
|
||||
if (l == null) {
|
||||
return false;
|
||||
}
|
||||
@ -92,7 +93,17 @@ public class MVPermissions implements PermissionsInterface {
|
||||
return this.hasPermission(p, "multiverse.access." + worldName, false);
|
||||
}
|
||||
|
||||
public Boolean canEnterDestination(CommandSender sender, MVDestination d) {
|
||||
/**
|
||||
* Check to see if a sender can enter a destination.
|
||||
* The reason this is not a player, is it can be used to simply check permissions
|
||||
* The console should, for exmaple, always see all worlds
|
||||
*
|
||||
* @param sender The CommandSender to check.
|
||||
* @param d The destination they are requesting.
|
||||
*
|
||||
* @return True if that sender can go to that destination
|
||||
*/
|
||||
public boolean canEnterDestination(CommandSender sender, MVDestination d) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user