Search in sources :

Example 26 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class GoldRushListener method onPlayerInteractEvent.

@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent())
        return;
    GoldRushInstance inst = optInst.get();
    BlockSnapshot snapshot = event.getTargetBlock();
    BlockState state = snapshot.getState();
    if (!snapshot.getLocation().isPresent()) {
        return;
    }
    Location<World> targetBlock = snapshot.getLocation().get();
    if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
        Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
        if (!optTileEnt.isPresent()) {
            return;
        }
        TileEntity tileEntity = optTileEnt.get();
        Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
        if (!optTexts.isPresent()) {
            return;
        }
        List<Text> texts = optTexts.get();
        boolean unlocked = false;
        String text = texts.get(1).toPlain().toLowerCase();
        net.minecraft.item.ItemStack[] itemStacks = tf(player).inventory.mainInventory;
        for (int i = 0; i < itemStacks.length; ++i) {
            ItemStack is = itemStacks[i];
            if (is == null || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
                continue;
            }
            if (text.contains("blue")) {
                if (is.getItemDamage() != 1) {
                    continue;
                }
            } else if (text.contains("red")) {
                if (is.getItemDamage() != 0) {
                    continue;
                }
            } else {
                continue;
            }
            unlocked = true;
            itemStacks[i] = null;
            break;
        }
        if (unlocked) {
            tf(player).inventoryContainer.detectAndSendChanges();
            texts.set(2, Text.of("Locked"));
            texts.set(3, Text.of("- Unlocked -"));
            tileEntity.offer(Keys.SIGN_LINES, texts);
        }
    } else if (state.getType() == BlockTypes.LEVER) {
        Task.builder().execute(() -> {
            if (inst.checkLevers())
                inst.completeGame();
        }).delayTicks(1).submit(SkreePlugin.inst());
    } else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
        event.setUseItemResult(Tristate.FALSE);
        event.setUseBlockResult(Tristate.FALSE);
        player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
        inst.payPlayer(player);
    } else if (!inst.isLocked()) {
        if (state.getType() == BlockTypes.STONE_BUTTON) {
            inst.tryToStart();
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) ItemStack(net.minecraft.item.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 27 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class JungleRaidEffectListener method onBlockBurn.

@Listener
public void onBlockBurn(ChangeBlockEvent event) {
    if (event.getCause().root() instanceof Player) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType finalType = transaction.getFinal().getState().getType();
        if (finalType != BlockTypes.FIRE) {
            continue;
        }
        Optional<JungleRaidInstance> optInst = manager.getApplicableZone(transaction.getOriginal().getLocation().get());
        if (optInst.isPresent()) {
            JungleRaidInstance inst = optInst.get();
            if (inst.isFlagEnabled(JungleRaidFlag.NO_FIRE_SPREAD)) {
                event.setCancelled(true);
            }
            break;
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 28 with Listener

use of org.spongepowered.api.event.Listener 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 29 with Listener

use of org.spongepowered.api.event.Listener 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 30 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class ItemCraftBlockingListener method onItemCraft.

@Listener
@Exclude(value = ChangeInventoryEvent.Held.class)
public void onItemCraft(ChangeInventoryEvent event) {
    event.getTransactions().forEach((t) -> {
        if (blockedItems.contains(t.getFinal().getType().getId())) {
            Optional<Player> optPlayer = event.getCause().first(Player.class);
            if (optPlayer.isPresent()) {
                Player player = optPlayer.get();
                player.sendMessage(Text.of(TextColors.RED, "This item has been disabled."));
            }
            event.setCancelled(true);
        }
    });
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) Exclude(org.spongepowered.api.event.filter.type.Exclude)

Aggregations

Listener (org.spongepowered.api.event.Listener)81 Player (org.spongepowered.api.entity.living.player.Player)36 World (org.spongepowered.api.world.World)26 Location (org.spongepowered.api.world.Location)21 ItemStack (org.spongepowered.api.item.inventory.ItemStack)18 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)17 Entity (org.spongepowered.api.entity.Entity)14 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)10 BlockType (org.spongepowered.api.block.BlockType)10 Text (org.spongepowered.api.text.Text)10 ItemStack (net.minecraft.item.ItemStack)9 Task (org.spongepowered.api.scheduler.Task)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 ItemDropper (com.skelril.nitro.item.ItemDropper)5 ModifierService (com.skelril.skree.service.ModifierService)5 RegionService (com.skelril.skree.service.RegionService)5 WorldService (com.skelril.skree.service.WorldService)5 Region (com.skelril.skree.service.internal.region.Region)5 Living (org.spongepowered.api.entity.living.Living)5 MainWorldWrapper (com.skelril.skree.content.world.main.MainWorldWrapper)4