Merge branch 'Linearpast:master' into master
This commit is contained in:
commit
e382d5f6f7
|
|
@ -8,6 +8,7 @@ import org.springframework.core.env.PropertySource;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ConfigLoader implements EnvironmentPostProcessor {
|
public class ConfigLoader implements EnvironmentPostProcessor {
|
||||||
public static final Map<String, String> config = new HashMap<>();
|
public static final Map<String, String> config = new HashMap<>();
|
||||||
|
|
@ -20,7 +21,7 @@ public class ConfigLoader implements EnvironmentPostProcessor {
|
||||||
).findFirst().orElseThrow();
|
).findFirst().orElseThrow();
|
||||||
if(source instanceof MapPropertySource mapPropertySource) {
|
if(source instanceof MapPropertySource mapPropertySource) {
|
||||||
for (String key : mapPropertySource.getPropertyNames()) {
|
for (String key : mapPropertySource.getPropertyNames()) {
|
||||||
config.put(key, mapPropertySource.getProperty(key).toString());
|
config.put(key, Objects.requireNonNull(mapPropertySource.getProperty(key)).toString());
|
||||||
System.out.println(key + "=" + mapPropertySource.getProperty(key));
|
System.out.println(key + "=" + mapPropertySource.getProperty(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,6 @@ import java.util.Map;
|
||||||
|
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
/**
|
|
||||||
* get
|
|
||||||
*
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doGet(String host, String path, String method,
|
public static HttpResponse doGet(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys)
|
Map<String, String> querys)
|
||||||
|
|
@ -58,18 +47,6 @@ public class HttpUtils {
|
||||||
return httpClient.execute(request);
|
return httpClient.execute(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* post form
|
|
||||||
*
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @param bodys
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doPost(String host, String path, String method,
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys,
|
Map<String, String> querys,
|
||||||
|
|
@ -96,18 +73,6 @@ public class HttpUtils {
|
||||||
return httpClient.execute(request);
|
return httpClient.execute(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Post String
|
|
||||||
*
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @param body
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doPost(String host, String path, String method,
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys,
|
Map<String, String> querys,
|
||||||
|
|
@ -127,18 +92,6 @@ public class HttpUtils {
|
||||||
return httpClient.execute(request);
|
return httpClient.execute(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Post stream
|
|
||||||
*
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @param body
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doPost(String host, String path, String method,
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys,
|
Map<String, String> querys,
|
||||||
|
|
@ -158,17 +111,6 @@ public class HttpUtils {
|
||||||
return httpClient.execute(request);
|
return httpClient.execute(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Put String
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @param body
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doPut(String host, String path, String method,
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys,
|
Map<String, String> querys,
|
||||||
|
|
@ -188,17 +130,6 @@ public class HttpUtils {
|
||||||
return httpClient.execute(request);
|
return httpClient.execute(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Put stream
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @param body
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doPut(String host, String path, String method,
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys,
|
Map<String, String> querys,
|
||||||
|
|
@ -218,17 +149,6 @@ public class HttpUtils {
|
||||||
return httpClient.execute(request);
|
return httpClient.execute(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete
|
|
||||||
*
|
|
||||||
* @param host
|
|
||||||
* @param path
|
|
||||||
* @param method
|
|
||||||
* @param headers
|
|
||||||
* @param querys
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static HttpResponse doDelete(String host, String path, String method,
|
public static HttpResponse doDelete(String host, String path, String method,
|
||||||
Map<String, String> headers,
|
Map<String, String> headers,
|
||||||
Map<String, String> querys)
|
Map<String, String> querys)
|
||||||
|
|
@ -252,7 +172,7 @@ public class HttpUtils {
|
||||||
if (null != querys) {
|
if (null != querys) {
|
||||||
StringBuilder sbQuery = new StringBuilder();
|
StringBuilder sbQuery = new StringBuilder();
|
||||||
for (Map.Entry<String, String> query : querys.entrySet()) {
|
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||||
if (0 < sbQuery.length()) {
|
if (!sbQuery.isEmpty()) {
|
||||||
sbQuery.append("&");
|
sbQuery.append("&");
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||||
|
|
@ -266,7 +186,7 @@ public class HttpUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 < sbQuery.length()) {
|
if (!sbQuery.isEmpty()) {
|
||||||
sbUrl.append("?").append(sbQuery);
|
sbUrl.append("?").append(sbQuery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -303,9 +223,7 @@ public class HttpUtils {
|
||||||
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||||
SchemeRegistry registry = ccm.getSchemeRegistry();
|
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||||
registry.register(new Scheme("https", ssf, 443));
|
registry.register(new Scheme("https", ssf, 443));
|
||||||
} catch (KeyManagementException ex) {
|
} catch (KeyManagementException | NoSuchAlgorithmException ex) {
|
||||||
throw new RuntimeException(ex);
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,7 @@ public class ConnectTask implements Callable<MinecraftClient> {
|
||||||
try {
|
try {
|
||||||
log.debug("Pausing for {} ms", this.connectOptions.getTimeBetweenRetries().toMillis());
|
log.debug("Pausing for {} ms", this.connectOptions.getTimeBetweenRetries().toMillis());
|
||||||
Thread.sleep(this.connectOptions.getTimeBetweenRetries().toMillis());
|
Thread.sleep(this.connectOptions.getTimeBetweenRetries().toMillis());
|
||||||
} catch (InterruptedException var2) {
|
} catch (InterruptedException e) {
|
||||||
InterruptedException e = var2;
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.linearpast.minecraftmanager.utils.rcon;
|
||||||
import com.linearpast.minecraftmanager.utils.WhitelistTarget;
|
import com.linearpast.minecraftmanager.utils.WhitelistTarget;
|
||||||
import com.linearpast.minecraftmanager.utils.config.SelfConfig;
|
import com.linearpast.minecraftmanager.utils.config.SelfConfig;
|
||||||
import io.graversen.minecraft.rcon.commands.base.ICommand;
|
import io.graversen.minecraft.rcon.commands.base.ICommand;
|
||||||
|
import io.graversen.minecraft.rcon.util.Target;
|
||||||
import io.graversen.minecraft.rcon.util.WhiteListModes;
|
import io.graversen.minecraft.rcon.util.WhiteListModes;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.commons.text.StringSubstitutor;
|
import org.apache.commons.text.StringSubstitutor;
|
||||||
|
|
@ -10,19 +11,25 @@ import org.apache.commons.text.StringSubstitutor;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public record LoginWhitelistCommand(WhitelistTarget whitelistTarget, WhiteListModes whiteListMode) implements ICommand {
|
//public record LoginWhitelistCommand(WhitelistTarget whitelistTarget, WhiteListModes whiteListMode) implements ICommand {
|
||||||
public LoginWhitelistCommand(WhitelistTarget whitelistTarget, WhiteListModes whiteListMode) {
|
// public LoginWhitelistCommand(WhitelistTarget whitelistTarget, WhiteListModes whiteListMode) {
|
||||||
this.whitelistTarget = whitelistTarget;
|
// this.whitelistTarget = whitelistTarget;
|
||||||
this.whiteListMode = Objects.requireNonNull(whiteListMode);
|
// this.whiteListMode = Objects.requireNonNull(whiteListMode);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// public String command() {
|
||||||
|
// return switch (this.whiteListMode()) {
|
||||||
|
// case ADD -> StringSubstitutor.replace(SelfConfig.addCommand + " ${name} ${uuid}", Map.of(
|
||||||
|
// "name", this.whitelistTarget().name(),
|
||||||
|
// "uuid", this.whitelistTarget().uuid())
|
||||||
|
// );
|
||||||
|
// case REMOVE, LIST, OFF, ON, RELOAD -> "";
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
public String command() {
|
public class LoginWhitelistCommand extends SelfWhiteListCommand {
|
||||||
return switch (this.whiteListMode()) {
|
public LoginWhitelistCommand(WhitelistTarget target, WhiteListModes whiteListMode) {
|
||||||
case ADD -> StringSubstitutor.replace(SelfConfig.addCommand + " ${name} ${uuid}", Map.of(
|
super(Target.player(target.name()), whiteListMode);
|
||||||
"name", this.whitelistTarget().name(),
|
|
||||||
"uuid", this.whitelistTarget().uuid())
|
|
||||||
);
|
|
||||||
case REMOVE, LIST, OFF, ON, RELOAD -> "";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import java.util.concurrent.*;
|
||||||
|
|
||||||
import io.graversen.minecraft.rcon.service.ConnectOptions;
|
import io.graversen.minecraft.rcon.service.ConnectOptions;
|
||||||
import io.graversen.minecraft.rcon.service.*;
|
import io.graversen.minecraft.rcon.service.*;
|
||||||
|
import lombok.Setter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
@ -22,6 +23,7 @@ public class MinecraftRconUtils {
|
||||||
private final ScheduledExecutorService executorService;
|
private final ScheduledExecutorService executorService;
|
||||||
private volatile IMinecraftClient minecraftClient;
|
private volatile IMinecraftClient minecraftClient;
|
||||||
private volatile MinecraftRcon minecraftRcon;
|
private volatile MinecraftRcon minecraftRcon;
|
||||||
|
@Setter
|
||||||
private volatile boolean isConnected;
|
private volatile boolean isConnected;
|
||||||
private volatile CountDownLatch connectionLatch;
|
private volatile CountDownLatch connectionLatch;
|
||||||
|
|
||||||
|
|
@ -108,9 +110,6 @@ public class MinecraftRconUtils {
|
||||||
if(this.minecraftClient != null) this.minecraftRcon = new MinecraftRcon(this.minecraftClient);
|
if(this.minecraftClient != null) this.minecraftRcon = new MinecraftRcon(this.minecraftClient);
|
||||||
else this.minecraftRcon = null;
|
else this.minecraftRcon = null;
|
||||||
}
|
}
|
||||||
public void setConnected(boolean connected) {
|
|
||||||
this.isConnected = connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestConnect implements Runnable {
|
private class TestConnect implements Runnable {
|
||||||
private final RconDetails rconDetails;
|
private final RconDetails rconDetails;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user