Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 KB | None | 0 0
  1. public class Events implements Listener {
  2.  
  3. private KStaffMode plugin;
  4. public Events(KStaffMode plugin) {
  5. this.plugin = plugin;
  6. }
  7.  
  8. @EventHandler
  9. public void onAttack(EntityDamageByEntityEvent e){
  10. if(e.getEntity()== null && e.getEntity() instanceof Player){
  11. return;
  12. }else{
  13. if(StaffModeCommand.staffmode.contains(e.getDamager().getUniqueId())){
  14. e.setCancelled(true);
  15. }
  16. if(StaffModeCommand.staffmode.contains(e.getEntity().getUniqueId())){
  17. e.setCancelled(true);
  18. }
  19. }
  20. }
  21. @SuppressWarnings("deprecation")
  22. @EventHandler
  23. public void onPlayerInteract(PlayerInteractEntityEvent e){
  24. Player p = e.getPlayer();
  25. Player t = (Player) e.getRightClicked();
  26. if(t instanceof Player){
  27. if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
  28. if(p.getItemInHand().getType() == Material.getMaterial(54)) {
  29. Inspect.inspectPlayer(p, t);
  30. }else{
  31. return;
  32. }
  33. }else{
  34. return;
  35. }
  36. }
  37. }
  38.  
  39. @EventHandler
  40. public void onBlockPlace(BlockPlaceEvent e){
  41. if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
  42. e.setCancelled(true);
  43. }
  44. }
  45. @EventHandler
  46. public void onBlockRemove(BlockBreakEvent e){
  47. if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
  48. e.setCancelled(true);
  49. }
  50. }
  51.  
  52. @EventHandler
  53. public void onQuit(PlayerQuitEvent e){
  54. if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())){
  55. StaffModeCommand.staffmode.remove(e.getPlayer().getUniqueId());
  56. if(StaffModeCommand.pitems.containsKey(e.getPlayer().getUniqueId())){
  57. e.getPlayer().getInventory().setContents(StaffModeCommand.pitems.get(e.getPlayer().getUniqueId()));
  58. StaffModeCommand.pitems.remove(e.getPlayer().getUniqueId());
  59.  
  60. }
  61. if(StaffModeCommand.parmor.containsKey(e.getPlayer().getUniqueId())){
  62. e.getPlayer().getInventory().setArmorContents(StaffModeCommand.parmor.get(e.getPlayer().getUniqueId()));
  63. StaffModeCommand.parmor.remove(e.getPlayer().getUniqueId());
  64.  
  65. }
  66. }
  67. }
  68.  
  69. @EventHandler
  70. public void onMove(PlayerMoveEvent e){
  71. Player p = e.getPlayer();
  72. Location from = e.getFrom();
  73. Location to = e.getTo();
  74.  
  75. if((from.getX() !=to.getX()) || (from.getY() !=to.getY()) || (from.getZ() !=to.getZ()) || (from.getYaw() !=to.getYaw())
  76. || (from.getPitch() !=to.getPitch())){
  77. if(StaffModeCommand.frozen.contains(p.getUniqueId())){
  78. e.setCancelled(true);
  79. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou can't move while frozen!"));
  80. }else{
  81. return;
  82. }
  83. }
  84. }
  85.  
  86. Map<UUID,Long> cooldownMap = new HashMap<>();
  87. private boolean hasCooledDown(UUID id){
  88. long cooldownStart = cooldownMap.getOrDefault(id, System.currentTimeMillis());
  89. return (System.currentTimeMillis() - cooldownStart) < 500;
  90. }
  91.  
  92. @SuppressWarnings("deprecation")
  93. @EventHandler
  94. public void onInteract(PlayerInteractEntityEvent e){
  95. if(e.getRightClicked() instanceof Player) {
  96. Player p = e.getPlayer();
  97. if(p !=null) {
  98. if (StaffModeCommand.staffmode.contains(p.getUniqueId())) {
  99. if (p.getItemInHand().getType() == Material.ICE) {
  100. Player t = (Player) e.getRightClicked();
  101. if(!hasCooledDown(p.getUniqueId())) {
  102. return;
  103. }
  104. if(t !=null) {
  105. if (!StaffModeCommand.frozen.contains(t.getUniqueId())) {
  106. cooldownMap.put(p.getUniqueId(), System.currentTimeMillis());
  107. FreezeUtil.addFreeze(t);
  108. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have frozen to " + t.getName()));
  109. } else {
  110. cooldownMap.put(p.getUniqueId(), System.currentTimeMillis());
  111. FreezeUtil.removeFreeze(t);
  112. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have unfrozen to " + t.getName()));
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120.  
  121. @SuppressWarnings("deprecation")
  122. @EventHandler
  123. public void onItemPickUp(PlayerPickupItemEvent e){
  124. if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
  125. e.setCancelled(true);
  126. }
  127. }
  128.  
  129. @EventHandler
  130. public void onItemDrop(PlayerDropItemEvent e){
  131. if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
  132. e.setCancelled(true);
  133. }
  134. }
  135.  
  136. @EventHandler
  137. public void onDamage(EntityDamageEvent e){
  138. if(e.getEntity() instanceof Player) {
  139. Player p = (Player) e.getEntity();
  140. if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
  141. e.setCancelled(true);
  142. }
  143. }
  144. }
  145. @EventHandler
  146. public void onClick(InventoryClickEvent e){
  147. if(e.getWhoClicked() instanceof Player){
  148. Player p = (Player) e.getWhoClicked();
  149. if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
  150. if(e.getClickedInventory().equals(p.getInventory())){
  151. e.setCancelled(true);
  152. }
  153. }
  154. }
  155. }
  156.  
  157.  
  158. @SuppressWarnings("deprecation")
  159. @EventHandler
  160. public void onAction(PlayerInteractEvent e) {
  161. Player p = e.getPlayer();
  162. Random r = new Random();
  163. ArrayList<Player> players = new ArrayList<>();
  164. if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
  165. if (p.hasPermission("kstaffmode.usestaffitems")) {
  166. if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK ||
  167. e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
  168. if (p.getItemInHand().getType() == Material.getMaterial(381)) {
  169. if (StaffModeCommand.staffmode.contains(p.getUniqueId())) {
  170. for (Player online : Bukkit.getOnlinePlayers()) {
  171. players.add(online);
  172. if (players.contains(p)) {
  173. players.remove(p);
  174. }
  175. }
  176. if (players.size() == 0) {
  177. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou need more players to do this."));
  178. } else {
  179. int index = r.nextInt(players.size());
  180. Player loc = players.get(index);
  181. p.teleport(loc);
  182. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have been teleported to " + loc.getName()));
  183. }
  184. } else {
  185. return;
  186. }
  187. }
  188. if (p.getItemInHand().getType() == Material.getMaterial(397)) {
  189. if (StaffModeCommand.staffmode.contains(p.getUniqueId())) {
  190. StaffList si = new StaffList();
  191. si.openMenuMain(p);
  192. }
  193. }
  194. if (p.getItemInHand().getType() == Material.getMaterial(351)) {
  195. if (StaffMode.vanish.contains(p.getUniqueId())) {
  196. p.getInventory().remove(Material.getMaterial(351));
  197. ItemStack unvanish = new ItemStack(351, 1, (short) 8);
  198. ItemMeta metaunvanish = unvanish.getItemMeta();
  199. metaunvanish.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&2Vanish"));
  200. List<String> loreunvanish = new ArrayList<>();
  201. loreunvanish.add("Show to other players");
  202. unvanish.setItemMeta(metaunvanish);
  203. p.getInventory().setItem(6, unvanish);
  204. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bYou have been unvanished!"));
  205. StaffMode.vanish.remove(p.getUniqueId());
  206. StaffMode.Vanish(p);
  207. } else if (!StaffMode.vanish.contains(p.getUniqueId())) {
  208. p.getInventory().remove(Material.getMaterial(351));
  209. ItemStack vanishe = new ItemStack(351, 1, (short) 10);
  210. ItemMeta metavanish = vanishe.getItemMeta();
  211. metavanish.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&2Unvanish"));
  212. List<String> lorevanish = new ArrayList<>();
  213. lorevanish.add("Hide to other players");
  214. vanishe.setItemMeta(metavanish);
  215. p.getInventory().setItem(6, vanishe);
  216. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bYou have been vanished!"));
  217. StaffMode.vanish.add(p.getUniqueId());
  218. StaffMode.Vanish(p);
  219. }
  220. } else {
  221. if (p.getItemInHand().getType() == Material.getMaterial(288)) {
  222. if (StaffMode.fly.contains(p.getUniqueId())) {
  223. StaffMode.Fly(p);
  224. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eYou have disabled flight"));
  225. } else {
  226. if (!StaffMode.fly.contains(p.getUniqueId())) {
  227. StaffMode.Fly(p);
  228. p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eYou have enabled flight"));
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235.  
  236. }else{
  237. return;
  238. }
  239. }
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement