vMinecraftCommands.java 81 KB

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