feat: new tag parser

This commit is contained in:
Sekwah 2023-11-22 01:16:36 +00:00
parent beee5e09dd
commit 394b238958
7 changed files with 73 additions and 32 deletions

View File

@ -2,8 +2,8 @@ package com.sekwah.advancedportals.core.module;
import com.google.inject.*;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.config.Config;
import com.sekwah.advancedportals.core.config.ConfigProvider;
import com.sekwah.advancedportals.core.serializeddata.config.Config;
import com.sekwah.advancedportals.core.serializeddata.config.ConfigProvider;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.repository.IDestinationRepository;

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.repository.impl;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.config.Config;
import com.sekwah.advancedportals.core.serializeddata.config.Config;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.repository.ConfigRepository;

View File

@ -28,4 +28,35 @@ public class PlayerTempData {
private String selectedPortal;
public BlockLocation getPos1() {
return pos1;
}
public void setPos1(BlockLocation pos1) {
this.pos1 = pos1;
}
public BlockLocation getPos2() {
return pos2;
}
public void setPos2(BlockLocation pos2) {
this.pos2 = pos2;
}
public long getGlobalCooldown() {
return globalCooldown;
}
public void setGlobalCooldown(long globalCooldown) {
this.globalCooldown = globalCooldown;
}
public String getSelectedPortal() {
return selectedPortal;
}
public void setSelectedPortal(String selectedPortal) {
this.selectedPortal = selectedPortal;
}
}

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.config;
package com.sekwah.advancedportals.core.serializeddata.config;
/**
* To store the data for config
@ -27,8 +27,4 @@ public class Config {
public String translationFile = "en_GB";
//public String selectionBlock_BELOW_1_13 = "STAINED_GLASS";
// public int selectionSubID_BELOW_1_13 = 14;
}

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.config;
package com.sekwah.advancedportals.core.serializeddata.config;
import com.google.inject.Provider;

View File

@ -3,6 +3,7 @@ package com.sekwah.advancedportals.core.services;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerTempData;
import com.sekwah.advancedportals.core.util.Lang;
import javax.inject.Singleton;
import java.util.HashMap;
@ -17,12 +18,24 @@ public final class PortalTempDataServices {
*/
private Map<UUID, PlayerTempData> tempDataMap = new HashMap<>();
private PlayerTempData getPlayerTempData(PlayerContainer player) {
return tempDataMap.computeIfAbsent(player.getUUID(), uuid -> new PlayerTempData());
}
public void activateCooldown(PlayerContainer player) {
}
public void playerLeave(PlayerContainer player) {
tempDataMap.remove(player.getUUID());
}
public void playerSelectorActivate(PlayerContainer player, BlockLocation blockLoc, boolean leftClick) {
var tempData = getPlayerTempData(player);
if(leftClick) {
tempData.setPos1(blockLoc);
} else {
tempData.setPos2(blockLoc);
}
player.sendMessage(Lang.translateInsertVariables("portal.selector.poschange", leftClick ? "1" : "2", blockLoc.posX, blockLoc.posY, blockLoc.posZ));
}
}

View File

@ -8,34 +8,35 @@ public class TagReader {
public static ArrayList<DataTag> getTagsFromArgs(String[] args) {
ArrayList<DataTag> tags = new ArrayList<>();
boolean partingValueWithSpaces = false;
String argBeingParsed = "";
String currentParsedValue = "";
for (int i = 1; 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));
StringBuilder currentValue = new StringBuilder();
String currentIdentifier = null;
boolean inQuotes = false;
for (String arg : args) {
if (arg.contains(":") && !inQuotes) {
if (currentIdentifier != null) {
tags.add(new DataTag(currentIdentifier, currentValue.toString()));
}
else {
currentParsedValue += " " + args[i];
int colonIndex = arg.indexOf(':');
currentIdentifier = arg.substring(0, colonIndex);
currentValue = new StringBuilder(arg.substring(colonIndex + 1));
inQuotes = currentValue.toString().startsWith("\"");
} else {
if (!currentValue.isEmpty()) {
currentValue.append(" ");
}
currentValue.append(arg);
}
else {
String detectedTag = TagReader.getTag(args[i].toLowerCase());
if(detectedTag != null) {
String arg = args[i].substring(detectedTag.length() + 1);
if(arg.length() > 0 && arg.charAt(0) == '"') {
argBeingParsed = detectedTag;
currentParsedValue = arg;
}
else {
tags.add(new DataTag(detectedTag.toLowerCase(), arg));
}
}
if (inQuotes && arg.endsWith("\"")) {
inQuotes = false;
}
}
if (currentIdentifier != null) {
tags.add(new DataTag(currentIdentifier, currentValue.toString().replace("\"", "")));
}
return tags;
}