mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
优化visitor
This commit is contained in:
@@ -170,12 +170,12 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ComponentProvider> matchTags(String json) {
|
||||
public Map<String, ComponentProvider> matchTags(String text) {
|
||||
if (this.networkTagTrie == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, ComponentProvider> tags = new HashMap<>();
|
||||
for (Token token : this.networkTagTrie.tokenize(json)) {
|
||||
for (Token token : this.networkTagTrie.tokenize(text)) {
|
||||
if (token.isMatch()) {
|
||||
tags.put(token.getFragment(), this.networkTagMapper.get(token.getFragment()));
|
||||
}
|
||||
|
||||
@@ -6,10 +6,8 @@ import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.text.component.ComponentProvider;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import net.momirealms.craftengine.core.util.CharacterUtils;
|
||||
import net.momirealms.craftengine.core.util.FormatUtils;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -110,7 +108,11 @@ public interface FontManager extends Manageable {
|
||||
return createOffsets(offset, (raw, font) -> raw);
|
||||
}
|
||||
|
||||
Map<String, ComponentProvider> matchTags(String json);
|
||||
Map<String, ComponentProvider> matchTags(String text);
|
||||
|
||||
default Map<String, ComponentProvider> matchTags(Tag nbt) {
|
||||
return matchTags(new StringValueOnlyTagVisitor().visit(nbt));
|
||||
}
|
||||
|
||||
void refreshEmojiSuggestions(UUID uuid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import net.momirealms.sparrow.nbt.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StringValueOnlyTagVisitor implements TagVisitor {
|
||||
protected final StringBuilder builder = new StringBuilder();
|
||||
|
||||
public String visit(Tag element) {
|
||||
element.accept(this);
|
||||
return this.builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitString(StringTag element) {
|
||||
this.builder.append(element.getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitByte(ByteTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitShort(ShortTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInt(IntTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLong(LongTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFloat(FloatTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDouble(DoubleTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitByteArray(ByteArrayTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIntArray(IntArrayTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLongArray(LongArrayTag element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitList(ListTag element) {
|
||||
for (Tag tag : element) {
|
||||
this.builder.append((new StringValueOnlyTagVisitor()).visit(tag));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCompound(CompoundTag compound) {
|
||||
for (Map.Entry<String, Tag> entry : compound.entrySet()) {
|
||||
this.builder.append((new StringValueOnlyTagVisitor()).visit(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd(EndTag element) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user