mirror of
https://e.coding.net/circlecloud/MiaoChat.git
synced 2024-12-21 19:08:47 +00:00
feat: 调整重载逻辑
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
db6a274918
commit
232ba7f95d
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoChat</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>1.3</version>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
|
@ -4,7 +4,6 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,7 +21,7 @@ public class ChatConfig {
|
||||
private static final String F = "Formats";
|
||||
private final Map<String, ChatMessagePart> formats;
|
||||
private final RuleComparator rulecomp;
|
||||
private final List<ChatRule> rules;
|
||||
private final LinkedList<ChatRule> rules;
|
||||
private final FileConfig config;
|
||||
private final FileConfig format;
|
||||
|
||||
@ -32,7 +31,7 @@ public class ChatConfig {
|
||||
rulecomp = new RuleComparator();
|
||||
formats = new HashMap<>();
|
||||
rules = new LinkedList<>();
|
||||
reload();
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,21 +54,27 @@ public class ChatConfig {
|
||||
return formats.get(name);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
format.reload();
|
||||
public void load() {
|
||||
formats.clear();
|
||||
for (final String name : format.getKeys(false)) {
|
||||
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
||||
Log.d("载入聊天格式: %s", name);
|
||||
}
|
||||
rules.clear();
|
||||
if (config.isSet(F)) {
|
||||
for (final String rule : config.getConfigurationSection(F).getKeys(false)) {
|
||||
rules.add(new ChatRule(rule, config.getConfigurationSection(F + "." + rule)));
|
||||
Log.d("载入聊天规则: %s => \"%s\"", rule, rules.getLast().getFormat());
|
||||
}
|
||||
}
|
||||
Collections.sort(rules, rulecomp);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
format.reload();
|
||||
load();
|
||||
}
|
||||
|
||||
private class RuleComparator implements Comparator<ChatRule> {
|
||||
@Override
|
||||
public int compare(final ChatRule o1, final ChatRule o2) {
|
||||
|
@ -93,7 +93,9 @@ public class ChatRule extends InjectConfigurationSection {
|
||||
if (!temp.isEmpty()) {
|
||||
for (final String var : temp) {
|
||||
final String[] args = tempvar.split("\\[" + var + "\\]", 2);
|
||||
formats.add(args[0]);
|
||||
if (!"".equals(args[0])) {
|
||||
formats.add(args[0]);
|
||||
}
|
||||
formats.add(var);
|
||||
tempvar = args[1];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user