vMinecraftCommands.java 76 KB

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