Search in sources :

Example 51 with MinecraftServer

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

the class ServerboundClaimGuiToggleDenyMessagesRequestPacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundClaimGuiToggleDenyMessagesRequestPacket message, final RemoteConnection connection, final Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
        final Player player = ((PlayerConnection) connection).getPlayer();
        final Claim claim = serverClaimManager.claimLookup(player, message.x, message.y, message.z, message.worldName);
        if (claim != null) {
            // if GP is loaded, claim should never be null.
            final boolean isOwner = (claim.getOwnerUniqueId().equals(player.getUniqueId()));
            final boolean isAdmin = player.hasPermission(ServerClaimManager.adminPermission);
            if (isOwner || isAdmin) {
                this.serverClaimManager.toggleClaimDenyMessages(claim, message.value);
                this.serverClaimManager.sendUpdateTo(player, claim, null, true, "claimGuiToggleDenyMessage");
                if (message.value) {
                    this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Deny Messages Enabled!"), 5);
                } else {
                    this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Deny Messages Disabled!"), 5);
                }
            } else {
                this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Insufficient Permissions!"), 5);
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PlayerConnection(org.spongepowered.api.network.PlayerConnection) Claim(com.griefdefender.api.claim.Claim) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 52 with MinecraftServer

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

the class ServerboundNucleusNameChangePacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundNucleusNameChangePacket message, final RemoteConnection connection, final Platform.Type side) {
    if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
        final Player player = ((PlayerConnection) connection).getPlayer();
        if (message.nickname.isEmpty()) {
            // nullify the nicknamet if the server sends an empty chance packet.
            message.nickname = null;
        }
        final Text nickname = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message.nickname == null ? player.getName() : message.nickname);
        // Validation checks
        if (message.nickname != null) {
            if (!player.hasPermission("nucleus.nick.base")) {
                // Nucleus Nickname Permission
                this.notificationManager.sendPopupNotification(player, Text.of("Nickname Error!"), Text.of("Insufficient Permissions!"), 5);
                return;
            }
            if (!NickUtil.nickNameRegex.matcher(nickname.toPlain()).matches()) {
                this.notificationManager.sendPopupNotification(player, Text.of("Nickname Error!"), Text.of("Invalid Character in Nickname!"), 5);
            }
            if (nickname.isEmpty() || nickname.toPlain().length() <= 3 || nickname.toPlain().length() > 20) {
                this.notificationManager.sendPopupNotification(player, Text.of("Nickname Error!"), Text.of("Validation of Nickname data failed!"), 5);
                return;
            }
        }
        this.nickManager.setForgeNickname((EntityPlayer) player, message.nickname == null ? player.getName() : message.nickname);
        this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
            try {
                if (message.nickname == null || player.getName().equalsIgnoreCase(message.nickname)) {
                    // Detect if player name equals
                    // packet name, if it does, the client is attempting to remove the nickname.
                    this.nickManager.removeNickname(service, player);
                } else {
                    this.nickManager.setNickname(service, player, nickname);
                }
            } catch (NicknameException e) {
                e.printStackTrace();
                return;
            }
            this.nickManager.sendNicknameUpdate(service, player);
        });
        this.game.getServer().getOnlinePlayers().forEach(onlinePlayer -> {
            if (onlinePlayer.getUniqueId().equals(player.getUniqueId())) {
                if (message.nickname == null || player.getName().equalsIgnoreCase(message.nickname)) {
                    this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("Nickname Removed!"), Text.of("You are now known as ", player.getName()), 5);
                } else {
                    this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("New Nickname!"), Text.of("You are now known as ", message.nickname), 5);
                }
            } else {
                if (message.nickname == null || player.getName().equalsIgnoreCase(message.nickname)) {
                    this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("Nickname removed!"), Text.of(player.getName() + " has removed their nickname."), 5);
                } else {
                    this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("New Nickname!"), Text.of(player.getName() + " is now known as ", message.nickname), 5);
                }
            }
        });
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) NucleusNicknameService(io.github.nucleuspowered.nucleus.api.module.nickname.NucleusNicknameService) Text(org.spongepowered.api.text.Text) NicknameException(io.github.nucleuspowered.nucleus.api.module.nickname.exception.NicknameException) PlayerConnection(org.spongepowered.api.network.PlayerConnection) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 53 with MinecraftServer

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

the class ServerboundModifyExchangePacketHandler method handleMessage.

@Override
public void handleMessage(final ServerboundModifyExchangePacket 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.exchangeManager.handleExchangeAdd(player, message.id, message.name, message.permission, message.isHidden);
                break;
            case MODIFY:
                this.exchangeManager.handleExchangeModify(player, message.id, message.name, message.permission, message.isHidden);
                break;
            case DELETE:
                this.exchangeManager.handleExchangeDelete(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)

Example 54 with MinecraftServer

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

the class ServerboundTransactionRequestPacketHandler method handleMessage.

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

Example 55 with MinecraftServer

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

the class ServerboundMembershipPurchaseRequestPacketHandler method handleMessage.

@Override
public void handleMessage(ServerboundMembershipPurchaseRequestPacket 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();
            if (message.type == 1) {
                membershipHandler.handleMembershipPurchase(player, message.membershipLevel);
            } else if (message.type == 2) {
                membershipHandler.handleMembershipSkills(player, message.membershipLevel);
            }
        }
    }
}
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