Search in sources :

Example 11 with Player

use of org.spongepowered.api.entity.living.player.Player 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 12 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class ZoneSlaveOrb method onDropItem.

@Listener
public void onDropItem(DropItemEvent.Dispense event) {
    event.getEntities().stream().filter(entity -> entity instanceof Item).forEach(entity -> {
        ItemStack stack = ((EntityItem) entity).getEntityItem();
        if (isZoneSlaveItem(stack)) {
            Optional<Player> optPlayer = event.getCause().first(Player.class);
            if (optPlayer.isPresent()) {
                Player player = optPlayer.get();
                if (!notifyGroupOwner(stack, player, false)) {
                }
                player.sendMessage(Text.of(TextColors.RED, "You've declined your group invite."));
            }
            entity.remove();
        }
    });
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) CustomItem(com.skelril.nitro.registry.item.CustomItem) Item(org.spongepowered.api.entity.Item) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) EventAwareContent(com.skelril.nitro.selector.EventAwareContent) Tristate(org.spongepowered.api.util.Tristate) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) SkreePlugin(com.skelril.skree.SkreePlugin) Text(org.spongepowered.api.text.Text) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Task(org.spongepowered.api.scheduler.Task) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) CreativeTabs(net.minecraft.creativetab.CreativeTabs) Player(org.spongepowered.api.entity.living.player.Player) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Listener(org.spongepowered.api.event.Listener) TextColors(org.spongepowered.api.text.format.TextColors) First(org.spongepowered.api.event.filter.cause.First) ZoneItemUtil(com.skelril.skree.content.registry.item.zone.ZoneItemUtil) EntityItem(net.minecraft.entity.item.EntityItem) CustomItem(com.skelril.nitro.registry.item.CustomItem) Item(org.spongepowered.api.entity.Item) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Listener(org.spongepowered.api.event.Listener)

Example 13 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class ZoneItemUtil method notifyGroupOwner.

public static boolean notifyGroupOwner(ItemStack stack, Player holder, boolean joined) {
    Validate.isTrue(isZoneSlaveItem(stack));
    Optional<Player> optPlayer = getGroupOwner(stack);
    if (optPlayer.isPresent()) {
        Player player = optPlayer.get();
        if (joined) {
            if (incrementCount(stack, player)) {
                player.sendMessage(Text.of(TextColors.GOLD, holder.getName() + " has accepted your invitation."));
            }
        } else {
            if (!isAttuned(stack) || decrementCount(stack, player)) {
                player.sendMessage(Text.of(TextColors.RED, holder.getName() + " has declined your invitation."));
            }
        }
        return true;
    }
    return false;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player)

Example 14 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class CursedMineInstance method drain.

public void drain() {
    for (Entity e : getContained(Carrier.class)) {
        // TODO Inventory API not fully implemented
        if (!(e instanceof Player)) {
            continue;
        }
        Inventory eInventory = ((Carrier) e).getInventory();
        if (e instanceof Player) {
            Location<World> playerLoc = e.getLocation();
            // Emerald
            long diff = System.currentTimeMillis() - lastActivation;
            if (playerLoc.getY() < 30 && (lastActivation == 0 || diff <= timeTilPumpShutoff * .35 || diff >= timeTilPumpShutoff * 5)) {
                PositionRandomizer randomizer = new PositionRandomizer(5);
                for (int i = 0; i < Probability.getRangedRandom(2, 5); i++) {
                    Vector3i targetPos;
                    do {
                        targetPos = randomizer.createPosition3i(playerLoc.getPosition());
                    } while (getRegion().getExtent().getBlockType(targetPos) != BlockTypes.AIR);
                    Entity entity = getRegion().getExtent().createEntity(EntityTypes.BLAZE, targetPos);
                    getRegion().getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.MOB_SPAWNER).build()).build());
                }
            }
        }
        for (int i = 0; i < (eInventory.size() / 2) - 2 || i < 1; i++) {
            if (e instanceof Player) {
                if (Probability.getChance(15) && checkInventory((Player) e)) {
                    ((Player) e).sendMessage(Text.of(TextColors.YELLOW, "Divine intervention protects some of your items."));
                    continue;
                }
            }
            // Iron
            eInventory.query(ItemTypes.IRON_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.IRON_ORE).poll(Probability.getRandom(4));
            eInventory.query(ItemTypes.IRON_INGOT).poll(Probability.getRandom(8));
            // Gold
            eInventory.query(ItemTypes.GOLD_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.GOLD_ORE).poll(Probability.getRandom(4));
            eInventory.query(ItemTypes.GOLD_INGOT).poll(Probability.getRandom(10));
            eInventory.query(ItemTypes.GOLD_NUGGET).poll(Probability.getRandom(80));
            // Redstone
            eInventory.query(ItemTypes.REDSTONE_ORE).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.REDSTONE).poll(Probability.getRandom(34));
            // Lap
            eInventory.query(ItemTypes.LAPIS_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.LAPIS_ORE).poll(Probability.getRandom(4));
            eInventory.query(LAPIS_DYE).poll(Probability.getRandom(34));
            // Diamond
            eInventory.query(ItemTypes.DIAMOND_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.DIAMOND_ORE).poll(Probability.getRandom(4));
            eInventory.query(ItemTypes.DIAMOND).poll(Probability.getRandom(16));
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) PositionRandomizer(com.skelril.nitro.position.PositionRandomizer) Player(org.spongepowered.api.entity.living.player.Player) Vector3i(com.flowpowered.math.vector.Vector3i) Carrier(org.spongepowered.api.item.inventory.Carrier) World(org.spongepowered.api.world.World) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 15 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class WildernessTeleportCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        src.sendMessage(Text.of("You must be a player to use this command!"));
        return CommandResult.empty();
    }
    if (!src.hasPermission("skree.world.wilderness.teleport")) {
        src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
        return CommandResult.empty();
    }
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    WildernessWorldWrapper wrapper = service.getEffectWrapper(WildernessWorldWrapper.class).get();
    int targetLevel = args.<Integer>getOne("target level").get();
    if (targetLevel < 1) {
        src.sendMessage(Text.of("The target level must be at least 1."));
        return CommandResult.empty();
    }
    Optional<World> optWorld = Sponge.getServer().getWorld(args.<String>getOne("world type").get());
    if (!optWorld.isPresent()) {
        src.sendMessage(Text.of("That world is not currently accessible."));
        return CommandResult.empty();
    }
    World world = optWorld.get();
    int variance = (int) (Math.sqrt(targetLevel) * 2);
    int negative = Probability.getChance(3) ? -1 : 1;
    targetLevel += Probability.getRandom(variance) * negative;
    Player player = (Player) src;
    for (int i = 0; i < 2; ++i) {
        tf(player).hurtResistantTime = 0;
        player.damage(wrapper.getDamageMod(targetLevel) * 3, DamageSource.builder().type(DAMAGE_TYPE).build());
    }
    if (player.get(Keys.HEALTH).orElse(0D) > 0) {
        int unit = wrapper.getLevelUnit(world);
        Location<World> dest;
        do {
            int x = getLevelCoord(targetLevel, unit);
            int z = getLevelCoord(targetLevel, unit);
            dest = SafeTeleportHelper.getSafeDest(new Location<>(world, x, 60, z)).orElse(null);
        } while (dest == null);
        player.setLocation(dest);
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService)

Aggregations

Player (org.spongepowered.api.entity.living.player.Player)113 Listener (org.spongepowered.api.event.Listener)34 ItemStack (org.spongepowered.api.item.inventory.ItemStack)28 Entity (org.spongepowered.api.entity.Entity)25 World (org.spongepowered.api.world.World)19 BigDecimal (java.math.BigDecimal)16 Text (org.spongepowered.api.text.Text)13 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)12 Vector3d (com.flowpowered.math.vector.Vector3d)10 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)10 Living (org.spongepowered.api.entity.living.Living)10 Location (org.spongepowered.api.world.Location)10 List (java.util.List)9 MarketService (com.skelril.skree.service.MarketService)8 Optional (java.util.Optional)8 ItemStack (net.minecraft.item.ItemStack)8 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 TextColors (org.spongepowered.api.text.format.TextColors)8 TEAccount (com.erigitic.config.TEAccount)7 ArrayList (java.util.ArrayList)7