fix: portal activation issue

This commit is contained in:
Sekwah 2024-01-15 01:20:12 +00:00
parent 116c45f5a5
commit ad3f117f04
13 changed files with 54 additions and 49 deletions

View File

@ -43,6 +43,8 @@ public class AdvancedPortalsCore {
private final ServerContainer serverContainer;
private static AdvancedPortalsCore instance;
@Inject
private CommandRegister commandRegister;
@ -68,6 +70,7 @@ public class AdvancedPortalsCore {
private GameScheduler gameScheduler;
public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, InfoLogger infoLogger, ServerContainer serverContainer) {
instance = this;
this.serverContainer = serverContainer;
this.dataStorage = new DataStorage(dataStorageLoc);
this.infoLogger = infoLogger;
@ -202,6 +205,10 @@ public class AdvancedPortalsCore {
return mcVersion;
}
public static AdvancedPortalsCore getInstance() {
return instance;
}
public ServerContainer getServerContainer() {
return serverContainer;
}

View File

@ -1,10 +1,8 @@
package com.sekwah.advancedportals.core.commands.subcommands.common;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.util.InfoLogger;
import com.sekwah.advancedportals.core.util.TagReader;
import com.sekwah.advancedportals.core.warphandler.Tag;
@ -55,18 +53,16 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
var tagSuggestions = autoComplete.autoComplete(argData);
if(tagSuggestions != null) {
if(tag instanceof Tag.SplitTag splitTag) {
if(tag instanceof Tag.Split splitTag) {
var multiTagSplit = splitTag.splitString();
System.out.printf("Splitting with %s%n", multiTagSplit);
boolean endsWithSplit = argData.endsWith(multiTagSplit);
String[] items = argData.split(multiTagSplit);
System.out.printf("Splitting with %s%n", Arrays.toString(items));
Set<String> existingItems = Arrays.stream(items, 0, endsWithSplit ? items.length : items.length - 1)
.map(String::trim)
.collect(Collectors.toSet());
String partialInput = endsWithSplit ? "" : items[items.length - 1].trim();
String baseString = endsWithSplit ? argData : argData.substring(0, argData.lastIndexOf(",") + 1);
String baseString = endsWithSplit ? argData : argData.substring(0, argData.lastIndexOf(multiTagSplit) + 1);
tagSuggestions = tagSuggestions.stream()
// Remove already listed items
@ -90,17 +86,17 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
}
}
ArrayList<DataTag> portalTags = TagReader.getTagsFromArgs(args);
ArrayList<DataTag> tagsFromArgs = TagReader.getTagsFromArgs(args);
allTags.stream().filter(tag -> {
for (DataTag portalTag : portalTags) {
if(portalTag.NAME.equals(tag.getName())) {
for (DataTag argTag : tagsFromArgs) {
if(argTag.NAME.equals(tag.getName())) {
return false;
}
var aliases = tag.getAliases();
if(aliases != null) {
for (String alias : aliases) {
if(portalTag.NAME.equals(alias)) {
if(argTag.NAME.equals(alias)) {
return false;
}
}
@ -127,13 +123,24 @@ public abstract class CreateTaggedSubCommand implements SubCommand {
List<Tag> relatedTags = this.getRelatedTags();
List<DataTag> processedTags = new ArrayList<>();
for (DataTag dataTag : dataTags) {
for (var dataTag : dataTags) {
for (Tag tag : relatedTags) {
if(tag instanceof Tag.Split splitTag) {
var splitString = splitTag.splitString();
if(splitString != null) {
List<String> newValues = new ArrayList<>();
for(String split : dataTag.VALUES) {
newValues.addAll(Arrays.stream(split.split(splitString)).map(String::trim).toList());
}
dataTag = new DataTag(dataTag.NAME, newValues.toArray(new String[0]));
}
}
if (dataTag.NAME.equals(tag.getName())) {
// DataTag name matches the tag's main name, add as is
processedTags.add(dataTag);
break;
} else if (tag.getAliases() != null && Arrays.asList(tag.getAliases()).contains(dataTag.NAME)) {
// There is currently an edge case where if someone uses multiple aliases or names for tags at the same time, it'll only use the last one applied to the mapping.
// DataTag name matches an alias, create a new DataTag with the main name
processedTags.add(new DataTag(tag.getName(), dataTag.VALUES));
break;

View File

@ -33,6 +33,7 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.destination.console"));
return;
}
ArrayList<DataTag> destinationTags = TagReader.getTagsFromArgs(args);
// Find the tag with the "name" NAME

View File

@ -43,6 +43,7 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.console"));
return;
}
ArrayList<DataTag> portalTags = TagReader.getTagsFromArgs(args);
// Find the tag with the "name" NAME

View File

@ -15,4 +15,5 @@ public interface EntityContainer {
WorldContainer getWorld();
String getName();
}

View File

@ -17,9 +17,6 @@ public class PlayerDataRepositoryImpl implements IPlayerDataRepository {
private final String fileLocation = "playerData/";
@Inject
private ConfigRepository configRepository;
@Inject
DataStorage dataStorage;

View File

@ -1,12 +1,10 @@
package com.sekwah.advancedportals.core.repository.impl;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
import com.sekwah.advancedportals.core.repository.IPortalRepository;
import com.sekwah.advancedportals.core.tags.activation.NameTag;
@ -44,7 +42,9 @@ public class PortalRepositoryImpl implements IPortalRepository {
@Override
public AdvancedPortal get(String name) {
return dataStorage.loadJson(AdvancedPortal.class, fileLocation + name + ".json");
var portal = dataStorage.loadJson(AdvancedPortal.class, fileLocation + name + ".json");
AdvancedPortalsCore.getInstance().getModule().getInjector().injectMembers(portal);
return portal;
}
@Override

View File

@ -86,10 +86,10 @@ public class PortalServices {
var blockEntityTopMaterial = world.getBlock(blockEntityTopLoc);
for (AdvancedPortal portal : portalCache.values()) {
if (portal.isLocationInPortal(toLoc)
|| portal.isLocationInPortal(blockEntityTopLoc)
|| portal.isTriggerBlock(blockMaterial)
|| portal.isTriggerBlock(blockEntityTopMaterial)) {
if ((portal.isLocationInPortal(toLoc)
&& portal.isTriggerBlock(blockMaterial))
|| (portal.isLocationInPortal(blockEntityTopLoc)
&& portal.isTriggerBlock(blockEntityTopMaterial))) {
portal.activate(player);
}
}

View File

@ -8,9 +8,11 @@ import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;
import javax.annotation.Nullable;
import java.util.List;
public class DestiTag implements Tag.Activation, Tag.AutoComplete {
public class DestiTag implements Tag.Activation, Tag.AutoComplete, Tag.Split {
public static String TAG_NAME = "destination";
@Inject
@ -63,4 +65,10 @@ public class DestiTag implements Tag.Activation, Tag.AutoComplete {
public List<String> autoComplete(String argData) {
return destinationServices.getDestinationNames();
}
@Nullable
@Override
public String splitString() {
return ",";
}
}

View File

@ -1,21 +1,14 @@
package com.sekwah.advancedportals.core.tags.activation;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.registry.TagTarget;
import com.sekwah.advancedportals.core.services.DestinationServices;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class TriggerBlockTag implements Tag.AutoComplete, Tag.SplitTag {
public class TriggerBlockTag implements Tag.AutoComplete, Tag.Split {
@Inject
private ServerContainer serverContainer;
@ -47,23 +40,6 @@ public class TriggerBlockTag implements Tag.AutoComplete, Tag.SplitTag {
@Override
public List<String> autoComplete(String argData) {
return serverContainer.getTriggerBlocks();
// boolean endsWithComma = argData.endsWith(",");
// String[] items = argData.split(",");
// Set<String> existingItems = Arrays.stream(items, 0, endsWithComma ? items.length : items.length - 1)
// .map(String::trim)
// .collect(Collectors.toSet());
//
// String partialInput = endsWithComma ? "" : items[items.length - 1].trim();
// String baseString = endsWithComma ? argData : argData.substring(0, argData.lastIndexOf(",") + 1);
//
// return serverContainer.getTriggerBlocks().stream()
// // Remove already listed items
// .filter(s -> !existingItems.contains(s))
// // Remove items that don't match the currently typed input
// .filter(s -> s.startsWith(partialInput))
// // Remap so the auto completes actually show
// .map(s -> baseString + s)
// .collect(Collectors.toList());
}
@Nullable

View File

@ -1,9 +1,11 @@
package com.sekwah.advancedportals.core.util;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.warphandler.Tag;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class TagReader {

View File

@ -57,7 +57,7 @@ public interface Tag {
}
interface SplitTag extends Tag {
interface Split extends Tag {
/**
* This is used to split the tag into the arguments if multiple are supported

View File

@ -58,4 +58,9 @@ public class SpigotEntityContainer implements EntityContainer {
public WorldContainer getWorld() {
return new SpigotWorldContainer(this.entity.getWorld());
}
@Override
public String getName() {
return this.entity.getName();
}
}