fixed dialog closing issue and changed dialog
This commit is contained in:
1 parent
ba0cc8e458
commit
a4063c3300
4 files changed
+64
-32
No files matched your search
@@ -92,7 +92,7 @@ public final class Dialog {
|
|||||||
inputs.add(text("phoneNumber", "Telefonnummer (optional)", state.phoneNumber, 30));
|
inputs.add(text("phoneNumber", "Telefonnummer (optional)", state.phoneNumber, 30));
|
||||||
}
|
}
|
||||||
case consent -> {
|
case consent -> {
|
||||||
title = "Einverständnis";
|
title = "Serverregeln";
|
||||||
body.add(plain(Component.text("Serverregeln", NamedTextColor.GOLD, TextDecoration.BOLD), rulesWidth));
|
body.add(plain(Component.text("Serverregeln", NamedTextColor.GOLD, TextDecoration.BOLD), rulesWidth));
|
||||||
body.add(plain(Component.text(rulesPreamble, NamedTextColor.GRAY), rulesWidth));
|
body.add(plain(Component.text(rulesPreamble, NamedTextColor.GRAY), rulesWidth));
|
||||||
for (String rule : rules) {
|
for (String rule : rules) {
|
||||||
@@ -103,25 +103,30 @@ public final class Dialog {
|
|||||||
.append(Component.text(" | "))
|
.append(Component.text(" | "))
|
||||||
.append(link("Vollständige Regeln", rulesUrl))
|
.append(link("Vollständige Regeln", rulesUrl))
|
||||||
.build(), rulesWidth));
|
.build(), rulesWidth));
|
||||||
|
}
|
||||||
|
case privacy -> {
|
||||||
|
title = "Einverständnis (1/3)";
|
||||||
body.add(plain(Component.text(
|
body.add(plain(Component.text(
|
||||||
"Mit den drei Haken erklärst du: " +
|
"Ich bin mit der Speicherung meiner in der Anmeldung angegebenen, persönlichen Daten einverstanden.",
|
||||||
"1) Ich bin mit der Speicherung meiner in der Anmeldung angegebenen, persönlichen Daten einverstanden. " +
|
NamedTextColor.GRAY), rulesWidth));
|
||||||
"2) Ich bin mit der Speicherung in Form von Logs aller meiner, beim Spielen anfallenden, " +
|
inputs.add(checkbox("privacy", "Ich stimme zu *", state.privacyAccepted));
|
||||||
|
}
|
||||||
|
case logs -> {
|
||||||
|
title = "Einverständnis (2/3)";
|
||||||
|
body.add(plain(Component.text(
|
||||||
|
"Ich bin mit der Speicherung in Form von Logs aller meiner, beim Spielen anfallenden, " +
|
||||||
"persönlichen Daten durch den Server einverstanden. " +
|
"persönlichen Daten durch den Server einverstanden. " +
|
||||||
"Die Log-Speicherung betrifft jede Interaktion im Spiel und zugehörige Daten, " +
|
"Die Log-Speicherung betrifft jede Interaktion im Spiel und zugehörige Daten, " +
|
||||||
"z.B. Chatnachrichten, welche vom Minecraft-Client an den Server übermittelt werden. " +
|
"z.B. Chatnachrichten, welche vom Minecraft-Client an den Server übermittelt werden.",
|
||||||
"3) Ich bin mit den Regeln einverstanden und achte sie.",
|
|
||||||
NamedTextColor.GRAY), rulesWidth));
|
NamedTextColor.GRAY), rulesWidth));
|
||||||
|
inputs.add(checkbox("logs", "Ich stimme zu *", state.logsAccepted));
|
||||||
inputs.add(checkbox("privacy",
|
}
|
||||||
"Ich stimme der Speicherung meiner\nAnmeldedaten zu. *",
|
case rules -> {
|
||||||
state.privacyAccepted));
|
title = "Einverständnis (3/3)";
|
||||||
inputs.add(checkbox("logs",
|
body.add(plain(Component.text(
|
||||||
"Ich stimme der Speicherung meiner\nSpiel-Logs zu. *",
|
"Ich bin mit den Regeln einverstanden und achte sie.",
|
||||||
state.logsAccepted));
|
NamedTextColor.GRAY), rulesWidth));
|
||||||
inputs.add(checkbox("rules",
|
inputs.add(checkbox("rules", "Ich stimme zu *", state.rulesAccepted));
|
||||||
"Ich akzeptiere die Regeln\nund halte sie ein. *",
|
|
||||||
state.rulesAccepted));
|
|
||||||
}
|
}
|
||||||
default -> throw new IllegalStateException();
|
default -> throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
@@ -159,11 +164,10 @@ public final class Dialog {
|
|||||||
state.birthday = payload.getString("birthday", "").trim();
|
state.birthday = payload.getString("birthday", "").trim();
|
||||||
state.phoneNumber = payload.getString("phoneNumber", "").trim();
|
state.phoneNumber = payload.getString("phoneNumber", "").trim();
|
||||||
}
|
}
|
||||||
case consent -> {
|
case consent -> {}
|
||||||
state.privacyAccepted = payload.getBoolean("privacy", false);
|
case privacy -> state.privacyAccepted = payload.getBoolean("privacy", false);
|
||||||
state.logsAccepted = payload.getBoolean("logs", false);
|
case logs -> state.logsAccepted = payload.getBoolean("logs", false);
|
||||||
state.rulesAccepted = payload.getBoolean("rules", false);
|
case rules -> state.rulesAccepted = payload.getBoolean("rules", false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,9 +179,15 @@ public final class Dialog {
|
|||||||
if (!isValidBirthday(state.birthday))
|
if (!isValidBirthday(state.birthday))
|
||||||
return error("Bitte gib ein richtiges Geburtsdatum an.");
|
return error("Bitte gib ein richtiges Geburtsdatum an.");
|
||||||
}
|
}
|
||||||
case consent -> {
|
case consent -> {}
|
||||||
if (!(state.privacyAccepted && state.logsAccepted && state.rulesAccepted))
|
case privacy -> {
|
||||||
return error("Du musst allen drei Punkten zustimmen, um fortzufahren.");
|
if (!state.privacyAccepted) return error("Du musst zustimmen, um fortzufahren.");
|
||||||
|
}
|
||||||
|
case logs -> {
|
||||||
|
if (!state.logsAccepted) return error("Du musst zustimmen, um fortzufahren.");
|
||||||
|
}
|
||||||
|
case rules -> {
|
||||||
|
if (!state.rulesAccepted) return error("Du musst zustimmen, um fortzufahren.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -204,6 +214,11 @@ public final class Dialog {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Component link(String text, String url) {
|
||||||
|
return Component.text(text, NamedTextColor.AQUA, TextDecoration.UNDERLINED)
|
||||||
|
.clickEvent(ClickEvent.openUrl(url));
|
||||||
|
}
|
||||||
|
|
||||||
private static DialogInput text(String key, String label, String initial, int maxLength) {
|
private static DialogInput text(String key, String label, String initial, int maxLength) {
|
||||||
return new DialogInput.Text(key, 300, Component.text(label), true, initial, maxLength, null);
|
return new DialogInput.Text(key, 300, Component.text(label), true, initial, maxLength, null);
|
||||||
}
|
}
|
||||||
@@ -228,8 +243,4 @@ public final class Dialog {
|
|||||||
return Component.text(text, NamedTextColor.RED);
|
return Component.text(text, NamedTextColor.RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Component link(String text, String url) {
|
|
||||||
return Component.text(text, NamedTextColor.AQUA, TextDecoration.UNDERLINED)
|
|
||||||
.clickEvent(ClickEvent.openUrl(url));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@ package eu.mhsl.craftattack.loginServer;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class DialogState {
|
public final class DialogState {
|
||||||
public enum Page { data, consent }
|
public enum Page { data, consent, privacy, logs, rules }
|
||||||
|
|
||||||
private static final List<Page> pages = List.of(Page.data, Page.consent);
|
private static final List<Page> pages = List.of(Page.data, Page.consent, Page.privacy, Page.logs, Page.rules);
|
||||||
private int pageIndex = 0;
|
private int pageIndex = 0;
|
||||||
|
|
||||||
String firstName = "";
|
String firstName = "";
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
public final class PlayerHandler {
|
public final class PlayerHandler {
|
||||||
private static final Map<UUID, DialogState> states = new ConcurrentHashMap<>();
|
private static final Map<UUID, DialogState> states = new ConcurrentHashMap<>();
|
||||||
|
private static final Map<UUID, float[]> lastLook = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private PlayerHandler() {}
|
private PlayerHandler() {}
|
||||||
|
|
||||||
@@ -36,11 +37,26 @@ public final class PlayerHandler {
|
|||||||
DialogState state = states.computeIfAbsent(player.getUuid(), id -> DialogState.create());
|
DialogState state = states.computeIfAbsent(player.getUuid(), id -> DialogState.create());
|
||||||
|
|
||||||
MinecraftServer.getSchedulerManager()
|
MinecraftServer.getSchedulerManager()
|
||||||
.buildTask(() -> Dialog.open(player, state))
|
.buildTask(() -> showDialog(player, state))
|
||||||
.delay(Duration.ofMillis(500))
|
.delay(Duration.ofMillis(500))
|
||||||
.schedule();
|
.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onMove(Player player, float newYaw, float newPitch) {
|
||||||
|
DialogState state = states.get(player.getUuid());
|
||||||
|
if (state == null) return;
|
||||||
|
float[] last = lastLook.get(player.getUuid());
|
||||||
|
if (last != null && last[0] == newYaw && last[1] == newPitch) return;
|
||||||
|
lastLook.put(player.getUuid(), new float[]{newYaw, newPitch});
|
||||||
|
if (last == null) return;
|
||||||
|
showDialog(player, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showDialog(Player player, DialogState state) {
|
||||||
|
lastLook.put(player.getUuid(), new float[]{player.getPosition().yaw(), player.getPosition().pitch()});
|
||||||
|
Dialog.open(player, state);
|
||||||
|
}
|
||||||
|
|
||||||
public static void handleDialogClick(PlayerCustomClickEvent event) {
|
public static void handleDialogClick(PlayerCustomClickEvent event) {
|
||||||
if (!Dialog.isDialogKey(event.getKey())) return;
|
if (!Dialog.isDialogKey(event.getKey())) return;
|
||||||
|
|
||||||
@@ -56,6 +72,7 @@ public final class PlayerHandler {
|
|||||||
|
|
||||||
private static void complete(Player player, DialogState state) {
|
private static void complete(Player player, DialogState state) {
|
||||||
states.remove(player.getUuid());
|
states.remove(player.getUuid());
|
||||||
|
lastLook.remove(player.getUuid());
|
||||||
|
|
||||||
String birthdayIso;
|
String birthdayIso;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package eu.mhsl.craftattack.loginServer.listeners;
|
package eu.mhsl.craftattack.loginServer.listeners;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.loginServer.PlayerHandler;
|
||||||
import net.minestom.server.event.Event;
|
import net.minestom.server.event.Event;
|
||||||
import net.minestom.server.event.EventNode;
|
import net.minestom.server.event.EventNode;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
@@ -7,6 +8,9 @@ import net.minestom.server.event.player.PlayerMoveEvent;
|
|||||||
public class PlayerMoveListener implements Listener {
|
public class PlayerMoveListener implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void register(EventNode<Event> node) {
|
public void register(EventNode<Event> node) {
|
||||||
node.addListener(PlayerMoveEvent.class, event -> event.setCancelled(true));
|
node.addListener(PlayerMoveEvent.class, event -> {
|
||||||
|
event.setCancelled(true);
|
||||||
|
PlayerHandler.onMove(event.getPlayer(), event.getNewPosition().yaw(), event.getNewPosition().pitch());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user