Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. /* */ package me.zdqnilo.basic.commands;
  2. /* */
  3. /* */ import java.util.HashMap;
  4. /* */ import java.util.Map;
  5. /* */ import java.util.UUID;
  6. /* */ import org.apache.commons.lang.StringUtils;
  7. /* */ import org.apache.commons.lang.time.DurationFormatUtils;
  8. /* */ import org.bukkit.Bukkit;
  9. /* */ import org.bukkit.Server;
  10. /* */ import org.bukkit.command.Command;
  11. /* */ import org.bukkit.command.CommandExecutor;
  12. /* */ import org.bukkit.command.CommandSender;
  13. /* */ import org.bukkit.entity.Player;
  14. /* */ import me.zdqnilo.basic.Basic;
  15. /* */ import me.zdqnilo.basic.listeners.StaffModeListener;
  16. /* */ import me.zdqnilo.basic.useful.ColorUtils;
  17. /* */ import me.zdqnilo.basic.useful.FancyMessage;
  18. /* */ import me.zdqnilo.basic.useful.TimeUtils;
  19. /* */
  20. /* */ public class ReportCommand implements CommandExecutor
  21. /* */ {
  22. /* 22 */ private final Basic basic = Basic.getInstance();
  23. /* */
  24. /* 24 */ private final Map<UUID, Long> report = new HashMap();
  25. private Map<Player, Integer> reportTimes = new HashMap<Player, Integer>();
  26. /* */
  27. /* */ public void setCooldown(Player player, long value)
  28. /* */ {
  29. /* 28 */ this.report.put(player.getUniqueId(), Long.valueOf(System.currentTimeMillis() + value));
  30. /* */ }
  31. /* */
  32. /* */ public void removeCooldown(Player player)
  33. /* */ {
  34. /* 33 */ if (isCooldownActive(player))
  35. /* */ {
  36. /* 35 */ this.report.remove(player.getUniqueId());
  37. /* */ }
  38. /* */ }
  39. /* */
  40. /* */ public boolean isCooldownActive(Player player)
  41. /* */ {
  42. /* 41 */ if (!this.report.containsKey(player.getUniqueId()))
  43. /* */ {
  44. /* 43 */ return false;
  45. /* */ }
  46. /* 45 */ return ((Long)this.report.get(player.getUniqueId())).longValue() > System.currentTimeMillis();
  47. /* */ }
  48. /* */
  49. /* */ public long getMillisecondLeft(Player player)
  50. /* */ {
  51. /* 50 */ if (!isCooldownActive(player))
  52. /* */ {
  53. /* 52 */ return -1L;
  54. /* */ }
  55. /* 54 */ return ((Long)this.report.get(player.getUniqueId())).longValue() - System.currentTimeMillis();
  56. /* */ }
  57. /* */
  58. /* */
  59. /* */ public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments)
  60. /* */ {
  61. /* 60 */ if ((sender instanceof Player))
  62. /* */ {
  63. /* 62 */ Player player = (Player)sender;
  64. /* 63 */ if (arguments.length < 2)
  65. /* */ {
  66. /* 65 */ player.sendMessage(new ColorUtils().translateFromString("&cUsage: /" + label + " <playerName> <reason>"));
  67. /* 66 */ return true;
  68. /* */ }
  69. /* */
  70. /* 69 */ Player target = Bukkit.getServer().getPlayerExact(arguments[0]);
  71. /* 70 */ if ((target == null) || (this.basic.getStaffModeListener().isStaffModeActive(target)) || (this.basic.getStaffModeListener().isVanished(target)))
  72. /* */ {
  73. /* 72 */ player.sendMessage(new ColorUtils().translateFromString("&cPlayer named '" + arguments[0] + "' not found."));
  74. /* */
  75. /* */
  76. /* */ }
  77. /* 76 */ else if (target.equals(player))
  78. /* */ {
  79. /* 78 */ player.sendMessage(new ColorUtils().translateFromString("&cYou can not report yourself."));
  80. /* */
  81. /* */
  82. /* */ }
  83. /* 82 */ else if (isCooldownActive(player))
  84. /* */ {
  85. /* 84 */ player.sendMessage(new ColorUtils().translateFromString("&cYou can not report other player again for &6" + DurationFormatUtils.formatDurationWords(getMillisecondLeft(player), true, true) + "&c."));
  86. /* */ }
  87. /* */ else
  88. /* */ {
  89. /* 88 */ setCooldown(player, TimeUtils.parse("1m"));
  90. /* 89 */ for (Player staff : Bukkit.getServer().getOnlinePlayers())
  91. /* */ {
  92. /* 91 */ if (staff.hasPermission("basic.p.staff"))
  93. /* */ {
  94. /* 93 */ FancyMessage fancyMessage = new FancyMessage("");
  95. /* 94 */ fancyMessage.then(new ColorUtils().translateFromString("&7[&c&lReport&7] &7[Practice] &d" + target.getName() + "&7" + reportTimes + " &7reported by &d" + player.getName() + " &efor &e" + StringUtils.join(arguments, ' ', 1, arguments.length) + "&e."));
  96. /* 95 */ fancyMessage.tooltip(new ColorUtils().translateFromString("&aClick to teleport to " + target.getName()));
  97. /* 96 */ fancyMessage.command("/teleport " + target.getName());
  98. /* 97 */ fancyMessage.send(staff);
  99. /* */ }
  100. /* */ }
  101. /* 100 */ player.sendMessage(new ColorUtils().translateFromString("&eSucessfully reported the player &9" + target.getName() + " &afor &e" + StringUtils.join(arguments, ' ', 1, arguments.length) + "&e, report sent to all online staff members."));
  102. /* */ }
  103. /* */
  104. /* */
  105. /* */ }
  106. /* */ else
  107. /* */ {
  108. /* 107 */ sender.sendMessage(new ColorUtils().translateFromString("&cYou can not execute this command on console."));
  109. /* */ }
  110. /* 109 */ return true;
  111. /* */ }
  112. /* */ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement