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