Esempio n. 1
0
  protected void die() {
    String message = spell.getMessage("death_broadcast").replace("$name", commandName);
    if (message.length() > 0) {
      controller.sendToMages(message, center);
    }

    // Kill power block
    if (castCommandBlock == null) {
      castCommandBlock = center.getBlock();
    }

    for (BlockFace powerFace : POWER_FACES) {
      Block checkForPower = castCommandBlock.getRelative(powerFace);
      if (commandReload) {
        controller.unregisterAutomata(checkForPower);
      }
      if (checkForPower.getType() == POWER_MATERIAL) {
        BlockData commitBlock = UndoList.register(checkForPower);
        commitBlock.setMaterial(Material.AIR);
        commitBlock.modify(checkForPower);
        commitBlock.commit();
      } else {
        BlockData commitBlock = UndoList.getBlockData(checkForPower.getLocation());
        if (commitBlock != null) {
          commitBlock.setMaterial(Material.AIR);
        }
      }
    }

    // Drop item
    if (dropItem != null && dropItem.length() > 0) {
      Wand magicItem = controller.createWand(dropItem);
      if (magicItem != null) {
        center.getWorld().dropItemNaturally(center, magicItem.getItem());
      }
    }

    // Drop Xp
    if (dropXp > 0) {
      Entity entity = center.getWorld().spawnEntity(center, EntityType.EXPERIENCE_ORB);
      if (entity != null && entity instanceof ExperienceOrb) {
        ExperienceOrb orb = (ExperienceOrb) entity;
        orb.setExperience(dropXp);
      }
    }
    if (includeCommands && castCommandBlock != null) {
      BlockData commitBlock = UndoList.register(castCommandBlock);
      commitBlock.setMaterial(Material.AIR);
      commitBlock.modify(castCommandBlock);
      commitBlock.commit();
    }

    if (level != null) {
      level.onDeath(mage, birthMaterial);
    }
    if (!mage.isPlayer()) {
      controller.removeMage(mage);
    }
  }