mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
Fix text setting loading to allow empty text
This commit is contained in:
parent
2caa1b360a
commit
8ee9ecb5ed
@ -4,9 +4,13 @@ import java.io.File;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
@ -152,15 +156,27 @@ public class Settings {
|
|||||||
"npc.pathfinding.default-stuck-action", "none"),
|
"npc.pathfinding.default-stuck-action", "none"),
|
||||||
DEFAULT_TALK_CLOSE("npc.default.talk-close.enabled", false),
|
DEFAULT_TALK_CLOSE("npc.default.talk-close.enabled", false),
|
||||||
DEFAULT_TALK_CLOSE_RANGE("Default talk close range in blocks", "npc.default.talk-close.range", 5),
|
DEFAULT_TALK_CLOSE_RANGE("Default talk close range in blocks", "npc.default.talk-close.range", 5),
|
||||||
DEFAULT_TEXT("npc.default.talk-close.text.0", "Hi, I'm <npc>!") {
|
DEFAULT_TEXT("npc.default.talk-close.text", "Hi, I'm <npc>!") {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void loadFromKey(DataKey root) {
|
public void loadFromKey(DataKey root) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
for (DataKey key : root.getRelative("npc.default.talk-close.text").getSubKeys()) {
|
Object raw = root.getRaw(path);
|
||||||
list.add(key.getString(""));
|
if (raw instanceof ConfigurationSection || raw instanceof Map) {
|
||||||
|
for (DataKey key : root.getRelative(path).getSubKeys()) {
|
||||||
|
list.add(key.getString(""));
|
||||||
|
}
|
||||||
|
} else if (raw instanceof Collection) {
|
||||||
|
list.addAll((Collection<? extends String>) raw);
|
||||||
}
|
}
|
||||||
value = list;
|
value = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setAtKey(DataKey root) {
|
||||||
|
root.setRaw(path, Lists.newArrayList(value));
|
||||||
|
setComments(root);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
DEFAULT_TEXT_DELAY_MAX("Default maximum delay when talking to players",
|
DEFAULT_TEXT_DELAY_MAX("Default maximum delay when talking to players",
|
||||||
"npc.text.default-random-text-delay-max", "10s"),
|
"npc.text.default-random-text-delay-max", "10s"),
|
||||||
@ -283,7 +299,7 @@ public class Settings {
|
|||||||
private String comments;
|
private String comments;
|
||||||
private Duration duration;
|
private Duration duration;
|
||||||
private String migrate;
|
private String migrate;
|
||||||
private final String path;
|
protected final String path;
|
||||||
protected Object value;
|
protected Object value;
|
||||||
|
|
||||||
Setting(String path, Object value) {
|
Setting(String path, Object value) {
|
||||||
@ -367,14 +383,14 @@ public class Settings {
|
|||||||
setComments(root);
|
setComments(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setComments(DataKey root) {
|
protected void setComments(DataKey root) {
|
||||||
if (SUPPORTS_SET_COMMENTS && root.keyExists(path)) {
|
if (!SUPPORTS_SET_COMMENTS || !root.keyExists(path))
|
||||||
try {
|
return;
|
||||||
((MemoryDataKey) root).getSection("").setComments(path,
|
try {
|
||||||
comments == null ? null : Arrays.asList(comments.split("<br>")));
|
((MemoryDataKey) root).getSection("").setComments(path,
|
||||||
} catch (Throwable t) {
|
comments == null ? null : Arrays.asList(comments.split("<br>")));
|
||||||
SUPPORTS_SET_COMMENTS = false;
|
} catch (Throwable t) {
|
||||||
}
|
SUPPORTS_SET_COMMENTS = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user