Пример #1
0
  public boolean validateIngredients(Player player) {
    if (!this.recipe.playerHasEnough(player)) {
      player.sendMessage(Txt.parse(Lang.altarUseIngredientsFail));
      player.sendMessage(this.recipe.getRecipeLine());
      return false;
    }

    player.sendMessage(Txt.parse(Lang.altarUseIngredientsSuccess));
    player.sendMessage(this.recipe.getRecipeLine());
    this.recipe.removeFromPlayer(player);
    return true;
  }
Пример #2
0
  public void onUse(Player player) {
    player.sendMessage(Txt.parse(this.desc));

    if (!this.validateUser(player)) return;
    if (!this.validateIngredients(player)) return;

    this.applyEffect(player);
  }
Пример #3
0
  public void evalBlockUse(Block coreBlock, Player player) {
    if (coreBlock.getType() != coreMaterial) return;

    // Make sure we include the coreBlock material in the wanted ones
    if (!this.materialCounts.containsKey(this.coreMaterial)) {
      this.materialCounts.put(this.coreMaterial, 1);
    }

    ArrayList<Block> blocks = GeometryUtil.getCubeBlocks(coreBlock, Conf.altarSearchRadius);
    Map<Material, Integer> nearbyMaterialCounts =
        GeometryUtil.countMaterials(blocks, this.materialCounts.keySet());

    // P.p.log("This is our nearby materials");
    // P.p.log(nearbyMaterialCounts);

    int requiredMaterialCountSum = this.sumCollection(this.materialCounts.values());
    int nearbyMaterialCountSum = this.sumCollection(nearbyMaterialCounts.values());

    // P.p.log("requiredMaterialCountSum: "+requiredMaterialCountSum);
    // P.p.log("nearbyMaterialCountSum: "+nearbyMaterialCountSum);

    // If the blocks are to far from looking anything like an altar we will just skip.
    if (nearbyMaterialCountSum < requiredMaterialCountSum * minRatioForInfo) return;

    // This is what's missing
    Map<Material, Integer> missingMaterialCounts =
        this.getMissingMaterialCounts(nearbyMaterialCounts);
    // P.p.log("This is what's missing:");
    // P.p.log(missingMaterialCounts);

    // Have we got all we need?
    if (this.sumCollection(missingMaterialCounts.values()) == 0) {
      this.onUse(player);
      return;
    }

    // Send info on what to do to finish the altar
    player.sendMessage(Txt.parse(Lang.altarIncomplete, this.name));

    for (Entry<Material, Integer> entry : missingMaterialCounts.entrySet()) {
      Material material = entry.getKey();
      int count = entry.getValue();
      player.sendMessage(Txt.parse("<h>%d <p>%s", count, Txt.getMaterialName(material)));
    }
  }
Пример #4
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerInteract(PlayerInteractEvent event) {
    Action action = event.getAction();
    if (!(action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)) return;

    Player player = event.getPlayer();
    VPlayer vplayer = VPlayers.i.get(player);
    Material itemMaterial = event.getMaterial();

    if (vplayer.isVampire()) {

      if (Conf.foodMaterials.contains(itemMaterial) && !Conf.vampireCanEat(itemMaterial)) {
        vplayer.msg(Lang.vampiresCantEatThat, Txt.getMaterialName(itemMaterial));
        event.setCancelled(true);
      }

      if (action == Action.RIGHT_CLICK_BLOCK
          && event.getClickedBlock().getType() == Material.CAKE_BLOCK
          && Conf.vampireCanEat(Material.CAKE_BLOCK)) {
        vplayer.msg(Lang.vampiresCantEatThat, Txt.getMaterialName(Material.CAKE));
        event.setCancelled(true);
      }

      if (Conf.jumpMaterials.contains(event.getMaterial())) {
        vplayer.jump(Conf.jumpDeltaSpeed, false);
      }
    }

    if (vplayer.isInfected() && itemMaterial == Material.BREAD) {
      vplayer.infectionHeal(Conf.infectionBreadHealAmount);
      player.getInventory().removeItem(new ItemStack(Material.BREAD, 1));
      player.updateInventory();
      event.setCancelled(true);
    }

    if (action != Action.RIGHT_CLICK_BLOCK) return;
    Conf.altarEvil.evalBlockUse(event.getClickedBlock(), player);
    Conf.altarGood.evalBlockUse(event.getClickedBlock(), player);
  }
Пример #5
0
  /**
   * In this entity-damage-listener we will cancel fall damage and suffocation damage for vampires.
   * We will also modify the damage dealt.
   */
  @EventHandler(priority = EventPriority.HIGH)
  public void onEntityDamageHigh(EntityDamageEvent event) {
    if (event.isCancelled()) return;

    // Define local fields
    Entity damagee;
    Player pDamagee;
    VPlayer vpDamagee;

    EntityDamageByEntityEvent edbeEvent;

    Entity damager;
    Player pDamager;
    VPlayer vpDamager;

    damagee = event.getEntity();

    // If the damagee is a player
    if (damagee instanceof Player) {
      pDamagee = (Player) damagee;
      vpDamagee = VPlayers.i.get(pDamagee);

      // Vampires can not drown or take fall damage or starve
      if (vpDamagee.isVampire() && Conf.vampiresCantTakeDamageFrom.contains(event.getCause())) {
        event.setCancelled(true);
        return;
      }
    }

    // For further interest this must be a close combat attack by another entity
    if (event.getCause() != DamageCause.ENTITY_ATTACK) return;
    if (!(event instanceof EntityDamageByEntityEvent)) return;

    edbeEvent = (EntityDamageByEntityEvent) event;
    damager = edbeEvent.getDamager();

    // For further interest that attacker must be a player.
    if (!(damager instanceof Player)) return;
    pDamager = (Player) damager;
    vpDamager = VPlayers.i.get(pDamager);

    // The damage will be modified under certain circumstances.
    float damage = event.getDamage();

    // Modify damage if damager is a vampire
    if (vpDamager.isVampire()) {
      damage *= vpDamager.getDamageDealtFactor();
    }

    // Modify damage if damagee is a vampire
    if (damagee instanceof Player) {
      pDamagee = (Player) damagee;
      vpDamagee = VPlayers.i.get(pDamagee);
      if (vpDamagee.isVampire()) {
        Material itemMaterial = pDamager.getItemInHand().getType();
        if (Conf.woodMaterials.contains(itemMaterial)) {
          damage = Conf.damageReceivedWood; // Just as much as a diamond sword.
          vpDamagee.msg(Lang.messageWoodCombatWarning, Txt.getMaterialName(itemMaterial));
        } else {
          damage *= vpDamagee.getDamageReceivedFactor();
        }
      }
    }

    event.setDamage(Math.round(damage));
  }