Advertisement
Guest User

Untitled

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