diff --git a/pom.xml b/pom.xml
index e927e37..9407c79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,7 @@
fr.zcraft
quartzlib
- 0.0.1
+ 0.0.2
org.bstats
diff --git a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java
index c110d87..241b0ea 100644
--- a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java
+++ b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java
@@ -38,15 +38,11 @@ package fr.moribus.imageonmap;
import fr.moribus.imageonmap.commands.maptool.DeleteCommand;
-import fr.moribus.imageonmap.commands.maptool.DeleteOtherCommand;
import fr.moribus.imageonmap.commands.maptool.ExploreCommand;
-import fr.moribus.imageonmap.commands.maptool.ExploreOtherCommand;
import fr.moribus.imageonmap.commands.maptool.GetCommand;
-import fr.moribus.imageonmap.commands.maptool.GetOtherCommand;
import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand;
import fr.moribus.imageonmap.commands.maptool.GiveCommand;
import fr.moribus.imageonmap.commands.maptool.ListCommand;
-import fr.moribus.imageonmap.commands.maptool.ListOtherCommand;
import fr.moribus.imageonmap.commands.maptool.MigrateCommand;
import fr.moribus.imageonmap.commands.maptool.NewCommand;
import fr.moribus.imageonmap.commands.maptool.RenameCommand;
@@ -74,6 +70,7 @@ public final class ImageOnMap extends QuartzPlugin {
private static ImageOnMap plugin;
private final File mapsDirectory;
private File imagesDirectory;
+ private CommandWorkers commandWorker;
public ImageOnMap() {
imagesDirectory = new File(this.getDataFolder(), IMAGES_DIRECTORY_NAME);
@@ -97,6 +94,9 @@ public final class ImageOnMap extends QuartzPlugin {
return new File(imagesDirectory, "map" + mapID + ".png");
}
+ public CommandWorkers getCommandWorker() {
+ return commandWorker;
+ }
@SuppressWarnings("unchecked")
@Override
@@ -113,9 +113,9 @@ public final class ImageOnMap extends QuartzPlugin {
saveDefaultConfig();
-
+ commandWorker = loadComponent(CommandWorkers.class);
loadComponents(I18n.class, Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class,
- ImageRendererExecutor.class, CommandWorkers.class);
+ ImageRendererExecutor.class);
//Init all the things !
I18n.setPrimaryLocale(PluginConfiguration.LANG.get());
@@ -129,23 +129,19 @@ public final class ImageOnMap extends QuartzPlugin {
"maptool",
NewCommand.class,
ListCommand.class,
- ListOtherCommand.class,
GetCommand.class,
- GetOtherCommand.class,
RenameCommand.class,
DeleteCommand.class,
- DeleteOtherCommand.class,
GiveCommand.class,
GetRemainingCommand.class,
ExploreCommand.class,
- ExploreOtherCommand.class,
MigrateCommand.class,
UpdateCommand.class
);
Commands.registerShortcut("maptool", NewCommand.class, "tomap");
Commands.registerShortcut("maptool", ExploreCommand.class, "maps");
- Commands.registerShortcut("maptool", GiveCommand.class, "mapgive");
+ Commands.registerShortcut("maptool", GiveCommand.class, "givemap");
if (PluginConfiguration.CHECK_FOR_UPDATES.get()) {
UpdateChecker.boot("imageonmap.26585");
diff --git a/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java b/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java
index 4bbb6e4..6517cb9 100644
--- a/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java
+++ b/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java
@@ -43,61 +43,15 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.i18n.I;
import java.util.ArrayList;
import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.bukkit.entity.Player;
public abstract class IoMCommand extends Command {
+
protected ImageMap getMapFromArgs() throws CommandException {
return getMapFromArgs(playerSender(), 0, true);
}
- //TODO:Add the quote system to zlib and refactor this
- protected ImageMap getMapFromArgs(Player player, int index) throws CommandException {
- if (args.length <= index) {
- throwInvalidArgument(I.t("You need to give a map name."));
- }
-
-
- StringBuilder mapName = new StringBuilder(args[index]);
- for (int i = index + 1, c = args.length; i < c; i++) {
- mapName.append(" ").append(args[i]);
- }
- String regex = "((\"([^\\\"]*(\\\\\\\")*)*([^\\\\\\\"]\"))|([^\\\"\\s\\\\]*(\\\\\\s)*[\\\\]*)*\"?)";
-
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(mapName.toString());
-
- StringBuilder result = new StringBuilder();
-
- //matcher.find();
- result.append(matcher.group(0));
- if (result != null) {
- if (result.charAt(0) == '\"') {
- if (result.length() == 1) {
- result.deleteCharAt(0);
- } else if (result.charAt(result.length() - 1) == '\"') {
- result = result.deleteCharAt(result.length() - 1);
- if (result != null && !result.equals("") && result.charAt(0) == '\"') {
- mapName = new StringBuilder(result.deleteCharAt(0).toString());
- }
-
- }
- }
- }
-
-
- mapName = new StringBuilder(mapName.toString().trim());
- ImageMap map;
- map = MapManager.getMap(player.getUniqueId(), mapName.toString());
-
- if (map == null) {
- error(I.t("This map does not exist."));
- }
- return map;
- }
-
protected ImageMap getMapFromArgs(Player player, int index, boolean expand) throws CommandException {
if (args.length <= index) {
throwInvalidArgument(I.t("You need to give a map name."));
@@ -122,6 +76,61 @@ public abstract class IoMCommand extends Command {
return map;
}
+ protected ArrayList getArgs() {
+ ArrayList arguments = new ArrayList<>();
+
+ //State of the automaton, can read word like:
+ //name_here; "name here"
+ int state = 0;
+ StringBuilder s = new StringBuilder();
+
+ for (String arg : args) {
+ if (arg.startsWith("http:") || arg.startsWith("https:")) {
+ arguments.add(arg);
+ continue;
+ }
+ if (state == 0) {
+ s = new StringBuilder();
+ } else {
+ s.append(" ");
+ }
+ for (char c : arg.toCharArray()) {
+ switch (state) {
+ case 0:
+ if (c == '\"') {
+ state = 1;
+ } else {
+ //If we read a : that means that we are on a new argument example:"hello"
+ if (c == ':') {
+ arguments.add(s.toString());
+ s = new StringBuilder();
+ } else {
+ s = s.append(c);
+ }
+ }
+ break;
+ case 1:
+ if (c == '\"') {
+ arguments.add(s.toString());
+ s = new StringBuilder();
+ state = 0;
+ } else {
+ s = s.append(c);
+ }
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + state);
+ }
+ }
+ if (s.length() > 0 && state != 1) {
+ arguments.add(s.toString());
+ }
+
+ }
+ return arguments;
+ }
+
+
protected List getMatchingMapNames(Player player, String prefix) {
return getMatchingMapNames(MapManager.getMapList(player.getUniqueId()), prefix);
}
diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java
index 021cdd7..033277d 100644
--- a/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java
+++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java
@@ -36,6 +36,7 @@
package fr.moribus.imageonmap.commands.maptool;
+import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
@@ -47,16 +48,18 @@ import fr.zcraft.quartzlib.components.commands.WithFlags;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.rawtext.RawText;
import fr.zcraft.quartzlib.tools.PluginLogger;
+import fr.zcraft.quartzlib.tools.text.RawMessage;
+import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-@CommandInfo(name = "delete", usageParameters = "