Skip to content

Commit

Permalink
feat: remap and filter tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Dec 7, 2023
1 parent 3c517a9 commit 0cf22e3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage("");
sender.sendMessage(Lang.translate("command.create.tags"));

if(destinationTags.isEmpty()) {
sender.sendMessage(Lang.translate("desti.info.noargs"));
}
else {
this.printTags(sender, destinationTags, Tag.TagType.DESTINATION);
if(!destinationTags.isEmpty()) {
this.filterAndProcessTags(destinationTags);
this.printTags(sender, destinationTags);
}
sender.sendMessage("");
Destination destination = destinationServices.createDesti(player, player.getLoc(), destinationTags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.complete"));
sender.sendMessage(Lang.translate("command.create.tags"));
sender.sendMessage("\u00A7a" + "triggerBlock\u00A77:\u00A7e" + Arrays.toString(portal.getTriggerBlocks()));
this.printTags(sender, portal.getArgs(), Tag.TagType.PORTAL);
this.printTags(sender, portal.getArgs());
}
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.error"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,41 @@ public List<String> onTabComplete(CommandSenderContainer sender, String[] args)
return suggestions;
}

protected void printTags(CommandSenderContainer sender, List<DataTag> dataTags, Tag.TagType tagType) {
protected void filterAndProcessTags(List<DataTag> dataTags) {
List<Tag> relatedTags = this.getRelatedTags();
List<DataTag> processedTags = new ArrayList<>();

for (DataTag dataTag : dataTags) {
for (Tag tag : relatedTags) {
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)) {
// DataTag name matches an alias, create a new DataTag with the main name
processedTags.add(new DataTag(tag.getName(), dataTag.VALUES));
break;
}
}
}

// Replace the original dataTags list with the processed tags
dataTags.clear();
dataTags.addAll(processedTags);
// Sort the tags by name however make sure name is first
dataTags.sort((o1, o2) -> {
if(o1.NAME.equals("name")) {
return -1;
}
if(o2.NAME.equals("name")) {
return 1;
}
return o1.NAME.compareTo(o2.NAME);
});
}


protected void printTags(CommandSenderContainer sender, List<DataTag> dataTags) {
for (DataTag tag : dataTags) {
if(tag.VALUES.length == 1) {
sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
Expand All @@ -112,6 +146,5 @@ protected void printTags(CommandSenderContainer sender, List<DataTag> dataTags,
}
}
}
// TODO add a note saying if tags were ignored due to not being valid for the type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Destination implements TagTarget {
private PlayerLocation loc;

@SerializedName("a")
transient private HashMap<String, String[]> args = new HashMap<>();
private HashMap<String, String[]> args = new HashMap<>();

private transient Set<String> argsCol;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* <p>
* Most tags shouldn't be like this unless they are to be paired with another tag.
*/
public class NameTag implements Tag.Activation, Tag.AutoComplete {
public class NameTag implements Tag.AutoComplete {

private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL, TagType.DESTINATION };

Expand All @@ -39,21 +39,6 @@ public String description() {
return Lang.translate("tag.name.description");
}

@Override
public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
return false;
}

@Override
public void postActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {

}

@Override
public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
return false;
}

@Override
public List<String> autoComplete(String argData) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ desti.error.noname= You must specify a name. (name:someNameHere)

error.notplayer=Only players can do that.

portal.selector.poschange=&eYou have selected pos%1$s X:%2$s Y:%3$s Z:%4$s
portal.selector.poschange=&aYou have selected &epos%1$s &aX&7:&e%2$s &aY&7:&e%3$s &aZ&7:&e%4$s

command.lang.help=Update the translation file

Expand Down

0 comments on commit 0cf22e3

Please sign in to comment.