summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/conversations/PlayerNamePrompt.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/bukkit/conversations/PlayerNamePrompt.java')
-rw-r--r--src/main/java/org/bukkit/conversations/PlayerNamePrompt.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/conversations/PlayerNamePrompt.java b/src/main/java/org/bukkit/conversations/PlayerNamePrompt.java
new file mode 100644
index 00000000..bc427cfc
--- /dev/null
+++ b/src/main/java/org/bukkit/conversations/PlayerNamePrompt.java
@@ -0,0 +1,35 @@
+package org.bukkit.conversations;
+
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+/**
+ * PlayerNamePrompt is the base class for any prompt that requires the player to enter another player's name.
+ */
+public abstract class PlayerNamePrompt extends ValidatingPrompt{
+ private Plugin plugin;
+
+ public PlayerNamePrompt(Plugin plugin) {
+ super();
+ this.plugin = plugin;
+ }
+
+ @Override
+ protected boolean isInputValid(ConversationContext context, String input) {
+ return plugin.getServer().getPlayer(input) != null;
+
+ }
+
+ @Override
+ protected Prompt acceptValidatedInput(ConversationContext context, String input) {
+ return acceptValidatedInput(context, plugin.getServer().getPlayer(input));
+ }
+
+ /**
+ * Override this method to perform some action with the user's player name response.
+ * @param context Context information about the conversation.
+ * @param input The user's player name response.
+ * @return The next {@link Prompt} in the prompt graph.
+ */
+ protected abstract Prompt acceptValidatedInput(ConversationContext context, Player input);
+}