Search in sources :

Example 1 with SpongePlayer

use of com.sk89q.worldedit.sponge.SpongePlayer in project Skree by Skelril.

the class SkyWarsListener method onInteract.

@Listener
public void onInteract(InteractBlockEvent event, @First Player player) {
    Optional<SkyWarsInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    SkyWarsInstance inst = optInst.get();
    if (inst.getState() != SkyWarsState.IN_PROGRESS) {
        return;
    }
    Optional<SkyWarsPlayerData> optPlayerData = inst.getPlayerData(player);
    if (!optPlayerData.isPresent()) {
        return;
    }
    SkyWarsPlayerData playerData = optPlayerData.get();
    Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optStack.isPresent()) {
        return;
    }
    ItemStack stack = optStack.get();
    if (stack.getItem() == CustomItemTypes.SKY_FEATHER) {
        Vector3d vel = EntityDirectionUtil.getFacingVector(player);
        Optional<SkyFeather.Data> optData = SkyFeather.getDataFor(stack);
        if (!optData.isPresent()) {
            return;
        }
        SkyFeather.Data data = optData.get();
        double radius = data.radius;
        double flight = data.flight;
        double pushBack = data.pushBack;
        if (event instanceof InteractBlockEvent.Primary.MainHand) {
            if (!playerData.canFly()) {
                return;
            }
            vel = vel.mul(flight);
            player.setVelocity(vel);
            playerData.stopFlight(250);
        } else if (event instanceof InteractBlockEvent.Secondary.MainHand) {
            if (!playerData.canPushBack()) {
                return;
            }
            vel = vel.mul(pushBack * 2);
            SpongePlayer spongePlayer = SpongeWorldEdit.inst().wrapPlayer(player);
            Collection<Entity> possibleTargets = inst.getContained(Player.class, Chicken.class);
            possibleTargets.remove(player);
            ParticleEffect radiationEffect = ParticleEffect.builder().type(ParticleTypes.FLAME).quantity(1).build();
            TargetBlock targetBlock = new TargetBlock(spongePlayer, 50, .2);
            while (targetBlock.getNextBlock() != null) {
                BlockWorldVector weBlock = targetBlock.getCurrentBlock();
                Location<World> loc = new Location<>(inst.getRegion().getExtent(), weBlock.getX(), weBlock.getY(), weBlock.getZ());
                for (int i = 0; i < 10; ++i) {
                    inst.getRegion().getExtent().spawnParticles(radiationEffect, loc.getPosition().add(Probability.getRangedRandom(0, 1.0), Probability.getRangedRandom(0, 1.0), Probability.getRangedRandom(0, 1.0)));
                }
                for (Entity aEntity : possibleTargets) {
                    if (aEntity.getLocation().getPosition().distanceSquared(loc.getPosition()) <= Math.pow(radius, 2)) {
                        if (aEntity instanceof Player) {
                            Player aPlayer = (Player) aEntity;
                            if (inst.isFriendlyFire(player, aPlayer)) {
                                continue;
                            }
                            // Handle Sender
                            playerData.stopPushBack(250);
                            player.sendMessage(Text.of(TextColors.YELLOW, "You push back: ", aPlayer.getName(), "!"));
                            // Handle Target
                            aPlayer.setVelocity(vel);
                            Optional<SkyWarsPlayerData> optAPlayerData = inst.getPlayerData(aPlayer);
                            if (optAPlayerData.isPresent()) {
                                SkyWarsPlayerData aPlayerData = optAPlayerData.get();
                                if (aPlayerData.canDefrost()) {
                                    aPlayerData.stopFlight();
                                }
                            }
                        } else {
                            inst.awardPowerup(player, stack);
                            aEntity.remove();
                        }
                    }
                }
            }
        }
        tf(stack).attemptDamageItem(1, new Random());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) SkyFeather(com.skelril.skree.content.registry.item.minigame.SkyFeather) TargetBlock(com.sk89q.worldedit.util.TargetBlock) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) Random(java.util.Random) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) Player(org.spongepowered.api.entity.living.player.Player) Optional(java.util.Optional) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) BlockWorldVector(com.sk89q.worldedit.BlockWorldVector) Vector3d(com.flowpowered.math.vector.Vector3d) Collection(java.util.Collection) Chicken(org.spongepowered.api.entity.living.animal.Chicken) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 2 with SpongePlayer

use of com.sk89q.worldedit.sponge.SpongePlayer in project RedProtect by FabioZumbi12.

the class WEListener method pasteWithWE.

public static void pasteWithWE(Player p, File f) throws DataException {
    SpongePlayer sp = SpongeWorldEdit.inst().wrapPlayer(p);
    SpongeWorld ws = SpongeWorldEdit.inst().getWorld(p.getWorld());
    LocalSession session = SpongeWorldEdit.inst().getSession(p);
    Closer closer = Closer.create();
    try {
        ClipboardFormat format = ClipboardFormat.findByAlias("schematic");
        FileInputStream fis = closer.register(new FileInputStream(f));
        BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
        ClipboardReader reader = format.getReader(bis);
        WorldData worldData = ws.getWorldData();
        Clipboard clipboard = reader.read(ws.getWorldData());
        session.setClipboard(new ClipboardHolder(clipboard, worldData));
        ClipboardHolder holder = session.getClipboard();
        Operation op = holder.createPaste(session.createEditSession(sp), ws.getWorldData()).to(session.getPlacementPosition(sp)).build();
        Operations.completeLegacy(op);
    } catch (IOException | MaxChangedBlocksException | EmptyClipboardException | IncompleteRegionException e) {
        e.printStackTrace();
    }
}
Also used : Closer(com.sk89q.worldedit.util.io.Closer) SpongePlayer(com.sk89q.worldedit.sponge.SpongePlayer) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) WorldData(com.sk89q.worldedit.world.registry.WorldData) Operation(com.sk89q.worldedit.function.operation.Operation) IOException(java.io.IOException) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) FileInputStream(java.io.FileInputStream) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) EmptyClipboardException(com.sk89q.worldedit.EmptyClipboardException) BufferedInputStream(java.io.BufferedInputStream) SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)

Aggregations

SpongePlayer (com.sk89q.worldedit.sponge.SpongePlayer)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 BlockWorldVector (com.sk89q.worldedit.BlockWorldVector)1 EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)1 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)1 Operation (com.sk89q.worldedit.function.operation.Operation)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 SpongeWorld (com.sk89q.worldedit.sponge.SpongeWorld)1 TargetBlock (com.sk89q.worldedit.util.TargetBlock)1 Closer (com.sk89q.worldedit.util.io.Closer)1 WorldData (com.sk89q.worldedit.world.registry.WorldData)1 SkyFeather (com.skelril.skree.content.registry.item.minigame.SkyFeather)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1