Skip to content

Commit

Permalink
query in PlayerArgumentProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Oct 29, 2023
1 parent 6925a4b commit a73fe9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
@@ -1,6 +1,7 @@
package me.hsgamer.bettergui.argument.type;

import me.hsgamer.bettergui.builder.ArgumentProcessorBuilder;
import me.hsgamer.bettergui.util.StringReplacerApplier;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

Expand All @@ -21,11 +22,6 @@ public PlayerArgumentProcessor(ArgumentProcessorBuilder.Input input) {
.orElse(false);
}

@Override
public String getValue(String query, UUID uuid) {
return getObject(uuid).map(this::getArgumentValue).orElse("");
}

@Override
protected Optional<OfflinePlayer> getObject(String name) {
if (onlineOnly) {
Expand All @@ -49,4 +45,14 @@ protected Stream<OfflinePlayer> getObjectStream() {
protected String getArgumentValue(OfflinePlayer object) {
return Optional.ofNullable(object.getName()).orElse("");
}

@Override
protected String getValue(String query, UUID uuid, OfflinePlayer object) {
if (query.startsWith("papi_")) {
String papiQuery = query.substring("papi_".length());
return StringReplacerApplier.replace("%" + papiQuery + "%", object.getUniqueId(), this);
} else {
return StringReplacerApplier.replace("{" + query + "}", object.getUniqueId(), this);
}
}
}
Expand Up @@ -34,6 +34,8 @@ public SingleArgumentProcessor(ArgumentProcessorBuilder.Input input) {

protected abstract String getArgumentValue(T object);

protected abstract String getValue(String query, UUID uuid, T object);

protected Optional<T> getObject(UUID uuid) {
return Optional.ofNullable(map.get(uuid));
}
Expand Down Expand Up @@ -65,6 +67,21 @@ public Optional<String[]> process(UUID uuid, String[] args) {
return Optional.of(Arrays.copyOfRange(args, 1, args.length));
}

@Override
public String getValue(String query, UUID uuid) {
Optional<T> object = getObject(uuid);
if (!object.isPresent()) {
return "";
}

T obj = object.get();
if (query.isEmpty()) {
return getArgumentValue(obj);
} else {
return getValue(query, uuid, obj);
}
}

@Override
public Pair<Optional<List<String>>, String[]> tabComplete(UUID uuid, String[] args) {
if (args.length == 1) {
Expand Down

0 comments on commit a73fe9c

Please sign in to comment.