mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 11:38:26 +01:00
Added default text in config file. This addresses CITIZENS-28.
This commit is contained in:
parent
bc01012701
commit
a37716ebeb
@ -1,6 +1,8 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.Storage;
|
||||
@ -8,7 +10,7 @@ import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
public class Settings {
|
||||
private final Storage config;
|
||||
private static Storage config;
|
||||
|
||||
public Settings(File folder) {
|
||||
config = new YamlStorage(folder + File.separator + "config.yml", "Citizens Configuration");
|
||||
@ -40,6 +42,7 @@ public class Settings {
|
||||
DEFAULT_LOOK_CLOSE("npc.default.look-close", false),
|
||||
DEFAULT_RANDOM_TALKER("npc.default.random-talker", true),
|
||||
DEFAULT_TALK_CLOSE("npc.default.talk-close", false),
|
||||
DEFAULT_TEXT("npc.default.text.0", "Hi, I'm <npc>!"),
|
||||
QUICK_SELECT("npc.selection.quick-select", false),
|
||||
SELECTION_ITEM("npc.selection.item", "280"),
|
||||
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
|
||||
@ -56,6 +59,13 @@ public class Settings {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public List<String> asList() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (DataKey key : config.getKey("npc.default.text").getIntegerSubKeys())
|
||||
list.add(key.getString(""));
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
for (DataKey sub : key.getIntegerSubKeys())
|
||||
text.add(sub.getString(""));
|
||||
if (text.isEmpty())
|
||||
populateDefaultText();
|
||||
|
||||
if (key.keyExists("talk-close"))
|
||||
talkClose = key.getBoolean("talk-close");
|
||||
@ -94,6 +96,12 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
if (text.isEmpty())
|
||||
populateDefaultText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void conversationAbandoned(ConversationAbandonedEvent event) {
|
||||
Bukkit.dispatchCommand((Player) event.getContext().getForWhom(), "npc text");
|
||||
@ -105,8 +113,8 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
|
||||
public Editor getEditor(final Player player) {
|
||||
final Conversation conversation = new ConversationFactory(plugin).addConversationAbandonedListener(this)
|
||||
.withLocalEcho(false).withEscapeSequence("/npc text").withModality(false)
|
||||
.withFirstPrompt(new StartPrompt(this)).buildConversation(player);
|
||||
.withLocalEcho(false).withEscapeSequence("/npc text").withModality(false).withFirstPrompt(
|
||||
new StartPrompt(this)).buildConversation(player);
|
||||
return new Editor() {
|
||||
|
||||
@Override
|
||||
@ -171,6 +179,11 @@ public class Text extends Trait implements Runnable, Toggleable, ConversationAba
|
||||
return randomTalker;
|
||||
}
|
||||
|
||||
private void populateDefaultText() {
|
||||
for (String line : Setting.DEFAULT_TEXT.asList())
|
||||
text.add(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
Loading…
Reference in New Issue
Block a user