Search in sources :

Example 1 with ServerPlayer

use of net.minecraft.entity.player.ServerPlayer in project StationAPI by ModificationStation.

the class ServerVanillaChecker method registerMessages.

@EventListener(priority = ListenerPriority.HIGH)
private static void registerMessages(MessageListenerRegistryEvent event) {
    event.registry.register(of(MODID, "modlist"), (player, message) -> {
        if (!CLIENT_REQUIRED_MODS.isEmpty()) {
            LOGGER.info("Received a list of mods from player \"" + player.name + "\", verifying...");
            ServerPlayer serverPlayer = (ServerPlayer) player;
            String version = message.strings[0];
            String serverStationVersion = MODID.getVersion().getFriendlyString();
            if (!version.equals(serverStationVersion)) {
                LOGGER.error("Player \"" + player.name + "\" has a mismatching " + MODID.getName() + " version \"" + version + "\", disconnecting.");
                serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:station_version_mismatch", serverStationVersion, version));
                return;
            }
            Map<String, String> clientMods = new HashMap<>();
            for (int i = 1; i < message.strings.length; i += 2) clientMods.put(message.strings[i], message.strings[i + 1]);
            LOGGER.info("Player \"" + player.name + "\"'s mods: " + clientMods.entrySet().stream().map(stringStringEntry -> "modid=" + stringStringEntry.getKey() + " version=" + stringStringEntry.getValue()).collect(Collectors.joining(", ", "[", "]")));
            String modid;
            String clientVersion;
            String serverVersion;
            for (ModContainer serverMod : CLIENT_REQUIRED_MODS) {
                ModMetadata modMetadata = serverMod.getMetadata();
                modid = modMetadata.getId();
                serverVersion = modMetadata.getVersion().getFriendlyString();
                if (clientMods.containsKey(modid)) {
                    clientVersion = clientMods.get(modid);
                    if (clientVersion == null || !clientVersion.equals(serverVersion)) {
                        LOGGER.error("Player \"" + player.name + "\" has a mismatching " + modMetadata.getName() + " (" + modid + ")" + " version \"" + clientVersion + "\", disconnecting.");
                        serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:mod_version_mismatch", modMetadata.getName(), modid, serverVersion, clientVersion == null ? "null" : clientVersion));
                        return;
                    }
                } else {
                    LOGGER.error("Player \"" + player.name + "\" has a missing mod " + modMetadata.getName() + " (" + modid + "), disconnecting.");
                    serverPlayer.packetHandler.kick(I18n.translate("disconnect.stationapi:missing_mod", modMetadata.getName(), modid, serverVersion));
                    return;
                }
            }
            LOGGER.info("Player \"" + player.name + "\"'s mods have passed verification.");
        }
    });
}
Also used : java.util(java.util) MODID(net.modificationstation.stationapi.api.StationAPI.MODID) MASK(net.modificationstation.stationapi.impl.network.VanillaChecker.MASK) I18n(net.minecraft.client.resource.language.I18n) ModdedPacketHandlerSetter(net.modificationstation.stationapi.impl.network.ModdedPacketHandlerSetter) java.util.stream(java.util.stream) Identifier.of(net.modificationstation.stationapi.api.registry.Identifier.of) CLIENT_REQUIRED_MODS(net.modificationstation.stationapi.impl.network.VanillaChecker.CLIENT_REQUIRED_MODS) EventListener(net.mine_diver.unsafeevents.listener.EventListener) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) PlayerAttemptLoginEvent(net.modificationstation.stationapi.api.server.event.network.PlayerAttemptLoginEvent) ListenerPriority(net.mine_diver.unsafeevents.listener.ListenerPriority) EventBusPolicy(net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy) LOGGER(net.modificationstation.stationapi.api.StationAPI.LOGGER) Entrypoint(net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint) MessageListenerRegistryEvent(net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent) ServerPlayer(net.minecraft.entity.player.ServerPlayer) ModContainer(net.fabricmc.loader.api.ModContainer) ModContainer(net.fabricmc.loader.api.ModContainer) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) ServerPlayer(net.minecraft.entity.player.ServerPlayer) Entrypoint(net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 2 with ServerPlayer

use of net.minecraft.entity.player.ServerPlayer in project StationAPI by ModificationStation.

the class DimensionHelperServerImpl method switchDimension.

@Override
public void switchDimension(PlayerBase player, Identifier destination, double scale, class_467 travelAgent) {
    // noinspection deprecation
    MinecraftServer server = (MinecraftServer) FabricLoader.getInstance().getGameInstance();
    ServerPlayer serverPlayer = (ServerPlayer) player;
    ServerLevel var2 = server.getLevel(serverPlayer.dimensionId);
    DimensionRegistry dimensions = DimensionRegistry.INSTANCE;
    int overworldSerial = dimensions.getSerialID(OVERWORLD).orElseThrow(() -> new IllegalStateException("Overworld not found!"));
    int destinationSerial = dimensions.getSerialID(destination).orElseThrow(() -> new IllegalArgumentException("Unknown dimension: " + destination + "!"));
    player.dimensionId = player.dimensionId == destinationSerial ? overworldSerial : destinationSerial;
    ServerLevel var4 = server.getLevel(serverPlayer.dimensionId);
    serverPlayer.packetHandler.send(new Respawn0x9C2SPacket((byte) serverPlayer.dimensionId));
    var2.removeEntityServer(serverPlayer);
    serverPlayer.removed = false;
    double var5 = serverPlayer.x;
    double var7 = serverPlayer.z;
    if (serverPlayer.dimensionId == destinationSerial) {
        var5 *= scale;
        var7 *= scale;
    } else {
        var5 /= scale;
        var7 /= scale;
    }
    serverPlayer.setPositionAndAngles(var5, serverPlayer.y, var7, serverPlayer.yaw, serverPlayer.pitch);
    if (serverPlayer.isAlive())
        var2.method_193(serverPlayer, false);
    if (serverPlayer.isAlive()) {
        var4.spawnEntity(serverPlayer);
        serverPlayer.setPositionAndAngles(var5, serverPlayer.y, var7, serverPlayer.yaw, serverPlayer.pitch);
        var4.method_193(serverPlayer, false);
        var4.serverLevelSource.field_933 = true;
        travelAgent.method_1530(var4, serverPlayer);
        var4.serverLevelSource.field_933 = false;
    }
    server.serverPlayerConnectionManager.method_554(serverPlayer);
    serverPlayer.packetHandler.method_832(serverPlayer.x, serverPlayer.y, serverPlayer.z, serverPlayer.yaw, serverPlayer.pitch);
    serverPlayer.setLevel(var4);
    server.serverPlayerConnectionManager.sendPlayerTime(serverPlayer, var4);
    server.serverPlayerConnectionManager.method_581(serverPlayer);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerPlayer(net.minecraft.entity.player.ServerPlayer) Respawn0x9C2SPacket(net.minecraft.packet.play.Respawn0x9C2SPacket) DimensionRegistry(net.modificationstation.stationapi.api.registry.DimensionRegistry) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

ServerPlayer (net.minecraft.entity.player.ServerPlayer)2 java.util (java.util)1 java.util.stream (java.util.stream)1 ModContainer (net.fabricmc.loader.api.ModContainer)1 ModMetadata (net.fabricmc.loader.api.metadata.ModMetadata)1 EventListener (net.mine_diver.unsafeevents.listener.EventListener)1 ListenerPriority (net.mine_diver.unsafeevents.listener.ListenerPriority)1 I18n (net.minecraft.client.resource.language.I18n)1 Respawn0x9C2SPacket (net.minecraft.packet.play.Respawn0x9C2SPacket)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 LOGGER (net.modificationstation.stationapi.api.StationAPI.LOGGER)1 MODID (net.modificationstation.stationapi.api.StationAPI.MODID)1 MessageListenerRegistryEvent (net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent)1 Entrypoint (net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint)1 EventBusPolicy (net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy)1 DimensionRegistry (net.modificationstation.stationapi.api.registry.DimensionRegistry)1 Identifier.of (net.modificationstation.stationapi.api.registry.Identifier.of)1 PlayerAttemptLoginEvent (net.modificationstation.stationapi.api.server.event.network.PlayerAttemptLoginEvent)1 ModdedPacketHandlerSetter (net.modificationstation.stationapi.impl.network.ModdedPacketHandlerSetter)1