Search in sources :

Example 6 with Listener

use of org.spongepowered.api.event.Listener in project TotalEconomy by Erigitic.

the class TEJobManager method onPlayerFish.

/**
     * Used for the catch option in jobs. Will check if the job has the catch node and if it does it will check if the
     * item that was caught is present in the config of the player's job. If it is, it will grab the job exp reward as
     * well as the pay.
     *
     * @param event FishingEvent.Stop
     */
@Listener
public void onPlayerFish(FishingEvent.Stop event) {
    if (event.getCause().first(Player.class).isPresent()) {
        // no transaction, so execution can stop
        if (event.getItemStackTransaction().size() == 0) {
            return;
        }
        Transaction<ItemStackSnapshot> itemTransaction = event.getItemStackTransaction().get(0);
        ItemStack itemStack = itemTransaction.getFinal().createStack();
        Player player = event.getCause().first(Player.class).get();
        UUID playerUUID = player.getUniqueId();
        String playerJob = getPlayerJob(player);
        Optional<TEJob> optPlayerJob = getJob(playerJob, true);
        if (optPlayerJob.isPresent()) {
            if (itemStack.get(FishData.class).isPresent()) {
                FishData fishData = itemStack.get(FishData.class).get();
                String fishName = fishData.type().get().getName();
                Optional<TEActionReward> reward = Optional.empty();
                List<String> sets = optPlayerJob.get().getSets();
                for (String s : sets) {
                    Optional<TEJobSet> optSet = getJobSet(s);
                    if (!optSet.isPresent()) {
                        logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
                        continue;
                    }
                    reward = optSet.get().getRewardFor("catch", fishName);
                }
                if (reward.isPresent()) {
                    int expAmount = reward.get().getExpReward();
                    BigDecimal payAmount = reward.get().getMoneyReward();
                    boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
                    TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                    if (notify) {
                        notifyPlayer(player, payAmount);
                    }
                    addExp(player, expAmount);
                    playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
                    checkForLevel(player);
                }
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal) FishData(org.spongepowered.api.data.manipulator.mutable.item.FishData) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 7 with Listener

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

the class ScrollOfSummation 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;
    }
    ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    net.minecraft.item.ItemStack[] pInv = tf(player).inventory.mainInventory;
    Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute((ItemStack[]) (Object[]) pInv);
    if (optCompacted.isPresent()) {
        Task.builder().execute(() -> {
            ItemStack[] nInv = optCompacted.get();
            for (int i = 0; i < pInv.length; ++i) {
                pInv[i] = tf(nInv[i]);
            }
            tf(player).inventoryContainer.detectAndSendChanges();
            tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
            player.sendMessage(Text.of(TextColors.GOLD, "The scroll glows brightly before turning to dust..."));
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemCompactor(com.skelril.nitro.item.ItemCompactor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 8 with Listener

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

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

Example 10 with Listener

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

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