Skip to content

Commit

Permalink
Few style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed May 18, 2024
1 parent 6de3412 commit 7055efb
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 130 deletions.
8 changes: 2 additions & 6 deletions client/src/main/java/com/soulfiremc/client/gui/SFMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ public SFMenuBar(GUIManager guiManager, LogPanel logPanel, GUIFrame guiFrame) {
for (var theme : THEMES) {
var themeItem = new JRadioButtonMenuItem(theme.getSimpleName());
themeUpdateCallbacks.add(
() -> {
themeItem.setSelected(theme.getName().equals(ThemeUtil.getThemeClassName()));
});
() -> themeItem.setSelected(theme.getName().equals(ThemeUtil.getThemeClassName())));
themeItem.addActionListener(
e -> {
GUIClientProps.setString("theme", theme.getName());
Expand All @@ -191,9 +189,7 @@ public SFMenuBar(GUIManager guiManager, LogPanel logPanel, GUIFrame guiFrame) {
for (var terminal : TerminalTheme.THEMES) {
var terminalItem = new JRadioButtonMenuItem(terminal.name());
terminalUpdateCallbacks.add(
() -> {
terminalItem.setSelected(terminal == ThemeUtil.getTerminal());
});
() -> terminalItem.setSelected(terminal == ThemeUtil.getTerminal()));
terminalItem.addActionListener(
e -> {
GUIClientProps.setString("terminal", terminal.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,10 @@ public MinecraftAccountProto toProto() {
.setLastKnownName(lastKnownName);

switch (accountData) {
case BedrockData bedrockData -> {
builder.setBedrockData(bedrockData.toProto());
}
case OfflineJavaData offlineJavaData -> {
builder.setOfflineJavaData(offlineJavaData.toProto());
}
case OnlineSimpleJavaData onlineSimpleJavaData -> {
builder.setOnlineSimpleJavaData(onlineSimpleJavaData.toProto());
}
case OnlineChainJavaData onlineChainJavaData -> {
builder.setOnlineChainJavaData(onlineChainJavaData.toProto());
}
case BedrockData bedrockData -> builder.setBedrockData(bedrockData.toProto());
case OfflineJavaData offlineJavaData -> builder.setOfflineJavaData(offlineJavaData.toProto());
case OnlineSimpleJavaData onlineSimpleJavaData -> builder.setOnlineSimpleJavaData(onlineSimpleJavaData.toProto());
case OnlineChainJavaData onlineChainJavaData -> builder.setOnlineChainJavaData(onlineChainJavaData.toProto());
}

return builder.build();
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/com/soulfiremc/util/PortHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@Slf4j
public class PortHelper {
public static int SF_DEFAULT_PORT = 38765;
public static final int SF_DEFAULT_PORT = 38765;

public static int getAvailablePort(int startPort) {
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ShutdownManager {
private final Runnable shutdownHook;
private final PluginManager pluginManager;
private final AtomicBoolean shutdownInProgress = new AtomicBoolean(false);
private CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();
private final CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();

/**
* Shuts down the software if it is running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static DedicatedServer getServer() {
return (DedicatedServer) FabricLoader.getInstance().getGameInstance();
}

@SuppressWarnings("DataFlowIssue")
public static GameTestHelper getGameTestHelper() {
return new GameTestHelper(null) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import net.kyori.adventure.key.Key;
import org.intellij.lang.annotations.Subst;

public class BlockShapeLoader {
public static final Map<Key, List<BlockShapeGroup>> BLOCK_SHAPES =
Expand All @@ -41,7 +42,8 @@ public class BlockShapeLoader {
.forEach(
line -> {
var parts = line.split("\\|");
var key = Key.key(parts[0]);
@Subst("empty") var keyString = parts[0];
var key = Key.key(keyString);

var blockShapeTypes = new ObjectArrayList<BlockShapeGroup>();
if (parts.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class GsonDataHelper {
private static final Map<String, JsonArray> LOADED_DATA = new HashMap<>();
private static final TypeAdapter<Key> RESOURCE_KEY_ADAPTER =
new TypeAdapter<Key>() {
new TypeAdapter<>() {
@Override
public void write(JsonWriter out, Key value) throws IOException {
out.value(value.asString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,13 @@ public JsonDataComponents read(JsonReader in) {
for (var entry : parsedJson.entrySet()) {
var value = entry.getValue();
switch (entry.getKey()) {
case "minecraft:max_stack_size" -> {
var maxStackSize = value.getAsInt();
map.put(DataComponentType.MAX_STACK_SIZE, new IntDataComponent(DataComponentType.MAX_STACK_SIZE, maxStackSize));
}
case "minecraft:rarity" -> {
var rarity = value.getAsString();
map.put(DataComponentType.RARITY, new IntDataComponent(DataComponentType.RARITY, Rarity.valueOf(rarity.toUpperCase(Locale.ROOT)).ordinal()));
}
case "minecraft:attribute_modifiers" -> {
map.put(DataComponentType.ATTRIBUTE_MODIFIERS, new ObjectDataComponent<>(DataComponentType.ATTRIBUTE_MODIFIERS, JsonToMCPLCodecs.ITEM_ATTRIBUTE_MODIFIERS_CODEC.decode(JsonOps.INSTANCE, value).result().orElseThrow().getFirst()));
}
case "minecraft:max_stack_size" -> map.put(DataComponentType.MAX_STACK_SIZE, new IntDataComponent(DataComponentType.MAX_STACK_SIZE, value.getAsInt()));
case "minecraft:rarity" -> map.put(DataComponentType.RARITY, new IntDataComponent(DataComponentType.RARITY, Rarity.valueOf(value.getAsString().toUpperCase(Locale.ROOT)).ordinal()));
case "minecraft:attribute_modifiers" -> map.put(DataComponentType.ATTRIBUTE_MODIFIERS, new ObjectDataComponent<>(DataComponentType.ATTRIBUTE_MODIFIERS, JsonToMCPLCodecs.ITEM_ATTRIBUTE_MODIFIERS_CODEC.decode(JsonOps.INSTANCE, value).result().orElseThrow().getFirst()));
case "minecraft:tool" -> {
// TODO: Implement
}
case "minecraft:food" -> {
map.put(DataComponentType.FOOD, new ObjectDataComponent<>(DataComponentType.FOOD, JsonToMCPLCodecs.FOOD_PROPERTIES_CODEC.decode(JsonOps.INSTANCE, value).result().orElseThrow().getFirst()));
}
case "minecraft:food" -> map.put(DataComponentType.FOOD, new ObjectDataComponent<>(DataComponentType.FOOD, JsonToMCPLCodecs.FOOD_PROPERTIES_CODEC.decode(JsonOps.INSTANCE, value).result().orElseThrow().getFirst()));
default -> log.trace("Unknown DataComponentType: {}", entry.getKey());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum MineableType {
AXE(ItemTags.AXES, BlockTags.MINEABLE_WITH_AXE),
HOE(ItemTags.HOES, BlockTags.MINEABLE_WITH_HOE);

public static MineableType[] VALUES = values();
public static final MineableType[] VALUES = values();
private final TagKey<ItemType> itemTagKey;
@Getter
private final TagKey<BlockType> blockTagKey;
Expand Down
169 changes: 83 additions & 86 deletions server/src/main/java/com/soulfiremc/server/plugins/POVServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.geysermc.mcprotocollib.network.tcp.TcpServer;
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.protocol.ServerLoginHandler;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.ProtocolState;
Expand All @@ -95,7 +94,6 @@
import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo;
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
import org.geysermc.mcprotocollib.protocol.data.status.VersionInfo;
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerInfoBuilder;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundKeepAlivePacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundPingPacket;
Expand Down Expand Up @@ -221,99 +219,98 @@ public POVServerInstance(int port, AttackManager attackManager) {

server.setGlobalFlag(MinecraftConstants.VERIFY_USERS_KEY, false);
server.setGlobalFlag(
MinecraftConstants.SERVER_INFO_BUILDER_KEY, (ServerInfoBuilder) session -> pong);
MinecraftConstants.SERVER_INFO_BUILDER_KEY, session -> pong);

server.setGlobalFlag(
MinecraftConstants.SERVER_LOGIN_HANDLER_KEY,
(ServerLoginHandler)
session -> {
session.send(
new ClientboundLoginPacket(
session -> {
session.send(
new ClientboundLoginPacket(
0,
false,
new String[] {"minecraft:the_end"},
1,
0,
0,
false,
false,
false,
new PlayerSpawnInfo(
0,
false,
new String[] {"minecraft:the_end"},
1,
0,
0,
false,
"minecraft:the_end",
100,
GameMode.SPECTATOR,
GameMode.SPECTATOR,
false,
false,
new PlayerSpawnInfo(
0,
"minecraft:the_end",
100,
GameMode.SPECTATOR,
GameMode.SPECTATOR,
false,
false,
null,
0),
false));

session.send(
new ClientboundPlayerAbilitiesPacket(false, false, true, false, 0.05f, 0.1f));

// this packet is also required to let our player spawn, but the location itself
// doesn't matter
session.send(new ClientboundSetDefaultSpawnPositionPacket(Vector3i.ZERO, 0));

// we have to listen to the teleport confirm on the PacketHandler to prevent respawn
// request packet spam,
// so send it after calling ConnectedEvent which adds the PacketHandler as listener
session.send(new ClientboundPlayerPositionPacket(0, 0, 0, 0, 0, 0));

// this packet is required since 1.20.3
session.send(
new ClientboundGameEventPacket(GameEvent.LEVEL_CHUNKS_LOAD_START, null));

var sectionCount = 16;
var buf = Unpooled.buffer();
for (var i = 0; i < sectionCount; i++) {
var chunk = DataPalette.createForChunk();
chunk.set(0, 0, 0, 0);
var biome = DataPalette.createForBiome();
biome.set(0, 0, 0, 0);
SFProtocolHelper.writeChunkSection(
buf,
new ChunkSection(0, chunk, biome),
(MinecraftCodecHelper) session.getCodecHelper());
}

var chunkBytes = new byte[buf.readableBytes()];
buf.readBytes(chunkBytes);

var lightMask = new BitSet();
lightMask.set(0, sectionCount + 2);
var skyUpdateList = new ArrayList<byte[]>();
for (var i = 0; i < sectionCount + 2; i++) {
skyUpdateList.add(FULL_LIGHT); // sky light
}

var lightUpdateData =
new LightUpdateData(
lightMask, new BitSet(), new BitSet(), lightMask, skyUpdateList, List.of());

session.send(
new ClientboundLevelChunkWithLightPacket(
0,
0,
chunkBytes,
NbtMap.EMPTY,
new BlockEntityInfo[0],
lightUpdateData));
null,
0),
false));

session.send(
new ClientboundPlayerAbilitiesPacket(false, false, true, false, 0.05f, 0.1f));

// this packet is also required to let our player spawn, but the location itself
// doesn't matter
session.send(new ClientboundSetDefaultSpawnPositionPacket(Vector3i.ZERO, 0));

// we have to listen to the teleport confirm on the PacketHandler to prevent respawn
// request packet spam,
// so send it after calling ConnectedEvent which adds the PacketHandler as listener
session.send(new ClientboundPlayerPositionPacket(0, 0, 0, 0, 0, 0));

// this packet is required since 1.20.3
session.send(
new ClientboundGameEventPacket(GameEvent.LEVEL_CHUNKS_LOAD_START, null));

var sectionCount = 16;
var buf = Unpooled.buffer();
for (var i = 0; i < sectionCount; i++) {
var chunk = DataPalette.createForChunk();
chunk.set(0, 0, 0, 0);
var biome = DataPalette.createForBiome();
biome.set(0, 0, 0, 0);
SFProtocolHelper.writeChunkSection(
buf,
new ChunkSection(0, chunk, biome),
(MinecraftCodecHelper) session.getCodecHelper());
}

// Manually call the connect event
session.callEvent(new ConnectedEvent(session));
var chunkBytes = new byte[buf.readableBytes()];
buf.readBytes(chunkBytes);

var brandBuffer = Unpooled.buffer();
session.getCodecHelper().writeString(brandBuffer, "SoulFire POV");
var lightMask = new BitSet();
lightMask.set(0, sectionCount + 2);
var skyUpdateList = new ArrayList<byte[]>();
for (var i = 0; i < sectionCount + 2; i++) {
skyUpdateList.add(FULL_LIGHT); // sky light
}

var lightUpdateData =
new LightUpdateData(
lightMask, new BitSet(), new BitSet(), lightMask, skyUpdateList, List.of());

session.send(
new ClientboundLevelChunkWithLightPacket(
0,
0,
chunkBytes,
NbtMap.EMPTY,
new BlockEntityInfo[0],
lightUpdateData));

var brandBytes = new byte[brandBuffer.readableBytes()];
brandBuffer.readBytes(brandBytes);
// Manually call the connect event
session.callEvent(new ConnectedEvent(session));

session.send(
new ClientboundCustomPayloadPacket(SFProtocolConstants.BRAND_PAYLOAD_KEY.toString(), brandBytes));
});
var brandBuffer = Unpooled.buffer();
session.getCodecHelper().writeString(brandBuffer, "SoulFire POV");

var brandBytes = new byte[brandBuffer.readableBytes()];
brandBuffer.readBytes(brandBytes);

session.send(
new ClientboundCustomPayloadPacket(SFProtocolConstants.BRAND_PAYLOAD_KEY.toString(), brandBytes));
});
server.setGlobalFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD, 256);

server.addListener(
Expand Down Expand Up @@ -694,7 +691,7 @@ private void syncBotAndUser() {
}

var currentId =
session.<GameProfile>getFlag(MinecraftConstants.PROFILE_KEY).getId();
session.getFlag(MinecraftConstants.PROFILE_KEY).getId();
session.send(
new ClientboundPlayerInfoUpdatePacket(
EnumSet.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Slf4j
public class ResolveUtil {
private static final DirContext DIR_CONTEXT;
public static int MC_DEFAULT_PORT = 25565;
public static final int MC_DEFAULT_PORT = 25565;

static {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.geysermc.mcprotocollib.network.tcp.TcpSession;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundDelimiterPacket;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

public class ViaClientSession extends TcpSession {
Expand Down Expand Up @@ -155,7 +156,7 @@ public void connect(boolean wait) {
bootstrap.handler(
new ChannelInitializer<>() {
@Override
public void initChannel(Channel channel) {
public void initChannel(@NotNull Channel channel) {
var protocol = getPacketProtocol();
protocol.newClientSession(ViaClientSession.this, false);

Expand Down Expand Up @@ -287,7 +288,7 @@ private void addHAProxySupport(ChannelPipeline pipeline) {
"proxy-protocol-packet-sender",
new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
public void channelActive(@NotNull ChannelHandlerContext ctx) throws Exception {
var proxiedProtocol =
clientAddress.getAddress() instanceof Inet4Address
? HAProxyProxiedProtocol.TCP4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import javax.crypto.Cipher;

public class EncryptionUtils {
;

public static final Pair<String, String> PEM_RSA_PUBLIC_KEY_DESCRIPTOR =
Pair.of("-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----");
public static final Pair<String, String> PEM_RSA_PRIVATE_KEY_DESCRIPTOR =
Expand Down
Loading

0 comments on commit 7055efb

Please sign in to comment.