vMinecraftCommands.java 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  1. import java.io.IOException;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.lang.reflect.Method;
  4. import java.util.ArrayList;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. //=====================================================================
  8. //Class: vMinecraftCommands
  9. //Use: Encapsulates all commands added by this mod
  10. //Author: nos, trapalice, cerevisiae
  11. //=====================================================================
  12. public class vMinecraftCommands{
  13. //Log output
  14. protected static final Logger log = Logger.getLogger("Minecraft");
  15. static final int EXIT_FAIL = 0,
  16. EXIT_SUCCESS = 1,
  17. EXIT_CONTINUE = 2;
  18. //The list of commands for vMinecraft
  19. public static commandList cl = new commandList();
  20. //=====================================================================
  21. //Function: loadCommands
  22. //Input: None
  23. //Output: None
  24. //Use: Imports all the commands into the command list
  25. //=====================================================================
  26. public static void loadCommands(){
  27. //If we had commands we would add them here.
  28. //register: Registers a function for use with a command
  29. //String: The command that will be used
  30. //String: The name of the function that will be called when
  31. // the command is used
  32. //String(Optional): The help menu description
  33. //Administrative
  34. cl.register("/prefix", "prefix", "Set your name color and prefix");
  35. cl.register("/rprefix", "removeTag", "Remove your name color and prefix");
  36. cl.register("/nick", "nickName", "Set your display name");
  37. cl.register("/rnick", "removeNick", "Reset your display name to your account name");
  38. cl.register("/suffix", "suffix", "Set your suffix");
  39. cl.register("/rsuffix", "removeSuffix", "Remove your suffix");
  40. cl.register("/vminecraft", "vminecrafthelp");
  41. cl.register("/reload", "reload");
  42. cl.register("/whois", "whois", "/whois [user]");
  43. cl.register("/say", "say");
  44. cl.register("/a", "adminChatToggle", "Toggle admin chat for every message");
  45. cl.register("/modify", "modify");
  46. cl.register("/rules", "rules", "Displays the rules");
  47. cl.register("/who", "who");
  48. cl.register("/promote", "promote", "Promote a player one rank");
  49. cl.register("/demote", "demote", "Demote a player one rank");
  50. //Movement
  51. cl.register("/freeze", "freeze");
  52. cl.register("/tp", "teleport");
  53. cl.register("/tphere", "tphere");
  54. cl.register("/masstp", "masstp", "Teleports those with lower permissions to you");
  55. //Health
  56. cl.register("/ezmodo", "invuln", "Toggle invulnerability");
  57. cl.register("/ezlist", "ezlist", "List invulnerable players");
  58. cl.register("/heal", "heal", "heal yourself or other players");
  59. cl.register("/suicide", "suicide", "Kill yourself... you loser");
  60. cl.register("/slay", "slay", "Kill target player");
  61. //Social
  62. cl.register("/colors", "colors", "Set your default chat color: /colors <Color Char>");
  63. cl.register("/me", "me");
  64. cl.register("/fabulous", "fabulous", "makes text SUUUPER");
  65. cl.register("/msg", "message", "Send a message to a player /msg [Player] [Message]");
  66. cl.register("/reply", "reply", "Reply to a player /reply [Message], Alias: /r");
  67. cl.register("/ignore", "addIgnored", "Adds a user to your ignore list");
  68. cl.register("/unignore", "removeIgnored", "Removes a user from your ignore list");
  69. cl.register("/ignorelist", "ignoreList", "Lists the players you have ignored");
  70. //registerAlias: Runs the second command when the first command is called
  71. //String: The command that this will be called by
  72. //String: The message that will be called when the first is entered
  73. // Can be modified with %# to have it insert a player
  74. // argument into that position.
  75. // EX: Aliased command is
  76. // cl.registerAlias("/test", "/i %0 100")
  77. // Player uses /test wood
  78. // The %0 will be replaced with wood for this instance
  79. // and Player will be given 100 wood.
  80. cl.registerAlias("/playerlist", "/who");
  81. cl.registerAlias("/vhelp", "/vminecraft");
  82. cl.registerAlias("/r", "/reply");
  83. cl.registerAlias("/t", "/msg");
  84. cl.registerAlias("/tell", "/msg");
  85. cl.registerAlias("/wrists", "/suicide");
  86. cl.registerAlias("/kill", "/suicide");
  87. cl.registerAlias("/ci", "/clearinventory");
  88. //registerMessage: Displays a message whenever a command is used
  89. //String: The command it will run on
  90. //String: What will be displayed
  91. // %p is the player calling the command
  92. // %# is the argument number of the command.
  93. // %#p is an argument number that will be required to be
  94. // an online player
  95. //String: The color the message will be
  96. //int: The number of arguments required for the message to appear
  97. //boolean: If the message should only display for admins
  98. cl.registerMessage("/kick", "%p has kicked %0p", Colors.Blue, 1, false);
  99. cl.registerMessage("/ban", "%p has banned %0p", Colors.Blue, 1, false);
  100. cl.registerMessage("/ipban", "%p has IP banned %0p", Colors.Blue, 1, false);
  101. cl.registerMessage("/time", "Time change thanks to %p", Colors.Blue, 1, true);
  102. }
  103. //=====================================================================
  104. //Function: vminecrafthelp (/vhelp or /vminecraft)
  105. //Input: Player player: The player using the command
  106. //Output: int: Exit Code
  107. //Use: Displays the current status of most vMinecraft settings
  108. // and provides some useful tips.
  109. //=====================================================================
  110. public static int vminecrafthelp(Player player, String[] args){
  111. vMinecraftChat.sendMessage(player, player, Colors.Yellow
  112. + "Chat Settings");
  113. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  114. + "Admin Chat: " + vMinecraftSettings.getInstance()
  115. .adminchat());
  116. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  117. + "FFF turns red: " + vMinecraftSettings.getInstance()
  118. .FFF());
  119. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  120. + "Greentext After >: " + vMinecraftSettings.getInstance()
  121. .greentext());
  122. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  123. + "Quake Color Script: " + vMinecraftSettings.getInstance()
  124. .quakeColors());
  125. vMinecraftChat.sendMessage(player, player, Colors.Yellow
  126. + "Enabled Commands are TRUE, disabled are FALSE");
  127. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  128. + "Command /ezmodo: " + vMinecraftSettings.getInstance()
  129. .cmdEzModo());
  130. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  131. + "Command /fabulous: " + vMinecraftSettings.getInstance()
  132. .cmdFabulous());
  133. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  134. + "Command /rules: " + vMinecraftSettings.getInstance()
  135. .cmdRules());
  136. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  137. + "Command /heal: " + vMinecraftSettings.getInstance()
  138. .cmdHeal());
  139. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  140. + "Command /masstp: " + vMinecraftSettings.getInstance()
  141. .cmdMasstp());
  142. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  143. + "Command /say: " + vMinecraftSettings.getInstance()
  144. .cmdSay());
  145. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  146. + "Command /suicide: " + vMinecraftSettings.getInstance()
  147. .cmdSuicide());
  148. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  149. + "Command /whois: " + vMinecraftSettings.getInstance()
  150. .cmdWhoIs());
  151. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  152. + "Command /tp won't work on higher ranked players: "
  153. + vMinecraftSettings.getInstance().cmdTp());
  154. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  155. + "Command /tphere won't work on higher ranked players: "
  156. + vMinecraftSettings.getInstance().cmdTphere());
  157. vMinecraftChat.sendMessage(player, player, Colors.Yellow
  158. + "Other Settings");
  159. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  160. + "Command /who: " + vMinecraftSettings.getInstance()
  161. .cmdWho());
  162. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  163. + "COLORED PLAYER LIST IS DEPENDENT ON /who BEING TRUE!");
  164. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple
  165. + "Global Messages: " + vMinecraftSettings.getInstance()
  166. .globalmessages());
  167. return EXIT_SUCCESS;
  168. }
  169. //=====================================================================
  170. //Function: prefix (/prefix)
  171. //Input: Player player: The player using the command
  172. // String[] args: The name of the player
  173. //Output: int: Exit Code
  174. //Use: Freezes a player in place
  175. //=====================================================================
  176. public static int freeze(Player player, String[] args){
  177. if(player.canUseCommand("/freeze") && vMinecraftSettings.getInstance().freeze()){
  178. if (args.length < 2){
  179. vMinecraftChat.gmsg(Colors.Rose + "Usage is /freeze [Player]");
  180. return EXIT_SUCCESS;
  181. }
  182. Player other = etc.getServer().matchPlayer(args[0]);
  183. if (other == null)
  184. {
  185. vMinecraftChat.gmsg(Colors.Rose + "The player you specified could not be found");
  186. return EXIT_SUCCESS;
  187. }
  188. if(player != other && other.hasControlOver(player)){
  189. vMinecraftChat.gmsg(Colors.Rose + "The player you specified has a higher rank than you");
  190. return EXIT_SUCCESS;
  191. }
  192. if(vMinecraftSettings.frozenplayers.contains(other)){
  193. vMinecraftSettings.getInstance().removeFrozen(other.getName());
  194. vMinecraftChat.gmsg(player.getName() + Colors.Blue + " has unfrozen " + other.getName());
  195. return EXIT_SUCCESS;
  196. }
  197. vMinecraftSettings.getInstance().addFrozen(other.getName());
  198. vMinecraftChat.gmsg(player.getName() + Colors.Blue + " has frozen " + other.getName());
  199. return EXIT_SUCCESS;
  200. }
  201. return EXIT_SUCCESS;
  202. }
  203. //=====================================================================
  204. //Function: prefix (/prefix)
  205. //Input: Player player: The player using the command
  206. // String[] args: The color and the prefix
  207. //Output: int: Exit Code
  208. //Use: Changes your name color and prefix
  209. //=====================================================================
  210. public static int prefix(Player player, String[] args){
  211. //if the player can prefix others
  212. if(player.canUseCommand("/prefixother") && vMinecraftSettings.getInstance().prefix()){
  213. //Check if there are enough arguments
  214. if(args.length < 2){
  215. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Usage is /prefix [Player] [Color Code] <Tag>");
  216. player.sendMessage(Colors.DarkPurple + "Example: /prefix " + player.getName() + " e ^0[^a<3^0]");
  217. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple + "This would produce a name like... " + Colors.Black + "[" + Colors.LightGreen + "<3" + Colors.Black + "]" + Colors.Yellow + player.getName());
  218. return EXIT_SUCCESS;
  219. }
  220. //Check if the player exists
  221. Player other = etc.getServer().matchPlayer(args[0]);
  222. if(other == null)
  223. {
  224. vMinecraftChat.sendMessage(player, player, Colors.Rose
  225. + "The player you specified could not be found");
  226. return EXIT_SUCCESS;
  227. }
  228. //Check if they are a higher rank than the other person
  229. if(player != other && other.hasControlOver(player))
  230. {
  231. vMinecraftChat.sendMessage(player, player, Colors.Rose
  232. + "The player you specified is a higher rank than you.");
  233. return EXIT_SUCCESS;
  234. }
  235. //Check if the prefix is too long
  236. if(vMinecraftChat.msgLength(args[1]) > 60)
  237. {
  238. vMinecraftChat.sendMessage(player, player, Colors.Rose
  239. + "The prefix you entered was too long.");
  240. return EXIT_SUCCESS;
  241. }
  242. if(args.length >= 2 && args[0] != null)
  243. {
  244. other.setPrefix(args[1]);
  245. player.sendMessage(Colors.Rose + "Name color changed");
  246. FlatFileSource ffs = new FlatFileSource();
  247. ffs.modifyPlayer(other);
  248. }
  249. if(args.length >= 3 && args[1] != null)
  250. {
  251. vMinecraftUsers.players.findProfile(other).setTag(args[2]);
  252. player.sendMessage(Colors.LightGreen + "Prefix changed");
  253. }
  254. return EXIT_SUCCESS;
  255. }
  256. //If the player can set their prefix
  257. if(!player.canUseCommand("/prefix")&& vMinecraftSettings.getInstance().prefix()){
  258. return EXIT_FAIL;
  259. }
  260. //Check if there are enough arguments
  261. if(args.length < 1){
  262. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Usage is /prefix [Color Code] <Tag>");
  263. player.sendMessage(Colors.DarkPurple + "Example: /prefix e ^0[^a<3^0]");
  264. vMinecraftChat.sendMessage(player, player, Colors.DarkPurple + "This would produce a name like... " + Colors.Black + "[" + Colors.LightGreen + "<3" + Colors.Black + "]" + Colors.Yellow + player.getName());
  265. return EXIT_SUCCESS;
  266. }
  267. //Name color
  268. if(args.length >= 1 && args[0] != null){
  269. player.setPrefix(args[0]);
  270. player.sendMessage(Colors.Rose + "Name color changed");
  271. }
  272. //Prefix
  273. if(args.length >= 2 && args[1] != null){
  274. //Check if the prefix is too long
  275. if(vMinecraftChat.msgLength(args[1]) > 60)
  276. {
  277. vMinecraftChat.sendMessage(player, player, Colors.Rose
  278. + "The prefix you entered was too long.");
  279. return EXIT_SUCCESS;
  280. }
  281. vMinecraftUsers.players.findProfile(player).setTag(args[1]);
  282. player.sendMessage(Colors.LightGreen + "Prefix changed");
  283. }
  284. return EXIT_SUCCESS;
  285. }
  286. //=====================================================================
  287. //Function: removeTag (/rprefix)
  288. //Input: Player player: The player using the command
  289. // String[] args: Ignored
  290. //Output: int: Exit Code
  291. //Use: Removes your prefix
  292. //=====================================================================
  293. public static int removeTag(Player player, String[] args){
  294. //if the player can suffix others
  295. if(player.canUseCommand("/prefixother")&& vMinecraftSettings.getInstance().prefix()){
  296. if(args.length < 1){
  297. vMinecraftChat.sendMessage(player, player, Colors.Rose
  298. + "Usage is /rprefix [Player]");
  299. return EXIT_SUCCESS;
  300. }
  301. //Check if the player exists
  302. Player other = etc.getServer().matchPlayer(args[0]);
  303. if(other == null)
  304. {
  305. vMinecraftChat.sendMessage(player, player, Colors.Rose
  306. + "The player you specified could not be found");
  307. return EXIT_SUCCESS;
  308. }
  309. //Check if they are a higher rank than the other person
  310. if(player != other && other.hasControlOver(player))
  311. {
  312. vMinecraftChat.sendMessage(player, player, Colors.Rose
  313. + "The player you specified is a higher rank than you.");
  314. return EXIT_SUCCESS;
  315. }
  316. vMinecraftUsers.getProfile(other).setTag("");
  317. player.sendMessage(Colors.LightGreen + "Prefix Removed");
  318. return EXIT_SUCCESS;
  319. }
  320. //Check if the player can set their own prefix.
  321. if(!player.canUseCommand("/prefix")&& vMinecraftSettings.getInstance().prefix()){
  322. return EXIT_FAIL;
  323. }
  324. if(args.length < 1){
  325. vMinecraftChat.sendMessage(player, player, Colors.Rose
  326. + "Usage is /rprefix");
  327. return EXIT_SUCCESS;
  328. }
  329. vMinecraftUsers.getProfile(player).setTag("");
  330. player.sendMessage(Colors.LightGreen + "Prefix Removed");
  331. return EXIT_SUCCESS;
  332. }
  333. //=====================================================================
  334. //Function: nickName (/nick)
  335. //Input: Player player: The player using the command
  336. // String[] args: The color and the prefix
  337. //Output: int: Exit Code
  338. //Use: Changes your name
  339. //=====================================================================
  340. public static int nickName(Player player, String[] args){
  341. //if the player can nickname others
  342. if(player.canUseCommand("/nickother") && vMinecraftSettings.getInstance().nick()){
  343. if(args.length < 2){
  344. vMinecraftChat.sendMessage(player, player, Colors.Rose
  345. + "Usage is /nick [Player] [Name]");
  346. return EXIT_SUCCESS;
  347. }
  348. //Check if the nickname is too long
  349. if(vMinecraftChat.msgLength(args[1]) > 85)
  350. {
  351. vMinecraftChat.sendMessage(player, player, Colors.Rose
  352. + "The nick you entered was too long.");
  353. return EXIT_SUCCESS;
  354. }
  355. //Check if the player exists
  356. Player other = etc.getServer().matchPlayer(args[0]);
  357. if(other == null)
  358. {
  359. vMinecraftChat.sendMessage(player, player, Colors.Rose
  360. + "The player you specified could not be found");
  361. return EXIT_SUCCESS;
  362. }
  363. //Check if they are a higher rank than the other person
  364. if(player != other && other.hasControlOver(player))
  365. {
  366. vMinecraftChat.sendMessage(player, player, Colors.Rose
  367. + "The player you specified is a higher rank than you.");
  368. return EXIT_SUCCESS;
  369. }
  370. vMinecraftUsers.getProfile(other).setNick(args[1]);
  371. player.sendMessage(Colors.LightGreen + "Nickname Set");
  372. return EXIT_SUCCESS;
  373. }
  374. //Make sure they can nickname themselves
  375. if(!player.canUseCommand("/nick")){
  376. return EXIT_FAIL;
  377. }
  378. //Check if the nickname is too long
  379. if(vMinecraftChat.msgLength(args[1]) > 85)
  380. {
  381. vMinecraftChat.sendMessage(player, player, Colors.Rose
  382. + "The nick you entered was too long.");
  383. return EXIT_SUCCESS;
  384. }
  385. if(args.length < 1){
  386. vMinecraftChat.sendMessage(player, player, Colors.Rose
  387. + "Usage is /nick [Name]");
  388. return EXIT_SUCCESS;
  389. }
  390. vMinecraftUsers.getProfile(player).setNick(args[0]);
  391. player.sendMessage(Colors.LightGreen + "Nickname Set");
  392. return EXIT_SUCCESS;
  393. }
  394. //=====================================================================
  395. //Function: removeNick (/rnick)
  396. //Input: Player player: The player using the command
  397. // String[] args: Ignored
  398. //Output: int: Exit Code
  399. //Use: Removes your nick
  400. //=====================================================================
  401. public static int removeNick(Player player, String[] args){
  402. //if the player can nick others
  403. if(player.canUseCommand("/nickother")&& vMinecraftSettings.getInstance().nick()){
  404. if(args.length < 1){
  405. vMinecraftChat.sendMessage(player, player, Colors.Rose
  406. + "Usage is /rnick [Player]");
  407. return EXIT_SUCCESS;
  408. }
  409. //Check if the player exists
  410. Player other = etc.getServer().matchPlayer(args[0]);
  411. if(other == null)
  412. {
  413. vMinecraftChat.sendMessage(player, player, Colors.Rose
  414. + "The player you specified could not be found");
  415. return EXIT_SUCCESS;
  416. }
  417. //Check if they are a higher rank than the other person
  418. if(player != other && other.hasControlOver(player))
  419. {
  420. vMinecraftChat.sendMessage(player, player, Colors.Rose
  421. + "The player you specified is a higher rank than you.");
  422. return EXIT_SUCCESS;
  423. }
  424. vMinecraftUsers.getProfile(other).setNick("");
  425. player.sendMessage(Colors.LightGreen + "Nickname Removed");
  426. return EXIT_SUCCESS;
  427. }
  428. //Check if the player can set their own nick.
  429. if(!player.canUseCommand("/nick")&& vMinecraftSettings.getInstance().nick()){
  430. return EXIT_FAIL;
  431. }
  432. if(args.length < 1){
  433. vMinecraftChat.sendMessage(player, player, Colors.Rose
  434. + "Usage is /rnick");
  435. return EXIT_SUCCESS;
  436. }
  437. vMinecraftUsers.getProfile(player).setNick("");
  438. player.sendMessage(Colors.LightGreen + "Nickname Removed");
  439. return EXIT_SUCCESS;
  440. }
  441. //=====================================================================
  442. //Function: suffix (/suffix)
  443. //Input: Player player: The player using the command
  444. // String[] args: The color and the suffix
  445. //Output: int: Exit Code
  446. //Use: Changes your suffix
  447. //=====================================================================
  448. public static int suffix(Player player, String[] args){
  449. //if the player can suffix others
  450. if(player.canUseCommand("/suffixother")&& vMinecraftSettings.getInstance().suffix()){
  451. if(args.length < 2){
  452. vMinecraftChat.sendMessage(player, player, Colors.Rose
  453. + "Usage is /suffix [Player] [Name]");
  454. return EXIT_SUCCESS;
  455. }
  456. //Check if the suffix is too long
  457. if(vMinecraftChat.msgLength(args[1]) > 60)
  458. {
  459. vMinecraftChat.sendMessage(player, player, Colors.Rose
  460. + "The suffix you entered was too long.");
  461. return EXIT_SUCCESS;
  462. }
  463. //Check if the player exists
  464. Player other = etc.getServer().matchPlayer(args[0]);
  465. if(other == null)
  466. {
  467. vMinecraftChat.sendMessage(player, player, Colors.Rose
  468. + "The player you specified could not be found");
  469. return EXIT_SUCCESS;
  470. }
  471. //Check if they are a higher rank than the other person
  472. if(player != other && other.hasControlOver(player))
  473. {
  474. vMinecraftChat.sendMessage(player, player, Colors.Rose
  475. + "The player you specified is a higher rank than you.");
  476. return EXIT_SUCCESS;
  477. }
  478. vMinecraftUsers.getProfile(other).setSuffix(args[1]);
  479. player.sendMessage(Colors.LightGreen + "Suffix Set");
  480. return EXIT_SUCCESS;
  481. }
  482. //Check if the player can set their own suffix.
  483. if(!player.canUseCommand("/suffix")&& vMinecraftSettings.getInstance().suffix()){
  484. return EXIT_FAIL;
  485. }
  486. if(args.length < 1){
  487. vMinecraftChat.sendMessage(player, player, Colors.Rose
  488. + "Usage is /suffix [Suffix]");
  489. return EXIT_SUCCESS;
  490. }
  491. //Check if the suffix is too long
  492. if(vMinecraftChat.msgLength(args[1]) > 60)
  493. {
  494. vMinecraftChat.sendMessage(player, player, Colors.Rose
  495. + "The suffix you entered was too long.");
  496. return EXIT_SUCCESS;
  497. }
  498. vMinecraftUsers.getProfile(player).setSuffix(args[0]);
  499. player.sendMessage(Colors.LightGreen + "Suffix Set");
  500. return EXIT_SUCCESS;
  501. }
  502. //=====================================================================
  503. //Function: removeSuffix (/rsuffix)
  504. //Input: Player player: The player using the command
  505. // String[] args: Ignored
  506. //Output: int: Exit Code
  507. //Use: Removes your suffix
  508. //=====================================================================
  509. public static int removeSuffix(Player player, String[] args){
  510. //if the player can suffix others
  511. if(player.canUseCommand("/suffixother")&& vMinecraftSettings.getInstance().suffix()){
  512. if(args.length < 1){
  513. vMinecraftChat.sendMessage(player, player, Colors.Rose
  514. + "Usage is /rsuffix [Player]");
  515. return EXIT_SUCCESS;
  516. }
  517. //Check if the player exists
  518. Player other = etc.getServer().matchPlayer(args[0]);
  519. if(other == null)
  520. {
  521. vMinecraftChat.sendMessage(player, player, Colors.Rose
  522. + "The player you specified could not be found");
  523. return EXIT_SUCCESS;
  524. }
  525. //Check if they are a higher rank than the other person
  526. if(player != other && other.hasControlOver(player))
  527. {
  528. vMinecraftChat.sendMessage(player, player, Colors.Rose
  529. + "The player you specified is a higher rank than you.");
  530. return EXIT_SUCCESS;
  531. }
  532. vMinecraftUsers.getProfile(other).setSuffix("");
  533. player.sendMessage(Colors.LightGreen + "Suffix Removed");
  534. return EXIT_SUCCESS;
  535. }
  536. //Check if the player can set their own suffix.
  537. if(!player.canUseCommand("/suffix")&& vMinecraftSettings.getInstance().suffix()){
  538. return EXIT_FAIL;
  539. }
  540. if(args.length < 1){
  541. vMinecraftChat.sendMessage(player, player, Colors.Rose
  542. + "Usage is /rsuffix");
  543. return EXIT_SUCCESS;
  544. }
  545. vMinecraftUsers.getProfile(player).setSuffix("");
  546. player.sendMessage(Colors.LightGreen + "Suffix Removed");
  547. return EXIT_SUCCESS;
  548. }
  549. //=====================================================================
  550. //Function: colors (/colors)
  551. //Input: Player player: The player using the command
  552. //Output: int: Exit Code
  553. //Use: Displays a list of all colors and color codes
  554. //=====================================================================
  555. public static int colors(Player player, String[] args){
  556. if(args.length > 0&& vMinecraftSettings.getInstance().colors())
  557. {
  558. vMinecraftUsers.getProfile(player).setColor(args[0]);
  559. vMinecraftChat.sendMessage(player, player, "^" + args[0].charAt(0)
  560. + "Default chat color set.");
  561. } else {
  562. player.sendMessage(Colors.Rose + "You use these color codes like in quake or MW2.");
  563. player.sendMessage(Colors.Rose + "^4 would make text " + Colors.Red
  564. + "red" + Colors.Rose + ", ^a would make it " + Colors.LightGreen
  565. + "light green" + Colors.Rose + ".");
  566. vMinecraftChat.sendMessage(player, player,
  567. Colors.Black + "0"
  568. + Colors.Navy + "1"
  569. + Colors.Green + "2"
  570. + Colors.Blue + "3"
  571. + Colors.Red + "4"
  572. + Colors.Purple + "5"
  573. + Colors.Gold + "6"
  574. + Colors.LightGray + "7"
  575. + Colors.Gray + "8"
  576. + Colors.DarkPurple + "9"
  577. + Colors.LightGreen + "A"
  578. + Colors.LightBlue + "B"
  579. + Colors.Rose + "C"
  580. + Colors.LightPurple + "D"
  581. + Colors.Yellow + "E"
  582. + Colors.White + "F"
  583. + "^r" + "[R]ainbow");
  584. }
  585. return EXIT_SUCCESS;
  586. }
  587. //=====================================================================
  588. //Function: me (/me)
  589. //Input: Player player: The player using the command
  590. // String[] args: Will contain the message the player sends
  591. //Output: int: Exit Code
  592. //Use: The player uses this to emote, but now its colorful.
  593. //=====================================================================
  594. public static int me(Player player, String[] args)
  595. {
  596. String str = etc.combineSplit(0, args, " ");
  597. if (args.length < 1) return EXIT_FAIL;
  598. vMinecraftChat.emote(player, str);
  599. return EXIT_SUCCESS;
  600. }
  601. //=====================================================================
  602. //Function: message (/msg, /w, /whisper)
  603. //Input: Player player: The player using the command
  604. // String[] args: Will contain the target player name and
  605. // message the player sends
  606. //Output: int: Exit Code
  607. //Use: Send a message to a player
  608. //=====================================================================
  609. public static int message(Player player, String[] args)
  610. {
  611. //Make sure a player is specified
  612. if (args.length < 2) {
  613. vMinecraftChat.sendMessage(player, player, Colors.Rose
  614. + "Usage is /msg [player] [message]");
  615. return EXIT_SUCCESS;
  616. }
  617. //Make sure the player exists
  618. Player toPlayer = etc.getServer().matchPlayer(args[0]);
  619. if (toPlayer == null || args.length < 1) {
  620. vMinecraftChat.sendMessage(player, player, Colors.Rose
  621. + "No player by the name of " + args[0] + " could be found.");
  622. return EXIT_SUCCESS;
  623. }
  624. String msg = etc.combineSplit(1, args, " ");
  625. //Send the message to the targeted player and the sender
  626. vMinecraftChat.sendMessage(player, toPlayer,
  627. Colors.LightGreen + "[From:" + vMinecraftChat.getName(player)
  628. + Colors.LightGreen + "] " + msg);
  629. vMinecraftChat.sendMessage(player, player,
  630. Colors.LightGreen + "[To:" + vMinecraftChat.getName(toPlayer)
  631. + Colors.LightGreen + "] " + msg);
  632. //Set the last massager for each player
  633. vMinecraftUsers.getProfile(player).setMessage(toPlayer);
  634. vMinecraftUsers.getProfile(toPlayer).setMessage(player);
  635. //Display the message to the log
  636. log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName()
  637. + ": " + msg);
  638. return EXIT_SUCCESS;
  639. }
  640. //=====================================================================
  641. //Function: reply (/r, /reply)
  642. //Input: Player player: The player using the command
  643. // String[] args: Will contain the message the player sends
  644. //Output: int: Exit Code
  645. //Use: Send a message to a player
  646. //=====================================================================
  647. public static int reply(Player player, String[] args)
  648. {
  649. //If the profile exists for the player
  650. if(vMinecraftUsers.getProfile(player) == null ) {
  651. vMinecraftChat.sendMessage(player, player,
  652. Colors.Rose + "The person you last message has logged off");
  653. return EXIT_SUCCESS;
  654. }
  655. //Make sure a message is specified
  656. if (args.length < 1) {
  657. vMinecraftChat.sendMessage(player, player,
  658. Colors.Rose + "Usage is /reply [Message]");
  659. return EXIT_SUCCESS;
  660. }
  661. //Make sure the player they're talking to is online
  662. Player toPlayer = vMinecraftUsers.getProfile(player).getMessage();
  663. if (toPlayer == null) {
  664. vMinecraftChat.sendMessage(player, player,
  665. Colors.Rose + "The person you last message has logged off");
  666. return EXIT_SUCCESS;
  667. }
  668. String msg = etc.combineSplit(0, args, " ");
  669. //Send the message to the targeted player and the sender
  670. vMinecraftChat.sendMessage(player, toPlayer,
  671. Colors.LightGreen + "[From:" + vMinecraftChat.getName(player)
  672. + Colors.LightGreen + "] " + msg);
  673. vMinecraftChat.sendMessage(player, player,
  674. Colors.LightGreen + "[To:" + vMinecraftChat.getName(toPlayer)
  675. + Colors.LightGreen + "] " + msg);
  676. //Set the last messager for each player
  677. vMinecraftUsers.getProfile(player).setMessage(toPlayer);
  678. vMinecraftUsers.getProfile(toPlayer).setMessage(player);
  679. //Display the message to the log
  680. log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName()
  681. + ": " + msg);
  682. return EXIT_SUCCESS;
  683. }
  684. //=====================================================================
  685. //Function: addIgnored (/ignore)
  686. //Input: Player player: The player using the command
  687. // String[] args: The name of the player to ignore
  688. //Output: int: Exit Code
  689. //Use: Adds a player to the ignore list
  690. //=====================================================================
  691. public static int addIgnored(Player player, String[] args)
  692. {
  693. //Make sure the player gave you a user to ignore
  694. if(args.length < 1 && vMinecraftSettings.getInstance().ignore())
  695. {
  696. vMinecraftChat.sendMessage(player, player,
  697. Colors.Rose + "Usage: /ignore [Player]");
  698. return EXIT_SUCCESS;
  699. }
  700. //Find the player and make sure they exist
  701. Player ignore = etc.getServer().matchPlayer(args[0]);
  702. if(ignore == null&& vMinecraftSettings.getInstance().ignore())
  703. {
  704. vMinecraftChat.sendMessage(player, player, Colors.Rose
  705. + "The person you tried to ignore is not logged in.");
  706. return EXIT_SUCCESS;
  707. }
  708. if(!player.hasControlOver(ignore)&& vMinecraftSettings.getInstance().ignore())
  709. {
  710. vMinecraftChat.sendMessage(player, player, Colors.Rose
  711. + "You can't ignore someone a higher rank than you.");
  712. return EXIT_SUCCESS;
  713. }
  714. //Don't let the player ignore themselves
  715. if(ignore.getName().equalsIgnoreCase(player.getName()))
  716. {
  717. vMinecraftChat.sendMessage(player, player,
  718. Colors.Rose + "You cannot ignore yourself");
  719. return EXIT_SUCCESS;
  720. }
  721. //Attempt to ignore the player and report accordingly
  722. if(vMinecraftUsers.getProfile(player).addIgnore(ignore))
  723. vMinecraftChat.sendMessage(player, player, Colors.Rose
  724. + ignore.getName() + " has been successfuly ignored.");
  725. else
  726. vMinecraftChat.sendMessage(player, player, Colors.Rose
  727. + "You are already ignoring " + ignore.getName());
  728. return EXIT_SUCCESS;
  729. }
  730. //=====================================================================
  731. //Function: removeIgnored (/unignore)
  732. //Input: Player player: The player using the command
  733. // String[] args: The name of the player to stop ignoring
  734. //Output: int: Exit Code
  735. //Use: Removes a player from the ignore list
  736. //=====================================================================
  737. public static int removeIgnored(Player player, String[] args)
  738. {
  739. //Make sure the player gave you a user to ignore
  740. if(args.length < 1&& vMinecraftSettings.getInstance().ignore())
  741. {
  742. vMinecraftChat.sendMessage(player, player,
  743. Colors.Rose + "Usage: /unignore [Player]");
  744. return EXIT_SUCCESS;
  745. }
  746. //Find the player and make sure they exist
  747. Player ignore = etc.getServer().matchPlayer(args[0]);
  748. if(ignore == null&& vMinecraftSettings.getInstance().ignore())
  749. {
  750. vMinecraftChat.sendMessage(player, player,
  751. Colors.Rose + "The person you tried to unignore is not logged in.");
  752. return EXIT_SUCCESS;
  753. }
  754. //Attempt to ignore the player and report accordingly
  755. if(vMinecraftUsers.getProfile(player).removeIgnore(ignore))
  756. vMinecraftChat.sendMessage(player, player,
  757. Colors.Rose + ignore.getName()+ " has been successfuly " +
  758. "unignored.");
  759. else
  760. vMinecraftChat.sendMessage(player, player,
  761. Colors.Rose + "You are not currently ignoring " + ignore.getName());
  762. return EXIT_SUCCESS;
  763. }
  764. //=====================================================================
  765. //Function: ignoreList (/ignorelist)
  766. //Input: Player player: The player using the command
  767. // String[] args: Ignored
  768. //Output: int: Exit Code
  769. //Use: Lists the player you have ignored
  770. //=====================================================================
  771. public static int ignoreList(Player player, String[] args)
  772. {
  773. if (vMinecraftSettings.getInstance().ignore()){
  774. //Get the ignore list
  775. String[] list = vMinecraftUsers.getProfile(player).listIgnore();
  776. //Find the last page number
  777. int lastPage = (int)list.length / 5;
  778. if((int)list.length % 5 > 0)
  779. lastPage++;
  780. //Find the page number the player wants displayed
  781. int page = 0;
  782. if(args.length > 0 && Integer.valueOf(args[0]) > 0
  783. && Integer.valueOf(args[0]) <= lastPage)
  784. page = Integer.valueOf(args[0]) - 1;
  785. //Display the header
  786. vMinecraftChat.sendMessage(player, player,
  787. Colors.Rose + "Ignore List [" + page + "/"
  788. + lastPage + "]");
  789. //Display up to 5 people
  790. for(int i = 0; i < 5 && i + (page * 5) < list.length; i++)
  791. vMinecraftChat.sendMessage(player, player,
  792. Colors.Rose + list[i+ (page * 5)]);
  793. return EXIT_SUCCESS;
  794. }
  795. return EXIT_FAIL;
  796. }
  797. //=====================================================================
  798. //Function: adminChatToggle (/a)
  799. //Input: Player player: The player using the command
  800. // String[] args: Ignored
  801. //Output: int: Exit Code
  802. //Use: Toggles the player into admin chat. Every message they
  803. // send will be piped to admin chat.
  804. //=====================================================================
  805. public static int adminChatToggle(Player player, String[] args)
  806. {
  807. //Make sure the user has access to the command
  808. if(!player.canUseCommand("/a")) return EXIT_FAIL;
  809. if(!vMinecraftSettings.getInstance().adminChatToggle()) return EXIT_FAIL;
  810. //If the player is already toggled for admin chat, remove them
  811. if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) {
  812. player.sendMessage(Colors.Red + "Admin Chat Toggle = off");
  813. vMinecraftSettings.getInstance().removeAdminToggled(player.getName());
  814. //Otherwise include them
  815. } else {
  816. player.sendMessage(Colors.Blue + "Admin Chat Toggled on");
  817. vMinecraftSettings.getInstance().addAdminToggled(player.getName());
  818. }
  819. return EXIT_SUCCESS;
  820. }
  821. //=====================================================================
  822. //Function: heal (/heal)
  823. //Input: Player player: The player using the command
  824. // String[] args: The arguments for the command. Should be a
  825. // player name or blank
  826. //Output: int: Exit Code
  827. //Use: Heals yourself or a specified player.
  828. //=====================================================================
  829. public static int heal(Player player, String[] args)
  830. {
  831. //Make sure the user has access to the command
  832. if(!player.canUseCommand("/heal")) return EXIT_FAIL;
  833. if(!vMinecraftSettings.getInstance().cmdHeal()) return EXIT_FAIL;
  834. //If a target wasn't specified, heal the user.
  835. if (args.length < 1){
  836. player.setHealth(20);
  837. player.sendMessage("Your health is restored");
  838. return EXIT_SUCCESS;
  839. }
  840. //If a target was specified, try to find them and then heal them
  841. //Otherwise report the error
  842. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  843. if (playerTarget == null){
  844. player.sendMessage(Colors.Rose
  845. + "Couldn't find that player");
  846. return EXIT_SUCCESS;
  847. }
  848. playerTarget.setHealth(20);
  849. player.sendMessage(Colors.Blue + "You have healed "
  850. + vMinecraftChat.getName(playerTarget));
  851. playerTarget.sendMessage(Colors.Blue
  852. + "You have been healed by "
  853. + vMinecraftChat.getName(player));
  854. return EXIT_SUCCESS;
  855. }
  856. //=====================================================================
  857. //Function: suicide (/suicide, /wrists)
  858. //Input: Player player: The player using the command
  859. // String[] args: Ignored
  860. //Output: int: Exit Code
  861. //Use: Kills yourself
  862. //=====================================================================
  863. public static int suicide(Player player, String[] args)
  864. {
  865. //Make sure the user has access to the command
  866. if(!player.canUseCommand("/suicide")) return EXIT_FAIL;
  867. if(!vMinecraftSettings.getInstance().cmdSuicide()) return EXIT_FAIL;
  868. //Set your health to 0. Not much to it.
  869. player.setHealth(0);
  870. return EXIT_SUCCESS;
  871. }
  872. //=====================================================================
  873. //Function: teleport (/tp)
  874. //Input: Player player: The player using the command
  875. // String[] args: The arguments for the command. Should be a
  876. // player name
  877. //Output: int: Exit Code
  878. //Use: Teleports the user to another player
  879. //=====================================================================
  880. public static int teleport(Player player, String[] args)
  881. {
  882. //Make sure the user has access to the command
  883. if(!player.canUseCommand("/tp")) return EXIT_FAIL;
  884. //Get if the command is enabled
  885. if(!vMinecraftSettings.getInstance().cmdTp())return EXIT_FAIL;
  886. //Make sure a player has been specified and return an error if not
  887. if (args.length < 1) {
  888. player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
  889. return EXIT_SUCCESS;
  890. }
  891. //Find the player by name
  892. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  893. //Target player isn't found
  894. if(playerTarget == null)
  895. player.sendMessage(Colors.Rose + "Can't find user "
  896. + args[0] + ".");
  897. //If it's you, return witty message
  898. else if (player.getName().equalsIgnoreCase(args[0]))
  899. player.sendMessage(Colors.Rose + "You're already here!");
  900. //If the player is higher rank than you, inform the user
  901. else if (!player.hasControlOver(playerTarget))
  902. player.sendMessage(Colors.Red +
  903. "That player has higher permissions than you.");
  904. //If the player exists transport the user to the player
  905. else {
  906. vMinecraftChat.gmsg( player, vMinecraftChat.getName(player)
  907. + Colors.LightBlue + " has teleported to "
  908. + vMinecraftChat.getName(playerTarget));
  909. log.log(Level.INFO, player.getName() + " teleported to " +
  910. playerTarget.getName());
  911. player.teleportTo(playerTarget);
  912. }
  913. return EXIT_SUCCESS;
  914. }
  915. //=====================================================================
  916. //Function: masstp (/masstp)
  917. //Input: Player player: The player using the command
  918. // String[] args: Should be empty or is ignored
  919. //Output: int: Exit Code
  920. //Use: Teleports all players to the user
  921. //=====================================================================
  922. public static int masstp(Player player, String[] args)
  923. {
  924. //Make sure the user has access to the command
  925. if(!player.canUseCommand("/masstp")) return EXIT_FAIL;
  926. //If the command is enabled
  927. if(!vMinecraftSettings.getInstance().cmdMasstp())return EXIT_FAIL;
  928. //Go through all players and move them to the user
  929. for (Player p : etc.getServer().getPlayerList()) {
  930. if (!p.hasControlOver(player)) {
  931. p.teleportTo(player);
  932. }
  933. }
  934. //Inform the user that the command has executed successfully
  935. player.sendMessage(Colors.Blue + "Summoning successful.");
  936. return EXIT_SUCCESS;
  937. }
  938. //=====================================================================
  939. //Function: tphere (/tphere)
  940. //Input: Player player: The player using the command
  941. // String[] args: The arguments for the command. Should be a
  942. // player name
  943. //Output: int: Exit Code
  944. //Use: Teleports the user to another player
  945. //=====================================================================
  946. public static int tphere(Player player, String[] args)
  947. {
  948. //Make sure the user has access to the command
  949. if(!player.canUseCommand("/tphere")) return EXIT_FAIL;
  950. //Check if the command is enabled.
  951. if (!vMinecraftSettings.getInstance().cmdTphere())return EXIT_FAIL;
  952. //Make sure a player is specified
  953. if (args.length < 1) {
  954. player.sendMessage(Colors.Rose + "Correct usage" +
  955. " is: /tphere [player]");
  956. return EXIT_SUCCESS;
  957. }
  958. //Get the player by name
  959. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  960. //If the target doesn't exist
  961. if(playerTarget == null)
  962. player.sendMessage(Colors.Rose + "Can't find user "
  963. + args[0] + ".");
  964. //If the player has a higher rank than the user, return error
  965. else if (!player.hasControlOver(playerTarget))
  966. player.sendMessage(Colors.Red + "That player has higher" +
  967. " permissions than you.");
  968. //If the user teleports themselves, mock them
  969. else if (player.getName().equalsIgnoreCase(args[0]))
  970. player.sendMessage(Colors.Rose + "Wow look at that! You" +
  971. " teleported yourself to yourself!");
  972. //If the target exists, teleport them to the user
  973. else {
  974. log.log(Level.INFO, player.getName() + " teleported "
  975. + player.getName() + " to their self.");
  976. playerTarget.teleportTo(player);
  977. }
  978. return EXIT_SUCCESS;
  979. }
  980. //=====================================================================
  981. //Function: reload (/reload)
  982. //Input: Player player: The player using the command
  983. // String[] args: Ignored
  984. //Output: int: Exit Code
  985. //Use: Reloads the settings for vMinecraft
  986. //=====================================================================
  987. public static int reload(Player player, String[] args)
  988. {
  989. //Make sure the user has access to the command
  990. if(!player.canUseCommand("/reload")) return EXIT_FAIL;
  991. vMinecraftSettings.getInstance().loadSettings();
  992. return EXIT_FAIL;
  993. }
  994. //=====================================================================
  995. //Function: rules (/rules)
  996. //Input: Player player: The player using the command
  997. // String[] args: Ignored
  998. //Output: int: Exit Code
  999. //Use: Lists the rules
  1000. //=====================================================================
  1001. public static int rules(Player player, String[] args)
  1002. {
  1003. //If the rules exist
  1004. if(!vMinecraftSettings.getInstance().cmdRules()
  1005. && vMinecraftSettings.getInstance().getRules().length > 0
  1006. && !vMinecraftSettings.getInstance().getRules()[0].isEmpty()) {
  1007. return EXIT_FAIL;
  1008. }
  1009. //Apply QuakeCode Colors to the rules
  1010. String[] rules = vMinecraftChat.applyColors(
  1011. vMinecraftSettings.getInstance().getRules());
  1012. //Display them
  1013. for (String str : rules ) {
  1014. if(!str.isEmpty())
  1015. player.sendMessage(Colors.Blue + str);
  1016. else
  1017. player.sendMessage(Colors.Blue
  1018. + "!!!The Rules Have Not Been Set!!!");
  1019. }
  1020. return EXIT_SUCCESS;
  1021. }
  1022. //=====================================================================
  1023. //Function: fabulous (/fabulous)
  1024. //Input: Player player: The player using the command
  1025. // String[] args: The message to apply the effect to
  1026. //Output: int: Exit Code
  1027. //Use: Makes the text rainbow colored
  1028. //=====================================================================
  1029. public static int fabulous(Player player, String[] args)
  1030. {
  1031. //If the command is enabled
  1032. if(!vMinecraftSettings.getInstance().cmdFabulous()) return EXIT_FAIL;
  1033. //Make sure a message has been specified
  1034. if (args.length < 1) {
  1035. player.sendMessage(Colors.Rose + "Usage /fabulous [Message]");
  1036. return EXIT_SUCCESS;
  1037. }
  1038. //Format the name
  1039. String playerName = Colors.White + "<"
  1040. + vMinecraftChat.getName(player) + Colors.White +"> ";
  1041. //Merge the message again
  1042. String str = etc.combineSplit(0, args, " ");
  1043. //Output for server
  1044. log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
  1045. //Prepend the player name and cut into lines.
  1046. vMinecraftChat.gmsg(player, playerName + vMinecraftChat.rainbow(str));
  1047. return EXIT_SUCCESS;
  1048. }
  1049. //=====================================================================
  1050. //Function: whois (/whois)
  1051. //Input: Player player: The player using the command
  1052. // String[] args: The player to find info on
  1053. //Output: int: Exit Code
  1054. //Use: Displays information about the player specified
  1055. //=====================================================================
  1056. public static int whois(Player player, String[] args)
  1057. {
  1058. //Make sure the user has access to the command
  1059. if(!player.canUseCommand("/whois")) return EXIT_FAIL;
  1060. //If the command is enabled
  1061. if (!vMinecraftSettings.getInstance().cmdWhoIs()) return EXIT_FAIL;
  1062. //If a player is specified
  1063. if (args.length < 1)
  1064. {
  1065. player.sendMessage(Colors.Rose + "Usage is /whois [player]");
  1066. return EXIT_SUCCESS;
  1067. }
  1068. //Get the player by name
  1069. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  1070. //If the player exists
  1071. if (playerTarget == null){
  1072. player.sendMessage(Colors.Rose+"Player not found.");
  1073. return EXIT_SUCCESS;
  1074. }
  1075. //Displaying the information
  1076. player.sendMessage(Colors.Blue + "Whois results for " +
  1077. vMinecraftChat.getName(playerTarget));
  1078. //Group
  1079. for(String group: playerTarget.getGroups())
  1080. player.sendMessage(Colors.Blue + "Groups: " + group);
  1081. //Only let admins see this info
  1082. if(player.isAdmin())
  1083. {
  1084. //Admin
  1085. player.sendMessage(Colors.Blue+"Admin: " +
  1086. String.valueOf(playerTarget.isAdmin()));
  1087. //IP
  1088. player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP());
  1089. //Restrictions
  1090. player.sendMessage(Colors.Blue+"Can ignore restrictions: " +
  1091. String.valueOf(playerTarget.canIgnoreRestrictions()));
  1092. }
  1093. return EXIT_SUCCESS;
  1094. }
  1095. //=====================================================================
  1096. //Function: who (/who)
  1097. //Input: Player player: The player using the command
  1098. // String[] args: Ignored
  1099. //Output: int: Exit Code
  1100. //Use: Displays the connected players
  1101. //=====================================================================
  1102. public static int who(Player player, String[] args)
  1103. {
  1104. //If the command is enabled
  1105. if (!vMinecraftSettings.getInstance().cmdWho()) return EXIT_FAIL;
  1106. //Loop through all players counting them and adding to the list
  1107. int count=0;
  1108. String tempList = "";
  1109. for( Player p : etc.getServer().getPlayerList())
  1110. {
  1111. if(p != null){
  1112. if(count == 0)
  1113. tempList += vMinecraftChat.getName(p);
  1114. else
  1115. tempList += Colors.White + ", " + vMinecraftChat.getName(p);
  1116. count++;
  1117. }
  1118. }
  1119. //Get the max players from the config
  1120. PropertiesFile server = new PropertiesFile("server.properties");
  1121. try {
  1122. server.load();
  1123. } catch (IOException e) {
  1124. e.printStackTrace();
  1125. }
  1126. int maxPlayers = server.getInt("max-players");
  1127. //Output the player list
  1128. vMinecraftChat.sendMessage(player, player, Colors.Rose + "Player List ("
  1129. + count + "/" + maxPlayers +"): " + tempList);
  1130. return EXIT_SUCCESS;
  1131. }
  1132. //=====================================================================
  1133. //Function: say (/say)
  1134. //Input: Player player: The player using the command
  1135. // String[] args: The message to apply the effect to
  1136. //Output: int: Exit Code
  1137. //Use: Announces the message to all players
  1138. //=====================================================================
  1139. public static int say(Player player, String[] args)
  1140. {
  1141. //Make sure the user has access to the command
  1142. if(!player.canUseCommand("/say")) return EXIT_FAIL;
  1143. //Check if the command is enabled
  1144. if (!vMinecraftSettings.getInstance().cmdSay()) return EXIT_FAIL;
  1145. //Make sure a message is supplied or output an error
  1146. if (args.length < 1) {
  1147. player.sendMessage(Colors.Rose + "Usage is /say [message]");
  1148. }
  1149. //Display the message globally
  1150. vMinecraftChat.gmsg(player, Colors.Yellow
  1151. + etc.combineSplit(0, args, " "));
  1152. return EXIT_SUCCESS;
  1153. }
  1154. //=====================================================================
  1155. //Function: slay (/slay)
  1156. //Input: Player player: The player using the command
  1157. // String[] args: The target for the command
  1158. //Output: int: Exit Code
  1159. //Use: Kill the target player
  1160. //=====================================================================
  1161. public static int slay(Player player, String[] args)
  1162. {
  1163. //Make sure the user has access to the command
  1164. if(!player.canUseCommand("/slay")) return EXIT_FAIL;
  1165. //Check if the command is enabled
  1166. if(!vMinecraftSettings.getInstance().cmdEzModo()) return EXIT_FAIL;
  1167. //Get the player by name
  1168. Player playerTarget = etc.getServer().matchPlayer(args[0]);
  1169. //If the player doesn't exist don't run
  1170. if(playerTarget == null)
  1171. {
  1172. player.sendMessage(Colors.Rose + "Usage is /slay [Player]");
  1173. return EXIT_SUCCESS;
  1174. }
  1175. //If the player isn't invulnerable kill them
  1176. if (vMinecraftSettings.getInstance()
  1177. .isEzModo(playerTarget.getName())) {
  1178. player.sendMessage(Colors.Rose + "That player is currently in" +
  1179. " ezmodo! Hahahaha");
  1180. }
  1181. playerTarget.setHealth(0);
  1182. vMinecraftChat.gmsg(player, vMinecraftChat.getName(player)
  1183. + Colors.LightBlue + " has slain "
  1184. + vMinecraftChat.getName(playerTarget));
  1185. //Otherwise output error to the user
  1186. return EXIT_SUCCESS;
  1187. }
  1188. //=====================================================================
  1189. //Function: invuln (/ezmodo)
  1190. //Input: Player player: The player using the command
  1191. // String[] args: The target for the command
  1192. //Output: int: Exit Code
  1193. //Use: Kill the target player
  1194. //=====================================================================
  1195. public static int invuln(Player player, String[] args)
  1196. {
  1197. //Make sure the user has access to the command
  1198. if(!player.canUseCommand("/ezmodo")) return EXIT_FAIL;
  1199. //If the command is enabled
  1200. if (!vMinecraftSettings.getInstance().cmdEzModo()) return EXIT_FAIL;
  1201. //If the player is already invulnerable, turn ezmodo off.
  1202. if (vMinecraftSettings.getInstance().isEzModo(player.getName())) {
  1203. player.sendMessage(Colors.Red + "ezmodo = off");
  1204. vMinecraftSettings.getInstance().removeEzModo(player.getName());
  1205. //Otherwise make them invulnerable
  1206. } else {
  1207. player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
  1208. player.sendMessage(Colors.Rose + "kimo-i");
  1209. player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru" +
  1210. " no wa shougakusei made dayo ne");
  1211. player.sendMessage(Colors.Red + "**Laughter**");
  1212. vMinecraftSettings.getInstance().addEzModo(player.getName());
  1213. }
  1214. return EXIT_SUCCESS;
  1215. }
  1216. //=====================================================================
  1217. //Function: ezlist (/ezlist)
  1218. //Input: Player player: The player using the command
  1219. // String[] args: Ignored
  1220. //Output: int: Exit Code
  1221. //Use: List all invulnerable players
  1222. //=====================================================================
  1223. public static int ezlist(Player player, String[] args)
  1224. {
  1225. //Make sure the user has access to the command
  1226. if(!player.canUseCommand("/ezmodo")) return EXIT_FAIL;
  1227. //If the feature is enabled list the players
  1228. if(!vMinecraftSettings.getInstance().cmdEzModo()) return EXIT_FAIL;
  1229. player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList());
  1230. return EXIT_SUCCESS;
  1231. }
  1232. //=====================================================================
  1233. //Function: modify (/modify)
  1234. //Input: Player player: The player using the command
  1235. // String[] args: Player, Command, Arguments
  1236. //Output: int: Exit Code
  1237. //Use: Display help for modifying features of players
  1238. //=====================================================================
  1239. public static int modify(Player player, String[] args)
  1240. {
  1241. if(player.canUseCommand("/prefixother"))
  1242. vMinecraftChat.sendMessage(player, player, "/prefix [Player]" +
  1243. " [Color] (Tag) - Set a players prefix and tag.");
  1244. else if(player.canUseCommand("/prefix"))
  1245. vMinecraftChat.sendMessage(player, player, "/prefix [Color]" +
  1246. " (Tag) - Set your prefix and tag.");
  1247. if(player.canUseCommand("/nickother"))
  1248. vMinecraftChat.sendMessage(player, player, "/nick [Player]" +
  1249. " [Nickname] - Set a players nickname.");
  1250. else if(player.canUseCommand("/nick"))
  1251. vMinecraftChat.sendMessage(player, player, "/nick [Nick]" +
  1252. " - Set your nickname.");
  1253. if(player.canUseCommand("/suffixother"))
  1254. vMinecraftChat.sendMessage(player, player, "/suffix [Player]" +
  1255. " [Suffix] - Set a players suffix.");
  1256. else if(player.canUseCommand("/suffix"))
  1257. vMinecraftChat.sendMessage(player, player, "/suffix [Suffix]" +
  1258. " - Set your suffix.");
  1259. if(player.canUseCommand("/suffixother"))
  1260. vMinecraftChat.sendMessage(player, player, "/suffix [Player]" +
  1261. " [Suffix] - Set a players suffix.");
  1262. else if(player.canUseCommand("/suffix"))
  1263. vMinecraftChat.sendMessage(player, player, "/suffix [Suffix]" +
  1264. " - Set your suffix.");
  1265. if(player.canUseCommand("/vranks"))
  1266. {
  1267. vMinecraftChat.sendMessage(player, player, "/promote [Player]" +
  1268. " - Promotes a player one rank");
  1269. vMinecraftChat.sendMessage(player, player, "/demote [Player]" +
  1270. " - Demotes a player one rank");
  1271. }
  1272. return EXIT_SUCCESS;
  1273. }
  1274. //=====================================================================
  1275. //Function: promote (/promote)
  1276. //Input: Player player: The player using the command
  1277. // String[] args: Player to promote
  1278. //Output: int: Exit Code
  1279. //Use: Attempt to promote a player one rank
  1280. //=====================================================================
  1281. public static int promote(Player player, String[] args)
  1282. {
  1283. //Check if they can promote
  1284. if(!player.canUseCommand("/promote")) return EXIT_FAIL;
  1285. //Check if they specified a player
  1286. if(args.length < 1)
  1287. {
  1288. vMinecraftChat.sendMessage(player, Colors.Rose + "Usage: /promote [Player] (Rank)");
  1289. return EXIT_SUCCESS;
  1290. }
  1291. //Try to find the player
  1292. Player target = etc.getServer().matchPlayer(args[0]);
  1293. if(target == null)
  1294. {
  1295. vMinecraftChat.sendMessage(player, Colors.Rose + "The player specified could not be found");
  1296. return EXIT_SUCCESS;
  1297. }
  1298. //Get the list of ranks
  1299. String[] ranks = vMinecraftSettings.getInstance().getRanks();
  1300. //Find the targets current rank number
  1301. String[] tarGroups = target.getGroups();
  1302. int tarRank = 0,
  1303. tarPos = 0;
  1304. boolean leave = false;
  1305. for(String rank : ranks)
  1306. {
  1307. for(String group : tarGroups)
  1308. {
  1309. if(rank.equalsIgnoreCase(group))
  1310. {
  1311. leave = true;
  1312. break;
  1313. }
  1314. else
  1315. tarPos++;
  1316. }
  1317. if(leave)
  1318. break;
  1319. tarRank++;
  1320. tarPos = 0;
  1321. }
  1322. if(!leave)
  1323. {
  1324. tarRank = 0;
  1325. tarPos = 0;
  1326. if(tarGroups != null)
  1327. {
  1328. String[] tempGroups = new String[tarGroups.length + 1];
  1329. System.arraycopy(tarGroups, 0, tempGroups, 1, tarGroups.length);
  1330. tarGroups = tempGroups;
  1331. } else
  1332. tarGroups = new String[1];
  1333. }
  1334. leave = false;
  1335. //Get the player's rank
  1336. String[] myGroups = player.getGroups();
  1337. int myRank = 0;
  1338. for(String rank : ranks)
  1339. {
  1340. for(String group : myGroups)
  1341. if(rank.equalsIgnoreCase(group))
  1342. {
  1343. leave = true;
  1344. break;
  1345. }
  1346. if(leave)
  1347. break;
  1348. myRank++;
  1349. }
  1350. if(!leave)
  1351. myRank = 0;
  1352. //Make sure they're not promoting to their rank or higher
  1353. if(myRank <= tarRank + 1)
  1354. {
  1355. vMinecraftChat.sendMessage(player, Colors.Rose + "You cannot promote someone to" +
  1356. " your rank or higher.");
  1357. return EXIT_SUCCESS;
  1358. }
  1359. tarGroups[tarPos] = ranks[tarRank + 1];
  1360. target.setGroups(tarGroups);
  1361. //Make sure the player is in the files
  1362. FlatFileSource ffs = new FlatFileSource();
  1363. if(!ffs.doesPlayerExist(target.getName()))
  1364. {
  1365. vMinecraftChat.sendMessage(player, Colors.Rose + "Adding player.");
  1366. ffs.addPlayer(target);
  1367. }
  1368. else
  1369. {
  1370. ffs.modifyPlayer(target);
  1371. }
  1372. vMinecraftChat.sendMessage(player, Colors.Rose + target.getName()
  1373. + " has been promoted to " + ranks[tarRank + 1] + ".");
  1374. vMinecraftChat.sendMessage(target, Colors.Rose + "You have been promoted to "
  1375. + ranks[tarRank + 1] + ".");
  1376. return EXIT_SUCCESS;
  1377. }
  1378. //=====================================================================
  1379. //Function: demote (/demote)
  1380. //Input: Player player: The player using the command
  1381. // String[] args: Player to promote
  1382. //Output: int: Exit Code
  1383. //Use: Attempt to promote a player one rank
  1384. //=====================================================================
  1385. public static int demote(Player player, String[] args)
  1386. {
  1387. //Check if they can demote
  1388. if(!player.canUseCommand("/demote")) return EXIT_FAIL;
  1389. //Check if they specified a player
  1390. if(args.length < 1)
  1391. {
  1392. vMinecraftChat.sendMessage(player, Colors.Rose + "Usage: /demote [Player] (Rank)");
  1393. return EXIT_SUCCESS;
  1394. }
  1395. //Try to find the player
  1396. Player target = etc.getServer().matchPlayer(args[0]);
  1397. if(target == null)
  1398. {
  1399. vMinecraftChat.sendMessage(player, Colors.Rose + "The player specified could not be found");
  1400. return EXIT_SUCCESS;
  1401. }
  1402. //Get the list of ranks
  1403. String[] ranks = vMinecraftSettings.getInstance().getRanks();
  1404. //Find the targets current rank number
  1405. String[] tarGroups = target.getGroups();
  1406. int tarRank = 0,
  1407. tarPos = 0;
  1408. boolean leave = false;
  1409. for(String rank : ranks)
  1410. {
  1411. for(String group : tarGroups)
  1412. {
  1413. if(rank.equalsIgnoreCase(group))
  1414. {
  1415. leave = true;
  1416. break;
  1417. }
  1418. else
  1419. tarPos++;
  1420. }
  1421. if(leave)
  1422. break;
  1423. tarRank++;
  1424. tarPos = 0;
  1425. }
  1426. if(!leave)
  1427. {
  1428. tarRank = 0;
  1429. tarPos = 0;
  1430. if(tarGroups != null)
  1431. {
  1432. String[] tempGroups = new String[tarGroups.length + 1];
  1433. System.arraycopy(tarGroups, 0, tempGroups, 1, tarGroups.length);
  1434. tarGroups = tempGroups;
  1435. } else
  1436. tarGroups = new String[1];
  1437. }
  1438. leave = false;
  1439. //Get the player's rank
  1440. String[] myGroups = player.getGroups();
  1441. int myRank = 0;
  1442. for(String rank : ranks)
  1443. {
  1444. for(String group : myGroups)
  1445. if(rank.equalsIgnoreCase(group))
  1446. {
  1447. leave = true;
  1448. break;
  1449. }
  1450. if(leave)
  1451. break;
  1452. myRank++;
  1453. }
  1454. if(!leave)
  1455. {
  1456. myRank = 0;
  1457. }
  1458. //Make sure they're not demoting to their rank or higher
  1459. if(myRank <= tarRank)
  1460. {
  1461. vMinecraftChat.sendMessage(player, Colors.Rose + "You cannot demote someone who is" +
  1462. " your rank or higher.");
  1463. return EXIT_SUCCESS;
  1464. }
  1465. if(tarRank - 1 < 0)
  1466. {
  1467. vMinecraftChat.sendMessage(player, Colors.Rose + target.getName() + " is already the" +
  1468. " lowest rank.");
  1469. return EXIT_SUCCESS;
  1470. }
  1471. tarGroups[tarPos] = ranks[tarRank - 1];
  1472. target.setGroups(tarGroups);
  1473. //Make sure the player is in the files
  1474. FlatFileSource ffs = new FlatFileSource();
  1475. if(!ffs.doesPlayerExist(target.getName()))
  1476. {
  1477. vMinecraftChat.sendMessage(player, Colors.Rose + "Adding player.");
  1478. ffs.addPlayer(target);
  1479. }
  1480. else
  1481. {
  1482. ffs.modifyPlayer(target);
  1483. }
  1484. vMinecraftChat.sendMessage(player, Colors.Rose + target.getName()
  1485. + " has been demoted to " + ranks[tarRank - 1] + ".");
  1486. vMinecraftChat.sendMessage(target, Colors.Rose + "You have been demoted to "
  1487. + ranks[tarRank - 1] + ".");
  1488. return EXIT_SUCCESS;
  1489. }
  1490. }
  1491. //=====================================================================
  1492. //Class: commandList
  1493. //Use: The list of commands that will be checked for
  1494. //Author: cerevisiae
  1495. //=====================================================================
  1496. class commandList {
  1497. ArrayList<command> commands;
  1498. protected static final Logger log = Logger.getLogger("Minecraft");
  1499. static final int EXIT_FAIL = 0,
  1500. EXIT_SUCCESS = 1,
  1501. EXIT_CONTINUE = 2;
  1502. //=====================================================================
  1503. //Function: commandList
  1504. //Input: None
  1505. //Output: None
  1506. //Use: Initialize the array of commands
  1507. //=====================================================================
  1508. public commandList(){
  1509. commands = new ArrayList<command>();
  1510. }
  1511. //=====================================================================
  1512. //Function: register
  1513. //Input: String name: The name of the command
  1514. // String func: The function to be called
  1515. //Output: boolean: Whether the command was input successfully or not
  1516. //Use: Registers a command to the command list for checking later
  1517. //=====================================================================
  1518. public boolean register(String name, String func)
  1519. {
  1520. //Check to make sure the command doesn't already exist
  1521. for(command temp : commands)
  1522. if(temp.getName().equalsIgnoreCase(name))
  1523. return false;
  1524. //Add the new function to the list
  1525. commands.add(new command(name, func));
  1526. //exit successfully
  1527. return true;
  1528. }
  1529. //=====================================================================
  1530. //Function: register
  1531. //Input: String name: The name of the command
  1532. // String func: The function to be called
  1533. // String info: The information for the command to put in help
  1534. //Output: boolean: Whether the command was input successfully or not
  1535. //Use: Registers a command to the command list for checking later
  1536. //=====================================================================
  1537. public boolean register(String name, String func, String info){
  1538. //Add to the /help list
  1539. etc.getInstance().addCommand(name, info);
  1540. //Finish registering
  1541. return register(name, func);
  1542. }
  1543. //=====================================================================
  1544. //Function: register
  1545. //Input: String name: The name of the command
  1546. // String func: The function to be called
  1547. //Output: boolean: Whether the command was input successfully or not
  1548. //Use: Registers a command to the command list for checking later
  1549. //=====================================================================
  1550. public boolean registerAlias(String name, String com)
  1551. {
  1552. //Check to make sure the command doesn't already exist
  1553. for(command temp : commands)
  1554. if(temp.getName().equalsIgnoreCase(name))
  1555. return false;
  1556. //Add the new function to the list
  1557. commands.add(new commandRef(name, com));
  1558. //exit successfully
  1559. return true;
  1560. }
  1561. //=====================================================================
  1562. //Function: registerMessage
  1563. //Input: String name: The name of the command
  1564. // String msg: The message to be displayed
  1565. // boolean admin: If the message is displayed to admins only
  1566. //Output: boolean: Whether the command was input successfully or not
  1567. //Use: Registers a command to the command list for checking later
  1568. //=====================================================================
  1569. public boolean registerMessage(String name, String msg, String clr, int args, boolean admin)
  1570. {
  1571. //Check to make sure the command doesn't already exist
  1572. for(command temp : commands)
  1573. if(temp.getName().equalsIgnoreCase(name))
  1574. return false;
  1575. //Add the new function to the list
  1576. commands.add(new commandAnnounce(name, msg, clr, args, admin));
  1577. //exit successfully
  1578. return true;
  1579. }
  1580. //=====================================================================
  1581. //Function: call
  1582. //Input: String name: The name of the command to be run
  1583. // Player player: The player calling the command
  1584. // String[] arg: The arguments being input for the command
  1585. //Output: boolean: If the command was called successfully
  1586. //Use: Attempts to call a command
  1587. //=====================================================================
  1588. public int call(String name, Player player, String[] arg){
  1589. //Search for the command
  1590. for(command cmd : commands)
  1591. {
  1592. //When found
  1593. if(cmd.getName().equalsIgnoreCase(name))
  1594. {
  1595. try {
  1596. //Call the command and return results
  1597. return cmd.call(player, arg);
  1598. } catch (SecurityException e) {
  1599. log.log(Level.SEVERE, "Exception while running command", e);
  1600. } catch (IllegalArgumentException e) {
  1601. log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
  1602. return EXIT_FAIL;
  1603. }
  1604. }
  1605. }
  1606. //Something went wrong
  1607. return EXIT_FAIL;
  1608. }
  1609. //=====================================================================
  1610. //Function: toString
  1611. //Input: None
  1612. //Output: String: A string representation of the aliases in the list
  1613. //Use: Displays all the aliases in thel ist
  1614. //=====================================================================
  1615. public String toString()
  1616. {
  1617. String temp = "";
  1618. int i = 0;
  1619. for(command comm : commands)
  1620. {
  1621. temp += comm.toString();
  1622. if(i < commands.size() - 1)
  1623. temp +=",";
  1624. }
  1625. return temp;
  1626. }
  1627. //=====================================================================
  1628. //Class: command
  1629. //Use: The specific command
  1630. //Author: cerevisiae
  1631. //=====================================================================
  1632. private class command
  1633. {
  1634. private String commandName;
  1635. private String function;
  1636. //=====================================================================
  1637. //Function: command
  1638. //Input: None
  1639. //Output: None
  1640. //Use: Initialize the command
  1641. //=====================================================================
  1642. public command(String name, String func){
  1643. commandName = name;
  1644. function = func;
  1645. }
  1646. //=====================================================================
  1647. //Function: getName
  1648. //Input: None
  1649. //Output: String: The command name
  1650. //Use: Returns the command name
  1651. //=====================================================================
  1652. public String getName(){return commandName;}
  1653. //=====================================================================
  1654. //Function: call
  1655. //Input: String[] arg: The arguments for the command
  1656. //Output: boolean: If the command was called successfully
  1657. //Use: Attempts to call the command
  1658. //=====================================================================
  1659. int call(Player player, String[] arg)
  1660. {
  1661. Method m;
  1662. try {
  1663. m = vMinecraftCommands.class.getMethod(function, Player.class, String[].class);
  1664. m.setAccessible(true);
  1665. return (Integer) m.invoke(null, player, arg);
  1666. } catch (SecurityException e) {
  1667. e.printStackTrace();
  1668. } catch (NoSuchMethodException e) {
  1669. e.printStackTrace();
  1670. } catch (IllegalArgumentException e) {
  1671. e.printStackTrace();
  1672. } catch (IllegalAccessException e) {
  1673. e.printStackTrace();
  1674. } catch (InvocationTargetException e) {
  1675. e.printStackTrace();
  1676. }
  1677. return 1;
  1678. }
  1679. //=====================================================================
  1680. //Function: toString
  1681. //Input: None
  1682. //Output: String: null
  1683. //Use: Returns null
  1684. //=====================================================================
  1685. public String toString() { return null; }
  1686. }
  1687. //=====================================================================
  1688. //Class: commandRef
  1689. //Use: A command referencing another command
  1690. //Author: cerevisiae
  1691. //=====================================================================
  1692. private class commandRef extends command
  1693. {
  1694. private String reference;
  1695. private String[] args;
  1696. //=====================================================================
  1697. //Function: command
  1698. //Input: String name: The command name
  1699. // String com: The command to run
  1700. //Output: None
  1701. //Use: Initialize the command
  1702. //=====================================================================
  1703. public commandRef(String name, String com){
  1704. super(name, "");
  1705. //Get the reference name
  1706. String[]temp = com.split(" ");
  1707. reference = temp[0];
  1708. //Get the arguments
  1709. args = new String[temp.length - 1];
  1710. System.arraycopy(temp, 1, args, 0, temp.length - 1);
  1711. }
  1712. //=====================================================================
  1713. //Function: call
  1714. //Input: String[] arg: The arguments for the command
  1715. //Output: boolean: If the command was called successfully
  1716. //Use: Attempts to call the command
  1717. //=====================================================================
  1718. int call(Player player, String[] arg)
  1719. {
  1720. String[] temp = new String[0];
  1721. int lastSet = 0,
  1722. argCount = 0;
  1723. //If there are args set with the function
  1724. if(args != null && args.length > 0) {
  1725. temp = new String[args.length];
  1726. System.arraycopy(args, 0, temp, 0, args.length);
  1727. //Insert the arguments into the pre-set arguments
  1728. for(String argument : temp)
  1729. {
  1730. if(argument.startsWith("%") && argument.length() > 1)
  1731. {
  1732. int argNum = Integer.parseInt(argument.substring(1));
  1733. if( argNum < arg.length )
  1734. {
  1735. temp[lastSet] = arg[argNum];
  1736. argCount++;
  1737. }
  1738. }
  1739. lastSet++;
  1740. }
  1741. }
  1742. //If there are args being input
  1743. if(arg.length > 0) {
  1744. //Append the rest of the arguments to the argument array
  1745. if(lastSet < temp.length + arg.length - argCount)
  1746. {
  1747. String[] temp2 = new String[temp.length + arg.length - argCount];
  1748. System.arraycopy(temp, 0, temp2, 0, temp.length);
  1749. System.arraycopy(arg, argCount, temp2,
  1750. temp.length, arg.length - argCount);
  1751. temp = temp2;
  1752. }
  1753. log.log(Level.INFO, reference + " " + etc.combineSplit(0, temp, " "));
  1754. //Call the referenced command
  1755. player.command(reference + " " + etc.combineSplit(0, temp, " "));
  1756. } else
  1757. player.command(reference);
  1758. return EXIT_SUCCESS;
  1759. }
  1760. //=====================================================================
  1761. //Function: toString
  1762. //Input: None
  1763. //Output: String: A string representation of this command.
  1764. // command@referencedcommand arg1 arg2 argn
  1765. //Use: Returns the string representation of the alias
  1766. //=====================================================================
  1767. public String toString()
  1768. {
  1769. String temp = getName();
  1770. temp += '@';
  1771. temp += reference;
  1772. temp += etc.combineSplit(0, args, " ");
  1773. return temp;
  1774. }
  1775. }
  1776. //=====================================================================
  1777. //Class: commandAnnounce
  1778. //Use: Announces when a command is used
  1779. //Author: cerevisiae
  1780. //=====================================================================
  1781. private class commandAnnounce extends command
  1782. {
  1783. private String message;
  1784. private boolean admin;
  1785. private int minArgs;
  1786. private String color;
  1787. //=====================================================================
  1788. //Function: commandAnnounce
  1789. //Input: String name: The command name
  1790. // String msg: The message to announce
  1791. //Output: None
  1792. //Use: Initialize the command
  1793. //=====================================================================
  1794. public commandAnnounce(String name, String msg, String clr, int args, boolean admn){
  1795. super(name, "");
  1796. message = msg;
  1797. admin = admn;
  1798. minArgs = args;
  1799. color = clr;
  1800. }
  1801. //=====================================================================
  1802. //Function: call
  1803. //Input: String[] arg: The arguments for the command
  1804. //Output: boolean: If the command was called successfully
  1805. //Use: Attempts to call the command
  1806. //=====================================================================
  1807. int call(Player player, String[] arg)
  1808. {
  1809. //Make sure the player can use the command first
  1810. if(!player.canUseCommand(super.commandName)) return EXIT_FAIL;
  1811. //Make sure the command is long enough to fire
  1812. if(minArgs < arg.length)
  1813. return EXIT_FAIL;
  1814. if(vMinecraftSettings.getInstance().globalmessages())
  1815. {
  1816. //Split up the message
  1817. String[] temp = message.split(" ");
  1818. //Insert the arguments into the message
  1819. int i = 0;
  1820. for(String argument : temp)
  1821. {
  1822. if(argument.startsWith("%") && argument.length() > 1)
  1823. {
  1824. char position = argument.charAt(1);
  1825. //Replace %p with the player name
  1826. if(position == 'p')
  1827. temp[i] = vMinecraftChat.getName(player) + color;
  1828. else if( Character.isDigit(position) && Character.getNumericValue(position) < arg.length )
  1829. {
  1830. //If the argument is specified to be a player insert it if the
  1831. //player is found or exit if they aren't
  1832. if(argument.length() > 2 && argument.charAt(2) == 'p')
  1833. {
  1834. Player targetName = etc.getServer().matchPlayer(arg[Character.getNumericValue(position)]);
  1835. if(targetName != null)
  1836. temp[i] = vMinecraftChat.getName(targetName) + color;
  1837. else
  1838. return EXIT_FAIL;
  1839. }
  1840. //Replace %# with the argument at position #
  1841. else
  1842. temp[i] = arg[Character.getNumericValue(position)];
  1843. }
  1844. }
  1845. i++;
  1846. }
  1847. message = etc.combineSplit(0, temp, " ");
  1848. //If it's an admin message only
  1849. if(admin)
  1850. {
  1851. for (Player p: etc.getServer().getPlayerList()) {
  1852. //If p is not null
  1853. if (p != null) {
  1854. //And if p is an admin or has access to adminchat send message
  1855. if (p.isAdmin()) {
  1856. vMinecraftChat.sendMessage(player, p, color + message);
  1857. }
  1858. }
  1859. }
  1860. } else
  1861. vMinecraftChat.gmsg(player, message);
  1862. }
  1863. return EXIT_FAIL;
  1864. }
  1865. //=====================================================================
  1866. //Function: toString
  1867. //Input: None
  1868. //Output: String: null
  1869. //Use: Returns null
  1870. //=====================================================================
  1871. public String toString() { return null; }
  1872. }
  1873. }