Search in sources :

Example 11 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class JungleRaidEffectListener method onPlayerInteract.

@Listener(order = Order.LATE)
public void onPlayerInteract(InteractBlockEvent.Primary.MainHand event, @First Player player) {
    Optional<Location<World>> optBlockLoc = event.getTargetBlock().getLocation();
    if (!optBlockLoc.isPresent()) {
        return;
    }
    Location<World> blockLoc = optBlockLoc.get();
    Optional<JungleRaidInstance> optInst = manager.getApplicableZone(blockLoc);
    if (!optInst.isPresent()) {
        return;
    }
    JungleRaidInstance inst = optInst.get();
    if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && player.getUniqueId().equals(inst.getFlagData().titan)) {
        if (blockLoc.getBlockType() == BlockTypes.BEDROCK) {
            return;
        }
        // TODO Convert to the Sponge API
        ((net.minecraft.world.World) blockLoc.getExtent()).destroyBlock(new BlockPos(blockLoc.getX(), blockLoc.getY(), blockLoc.getZ()), true);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 12 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class SkullOfTheFallen method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    if (this != optHeldItem.get().getItem()) {
        return;
    }
    Location<World> pLoc = player.getLocation();
    Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
    if (optWorldService.isPresent()) {
        WorldService worldService = optWorldService.get();
        WildernessWorldWrapper wrapper = worldService.getEffectWrapper(WildernessWorldWrapper.class).get();
        Optional<Integer> optLevel = wrapper.getLevel(pLoc);
        if (optLevel.isPresent()) {
            int level = optLevel.get();
            DecimalFormat df = new DecimalFormat("#,###.##");
            player.sendMessages(Text.of(TextColors.YELLOW, "Wilderness level: " + level), Text.of(TextColors.YELLOW, "PvP Enabled: " + (wrapper.allowsPvP(level) ? "Yes" : "No")), Text.of(TextColors.YELLOW, "Mob damage: +" + df.format(wrapper.getDamageMod(level))), Text.of(TextColors.YELLOW, "Mob health: x" + df.format(wrapper.getHealthMod(level))), Text.of(TextColors.YELLOW, "Ore modifier: x" + df.format(wrapper.getOreMod(wrapper.getDropTier(level)))), Text.of(TextColors.YELLOW, "Drop modifier: x" + df.format(level * wrapper.getDropMod(wrapper.getDropTier(level)))));
        } else {
            player.sendMessage(Text.of(TextColors.RED, "You're not in a Wilderness world!"));
        }
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) WildernessWorldWrapper(com.skelril.skree.content.world.wilderness.WildernessWorldWrapper) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService) Listener(org.spongepowered.api.event.Listener)

Example 13 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class WorldListCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    List<WorldEffectWrapper> worldEffectWrapperList = service.getEffectWrappers().stream().sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).collect(Collectors.toList());
    for (WorldEffectWrapper wrapper : worldEffectWrapperList) {
        String worldType = wrapper.getName();
        if (!src.hasPermission("skree.world." + worldType.toLowerCase() + ".teleport")) {
            continue;
        }
        src.sendMessage(Text.of(TextColors.GOLD, "Available ", worldType, " worlds (click to teleport):"));
        for (World world : wrapper.getWorlds()) {
            String worldName = world.getName();
            String prettyName = worldName.replaceAll("_", " ");
            src.sendMessage(Text.of(TextColors.YELLOW, TextActions.runCommand("/world " + worldName), TextActions.showText(Text.of("Teleport to " + prettyName)), " - ", prettyName));
        }
    }
    return CommandResult.success();
}
Also used : WorldService(com.skelril.skree.service.WorldService) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) List(java.util.List) WorldEffectWrapper(com.skelril.skree.service.internal.world.WorldEffectWrapper) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) World(org.spongepowered.api.world.World) TextColors(org.spongepowered.api.text.format.TextColors) WorldEffectWrapper(com.skelril.skree.service.internal.world.WorldEffectWrapper) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService)

Example 14 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class TeleportCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player target;
    if (src instanceof Player) {
        target = (Player) src;
    } else {
        src.sendMessage(Text.of(TextColors.RED, "You are not a player and teleporting other players is not currently supported!"));
        return CommandResult.empty();
    }
    Optional<Vector3d> dest = args.getOne("dest");
    Vector3d rotation = new Vector3d(0, 0, 0);
    World targetExtent = target.getWorld();
    String destStr;
    if (dest.isPresent()) {
        if (!src.hasPermission("skree.teleport.teleport.coord")) {
            src.sendMessage(Text.of(TextColors.RED, "You do not have permission to teleport by coordinates here."));
            return CommandResult.empty();
        }
        destStr = dest.get().toString();
    } else {
        if (!src.hasPermission("skree.teleport.teleport.player")) {
            src.sendMessage(Text.of(TextColors.RED, "You do not have permission to teleport to players here."));
            return CommandResult.empty();
        }
        Player player = args.<Player>getOne("dest-player").get();
        targetExtent = player.getWorld();
        rotation = player.getRotation();
        dest = Optional.of(player.getLocation().getPosition());
        destStr = player.getName();
    }
    Optional<Location<World>> optSafeDest = SafeTeleportHelper.getSafeDest(target, new Location<>(targetExtent, dest.get()));
    if (optSafeDest.isPresent()) {
        if (!WorldEntryPermissionCheck.checkDestination(target, optSafeDest.get().getExtent())) {
            src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
            return CommandResult.empty();
        }
        target.setLocationAndRotation(optSafeDest.get(), rotation);
        src.sendMessage(Text.of(TextColors.YELLOW, "Teleported to " + destStr + '.'));
    } else {
        src.sendMessage(Text.of(TextColors.RED, "The requested destination is unsafe."));
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Vector3d(com.flowpowered.math.vector.Vector3d) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Example 15 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class Luminositor method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (optHeldItem.isPresent()) /* && optClickedPosition.isPresent() */
    {
        if (this.equals(optHeldItem.get().getItem())) {
            Direction dir = event.getTargetSide();
            Optional<Location<World>> optTargetBlockLoc = event.getTargetBlock().getLocation();
            if (!optTargetBlockLoc.isPresent()) {
                return;
            }
            Location<World> targetBlockLoc = optTargetBlockLoc.get();
            Vector3i targPos = targetBlockLoc.getBlockPosition().add(dir.toVector3d().toInt());
            Location<World> trueTargBlock = new Location<>(targetBlockLoc.getExtent(), targPos);
            int lightLevel = LightLevelUtil.getMaxLightLevel(trueTargBlock).get();
            TextColor color;
            if (lightLevel >= 12) {
                color = TextColors.GREEN;
            } else if (lightLevel >= 8) {
                color = TextColors.RED;
            } else {
                color = TextColors.DARK_RED;
            }
            // TODO system message.color(color)
            player.sendMessage(Text.of(TextColors.YELLOW, "Light level: ", color, lightLevel));
            event.setUseBlockResult(Tristate.FALSE);
        }
    }
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) TextColor(org.spongepowered.api.text.format.TextColor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

World (org.spongepowered.api.world.World)81 Listener (org.spongepowered.api.event.Listener)24 Location (org.spongepowered.api.world.Location)23 Entity (org.spongepowered.api.entity.Entity)18 Player (org.spongepowered.api.entity.living.player.Player)18 Vector3i (com.flowpowered.math.vector.Vector3i)11 WorldService (com.skelril.skree.service.WorldService)11 BlockType (org.spongepowered.api.block.BlockType)10 ItemStack (org.spongepowered.api.item.inventory.ItemStack)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)8 ArrayList (java.util.ArrayList)7 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 BlockState (org.spongepowered.api.block.BlockState)7 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)6 Living (org.spongepowered.api.entity.living.Living)5 Monster (org.spongepowered.api.entity.living.monster.Monster)5 ItemDropper (com.skelril.nitro.item.ItemDropper)4 ModifierService (com.skelril.skree.service.ModifierService)4 IOException (java.io.IOException)4