fix text editing

This commit is contained in:
aPunch 2012-03-08 17:57:24 -06:00
parent 97dd0f33eb
commit 7893d42ab8
5 changed files with 24 additions and 15 deletions

View File

@ -16,8 +16,8 @@
<javac srcdir="${src}" destdir="${build}" debug="on" debuglevel="lines,vars,source" includeantruntime="false" encoding="Cp1252"> <javac srcdir="${src}" destdir="${build}" debug="on" debuglevel="lines,vars,source" includeantruntime="false" encoding="Cp1252">
<classpath> <classpath>
<pathelement path="${lib}" /> <pathelement path="${lib}" />
<pathelement location="${lib}/bukkit-1.2.2-R0.1-SNAPSHOT.jar" /> <pathelement location="${lib}/bukkit-1.2.3-R0.2-SNAPSHOT.jar" />
<pathelement location="${lib}/craftbukkit-1.2.2-R0.1-SNAPSHOT.jar" /> <pathelement location="${lib}/craftbukkit-1.2.3-R0.2-SNAPSHOT.jar" />
<pathelement location="${lib}/CitizensAPI.jar" /> <pathelement location="${lib}/CitizensAPI.jar" />
</classpath> </classpath>
</javac> </javac>

View File

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

View File

@ -8,6 +8,9 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.conversations.ConversationAbandonedListener;
import org.bukkit.conversations.ConversationFactory; import org.bukkit.conversations.ConversationFactory;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,7 +30,7 @@ import net.citizensnpcs.util.Paginator;
import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityLiving;
public class Text extends Trait implements Runnable, Toggleable { public class Text extends Trait implements Runnable, Toggleable, ConversationAbandonedListener {
private final Citizens plugin; private final Citizens plugin;
private final NPC npc; private final NPC npc;
private final List<String> text = new ArrayList<String>(); private final List<String> text = new ArrayList<String>();
@ -91,13 +94,8 @@ public class Text extends Trait implements Runnable, Toggleable {
} }
@Override @Override
public String toString() { public void conversationAbandoned(ConversationAbandonedEvent event) {
StringBuilder builder = new StringBuilder(); plugin.getServer().dispatchCommand((Player) event.getContext().getForWhom(), "npc text");
builder.append("Text{talk-close=" + talkClose + ",text=");
for (String line : text)
builder.append(line + ",");
builder.append("}");
return builder.toString();
} }
public boolean shouldTalkClose() { public boolean shouldTalkClose() {
@ -105,15 +103,16 @@ public class Text extends Trait implements Runnable, Toggleable {
} }
public Editor getEditor(final Player player) { public Editor getEditor(final Player player) {
final StartPrompt startPrompt = new StartPrompt(this); final Conversation conversation = new ConversationFactory(plugin).addConversationAbandonedListener(this)
.withLocalEcho(false).withEscapeSequence("/npc text").withModality(false).withFirstPrompt(
new StartPrompt(this)).buildConversation(player);
return new Editor() { return new Editor() {
@Override @Override
public void begin() { public void begin() {
Messaging.send(player, "<b>Entered the text editor!"); Messaging.send(player, "<b>Entered the text editor!");
new ConversationFactory(plugin).withModality(false).withFirstPrompt(startPrompt).withEscapeSequence( conversation.begin();
"/npc text").buildConversation(player).begin();
} }
@Override @Override
@ -170,4 +169,14 @@ public class Text extends Trait implements Runnable, Toggleable {
randomTalker = !randomTalker; randomTalker = !randomTalker;
return randomTalker; return randomTalker;
} }
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Text{talk-close=" + talkClose + ",text=");
for (String line : text)
builder.append(line + ",");
builder.append("}");
return builder.toString();
}
} }