@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; }
@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 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; }