Exemplo n.º 1
0
  @Override
  public SpellResult start(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Player player = mage.getPlayer();
    if (player == null) {
      return SpellResult.PLAYER_REQUIRED;
    }

    List<Player> allPlayers = null;
    players.clear();

    if (allowCrossWorld) {
      allPlayers = new ArrayList<>(controller.getPlugin().getServer().getOnlinePlayers());
    } else {
      allPlayers = context.getLocation().getWorld().getPlayers();
    }

    Collections.sort(
        allPlayers,
        new Comparator<Player>() {
          @Override
          public int compare(Player p1, Player p2) {
            return p1.getDisplayName().compareTo(p2.getDisplayName());
          }
        });

    int index = 0;
    for (Player targetPlayer : allPlayers) {
      if (!context.getTargetsCaster() && targetPlayer == player) continue;
      if (targetPlayer.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
      if (!context.canTarget(targetPlayer)) continue;
      players.put(index++, new WeakReference<>(targetPlayer));
    }
    if (players.size() == 0) return SpellResult.NO_TARGET;

    String inventoryTitle = context.getMessage("title", "Select Player");
    int invSize = ((players.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (Map.Entry<Integer, WeakReference<Player>> entry : players.entrySet()) {
      Player targetPlayer = entry.getValue().get();
      if (targetPlayer == null) continue;

      String name = targetPlayer.getName();
      String displayName = targetPlayer.getDisplayName();
      ItemStack playerItem = InventoryUtils.getPlayerSkull(targetPlayer, displayName);
      if (!name.equals(displayName)) {
        ItemMeta meta = playerItem.getItemMeta();
        List<String> lore = new ArrayList<>();
        lore.add(name);
        meta.setLore(lore);
        playerItem.setItemMeta(meta);
      }
      displayInventory.setItem(entry.getKey(), playerItem);
    }
    active = true;
    mage.activateGUI(this, displayInventory);

    return SpellResult.NO_ACTION;
  }
Exemplo n.º 2
0
  @Override
  public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null || !(entity instanceof Damageable) || entity.isDead()) {
      return SpellResult.NO_TARGET;
    }

    double damage = 1;

    Damageable targetEntity = (Damageable) entity;
    LivingEntity livingTarget = (entity instanceof LivingEntity) ? (LivingEntity) entity : null;
    context.registerDamaged(targetEntity);
    Mage mage = context.getMage();
    MageController controller = context.getController();

    double previousKnockbackResistance = 0D;
    try {
      if (knockbackResistance != null && livingTarget != null) {
        AttributeInstance knockBackAttribute =
            livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
        previousKnockbackResistance = knockBackAttribute.getBaseValue();
        knockBackAttribute.setBaseValue(knockbackResistance);
      }
      if (controller.isElemental(entity)) {
        damage = elementalDamage;
        controller.damageElemental(
            entity, damage * mage.getDamageMultiplier(), 0, mage.getCommandSender());
      } else {
        if (percentage != null) {
          damage = percentage * targetEntity.getMaxHealth();
        } else if (targetEntity instanceof Player) {
          damage = playerDamage;
        } else {
          damage = entityDamage;
        }
        damage *= mage.getDamageMultiplier();
        if (magicDamage && (magicEntityDamage || targetEntity instanceof Player)) {
          CompatibilityUtils.magicDamage(targetEntity, damage, mage.getEntity());
        } else {
          CompatibilityUtils.damage(targetEntity, damage, mage.getEntity());
        }
      }
    } finally {
      if (knockbackResistance != null && livingTarget != null) {
        AttributeInstance knockBackAttribute =
            livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
        knockBackAttribute.setBaseValue(previousKnockbackResistance);
      }
    }

    return SpellResult.CAST;
  }
  @Override
  public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);

    doVelocity = parameters.getBoolean("apply_velocity", true);
    doTeleport = parameters.getBoolean("teleport", true);
    noTarget = parameters.getBoolean("no_target", true);
    orient = parameters.getBoolean("orient", true);
    velocityOffset = ConfigurationUtils.getVector(parameters, "velocity_offset");
    locationOffset = ConfigurationUtils.getVector(parameters, "location_offset");

    try {
      String entityTypeName = parameters.getString("type", "");
      if (!entityTypeName.isEmpty()) {
        entityType = EntityType.valueOf(entityTypeName.toUpperCase());
      }
    } catch (Exception ex) {
      entityType = null;
    }

    if (parameters.contains("spawn_reason")) {
      String reasonText = parameters.getString("spawn_reason").toUpperCase();
      try {
        spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
      } catch (Exception ex) {
        context.getMage().sendMessage("Unknown spawn reason: " + reasonText);
      }
    }

    customName = parameters.getString("name");
    isBaby = parameters.getBoolean("baby", false);
    variantName = parameters.getString("variant");
    if (variantName != null && variantName.isEmpty()) {
      variantName = null;
    }
  }
Exemplo n.º 4
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;
	}