mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
changes to text editing, added click to talk and some talk settings
This commit is contained in:
parent
b6b00f8fef
commit
de6d1b7e18
@ -7,6 +7,7 @@ import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
|||||||
import net.citizensnpcs.editor.Editor;
|
import net.citizensnpcs.editor.Editor;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.EntityHumanNPC;
|
import net.citizensnpcs.resource.lib.EntityHumanNPC;
|
||||||
|
import net.citizensnpcs.trait.text.Text;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -112,7 +113,10 @@ public class EventListen implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO NPC text
|
if ((player.hasPermission("citizens.npc.talk") || player.hasPermission("citizens.admin"))
|
||||||
|
&& player.getItemInHand().getTypeId() == Setting.TALK_ITEM.asInt())
|
||||||
|
npc.getTrait(Text.class).sendText(player);
|
||||||
|
|
||||||
if (npc.getCharacter() != null)
|
if (npc.getCharacter() != null)
|
||||||
npc.getCharacter().onRightClick(npc, player);
|
npc.getCharacter().onRightClick(npc, player);
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,15 @@ public class Settings {
|
|||||||
DATABASE_URL("database.url", ""),
|
DATABASE_URL("database.url", ""),
|
||||||
DATABASE_USERNAME("database.username", ""),
|
DATABASE_USERNAME("database.username", ""),
|
||||||
DEBUG_MODE("general.debug-mode", false),
|
DEBUG_MODE("general.debug-mode", false),
|
||||||
|
DEFAULT_LOOK_CLOSE("npc.default.look-close", false),
|
||||||
|
DEFAULT_RANDOM_TALKER("npc.default.random-talker", true),
|
||||||
|
DEFAULT_TALK_CLOSE("npc.default.talk-close", false),
|
||||||
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>!"),
|
||||||
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.talk.max-cooldown", 60),
|
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.talk.max-cooldown", 60),
|
||||||
TALK_CLOSE_MINIMUM_COOLDOWN("npc.talk.min-cooldown", 30),
|
TALK_CLOSE_MINIMUM_COOLDOWN("npc.talk.min-cooldown", 30),
|
||||||
|
TALK_ITEM("npc.talk-item", 340),
|
||||||
USE_DATABASE("use-database", false);
|
USE_DATABASE("use-database", false);
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
@ -19,7 +19,6 @@ import net.citizensnpcs.command.exception.CommandException;
|
|||||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.trait.LookClose;
|
import net.citizensnpcs.trait.LookClose;
|
||||||
import net.citizensnpcs.trait.text.Text;
|
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.Paginator;
|
import net.citizensnpcs.util.Paginator;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
import net.citizensnpcs.util.StringHelper;
|
||||||
@ -207,10 +206,8 @@ public class NPCCommands {
|
|||||||
max = 1,
|
max = 1,
|
||||||
permission = "npc.lookclose")
|
permission = "npc.lookclose")
|
||||||
public void lookClose(CommandContext args, Player player, NPC npc) {
|
public void lookClose(CommandContext args, Player player, NPC npc) {
|
||||||
LookClose trait = npc.getTrait(LookClose.class);
|
|
||||||
trait.toggle();
|
|
||||||
String msg = StringHelper.wrap(npc.getName()) + " will "
|
String msg = StringHelper.wrap(npc.getName()) + " will "
|
||||||
+ (trait.shouldLookClose() ? "now rotate" : "no longer rotate");
|
+ (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate");
|
||||||
Messaging.send(player, msg += " when a player is nearby.");
|
Messaging.send(player, msg += " when a player is nearby.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,22 +330,6 @@ public class NPCCommands {
|
|||||||
+ " Use '/npc tphere' to teleport the NPC to your location.");
|
+ " Use '/npc tphere' to teleport the NPC to your location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
|
||||||
aliases = { "npc" },
|
|
||||||
usage = "talkclose",
|
|
||||||
desc = "Toggle whether an NPC talks when a player is near",
|
|
||||||
modifiers = { "talkclose", "talk" },
|
|
||||||
min = 1,
|
|
||||||
max = 1,
|
|
||||||
permission = "npc.talkclose")
|
|
||||||
public void talkClose(CommandContext args, Player player, NPC npc) {
|
|
||||||
Text trait = npc.getTrait(Text.class);
|
|
||||||
trait.toggle();
|
|
||||||
String msg = StringHelper.wrap(npc.getName()) + " will "
|
|
||||||
+ (trait.shouldTalkClose() ? "now talk" : "no longer talk");
|
|
||||||
Messaging.send(player, msg += " when a player is nearby.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "tp",
|
usage = "tp",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.citizensnpcs.trait;
|
package net.citizensnpcs.trait;
|
||||||
|
|
||||||
|
import net.citizensnpcs.Settings.Setting;
|
||||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.trait.SaveId;
|
import net.citizensnpcs.api.trait.SaveId;
|
||||||
@ -14,7 +15,7 @@ import org.bukkit.entity.Entity;
|
|||||||
@SaveId("look-close")
|
@SaveId("look-close")
|
||||||
public class LookClose extends Trait implements Runnable, Toggleable {
|
public class LookClose extends Trait implements Runnable, Toggleable {
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private boolean shouldLookClose;
|
private boolean lookClose = Setting.DEFAULT_LOOK_CLOSE.asBoolean();
|
||||||
|
|
||||||
public LookClose(NPC npc) {
|
public LookClose(NPC npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
@ -45,37 +46,30 @@ public class LookClose extends Trait implements Runnable, Toggleable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(DataKey key) throws NPCLoadException {
|
public void load(DataKey key) throws NPCLoadException {
|
||||||
shouldLookClose = key.getBoolean("");
|
lookClose = key.getBoolean("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
EntityLiving search = null;
|
EntityLiving search = null;
|
||||||
CitizensNPC handle = (CitizensNPC) npc;
|
CitizensNPC handle = (CitizensNPC) npc;
|
||||||
if ((search = handle.getHandle().world.findNearbyPlayer(handle.getHandle(), 5)) != null && shouldLookClose)
|
if ((search = handle.getHandle().world.findNearbyPlayer(handle.getHandle(), 5)) != null && lookClose)
|
||||||
faceEntity(handle, search.getBukkitEntity());
|
faceEntity(handle, search.getBukkitEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(DataKey key) {
|
public void save(DataKey key) {
|
||||||
key.setBoolean("", shouldLookClose);
|
key.setBoolean("", lookClose);
|
||||||
}
|
|
||||||
|
|
||||||
public void setLookClose(boolean shouldLookClose) {
|
|
||||||
this.shouldLookClose = shouldLookClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldLookClose() {
|
|
||||||
return shouldLookClose;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toggle() {
|
public boolean toggle() {
|
||||||
shouldLookClose = !shouldLookClose;
|
lookClose = !lookClose;
|
||||||
|
return lookClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LookClose{" + shouldLookClose + "}";
|
return "LookClose{" + lookClose + "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,5 +2,5 @@ package net.citizensnpcs.trait;
|
|||||||
|
|
||||||
public interface Toggleable {
|
public interface Toggleable {
|
||||||
|
|
||||||
public void toggle();
|
public boolean toggle();
|
||||||
}
|
}
|
@ -33,7 +33,9 @@ public class Text extends Trait implements Runnable, Toggleable {
|
|||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final List<String> text = new ArrayList<String>();
|
private final List<String> text = new ArrayList<String>();
|
||||||
private final Map<String, Calendar> cooldowns = new HashMap<String, Calendar>();
|
private final Map<String, Calendar> cooldowns = new HashMap<String, Calendar>();
|
||||||
private boolean talkClose;
|
private boolean talkClose = Setting.DEFAULT_TALK_CLOSE.asBoolean();
|
||||||
|
private boolean randomTalker = Setting.DEFAULT_RANDOM_TALKER.asBoolean();
|
||||||
|
private int currentIndex;
|
||||||
|
|
||||||
public Text(NPC npc) {
|
public Text(NPC npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
@ -47,18 +49,22 @@ public class Text extends Trait implements Runnable, Toggleable {
|
|||||||
|
|
||||||
if (key.keyExists("talk-close"))
|
if (key.keyExists("talk-close"))
|
||||||
talkClose = key.getBoolean("talk-close");
|
talkClose = key.getBoolean("talk-close");
|
||||||
|
if (key.keyExists("random-talker"))
|
||||||
|
randomTalker = key.getBoolean("random-talker");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(DataKey key) {
|
public void save(DataKey key) {
|
||||||
key.setBoolean("talk-close", talkClose);
|
key.setBoolean("talk-close", talkClose);
|
||||||
|
key.setBoolean("random-talker", randomTalker);
|
||||||
for (int i = 0; i < text.size(); i++)
|
for (int i = 0; i < text.size(); i++)
|
||||||
key.setString(String.valueOf(i), text.get(i));
|
key.setString(String.valueOf(i), text.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toggle() {
|
public boolean toggle() {
|
||||||
talkClose = !talkClose;
|
talkClose = !talkClose;
|
||||||
|
return talkClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +79,7 @@ public class Text extends Trait implements Runnable, Toggleable {
|
|||||||
return;
|
return;
|
||||||
cooldowns.remove(player.getName());
|
cooldowns.remove(player.getName());
|
||||||
}
|
}
|
||||||
sendRandomText(player);
|
if (sendText(player)) {
|
||||||
// Add a cooldown if the text was successfully sent
|
// Add a cooldown if the text was successfully sent
|
||||||
Calendar wait = Calendar.getInstance();
|
Calendar wait = Calendar.getInstance();
|
||||||
wait.add(
|
wait.add(
|
||||||
@ -83,6 +89,7 @@ public class Text extends Trait implements Runnable, Toggleable {
|
|||||||
cooldowns.put(player.getName(), wait);
|
cooldowns.put(player.getName(), wait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@ -94,10 +101,6 @@ public class Text extends Trait implements Runnable, Toggleable {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldTalkClose() {
|
|
||||||
return talkClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Editor getEditor(final Player player) {
|
public Editor getEditor(final Player player) {
|
||||||
final StartPrompt startPrompt = new StartPrompt(this);
|
final StartPrompt startPrompt = new StartPrompt(this);
|
||||||
return new Editor() {
|
return new Editor() {
|
||||||
@ -142,7 +145,26 @@ public class Text extends Trait implements Runnable, Toggleable {
|
|||||||
return paginator.sendPage(player, page);
|
return paginator.sendPage(player, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendRandomText(Player player) {
|
public boolean sendText(Player player) {
|
||||||
npc.chat(player, text.get(new Random().nextInt(text.size())));
|
if (text.size() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
if (randomTalker)
|
||||||
|
index = new Random().nextInt(text.size());
|
||||||
|
else {
|
||||||
|
if (currentIndex > text.size() - 1)
|
||||||
|
currentIndex = 0;
|
||||||
|
index = currentIndex++;
|
||||||
|
}
|
||||||
|
Messaging.log("current: " + currentIndex);
|
||||||
|
Messaging.log("index: " + index);
|
||||||
|
npc.chat(player, text.get(index));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean toggleRandomTalker() {
|
||||||
|
randomTalker = !randomTalker;
|
||||||
|
return randomTalker;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,35 +10,30 @@ import org.bukkit.conversations.NumericPrompt;
|
|||||||
import org.bukkit.conversations.Prompt;
|
import org.bukkit.conversations.Prompt;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TextEditSelectIndexPrompt extends NumericPrompt {
|
public class PageChangePrompt extends NumericPrompt {
|
||||||
private Text text;
|
private Text text;
|
||||||
|
|
||||||
public TextEditSelectIndexPrompt(Text text) {
|
public PageChangePrompt(Text text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||||
context.setSessionData("index", input.intValue());
|
Player player = (Player) context.getForWhom();
|
||||||
Messaging.send((Player) context.getForWhom(), "<a>Now <e>editing <a>the entry at index <e>" + input.intValue()
|
if (!text.sendPage(player, input.intValue())) {
|
||||||
+ "<a>.");
|
Messaging.sendError(player, "Invalid page number.");
|
||||||
return new TextEditPrompt(text);
|
return new StartPrompt(text);
|
||||||
|
}
|
||||||
|
return (Prompt) context.getSessionData("previous");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFailedValidationText(ConversationContext context, String input) {
|
public String getFailedValidationText(ConversationContext context, String input) {
|
||||||
return ChatColor.RED + "'" + input + "' is not a valid index!";
|
return ChatColor.RED + "Invalid page number.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
Player player = (Player) context.getForWhom();
|
return StringHelper.parseColors("<a>Enter a page number to view more text entries.");
|
||||||
text.sendPage(player, 1);
|
|
||||||
return StringHelper.parseColors("<a>Enter the index of the entry you wish to edit.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNumberValid(ConversationContext context, Number input) {
|
|
||||||
return text.hasIndex(input.intValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,14 +17,20 @@ public class StartPrompt extends StringPrompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Prompt acceptInput(ConversationContext context, String string) {
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
if (string.equalsIgnoreCase("add"))
|
if (input.equalsIgnoreCase("add"))
|
||||||
return new TextAddPrompt(text);
|
return new TextAddPrompt(text);
|
||||||
else if (string.equalsIgnoreCase("edit"))
|
else if (input.equalsIgnoreCase("edit"))
|
||||||
return new TextEditSelectIndexPrompt(text);
|
return new TextEditStartPrompt(text);
|
||||||
else if (string.equalsIgnoreCase("remove"))
|
else if (input.equalsIgnoreCase("remove"))
|
||||||
return new TextRemovePrompt(text);
|
return new TextRemovePrompt(text);
|
||||||
else {
|
else {
|
||||||
|
if (input.equalsIgnoreCase("random"))
|
||||||
|
Messaging.send((Player) context.getForWhom(), "<e>Random talker <a>set to <e>"
|
||||||
|
+ text.toggleRandomTalker() + "<a>.");
|
||||||
|
else if (input.equalsIgnoreCase("close")) {
|
||||||
|
Messaging.send((Player) context.getForWhom(), "<e>Close talker <a>set to <e>" + text.toggle() + "<a>.");
|
||||||
|
} else
|
||||||
Messaging.sendError((Player) context.getForWhom(), "Invalid edit type.");
|
Messaging.sendError((Player) context.getForWhom(), "Invalid edit type.");
|
||||||
return new StartPrompt(text);
|
return new StartPrompt(text);
|
||||||
}
|
}
|
||||||
@ -33,6 +39,6 @@ public class StartPrompt extends StringPrompt {
|
|||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
return StringHelper
|
return StringHelper
|
||||||
.parseColors("<a>Type <e>add <a>to add an entry, <e>edit <a>to edit entries, and <e>remove <a>to remove entries.");
|
.parseColors("<a>Type <e>add <a>to add an entry, <e>edit <a>to edit entries, <e>remove <a>to remove entries, <e>close <a>to toggle the NPC as a close talker, and <e>random <a>to toggle the NPC as a random talker.");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,14 @@
|
|||||||
package net.citizensnpcs.trait.text.prompt;
|
package net.citizensnpcs.trait.text.prompt;
|
||||||
|
|
||||||
import net.citizensnpcs.trait.text.Text;
|
import net.citizensnpcs.trait.text.Text;
|
||||||
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
import org.bukkit.conversations.Prompt;
|
import org.bukkit.conversations.Prompt;
|
||||||
import org.bukkit.conversations.StringPrompt;
|
import org.bukkit.conversations.StringPrompt;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TextAddPrompt extends StringPrompt {
|
public class TextAddPrompt extends StringPrompt {
|
||||||
private Text text;
|
private Text text;
|
||||||
@ -18,7 +20,8 @@ public class TextAddPrompt extends StringPrompt {
|
|||||||
@Override
|
@Override
|
||||||
public Prompt acceptInput(ConversationContext context, String input) {
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
text.add(input);
|
text.add(input);
|
||||||
context.getForWhom().sendRawMessage(StringHelper.parseColors("<e>Added <a>the entry <e>" + input + "."));
|
Messaging.send((Player) context.getForWhom(), StringHelper.parseColors("<e>Added <a>the entry <e>" + input
|
||||||
|
+ "."));
|
||||||
return new StartPrompt(text);
|
return new StartPrompt(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ package net.citizensnpcs.trait.text.prompt;
|
|||||||
|
|
||||||
import net.citizensnpcs.trait.text.Text;
|
import net.citizensnpcs.trait.text.Text;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
import org.bukkit.conversations.Prompt;
|
import org.bukkit.conversations.Prompt;
|
||||||
import org.bukkit.conversations.StringPrompt;
|
import org.bukkit.conversations.StringPrompt;
|
||||||
@ -18,15 +18,15 @@ public class TextEditPrompt extends StringPrompt {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Prompt acceptInput(ConversationContext context, String input) {
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
text.edit((Integer) context.getSessionData("index"), input);
|
int index = (Integer) context.getSessionData("index");
|
||||||
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + context.getSessionData("index")
|
text.edit(index, input);
|
||||||
+ " <a>to <e>" + input + "<a>.");
|
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + index + " <a>to <e>" + input
|
||||||
|
+ "<a>.");
|
||||||
return new StartPrompt(text);
|
return new StartPrompt(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
return StringHelper.parseColors("<a>Enter text to change the entry at the index <e>"
|
return ChatColor.GREEN + "Enter text to edit the entry.";
|
||||||
+ context.getSessionData("index") + "<a>.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package net.citizensnpcs.trait.text.prompt;
|
||||||
|
|
||||||
|
import net.citizensnpcs.trait.text.Text;
|
||||||
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
import org.bukkit.conversations.Prompt;
|
||||||
|
import org.bukkit.conversations.StringPrompt;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class TextEditStartPrompt extends StringPrompt {
|
||||||
|
private Text text;
|
||||||
|
|
||||||
|
public TextEditStartPrompt(Text text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
|
Player player = (Player) context.getForWhom();
|
||||||
|
try {
|
||||||
|
int index = Integer.parseInt(input);
|
||||||
|
if (!text.hasIndex(index)) {
|
||||||
|
Messaging.sendError(player, "'" + index + "' is not a valid index!");
|
||||||
|
return new StartPrompt(text);
|
||||||
|
}
|
||||||
|
context.setSessionData("index", index);
|
||||||
|
return new TextEditPrompt(text);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
if (input.equalsIgnoreCase("page")) {
|
||||||
|
context.setSessionData("previous", this);
|
||||||
|
return new PageChangePrompt(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Messaging.sendError(player, "Invalid input.");
|
||||||
|
return new StartPrompt(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPromptText(ConversationContext context) {
|
||||||
|
text.sendPage(((Player) context.getForWhom()), 1);
|
||||||
|
return StringHelper
|
||||||
|
.parseColors("<a>Enter the index of the entry you wish to edit or <e>page <a>to view more pages.");
|
||||||
|
}
|
||||||
|
}
|
@ -2,14 +2,14 @@ package net.citizensnpcs.trait.text.prompt;
|
|||||||
|
|
||||||
import net.citizensnpcs.trait.text.Text;
|
import net.citizensnpcs.trait.text.Text;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
import org.bukkit.conversations.NumericPrompt;
|
|
||||||
import org.bukkit.conversations.Prompt;
|
import org.bukkit.conversations.Prompt;
|
||||||
|
import org.bukkit.conversations.StringPrompt;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TextRemovePrompt extends NumericPrompt {
|
public class TextRemovePrompt extends StringPrompt {
|
||||||
private Text text;
|
private Text text;
|
||||||
|
|
||||||
public TextRemovePrompt(Text text) {
|
public TextRemovePrompt(Text text) {
|
||||||
@ -17,27 +17,31 @@ public class TextRemovePrompt extends NumericPrompt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
public Prompt acceptInput(ConversationContext context, String input) {
|
||||||
int index = input.intValue();
|
Player player = (Player) context.getForWhom();
|
||||||
|
try {
|
||||||
|
int index = Integer.parseInt(input);
|
||||||
|
if (!text.hasIndex(index)) {
|
||||||
|
Messaging.sendError(player, "'" + index + "' is not a valid index!");
|
||||||
|
return new StartPrompt(text);
|
||||||
|
}
|
||||||
text.remove(index);
|
text.remove(index);
|
||||||
Messaging.send((Player) context.getForWhom(), "<e>Removed <a>entry at index <e>" + index + "<a>.");
|
Messaging.send(player, "<e>Removed <a>entry at index <e>" + index + "<a>.");
|
||||||
|
return new StartPrompt(text);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
if (input.equalsIgnoreCase("page")) {
|
||||||
|
context.setSessionData("previous", this);
|
||||||
|
return new PageChangePrompt(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Messaging.sendError(player, "Invalid input.");
|
||||||
return new StartPrompt(text);
|
return new StartPrompt(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFailedValidationText(ConversationContext context, String input) {
|
|
||||||
return ChatColor.RED + "'" + input + "' is not a valid index!";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
Player player = (Player) context.getForWhom();
|
text.sendPage(((Player) context.getForWhom()), 1);
|
||||||
text.sendPage(player, 1);
|
return StringHelper
|
||||||
return ChatColor.GREEN + "Enter the index of the entry you wish to remove.";
|
.parseColors("<a>Enter the index of the entry you wish to remove or <e>page <a>to view more pages.");
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNumberValid(ConversationContext context, Number input) {
|
|
||||||
return text.hasIndex(input.intValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,6 +32,7 @@ permissions:
|
|||||||
citizens.npc.rename: true
|
citizens.npc.rename: true
|
||||||
citizens.npc.select: true
|
citizens.npc.select: true
|
||||||
citizens.npc.spawn: true
|
citizens.npc.spawn: true
|
||||||
|
citizens.npc.talk: true
|
||||||
citizens.npc.tp: true
|
citizens.npc.tp: true
|
||||||
citizens.npc.tphere: true
|
citizens.npc.tphere: true
|
||||||
citizens.npc.lookclose: true
|
citizens.npc.lookclose: true
|
Loading…
Reference in New Issue
Block a user