changes to text

This commit is contained in:
aPunch 2012-03-02 16:42:58 -06:00
parent 44a98bb60f
commit ac897a471a
6 changed files with 39 additions and 25 deletions

View File

@ -11,8 +11,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.2.2-R0.1-SNAPSHOT</bukkit.version>
<craftbukkit.version>1.2.2-R0.1-SNAPSHOT</craftbukkit.version>
<bukkit.version>1.2.3-R0.1-SNAPSHOT</bukkit.version>
<craftbukkit.version>1.2.3-R0.1-SNAPSHOT</craftbukkit.version>
<citizensapi.version>2.0-SNAPSHOT</citizensapi.version>
<build.number>Unknown</build.number>
</properties>

View File

@ -82,8 +82,8 @@ public class Text extends Trait implements Runnable, Toggleable {
public void begin() {
Messaging.send(player, "<b>Entered the text editor!");
new ConversationFactory(plugin).withFirstPrompt(startPrompt).withEscapeSequence("/npc text")
.buildConversation(player).begin();
new ConversationFactory(plugin).withModality(false).withFirstPrompt(startPrompt).withEscapeSequence(
"/npc text").buildConversation(player).begin();
}
@Override
@ -105,11 +105,15 @@ public class Text extends Trait implements Runnable, Toggleable {
text.set(index, newText);
}
public boolean hasIndex(int index) {
return text.size() > index;
}
public boolean sendPage(Player player, int page) {
Paginator paginator = new Paginator();
paginator.setHeaderText(npc.getName() + "'s Text Entries");
for (String line : text)
paginator.addLine(line);
for (int i = 0; i < text.size(); i++)
paginator.addLine("<a>" + i + " <7>- <e>" + text.get(i));
return paginator.sendPage(player, page);
}

View File

@ -3,6 +3,7 @@ package net.citizensnpcs.trait.text.prompt;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
@ -15,14 +16,14 @@ public class TextAddPrompt extends StringPrompt {
}
@Override
public Prompt acceptInput(ConversationContext context, String string) {
text.add(string);
context.getForWhom().sendRawMessage(StringHelper.parseColors("<e>Added <a>the entry <e>" + string + "."));
public Prompt acceptInput(ConversationContext context, String input) {
text.add(input);
context.getForWhom().sendRawMessage(StringHelper.parseColors("<e>Added <a>the entry <e>" + input + "."));
return new StartPrompt(text);
}
@Override
public String getPromptText(ConversationContext context) {
return "Enter text to add to the NPC.";
return ChatColor.GREEN + "Enter text to add to the NPC.";
}
}

View File

@ -17,10 +17,10 @@ public class TextEditPrompt extends StringPrompt {
}
@Override
public Prompt acceptInput(ConversationContext context, String string) {
text.edit((Integer) context.getSessionData("index"), string);
public Prompt acceptInput(ConversationContext context, String input) {
text.edit((Integer) context.getSessionData("index"), input);
Messaging.send((Player) context.getForWhom(), "<a>Changed entry at index <e>" + context.getSessionData("index")
+ " <a>to <e>" + string + "<a>.");
+ " <a>to <e>" + input + "<a>.");
return new StartPrompt(text);
}

View File

@ -18,16 +18,16 @@ public class TextEditSelectIndexPrompt extends NumericPrompt {
}
@Override
public Prompt acceptValidatedInput(ConversationContext context, Number number) {
context.setSessionData("index", number.intValue());
Messaging.send((Player) context.getForWhom(), "<a>Now <e>editing <a>the entry at index <e>" + number.intValue()
+ "<a>. Enter text to replace the entry with.");
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
context.setSessionData("index", input.intValue());
Messaging.send((Player) context.getForWhom(), "<a>Now <e>editing <a>the entry at index <e>" + input.intValue()
+ "<a>.");
return new TextEditPrompt(text);
}
@Override
public String getFailedValidationText(ConversationContext context, String invalidInput) {
return ChatColor.RED + invalidInput + " is not a valid index!";
public String getFailedValidationText(ConversationContext context, String input) {
return ChatColor.RED + "'" + input + "' is not a valid index!";
}
@Override
@ -36,4 +36,9 @@ public class TextEditSelectIndexPrompt extends NumericPrompt {
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());
}
}

View File

@ -2,7 +2,6 @@ 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.ChatColor;
import org.bukkit.conversations.ConversationContext;
@ -18,22 +17,27 @@ public class TextRemovePrompt extends NumericPrompt {
}
@Override
public Prompt acceptValidatedInput(ConversationContext context, Number number) {
int index = number.intValue();
public Prompt acceptValidatedInput(ConversationContext context, Number input) {
int index = input.intValue();
text.remove(index);
Messaging.send((Player) context.getForWhom(), "<e>Removed <a>entry at index <e>" + index + "<a>.");
return new StartPrompt(text);
}
@Override
public String getFailedValidationText(ConversationContext context, String invalidInput) {
return ChatColor.RED + invalidInput + " is not a valid index!";
public String getFailedValidationText(ConversationContext context, String input) {
return ChatColor.RED + "'" + input + "' is not a valid index!";
}
@Override
public String getPromptText(ConversationContext context) {
Player player = (Player) context.getForWhom();
text.sendPage(player, 1);
return StringHelper.parseColors("<a>Enter the index of the entry you wish to remove.");
return ChatColor.GREEN + "Enter the index of the entry you wish to remove.";
}
@Override
public boolean isNumberValid(ConversationContext context, Number input) {
return text.hasIndex(input.intValue());
}
}