mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Still working on these multi staged modify commands
This commit is contained in:
parent
55b873ddea
commit
0187a600b3
@ -184,6 +184,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.commandManager.addCommand(new InfoCommand(this));
|
||||
this.commandManager.addCommand(new ReloadCommand(this));
|
||||
this.commandManager.addCommand(new ModifyCommand(this));
|
||||
this.commandManager.addCommand(new ModifyAddCommand(this));
|
||||
this.commandManager.addCommand(new ModifySetCommand(this));
|
||||
this.commandManager.addCommand(new ModifyRemoveCommand(this));
|
||||
this.commandManager.addCommand(new ModifyClearCommand(this));
|
||||
this.commandManager.addCommand(new EnvironmentCommand(this));
|
||||
this.commandManager.addCommand(new PurgeCommand(this));
|
||||
}
|
||||
|
@ -29,23 +29,25 @@ public abstract class BaseCommand {
|
||||
public abstract void execute(CommandSender sender, String[] args);
|
||||
|
||||
public boolean validate(String name, String[] parsedArgs, StringBuilder identifier) {
|
||||
String match = this.matchIdentifier(name);
|
||||
String match = this.matchIdentifier(name, parsedArgs);
|
||||
if (match != null) {
|
||||
identifier = identifier.append(match);
|
||||
if (parsedArgs == null) {
|
||||
parsedArgs = new String[0];
|
||||
}
|
||||
int l = parsedArgs.length;
|
||||
if (l >= this.minArgs && (this.maxArgs == -1 ||l <= this.maxArgs)) {
|
||||
if (l >= this.minArgs && (this.maxArgs == -1 || l <= this.maxArgs)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String matchIdentifier(String input) {
|
||||
String lower = input.toLowerCase();
|
||||
public String matchIdentifier(String input, String[] args) {
|
||||
|
||||
String argsString = this.getArgsString(args);
|
||||
String lower = input.toLowerCase() + argsString;
|
||||
System.out.print("Trying to match Identifer: " + lower);
|
||||
int index = -1;
|
||||
int n = this.identifiers.size();
|
||||
for (int i = 0; i < n; i++) {
|
||||
@ -62,6 +64,14 @@ public abstract class BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private String getArgsString(String[] args) {
|
||||
String returnString = "";
|
||||
for (String s : args) {
|
||||
returnString += " " + s;
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public List<String> getIdentifiers() {
|
||||
return this.identifiers;
|
||||
}
|
||||
|
@ -40,10 +40,12 @@ public class CommandManager {
|
||||
for (BaseCommand cmd : this.commands) {
|
||||
StringBuilder tmpIdentifier = new StringBuilder();
|
||||
String[] tmpArgs = parseAllQuotedStrings(args);
|
||||
|
||||
if (match == null) {
|
||||
match = cmd.matchIdentifier(label) == null ? null : cmd;
|
||||
match = cmd.matchIdentifier(label, tmpArgs) == null ? null : cmd;
|
||||
}
|
||||
|
||||
|
||||
if (match != null && cmd.validate(label, tmpArgs, tmpIdentifier) && tmpIdentifier.length() > identifier.length()) {
|
||||
identifier = tmpIdentifier;
|
||||
trimmedArgs = tmpArgs;
|
||||
|
@ -27,7 +27,7 @@ public class HelpCommand extends BaseCommand {
|
||||
this.minArgs = 0;
|
||||
this.maxArgs = 1;
|
||||
this.identifiers.add("mv");
|
||||
this.identifiers.add("mvhelp");
|
||||
this.identifiers.add("mv help");
|
||||
this.permission = "multiverse.help";
|
||||
this.requiresOp = false;
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||
|
||||
|
||||
|
||||
// This will contain all the properties that support the ADD/REMOVE
|
||||
// Anything not in here will only support the SET action
|
||||
|
||||
public class ModifyAddCommand extends BaseCommand {
|
||||
|
||||
public ModifyAddCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.name = "Modify a World (Add a value)";
|
||||
this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used";
|
||||
this.usage = "/mvmodify " + ChatColor.GREEN + "ADD {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] ";
|
||||
this.minArgs = 3;
|
||||
this.maxArgs = 4;
|
||||
this.identifiers.add("mvmodify add");
|
||||
this.permission = "multiverse.world.modify";
|
||||
this.requiresOp = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (!(sender instanceof Player)) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.length == 3 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.description);
|
||||
sender.sendMessage(this.usage);
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MVWorld world;
|
||||
String value = args[1];
|
||||
String property = args[2];
|
||||
|
||||
if (args.length == 3) {
|
||||
world = this.plugin.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.plugin.getMVWorld(args[3]);
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Add, property)) {
|
||||
sender.sendMessage("Sorry, you can't ADD to " + property);
|
||||
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (world.addToList(property, value)) {
|
||||
sender.sendMessage(value + " was added to " + property);
|
||||
} else {
|
||||
sender.sendMessage(value + " could not be added to " + property);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||
|
||||
public class ModifyClearCommand extends BaseCommand {
|
||||
|
||||
public ModifyClearCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.name = "Modify a World (Clear a property)";
|
||||
this.description = "Removes all values from a property. This will work on properties that contain lists";
|
||||
this.usage = "/mvmodify" + ChatColor.GREEN + " CLEAR {PROPERTY}" + ChatColor.GOLD + " [WORLD] ";
|
||||
this.minArgs = 2;
|
||||
this.maxArgs = 3;
|
||||
this.identifiers.add("mvmodify clear");
|
||||
this.permission = "multiverse.world.modify";
|
||||
this.requiresOp = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (!(sender instanceof Player)) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
if (args.length == 2 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.description);
|
||||
sender.sendMessage(this.usage);
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MVWorld world;
|
||||
String property = args[1];
|
||||
|
||||
if (args.length == 2) {
|
||||
world = this.plugin.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.plugin.getMVWorld(args[2]);
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Clear, property)) {
|
||||
sender.sendMessage("Sorry, you can't use CLEAR with " + property);
|
||||
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
|
||||
return;
|
||||
}
|
||||
if (world.clearList(property)) {
|
||||
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
||||
} else {
|
||||
sender.sendMessage(property + " was NOT cleared.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,22 +2,18 @@ package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||
|
||||
enum Action {
|
||||
Set, Add, Remove, Clear
|
||||
}
|
||||
|
||||
// This will contain all the properties that support the ADD/REMOVE
|
||||
// Anything not in here will only support the SET action
|
||||
enum AddProperties {
|
||||
animallist, monsterlist, blockblacklist, playerwhitelist, playerblacklist, editwhitelist, editblacklist, worldblacklist, animals, monsters
|
||||
}
|
||||
|
||||
enum Action {
|
||||
Set, Add, Remove, Clear
|
||||
}
|
||||
|
||||
enum SetProperties {
|
||||
alias, animals, monsters, pvp, scaling
|
||||
}
|
||||
@ -27,10 +23,10 @@ public class ModifyCommand extends BaseCommand {
|
||||
public ModifyCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.name = "Modify a World";
|
||||
this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used";
|
||||
this.usage = "/mvmodify" + ChatColor.GOLD + " [WORLD] " + ChatColor.GREEN + "{SET|ADD|REMOVE|CLEAR} {PROPERTY} {VALUE|all}";
|
||||
this.minArgs = 2;
|
||||
this.maxArgs = 4;
|
||||
this.description = "MVModify requires an extra parameter: SET,ADD,REMOVE or CLEAR. See below for usage.";
|
||||
this.usage = "/mvmodify" + ChatColor.GREEN + " {SET|ADD|REMOVE|CLEAR} ...";
|
||||
this.minArgs = 0;
|
||||
this.maxArgs = 0;
|
||||
this.identifiers.add("mvmodify");
|
||||
this.permission = "multiverse.world.modify";
|
||||
this.requiresOp = true;
|
||||
@ -38,76 +34,16 @@ public class ModifyCommand extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// We NEED a world from the command line
|
||||
if (args.length == 3 && !(sender instanceof Player)) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
sender.sendMessage(this.name);
|
||||
sender.sendMessage(this.description);
|
||||
sender.sendMessage(this.usage);
|
||||
// This is just a place holder. The real commands are in:
|
||||
// ModifyAddCommand
|
||||
// ModifyRemoveCommand
|
||||
// ModifySetCommand
|
||||
// ModifyClearCommand
|
||||
}
|
||||
|
||||
MVWorld world;
|
||||
Action action;
|
||||
String value;
|
||||
String property;
|
||||
Player p;
|
||||
// Handle special CLEAR case
|
||||
if (args.length == 3) {
|
||||
p = (Player) sender;
|
||||
world = this.plugin.getMVWorld(p.getWorld().getName());
|
||||
action = getActionEnum(args[0]);
|
||||
value = args[2];
|
||||
property = args[1];
|
||||
} else {
|
||||
world = this.plugin.getMVWorld(args[0]);
|
||||
action = getActionEnum(args[1]);
|
||||
value = args[3];
|
||||
property = args[2];
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == null) {
|
||||
sender.sendMessage("That wasn't a valid action. Valid actions are:");
|
||||
sender.sendMessage("SET, ADD or REMOVE");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.validateAction(action, property)) {
|
||||
sender.sendMessage("Sorry, you can't use " + action + " with " + property);
|
||||
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
|
||||
return;
|
||||
}
|
||||
if (action == Action.Set) {
|
||||
if (world.setVariable(property, value)) {
|
||||
sender.sendMessage("Property " + property + " was set to " + value);
|
||||
} else {
|
||||
sender.sendMessage("There was an error setting " + property);
|
||||
}
|
||||
} else if (action == Action.Add) {
|
||||
if (world.addToList(property, value)) {
|
||||
sender.sendMessage(value + " was added to " + property);
|
||||
} else {
|
||||
sender.sendMessage(value + " could not be added to " + property);
|
||||
}
|
||||
} else if (action == Action.Remove) {
|
||||
if (world.removeFromList(property, value)) {
|
||||
sender.sendMessage(value + " was removed from " + property);
|
||||
} else {
|
||||
sender.sendMessage(value + " could not be removed from " + property);
|
||||
}
|
||||
} else if (action == Action.Clear) {
|
||||
if (world.clearList(property)) {
|
||||
sender.sendMessage(property + " was cleared. It contains 0 values now.");
|
||||
} else {
|
||||
sender.sendMessage(property + " was NOT cleared.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateAction(Action action, String property) {
|
||||
protected static boolean validateAction(Action action, String property) {
|
||||
if (action == Action.Set) {
|
||||
try {
|
||||
SetProperties.valueOf(property);
|
||||
@ -125,21 +61,4 @@ public class ModifyCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Action getActionEnum(String action) {
|
||||
if (action.equalsIgnoreCase("set")) {
|
||||
return Action.Set;
|
||||
}
|
||||
if (action.equalsIgnoreCase("add") || action.equalsIgnoreCase("+")) {
|
||||
return Action.Add;
|
||||
}
|
||||
if (action.equalsIgnoreCase("remove") || action.equalsIgnoreCase("-")) {
|
||||
return Action.Remove;
|
||||
}
|
||||
if (action.equalsIgnoreCase("clear")) {
|
||||
return Action.Clear;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||
|
||||
public class ModifyRemoveCommand extends BaseCommand {
|
||||
|
||||
public ModifyRemoveCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.name = "Modify a World";
|
||||
this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used";
|
||||
this.usage = "/mvmodify" + ChatColor.GREEN + "REMOVE {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD] ";
|
||||
this.minArgs = 3;
|
||||
this.maxArgs = 4;
|
||||
this.identifiers.add("mvmodify remove");
|
||||
this.identifiers.add("mvmodify r");
|
||||
this.permission = "multiverse.world.modify";
|
||||
this.requiresOp = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (!(sender instanceof Player)) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.length == 3 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.description);
|
||||
sender.sendMessage(this.usage);
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MVWorld world;
|
||||
String value = args[1];
|
||||
String property = args[2];
|
||||
|
||||
if (args.length == 3) {
|
||||
world = this.plugin.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.plugin.getMVWorld(args[3]);
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Remove, property)) {
|
||||
sender.sendMessage("Sorry, you can't REMOVE anything from" + property);
|
||||
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
|
||||
return;
|
||||
}
|
||||
if (world.removeFromList(property, value)) {
|
||||
sender.sendMessage(value + " was removed from " + property);
|
||||
} else {
|
||||
sender.sendMessage(value + " could not be removed from " + property);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||
|
||||
public class ModifySetCommand extends BaseCommand {
|
||||
|
||||
public ModifySetCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.name = "Modify a World (Set a value)";
|
||||
this.description = "Modify various aspects of worlds. See the help wiki for how to use this command properly. If you do not include a world, the current world will be used";
|
||||
this.usage = "/mvmodify" + ChatColor.GREEN + " SET {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD] ";
|
||||
this.minArgs = 3;
|
||||
this.maxArgs = 4;
|
||||
this.identifiers.add("mvmodify set");
|
||||
this.permission = "multiverse.world.modify";
|
||||
this.requiresOp = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// We NEED a world from the command line
|
||||
Player p = null;
|
||||
if (!(sender instanceof Player)) {
|
||||
p = (Player) sender;
|
||||
}
|
||||
|
||||
if (args.length == 3 && p == null) {
|
||||
sender.sendMessage("From the command line, WORLD is required.");
|
||||
sender.sendMessage(this.description);
|
||||
sender.sendMessage(this.usage);
|
||||
sender.sendMessage("Nothing changed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MVWorld world;
|
||||
String value = args[1];
|
||||
String property = args[2];
|
||||
|
||||
if (args.length == 3) {
|
||||
world = this.plugin.getMVWorld(p.getWorld().getName());
|
||||
} else {
|
||||
world = this.plugin.getMVWorld(args[3]);
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("That world does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ModifyCommand.validateAction(Action.Set, property)) {
|
||||
sender.sendMessage("Sorry, you can't SET " + property);
|
||||
sender.sendMessage("Please visit our wiki for more information: URLGOESHERE FERNFERRET DON'T FORGET IT!");
|
||||
return;
|
||||
}
|
||||
if (world.setVariable(property, value)) {
|
||||
sender.sendMessage("Property " + property + " was set to " + value);
|
||||
} else {
|
||||
sender.sendMessage("There was an error setting " + property);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,12 +2,14 @@ package com.onarandombox.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
|
||||
import com.earth2me.essentials.Mob.Enemies;
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
@ -64,8 +66,9 @@ public class PurgeWorlds {
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
entitiesKilled = 0;
|
||||
this.plugin.log(Level.INFO, "I just murdered " + entitiesKilled + " in " + world.getName());
|
||||
}
|
||||
|
||||
private boolean killCreature(MVWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
@ -97,7 +100,7 @@ public class PurgeWorlds {
|
||||
*/
|
||||
private boolean killMonster(MVWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Slime || e instanceof Monster) {
|
||||
if (e instanceof Slime || e instanceof Monster || e instanceof Ghast) {
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
e.remove();
|
||||
|
Loading…
Reference in New Issue
Block a user