Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Events implements Listener {
- private KStaffMode plugin;
- public Events(KStaffMode plugin) {
- this.plugin = plugin;
- }
- @EventHandler
- public void onAttack(EntityDamageByEntityEvent e){
- if(e.getEntity()== null && e.getEntity() instanceof Player){
- return;
- }else{
- if(StaffModeCommand.staffmode.contains(e.getDamager().getUniqueId())){
- e.setCancelled(true);
- }
- if(StaffModeCommand.staffmode.contains(e.getEntity().getUniqueId())){
- e.setCancelled(true);
- }
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onPlayerInteract(PlayerInteractEntityEvent e){
- Player p = e.getPlayer();
- Player t = (Player) e.getRightClicked();
- if(t instanceof Player){
- if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
- if(p.getItemInHand().getType() == Material.getMaterial(54)) {
- Inspect.inspectPlayer(p, t);
- }else{
- return;
- }
- }else{
- return;
- }
- }
- }
- @EventHandler
- public void onBlockPlace(BlockPlaceEvent e){
- if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onBlockRemove(BlockBreakEvent e){
- if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onQuit(PlayerQuitEvent e){
- if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())){
- StaffModeCommand.staffmode.remove(e.getPlayer().getUniqueId());
- if(StaffModeCommand.pitems.containsKey(e.getPlayer().getUniqueId())){
- e.getPlayer().getInventory().setContents(StaffModeCommand.pitems.get(e.getPlayer().getUniqueId()));
- StaffModeCommand.pitems.remove(e.getPlayer().getUniqueId());
- }
- if(StaffModeCommand.parmor.containsKey(e.getPlayer().getUniqueId())){
- e.getPlayer().getInventory().setArmorContents(StaffModeCommand.parmor.get(e.getPlayer().getUniqueId()));
- StaffModeCommand.parmor.remove(e.getPlayer().getUniqueId());
- }
- }
- }
- @EventHandler
- public void onMove(PlayerMoveEvent e){
- Player p = e.getPlayer();
- Location from = e.getFrom();
- Location to = e.getTo();
- if((from.getX() !=to.getX()) || (from.getY() !=to.getY()) || (from.getZ() !=to.getZ()) || (from.getYaw() !=to.getYaw())
- || (from.getPitch() !=to.getPitch())){
- if(StaffModeCommand.frozen.contains(p.getUniqueId())){
- e.setCancelled(true);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou can't move while frozen!"));
- }else{
- return;
- }
- }
- }
- Map<UUID,Long> cooldownMap = new HashMap<>();
- private boolean hasCooledDown(UUID id){
- long cooldownStart = cooldownMap.getOrDefault(id, System.currentTimeMillis());
- return (System.currentTimeMillis() - cooldownStart) < 500;
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onInteract(PlayerInteractEntityEvent e){
- if(e.getRightClicked() instanceof Player) {
- Player p = e.getPlayer();
- if(p !=null) {
- if (StaffModeCommand.staffmode.contains(p.getUniqueId())) {
- if (p.getItemInHand().getType() == Material.ICE) {
- Player t = (Player) e.getRightClicked();
- if(!hasCooledDown(p.getUniqueId())) {
- return;
- }
- if(t !=null) {
- if (!StaffModeCommand.frozen.contains(t.getUniqueId())) {
- cooldownMap.put(p.getUniqueId(), System.currentTimeMillis());
- FreezeUtil.addFreeze(t);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have frozen to " + t.getName()));
- } else {
- cooldownMap.put(p.getUniqueId(), System.currentTimeMillis());
- FreezeUtil.removeFreeze(t);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have unfrozen to " + t.getName()));
- }
- }
- }
- }
- }
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onItemPickUp(PlayerPickupItemEvent e){
- if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onItemDrop(PlayerDropItemEvent e){
- if(StaffModeCommand.staffmode.contains(e.getPlayer().getUniqueId())) {
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onDamage(EntityDamageEvent e){
- if(e.getEntity() instanceof Player) {
- Player p = (Player) e.getEntity();
- if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
- e.setCancelled(true);
- }
- }
- }
- @EventHandler
- public void onClick(InventoryClickEvent e){
- if(e.getWhoClicked() instanceof Player){
- Player p = (Player) e.getWhoClicked();
- if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
- if(e.getClickedInventory().equals(p.getInventory())){
- e.setCancelled(true);
- }
- }
- }
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onAction(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- Random r = new Random();
- ArrayList<Player> players = new ArrayList<>();
- if(StaffModeCommand.staffmode.contains(p.getUniqueId())){
- if (p.hasPermission("kstaffmode.usestaffitems")) {
- if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK ||
- e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
- if (p.getItemInHand().getType() == Material.getMaterial(381)) {
- if (StaffModeCommand.staffmode.contains(p.getUniqueId())) {
- for (Player online : Bukkit.getOnlinePlayers()) {
- players.add(online);
- if (players.contains(p)) {
- players.remove(p);
- }
- }
- if (players.size() == 0) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou need more players to do this."));
- } else {
- int index = r.nextInt(players.size());
- Player loc = players.get(index);
- p.teleport(loc);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have been teleported to " + loc.getName()));
- }
- } else {
- return;
- }
- }
- if (p.getItemInHand().getType() == Material.getMaterial(397)) {
- if (StaffModeCommand.staffmode.contains(p.getUniqueId())) {
- StaffList si = new StaffList();
- si.openMenuMain(p);
- }
- }
- if (p.getItemInHand().getType() == Material.getMaterial(351)) {
- if (StaffMode.vanish.contains(p.getUniqueId())) {
- p.getInventory().remove(Material.getMaterial(351));
- ItemStack unvanish = new ItemStack(351, 1, (short) 8);
- ItemMeta metaunvanish = unvanish.getItemMeta();
- metaunvanish.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&2Vanish"));
- List<String> loreunvanish = new ArrayList<>();
- loreunvanish.add("Show to other players");
- unvanish.setItemMeta(metaunvanish);
- p.getInventory().setItem(6, unvanish);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bYou have been unvanished!"));
- StaffMode.vanish.remove(p.getUniqueId());
- StaffMode.Vanish(p);
- } else if (!StaffMode.vanish.contains(p.getUniqueId())) {
- p.getInventory().remove(Material.getMaterial(351));
- ItemStack vanishe = new ItemStack(351, 1, (short) 10);
- ItemMeta metavanish = vanishe.getItemMeta();
- metavanish.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&2Unvanish"));
- List<String> lorevanish = new ArrayList<>();
- lorevanish.add("Hide to other players");
- vanishe.setItemMeta(metavanish);
- p.getInventory().setItem(6, vanishe);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bYou have been vanished!"));
- StaffMode.vanish.add(p.getUniqueId());
- StaffMode.Vanish(p);
- }
- } else {
- if (p.getItemInHand().getType() == Material.getMaterial(288)) {
- if (StaffMode.fly.contains(p.getUniqueId())) {
- StaffMode.Fly(p);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eYou have disabled flight"));
- } else {
- if (!StaffMode.fly.contains(p.getUniqueId())) {
- StaffMode.Fly(p);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eYou have enabled flight"));
- }
- }
- }
- }
- }
- }
- }else{
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement