Пример #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);
    }
  }
Пример #2
0
    @Override
    public SpellResult perform(CastContext context)
    {
		Block target = context.getTargetBlock();
		if (requireSapling && target.getType() != Material.SAPLING)
		{
			return SpellResult.NO_TARGET;
		}
		if (!context.hasBuildPermission(target))
        {
			return SpellResult.INSUFFICIENT_PERMISSION;
		}

        World world = context.getWorld();
		Location treeLoc = new Location(world, target.getX(), target.getY() + 1, target.getZ(), 0, 0);

        Random random = context.getRandom();
        TreeType useType = null;
        if (treeType != null)
		{
            useType = treeType;
		}
        else
        if (biomeMap != null)
        {
            Biome biome = treeLoc.getWorld().getBiome(treeLoc.getBlockX(), treeLoc.getBlockZ());
            List<TreeType> types = biomeMap.get(biome);
            if (types != null)
            {
                useType = types.get(random.nextInt(types.size()));
            }
        }
        if (useType == null)
        {
            useType = TreeType.values()[random.nextInt(TreeType.values().length)];
        }
        UndoList restoreOnFail = new UndoList(context.getMage(), context.getSpell().getName());
        Block treeBlock = treeLoc.getBlock();
        if (!context.isDestructible(treeBlock))
        {
            return SpellResult.NO_TARGET;
        }
        restoreOnFail.add(treeBlock);
        treeLoc.getBlock().setType(Material.AIR);
		boolean result = world.generateTree(treeLoc, useType);
        if (!result) {
            UndoList undoList = new UndoList(context.getMage(), context.getSpell().getName());
            for (int z = -2; z <= 2; z++) {
                for (int x = -2; x <= 2; x++) {
                    Block clearBlock = treeBlock.getRelative(x, 0, z);
                    Block lowerBlock = clearBlock.getRelative(BlockFace.DOWN);
                    if (context.isDestructible(clearBlock) && lowerBlock.getType() != target.getType())
                    {
                        undoList.add(lowerBlock);
                        lowerBlock.setType(target.getType());
                    }
                    if (x == 0 && z == 0) continue;
                    if (!context.isDestructible(clearBlock)) continue;
                    restoreOnFail.add(clearBlock);
                    clearBlock.setType(Material.AIR);
                }
            }
            result = world.generateTree(treeLoc, useType);
            context.addWork(100);
            undoList.undo(true);
        }
        if (result) {
            context.addWork(500);
        } else {
            context.addWork(100);
            restoreOnFail.undo(true);
        }
		return result ? SpellResult.CAST : SpellResult.FAIL;
	}