WIP: refactored report and feedback systems; updated repository models, APIs, and component utilities

This commit is contained in:
2025-10-27 14:25:44 +01:00
parent 78f87d97f0
commit c220479052
11 changed files with 110 additions and 83 deletions

View File

@@ -1,13 +1,10 @@
package eu.mhsl.craftattack.spawn.craftattack.api.repositories;
import com.google.common.reflect.TypeToken;
import eu.mhsl.craftattack.spawn.core.api.client.HttpRepository;
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class FeedbackRepository extends HttpRepository {
@@ -15,14 +12,15 @@ public class FeedbackRepository extends HttpRepository {
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
}
public record Request(String event, List<UUID> users) {
public record Request(String event, String title, List<UUID> users) {
}
public ReqResp<Map<UUID, String>> createFeedbackUrls(Request data) {
final Type responseType = new TypeToken<Map<UUID, String>>() {
}.getType();
ReqResp<Object> rawData = this.post("feedback", data, Object.class);
// TODO: use convertToTypeToken from ReqResp
return new ReqResp<>(rawData.status(), this.gson.fromJson(this.gson.toJson(rawData.data()), responseType));
public record Response(List<Feedback> feedback) {
public record Feedback(UUID uuid, String url) {
}
}
public ReqResp<Response> createFeedbackUrls(Request data) {
return this.post("feedback", data, Response.class);
}
}

View File

@@ -4,6 +4,7 @@ import eu.mhsl.craftattack.spawn.core.api.client.HttpRepository;
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
import java.util.List;
import java.util.UUID;
public class WhitelistRepository extends HttpRepository {
@@ -16,17 +17,15 @@ public class WhitelistRepository extends HttpRepository {
String username,
String firstname,
String lastname,
Long banned_until,
Long outlawed_until
List<Strike> strikes
) {
public record Strike(int at, int weight) {
}
}
private record UserQuery(UUID uuid) {}
public ReqResp<UserData> getUserData(UUID userId) {
return this.post(
"player",
new UserQuery(userId),
return this.get(
"users/%s".formatted(userId.toString()),
UserData.class
);
}

View File

@@ -1,7 +1,7 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.feedback;
import eu.mhsl.craftattack.spawn.core.Main;
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
import eu.mhsl.craftattack.spawn.core.util.text.ComponentUtil;
import eu.mhsl.craftattack.spawn.craftattack.api.repositories.FeedbackRepository;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
@@ -9,7 +9,6 @@ import eu.mhsl.craftattack.spawn.core.api.HttpStatus;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Entity;
@@ -18,32 +17,27 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class Feedback extends Appliance {
public Feedback() {
super("feedback");
}
public void requestFeedback(String eventName, List<Player> receivers, @Nullable String question) {
ReqResp<Map<UUID, String>> response = this.queryRepository(FeedbackRepository.class).createFeedbackUrls(
new FeedbackRepository.Request(eventName, receivers.stream().map(Entity::getUniqueId).toList())
public void requestFeedback(String eventName, String title, List<Player> receivers, @Nullable String question) {
ReqResp<FeedbackRepository.Response> response = this.queryRepository(FeedbackRepository.class).createFeedbackUrls(
new FeedbackRepository.Request(eventName, title, receivers.stream().map(Entity::getUniqueId).toList())
);
System.out.println(response.toString());
System.out.println(response.status());
if(response.status() != HttpStatus.CREATED) throw new RuntimeException();
if(response.status() != HttpStatus.OK) throw new RuntimeException();
Component border = Component.text("-".repeat(40), NamedTextColor.GRAY);
receivers.forEach(player -> {
String feedbackUrl = response.data().get(player.getUniqueId());
if(feedbackUrl == null) {
Main.logger().warning(String.format("FeedbackUrl not found for player '%s' from backend!", player.getUniqueId()));
return;
}
String feedbackUrl = response.data().feedback().stream()
.filter(feedback -> feedback.uuid().equals(player.getUniqueId()))
.findFirst()
.orElseThrow()
.url();
ComponentBuilder<TextComponent, TextComponent.Builder> message = Component.text()
.append(border)
@@ -58,8 +52,7 @@ public class Feedback extends Appliance {
message
.append(Component.text("Klicke hier und gib uns Feedback, damit wir dein Spielerlebnis verbessern können!", NamedTextColor.DARK_GREEN)
.clickEvent(ClickEvent.openUrl(feedbackUrl)))
.hoverEvent(HoverEvent.showText(Component.text("Klicke, um Feedback zu geben.")))
.hoverEvent(HoverEvent.showText(ComponentUtil.clickLink(feedbackUrl))))
.appendNewline()
.append(border);

View File

@@ -22,6 +22,7 @@ class FeedbackCommand extends ApplianceCommand.PlayerChecked<Feedback> {
Main.instance(),
() -> this.getAppliance().requestFeedback(
"self-issued-ingame",
"Dein Feedback an uns",
List.of(this.getPlayer()),
null
)

View File

@@ -20,6 +20,7 @@ class RequestFeedbackCommand extends ApplianceCommand<Feedback> {
Main.instance(),
() -> this.getAppliance().requestFeedback(
"admin-issued-ingame",
"Hilf uns dein Spielerlebnis zu verbessern!",
new ArrayList<>(Bukkit.getOnlinePlayers()), String.join(" ", args)
)
);

View File

@@ -0,0 +1,21 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.strike;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import java.time.Duration;
import java.util.Map;
public class Strike extends Appliance {
public Strike() {
super("strike");
}
private final Map<Integer, Duration> strikePunishmentMap = Map.of(
1, Duration.ofHours(1),
2, Duration.ofHours(24),
3, Duration.ofDays(3),
4, Duration.ofDays(7)
);
}

View File

@@ -47,7 +47,7 @@ public class Whitelist extends Appliance {
player.getUniqueId()
);
}
this.queryAppliance(Outlawed.class).updateForcedStatus(player, this.timestampRelevant(user.outlawed_until()));
this.queryAppliance(Outlawed.class).updateForcedStatus(player, this.timestampRelevant(0L)); // TODO
String purePlayerName = Floodgate.isBedrock(player)
? Floodgate.getBedrockPlayer(player).getUsername()
@@ -67,14 +67,14 @@ public class Whitelist extends Appliance {
Main.instance().getLogger().info(String.format("Running integrityCheck for %s", name));
boolean overrideCheck = this.localConfig().getBoolean("overrideIntegrityCheck", false);
WhitelistRepository.UserData user = overrideCheck
? new WhitelistRepository.UserData(uuid, name, "", "", 0L, 0L)
? new WhitelistRepository.UserData(uuid, name, "", "", List.of())
: this.fetchUserData(uuid);
this.userData.put(uuid, user);
Main.logger().info(String.format("got userdata %s", user.toString()));
if(this.timestampRelevant(user.banned_until())) {
Instant bannedDate = new Date(user.banned_until() * 1000L)
if(this.timestampRelevant(0L)) { //TODO
Instant bannedDate = new Date(0 * 1000L) // TODO
.toInstant()
.plus(1, ChronoUnit.HOURS);