vMinecraftCommands.java 84 KB

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