[REFACTOR] Upgrade to Java 17

This commit is contained in:
Gravita 2021-09-22 12:19:18 +07:00
parent eec54ad4d9
commit fbbde7991e
12 changed files with 21 additions and 51 deletions

View file

@ -12,8 +12,8 @@
}
}
sourceCompatibility = '11'
targetCompatibility = '11'
sourceCompatibility = '17'
targetCompatibility = '17'
configurations {
compileOnlyA

View file

@ -247,18 +247,10 @@ public void invoke(String... args) throws Exception {
return;
}
switch (args[0]) {
case "full":
reload(ReloadType.FULL);
break;
case "no_auth":
reload(ReloadType.NO_AUTH);
break;
case "no_components":
reload(ReloadType.NO_COMPONENTS);
break;
default:
reload(ReloadType.FULL);
break;
case "full" -> reload(ReloadType.FULL);
case "no_auth" -> reload(ReloadType.NO_AUTH);
case "no_components" -> reload(ReloadType.NO_COMPONENTS);
default -> reload(ReloadType.FULL);
}
}
};

View file

@ -85,9 +85,6 @@ public static void main(String[] args) throws Exception {
logger.warn("LaunchServer signed incorrectly. Status: {}", result.type.name());
}
}
if (JVMHelper.getVersion() < 17) {
logger.warn("LaunchServer will end Java {} support in next release. Please install Java 17 or above", JVMHelper.getVersion());
}
LaunchServerRuntimeConfig runtimeConfig;
LaunchServerConfig config;

View file

@ -134,8 +134,7 @@ public byte[] transformClass(byte[] bytes, String classname, BuildContext contex
ClassWriter writer;
ClassNode cn = null;
for (Transformer t : transformers) {
if (t instanceof ASMTransformer) {
ASMTransformer asmTransformer = (ASMTransformer) t;
if (t instanceof ASMTransformer asmTransformer) {
if (cn == null) {
ClassReader cr = new ClassReader(result);
cn = new ClassNode();

View file

@ -171,19 +171,10 @@ public void invoke(String... args) {
}
switch (config.env) {
case DEV:
printCheckResult("env", "found env DEV", false);
break;
case DEBUG:
printCheckResult("env", "found env DEBUG", false);
break;
case STD:
printCheckResult("env", "you can improve security by using env PROD", null);
break;
case PROD:
printCheckResult("env", "", true);
break;
case DEV -> printCheckResult("env", "found env DEV", false);
case DEBUG -> printCheckResult("env", "found env DEBUG", false);
case STD -> printCheckResult("env", "you can improve security by using env PROD", null);
case PROD -> printCheckResult("env", "", true);
}
//Profiles

View file

@ -117,8 +117,7 @@ private String authWithProviderAndHandler(AuthResponse.AuthContext context, Auth
private AuthReport authWithCore(AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password) throws AuthException {
AuthCoreProvider provider = context.pair.core;
provider.verifyAuth(context);
if (password instanceof AuthOAuthPassword) {
AuthOAuthPassword password1 = (AuthOAuthPassword) password;
if (password instanceof AuthOAuthPassword password1) {
UserSession session;
try {
session = provider.getUserSessionByOAuthAccessToken(password1.accessToken);
@ -327,12 +326,10 @@ private PlayerProfile getPlayerProfile(UUID uuid, String username, String client
}
public AuthRequest.AuthPasswordInterface decryptPassword(AuthRequest.AuthPasswordInterface password) throws AuthException {
if (password instanceof Auth2FAPassword) {
Auth2FAPassword auth2FAPassword = (Auth2FAPassword) password;
if (password instanceof Auth2FAPassword auth2FAPassword) {
auth2FAPassword.firstPassword = tryDecryptPasswordPlain(auth2FAPassword.firstPassword);
auth2FAPassword.secondPassword = tryDecryptPasswordPlain(auth2FAPassword.secondPassword);
} else if (password instanceof AuthMultiPassword) {
AuthMultiPassword multiPassword = (AuthMultiPassword) password;
} else if (password instanceof AuthMultiPassword multiPassword) {
List<AuthRequest.AuthPasswordInterface> list = new ArrayList<>(multiPassword.list.size());
for (AuthRequest.AuthPasswordInterface p : multiPassword.list) {
list.add(tryDecryptPasswordPlain(p));

View file

@ -155,8 +155,7 @@ void process(ChannelHandlerContext ctx, WebSocketServerResponse response, Client
if (hook.hook(context, ctx)) {
return;
}
if (response instanceof SimpleResponse) {
SimpleResponse simpleResponse = (SimpleResponse) response;
if (response instanceof SimpleResponse simpleResponse) {
simpleResponse.server = server;
simpleResponse.service = this;
simpleResponse.ctx = ctx;

View file

@ -31,8 +31,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
if (username == null && uuid == null) {
Map<String, String> properties;
User user = client.getUser();
if (user instanceof UserSupportAdditionalData) {
UserSupportAdditionalData userSupport = (UserSupportAdditionalData) user;
if (user instanceof UserSupportAdditionalData userSupport) {
if (user.getPermissions().isPermission(ClientPermissions.PermissionConsts.ADMIN)) {
properties = userSupport.getPropertiesMap();
} else {
@ -50,11 +49,10 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
} else {
user = pair.core.getUserByUUID(uuid);
}
if (!(user instanceof UserSupportAdditionalData)) {
if (!(user instanceof UserSupportAdditionalData userSupport)) {
sendResult(new AdditionalDataRequestEvent(Map.of()));
return;
}
UserSupportAdditionalData userSupport = (UserSupportAdditionalData) user;
Map<String, String> properties;
if (client.permissions.isPermission(ClientPermissions.PermissionConsts.ADMIN)) {
properties = userSupport.getPropertiesMap();

View file

@ -26,8 +26,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
List<ClientProfile> profileList;
Set<ClientProfile> serverProfiles = server.getProfiles();
if (server.config.protectHandler instanceof ProfilesProtectHandler) {
ProfilesProtectHandler protectHandler = (ProfilesProtectHandler) server.config.protectHandler;
if (server.config.protectHandler instanceof ProfilesProtectHandler protectHandler) {
profileList = new ArrayList<>(4);
for (ClientProfile profile : serverProfiles) {
if (protectHandler.canGetProfile(profile, client)) {

View file

@ -14,13 +14,12 @@ public String getType() {
@Override
public void execute(ChannelHandlerContext ctx, Client client) {
if (!(server.config.protectHandler instanceof SecureProtectHandler)) {
if (!(server.config.protectHandler instanceof SecureProtectHandler secureProtectHandler)) {
GetSecureLevelInfoRequestEvent response = new GetSecureLevelInfoRequestEvent(null);
response.enabled = false;
sendResult(response);
return;
}
SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler;
if (!secureProtectHandler.allowGetSecureLevelInfo(client)) {
sendError("Access denied");
return;

View file

@ -19,11 +19,10 @@ public String getType() {
@Override
public void execute(ChannelHandlerContext ctx, Client client) {
if (!(server.config.protectHandler instanceof SecureProtectHandler) || client.trustLevel == null || client.trustLevel.verifySecureKey == null) {
if (!(server.config.protectHandler instanceof SecureProtectHandler secureProtectHandler) || client.trustLevel == null || client.trustLevel.verifySecureKey == null) {
sendError("This method not allowed");
return;
}
SecureProtectHandler secureProtectHandler = (SecureProtectHandler) server.config.protectHandler;
try {
secureProtectHandler.verifySecureLevelKey(publicKey, client.trustLevel.verifySecureKey, signature);
} catch (InvalidKeySpecException e) {

@ -1 +1 @@
Subproject commit 84a5599243bddf0f7a8081cc7f5672e9140893bd
Subproject commit 74a45c7a697d33dbfc15efb0f5fac83055623ae9