ThatGamerBlue2

Untitled

Apr 9th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. package com.earth2me.essentials.commands;
  2.  
  3. import static com.earth2me.essentials.I18n.*;
  4. import com.earth2me.essentials.User;
  5. import org.bukkit.Location;
  6. import org.bukkit.Server;
  7. import org.bukkit.inventory.Inventory;
  8.  
  9. import java.util.Collections;
  10. import java.util.List;
  11.  
  12. public class Commandinvsee extends EssentialsCommand {
  13. public Commandinvsee() {
  14. super("invsee");
  15. }
  16.  
  17. //This method has a hidden param, which if given will display the equip slots. #easteregg
  18. @Override
  19. protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
  20. if (args.length < 1) {
  21. throw new NotEnoughArgumentsException();
  22. }
  23.  
  24. final User invUser = getPlayer(server, user, args, 0);
  25. Inventory inv;
  26.  
  27. if (ess.getSettings().isLimitInvseeDistance() && !user.isAuthorized("essentials.invsee.bypassdistance")) {
  28. try {
  29. checkDistance(user, invUser);
  30. }
  31. catch (Exception ex) {
  32. user.sendMessage("fuck you fuck you fuck you");
  33. }
  34. }
  35.  
  36. if (args.length > 1 && user.isAuthorized("essentials.invsee.equip")) {
  37. inv = server.createInventory(invUser.getBase(), 9, "Equipped");
  38. inv.setContents(invUser.getBase().getInventory().getArmorContents());
  39. } else {
  40. inv = invUser.getBase().getInventory();
  41. }
  42. user.getBase().closeInventory();
  43. user.getBase().openInventory(inv);
  44. user.setInvSee(true);
  45. }
  46.  
  47. @Override
  48. protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
  49. if (args.length == 1) {
  50. return getPlayers(server, user);
  51. } else {
  52. //if (args.length == 2) {
  53. // return Lists.newArrayList("equipped");
  54. //}
  55. return Collections.emptyList();
  56. }
  57. }
  58.  
  59. private void checkDistance(User invoker, User target) throws Exception {
  60. invoker.sendMessage("> checkDist");
  61. final Location invokerLoc = invoker.getLocation();
  62. final Location targetLoc = target.getLocation();
  63.  
  64. if (invoker.getWorld() != target.getWorld()) {
  65. invoker.sendMessage("< checkDist world check");
  66. throw new Exception(tl("invseeDifferentWorld", target.getDisplayName()));
  67. }
  68.  
  69. final long maxDistance = ess.getSettings().getInvseeRadius();
  70. final long maxSquared = maxDistance * maxDistance;
  71. final long delta = (long) invokerLoc.distanceSquared(targetLoc);
  72.  
  73. if (maxSquared > delta) {
  74. invoker.sendMessage("< checkDist distance check");
  75. throw new Exception(tl("invseeTooFar", maxDistance));
  76. }
  77. invoker.sendMessage("< checkDist " + delta + " " + maxSquared + " " + maxDistance);
  78. }
  79. }
Add Comment
Please, Sign In to add comment