mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-14 13:20:12 +02:00
182 lines
8.0 KiB
Java
182 lines
8.0 KiB
Java
/*
|
|
* Copyright (C) 2020 Nan1t
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package ru.nanit.limbo.connection;
|
|
|
|
import ru.nanit.limbo.LimboConstants;
|
|
import ru.nanit.limbo.protocol.PacketSnapshot;
|
|
import ru.nanit.limbo.protocol.packets.login.PacketLoginSuccess;
|
|
import ru.nanit.limbo.protocol.packets.play.*;
|
|
import ru.nanit.limbo.server.LimboServer;
|
|
import ru.nanit.limbo.server.data.Title;
|
|
import ru.nanit.limbo.util.UuidUtil;
|
|
|
|
import java.util.Collections;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
public final class PacketSnapshots {
|
|
|
|
public static PacketSnapshot PACKET_LOGIN_SUCCESS;
|
|
public static PacketSnapshot PACKET_JOIN_GAME;
|
|
public static PacketSnapshot PACKET_SPAWN_POSITION;
|
|
public static PacketSnapshot PACKET_PLUGIN_MESSAGE;
|
|
public static PacketSnapshot PACKET_PLAYER_ABILITIES;
|
|
public static PacketSnapshot PACKET_PLAYER_INFO;
|
|
public static PacketSnapshot PACKET_DECLARE_COMMANDS;
|
|
public static PacketSnapshot PACKET_PLAYER_POS;
|
|
public static PacketSnapshot PACKET_JOIN_MESSAGE;
|
|
public static PacketSnapshot PACKET_BOSS_BAR;
|
|
public static PacketSnapshot PACKET_HEADER_AND_FOOTER;
|
|
|
|
public static PacketSnapshot PACKET_TITLE_TITLE;
|
|
public static PacketSnapshot PACKET_TITLE_SUBTITLE;
|
|
public static PacketSnapshot PACKET_TITLE_TIMES;
|
|
|
|
public static PacketSnapshot PACKET_TITLE_LEGACY_TITLE;
|
|
public static PacketSnapshot PACKET_TITLE_LEGACY_SUBTITLE;
|
|
public static PacketSnapshot PACKET_TITLE_LEGACY_TIMES;
|
|
|
|
|
|
private PacketSnapshots() { }
|
|
|
|
public static void initPackets(LimboServer server) {
|
|
final String username = server.getConfig().getPingData().getVersion();
|
|
final UUID uuid = UuidUtil.getOfflineModeUuid(username);
|
|
|
|
PacketLoginSuccess loginSuccess = new PacketLoginSuccess();
|
|
loginSuccess.setUsername(username);
|
|
loginSuccess.setUuid(uuid);
|
|
|
|
PacketJoinGame joinGame = new PacketJoinGame();
|
|
joinGame.setEntityId(0);
|
|
joinGame.setEnableRespawnScreen(true);
|
|
joinGame.setFlat(false);
|
|
joinGame.setGameMode(server.getConfig().getGameMode());
|
|
joinGame.setHardcore(false);
|
|
joinGame.setMaxPlayers(server.getConfig().getMaxPlayers());
|
|
joinGame.setPreviousGameMode(-1);
|
|
joinGame.setReducedDebugInfo(true);
|
|
joinGame.setDebug(false);
|
|
joinGame.setViewDistance(0);
|
|
String worldName = "minecraft:" + server.getConfig().getDimensionType().toLowerCase();
|
|
joinGame.setWorldName(worldName);
|
|
joinGame.setWorldNames(worldName);
|
|
joinGame.setHashedSeed(0);
|
|
joinGame.setDimensionRegistry(server.getDimensionRegistry());
|
|
|
|
PacketPlayerAbilities playerAbilities = new PacketPlayerAbilities();
|
|
playerAbilities.setFlyingSpeed(0.0F);
|
|
playerAbilities.setFlags(0x02);
|
|
playerAbilities.setFieldOfView(0.1F);
|
|
|
|
PacketPlayerPositionAndLook positionAndLook = new PacketPlayerPositionAndLook();
|
|
positionAndLook.setX(server.getConfig().getSpawnPosition().getX());
|
|
positionAndLook.setY(server.getConfig().getSpawnPosition().getY());
|
|
positionAndLook.setZ(server.getConfig().getSpawnPosition().getZ());
|
|
positionAndLook.setYaw(server.getConfig().getSpawnPosition().getYaw());
|
|
positionAndLook.setPitch(server.getConfig().getSpawnPosition().getPitch());
|
|
positionAndLook.setTeleportId(ThreadLocalRandom.current().nextInt());
|
|
|
|
PacketDeclareCommands declareCommands = new PacketDeclareCommands();
|
|
declareCommands.setCommands(Collections.emptyList());
|
|
|
|
PacketPlayerInfo info = new PacketPlayerInfo();
|
|
info.setUsername(server.getConfig().getPlayerListUsername());
|
|
info.setGameMode(server.getConfig().getGameMode());
|
|
info.setUuid(uuid);
|
|
|
|
PacketSpawnPosition packetSpawnPosition = new PacketSpawnPosition();
|
|
packetSpawnPosition.setX((long) server.getConfig().getSpawnPosition().getX());
|
|
packetSpawnPosition.setY((long) server.getConfig().getSpawnPosition().getY());
|
|
packetSpawnPosition.setZ((long) server.getConfig().getSpawnPosition().getZ());
|
|
|
|
PACKET_LOGIN_SUCCESS = PacketSnapshot.of(loginSuccess);
|
|
PACKET_JOIN_GAME = PacketSnapshot.of(joinGame);
|
|
PACKET_SPAWN_POSITION = PacketSnapshot.of(packetSpawnPosition);
|
|
PACKET_PLAYER_ABILITIES = PacketSnapshot.of(playerAbilities);
|
|
PACKET_PLAYER_POS = PacketSnapshot.of(positionAndLook);
|
|
PACKET_PLAYER_INFO = PacketSnapshot.of(info);
|
|
|
|
PACKET_DECLARE_COMMANDS = PacketSnapshot.of(declareCommands);
|
|
|
|
if (server.getConfig().isUseHeaderAndFooter()) {
|
|
PacketPlayerListHeader header = new PacketPlayerListHeader();
|
|
header.setHeader(server.getConfig().getPlayerListHeader());
|
|
header.setFooter(server.getConfig().getPlayerListFooter());
|
|
PACKET_HEADER_AND_FOOTER = PacketSnapshot.of(header);
|
|
}
|
|
|
|
if (server.getConfig().isUseBrandName()){
|
|
PacketPluginMessage pluginMessage = new PacketPluginMessage();
|
|
pluginMessage.setChannel(LimboConstants.BRAND_CHANNEL);
|
|
pluginMessage.setMessage(server.getConfig().getBrandName());
|
|
PACKET_PLUGIN_MESSAGE = PacketSnapshot.of(pluginMessage);
|
|
}
|
|
|
|
if (server.getConfig().isUseJoinMessage()) {
|
|
PacketChatMessage joinMessage = new PacketChatMessage();
|
|
joinMessage.setJsonData(server.getConfig().getJoinMessage());
|
|
joinMessage.setPosition(PacketChatMessage.PositionLegacy.SYSTEM_MESSAGE);
|
|
joinMessage.setSender(UUID.randomUUID());
|
|
PACKET_JOIN_MESSAGE = PacketSnapshot.of(joinMessage);
|
|
}
|
|
|
|
if (server.getConfig().isUseBossBar()) {
|
|
PacketBossBar bossBar = new PacketBossBar();
|
|
bossBar.setBossBar(server.getConfig().getBossBar());
|
|
bossBar.setUuid(UUID.randomUUID());
|
|
PACKET_BOSS_BAR = PacketSnapshot.of(bossBar);
|
|
}
|
|
|
|
if (server.getConfig().isUseTitle()) {
|
|
Title title = server.getConfig().getTitle();
|
|
|
|
PacketTitleSetTitle packetTitle = new PacketTitleSetTitle();
|
|
PacketTitleSetSubTitle packetSubtitle = new PacketTitleSetSubTitle();
|
|
PacketTitleTimes packetTimes = new PacketTitleTimes();
|
|
|
|
PacketTitleLegacy legacyTitle = new PacketTitleLegacy();
|
|
PacketTitleLegacy legacySubtitle = new PacketTitleLegacy();
|
|
PacketTitleLegacy legacyTimes = new PacketTitleLegacy();
|
|
|
|
packetTitle.setTitle(title.getTitle());
|
|
packetSubtitle.setSubtitle(title.getSubtitle());
|
|
packetTimes.setFadeIn(title.getFadeIn());
|
|
packetTimes.setStay(title.getStay());
|
|
packetTimes.setFadeOut(title.getFadeOut());
|
|
|
|
legacyTitle.setTitle(title);
|
|
legacyTitle.setAction(PacketTitleLegacy.Action.SET_TITLE);
|
|
|
|
legacySubtitle.setTitle(title);
|
|
legacySubtitle.setAction(PacketTitleLegacy.Action.SET_SUBTITLE);
|
|
|
|
legacyTimes.setTitle(title);
|
|
legacyTimes.setAction(PacketTitleLegacy.Action.SET_TIMES_AND_DISPLAY);
|
|
|
|
PACKET_TITLE_TITLE = PacketSnapshot.of(packetTitle);
|
|
PACKET_TITLE_SUBTITLE = PacketSnapshot.of(packetSubtitle);
|
|
PACKET_TITLE_TIMES = PacketSnapshot.of(packetTimes);
|
|
|
|
PACKET_TITLE_LEGACY_TITLE = PacketSnapshot.of(legacyTitle);
|
|
PACKET_TITLE_LEGACY_SUBTITLE = PacketSnapshot.of(legacySubtitle);
|
|
PACKET_TITLE_LEGACY_TIMES = PacketSnapshot.of(legacyTimes);
|
|
}
|
|
}
|
|
}
|