Search in sources :

Example 21 with Listener

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

the class RespawnServiceImpl method onPlayerRespawn.

@Listener
public void onPlayerRespawn(RespawnPlayerEvent event) {
    Player player = event.getTargetEntity();
    event.setToTransform(new Transform<>(pop(player).orElse(getDefault(player))));
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener)

Example 22 with Listener

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

the class DropClearServiceImpl method onItemSpawn.

@Listener(order = Order.POST)
public void onItemSpawn(SpawnEntityEvent event) {
    long spawnedCount = event.getEntities().stream().filter(DropClearServiceImpl.CHECK_PREDICATE).count();
    World targetWorld = event.getTargetWorld();
    long newCount = entityCount.merge(targetWorld, spawnedCount, (a, b) -> a + b);
    if (newCount > autoAmt) {
        checkedCleanup(targetWorld);
    }
}
Also used : World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 23 with Listener

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

the class RegionMarker method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        if (!block.isValid()) {
            continue;
        }
        if (block.getOriginal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (optLoc.isPresent()) {
            Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
            if (optRef.isPresent()) {
                Region ref = optRef.get();
                if (ref.isMember(player)) {
                    ref.remPoint(new RegionPoint(optLoc.get().getPosition()));
                    player.sendMessage(Text.of(TextColors.YELLOW, "Region marker deleted!"));
                }
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location) RegionPoint(com.skelril.skree.service.internal.region.RegionPoint) Listener(org.spongepowered.api.event.Listener)

Example 24 with Listener

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

the class RegionMaster method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        if (!block.isValid()) {
            continue;
        }
        if (block.getOriginal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
        if (!optRef.isPresent()) {
            continue;
        }
        Region ref = optRef.get();
        if (!ref.getFullPoints().isEmpty()) {
            block.setValid(false);
            player.sendMessage(Text.of(TextColors.RED, "You must first delete all markers!"));
        } else {
            service.rem(optLoc.get());
            player.sendMessage(Text.of(TextColors.YELLOW, "Region deleted!"));
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 25 with Listener

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

the class GoldRushListener method onChestClose.

@Listener
public void onChestClose(InteractInventoryEvent.Close event) {
    Inventory inventory = event.getTargetInventory();
    if (inventory instanceof ContainerChest) {
        IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
        if (chestInv instanceof ILockableContainer) {
            String lockCode = ((ILockableContainer) chestInv).getLockCode().getLock();
            Optional<Player> optPlayer = Optional.ofNullable(tileEntityClaimMap.remove(lockCode));
            if (optPlayer.isPresent()) {
                Player player = optPlayer.get();
                ((ILockableContainer) chestInv).setLockCode(LockCode.EMPTY_CODE);
                Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
                if (!optInst.isPresent())
                    return;
                // TODO Sponge port
                GoldRushInstance inst = optInst.get();
                List<org.spongepowered.api.item.inventory.ItemStack> toEvaluate = new ArrayList<>();
                ArrayDeque<org.spongepowered.api.item.inventory.ItemStack> toReturn = new ArrayDeque<>();
                for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
                    ItemStack stack = chestInv.getStackInSlot(i);
                    if (stack == null) {
                        continue;
                    }
                    if (stack.getItem() instanceof CofferItem) {
                        toEvaluate.add(tf(stack));
                    } else {
                        toReturn.add(tf(stack));
                    }
                    chestInv.setInventorySlotContents(i, null);
                }
                BigDecimal value = BigDecimal.ZERO;
                for (org.spongepowered.api.item.inventory.ItemStack stack : toEvaluate) {
                    value = value.add(new BigDecimal(CofferValueMap.inst().getValue(Collections.singleton(stack)).orElse(BigInteger.ZERO)));
                }
                inst.cofferRisk.put(player.getUniqueId(), value);
                for (Inventory slot : player.getInventory().slots()) {
                    if (toReturn.isEmpty()) {
                        break;
                    }
                    if (slot.size() == 0) {
                        slot.set(toReturn.poll());
                    }
                }
                if (!toReturn.isEmpty()) {
                    new ItemDropper(player.getLocation()).dropStacks(toReturn, SpawnTypes.PLUGIN);
                }
                player.sendMessage(Text.of(TextColors.YELLOW, "You are now risking ", format(value), " coffers."));
                MessageChannel targetChannel = inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
                targetChannel.send(Text.of(TextColors.YELLOW, "Group risk of ", format(inst.getTotalRisk()), " coffers."));
                targetChannel.send(Text.of(TextColors.YELLOW, "Risk of lava ", inst.getChanceOfLava(), " / 100."));
                targetChannel.send(Text.of(TextColors.YELLOW, "Security system delay ", inst.getBaseTime(), " +/- ", inst.getTimeVariance(), " seconds."));
            }
        }
    }
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ILockableContainer(net.minecraft.world.ILockableContainer) ContainerChest(net.minecraft.inventory.ContainerChest) IInventory(net.minecraft.inventory.IInventory) Player(org.spongepowered.api.entity.living.player.Player) BigDecimal(java.math.BigDecimal) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) CofferItem(com.skelril.skree.content.registry.item.currency.CofferItem) ItemStack(net.minecraft.item.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Listener(org.spongepowered.api.event.Listener)

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