use of org.spongepowered.api.util.blockray.BlockRayHit in project modules-extra by CubeEngine.
the class InvasionCommand method invasion.
@Command(desc = "Spawns a mob next to every player on the server")
public void invasion(CommandSource context, String mob) {
EntityType entityType = em.mob(mob, context.getLocale());
if (entityType == null) {
i18n.send(context, MessageType.NEGATIVE, "EntityType {input} not found", mob);
return;
}
Sponge.getCauseStackManager().pushCause(context);
for (Player player : Sponge.getServer().getOnlinePlayers()) {
Optional<BlockRayHit<World>> end = BlockRay.from(player).stopFilter(BlockRay.onlyAirFilter()).distanceLimit(module.getConfig().command.invasion.distance).build().end();
if (end.isPresent()) {
Location<World> location = end.get().getLocation();
Entity entity = location.getExtent().createEntity(entityType, location.getPosition());
location.getExtent().spawnEntity(entity);
}
}
}
use of org.spongepowered.api.util.blockray.BlockRayHit in project modules-extra by CubeEngine.
the class NukeCommand method nuke.
@Command(desc = "Makes a carpet of TNT fall on a player or where you're looking")
public void nuke(CommandSource context, @Optional Integer diameter, @Named({ "player", "p" }) Player player, @Named({ "height", "h" }) Integer height, @Named({ "range", "r" }) Integer range, @Flag boolean unsafe, @Flag boolean quiet) {
Location<World> location;
range = range == null ? 4 : range;
height = height == null ? 5 : height;
diameter = diameter == null ? 5 : diameter;
diameter = Math.min(10, diameter);
if (range != 4 && !context.hasPermission(module.perms().COMMAND_NUKE_CHANGE_RANGE.getId())) {
i18n.send(context, NEGATIVE, "You are not allowed to change the explosion range of the nuke carpet!");
return;
}
if (range < 0 || range > this.module.getConfig().command.nuke.maxExplosionRange) {
i18n.send(context, NEGATIVE, "The explosion range can't be less than 0 or greater than {integer}", this.module.getConfig().command.nuke.maxExplosionRange);
return;
}
if (player != null) {
if (!context.equals(player) && !context.hasPermission(module.perms().COMMAND_NUKE_OTHER.getId())) {
i18n.send(context, NEGATIVE, "You are not allowed to specify a player!");
return;
}
location = ((Player) context).getLocation();
} else {
if (!(context instanceof Player)) {
i18n.send(context, NEGATIVE, "This command can only be used by a player!");
return;
}
java.util.Optional<BlockRayHit<World>> end = BlockRay.from(((Player) context)).stopFilter(onlyAirFilter()).distanceLimit(100).build().end();
if (!end.isPresent()) {
throw new IllegalStateException();
}
location = end.get().getLocation();
}
location = this.getSpawnLocation(location, height);
Shape aShape = new Cuboid(new Vector3d(location.getX() + .5, location.getY() + .5, location.getZ() + .5), diameter, 1, diameter);
int blockAmount = this.spawnNuke(aShape, location.getExtent(), range, unsafe);
if (!quiet) {
i18n.send(context, POSITIVE, "You spawned {integer} blocks of tnt.", blockAmount);
}
}
use of org.spongepowered.api.util.blockray.BlockRayHit in project modules-extra by CubeEngine.
the class PlayerCommands method lightning.
@Command(alias = "strike", desc = "Throws a lightning bolt at a player or where you're looking")
public void lightning(CommandSource context, @Optional Integer damage, @Named({ "player", "p" }) Player player, @Named({ "fireticks", "f" }) Integer seconds, @Flag boolean unsafe) {
damage = damage == null ? -1 : damage;
if (damage != -1 && !context.hasPermission(module.perms().COMMAND_LIGHTNING_PLAYER_DAMAGE.getId())) {
i18n.send(context, NEGATIVE, "You are not allowed to specify the damage!");
return;
}
if ((damage != -1 && damage < 0) || damage > 20) {
i18n.send(context, NEGATIVE, "The damage value has to be a number from 1 to 20");
return;
}
if (unsafe && !context.hasPermission(module.perms().COMMAND_LIGHTNING_UNSAFE.getId())) {
i18n.send(context, NEGATIVE, "You are not allowed to use the unsafe flag");
return;
}
Location<World> location;
if (player != null) {
location = player.getLocation();
player.offer(Keys.FIRE_TICKS, 20 * (seconds == null ? 0 : seconds));
if (damage != -1) {
// TODO better source
player.damage(damage, DamageSource.builder().type(DamageTypes.CONTACT).build());
}
} else {
if (!(context instanceof Player)) {
i18n.send(context, NEGATIVE, "This command can only be used by a player!");
return;
}
java.util.Optional<BlockRayHit<World>> end = BlockRay.from(((Player) context)).distanceLimit(module.getConfig().command.lightning.distance).stopFilter(BlockRay.onlyAirFilter()).build().end();
if (end.isPresent()) {
location = end.get().getLocation();
} else {
throw new IllegalStateException();
}
}
Entity entity = location.getExtent().createEntity(EntityTypes.LIGHTNING, location.getPosition());
if (!unsafe) {
((Lightning) entity).setEffect(true);
}
Sponge.getCauseStackManager().pushCause(context);
location.getExtent().spawnEntity(entity);
}
use of org.spongepowered.api.util.blockray.BlockRayHit in project core by CubeEngine.
the class LocationUtil method getBlockInSight.
/**
* Returns the block in sight.
* When in fluids returns the first Air or Solid Block
* else returns the first Solid or Fluid Block
*
* @param player the looking player
* @return the block in sight
*/
public static Location<World> getBlockInSight(Player player) {
BlockType headIn = player.getLocation().getRelative(UP).getBlockType();
List<BlockType> fluidBlocks = Sponge.getRegistry().getAllOf(FluidType.class).stream().map(FluidType::getBlockTypeBase).filter(Optional::isPresent).map(Optional::get).collect(toList());
boolean headInFluid = fluidBlocks.contains(headIn);
Iterator<BlockRayHit<World>> it = BlockRay.from(player).distanceLimit(500).iterator();
BlockRayHit<World> next = null;
while (it.hasNext()) {
next = it.next();
BlockType nextType = next.getLocation().getBlockType();
if (fluidBlocks.contains(nextType)) {
if (!headInFluid) {
break;
}
} else if (canPass(nextType)) {
if (BlockTypes.AIR.equals(nextType) && headInFluid) {
break;
}
} else {
break;
}
}
return next == null ? null : next.getLocation();
}
use of org.spongepowered.api.util.blockray.BlockRayHit in project core by CubeEngine.
the class LocationUtil method getBlockBehindWall.
public static Optional<Location<World>> getBlockBehindWall(Player player, int maxRange, int maxWallThickness) {
Iterator<BlockRayHit<World>> it = BlockRay.from(player).distanceLimit(maxRange + maxWallThickness).iterator();
boolean wallHit = false;
int blocks = 0;
Location<World> loc = null;
while (it.hasNext()) {
blocks++;
if (!wallHit && blocks > maxRange) {
break;
}
BlockRayHit<World> hit = it.next();
Location<World> curLoc = hit.getLocation();
BlockType blockType = curLoc.getBlockType();
if (!wallHit) {
if (!canPass(blockType)) {
wallHit = true;
}
} else {
if (canPass(blockType) && canPass(curLoc.getRelative(UP).getBlockType())) {
loc = curLoc;
break;
}
}
}
return Optional.ofNullable(loc);
}
Aggregations