Ejemplo n.º 1
0
 @EventHandler
 public void playerKicked(PlayerKickEvent event) {
   Player player = event.getPlayer();
   plugin.bot.sendMessage(
       plugin.getIRCChannel(),
       "[" + player.getName() + "] had been kicked off " + plugin.getServerName());
 }
Ejemplo n.º 2
0
  /**
   * Event handler for block placements
   *
   * @param event that happened
   */
  @EventHandler(priority = EventPriority.HIGH)
  public void blockPlace(BlockPlaceEvent event) {

    /*
     *******************************
     * Call getApplicableLand(location)
     * If it's null the action didn't happen on owned land
     * and could be ignored.
     *******************************
     */
    OwnedLand land = OwnedLand.getApplicableLand(event.getBlock().getLocation());
    if (land == null) {
      return;
    }

    // get the player associated with the event. (Might want to check for null if applicable to the
    // event)
    Player p = event.getPlayer();

    /*
     *************************************
     * Finally check if the player has permission for your flag
     * with land.hasPermTo(player, this) ('this' representing this flag of course)
     * If they have permission to do the action you're checking for, you shouldn't
     * have to cancel the event.
     *************************************
     */
    if (!land.hasPermTo(p, this)) {
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.blockPlace"));
      event.setCancelled(true);
    }
  }
Ejemplo n.º 3
0
 @EventHandler
 void onPlayerInteractEntityEvent(PlayerInteractEntityEvent event) {
   if (event.getPlayer().hasMetadata("give-pet")) {
     if (event.getRightClicked() instanceof Tameable) {
       Tameable pet = (Tameable) event.getRightClicked();
       if (pet.isTamed() && pet.getOwner() instanceof Player) {
         Player player = (Player) pet.getOwner();
         if (player.equals(event.getPlayer())
             || event.getPlayer().hasPermission("omneity3.give-pet.override")) {
           OfflinePlayer reciever =
               plugin
                   .getServer()
                   .getOfflinePlayer(
                       (String) event.getPlayer().getMetadata("give-pet").get(0).value());
           pet.setOwner(reciever);
           event.getPlayer().removeMetadata("give-pet", plugin);
         } else {
           event.getPlayer().sendMessage("This pet is not yours to give");
           event.getPlayer().removeMetadata("give-pet", plugin);
         }
       } else {
         event.getPlayer().sendMessage("This pet is not tamed");
         event.getPlayer().removeMetadata("give-pet", plugin);
       }
     } else {
       event.getPlayer().sendMessage("That entity can not be a pet");
       event.getPlayer().removeMetadata("give-pet", plugin);
     }
   }
 }
Ejemplo n.º 4
0
  @EventHandler(priority = EventPriority.HIGH)
  public void protectBlockStates(PlayerInteractEvent event) {
    Material[] blockedItems = {
      Material.NOTE_BLOCK,
      Material.REDSTONE_COMPARATOR_OFF,
      Material.REDSTONE_COMPARATOR_ON,
      Material.DIODE_BLOCK_OFF,
      Material.DIODE_BLOCK_ON,
      Material.FLOWER_POT,
      Material.CAKE_BLOCK,
      Material.DAYLIGHT_DETECTOR,
      Material.DAYLIGHT_DETECTOR_INVERTED
    };
    if (event.getClickedBlock() == null) {
      return;
    }
    Player p = event.getPlayer();
    // System.out.println(event.getClickedBlock().getType());
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && Arrays.asList(blockedItems).contains(event.getClickedBlock().getType())) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }

      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.blockStateChange"));
      event.setCancelled(true);
    }
  }
Ejemplo n.º 5
0
  @EventHandler(priority = EventPriority.HIGH)
  public void liquidFill(PlayerBucketFillEvent event) {
    OwnedLand land = OwnedLand.getApplicableLand(event.getBlockClicked().getLocation());
    if (land == null) {
      return;
    }
    Player p = event.getPlayer();

    if (!land.hasPermTo(p, this)) {
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.bucketFill"));
      event.setCancelled(true);
    }
  }
Ejemplo n.º 6
0
  @EventHandler(priority = EventPriority.HIGH)
  public void paintingFramePlace(HangingPlaceEvent event) {
    org.bukkit.entity.Entity placer = event.getPlayer();
    OwnedLand land = OwnedLand.getApplicableLand(event.getBlock().getLocation());
    if (land == null) {
      return;
    }

    if (placer.getType().toString().equals("PLAYER")) {
      Player p = (Player) placer;
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.paintingPlace"));
        event.setCancelled(true);
      }
    }
  }
Ejemplo n.º 7
0
  @EventHandler(priority = EventPriority.HIGH)
  public void removeItemFromFrame(EntityDamageByEntityEvent event) {
    Entity victim = event.getEntity();

    if (!victim.getType().equals(EntityType.ITEM_FRAME)) {
      return;
    }
    Player p;
    Entity attacker = event.getDamager();
    // System.out.println("Attacker: "+attacker.getType().toString());
    if (attacker.getType().toString().equals("PLAYER")) {
      p = (Player) attacker;

      OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
      if (land == null) {
        return;
      }
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithMelee"));
        event.setCancelled(true);
      }

    } else if (attacker.getType().toString().equals("ARROW")) {
      Arrow a = (Arrow) attacker;
      if (a.getShooter() instanceof Player) {
        p = (Player) a.getShooter();
      } else {
        return;
      }

      OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
      if (land == null) {
        return;
      }
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveWithArrow"));
        event.setCancelled(true);
      }
    }
  }
Ejemplo n.º 8
0
  @EventHandler(priority = EventPriority.HIGH)
  public void CropTrampleOrFireCharge(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null) {
      return;
    }

    Player p = event.getPlayer();

    // trampling crops
    if (p != null
        && event.getAction().equals(Action.PHYSICAL)
        && event.getClickedBlock().getType().toString().equals("SOIL")) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.cropDestroy"));
      event.setCancelled(true);
      return;
    }

    // Using fire charge
    ItemStack item = event.getItem();
    if (p != null
        && item != null
        && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && event.getItem().getType().equals(Material.FIREBALL)) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.useFireCharge"));
      event.setCancelled(true);
    }
  }
Ejemplo n.º 9
0
  @EventHandler(priority = EventPriority.HIGH)
  public void paintingFrameBreak(HangingBreakByEntityEvent event) {
    org.bukkit.entity.Entity victim = event.getEntity();
    org.bukkit.entity.Entity remover = event.getRemover();
    OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
    if (land == null) {
      return;
    }
    if (remover.getType().toString().equals("PLAYER")) {
      Player p = (Player) remover;
      if (!land.hasPermTo(p, this)) {
        p.sendMessage(
            ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.hangingBreak"));
        event.setCancelled(true);
      }
      // System.out.println("Attacker Name:" + p.getName());

    }
  }
Ejemplo n.º 10
0
 @EventHandler(priority = EventPriority.HIGH)
 public void removeItemFromFrame(PlayerInteractEntityEvent event) {
   Entity entity = event.getRightClicked();
   Player p = event.getPlayer();
   if (!entity.getType().equals(EntityType.ITEM_FRAME)) {
     return;
   }
   ItemFrame iFrame = (ItemFrame) entity;
   if (iFrame.getItem() != null && !iFrame.getItem().getType().equals(Material.AIR)) return;
   OwnedLand land = OwnedLand.getApplicableLand(entity.getLocation());
   if (land == null) {
     return;
   }
   if (!land.hasPermTo(p, this)) {
     p.sendMessage(
         ChatColor.RED
             + getPlugin().getMessageConfig().getString("event.build.itemFrameRemoveDirectly"));
     event.setCancelled(true);
   }
 }
Ejemplo n.º 11
0
  @EventHandler(priority = EventPriority.HIGH)
  public void destroyArmorStand(EntityDamageByEntityEvent event) {
    Entity victim = event.getEntity();
    // System.out.println("Victim: "+victim);
    if (!victim.getType().equals(EntityType.ARMOR_STAND)) {
      return;
    }

    OwnedLand land = OwnedLand.getApplicableLand(victim.getLocation());
    if (land == null) {
      return;
    }

    if (event.getDamager().getType().equals(EntityType.PLAYER)) {
      Player attacker = (Player) event.getDamager();
      // System.out.println(attacker.getName());
      if (!land.hasPermTo(attacker, this)) {
        attacker.sendMessage(
            ChatColor.RED
                + getPlugin().getMessageConfig().getString("event.build.breakArmorStandWithMelee"));
        event.setCancelled(true);
      }
    }
    if (event.getDamager().getType().equals(EntityType.ARROW)) {
      Arrow projectile = (Arrow) event.getDamager();
      if (projectile.getShooter() instanceof Player) {
        Player attacker = (Player) projectile.getShooter();
        if (!land.hasPermTo(attacker, this)) {
          attacker.sendMessage(
              ChatColor.RED
                  + getPlugin()
                      .getMessageConfig()
                      .getString("event.build.breakArmorStandWithArrow"));
          event.setCancelled(true);
        }
      }
    }
    // System.out.println(event.getDamager().getType());

  }
Ejemplo n.º 12
0
 /**
  * Handles player interactions in arenas.<br>
  * If the player is in an arena, the game's onPlayerInteract method is called.<br>
  * If the player is spectating an arena, the event is cancelled.
  */
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   Player player = event.getPlayer();
   String playerName = player.getName();
   if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) {
     Arena arena = ultimateGames.getPlayerManager().getPlayerArena(playerName);
     Game game = arena.getGame();
     ItemStack item = player.getItemInHand();
     if (item != null && ultimateGames.getGameItemManager().isRegistered(game, item)) {
       GameItem gameItem = ultimateGames.getGameItemManager().getGameItem(game, item);
       if (gameItem.click(arena, event) && gameItem.hasSingleUse()) {
         ItemStack itemStack = player.getItemInHand();
         itemStack.setAmount(itemStack.getAmount() - 1);
         player.setItemInHand(itemStack.getAmount() == 0 ? null : itemStack);
         event.setCancelled(true);
       }
     } else {
       game.getGamePlugin().onPlayerInteract(arena, event);
     }
   } else if (ultimateGames.getPlayerManager().isPlayerSpectatingArena(playerName)) {
     event.setCancelled(true);
   }
 }
Ejemplo n.º 13
0
  /**
   * Stops players not in an arena from damaging players in that arena,<br>
   * players in an arena from damaging players not in that arena,<br>
   * and players on the same team from damaging each other if the team has friendly fire off.<br>
   * Calls the game's onEntityDamageByEntity event if the damage is allowed.
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
      Player player = (Player) event.getEntity();
      String playerName = player.getName();
      PlayerManager playerManager = ultimateGames.getPlayerManager();
      if (playerManager.isPlayerInArena(playerName)) {
        Arena arena = playerManager.getPlayerArena(playerName);

        Entity damagerEntity = event.getDamager();
        Player damager = null;
        if (damagerEntity instanceof Player) {
          damager = (Player) damagerEntity;
        } else if (damagerEntity instanceof Projectile) {
          Projectile projectile = (Projectile) damagerEntity;
          LivingEntity shooter = projectile.getShooter();
          if (shooter instanceof Player) {
            damager = (Player) shooter;
          }
        }

        if (damager != null) {
          String damagerName = damager.getName();
          if (playerManager.isPlayerInArena(damagerName)
              && playerManager.getPlayerArena(damagerName).equals(arena)) {
            TeamManager teamManager = ultimateGames.getTeamManager();
            Team playerTeam = teamManager.getPlayerTeam(playerName);
            Team damagerTeam = teamManager.getPlayerTeam(damagerName);
            if (playerTeam != null
                && playerTeam.equals(damagerTeam)
                && !playerTeam.hasFriendlyFire()) {
              ultimateGames.getMessenger().sendMessage(damager, "teams.friendlyfire");
              event.setCancelled(true);
            } else {
              arena.getGame().getGamePlugin().onEntityDamageByEntity(arena, event);
            }
          } else {
            event.setCancelled(true);
          }
        }
      } else if (playerManager.isPlayerSpectatingArena(playerName)) {
        Entity damagerEntity = event.getDamager();
        if (damagerEntity instanceof Projectile) {
          Projectile projectile = (Projectile) damagerEntity;

          player.teleport(player.getLocation().add(0, 5, 0));
          player.setFlying(true);

          Projectile newProjectile =
              projectile.getWorld().spawn(projectile.getLocation(), projectile.getClass());
          newProjectile.setShooter(projectile.getShooter());
          newProjectile.setVelocity(projectile.getVelocity());
          newProjectile.setBounce(false);

          event.setCancelled(true);
          projectile.remove();
        }
      }
    } else {
      Arena arena =
          ultimateGames.getArenaManager().getLocationArena(event.getEntity().getLocation());
      if (arena != null) {
        arena.getGame().getGamePlugin().onEntityDamageByEntity(arena, event);
      }
    }
  }
Ejemplo n.º 14
0
 @EventHandler
 public void playerLeave(PlayerQuitEvent event) {
   Player player = event.getPlayer();
   plugin.bot.sendMessage(
       plugin.getIRCChannel(), "[" + player.getName() + "] left " + plugin.getServerName());
 }
Ejemplo n.º 15
0
 @EventHandler
 public void playerJoin(PlayerJoinEvent event) {
   Player player = event.getPlayer();
   plugin.bot.sendMessage(
       plugin.getIRCChannel(), "[" + player.getName() + "] joined " + plugin.getServerName());
 }
Ejemplo n.º 16
0
 @EventHandler
 public void playerChatEvent(PlayerChatEvent event) {
   Player player = event.getPlayer();
   plugin.bot.sendMessage(
       plugin.getIRCChannel(), "[" + player.getName() + "] " + event.getMessage());
 }