Search in sources :

Example 41 with Listener

use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.

the class ServerHeadUpDisplayManager method onEconomyTransaction.

@Listener(order = Order.LAST)
public void onEconomyTransaction(EconomyTransactionEvent event) {
    final TransactionResult result = event.getTransactionResult();
    final Account account = result.getAccount();
    if (account instanceof UniqueAccount) {
        Sponge.getServer().getPlayer(((UniqueAccount) account).getUniqueId()).ifPresent(player -> Task.builder().delayTicks(1).execute(() -> {
            final ClientboundPlayerCurrencyPacket packet = this.createPlayerCurrencyPacket(player);
            if (packet != null) {
                this.network.sendTo(player, packet);
            }
        }).submit(this.container));
    }
}
Also used : Account(org.spongepowered.api.service.economy.account.Account) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) ClientboundPlayerCurrencyPacket(com.almuradev.almura.feature.hud.network.ClientboundPlayerCurrencyPacket) Listener(org.spongepowered.api.event.Listener)

Example 42 with Listener

use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.

the class ServerNickManager method onClientConnectionEventJoin.

@Listener
public void onClientConnectionEventJoin(final ClientConnectionEvent.Join event) {
    this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
        service.getNickname(event.getTargetEntity()).ifPresent((nick) -> {
            final String oldNick = TextSerializers.LEGACY_FORMATTING_CODE.serialize(nick);
            // Tell the Forge mods
            final String newNick = ForgeEventFactory.getPlayerDisplayName((EntityPlayer) event.getTargetEntity(), TextSerializers.LEGACY_FORMATTING_CODE.serialize(nick));
            if (!oldNick.equals(newNick)) {
                try {
                    service.setNickname(event.getTargetEntity(), TextSerializers.LEGACY_FORMATTING_CODE.deserialize(newNick));
                } catch (NicknameException e) {
                    e.printStackTrace();
                }
            }
            try {
                displayNameField.set(event.getTargetEntity(), newNick);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        });
        // Send the joining player's nickname to others
        Text nickname = service.getNickname(event.getTargetEntity()).orElse(null);
        if (nickname == null) {
            nickname = Text.of(event.getTargetEntity().getName());
        } else {
            nickname = Text.of("~" + nickname.toPlain());
        }
        final ClientboundNucleusNameChangeMappingPacket joiningPlayerPacket = this.getMappingMessage(event.getTargetEntity(), nickname);
        this.game.getServer().getOnlinePlayers().stream().filter((player) -> !player.getUniqueId().equals(event.getTargetEntity().getUniqueId())).forEach((player) -> this.network.sendTo(player, joiningPlayerPacket));
        Task.builder().delayTicks(40).execute(t -> {
            // Send everyone's nicknames to the joining player
            this.network.sendTo(event.getTargetEntity(), this.getMappingMessage(service));
        }).submit(this.container);
    });
}
Also used : Getter(org.spongepowered.api.event.filter.Getter) NucleusChangeNicknameEvent(io.github.nucleuspowered.nucleus.api.events.NucleusChangeNicknameEvent) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) Game(org.spongepowered.api.Game) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) NucleusNicknameService(io.github.nucleuspowered.nucleus.api.service.NucleusNicknameService) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NicknameException(io.github.nucleuspowered.nucleus.api.exceptions.NicknameException) Text(org.spongepowered.api.text.Text) Order(org.spongepowered.api.event.Order) Map(java.util.Map) Task(org.spongepowered.api.scheduler.Task) ClientboundNucleusNameMappingsPacket(com.almuradev.almura.feature.nick.network.ClientboundNucleusNameMappingsPacket) GameState(org.spongepowered.api.GameState) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ClientboundNucleusNameChangeMappingPacket(com.almuradev.almura.feature.nick.network.ClientboundNucleusNameChangeMappingPacket) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) Field(java.lang.reflect.Field) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) Witness(com.almuradev.core.event.Witness) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Transform(org.spongepowered.api.entity.Transform) World(org.spongepowered.api.world.World) ChannelId(org.spongepowered.api.network.ChannelId) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) Singleton(com.google.inject.Singleton) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) NucleusNicknameService(io.github.nucleuspowered.nucleus.api.service.NucleusNicknameService) ClientboundNucleusNameChangeMappingPacket(com.almuradev.almura.feature.nick.network.ClientboundNucleusNameChangeMappingPacket) NicknameException(io.github.nucleuspowered.nucleus.api.exceptions.NicknameException) Text(org.spongepowered.api.text.Text) Listener(org.spongepowered.api.event.Listener)

Example 43 with Listener

use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.

the class ServerNickManager method onChangeNickname.

@Listener(order = Order.POST)
public void onChangeNickname(final NucleusChangeNicknameEvent event, @Getter("getTargetUser") final Player player) throws IllegalAccessException {
    final EntityPlayerMP mcPlayer = (EntityPlayerMP) player;
    final String oldNick = mcPlayer.getDisplayNameString();
    final String newNick = TextSerializers.LEGACY_FORMATTING_CODE.serialize(event.getNewNickname());
    if (!oldNick.equals(newNick)) {
        // Tell the Forge mods
        final String modNick = ForgeEventFactory.getPlayerDisplayName(mcPlayer, newNick);
        final Text finalNick = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(modNick);
        if (!newNick.equals(modNick)) {
            // Mod says our nick needs to be something else
            this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
                try {
                    service.setNickname(player, finalNick);
                } catch (NicknameException e) {
                    e.printStackTrace();
                }
            });
        }
        displayNameField.set(mcPlayer, modNick);
        // Tell everyone about the new nick
        this.network.sendToAll(this.getMappingMessage(player, Text.of("~" + finalNick.toPlain())));
    }
}
Also used : NucleusNicknameService(io.github.nucleuspowered.nucleus.api.service.NucleusNicknameService) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Text(org.spongepowered.api.text.Text) NicknameException(io.github.nucleuspowered.nucleus.api.exceptions.NicknameException) Listener(org.spongepowered.api.event.Listener)

Example 44 with Listener

use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.

the class SignEditFeature method interact.

@Listener
public void interact(final InteractBlockEvent.Secondary.MainHand event, @Root final Player player) {
    if (!(player instanceof EntityPlayerMP) || !player.require(Keys.IS_SNEAKING)) {
        return;
    }
    final BlockSnapshot snapshot = event.getTargetBlock();
    final BlockType type = snapshot.getState().getType();
    if (type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
        snapshot.getLocation().flatMap(Location::getTileEntity).ifPresent((be) -> {
            if (be instanceof TileEntitySign) {
                ((EntityPlayerMP) player).connection.sendPacket(new SPacketSignEditorOpen(VecHelper.toBlockPos(snapshot.getPosition())));
            }
        });
    }
}
Also used : TileEntitySign(net.minecraft.tileentity.TileEntitySign) SPacketSignEditorOpen(net.minecraft.network.play.server.SPacketSignEditorOpen) BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Listener(org.spongepowered.api.event.Listener)

Example 45 with Listener

use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.

the class ServerTitleManager method onClientConnectionEventJoin.

@Listener
public void onClientConnectionEventJoin(ClientConnectionEvent.Join event, @Getter("getTargetEntity") Player player) {
    // Send joining player's title to everyone
    Text selectedTitle = this.getSelectedTitleFor(player).orElse(null);
    if (selectedTitle == null) {
        selectedTitle = this.getTitlesFor(player).stream().findFirst().orElse(null);
        if (selectedTitle != null) {
            this.putSelectedTitle(player.getUniqueId(), selectedTitle);
        }
    }
    Task.builder().async().delayTicks(40).execute(() -> this.createPlayerSelectedTitlesPacket().ifPresent((packet) -> {
        // Send joining player everyone's title (including itself)
        this.network.sendTo(player, packet);
    })).submit(this.container);
    if (selectedTitle != null) {
        // Java, just why
        final Text found = selectedTitle;
        this.game.getServer().getOnlinePlayers().stream().filter((p) -> !p.getUniqueId().equals(player.getUniqueId())).forEach((p) -> this.network.sendTo(p, this.createAddPlayerSelectedTitlePacket(player.getUniqueId(), found)));
    }
}
Also used : ConfigurationOptions(ninja.leaping.configurate.ConfigurationOptions) Getter(org.spongepowered.api.event.filter.Getter) Game(org.spongepowered.api.Game) GameStartingServerEvent(org.spongepowered.api.event.game.state.GameStartingServerEvent) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Text(org.spongepowered.api.text.Text) Map(java.util.Map) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Task(org.spongepowered.api.scheduler.Task) GameState(org.spongepowered.api.GameState) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ClientboundPlayerSelectedTitlesPacket(com.almuradev.almura.feature.title.network.ClientboundPlayerSelectedTitlesPacket) Logger(org.slf4j.Logger) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) Files(java.nio.file.Files) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ConfigDir(org.spongepowered.api.config.ConfigDir) Set(java.util.Set) IOException(java.io.IOException) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) UUID(java.util.UUID) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) ChannelBinding(org.spongepowered.api.network.ChannelBinding) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) ConfigRenderOptions(com.typesafe.config.ConfigRenderOptions) Witness(com.almuradev.core.event.Witness) ClientboundPlayerSelectedTitlePacket(com.almuradev.almura.feature.title.network.ClientboundPlayerSelectedTitlePacket) ChannelId(org.spongepowered.api.network.ChannelId) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) Collections(java.util.Collections) Message(org.spongepowered.api.network.Message) Text(org.spongepowered.api.text.Text) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)93 Player (org.spongepowered.api.entity.living.player.Player)41 World (org.spongepowered.api.world.World)28 Location (org.spongepowered.api.world.Location)21 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)18 ItemStack (org.spongepowered.api.item.inventory.ItemStack)18 Entity (org.spongepowered.api.entity.Entity)14 Text (org.spongepowered.api.text.Text)14 BlockType (org.spongepowered.api.block.BlockType)11 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)10 ItemStack (net.minecraft.item.ItemStack)10 Task (org.spongepowered.api.scheduler.Task)10 Vector3d (com.flowpowered.math.vector.Vector3d)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)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 UUID (java.util.UUID)5