made repository calls async

This commit is contained in:
Lars Neuhaus 2024-12-25 16:12:07 +01:00
parent 2e67b41b44
commit 0e3a54a1b9
6 changed files with 39 additions and 19 deletions

View File

@ -83,6 +83,7 @@ public class Event extends Appliance {
public void openEvent() { public void openEvent() {
if(this.isOpen) throw new ApplianceCommand.Error("Es läuft derzeit bereits ein Event!"); if(this.isOpen) throw new ApplianceCommand.Error("Es läuft derzeit bereits ein Event!");
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
ReqResp<EventRepository.CreatedRoom> sessionResponse = this.queryRepository(EventRepository.class).createSession(); ReqResp<EventRepository.CreatedRoom> sessionResponse = this.queryRepository(EventRepository.class).createSession();
if(sessionResponse.status() != HttpStatus.OK) if(sessionResponse.status() != HttpStatus.OK)
@ -90,6 +91,7 @@ public class Event extends Appliance {
this.isOpen = true; this.isOpen = true;
this.roomId = sessionResponse.data().uuid(); this.roomId = sessionResponse.data().uuid();
});
} }
public void joinEvent(Player p) { public void joinEvent(Player p) {
@ -110,16 +112,19 @@ public class Event extends Appliance {
Main.instance().getLogger().info("Verbinde mit eventserver: " + p.getName()); Main.instance().getLogger().info("Verbinde mit eventserver: " + p.getName());
p.sendMessage(Component.text("Authentifiziere...", NamedTextColor.GREEN)); p.sendMessage(Component.text("Authentifiziere...", NamedTextColor.GREEN));
ReqResp<EventRepository.QueueRoom.Response> queueRespone = this.queryRepository(EventRepository.class)
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
ReqResp<EventRepository.QueueRoom.Response> queueResponse = this.queryRepository(EventRepository.class)
.queueRoom(new EventRepository.QueueRoom(p.getUniqueId(), this.roomId)); .queueRoom(new EventRepository.QueueRoom(p.getUniqueId(), this.roomId));
if(queueRespone.status() != HttpStatus.OK || queueRespone.data().error() != null) { if(queueResponse.status() != HttpStatus.OK || queueResponse.data().error() != null) {
p.sendMessage(Component.text("Fehler beim Betreten: " + queueRespone.data().error(), NamedTextColor.RED)); p.sendMessage(Component.text("Fehler beim Betreten: " + queueResponse.data().error(), NamedTextColor.RED));
return; return;
} }
p.sendMessage(Component.text("Betrete...", NamedTextColor.GREEN)); p.sendMessage(Component.text("Betrete...", NamedTextColor.GREEN));
PluginMessage.connect(p, this.localConfig().getString("connect-server-name")); PluginMessage.connect(p, this.localConfig().getString("connect-server-name"));
});
} }
public void endEvent() { public void endEvent() {

View File

@ -16,6 +16,6 @@ public class EventOpenSessionCommand extends ApplianceCommand<Event> {
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
this.getAppliance().openEvent(); this.getAppliance().openEvent();
sender.sendMessage(Component.text("Event-Server erfolgreich gestartet!", NamedTextColor.GREEN)); sender.sendMessage(Component.text("Event-Server gestartet!", NamedTextColor.GREEN));
} }
} }

View File

@ -1,8 +1,10 @@
package eu.mhsl.craftattack.spawn.appliances.feedback.commands; package eu.mhsl.craftattack.spawn.appliances.feedback.commands;
import eu.mhsl.craftattack.spawn.Main;
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand; import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.appliances.feedback.Feedback; import eu.mhsl.craftattack.spawn.appliances.feedback.Feedback;
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil; import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -17,6 +19,8 @@ public class FeedbackCommand extends ApplianceCommand.PlayerChecked<Feedback> {
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
sender.sendMessage(ComponentUtil.pleaseWait()); sender.sendMessage(ComponentUtil.pleaseWait());
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
this.getAppliance().requestFeedback("self-issued-ingame", List.of(this.getPlayer()), null); this.getAppliance().requestFeedback("self-issued-ingame", List.of(this.getPlayer()), null);
});
} }
} }

View File

@ -1,5 +1,6 @@
package eu.mhsl.craftattack.spawn.appliances.feedback.commands; package eu.mhsl.craftattack.spawn.appliances.feedback.commands;
import eu.mhsl.craftattack.spawn.Main;
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand; import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.appliances.feedback.Feedback; import eu.mhsl.craftattack.spawn.appliances.feedback.Feedback;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -16,6 +17,8 @@ public class RequestFeedbackCommand extends ApplianceCommand<Feedback> {
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
this.getAppliance().requestFeedback("admin-issued-ingame", new ArrayList<>(Bukkit.getOnlinePlayers()), String.join(" ", args)); this.getAppliance().requestFeedback("admin-issued-ingame", new ArrayList<>(Bukkit.getOnlinePlayers()), String.join(" ", args));
});
} }
} }

View File

@ -37,7 +37,9 @@ public class Report extends Appliance {
public void reportToUnknown(@NotNull Player issuer) { public void reportToUnknown(@NotNull Player issuer) {
ReportRepository.ReportCreationInfo request = new ReportRepository.ReportCreationInfo(issuer.getUniqueId(), null, ""); ReportRepository.ReportCreationInfo request = new ReportRepository.ReportCreationInfo(issuer.getUniqueId(), null, "");
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
this.createReport(issuer, request); this.createReport(issuer, request);
});
} }
public void reportToKnown(@NotNull Player issuer, @NotNull String targetUsername, @Nullable String reason) { public void reportToKnown(@NotNull Player issuer, @NotNull String targetUsername, @Nullable String reason) {
@ -52,7 +54,9 @@ public class Report extends Appliance {
offlinePlayer.getUniqueId(), offlinePlayer.getUniqueId(),
Optional.ofNullable(reason).orElse("") Optional.ofNullable(reason).orElse("")
); );
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
this.createReport(issuer, request); this.createReport(issuer, request);
});
} }
private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) { private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) {

View File

@ -1,7 +1,9 @@
package eu.mhsl.craftattack.spawn.appliances.report; package eu.mhsl.craftattack.spawn.appliances.report;
import eu.mhsl.craftattack.spawn.Main;
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand; import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil; import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -14,6 +16,8 @@ public class ReportsCommand extends ApplianceCommand.PlayerChecked<Report> {
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage(ComponentUtil.pleaseWait()); sender.sendMessage(ComponentUtil.pleaseWait());
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
this.getAppliance().queryReports(this.getPlayer()); this.getAppliance().queryReports(this.getPlayer());
});
} }
} }