vMinecraftCommands.java 77 KB

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