vMinecraftCommands.java 79 KB

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