diff --git a/src/main/java/net/citizensnpcs/Settings.java b/src/main/java/net/citizensnpcs/Settings.java index 4415b3b85..1814a4893 100644 --- a/src/main/java/net/citizensnpcs/Settings.java +++ b/src/main/java/net/citizensnpcs/Settings.java @@ -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 !"), QUICK_SELECT("npc.selection.quick-select", false), SELECTION_ITEM("npc.selection.item", "280"), SELECTION_MESSAGE("npc.selection.message", "You selected !"), @@ -56,6 +59,13 @@ public class Settings { this.value = value; } + public List asList() { + List list = new ArrayList(); + for (DataKey key : config.getKey("npc.default.text").getIntegerSubKeys()) + list.add(key.getString("")); + return list; + } + public boolean asBoolean() { return (Boolean) value; } diff --git a/src/main/java/net/citizensnpcs/trait/text/Text.java b/src/main/java/net/citizensnpcs/trait/text/Text.java index 79e839ea2..0bb9002e2 100644 --- a/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/src/main/java/net/citizensnpcs/trait/text/Text.java @@ -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();