Search in sources :

Example 56 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.

the class ServerboundGuideOpenRequestPacketHandler method handleMessage.

@Override
public void handleMessage(ServerboundGuideOpenRequestPacket message, RemoteConnection connection, Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && Sponge.isServerAvailable()) {
        final MinecraftServer server = (MinecraftServer) Sponge.getServer();
        if (PacketUtil.checkThreadAndEnqueue(server, message, this, connection, side)) {
            final Player player = ((PlayerConnection) connection).getPlayer();
            if (!player.hasPermission("almura.guide.open") || player.hasPermission("almura.singleplayer") && MalisisCore.isObfEnv) {
                player.sendMessage(Text.of(TextColors.WHITE, "Access denied, missing permission: ", TextColors.AQUA, "almura.guide.open", TextColors.WHITE, "."));
                return;
            }
            // Open the GUI
            this.network.sendTo(player, new ClientboundGuideOpenResponsePacket(GuideOpenType.PLAYER_INVOKED_KEYBIND, player.hasPermission("almura.guide.add"), player.hasPermission("almura.guide.remove"), player.hasPermission("almura.guide.modify"), true));
            final Map<String, Page> pagesToSend = this.manager.getAvailablePagesFor(player);
            if (pagesToSend.size() > 0) {
                final List<PageListEntry> playerListings = pagesToSend.entrySet().stream().map(entry -> new PageListEntry(entry.getKey(), entry.getValue().getName())).collect(Collectors.toList());
                final PageListEntry switchToPageEntry = playerListings.stream().findFirst().orElse(null);
                // Send the list of pages
                this.network.sendTo(player, new ClientboundPageListingsPacket(playerListings, switchToPageEntry == null ? null : switchToPageEntry.getId()));
            }
        }
    }
}
Also used : Page(com.almuradev.almura.feature.guide.Page) RemoteConnection(org.spongepowered.api.network.RemoteConnection) ServerPageManager(com.almuradev.almura.feature.guide.ServerPageManager) Platform(org.spongepowered.api.Platform) Inject(javax.inject.Inject) MinecraftServer(net.minecraft.server.MinecraftServer) ServerboundGuideOpenRequestPacket(com.almuradev.almura.feature.guide.network.ServerboundGuideOpenRequestPacket) Text(org.spongepowered.api.text.Text) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) GuideOpenType(com.almuradev.almura.feature.guide.network.GuideOpenType) ClientboundPageListingsPacket(com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket) MalisisCore(net.malisis.core.MalisisCore) Scheduler(org.spongepowered.api.scheduler.Scheduler) ClientboundGuideOpenResponsePacket(com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket) Sponge(org.spongepowered.api.Sponge) NetworkConfig(com.almuradev.almura.shared.network.NetworkConfig) MessageHandler(org.spongepowered.api.network.MessageHandler) Collectors(java.util.stream.Collectors) PlayerConnection(org.spongepowered.api.network.PlayerConnection) PageListEntry(com.almuradev.almura.feature.guide.PageListEntry) PacketUtil(com.almuradev.almura.shared.util.PacketUtil) ChannelBinding(org.spongepowered.api.network.ChannelBinding) List(java.util.List) ChannelId(org.spongepowered.api.network.ChannelId) Player(org.spongepowered.api.entity.living.player.Player) Player(org.spongepowered.api.entity.living.player.Player) ClientboundGuideOpenResponsePacket(com.almuradev.almura.feature.guide.network.ClientboundGuideOpenResponsePacket) Page(com.almuradev.almura.feature.guide.Page) ClientboundPageListingsPacket(com.almuradev.almura.feature.guide.network.ClientboundPageListingsPacket) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer) PageListEntry(com.almuradev.almura.feature.guide.PageListEntry)

Example 57 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.

the class ServerboundMembershipGuiOpenRequestPacketHandler method handleMessage.

@Override
public void handleMessage(ServerboundMembershipGuiOpenRequestPacket message, RemoteConnection connection, Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && Sponge.isServerAvailable()) {
        final MinecraftServer server = (MinecraftServer) Sponge.getServer();
        if (PacketUtil.checkThreadAndEnqueue(server, message, this, connection, side)) {
            final PlayerConnection playerConnection = (PlayerConnection) connection;
            final Player player = playerConnection.getPlayer();
            membershipHandler.requestClientGui(player);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 58 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.

the class ServerboundModifyItemsPacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundModifyItemsPacket message, final RemoteConnection connection, final Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
        checkNotNull(message.type);
        final Player player = ((PlayerConnection) connection).getPlayer();
        switch(message.type) {
            case SELLING:
                this.storeManager.handleModifySellingItems(player, message.id, message.candidates);
                break;
            case BUYING:
                this.storeManager.handleModifyBuyingItems(player, message.id, message.candidates);
                break;
            default:
                throw new UnsupportedOperationException(message.type + " is not supported yet!");
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 59 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.

the class ServerboundModifyTitlePacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundModifyTitlePacket message, final RemoteConnection connection, final Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
        checkNotNull(message.type);
        final Player player = ((PlayerConnection) connection).getPlayer();
        if (!player.hasPermission(Almura.ID + ".title.change")) {
            this.notificationManager.sendPopupNotification(player, Text.of("Title Manager"), Text.of("Insufficient Permissions to change Title!"), 2);
            return;
        }
        switch(message.type) {
            case ADD:
                this.titleManager.addTitle(player, message.id, message.permission, message.content, message.isHidden);
                break;
            case MODIFY:
                this.titleManager.modifyTitle(player, message.id, message.permission, message.content, message.isHidden);
                break;
            case DELETE:
                this.titleManager.deleteTitle(player, message.id);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 60 with MinecraftServer

use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.

the class ServerboundModifyStorePacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundModifyStorePacket message, final RemoteConnection connection, final Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
        checkNotNull(message.type);
        final Player player = ((PlayerConnection) connection).getPlayer();
        switch(message.type) {
            case ADD:
                this.storeManager.handleStoreAdd(player, message.id, message.name, message.permission, message.isHidden);
                break;
            case MODIFY:
                this.storeManager.handleStoreModify(player, message.id, message.name, message.permission, message.isHidden);
                break;
            case DELETE:
                this.storeManager.handleStoreDelete(player, message.id);
                break;
            default:
                throw new UnsupportedOperationException(message.type + " is not supported yet!");
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

MinecraftServer (net.minecraft.server.MinecraftServer)166 WorldServer (net.minecraft.world.WorldServer)35 BlockPos (net.minecraft.util.math.BlockPos)34 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)31 Player (org.spongepowered.api.entity.living.player.Player)30 PlayerConnection (org.spongepowered.api.network.PlayerConnection)30 CommandException (net.minecraft.command.CommandException)19 World (net.minecraft.world.World)18 Template (net.minecraft.world.gen.structure.template.Template)18 TextComponentString (net.minecraft.util.text.TextComponentString)16 ICommandSender (net.minecraft.command.ICommandSender)15 Entity (net.minecraft.entity.Entity)15 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)15 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 ResourceLocation (net.minecraft.util.ResourceLocation)14 Rotation (net.minecraft.util.Rotation)12 RCConfig (ivorius.reccomplex.RCConfig)11 TileEntity (net.minecraft.tileentity.TileEntity)11 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)10