forked from circlecloud/MiaoChat
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>MiaoChat</artifactId>
|
<artifactId>MiaoChat</artifactId>
|
||||||
<version>1.2</version>
|
<version>1.3</version>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -4,7 +4,6 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -22,7 +21,7 @@ public class ChatConfig {
|
|||||||
private static final String F = "Formats";
|
private static final String F = "Formats";
|
||||||
private final Map<String, ChatMessagePart> formats;
|
private final Map<String, ChatMessagePart> formats;
|
||||||
private final RuleComparator rulecomp;
|
private final RuleComparator rulecomp;
|
||||||
private final List<ChatRule> rules;
|
private final LinkedList<ChatRule> rules;
|
||||||
private final FileConfig config;
|
private final FileConfig config;
|
||||||
private final FileConfig format;
|
private final FileConfig format;
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ public class ChatConfig {
|
|||||||
rulecomp = new RuleComparator();
|
rulecomp = new RuleComparator();
|
||||||
formats = new HashMap<>();
|
formats = new HashMap<>();
|
||||||
rules = new LinkedList<>();
|
rules = new LinkedList<>();
|
||||||
reload();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,21 +54,27 @@ public class ChatConfig {
|
|||||||
return formats.get(name);
|
return formats.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void load() {
|
||||||
format.reload();
|
|
||||||
formats.clear();
|
formats.clear();
|
||||||
for (final String name : format.getKeys(false)) {
|
for (final String name : format.getKeys(false)) {
|
||||||
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
||||||
|
Log.d("载入聊天格式: %s", name);
|
||||||
}
|
}
|
||||||
rules.clear();
|
rules.clear();
|
||||||
if (config.isSet(F)) {
|
if (config.isSet(F)) {
|
||||||
for (final String rule : config.getConfigurationSection(F).getKeys(false)) {
|
for (final String rule : config.getConfigurationSection(F).getKeys(false)) {
|
||||||
rules.add(new ChatRule(rule, config.getConfigurationSection(F + "." + rule)));
|
rules.add(new ChatRule(rule, config.getConfigurationSection(F + "." + rule)));
|
||||||
|
Log.d("载入聊天规则: %s => \"%s\"", rule, rules.getLast().getFormat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(rules, rulecomp);
|
Collections.sort(rules, rulecomp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reload() {
|
||||||
|
format.reload();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
private class RuleComparator implements Comparator<ChatRule> {
|
private class RuleComparator implements Comparator<ChatRule> {
|
||||||
@Override
|
@Override
|
||||||
public int compare(final ChatRule o1, final ChatRule o2) {
|
public int compare(final ChatRule o1, final ChatRule o2) {
|
||||||
|
@ -93,7 +93,9 @@ public class ChatRule extends InjectConfigurationSection {
|
|||||||
if (!temp.isEmpty()) {
|
if (!temp.isEmpty()) {
|
||||||
for (final String var : temp) {
|
for (final String var : temp) {
|
||||||
final String[] args = tempvar.split("\\[" + var + "\\]", 2);
|
final String[] args = tempvar.split("\\[" + var + "\\]", 2);
|
||||||
formats.add(args[0]);
|
if (!"".equals(args[0])) {
|
||||||
|
formats.add(args[0]);
|
||||||
|
}
|
||||||
formats.add(var);
|
formats.add(var);
|
||||||
tempvar = args[1];
|
tempvar = args[1];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user