Exemplo n.º 1
0
 @EventHandler
 public void onInventoryClose(InventoryCloseEvent e) {
   if (recipeWindows.containsKey(e.getPlayer().getName())) {
     int id = recipeWindows.remove(e.getPlayer().getName());
     RPGItem item = ItemManager.getItemById(id);
     if (item.recipe == null) {
       item.recipe = new ArrayList<ItemStack>();
     }
     item.recipe.clear();
     for (int y = 0; y < 3; y++) {
       for (int x = 0; x < 3; x++) {
         int i = x + y * 9;
         ItemStack it = e.getInventory().getItem(i);
         item.recipe.add(it);
       }
     }
     item.hasRecipe = true;
     item.resetRecipe(true);
     ItemManager.save(Plugin.plugin);
     ((Player) e.getPlayer()).sendMessage(ChatColor.AQUA + "Recipe set for " + item.getName());
   } else if (useLocaleInv && e.getView() instanceof LocaleInventory) {
     localeInventories.remove(e.getView());
     ((LocaleInventory) e.getView()).getView().close();
   }
 }
Exemplo n.º 2
0
 private double projectileDamager(EntityDamageByEntityEvent e, double damage) {
   Projectile entity = (Projectile) e.getDamager();
   if (rpgProjectiles.contains(entity.getEntityId())) {
     RPGItem rItem = ItemManager.getItemById(rpgProjectiles.get(entity.getEntityId()));
     if (rItem == null) return damage;
     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) entity.getShooter(), le, e.getDamage());
     }
   }
   return damage;
 }
Exemplo n.º 3
0
  @EventHandler
  public void onProjectileHit(ProjectileHitEvent e) {
    final Entity entity = e.getEntity();
    if (removeArrows.contains(entity.getEntityId())) {
      entity.remove();
      removeArrows.remove(entity.getEntityId());
    } else if (rpgProjectiles.contains(entity.getEntityId())) {
      RPGItem item = ItemManager.getItemById(rpgProjectiles.get(entity.getEntityId()));
      new BukkitRunnable() {

        public void run() {
          rpgProjectiles.remove(entity.getEntityId());
        }
      }.runTask(Plugin.plugin);
      if (item == null) return;
      item.projectileHit((Player) ((Projectile) entity).getShooter(), (Projectile) entity);
    }
  }
Exemplo n.º 4
0
 @EventHandler
 public void onEntityDeath(EntityDeathEvent e) {
   String type = e.getEntity().getType().toString();
   Random random = new Random();
   if (drops.containsKey(type)) {
     Set<Integer> items = drops.get(type);
     Iterator<Integer> it = items.iterator();
     while (it.hasNext()) {
       int id = it.next();
       RPGItem item = ItemManager.getItemById(id);
       if (item == null) {
         it.remove();
         continue;
       }
       double chance = item.dropChances.get(type);
       if (random.nextDouble() < chance / 100d) {
         e.getDrops().add(item.toItemStack("en_GB"));
       }
     }
   }
 }