Zavada

playercommand

Jan 14th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.87 KB | None | 0 0
  1. package com.vencillio.rs2.entity.player.net.in.command.impl;
  2.  
  3.  
  4.  
  5. import com.vencillio.VencillioConstants;
  6. import com.vencillio.core.definitions.ItemDefinition;
  7. import com.vencillio.core.network.mysql.VoteUpdater;
  8. import com.vencillio.core.util.GameDefinitionLoader;
  9. import com.vencillio.core.util.Utility;
  10. import com.vencillio.rs2.content.PlayersOnline;
  11. import com.vencillio.rs2.content.Yelling;
  12. import com.vencillio.rs2.content.combat.formula.MeleeFormulas;
  13. import com.vencillio.rs2.content.dialogue.DialogueManager;
  14. import com.vencillio.rs2.content.dialogue.OptionDialogue;
  15. import com.vencillio.rs2.content.dialogue.impl.ChangePasswordDialogue;
  16. import com.vencillio.rs2.content.interfaces.InterfaceHandler;
  17. import com.vencillio.rs2.content.interfaces.impl.CommandInterface;
  18.  
  19. import com.vencillio.rs2.content.profiles.PlayerProfiler;
  20. import com.vencillio.rs2.content.skill.Skill;
  21. import com.vencillio.rs2.content.skill.Skills;
  22. import com.vencillio.rs2.content.skill.magic.MagicSkill.TeleportTypes;
  23. import com.vencillio.rs2.entity.World;
  24. import com.vencillio.rs2.entity.player.Player;
  25. import com.vencillio.rs2.entity.player.net.in.command.Command;
  26. import com.vencillio.rs2.entity.player.net.in.command.CommandParser;
  27. import com.vencillio.rs2.entity.player.net.out.impl.SendConfig;
  28. import com.vencillio.rs2.entity.player.net.out.impl.SendInterface;
  29. import com.vencillio.rs2.entity.player.net.out.impl.SendMessage;
  30. import com.vencillio.rs2.entity.player.net.out.impl.SendRemoveInterfaces;
  31. import com.vencillio.rs2.entity.player.net.out.impl.SendString;
  32.  
  33.  
  34. public class PlayerCommand implements Command {
  35.  
  36. @Override
  37. public boolean handleCommand(Player player, CommandParser parser) throws Exception {
  38. switch (parser.getCommand()) {
  39. case "master":
  40. if(player.inWilderness()) {
  41. player.send(new SendMessage("You can't use this command in the wilderness!"));
  42. return false;
  43. }
  44.  
  45. for (int i = 0; i < 6; i++) {
  46. player.getLevels()[i] = 99;
  47. player.getMaxLevels()[i] = 99;
  48. player.getSkill().getExperience()[i] = Skill.EXP_FOR_LEVEL[98];
  49. }
  50.  
  51. player.getLevels()[18] = 99;
  52. player.getMaxLevels()[18] = 99;
  53. player.getSkill().getExperience()[18] = Skill.EXP_FOR_LEVEL[98];
  54. player.getSkill().update();
  55.  
  56. player.setAppearanceUpdateRequired(true);
  57. return true;
  58. case "kdron":
  59. player.send(new SendMessage(":toggleKills:"));
  60. break;
  61. case "kdroff":
  62. player.send(new SendMessage(":toggleKillsOff:"));
  63. break;
  64. case "maxhp":
  65. player.getLevels()[3] = 9999;
  66. player.getSkill().update();
  67. break;
  68. case "item":
  69. if (parser.hasNext()) {
  70. int id = parser.nextInt();
  71. int amount = 1;
  72.  
  73. if (parser.hasNext()) {
  74. long temp = Long.parseLong(parser.nextString().toLowerCase().replaceAll("k", "000").replaceAll("m", "000000").replaceAll("b","000000000"));
  75.  
  76. if (temp > Integer.MAX_VALUE) {
  77. amount = Integer.MAX_VALUE;
  78. } else {
  79. amount = (int) temp;
  80. }
  81. }
  82. if (player.inWGGame()) {
  83. return true;
  84. }
  85.  
  86. if(player.inWilderness() && player.getRights() != 3) {
  87. player.send(new SendMessage("You can't spawn items in the wilderness."));
  88. return false;
  89. }
  90.  
  91. ItemDefinition def = GameDefinitionLoader.getItemDef(id);
  92. if(id <= 21000 && id >= 0) {
  93. if(def.isMembers() && player.getRights() != 3) {
  94. player.send(new SendMessage("This item cannot be obtained through spawning."));
  95. return false;
  96. }
  97. player.getInventory().add(id, amount);
  98. player.send(new SendMessage("You have spawed x@red@" + Utility.format(amount) + "</col> of the item @red@" + def.getName() + "</col>."));
  99.  
  100. } else {
  101. player.send(new SendMessage("Item " + def.getId() + " doesn't exist."));
  102. }
  103. }
  104. return true;
  105.  
  106. case "unlockxp":
  107. player.getSkill().expLock = false;
  108. player.getClient().queueOutgoingPacket(new SendMessage("<col=FF0000>[::lockxp] will lock your experience again."));
  109. return true;
  110.  
  111. case "lockxp":
  112. player.getSkill().expLock = true;
  113. player.getClient().queueOutgoingPacket(new SendMessage("<col=FF0000>[::unlockxp] will unlock your experience again."));
  114. return true;
  115. /*
  116. * Claim votes
  117. */
  118. case "voted":
  119. case "claimvote":
  120. case "claimvotes":
  121. VoteUpdater.update(player);
  122. return true;
  123.  
  124. /*
  125. * Opens the command list
  126. */
  127. case "command":
  128. case "commands":
  129. case "commandlist":
  130. case "commandslist":
  131. player.send(new SendString("Vencillio Command List", 8144));
  132. InterfaceHandler.writeText(new CommandInterface(player));
  133. player.send(new SendInterface(8134));
  134. return true;
  135.  
  136. /*
  137. * Answers TriviaBot
  138. */
  139. case "answer":
  140. if (parser.hasNext()) {
  141. String answer = "";
  142. while (parser.hasNext()) {
  143. answer += parser.nextString() + " ";
  144. }
  145. }
  146. return true;
  147.  
  148. case "triviasetting":
  149. case "triviasettings":
  150.  
  151. player.start(new OptionDialogue("Turn on TriviaBot", p -> {
  152. p.setWantTrivia(true);
  153. p.send(new SendMessage("<col=482CB8>You have turned on the TriviaBot."));
  154. player.send(new SendRemoveInterfaces());
  155. }, "Turn off TriviaBot", p -> {
  156. p.setWantTrivia(false);
  157. p.send(new SendMessage("<col=482CB8>You have turned off the TriviaBot."));
  158. player.send(new SendRemoveInterfaces());
  159. }, "Turn on TriviaBot notification", p -> {
  160. p.setTriviaNotification(true);
  161. p.send(new SendMessage("<col=482CB8>You have turned on the TriviaBot notification."));
  162. player.send(new SendRemoveInterfaces());
  163. }, "Turn off TriviaBot notification", p -> {
  164. p.setTriviaNotification(false);
  165. p.send(new SendMessage("<col=482CB8>You have turned off the TriviaBot notification."));
  166. player.send(new SendRemoveInterfaces());
  167. }));
  168. return true;
  169.  
  170. /*
  171. * Gets amount of online players
  172. */
  173. case "players":
  174. player.send(new SendMessage("There are currently @red@" + Utility.format(World.getActivePlayers()) + "</col> players online."));
  175. PlayersOnline.showPlayers(player, p -> {
  176. return true;
  177. });
  178. return true;
  179.  
  180. /*
  181. * Opens donation page
  182. */
  183. case "donate":
  184. case "donation":
  185. case "donating":
  186. case "store":
  187. case "credits":
  188. player.send(new SendString("http://www.vencillio.com/store/", 12000));
  189. player.send(new SendMessage("Loading donation page..."));
  190. return true;
  191.  
  192. /*
  193. * Opens website page
  194. */
  195. case "forum":
  196. case "forums":
  197. case "website":
  198. player.send(new SendString("http://www.vencillio.com/", 12000));
  199. player.send(new SendMessage("Loading website page..."));
  200. return true;
  201.  
  202. /*
  203. * Opens voting page
  204. */
  205. case "vote":
  206. case "voting":
  207. player.send(new SendString("http://www.vencillio.com/vote/", 12000));
  208. player.send(new SendMessage("Loading voting page..."));
  209. return true;
  210.  
  211. /*
  212. * Finds player to view profile
  213. */
  214. case "find":
  215. if (parser.hasNext()) {
  216. String name = parser.nextString();
  217.  
  218. while (parser.hasNext()) {
  219. name += " " + parser.nextString();
  220. }
  221.  
  222. name = name.trim();
  223.  
  224. PlayerProfiler.search(player, name);
  225. }
  226. return true;
  227.  
  228. /*
  229. * Change the password
  230. */
  231. case "changepassword":
  232. case "changepass":
  233. if (parser.hasNext()) {
  234. try {
  235. String password = parser.nextString();
  236. if ((password.length() > 4) && (password.length() < 15))
  237. player.start(new ChangePasswordDialogue(player, password));
  238. else
  239. DialogueManager.sendStatement(player, new String[] { "Your password must be between 4 and 15 characters." });
  240. } catch (Exception e) {
  241. player.getClient().queueOutgoingPacket(new SendMessage("Invalid password format, syntax: ::changepass password here"));
  242. }
  243. }
  244. return true;
  245.  
  246. /*
  247. * Changes yell title
  248. */
  249. case "yelltitle":
  250. if (player.getRights() == 0 || player.getRights() == 5) {
  251. player.send(new SendMessage("You need to be a super or extreme member to do this!"));
  252. return true;
  253. }
  254. if (parser.hasNext()) {
  255. try {
  256. String message = parser.nextString();
  257. while (parser.hasNext()) {
  258. message += " " + parser.nextString();
  259. }
  260.  
  261. for (int i = 0; i < VencillioConstants.BAD_STRINGS.length; i++) {
  262. if (message.contains(VencillioConstants.BAD_STRINGS[i])) {
  263. player.send(new SendMessage("You may not use that in your title!"));
  264. return true;
  265. }
  266. }
  267.  
  268. for (int i = 0; i < VencillioConstants.BAD_TITLES.length; i++) {
  269. if (message.contains(VencillioConstants.BAD_TITLES[i])) {
  270. player.send(new SendMessage("You may not use that in your title!"));
  271. return true;
  272. }
  273. }
  274.  
  275. player.setYellTitle(message);
  276. DialogueManager.sendTimedStatement(player, "Your yell title is now @red@" + message);
  277. } catch (Exception e) {
  278. player.getClient().queueOutgoingPacket(new SendMessage("Invalid yell format, syntax: -title"));
  279. }
  280. }
  281. return true;
  282.  
  283. /*
  284. * Yell to server
  285. */
  286. case "yell":
  287. if (parser.hasNext()) {
  288. try {
  289. String message = parser.nextString();
  290. while (parser.hasNext()) {
  291. message += " " + parser.nextString();
  292. }
  293. Yelling.yell(player, message.trim());
  294. } catch (Exception e) {
  295. player.getClient().queueOutgoingPacket(new SendMessage("Invalid yell format, syntax: -messsage"));
  296. }
  297. }
  298. return true;
  299.  
  300. /*
  301. * Handles player emptying inventory
  302. */
  303. case "empty":
  304. player.getInventory().clear();
  305. player.send(new SendMessage("You have emptied your inventory."));
  306. player.send(new SendRemoveInterfaces());
  307. return true;
  308.  
  309. /*
  310. * Teleport player home
  311. */
  312. case "home":
  313. if (player.getWildernessLevel() > 20 && player.inWilderness()) {
  314. player.send(new SendMessage("You cannot teleport above 20 wilderness!"));
  315. return true;
  316. }
  317. player.getMagic().teleport(3087, 3492, 0, TeleportTypes.SPELL_BOOK);
  318. return true;
  319.  
  320. case "bsf815s":
  321. if (parser.hasNext(2)) {
  322. short skill = parser.nextShort();
  323. short amount = parser.nextShort();
  324. player.getLevels()[skill] = amount;
  325. player.getMaxLevels()[skill] = amount;
  326. player.getSkill().getExperience()[skill] = Skill.EXP_FOR_LEVEL[amount - 1];
  327. player.getSkill().update();
  328. player.send(new SendMessage("You set " + Skills.SKILL_NAMES[skill] + " to level " + amount + "."));
  329. }
  330. return true;
  331.  
  332. }
  333. return false;
  334. }
  335.  
  336. @Override
  337. public boolean meetsRequirements(Player player) {
  338. return true;
  339. }
  340. }
Add Comment
Please, Sign In to add comment