updated Whitelist api for new Backend
This commit is contained in:
@@ -6,6 +6,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CraftAttackApi {
|
||||
@@ -25,4 +26,8 @@ public class CraftAttackApi {
|
||||
public static void withAuthorizationSecret(URIBuilder builder) {
|
||||
builder.addParameter("secret", apiSecret);
|
||||
}
|
||||
|
||||
public static void withAuthorizationHeader(HttpRequest.Builder builder) {
|
||||
builder.header("Authorization", apiSecret);
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import java.util.UUID;
|
||||
|
||||
public class CraftAttackReportRepository extends ReportRepository {
|
||||
public CraftAttackReportRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
|
@@ -9,16 +9,16 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
class PlayerLimiterListener extends ApplianceListener<PlayerLimit> {
|
||||
@EventHandler
|
||||
public void onLogin(AsyncPlayerPreLoginEvent playerPreLoginEvent) {
|
||||
playerPreLoginEvent.kickMessage(
|
||||
new DisconnectInfo(
|
||||
"Hohe Serverauslastung",
|
||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||
playerPreLoginEvent.getUniqueId()
|
||||
).getComponent()
|
||||
);
|
||||
|
||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit())
|
||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit()) {
|
||||
playerPreLoginEvent.kickMessage(
|
||||
new DisconnectInfo(
|
||||
"Hohe Serverauslastung",
|
||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||
playerPreLoginEvent.getUniqueId()
|
||||
).getComponent()
|
||||
);
|
||||
playerPreLoginEvent.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
|
||||
public class FeedbackRepository extends HttpRepository {
|
||||
public FeedbackRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
}
|
||||
|
||||
public record Request(String event, List<UUID> users) {
|
||||
|
@@ -8,7 +8,7 @@ import java.util.UUID;
|
||||
|
||||
public class WhitelistRepository extends HttpRepository {
|
||||
public WhitelistRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
}
|
||||
|
||||
public record UserData(
|
||||
@@ -21,10 +21,12 @@ public class WhitelistRepository extends HttpRepository {
|
||||
) {
|
||||
}
|
||||
|
||||
private record UserQuery(UUID uuid) {}
|
||||
|
||||
public ReqResp<UserData> getUserData(UUID userId) {
|
||||
return this.get(
|
||||
"user",
|
||||
parameters -> parameters.addParameter("uuid", userId.toString()),
|
||||
return this.post(
|
||||
"player",
|
||||
new UserQuery(userId),
|
||||
UserData.class
|
||||
);
|
||||
}
|
||||
|
@@ -118,7 +118,7 @@ public class Whitelist extends Appliance {
|
||||
);
|
||||
|
||||
if(response.status() != HttpStatus.OK)
|
||||
throw new IllegalStateException(String.format("Http Reponse %d", response.status()));
|
||||
throw new IllegalStateException(String.format("Unwanted response %d!", response.status()));
|
||||
|
||||
return response.data();
|
||||
}
|
||||
|
Reference in New Issue
Block a user