diff --git a/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java b/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java index 6d387a43..43d78c10 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java @@ -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; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index 2a5c63b2..8e3933a1 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -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; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java index fdb7c048..5694777f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/PlayerTempData.java @@ -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; + } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/config/Config.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java similarity index 77% rename from core/src/main/java/com/sekwah/advancedportals/core/config/Config.java rename to core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java index a10b2ef1..5eb8c0fa 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/config/Config.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java @@ -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; - } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/config/ConfigProvider.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/ConfigProvider.java similarity index 72% rename from core/src/main/java/com/sekwah/advancedportals/core/config/ConfigProvider.java rename to core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/ConfigProvider.java index 655f78e7..4873ab7f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/config/ConfigProvider.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/ConfigProvider.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.core.config; +package com.sekwah.advancedportals.core.serializeddata.config; import com.google.inject.Provider; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/PortalTempDataServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/PortalTempDataServices.java index f36ec8d3..ab4181eb 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/PortalTempDataServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/PortalTempDataServices.java @@ -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; @@ -17,12 +18,24 @@ public final class PortalTempDataServices { */ private Map 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)); } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java b/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java index 2b4e6bcc..a39433b4 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java @@ -8,34 +8,35 @@ public class TagReader { public static ArrayList getTagsFromArgs(String[] args) { ArrayList 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; }