WIP: report implementation for varo
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.api;
|
||||
package eu.mhsl.craftattack.spawn.common.api;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.config.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
@ -0,0 +1,27 @@
|
||||
package eu.mhsl.craftattack.spawn.common.api.repositories;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CraftAttackReportRepository extends ReportRepository {
|
||||
public CraftAttackReportRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
return this.get(
|
||||
"report",
|
||||
(parameters) -> parameters.addParameter("uuid", player.toString()),
|
||||
PlayerReports.class
|
||||
);
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
}
|
@ -1,17 +1,18 @@
|
||||
package eu.mhsl.craftattack.spawn.common.api.repositories;
|
||||
|
||||
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 eu.mhsl.craftattack.spawn.core.api.client.RepositoryLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ReportRepository extends HttpRepository {
|
||||
public ReportRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
@RepositoryLoader.Abstraction
|
||||
public abstract class ReportRepository extends HttpRepository {
|
||||
public ReportRepository(URI basePath, RequestModifier... baseRequestModifier) {
|
||||
super(basePath, baseRequestModifier);
|
||||
}
|
||||
|
||||
public record ReportCreationInfo(@NotNull UUID reporter, @Nullable UUID reported, String reason) {
|
||||
@ -38,20 +39,4 @@ public class ReportRepository extends HttpRepository {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
return this.get(
|
||||
"report",
|
||||
(parameters) -> parameters.addParameter("uuid", player.toString()),
|
||||
PlayerReports.class
|
||||
);
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
package eu.mhsl.craftattack.spawn.common.api.repositories;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.api.VaroApi;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VaroReportRepository extends ReportRepository {
|
||||
public VaroReportRepository() {
|
||||
super(VaroApi.getBaseUri(), new RequestModifier(null, VaroApi::authorizationHeader));
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
throw new NotImplementedException("Report querying is not supported in Varo!");
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
|
||||
public record StrikeCreationInfo(
|
||||
@Nullable UUID reporter, // null for automatic creations
|
||||
@NotNull UUID reported,
|
||||
@NotNull String reason,
|
||||
@Nullable String body,
|
||||
@Nullable String notice,
|
||||
@Nullable String statement,
|
||||
int strike_reason_id // internal strike mapping
|
||||
) {
|
||||
}
|
||||
public ReqResp<Void> createStrike(StrikeCreationInfo data) {
|
||||
return this.put(
|
||||
"report",
|
||||
data,
|
||||
Void.class
|
||||
);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.ReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.VaroReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.ReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -36,7 +38,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
public void reportToUnknown(@NotNull Player issuer) {
|
||||
ReportRepository.ReportCreationInfo request = new ReportRepository.ReportCreationInfo(issuer.getUniqueId(), null, "");
|
||||
CraftAttackReportRepository.ReportCreationInfo request = new CraftAttackReportRepository.ReportCreationInfo(issuer.getUniqueId(), null, "");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(
|
||||
Main.instance(),
|
||||
() -> this.createReport(issuer, request)
|
||||
@ -62,10 +64,11 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) {
|
||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(ReportRepository.class)
|
||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(VaroReportRepository.class)
|
||||
.createReport(reportRequest);
|
||||
|
||||
switch(createdReport.status()) {
|
||||
case 200: // varo-endpoint specific
|
||||
case 201:
|
||||
issuer.sendMessage(
|
||||
Component.text()
|
||||
@ -112,7 +115,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
public void queryReports(Player issuer) {
|
||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(ReportRepository.class)
|
||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(VaroReportRepository.class)
|
||||
.queryReports(issuer.getUniqueId());
|
||||
|
||||
if(userReports.status() != 200) {
|
||||
|
@ -48,6 +48,19 @@ public abstract class HttpRepository extends Repository {
|
||||
return this.execute(request, outputType);
|
||||
}
|
||||
|
||||
protected <TInput, TOutput> ReqResp<TOutput> put(String command, TInput data, Class<TOutput> outputType) {
|
||||
return this.put(command, parameters -> {
|
||||
}, data, outputType);
|
||||
}
|
||||
|
||||
protected <TInput, TOutput> ReqResp<TOutput> put(String command, Consumer<URIBuilder> parameters, TInput data, Class<TOutput> outputType) {
|
||||
HttpRequest request = this.getRequestBuilder(this.getUri(command, parameters))
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(this.gson.toJson(data)))
|
||||
.build();
|
||||
|
||||
return this.execute(request, outputType);
|
||||
}
|
||||
|
||||
protected <TOutput> ReqResp<TOutput> get(String command, Class<TOutput> outputType) {
|
||||
return this.get(command, parameters -> {
|
||||
}, outputType);
|
||||
|
@ -3,7 +3,7 @@ package eu.mhsl.craftattack.spawn.varo.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.varo.api.VaroApi;
|
||||
import eu.mhsl.craftattack.spawn.common.api.VaroApi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -2,7 +2,7 @@ package eu.mhsl.craftattack.spawn.varo.api.repositories;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.HttpRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.varo.api.VaroApi;
|
||||
import eu.mhsl.craftattack.spawn.common.api.VaroApi;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
Reference in New Issue
Block a user