Пример #1
0
 @Override
 public SpellResult perform(CastContext context) {
   Entity entity = context.getEntity();
   if (entity == null) {
     return SpellResult.ENTITY_REQUIRED;
   }
   Location targetLocation = context.getLocation();
   for (int i = 0; i < 2; i++) {
     if (!context.allowPassThrough(targetLocation.getBlock().getType()))
       return SpellResult.NO_TARGET;
     targetLocation.setY(targetLocation.getY() + 1);
   }
   Location location = context.findPlaceToStand(targetLocation, verticalSearchDistance, true);
   if (location == null && !safe) {
     location = context.getTargetLocation();
     location.setPitch(targetLocation.getPitch());
     location.setYaw(targetLocation.getYaw());
     verticalSearchDistance = 0;
   }
   if (location != null) {
     teleport(context, entity, location);
     return SpellResult.CAST;
   }
   return SpellResult.NO_TARGET;
 }
Пример #2
0
  @Override
  public void prepare(CastContext context, ConfigurationSection parameters) {
    track = parameters.getBoolean("track", true);
    loot = parameters.getBoolean("loot", false);
    force = parameters.getBoolean("force", false);
    setTarget = parameters.getBoolean("set_target", false);
    speed = parameters.getDouble("speed", 0);
    direction = ConfigurationUtils.getVector(parameters, "direction");
    dyOffset = parameters.getDouble("dy_offset", 0);

    if (parameters.contains("type")) {
      String mobType = parameters.getString("type");
      entityData = context.getController().getMob(mobType);
      if (entityData == null) {
        entityData =
            new com.elmakers.mine.bukkit.entity.EntityData(context.getController(), parameters);
      }
    }

    if (parameters.contains("reason")) {
      String reasonText = parameters.getString("reason").toUpperCase();
      try {
        spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText);
      } catch (Exception ex) {
        spawnReason = CreatureSpawnEvent.SpawnReason.EGG;
      }
    }
  }
Пример #3
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 SpellResult start(CastContext context) {
   if (entity == null && entityType != null) {
     Location location = context.getEyeLocation();
     setEntity(
         context.getController(),
         CompatibilityUtils.spawnEntity(location, entityType, spawnReason));
   }
   if (entity == null) {
     return SpellResult.FAIL;
   }
   return super.start(context);
 }
Пример #5
0
  @Override
  public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null || !(entity instanceof LivingEntity)) {
      return SpellResult.NO_TARGET;
    }

    LivingEntity targetEntity = (LivingEntity) entity;
    Collection<PotionEffect> currentEffects = targetEntity.getActivePotionEffects();
    for (PotionEffect effect : currentEffects) {
      if (negativeEffects.contains(effect.getType())) {
        context.registerPotionEffects(targetEntity);
        targetEntity.removePotionEffect(effect.getType());
      }
    }
    return SpellResult.CAST;
  }
Пример #6
0
  @Override
  public SpellResult step(CastContext context) {
    Block attachBlock = context.getTargetBlock();
    BlockFace direction = BlockFace.UP;
    Block targetBlock = attachBlock.getRelative(direction);
    int distance = 0;

    while (context.isTargetable(targetBlock) && distance <= MAX_SEARCH_DISTANCE) {
      distance++;
      attachBlock = targetBlock;
      targetBlock = attachBlock.getRelative(direction);
    }
    if (context.isTargetable(targetBlock)) {
      return SpellResult.NO_TARGET;
    }

    actionContext.setTargetLocation(targetBlock.getLocation());
    context.getBrush().setTarget(attachBlock.getLocation(), targetBlock.getLocation());
    return startActions();
  }
Пример #7
0
 @Override
 public void prepare(CastContext context, ConfigurationSection parameters) {
   super.prepare(context, parameters);
   direction = BlockFace.UP;
   try {
     direction = BlockFace.valueOf(parameters.getString("direction", "up").toUpperCase());
   } catch (Exception ex) {
     context.getLogger().info("Invalid search direction: " + parameters.getString("direction"));
     direction = BlockFace.DOWN;
   }
 }
Пример #8
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;
  }
  @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;
    }
  }
Пример #10
0
  @Override
  public SpellResult perform(CastContext context) {
    Block targetBlock = context.getTargetBlock();
    Entity currentEntity = current == null ? null : current.get();
    current = null;
    if (currentEntity != null) {
      currentEntity.remove();
    }

    targetBlock = targetBlock.getRelative(BlockFace.UP);

    Location spawnLocation = targetBlock.getLocation();
    Location sourceLocation = context.getLocation();
    spawnLocation.setPitch(sourceLocation.getPitch());
    spawnLocation.setYaw(sourceLocation.getYaw());

    MageController controller = context.getController();
    if (entityData == null) {
      String randomType = RandomUtils.weightedRandom(entityTypeProbability);
      try {
        entityData = controller.getMob(randomType);
        if (entityData == null) {
          entityData =
              new com.elmakers.mine.bukkit.entity.EntityData(
                  EntityType.valueOf(randomType.toUpperCase()));
        }
      } catch (Throwable ex) {
        entityData = null;
      }
    }
    if (entityData == null) {
      return SpellResult.FAIL;
    }

    if (force) {
      controller.setForceSpawn(true);
    }
    Entity spawnedEntity = null;
    try {
      spawnedEntity = entityData.spawn(context.getController(), spawnLocation, spawnReason);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    if (force) {
      controller.setForceSpawn(false);
    }

    if (spawnedEntity == null) {
      return SpellResult.FAIL;
    }

    if (!loot) {
      spawnedEntity.setMetadata("nodrops", new FixedMetadataValue(controller.getPlugin(), true));
    }
    if (speed > 0) {
      Vector motion = direction;
      if (motion == null) {
        motion = context.getDirection();
      } else {
        motion = motion.clone();
      }

      if (dyOffset != 0) {
        motion.setY(motion.getY() + dyOffset);
      }
      motion.normalize();
      motion.multiply(speed);
      CompatibilityUtils.setEntityMotion(spawnedEntity, motion);
    }

    Collection<EffectPlayer> projectileEffects = context.getEffects("spawned");
    for (EffectPlayer effectPlayer : projectileEffects) {
      effectPlayer.start(spawnedEntity.getLocation(), spawnedEntity, null, null);
    }
    context.registerForUndo(spawnedEntity);

    if (track) {
      current = new WeakReference<Entity>(spawnedEntity);
    }
    if (setTarget) {
      context.setTargetEntity(spawnedEntity);
    }
    return SpellResult.CAST;
  }
Пример #11
0
 @Override
 public SpellResult perform(CastContext context) {
   Entity sourceEntity = context.getEntity();
   Location sourceLocation = context.getEyeLocation().clone();
   Entity targetEntity = context.getTargetEntity();
   Location targetLocation = context.getTargetLocation();
   if (targetLocation != null) {
     targetLocation = targetLocation.clone();
   }
   Vector direction = context.getDirection().normalize();
   if (sourceLocation == null) {
     return SpellResult.LOCATION_REQUIRED;
   }
   if (targetSelf) {
     targetEntity = sourceEntity;
     targetLocation = sourceLocation;
   } else if (targetEntityLocation && targetEntity != null) {
     targetLocation = targetEntity.getLocation();
   }
   if (attachBlock) {
     Block previousBlock = context.getPreviousBlock();
     if (previousBlock != null) {
       Location current = targetLocation;
       targetLocation = previousBlock.getLocation();
       context.getBrush().setTarget(current, targetLocation);
     }
   }
   if (sourceOffset != null) {
     sourceLocation = sourceLocation.add(sourceOffset);
   }
   if (targetOffset != null && targetLocation != null) {
     targetLocation = targetLocation.add(targetOffset);
   }
   if (randomSourceOffset != null) {
     sourceLocation = RandomUtils.randomizeLocation(sourceLocation, randomSourceOffset);
   }
   if (randomTargetOffset != null && targetLocation != null) {
     targetLocation = RandomUtils.randomizeLocation(targetLocation, randomTargetOffset);
   }
   if (targetDirection != null && targetLocation != null) {
     targetLocation.setDirection(targetDirection);
   }
   if (sourceDirection != null) {
     sourceLocation.setDirection(sourceDirection);
     direction = sourceDirection.clone();
   }
   if (targetDirectionOffset != null && targetLocation != null) {
     targetLocation.setDirection(targetLocation.getDirection().add(targetDirectionOffset));
   }
   if (sourceDirectionOffset != null) {
     sourceLocation.setDirection(direction.add(sourceDirectionOffset));
   }
   if (sourceDirectionSpeed != null) {
     sourceLocation = sourceLocation.add(direction.clone().multiply(sourceDirectionSpeed));
   }
   if (targetDirectionSpeed != null && targetLocation != null) {
     targetLocation = targetLocation.add(direction.clone().multiply(targetDirectionSpeed));
   }
   if (sourceAtTarget && targetLocation != null) {
     sourceLocation.setX(targetLocation.getX());
     sourceLocation.setY(targetLocation.getY());
     sourceLocation.setZ(targetLocation.getZ());
     sourceLocation.setWorld(targetLocation.getWorld());
   }
   if (persistTarget) {
     context.setTargetLocation(targetLocation);
   }
   CastContext newContext =
       createContext(context, sourceEntity, sourceLocation, targetEntity, targetLocation);
   return super.perform(newContext);
 }
Пример #12
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;
	}