Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.02 KB | None | 0 0
  1. package com.jcwhatever.bukkit.generic.commands;
  2.  
  3. import java.util.Collection;
  4.  
  5. import javax.annotation.Nullable;
  6.  
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.inventory.ItemStack;
  9.  
  10. /**
  11. * Represents an implementation that processes command arguments as needed.
  12. *
  13. * <p>Commands can request parameters by name and have them parsed into the expected
  14. * object type at the same time. If the parameter has no provided value, cannot be parsed
  15. * or required conditions for parsing the object are not met, an {@code InvalidValueException}
  16. * is thrown and should be caught by the command handler.</p>
  17. *
  18. * @author JC The Pants
  19. *
  20. */
  21. public interface ICommandArguments {
  22.  
  23. /**
  24. * The number of arguments in the collection.
  25. *
  26. * <p>Includes arguments automatically added due to the
  27. * parameter having a default value.</p>
  28. *
  29. * @return
  30. */
  31. public int size();
  32.  
  33. /**
  34. * The number of arguments expected.
  35. *
  36. * <p>Used by the command handler to quickly determine if the number of
  37. * arguments provided is valid.</p>
  38. *
  39. * @return
  40. */
  41. public int expectedSize();
  42.  
  43. /**
  44. * Get an {@code ICommandParameter} by index
  45. *
  46. * @param index The index position of the parameter as provided by the command sender
  47. *
  48. * @return
  49. */
  50. @Nullable
  51. public ICommandArgument get(int index);
  52.  
  53. /**
  54. * Get an argument as a {@code String} and ensures it meets proper naming conventions.
  55. *
  56. * <p>The name must be alphanumeric characters only, must not start with a number,
  57. * no spaces, underscores are allowed. Must be no more than 16 characters in length.</p>
  58. *
  59. * @param parameterName The name of the parameter to get
  60. *
  61. * @return {@code String}
  62. *
  63. * @throws InvalidValueException
  64. */
  65. public String getName(String parameterName) throws InvalidValueException;
  66.  
  67. /**
  68. * Get an argument as a {@code String} and ensures it meets proper naming conventions.
  69. *
  70. * <p>The name must be alphanumeric characters only, must not start with a number,
  71. * no spaces, underscores are allowed. </p>
  72. *
  73. * @param parameterName The name of the arguments parameter
  74. * @param maxLen The maximum length of the value
  75. *
  76. * @return {@code String}
  77. *
  78. * @throws InvalidValueException
  79. */
  80. public String getName(String parameterName, int maxLen) throws InvalidValueException;
  81.  
  82. /**
  83. * Get an argument as a string.
  84. *
  85. * @param parameterName The name of the arguments parameter
  86. *
  87. * @return {@code String}
  88. *
  89. * @throws InvalidValueException
  90. */
  91. public String getString(String parameterName) throws InvalidValueException;
  92.  
  93. /**
  94. * Get an argument as a character.
  95. *
  96. * @param parameterName The name of the arguments parameter
  97. *
  98. * @return {@code char}
  99. *
  100. * @throws InvalidValueException
  101. */
  102. public char getChar(String parameterName) throws InvalidValueException;
  103.  
  104. /**
  105. * Gets an argument as an integer.
  106. *
  107. * @param parameterName The name of the arguments parameter
  108. *
  109. * @return {@code int}
  110. *
  111. * @throws InvalidValueException
  112. */
  113. public int getInt(String parameterName) throws InvalidValueException;
  114.  
  115. /**
  116. * Gets an argument as a short.
  117. *
  118. * @param parameterName The name of the arguments parameter
  119. *
  120. * @return {@code short}
  121. *
  122. * @throws InvalidValueException
  123. */
  124. public short getShort(String parameterName) throws InvalidValueException;
  125.  
  126. /**
  127. * Gets an argument as a byte.
  128. *
  129. * @param parameterName The name of the arguments parameter
  130. *
  131. * @return {@code byte}
  132. *
  133. * @throws InvalidValueException
  134. */
  135. public byte getByte(String parameterName) throws InvalidValueException;
  136.  
  137. /**
  138. * Gets an argument as a double.
  139. *
  140. * @param parameterName The name of the arguments parameter
  141. *
  142. * @return {@code double}
  143. *
  144. * @throws InvalidValueException
  145. */
  146. public double getDouble(String parameterName) throws InvalidValueException;
  147.  
  148. /**
  149. * Gets an argument as a float.
  150. *
  151. * @param parameterName The name of the arguments parameter
  152. *
  153. * @return {@code float}
  154. *
  155. * @throws InvalidValueException
  156. */
  157. public float getFloat(String parameterName) throws InvalidValueException;
  158.  
  159. /**
  160. * Gets an argument as a boolean.
  161. *
  162. * <p>true,on,yes = true</p>
  163. * <p>false,off,no = false</p>
  164. *
  165. * @param parameterName The name of the arguments parameter
  166. *
  167. * @return {@code boolean}
  168. *
  169. * @throws InvalidValueException
  170. */
  171. public boolean getBoolean(String parameterName) throws InvalidValueException;
  172.  
  173. /**
  174. * Gets an argument as a double. "%" characters are ignored.
  175. *
  176. * @param parameterName The name of the arguments parameter
  177. *
  178. * @return {@code double}
  179. *
  180. * @throws InvalidValueException
  181. */
  182. public double getPercent(String parameterName) throws InvalidValueException;
  183.  
  184. /**
  185. * Gets an arguments raw {@code String} value, splits it at the space character
  186. * and returns it as a {@code String[]}
  187. *
  188. * @param parameterName The name of the arguments parameter
  189. *
  190. * @return {@code String[]}
  191. */
  192. public String[] getParams(String parameterName) throws InvalidValueException;
  193.  
  194. /**
  195. * Gets an argument as an {@code ItemStack[]}.
  196. *
  197. * <p>The supplied argument can be a parsable string representing an {@code ItemStack}</p>
  198. *
  199. * <p>The supplied argument can also be "inhand" for the stack in the players hand,
  200. * "inventory" to return all items in the players inventory, or "hotbar" to return
  201. * all items in the players hotbar. All items returned from the player are cloned objects.</p>
  202. *
  203. * <p>Use getString(parameterName) method on the same parameter to determine if the player
  204. * typed "inhand", "inventory", or "hotbar" if that information is needed.</p>
  205. *
  206. * <p>If the command sender is not a player, and therefore has no inventory, the argument
  207. * will only be valid if a parsable item stack string was provided.</p>
  208. *
  209. * @param sender The {@code CommandSender} who executed the command
  210. * @param parameterName The name of the arguments parameter
  211. *
  212. * @return {@code ItemStack[]}
  213. *
  214. * @throws InvalidValueException
  215. */
  216. public ItemStack[] getItemStack(CommandSender sender, String parameterName) throws InvalidValueException;
  217.  
  218. /**
  219. * Gets an argument as a location.
  220. *
  221. * <p>Possible values are "current" or "select"</p>
  222. *
  223. * <p>If the argument value is "current", the players current location is returned via
  224. * the {@code LocationHandler}.</p>
  225. *
  226. * <p>If the argument value is "select", the player is asked to click on the location
  227. * to be selected and the value is return via the {@code LocationHandler}.</p>
  228. *
  229. * <p>If the {@CommandSender} is not a player the argument is always considered invalid.</p>
  230. *
  231. * @param sender The {@code CommandSender} who executed the command
  232. * @param parameterName The name of the arguments parameter
  233. * @param locationHandler The {@code LocationHandler} responsible for dealing with the return location.
  234. *
  235. * @throws InvalidValueException
  236. */
  237. public void getLocation(CommandSender sender, String parameterName, LocationHandler locationHandler) throws InvalidValueException;
  238.  
  239. /**
  240. * Gets an argument as an enum. The argument must be the name of the enum constant and
  241. * is not case sensitive, unless there are case conflicts.
  242. *
  243. * @param parameterName The name of the arguments parameter
  244. * @param enumClass The enums class
  245. *
  246. * @return
  247. *
  248. * @throws InvalidValueException
  249. */
  250. public <T extends Enum<T>> T getEnum(String parameterName, Class<T> enumClass) throws InvalidValueException;
  251.  
  252. /**
  253. * Gets an argument as an enum. The argument must be the name of the enum constant and
  254. * is not case sensitive, unless there are case conflicts.
  255. *
  256. * <p>Valid values can be specified to prevent all of an enums constants from being valid.
  257. * Use if you have no control over the enum and it isn't practical to make a
  258. * new enum.</p>
  259. *
  260. * @param parameterName The name of the arguments parameter
  261. * @param enumClass The enums class
  262. * @param validValues an array of valid enum constants
  263. *
  264. * @return
  265. *
  266. * @throws InvalidValueException
  267. */
  268. public <T extends Enum<T>> T getEnum(String parameterName, Class<T> enumClass, T[] validValues) throws InvalidValueException;
  269.  
  270. /**
  271. * Gets an argument as an enum. The argument must be the name of the enum constant and
  272. * is not case sensitive, unless there are case conflicts.
  273. *
  274. * <p>Valid values can be specified to prevent all of an enums constants from being valid.
  275. * Use if you have no control over the enum and it isn't practical to make a
  276. * new enum.</p>
  277. *
  278. * @param parameterName The name of the arguments parameter
  279. * @param enumClass The enums class
  280. * @param validValues A collection of valid enum constants
  281. *
  282. * @return
  283. *
  284. * @throws InvalidValueException
  285. */
  286. public <T extends Enum<T>> T getEnum(String parameterName, Class<T> enumClass, Collection<T> validValues) throws InvalidValueException;
  287.  
  288.  
  289. /**
  290. * Determine if an argument is provided.
  291. *
  292. * @param parameterName The name of the arguments parameter
  293. *
  294. * @return
  295. */
  296. public boolean hasValue(String parameterName);
  297.  
  298. /**
  299. * Determine if an argument is provided.
  300. *
  301. * @param parameterName The name of the arguments parameter
  302. *
  303. * @return
  304. */
  305. public boolean hasString(String parameterName);
  306.  
  307. /**
  308. * Determine if an argument is provided and is a single character.
  309. *
  310. * @param parameterName The name of the arguments parameter
  311. *
  312. * @return
  313. */
  314. public boolean hasChar(String parameterName);
  315.  
  316. /**
  317. * Determine if an argument is provided and can be used as an integer value.
  318. *
  319. * @param parameterName The name of the arguments parameter
  320. *
  321. * @return
  322. */
  323. public boolean hasInt(String parameterName);
  324.  
  325. /**
  326. * Determine if an argument is provided and can be used as a short value.
  327. *
  328. * @param parameterName The name of the arguments parameter
  329. *
  330. * @return
  331. */
  332. public boolean hasShort(String parameterName);
  333.  
  334. /**
  335. * Determine if an argument is provided and can be used as a byte value.
  336. *
  337. * @param parameterName The name of the arguments parameter
  338. *
  339. * @return
  340. */
  341. public boolean hasByte(String parameterName);
  342.  
  343. /**
  344. * Determine if an argument is provided and can be used as a double value.
  345. *
  346. * @param parameterName The name of the arguments parameter
  347. *
  348. * @return
  349. */
  350. public boolean hasDouble(String parameterName);
  351.  
  352. /**
  353. * Determine if an argument is provided and can be used as a float value.
  354. *
  355. * @param parameterName The name of the arguments parameter
  356. *
  357. * @return
  358. */
  359. public boolean hasFloat(String parameterName);
  360.  
  361. /**
  362. * Determine if an argument is provided and can be used as a boolean value.
  363. *
  364. * @param parameterName The name of the arguments parameter
  365. * @return
  366. */
  367. public boolean hasBoolean(String parameterName);
  368.  
  369. /**
  370. * Determine if an argument is provided and can be used as an item stack array.
  371. *
  372. * @param parameterName The name of the arguments parameter
  373. * @return
  374. */
  375. public boolean hasItemStack(String parameterName);
  376.  
  377. /**
  378. * Determine if an argument is provided and can be used as a double value.
  379. *
  380. * <p>A '%' character in the value will not invalidate the argument.</p>
  381. *
  382. * @param parameterName The name of the arguments parameter
  383. * @return
  384. */
  385. public boolean hasPercent(String parameterName);
  386.  
  387. /**
  388. * Determine if an argument is provided and can be used as an enum.
  389. *
  390. * @param parameterName The name of the arguments parameter
  391. * @param enumClass The enum class the argument must be used as
  392. * @return
  393. */
  394. public <T extends Enum<T>> boolean hasEnum(String parameterName, Class<T> enumClass);
  395.  
  396.  
  397.  
  398.  
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement