Search in sources :

Example 81 with Player

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

the class MarketUntrackItemComand 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();
    }
    Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
        return CommandResult.empty();
    }
    MarketService service = optService.get();
    Optional<ItemStack> held = ((Player) src).getItemInHand(HandTypes.MAIN_HAND);
    if (!held.isPresent()) {
        src.sendMessage(Text.of(TextColors.RED, "You are not holding an item."));
        return CommandResult.empty();
    }
    ItemStack item = held.get();
    if (service.remItem(item)) {
        src.sendMessage(Text.of(TextColors.YELLOW, "Your held item is no longer being tracked."));
    } else {
        src.sendMessage(Text.of(TextColors.RED, "Your held item is not tracked."));
        return CommandResult.empty();
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) MarketService(com.skelril.skree.service.MarketService)

Example 82 with Player

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

the class ZoneMasterOrb method onBlockInteract.

@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<org.spongepowered.api.item.inventory.ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optItemStack.isPresent()) {
        return;
    }
    ItemStack itemStack = tf(optItemStack.get());
    if (!isZoneMasterItem(itemStack)) {
        return;
    }
    if (isAttuned(itemStack)) {
        if (isInInstanceWorld(player)) {
            player.sendMessage(Text.of(TextColors.RED, "You cannot start an instance from within an instance."));
            event.setCancelled(true);
            return;
        }
        Optional<ZoneService> optService = Sponge.getServiceManager().provide(ZoneService.class);
        if (optService.isPresent()) {
            Task.builder().execute(() -> {
                ZoneService service = optService.get();
                List<Player> group = new ArrayList<>();
                group.add(player);
                for (Player aPlayer : Sponge.getServer().getOnlinePlayers()) {
                    ItemStack[] itemStacks = tf(aPlayer).inventory.mainInventory;
                    for (ItemStack aStack : itemStacks) {
                        if (!hasSameZoneID(itemStack, aStack)) {
                            continue;
                        }
                        if (isAttuned(aStack) && isZoneSlaveItem(aStack)) {
                            Optional<Player> optZoneOwner = getGroupOwner(aStack);
                            if (optZoneOwner.isPresent()) {
                                group.add(aPlayer);
                                break;
                            }
                        }
                    }
                }
                for (int i = group.size() - 1; i >= 0; --i) {
                    purgeZoneItems(group.get(i), itemStack);
                    // createLightningStrike(group.get(i)); SpongeCommon/420
                    saveLocation(group.get(i));
                    getMainWorldWrapper().getLobby().add(group.get(i));
                }
                service.requestZone(getZone(itemStack).get(), group, () -> {
                    getMainWorldWrapper().getLobby().remove(group);
                }, result -> {
                    if (result.isPresent()) {
                        result.get().stream().filter(entry -> entry.getValue() != ZoneStatus.ADDED).forEach(entry -> {
                            player.setLocation(getRespawnLocation(player));
                            player.sendMessage(Text.of(TextColors.RED, "You could not be added to the zone."));
                        });
                    }
                });
            }).delayTicks(1).submit(SkreePlugin.inst());
        }
    }
    event.setUseBlockResult(Tristate.FALSE);
}
Also used : WorldService(com.skelril.skree.service.WorldService) InstanceWorldWrapper(com.skelril.skree.content.world.instance.InstanceWorldWrapper) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) Craftable(com.skelril.nitro.registry.Craftable) SkreePlugin(com.skelril.skree.SkreePlugin) WorldEffectWrapper(com.skelril.skree.service.internal.world.WorldEffectWrapper) Side(net.minecraftforge.fml.relauncher.Side) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) ZoneItemUtil(com.skelril.skree.content.registry.item.zone.ZoneItemUtil) EntityItem(net.minecraft.entity.item.EntityItem) Lightning(org.spongepowered.api.entity.weather.Lightning) Location(org.spongepowered.api.world.Location) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) CustomItem(com.skelril.nitro.registry.item.CustomItem) Sponge(org.spongepowered.api.Sponge) CustomItemTypes(com.skelril.skree.content.registry.item.CustomItemTypes) EventAwareContent(com.skelril.nitro.selector.EventAwareContent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) RespawnService(com.skelril.skree.service.RespawnService) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(org.spongepowered.api.world.World) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) First(org.spongepowered.api.event.filter.cause.First) Blocks(net.minecraft.init.Blocks) Getter(org.spongepowered.api.event.filter.Getter) Keys(org.spongepowered.api.data.key.Keys) MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EntityTypes(org.spongepowered.api.entity.EntityTypes) Text(org.spongepowered.api.text.Text) Task(org.spongepowered.api.scheduler.Task) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus) CreativeTabs(net.minecraft.creativetab.CreativeTabs) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TextColors(org.spongepowered.api.text.format.TextColors) ZoneService(com.skelril.skree.service.ZoneService) Items(net.minecraft.init.Items) Item(org.spongepowered.api.entity.Item) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ZoneService(com.skelril.skree.service.ZoneService) ItemStack(net.minecraft.item.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 83 with Player

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

the class PactScroll method onEntityInteract.

@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @Root Player player) {
    Entity targetEntity = event.getTargetEntity();
    if (!(targetEntity instanceof Player)) {
        return;
    }
    Player targetPlayer = (Player) targetEntity;
    Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optItemStack.isPresent()) {
        return;
    }
    ItemStack itemStack = optItemStack.get();
    if (itemStack.getItem() != this) {
        return;
    }
    pactMap.putIfAbsent(player.getUniqueId(), new ArrayList<>());
    List<UUID> pacts = pactMap.get(player.getUniqueId());
    if (pacts.contains(targetPlayer.getUniqueId())) {
        pacts.remove(targetPlayer.getUniqueId());
        player.sendMessage(Text.of(TextColors.YELLOW, "Your pact with ", targetPlayer.getName(), " has been broken!"));
    } else {
        pacts.add(targetPlayer.getUniqueId());
        player.sendMessage(Text.of(TextColors.YELLOW, "You've formed a pact with ", targetPlayer.getName(), "."));
        player.sendMessage(Text.of(TextColors.YELLOW, "You will no longer be able to damage ", targetPlayer.getName(), ", unless attacked first."));
        player.sendMessage(Text.of(TextColors.YELLOW, "You must carry a pact scroll for the pact to remain in effect."));
        player.sendMessage(Text.of(TextColors.YELLOW, "All pacts will automatically be reset upon disconnect."));
    }
    event.setCancelled(true);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 84 with Player

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

the class PactScroll method onBlockInteract.

@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
    Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optItemStack.isPresent()) {
        return;
    }
    ItemStack itemStack = optItemStack.get();
    if (itemStack.getItem() != this) {
        return;
    }
    UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
    PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    List<Text> result = pactMap.getOrDefault(player.getUniqueId(), new ArrayList<>()).stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
    pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Pact Members")).padding(Text.of(" ")).sendTo(player);
    event.setUseBlockResult(Tristate.FALSE);
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) java.util(java.util) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) UserStorageService(org.spongepowered.api.service.user.UserStorageService) Craftable(com.skelril.nitro.registry.Craftable) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) Order(org.spongepowered.api.event.Order) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) CollideEntityEvent(org.spongepowered.api.event.entity.CollideEntityEvent) CreativeTabs(net.minecraft.creativetab.CreativeTabs) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) TextColors(org.spongepowered.api.text.format.TextColors) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) Items(net.minecraft.init.Items) CustomItem(com.skelril.nitro.registry.item.CustomItem) Sponge(org.spongepowered.api.Sponge) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) EventAwareContent(com.skelril.nitro.selector.EventAwareContent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Root(org.spongepowered.api.event.filter.cause.Root) Cancellable(org.spongepowered.api.event.Cancellable) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) HandTypes(org.spongepowered.api.data.type.HandTypes) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) ItemType(org.spongepowered.api.item.ItemType) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 85 with Player

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

the class ZoneItemUtil method purgeZoneItems.

public static void purgeZoneItems(EntityPlayer player, @Nullable ItemStack activating) {
    ItemStack[] itemStacks = player.inventory.mainInventory;
    for (int i = 0; i < itemStacks.length; ++i) {
        if (isZoneItem(itemStacks[i])) {
            if (isZoneMasterItem(itemStacks[i])) {
                // Check to see if this is the activating item, if so remove it
                if (activating != null && hasSameZoneID(itemStacks[i], activating)) {
                    itemStacks[i] = null;
                    continue;
                }
                // Close groups for master orbs carried by other players
                if (isAttuned(itemStacks[i])) {
                    rescindGroupInvite(itemStacks[i]);
                    ItemStack reset = new ItemStack(CustomItemTypes.ZONE_MASTER_ORB);
                    setMasterToZone(reset, getZone(itemStacks[i]).get());
                    itemStacks[i] = reset;
                }
                continue;
            } else if (isZoneSlaveItem(itemStacks[i])) {
                if (activating == null || !hasSameZoneID(itemStacks[i], activating)) {
                    notifyGroupOwner(itemStacks[i], (Player) player, false);
                }
            }
            itemStacks[i] = null;
        }
    }
    player.inventoryContainer.detectAndSendChanges();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Player (org.spongepowered.api.entity.living.player.Player)125 Listener (org.spongepowered.api.event.Listener)40 ItemStack (org.spongepowered.api.item.inventory.ItemStack)28 Entity (org.spongepowered.api.entity.Entity)25 World (org.spongepowered.api.world.World)21 Text (org.spongepowered.api.text.Text)17 BigDecimal (java.math.BigDecimal)16 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)12 Vector3d (com.flowpowered.math.vector.Vector3d)10 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)10 List (java.util.List)10 Optional (java.util.Optional)10 ItemStack (net.minecraft.item.ItemStack)10 Living (org.spongepowered.api.entity.living.Living)10 Task (org.spongepowered.api.scheduler.Task)10 Location (org.spongepowered.api.world.Location)10 MarketService (com.skelril.skree.service.MarketService)8 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 TextColors (org.spongepowered.api.text.format.TextColors)8