示例#1
0
  @EventHandler
  public void onPlayerAction(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if ((e.getAction() == Action.RIGHT_CLICK_AIR
        || (e.getAction() == Action.RIGHT_CLICK_BLOCK) && !e.isCancelled())) {
      ItemStack item = player.getItemInHand();
      if (item.getType() == Material.BOW
          || item.getType() == Material.SNOW_BALL
          || item.getType() == Material.EGG
          || item.getType() == Material.POTION) return;

      RPGItem rItem = ItemManager.toRPGItem(item);
      if (rItem == null) return;
      if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return;
      if (rItem.getHasPermission() == true
          && player.hasPermission(rItem.getPermission()) == false) {
        e.setCancelled(true);
        player.sendMessage(
            ChatColor.RED
                + String.format(
                    Locale.get("message.error.permission", Locale.getPlayerLocale(player))));
      }
      rItem.rightClick(player);
      if (player.getItemInHand().getTypeId() != 0) {
        RPGItem.updateItem(item, Locale.getPlayerLocale(player));
      } else player.setItemInHand(null);
      player.updateInventory();
    } else if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
      ItemStack item = player.getItemInHand();
      if (item.getType() == Material.BOW
          || item.getType() == Material.SNOW_BALL
          || item.getType() == Material.EGG
          || item.getType() == Material.POTION) return;

      RPGItem rItem = ItemManager.toRPGItem(item);
      if (rItem == null) return;
      if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return;
      if (rItem.getHasPermission() == true
          && player.hasPermission(rItem.getPermission()) == false) {
        e.setCancelled(true);
        player.sendMessage(
            ChatColor.RED
                + String.format(
                    Locale.get("message.error.permission", Locale.getPlayerLocale(player))));
      }
      rItem.leftClick(player);
      RPGItem.updateItem(item, Locale.getPlayerLocale(player));
    }
  }
示例#2
0
 @SuppressWarnings("deprecation")
 @EventHandler
 public void onProjectileFire(ProjectileLaunchEvent e) {
   ProjectileSource shooter = e.getEntity().getShooter();
   if (shooter instanceof Player) {
     Player player = (Player) shooter;
     ItemStack item = player.getItemInHand();
     RPGItem rItem = ItemManager.toRPGItem(item);
     if (rItem == null) return;
     if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return;
     if (rItem.getHasPermission() == true
         && player.hasPermission(rItem.getPermission()) == false) {
       e.setCancelled(true);
       player.sendMessage(
           ChatColor.RED
               + String.format(
                   Locale.get("message.error.permission", Locale.getPlayerLocale(player))));
     }
     RPGMetadata meta = RPGItem.getMetadata(item);
     if (rItem.getMaxDurability() != -1) {
       int durability =
           meta.containsKey(RPGMetadata.DURABILITY)
               ? ((Number) meta.get(RPGMetadata.DURABILITY)).intValue()
               : rItem.getMaxDurability();
       durability--;
       if (durability <= 0) {
         player.setItemInHand(null);
       }
       meta.put(RPGMetadata.DURABILITY, Integer.valueOf(durability));
     }
     RPGItem.updateItem(item, Locale.getPlayerLocale(player), meta);
     player.updateInventory();
     rpgProjectiles.put(e.getEntity().getEntityId(), rItem.getID());
   }
 }
示例#3
0
 private double playerHit(EntityDamageByEntityEvent e, double damage) {
   Player p = (Player) e.getEntity();
   if (e.isCancelled() || !WorldGuard.canPvP(p.getLocation())) return damage;
   String locale = Locale.getPlayerLocale(p);
   ItemStack[] armour = p.getInventory().getArmorContents();
   for (int i = 0; i < armour.length; i++) {
     ItemStack pArmour = armour[i];
     RPGItem pRItem = ItemManager.toRPGItem(pArmour);
     if (pRItem == null) continue;
     if (!WorldGuard.canPvP(p.getLocation()) && !pRItem.ignoreWorldGuard) return damage;
     if (pRItem.getHasPermission() == true && p.hasPermission(pRItem.getPermission()) == false) {
       damage = 0;
       e.setCancelled(true);
       p.sendMessage(
           ChatColor.RED
               + String.format(Locale.get("message.error.permission", Locale.getPlayerLocale(p))));
     }
     if (pRItem.getArmour() > 0) {
       damage -= Math.round(((double) damage) * (((double) pRItem.getArmour()) / 100d));
     }
     RPGMetadata meta = RPGItem.getMetadata(pArmour);
     if (pRItem.getMaxDurability() != -1) {
       int durability =
           meta.containsKey(RPGMetadata.DURABILITY)
               ? ((Number) meta.get(RPGMetadata.DURABILITY)).intValue()
               : pRItem.getMaxDurability();
       durability--;
       if (durability <= 0) {
         armour[i] = null;
       }
       meta.put(RPGMetadata.DURABILITY, Integer.valueOf(durability));
     }
     RPGItem.updateItem(pArmour, locale, meta);
   }
   p.getInventory().setArmorContents(armour);
   p.updateInventory();
   return damage;
 }
示例#4
0
  @SuppressWarnings("deprecation")
  private double playerDamager(EntityDamageByEntityEvent e, double damage) {
    Player player = (Player) e.getDamager();
    ItemStack item = player.getItemInHand();
    if (item.getType() == Material.BOW
        || item.getType() == Material.SNOW_BALL
        || item.getType() == Material.EGG
        || item.getType() == Material.POTION) return damage;

    RPGItem rItem = ItemManager.toRPGItem(item);
    if (rItem == null) return damage;
    if (!WorldGuard.canPvP(player.getLocation()) && !rItem.ignoreWorldGuard) return damage;
    if (rItem.getHasPermission() == true && player.hasPermission(rItem.getPermission()) == false) {
      damage = 0;
      e.setCancelled(true);
      player.sendMessage(
          ChatColor.RED
              + String.format(
                  Locale.get("message.error.permission", Locale.getPlayerLocale(player))));
    }
    damage =
        rItem.getDamageMin() != rItem.getDamageMax()
            ? (rItem.getDamageMin() + random.nextInt(rItem.getDamageMax() - rItem.getDamageMin()))
            : rItem.getDamageMin();
    if (e.getEntity() instanceof LivingEntity) {
      LivingEntity le = (LivingEntity) e.getEntity();
      rItem.hit(player, le, e.getDamage());
    }
    RPGMetadata meta = RPGItem.getMetadata(item);
    if (rItem.getMaxDurability() != -1) {
      int durability =
          meta.containsKey(RPGMetadata.DURABILITY)
              ? ((Number) meta.get(RPGMetadata.DURABILITY)).intValue()
              : rItem.getMaxDurability();
      durability--;
      if (durability <= 0) {
        player.setItemInHand(null);
      }
      meta.put(RPGMetadata.DURABILITY, Integer.valueOf(durability));
    }
    RPGItem.updateItem(item, Locale.getPlayerLocale(player), meta);
    player.updateInventory();
    return damage;
  }