SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@ package org.bukkit.conversations;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* BooleanPrompt is the base class for any prompt that requires a boolean
|
||||
@@ -14,13 +16,14 @@ public abstract class BooleanPrompt extends ValidatingPrompt {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isInputValid(ConversationContext context, String input) {
|
||||
protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) {
|
||||
String[] accepted = {/* Apache values: */"true", "false", "on", "off", "yes", "no",/* Additional values: */ "y", "n", "1", "0", "right", "wrong", "correct", "incorrect", "valid", "invalid"};
|
||||
return ArrayUtils.contains(accepted, input.toLowerCase());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
|
||||
protected Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull String input) {
|
||||
if (input.equalsIgnoreCase("y") || input.equals("1") || input.equalsIgnoreCase("right") || input.equalsIgnoreCase("correct") || input.equalsIgnoreCase("valid")) input = "true";
|
||||
return acceptValidatedInput(context, BooleanUtils.toBoolean(input));
|
||||
}
|
||||
@@ -33,5 +36,6 @@ public abstract class BooleanPrompt extends ValidatingPrompt {
|
||||
* @param input The user's boolean response.
|
||||
* @return The next {@link Prompt} in the prompt graph.
|
||||
*/
|
||||
protected abstract Prompt acceptValidatedInput(ConversationContext context, boolean input);
|
||||
@Nullable
|
||||
protected abstract Prompt acceptValidatedInput(@NotNull ConversationContext context, boolean input);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The Conversable interface is used to indicate objects that can have
|
||||
* conversations.
|
||||
@@ -20,7 +22,7 @@ public interface Conversable {
|
||||
*
|
||||
* @param input The input message into the conversation
|
||||
*/
|
||||
public void acceptConversationInput(String input);
|
||||
public void acceptConversationInput(@NotNull String input);
|
||||
|
||||
/**
|
||||
* Enters into a dialog with a Conversation object.
|
||||
@@ -29,14 +31,14 @@ public interface Conversable {
|
||||
* @return True if the conversation should proceed, false if it has been
|
||||
* enqueued
|
||||
*/
|
||||
public boolean beginConversation(Conversation conversation);
|
||||
public boolean beginConversation(@NotNull Conversation conversation);
|
||||
|
||||
/**
|
||||
* Abandons an active conversation.
|
||||
*
|
||||
* @param conversation The conversation to abandon
|
||||
*/
|
||||
public void abandonConversation(Conversation conversation);
|
||||
public void abandonConversation(@NotNull Conversation conversation);
|
||||
|
||||
/**
|
||||
* Abandons an active conversation.
|
||||
@@ -44,12 +46,12 @@ public interface Conversable {
|
||||
* @param conversation The conversation to abandon
|
||||
* @param details Details about why the conversation was abandoned
|
||||
*/
|
||||
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details);
|
||||
public void abandonConversation(@NotNull Conversation conversation, @NotNull ConversationAbandonedEvent details);
|
||||
|
||||
/**
|
||||
* Sends this sender a message raw
|
||||
*
|
||||
* @param message Message to be displayed
|
||||
*/
|
||||
public void sendRawMessage(String message);
|
||||
public void sendRawMessage(@NotNull String message);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -51,7 +53,7 @@ public class Conversation {
|
||||
* @param forWhom The entity for whom this conversation is mediating.
|
||||
* @param firstPrompt The first prompt in the conversation graph.
|
||||
*/
|
||||
public Conversation(Plugin plugin, Conversable forWhom, Prompt firstPrompt) {
|
||||
public Conversation(@Nullable Plugin plugin, @NotNull Conversable forWhom, @Nullable Prompt firstPrompt) {
|
||||
this(plugin, forWhom, firstPrompt, new HashMap<Object, Object>());
|
||||
}
|
||||
|
||||
@@ -64,7 +66,7 @@ public class Conversation {
|
||||
* @param initialSessionData Any initial values to put in the conversation
|
||||
* context sessionData map.
|
||||
*/
|
||||
public Conversation(Plugin plugin, Conversable forWhom, Prompt firstPrompt, Map<Object, Object> initialSessionData) {
|
||||
public Conversation(@Nullable Plugin plugin, @NotNull Conversable forWhom, @Nullable Prompt firstPrompt, @NotNull Map<Object, Object> initialSessionData) {
|
||||
this.firstPrompt = firstPrompt;
|
||||
this.context = new ConversationContext(plugin, forWhom, initialSessionData);
|
||||
this.modal = true;
|
||||
@@ -79,6 +81,7 @@ public class Conversation {
|
||||
*
|
||||
* @return The entity.
|
||||
*/
|
||||
@NotNull
|
||||
public Conversable getForWhom() {
|
||||
return context.getForWhom();
|
||||
}
|
||||
@@ -133,6 +136,7 @@ public class Conversation {
|
||||
*
|
||||
* @return The ConversationPrefix in use.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationPrefix getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
@@ -143,7 +147,7 @@ public class Conversation {
|
||||
*
|
||||
* @param prefix The ConversationPrefix to use.
|
||||
*/
|
||||
void setPrefix(ConversationPrefix prefix) {
|
||||
void setPrefix(@NotNull ConversationPrefix prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@@ -152,7 +156,7 @@ public class Conversation {
|
||||
*
|
||||
* @param canceller The {@link ConversationCanceller} to add.
|
||||
*/
|
||||
void addConversationCanceller(ConversationCanceller canceller) {
|
||||
void addConversationCanceller(@NotNull ConversationCanceller canceller) {
|
||||
canceller.setConversation(this);
|
||||
this.cancellers.add(canceller);
|
||||
}
|
||||
@@ -162,6 +166,7 @@ public class Conversation {
|
||||
*
|
||||
* @return The list.
|
||||
*/
|
||||
@NotNull
|
||||
public List<ConversationCanceller> getCancellers() {
|
||||
return cancellers;
|
||||
}
|
||||
@@ -171,6 +176,7 @@ public class Conversation {
|
||||
*
|
||||
* @return The ConversationContext.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationContext getContext() {
|
||||
return context;
|
||||
}
|
||||
@@ -192,6 +198,7 @@ public class Conversation {
|
||||
*
|
||||
* @return The current state of the conversation.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationState getState() {
|
||||
if (currentPrompt != null) {
|
||||
return ConversationState.STARTED;
|
||||
@@ -208,7 +215,7 @@ public class Conversation {
|
||||
*
|
||||
* @param input The user's chat text.
|
||||
*/
|
||||
public void acceptInput(String input) {
|
||||
public void acceptInput(@NotNull String input) {
|
||||
if (currentPrompt != null) {
|
||||
|
||||
// Echo the user's input
|
||||
@@ -235,7 +242,7 @@ public class Conversation {
|
||||
*
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void addConversationAbandonedListener(ConversationAbandonedListener listener) {
|
||||
public synchronized void addConversationAbandonedListener(@NotNull ConversationAbandonedListener listener) {
|
||||
abandonedListeners.add(listener);
|
||||
}
|
||||
|
||||
@@ -244,7 +251,7 @@ public class Conversation {
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void removeConversationAbandonedListener(ConversationAbandonedListener listener) {
|
||||
public synchronized void removeConversationAbandonedListener(@NotNull ConversationAbandonedListener listener) {
|
||||
abandonedListeners.remove(listener);
|
||||
}
|
||||
|
||||
@@ -262,7 +269,7 @@ public class Conversation {
|
||||
*
|
||||
* @param details Details about why the conversation was abandoned
|
||||
*/
|
||||
public synchronized void abandon(ConversationAbandonedEvent details) {
|
||||
public synchronized void abandon(@NotNull ConversationAbandonedEvent details) {
|
||||
if (!abandoned) {
|
||||
abandoned = true;
|
||||
currentPrompt = null;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
@@ -11,11 +14,11 @@ public class ConversationAbandonedEvent extends EventObject {
|
||||
private ConversationContext context;
|
||||
private ConversationCanceller canceller;
|
||||
|
||||
public ConversationAbandonedEvent(Conversation conversation) {
|
||||
public ConversationAbandonedEvent(@NotNull Conversation conversation) {
|
||||
this(conversation, null);
|
||||
}
|
||||
|
||||
public ConversationAbandonedEvent(Conversation conversation, ConversationCanceller canceller) {
|
||||
public ConversationAbandonedEvent(@NotNull Conversation conversation, @Nullable ConversationCanceller canceller) {
|
||||
super(conversation);
|
||||
this.context = conversation.getContext();
|
||||
this.canceller = canceller;
|
||||
@@ -26,6 +29,7 @@ public class ConversationAbandonedEvent extends EventObject {
|
||||
*
|
||||
* @return The object that abandoned the conversation.
|
||||
*/
|
||||
@Nullable
|
||||
public ConversationCanceller getCanceller() {
|
||||
return canceller;
|
||||
}
|
||||
@@ -35,6 +39,7 @@ public class ConversationAbandonedEvent extends EventObject {
|
||||
*
|
||||
* @return The abandoned conversation's conversation context.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
@@ -11,5 +13,5 @@ public interface ConversationAbandonedListener extends EventListener {
|
||||
* @param abandonedEvent Contains details about the abandoned
|
||||
* conversation.
|
||||
*/
|
||||
public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent);
|
||||
public void conversationAbandoned(@NotNull ConversationAbandonedEvent abandonedEvent);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A ConversationCanceller is a class that cancels an active {@link
|
||||
* Conversation}. A Conversation can have more than one ConversationCanceller.
|
||||
@@ -11,7 +13,7 @@ public interface ConversationCanceller extends Cloneable {
|
||||
*
|
||||
* @param conversation A conversation.
|
||||
*/
|
||||
public void setConversation(Conversation conversation);
|
||||
public void setConversation(@NotNull Conversation conversation);
|
||||
|
||||
/**
|
||||
* Cancels a conversation based on user input.
|
||||
@@ -20,7 +22,7 @@ public interface ConversationCanceller extends Cloneable {
|
||||
* @param input The input text from the user.
|
||||
* @return True to cancel the conversation, False otherwise.
|
||||
*/
|
||||
public boolean cancelBasedOnInput(ConversationContext context, String input);
|
||||
public boolean cancelBasedOnInput(@NotNull ConversationContext context, @NotNull String input);
|
||||
|
||||
/**
|
||||
* Allows the {@link ConversationFactory} to duplicate this
|
||||
@@ -30,5 +32,6 @@ public interface ConversationCanceller extends Cloneable {
|
||||
*
|
||||
* @return A clone.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationCanceller clone();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,7 +23,7 @@ public class ConversationContext {
|
||||
* @param initialSessionData Any initial values to put in the sessionData
|
||||
* map.
|
||||
*/
|
||||
public ConversationContext(Plugin plugin, Conversable forWhom, Map<Object, Object> initialSessionData) {
|
||||
public ConversationContext(@Nullable Plugin plugin, @NotNull Conversable forWhom, @NotNull Map<Object, Object> initialSessionData) {
|
||||
this.plugin = plugin;
|
||||
this.forWhom = forWhom;
|
||||
this.sessionData = initialSessionData;
|
||||
@@ -32,6 +34,7 @@ public class ConversationContext {
|
||||
*
|
||||
* @return The owning plugin.
|
||||
*/
|
||||
@Nullable
|
||||
public Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
@@ -41,6 +44,7 @@ public class ConversationContext {
|
||||
*
|
||||
* @return The subject of the conversation.
|
||||
*/
|
||||
@NotNull
|
||||
public Conversable getForWhom() {
|
||||
return forWhom;
|
||||
}
|
||||
@@ -52,6 +56,7 @@ public class ConversationContext {
|
||||
*
|
||||
* @return The full sessionData map.
|
||||
*/
|
||||
@NotNull
|
||||
public Map<Object, Object> getAllSessionData() {
|
||||
return sessionData;
|
||||
}
|
||||
@@ -64,7 +69,8 @@ public class ConversationContext {
|
||||
* @param key The session data key.
|
||||
* @return The requested session data.
|
||||
*/
|
||||
public Object getSessionData(Object key) {
|
||||
@Nullable
|
||||
public Object getSessionData(@NotNull Object key) {
|
||||
return sessionData.get(key);
|
||||
}
|
||||
|
||||
@@ -76,7 +82,7 @@ public class ConversationContext {
|
||||
* @param key The session data key.
|
||||
* @param value The session data value.
|
||||
*/
|
||||
public void setSessionData(Object key, Object value) {
|
||||
public void setSessionData(@NotNull Object key, @Nullable Object value) {
|
||||
sessionData.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -35,7 +37,7 @@ public class ConversationFactory {
|
||||
*
|
||||
* @param plugin The plugin that owns the factory.
|
||||
*/
|
||||
public ConversationFactory(Plugin plugin) {
|
||||
public ConversationFactory(@NotNull Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
isModal = true;
|
||||
localEchoEnabled = true;
|
||||
@@ -57,6 +59,7 @@ public class ConversationFactory {
|
||||
* @param modal The modality of all conversations to be created.
|
||||
* @return This object.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationFactory withModality(boolean modal) {
|
||||
isModal = modal;
|
||||
return this;
|
||||
@@ -70,6 +73,7 @@ public class ConversationFactory {
|
||||
* @param localEchoEnabled The status of local echo.
|
||||
* @return This object.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationFactory withLocalEcho(boolean localEchoEnabled) {
|
||||
this.localEchoEnabled = localEchoEnabled;
|
||||
return this;
|
||||
@@ -84,7 +88,8 @@ public class ConversationFactory {
|
||||
* @param prefix The ConversationPrefix to use.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory withPrefix(ConversationPrefix prefix) {
|
||||
@NotNull
|
||||
public ConversationFactory withPrefix(@NotNull ConversationPrefix prefix) {
|
||||
this.prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
@@ -98,6 +103,7 @@ public class ConversationFactory {
|
||||
* @param timeoutSeconds The number of seconds to wait.
|
||||
* @return This object.
|
||||
*/
|
||||
@NotNull
|
||||
public ConversationFactory withTimeout(int timeoutSeconds) {
|
||||
return withConversationCanceller(new InactivityConversationCanceller(plugin, timeoutSeconds));
|
||||
}
|
||||
@@ -110,7 +116,8 @@ public class ConversationFactory {
|
||||
* @param firstPrompt The first prompt.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory withFirstPrompt(Prompt firstPrompt) {
|
||||
@NotNull
|
||||
public ConversationFactory withFirstPrompt(@Nullable Prompt firstPrompt) {
|
||||
this.firstPrompt = firstPrompt;
|
||||
return this;
|
||||
}
|
||||
@@ -123,7 +130,8 @@ public class ConversationFactory {
|
||||
* sessionData.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory withInitialSessionData(Map<Object, Object> initialSessionData) {
|
||||
@NotNull
|
||||
public ConversationFactory withInitialSessionData(@NotNull Map<Object, Object> initialSessionData) {
|
||||
this.initialSessionData = initialSessionData;
|
||||
return this;
|
||||
}
|
||||
@@ -135,7 +143,8 @@ public class ConversationFactory {
|
||||
* @param escapeSequence Input to terminate the conversation.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory withEscapeSequence(String escapeSequence) {
|
||||
@NotNull
|
||||
public ConversationFactory withEscapeSequence(@NotNull String escapeSequence) {
|
||||
return withConversationCanceller(new ExactMatchConversationCanceller(escapeSequence));
|
||||
}
|
||||
|
||||
@@ -145,7 +154,8 @@ public class ConversationFactory {
|
||||
* @param canceller The {@link ConversationCanceller} to add.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory withConversationCanceller(ConversationCanceller canceller) {
|
||||
@NotNull
|
||||
public ConversationFactory withConversationCanceller(@NotNull ConversationCanceller canceller) {
|
||||
cancellers.add(canceller);
|
||||
return this;
|
||||
}
|
||||
@@ -158,7 +168,8 @@ public class ConversationFactory {
|
||||
* starting a conversation.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory thatExcludesNonPlayersWithMessage(String playerOnlyMessage) {
|
||||
@NotNull
|
||||
public ConversationFactory thatExcludesNonPlayersWithMessage(@Nullable String playerOnlyMessage) {
|
||||
this.playerOnlyMessage = playerOnlyMessage;
|
||||
return this;
|
||||
}
|
||||
@@ -170,7 +181,8 @@ public class ConversationFactory {
|
||||
* @param listener The listener to add.
|
||||
* @return This object.
|
||||
*/
|
||||
public ConversationFactory addConversationAbandonedListener(ConversationAbandonedListener listener) {
|
||||
@NotNull
|
||||
public ConversationFactory addConversationAbandonedListener(@NotNull ConversationAbandonedListener listener) {
|
||||
abandonedListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
@@ -182,7 +194,8 @@ public class ConversationFactory {
|
||||
* @param forWhom The entity for whom the new conversation is mediating.
|
||||
* @return A new conversation.
|
||||
*/
|
||||
public Conversation buildConversation(Conversable forWhom) {
|
||||
@NotNull
|
||||
public Conversation buildConversation(@NotNull Conversable forWhom) {
|
||||
//Abort conversation construction if we aren't supposed to talk to non-players
|
||||
if (playerOnlyMessage != null && !(forWhom instanceof Player)) {
|
||||
return new Conversation(plugin, forWhom, new NotPlayerMessagePrompt());
|
||||
@@ -213,12 +226,14 @@ public class ConversationFactory {
|
||||
|
||||
private class NotPlayerMessagePrompt extends MessagePrompt {
|
||||
|
||||
public String getPromptText(ConversationContext context) {
|
||||
@NotNull
|
||||
public String getPromptText(@NotNull ConversationContext context) {
|
||||
return playerOnlyMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Prompt getNextPrompt(ConversationContext context) {
|
||||
protected Prompt getNextPrompt(@NotNull ConversationContext context) {
|
||||
return Prompt.END_OF_CONVERSATION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A ConversationPrefix implementation prepends all output from the
|
||||
* conversation to the player. The ConversationPrefix can be used to display
|
||||
@@ -13,5 +15,6 @@ public interface ConversationPrefix {
|
||||
* @param context Context information about the conversation.
|
||||
* @return The prefix text.
|
||||
*/
|
||||
String getPrefix(ConversationContext context);
|
||||
@NotNull
|
||||
String getPrefix(@NotNull ConversationContext context);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An ExactMatchConversationCanceller cancels a conversation if the user
|
||||
* enters an exact input string
|
||||
@@ -13,16 +15,17 @@ public class ExactMatchConversationCanceller implements ConversationCanceller {
|
||||
* @param escapeSequence The string that, if entered by the user, will
|
||||
* cancel the conversation.
|
||||
*/
|
||||
public ExactMatchConversationCanceller(String escapeSequence) {
|
||||
public ExactMatchConversationCanceller(@NotNull String escapeSequence) {
|
||||
this.escapeSequence = escapeSequence;
|
||||
}
|
||||
|
||||
public void setConversation(Conversation conversation) {}
|
||||
public void setConversation(@NotNull Conversation conversation) {}
|
||||
|
||||
public boolean cancelBasedOnInput(ConversationContext context, String input) {
|
||||
public boolean cancelBasedOnInput(@NotNull ConversationContext context, @NotNull String input) {
|
||||
return input.equals(escapeSequence);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConversationCanceller clone() {
|
||||
return new ExactMatchConversationCanceller(escapeSequence);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -21,7 +23,7 @@ public abstract class FixedSetPrompt extends ValidatingPrompt {
|
||||
* @param fixedSet A fixed set of strings, one of which the user must
|
||||
* type.
|
||||
*/
|
||||
public FixedSetPrompt(String... fixedSet) {
|
||||
public FixedSetPrompt(@NotNull String... fixedSet) {
|
||||
super();
|
||||
this.fixedSet = Arrays.asList(fixedSet);
|
||||
}
|
||||
@@ -29,7 +31,7 @@ public abstract class FixedSetPrompt extends ValidatingPrompt {
|
||||
private FixedSetPrompt() {}
|
||||
|
||||
@Override
|
||||
protected boolean isInputValid(ConversationContext context, String input) {
|
||||
protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) {
|
||||
return fixedSet.contains(input);
|
||||
}
|
||||
|
||||
@@ -40,6 +42,7 @@ public abstract class FixedSetPrompt extends ValidatingPrompt {
|
||||
* @return the options formatted like "[bar, cheese, panda]" if bar,
|
||||
* cheese, and panda were the options used
|
||||
*/
|
||||
@NotNull
|
||||
protected String formatFixedSet() {
|
||||
return "[" + StringUtils.join(fixedSet, ", ") + "]";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An InactivityConversationCanceller will cancel a {@link Conversation} after
|
||||
@@ -18,23 +19,24 @@ public class InactivityConversationCanceller implements ConversationCanceller {
|
||||
* @param plugin The owning plugin.
|
||||
* @param timeoutSeconds The number of seconds of inactivity to wait.
|
||||
*/
|
||||
public InactivityConversationCanceller(Plugin plugin, int timeoutSeconds) {
|
||||
public InactivityConversationCanceller(@NotNull Plugin plugin, int timeoutSeconds) {
|
||||
this.plugin = plugin;
|
||||
this.timeoutSeconds = timeoutSeconds;
|
||||
}
|
||||
|
||||
public void setConversation(Conversation conversation) {
|
||||
public void setConversation(@NotNull Conversation conversation) {
|
||||
this.conversation = conversation;
|
||||
startTimer();
|
||||
}
|
||||
|
||||
public boolean cancelBasedOnInput(ConversationContext context, String input) {
|
||||
public boolean cancelBasedOnInput(@NotNull ConversationContext context, @NotNull String input) {
|
||||
// Reset the inactivity timer
|
||||
stopTimer();
|
||||
startTimer();
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConversationCanceller clone() {
|
||||
return new InactivityConversationCanceller(plugin, timeoutSeconds);
|
||||
}
|
||||
@@ -72,7 +74,7 @@ public class InactivityConversationCanceller implements ConversationCanceller {
|
||||
*
|
||||
* @param conversation The conversation being abandoned.
|
||||
*/
|
||||
protected void cancelling(Conversation conversation) {
|
||||
protected void cancelling(@NotNull Conversation conversation) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The ManuallyAbandonedConversationCanceller is only used as part of a {@link
|
||||
* ConversationAbandonedEvent} to indicate that the conversation was manually
|
||||
* abandoned by programmatically calling the abandon() method on it.
|
||||
*/
|
||||
public class ManuallyAbandonedConversationCanceller implements ConversationCanceller {
|
||||
public void setConversation(Conversation conversation) {
|
||||
public void setConversation(@NotNull Conversation conversation) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean cancelBasedOnInput(ConversationContext context, String input) {
|
||||
public boolean cancelBasedOnInput(@NotNull ConversationContext context, @NotNull String input) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConversationCanceller clone() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* MessagePrompt is the base class for any prompt that only displays a message
|
||||
* to the user and requires no input.
|
||||
@@ -16,7 +19,7 @@ public abstract class MessagePrompt implements Prompt {
|
||||
* @param context Context information about the conversation.
|
||||
* @return Always false.
|
||||
*/
|
||||
public boolean blocksForInput(ConversationContext context) {
|
||||
public boolean blocksForInput(@NotNull ConversationContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,7 +31,8 @@ public abstract class MessagePrompt implements Prompt {
|
||||
* @param input Ignored.
|
||||
* @return The next prompt in the prompt graph.
|
||||
*/
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
@Nullable
|
||||
public Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input) {
|
||||
return getNextPrompt(context);
|
||||
}
|
||||
|
||||
@@ -38,5 +42,6 @@ public abstract class MessagePrompt implements Prompt {
|
||||
* @param context Context information about the conversation.
|
||||
* @return The next prompt in the prompt graph.
|
||||
*/
|
||||
protected abstract Prompt getNextPrompt(ConversationContext context);
|
||||
@Nullable
|
||||
protected abstract Prompt getNextPrompt(@NotNull ConversationContext context);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* NullConversationPrefix is a {@link ConversationPrefix} implementation that
|
||||
* displays nothing in front of conversation output.
|
||||
@@ -12,7 +14,8 @@ public class NullConversationPrefix implements ConversationPrefix {
|
||||
* @param context Context information about the conversation.
|
||||
* @return An empty string.
|
||||
*/
|
||||
public String getPrefix(ConversationContext context) {
|
||||
@NotNull
|
||||
public String getPrefix(@NotNull ConversationContext context) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* NumericPrompt is the base class for any prompt that requires a {@link
|
||||
@@ -12,7 +14,7 @@ public abstract class NumericPrompt extends ValidatingPrompt {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isInputValid(ConversationContext context, String input) {
|
||||
protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) {
|
||||
return NumberUtils.isNumber(input) && isNumberValid(context, NumberUtils.createNumber(input));
|
||||
}
|
||||
|
||||
@@ -24,12 +26,13 @@ public abstract class NumericPrompt extends ValidatingPrompt {
|
||||
* @param input The number the player provided.
|
||||
* @return The validity of the player's input.
|
||||
*/
|
||||
protected boolean isNumberValid(ConversationContext context, Number input) {
|
||||
protected boolean isNumberValid(@NotNull ConversationContext context, @NotNull Number input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
|
||||
protected Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull String input) {
|
||||
try {
|
||||
return acceptValidatedInput(context, NumberUtils.createNumber(input));
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -45,10 +48,12 @@ public abstract class NumericPrompt extends ValidatingPrompt {
|
||||
* @param input The user's response as a {@link Number}.
|
||||
* @return The next {@link Prompt} in the prompt graph.
|
||||
*/
|
||||
protected abstract Prompt acceptValidatedInput(ConversationContext context, Number input);
|
||||
@Nullable
|
||||
protected abstract Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull Number input);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String getFailedValidationText(ConversationContext context, String invalidInput) {
|
||||
protected String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) {
|
||||
if (NumberUtils.isNumber(invalidInput)) {
|
||||
return getFailedValidationText(context, NumberUtils.createNumber(invalidInput));
|
||||
} else {
|
||||
@@ -64,7 +69,8 @@ public abstract class NumericPrompt extends ValidatingPrompt {
|
||||
* @param invalidInput The invalid input provided by the user.
|
||||
* @return A message explaining how to correct the input.
|
||||
*/
|
||||
protected String getInputNotNumericText(ConversationContext context, String invalidInput) {
|
||||
@Nullable
|
||||
protected String getInputNotNumericText(@NotNull ConversationContext context, @NotNull String invalidInput) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,7 +82,8 @@ public abstract class NumericPrompt extends ValidatingPrompt {
|
||||
* @param invalidInput The invalid input provided by the user.
|
||||
* @return A message explaining how to correct the input.
|
||||
*/
|
||||
protected String getFailedValidationText(ConversationContext context, Number invalidInput) {
|
||||
@Nullable
|
||||
protected String getFailedValidationText(@NotNull ConversationContext context, @NotNull Number invalidInput) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* PlayerNamePrompt is the base class for any prompt that requires the player
|
||||
@@ -10,18 +12,19 @@ import org.bukkit.plugin.Plugin;
|
||||
public abstract class PlayerNamePrompt extends ValidatingPrompt {
|
||||
private Plugin plugin;
|
||||
|
||||
public PlayerNamePrompt(Plugin plugin) {
|
||||
public PlayerNamePrompt(@NotNull Plugin plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isInputValid(ConversationContext context, String input) {
|
||||
protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) {
|
||||
return plugin.getServer().getPlayer(input) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
|
||||
protected Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull String input) {
|
||||
return acceptValidatedInput(context, plugin.getServer().getPlayer(input));
|
||||
}
|
||||
|
||||
@@ -33,5 +36,6 @@ public abstract class PlayerNamePrompt extends ValidatingPrompt {
|
||||
* @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);
|
||||
@Nullable
|
||||
protected abstract Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull Player input);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* PluginNameConversationPrefix is a {@link ConversationPrefix} implementation
|
||||
@@ -15,11 +16,11 @@ public class PluginNameConversationPrefix implements ConversationPrefix {
|
||||
|
||||
private String cachedPrefix;
|
||||
|
||||
public PluginNameConversationPrefix(Plugin plugin) {
|
||||
public PluginNameConversationPrefix(@NotNull Plugin plugin) {
|
||||
this(plugin, " > ", ChatColor.LIGHT_PURPLE);
|
||||
}
|
||||
|
||||
public PluginNameConversationPrefix(Plugin plugin, String separator, ChatColor prefixColor) {
|
||||
public PluginNameConversationPrefix(@NotNull Plugin plugin, @NotNull String separator, @NotNull ChatColor prefixColor) {
|
||||
this.separator = separator;
|
||||
this.prefixColor = prefixColor;
|
||||
this.plugin = plugin;
|
||||
@@ -33,7 +34,8 @@ public class PluginNameConversationPrefix implements ConversationPrefix {
|
||||
* @param context Context information about the conversation.
|
||||
* @return An empty string.
|
||||
*/
|
||||
public String getPrefix(ConversationContext context) {
|
||||
@NotNull
|
||||
public String getPrefix(@NotNull ConversationContext context) {
|
||||
return cachedPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A Prompt is the main constituent of a {@link Conversation}. Each prompt
|
||||
* displays text to the user and optionally waits for a user's response.
|
||||
@@ -21,7 +24,8 @@ public interface Prompt extends Cloneable {
|
||||
* @param context Context information about the conversation.
|
||||
* @return The text to display.
|
||||
*/
|
||||
String getPromptText(ConversationContext context);
|
||||
@NotNull
|
||||
String getPromptText(@NotNull ConversationContext context);
|
||||
|
||||
/**
|
||||
* Checks to see if this prompt implementation should wait for user input
|
||||
@@ -29,9 +33,9 @@ public interface Prompt extends Cloneable {
|
||||
*
|
||||
* @param context Context information about the conversation.
|
||||
* @return If true, the {@link Conversation} will wait for input before
|
||||
* continuing.
|
||||
* continuing. If false, {@link #acceptInput(ConversationContext, String)} will be called immediately with {@code null} input.
|
||||
*/
|
||||
boolean blocksForInput(ConversationContext context);
|
||||
boolean blocksForInput(@NotNull ConversationContext context);
|
||||
|
||||
/**
|
||||
* Accepts and processes input from the user. Using the input, the next
|
||||
@@ -41,5 +45,6 @@ public interface Prompt extends Cloneable {
|
||||
* @param input The input text from the user.
|
||||
* @return The next Prompt in the prompt graph.
|
||||
*/
|
||||
Prompt acceptInput(ConversationContext context, String input);
|
||||
@Nullable
|
||||
Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -10,11 +13,11 @@ public abstract class RegexPrompt extends ValidatingPrompt {
|
||||
|
||||
private Pattern pattern;
|
||||
|
||||
public RegexPrompt(String regex) {
|
||||
public RegexPrompt(@NotNull String regex) {
|
||||
this(Pattern.compile(regex));
|
||||
}
|
||||
|
||||
public RegexPrompt(Pattern pattern) {
|
||||
public RegexPrompt(@NotNull Pattern pattern) {
|
||||
super();
|
||||
this.pattern = pattern;
|
||||
}
|
||||
@@ -22,7 +25,7 @@ public abstract class RegexPrompt extends ValidatingPrompt {
|
||||
private RegexPrompt() {}
|
||||
|
||||
@Override
|
||||
protected boolean isInputValid(ConversationContext context, String input) {
|
||||
protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) {
|
||||
return pattern.matcher(input).matches();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* StringPrompt is the base class for any prompt that accepts an arbitrary
|
||||
* string from the user.
|
||||
@@ -12,7 +14,7 @@ public abstract class StringPrompt implements Prompt {
|
||||
* @param context Context information about the conversation.
|
||||
* @return True.
|
||||
*/
|
||||
public boolean blocksForInput(ConversationContext context) {
|
||||
public boolean blocksForInput(@NotNull ConversationContext context) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* ValidatingPrompt is the base class for any prompt that requires validation.
|
||||
@@ -21,7 +23,8 @@ public abstract class ValidatingPrompt implements Prompt {
|
||||
* @param input The input text from the user.
|
||||
* @return This prompt or the next Prompt in the prompt graph.
|
||||
*/
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
@Nullable
|
||||
public Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input) {
|
||||
if (isInputValid(context, input)) {
|
||||
return acceptValidatedInput(context, input);
|
||||
} else {
|
||||
@@ -40,7 +43,7 @@ public abstract class ValidatingPrompt implements Prompt {
|
||||
* @param context Context information about the conversation.
|
||||
* @return True.
|
||||
*/
|
||||
public boolean blocksForInput(ConversationContext context) {
|
||||
public boolean blocksForInput(@NotNull ConversationContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,7 +54,7 @@ public abstract class ValidatingPrompt implements Prompt {
|
||||
* @param input The player's raw console input.
|
||||
* @return True or false depending on the validity of the input.
|
||||
*/
|
||||
protected abstract boolean isInputValid(ConversationContext context, String input);
|
||||
protected abstract boolean isInputValid(@NotNull ConversationContext context, @NotNull String input);
|
||||
|
||||
/**
|
||||
* Override this method to accept and processes the validated input from
|
||||
@@ -62,7 +65,8 @@ public abstract class ValidatingPrompt implements Prompt {
|
||||
* @param input The validated input text from the user.
|
||||
* @return The next Prompt in the prompt graph.
|
||||
*/
|
||||
protected abstract Prompt acceptValidatedInput(ConversationContext context, String input);
|
||||
@Nullable
|
||||
protected abstract Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull String input);
|
||||
|
||||
/**
|
||||
* Optionally override this method to display an additional message if the
|
||||
@@ -72,7 +76,8 @@ public abstract class ValidatingPrompt implements Prompt {
|
||||
* @param invalidInput The invalid input provided by the user.
|
||||
* @return A message explaining how to correct the input.
|
||||
*/
|
||||
protected String getFailedValidationText(ConversationContext context, String invalidInput) {
|
||||
@Nullable
|
||||
protected String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user