Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions commons/src/main/java/net/swofty/commons/MinecraftVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public enum MinecraftVersion {
MINECRAFT_1_20_5(766, new String[]{"1.20.5", "1.20.6"}),
MINECRAFT_1_21(767, new String[]{"1.21", "1.21.1"}),
MINECRAFT_1_21_2(768, new String[]{"1.21.2", "1.21.3"}),
MINECRAFT_1_21_4(769, new String[]{"1.21.4"}),
MINECRAFT_1_21_5(770, new String[]{"1.21.5"}),
MINECRAFT_1_21_6(771, new String[]{"1.21.6"}),
MINECRAFT_1_21_7(772, new String[]{"1.21.7"}),
MINECRAFT_1_21_8(772, new String[]{"1.21.8"}),
MINECRAFT_1_21_9(773, new String[]{"1.21.9"}),
MINECRAFT_1_21_10(773, new String[]{"1.21.10"}),
MINECRAFT_1_21_11(774, new String[]{"1.21.11"}),
;

private final int protocol;
Expand All @@ -64,7 +72,5 @@ public static MinecraftVersion byProtocolId(int protocolID) {
.findFirst()
.orElse(null);
}
public boolean isMoreRecentThan(MinecraftVersion version) {
return this.protocol > version.protocol;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public class HypixelPlayer extends Player {
@Setter
@Getter
private ServerType originServer = ServerType.SKYBLOCK_HUB;
@Setter
@Getter
private MinecraftVersion version = MinecraftVersion.MINECRAFT_1_20_3;
@Getter
private boolean readyForEvents = false;
@Getter
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import com.velocitypowered.api.event.player.KickedFromServerEvent;
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
Expand All @@ -37,6 +39,7 @@
import net.swofty.commons.ServerType;
import net.swofty.commons.proxy.FromProxyChannels;
import net.swofty.redisapi.api.RedisAPI;
import net.swofty.velocity.command.ProtocolVersionCommand;
import net.swofty.velocity.command.ServerStatusCommand;
import net.swofty.velocity.data.CoopDatabase;
import net.swofty.velocity.data.ProfilesDatabase;
Expand Down Expand Up @@ -174,6 +177,13 @@ public void onProxyInitialization(ProxyInitializeEvent event) {

commandManager.register(statusCommandMeta, new ServerStatusCommand());

CommandMeta protocolVersionMeta = commandManager.metaBuilder("protocolversion")
.aliases("protocol")
.plugin(this)
.build();

commandManager.register(protocolVersionMeta, new ProtocolVersionCommand());


/**
* Handle database
Expand Down Expand Up @@ -339,6 +349,22 @@ public void onPing(ProxyPingEvent event) {
));
}

@Subscribe
public void onPlayerConnect(ServerPostConnectEvent event) {
if (!(event.getPlayer().getProtocolVersion().getProtocol() >= ProtocolVersion.MAXIMUM_VERSION.getProtocol())) {
StringBuilder message = new StringBuilder();

message.append("\n");
message.append("§6§l----------- §cServer Notice §6§l-----------\n");
message.append("§cAlthough we do support versions prior to §6" + ProtocolVersion.MAXIMUM_VERSION.getVersionIntroducedIn() + "§c, the experience may be buggy.\n");
message.append("§cIf you experience a bug, please test if it also occurs on §6" + ProtocolVersion.MAXIMUM_VERSION.getVersionIntroducedIn() + "§c before reporting it.\n");
message.append("§6§l---------------------------------\n");
message.append("\n");

event.getPlayer().sendMessage(Component.text(message.toString()));
}
}

public static <T> Stream<T> loopThroughPackage(String packageName, Class<T> clazz) {
Reflections reflections = new Reflections(packageName);
Set<Class<? extends T>> subTypes = reflections.getSubTypesOf(clazz);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.swofty.velocity.command;

import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;

import java.util.List;

public class ProtocolVersionCommand implements SimpleCommand {

@Override
public void execute(Invocation invocation) {
CommandSource source = invocation.source();
if (!(source instanceof Player player)) {
return;
}
ProtocolVersion version = player.getProtocolVersion();
List<String> versionsSupportedBy = version.getVersionsSupportedBy();
player.sendMessage(Component.text(version.getProtocol() + " §7(" + String.join(", ", versionsSupportedBy) + ")"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProtocolVersion getClosestServerProtocol(UserConnection user) throws Exce
}

private ProtocolVersion getBackProtocol(UserConnection user) {
return ProtocolVersion.v1_21_4; // backend server version
return ProtocolVersion.v1_21_11; // backend server version
}

private ProtocolVersion getFrontProtocol(UserConnection user) throws Exception {
Expand Down