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