Skip to content

Commit

Permalink
feat: new tag parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 22, 2023
1 parent beee5e0 commit 394b238
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.config;
package com.sekwah.advancedportals.core.serializeddata.config;

/**
* To store the data for config
Expand Down Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.config;
package com.sekwah.advancedportals.core.serializeddata.config;

import com.google.inject.Provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 394b238

Please sign in to comment.