Пример #1
0
 public void onItemDamage(PlayerItemConsumeEvent e) {
   if (ItemManager.toRPGItem(e.getItem()) != null) {
     RPGItem rpgitem = ItemManager.toRPGItem(e.getItem());
     if (rpgitem.getMaxDurability() > 0) {
       e.getItem().setDurability((short) -1);
     }
   }
 }
Пример #2
0
 @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
 public void onItemCraft(PrepareItemCraftEvent e) {
   if (ItemManager.toRPGItem(e.getInventory().getResult()) != null) {
     Random random = new Random();
     if (random.nextInt(ItemManager.toRPGItem(e.getInventory().getResult()).recipechance) != 0) {
       ItemStack baseitem = new ItemStack(e.getInventory().getResult().getType());
       e.getInventory().setResult(baseitem);
     }
   }
 }
Пример #3
0
 @EventHandler
 public void onPlayerJoin(PlayerJoinEvent e) {
   Player player = e.getPlayer();
   PlayerInventory in = player.getInventory();
   String locale = Locale.getPlayerLocale(player);
   for (int i = 0; i < in.getSize(); i++) {
     ItemStack item = in.getItem(i);
     if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
   }
   for (ItemStack item : player.getInventory().getArmorContents()) {
     if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
   }
 }
Пример #4
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));
    }
  }
Пример #5
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());
   }
 }
Пример #6
0
 @EventHandler
 public void onPlayerPickup(PlayerPickupItemEvent e) {
   ItemStack item = e.getItem().getItemStack();
   String locale = Locale.getPlayerLocale(e.getPlayer());
   if (ItemManager.toRPGItem(item) != null) {
     RPGItem.updateItem(item, locale);
     e.getItem().setItemStack(item);
   }
 }
Пример #7
0
  @EventHandler
  public void onBlockPlace(BlockPlaceEvent e) {
    ItemStack item = e.getPlayer().getItemInHand();
    if (item == null) return;

    RPGItem rItem = ItemManager.toRPGItem(item);
    if (rItem == null) return;
    e.setCancelled(true);
  }
Пример #8
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;
  }
Пример #9
0
 @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
 public void onInventoryOpen(final InventoryOpenEvent e) {
   if (e.getView() instanceof LocaleInventory) return;
   if (e.getInventory().getType() != InventoryType.CHEST || !useLocaleInv) {
     Inventory in = e.getInventory();
     Iterator<ItemStack> it = in.iterator();
     String locale = Locale.getPlayerLocale((Player) e.getPlayer());
     try {
       while (it.hasNext()) {
         ItemStack item = it.next();
         if (ItemManager.toRPGItem(item) != null) RPGItem.updateItem(item, locale);
       }
     } catch (ArrayIndexOutOfBoundsException ex) {
       // Fix for the bug with anvils in craftbukkit
     }
   } else if (useLocaleInv) {
     LocaleInventory localeInv = new LocaleInventory((Player) e.getPlayer(), e.getView());
     e.setCancelled(true);
     e.getPlayer().openInventory(localeInv);
     localeInventories.add(localeInv);
   }
 }
Пример #10
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;
 }
Пример #11
0
 @SuppressWarnings("deprecation")
 @EventHandler(ignoreCancelled = true)
 public void onBlockBreak(BlockBreakEvent e) {
   Player player = e.getPlayer();
   ItemStack item = player.getItemInHand();
   RPGItem rItem;
   if ((rItem = ItemManager.toRPGItem(item)) != null) {
     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();
   }
 }