mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-29 05:55:19 +01:00
Updated create commands
This commit is contained in:
parent
55bb31c470
commit
d0ca581056
@ -29,7 +29,6 @@ public class DestinationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) throws PortalException {
|
public void createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList<DataTag> tags) throws PortalException {
|
||||||
Destination destination = new Destination(playerLocation);
|
|
||||||
if(name == null || name.equals("")) {
|
if(name == null || name.equals("")) {
|
||||||
throw new PortalException("desti.error.noname");
|
throw new PortalException("desti.error.noname");
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
|||||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
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.core.util.Lang;
|
||||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CreateSubCommand implements SubCommand {
|
public class CreateDestiSubCommand extends CreateSubCommand implements SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
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"));
|
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArrayList<DataTag> portalTags = new ArrayList<>();
|
ArrayList<DataTag> destiTags = this.getTagsFromArgs(args);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), portalTags);
|
AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), destiTags);
|
||||||
} catch (PortalException portalTagExeption) {
|
} catch (PortalException portalTagExeption) {
|
||||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
|
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " "
|
||||||
+ Lang.translate(portalTagExeption.getMessage()));
|
+ Lang.translate(portalTagExeption.getMessage()));
|
||||||
@ -62,8 +35,8 @@ public class CreateSubCommand implements SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTag(String arg) {
|
protected String getTag(String arg) {
|
||||||
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
|
ArrayList<String> tags = AdvancedPortalsCore.getDestinationTagRegistry().getTags();
|
||||||
for(String tag : tags) {
|
for(String tag : tags) {
|
||||||
if(arg.startsWith(tag + ":")) {
|
if(arg.startsWith(tag + ":")) {
|
||||||
return tag;
|
return tag;
|
@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore;
|
|||||||
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
import com.sekwah.advancedportals.core.api.commands.SubCommand;
|
||||||
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
import com.sekwah.advancedportals.core.api.portal.DataTag;
|
||||||
import com.sekwah.advancedportals.core.api.portal.PortalException;
|
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.core.util.Lang;
|
||||||
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
|
||||||
import com.sekwah.advancedportals.coreconnector.container.PlayerContainer;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CreateSubCommand implements SubCommand {
|
public class CreatePortalSubCommand extends CreateSubCommand implements SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
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"));
|
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArrayList<DataTag> portalTags = new ArrayList<>();
|
ArrayList<DataTag> portalTags = this.getTagsFromArgs(args);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
|
AdvancedPortalsCore.getPortalManager().createPortal(args[1], player, portalTags);
|
||||||
} catch (PortalException portalTagExeption) {
|
} 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();
|
ArrayList<String> tags = AdvancedPortalsCore.getPortalTagRegistry().getTags();
|
||||||
for(String tag : tags) {
|
for(String tag : tags) {
|
||||||
if(arg.startsWith(tag + ":")) {
|
if(arg.startsWith(tag + ":")) {
|
Loading…
Reference in New Issue
Block a user