Updated create commands

This commit is contained in:
sekwah41 2018-02-21 17:19:29 +00:00 committed by Sekwah
parent 55bb31c470
commit d0ca581056
4 changed files with 55 additions and 65 deletions

View File

@ -29,7 +29,6 @@ public class DestinationManager {
}
public void createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) throws PortalException {
Destination destination = new Destination(playerLocation);
if(name == null || name.equals("")) {
throw new PortalException("desti.error.noname");
}

View File

@ -0,0 +1,45 @@
package com.sekwah.advancedportals.core.commands.subcommands;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import java.util.ArrayList;
public abstract class CreateSubCommand {
protected ArrayList<DataTag> getTagsFromArgs(String[] args) {
ArrayList<DataTag> tags = new ArrayList<>();
boolean partingValueWithSpaces = false;
String argBeingParsed = "";
String currentParsedValue = "";
for (int i = 2; i < args.length; i++) {
if(partingValueWithSpaces) {
if(args[i].charAt(args[i].length() - 1) == '"') {
args[i] = args[i].substring(0, args[i].length() - 1);
partingValueWithSpaces = false;
tags.add(new DataTag(argBeingParsed.toLowerCase(), currentParsedValue));
}
else {
currentParsedValue += " " + args[i];
}
}
else {
String detectedTag = this.getTag(args[i].toLowerCase());
if(detectedTag != null) {
String arg = args[i].substring(detectedTag.length());
if(arg.length() > 0 && arg.charAt(0) == '"') {
argBeingParsed = detectedTag;
currentParsedValue = arg;
}
else {
tags.add(new DataTag(detectedTag.toLowerCase(), arg));
}
}
}
}
return tags;
}
protected abstract String getTag(String arg);
}

View File

@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import com.sekwah.advancedportals.core.api.portal.PortalException;
import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
@ -11,7 +12,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.ArrayList;
import java.util.List;
public class CreateSubCommand implements SubCommand {
public class CreateDestiSubCommand extends CreateSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
@ -21,37 +22,9 @@ public class CreateSubCommand implements SubCommand {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<DataTag> portalTags = new ArrayList<>();
boolean partingValueWithSpaces = false;
String argBeingParsed = "";
String currentParsedValue = "";
for (int i = 2; i < args.length; i++) {
if(partingValueWithSpaces) {
if(args[i].charAt(args[i].length() - 1) == '"') {
args[i] = args[i].substring(0, args[i].length() - 1);
partingValueWithSpaces = false;
portalTags.add(new DataTag(argBeingParsed.toLowerCase(), currentParsedValue));
}
else {
currentParsedValue += " " + args[i];
}
}
else {
String detectedTag = this.getTag(args[i].toLowerCase());
if(detectedTag != null) {
String arg = args[i].substring(detectedTag.length());
if(arg.length() > 0 && arg.charAt(0) == '"') {
argBeingParsed = detectedTag;
currentParsedValue = arg;
}
else {
portalTags.add(new DataTag(detectedTag.toLowerCase(), arg));
}
}
}
}
ArrayList<DataTag> destiTags = this.getTagsFromArgs(args);
try {
AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), portalTags);
AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), destiTags);
} catch (PortalException portalTagExeption) {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
+ Lang.translate(portalTagExeption.getMessage()));
@ -62,8 +35,8 @@ public class CreateSubCommand implements SubCommand {
}
}
private String getTag(String arg) {
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
protected String getTag(String arg) {
ArrayList<String> tags = AdvancedPortalsCore.getDestinationTagRegistry().getTags();
for(String tag : tags) {
if(arg.startsWith(tag + ":")) {
return tag;

View File

@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.api.portal.DataTag;
import com.sekwah.advancedportals.core.api.portal.PortalException;
import com.sekwah.advancedportals.core.commands.subcommands.CreateSubCommand;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
@ -11,7 +12,7 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
import java.util.ArrayList;
import java.util.List;
public class CreateSubCommand implements SubCommand {
public class CreatePortalSubCommand extends CreateSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
@ -21,35 +22,7 @@ public class CreateSubCommand implements SubCommand {
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<DataTag> portalTags = new ArrayList<>();
boolean partingValueWithSpaces = false;
String argBeingParsed = "";
String currentParsedValue = "";
for (int i = 2; i < args.length; i++) {
if(partingValueWithSpaces) {
if(args[i].charAt(args[i].length() - 1) == '"') {
args[i] = args[i].substring(0, args[i].length() - 1);
partingValueWithSpaces = false;
portalTags.add(new DataTag(argBeingParsed.toLowerCase(), currentParsedValue));
}
else {
currentParsedValue += " " + args[i];
}
}
else {
String detectedTag = this.getTag(args[i].toLowerCase());
if(detectedTag != null) {
String arg = args[i].substring(detectedTag.length());
if(arg.length() > 0 && arg.charAt(0) == '"') {
argBeingParsed = detectedTag;
currentParsedValue = arg;
}
else {
portalTags.add(new DataTag(detectedTag.toLowerCase(), arg));
}
}
}
}
ArrayList<DataTag> portalTags = this.getTagsFromArgs(args);
try {
AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
} catch (PortalException portalTagExeption) {
@ -62,7 +35,7 @@ public class CreateSubCommand implements SubCommand {
}
}
private String getTag(String arg) {
protected String getTag(String arg) {
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
for(String tag : tags) {
if(arg.startsWith(tag + ":")) {