proper disconnectInfo screen and preventing dead users from joining
This commit is contained in:
parent
2f4251ef72
commit
987acf6b45
@ -108,13 +108,13 @@ public class Lobby extends InstanceContainer {
|
|||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
.containsAll(livingPlayers);
|
.containsAll(livingPlayers);
|
||||||
|
|
||||||
if(this.isComplete) {
|
if(this.isComplete && !wasComplete) {
|
||||||
this.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 1f, 1f));
|
this.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 1f, 1f));
|
||||||
this.everyMember(p -> p.sendMessage(Component.text(
|
this.everyMember(p -> p.sendMessage(Component.text(
|
||||||
"Das Team ist vollständig. Der Server kann jederzeit über den Knopf betreten werden!",
|
"Das Team ist vollständig. Der Server kann jederzeit über den Knopf betreten werden!",
|
||||||
NamedTextColor.GREEN
|
NamedTextColor.GREEN
|
||||||
)));
|
)));
|
||||||
} else if(wasComplete) {
|
} else if(!this.isComplete && wasComplete) {
|
||||||
this.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 1f, 0.1f));
|
this.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 1f, 0.1f));
|
||||||
this.everyMember(p -> p.sendMessage(Component.text(
|
this.everyMember(p -> p.sendMessage(Component.text(
|
||||||
"Das Team ist nicht mehr vollständig.",
|
"Das Team ist nicht mehr vollständig.",
|
||||||
@ -152,17 +152,6 @@ public class Lobby extends InstanceContainer {
|
|||||||
this.playSound(Sound.sound(SoundEvent.ENTITY_PLAYER_LEVELUP, Sound.Source.PLAYER, 1f, 1f));
|
this.playSound(Sound.sound(SoundEvent.ENTITY_PLAYER_LEVELUP, Sound.Source.PLAYER, 1f, 1f));
|
||||||
|
|
||||||
MinecraftServer.getSchedulerManager().scheduleTask(() -> this.everyMember(p -> {
|
MinecraftServer.getSchedulerManager().scheduleTask(() -> this.everyMember(p -> {
|
||||||
var isDead = this.team.users().stream()
|
|
||||||
.filter(user -> user.uuid().equals(p.getUuid()))
|
|
||||||
.findAny()
|
|
||||||
.orElseThrow()
|
|
||||||
.dead();
|
|
||||||
|
|
||||||
if(isDead) {
|
|
||||||
p.sendActionBar(Component.text("Du bist bereits aus dem Projekt ausgeschieden!", NamedTextColor.RED));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.addEffect(new Potion(PotionEffect.DARKNESS, 0, 5 * Ticks.TICKS_PER_SECOND));
|
p.addEffect(new Potion(PotionEffect.DARKNESS, 0, 5 * Ticks.TICKS_PER_SECOND));
|
||||||
p.sendActionBar(Component.text("Verbinde...", NamedTextColor.GREEN));
|
p.sendActionBar(Component.text("Verbinde...", NamedTextColor.GREEN));
|
||||||
PluginMessageUtil.connect(p, this.targetServer);
|
PluginMessageUtil.connect(p, this.targetServer);
|
||||||
|
@ -15,11 +15,12 @@ public class LobbyManager {
|
|||||||
public LobbyManager() {
|
public LobbyManager() {
|
||||||
MinecraftServer.getSchedulerManager().scheduleTask(
|
MinecraftServer.getSchedulerManager().scheduleTask(
|
||||||
this::loadTeams,
|
this::loadTeams,
|
||||||
TaskSchedule.seconds(3),
|
TaskSchedule.immediate(),
|
||||||
TaskSchedule.minutes(1)
|
TaskSchedule.minutes(1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Object teamLock = new Object();
|
||||||
private Set<Team> teams = Set.of();
|
private Set<Team> teams = Set.of();
|
||||||
private final Map<Team, Lobby> instances = new HashMap<>();
|
private final Map<Team, Lobby> instances = new HashMap<>();
|
||||||
|
|
||||||
@ -28,19 +29,31 @@ public class LobbyManager {
|
|||||||
.GET()
|
.GET()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
this.teams = Request.execute(request, new TypeToken<Set<Team>>(){}.getType()).cast();
|
synchronized(this.teamLock) {
|
||||||
|
this.teams = Request.execute(request, new TypeToken<Set<Team>>(){}.getType()).cast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized @NotNull Lobby getPlayerInstance(Player player) {
|
public @NotNull Lobby getPlayerInstance(Player player) {
|
||||||
UUID playerId = player.getUuid();
|
UUID playerId = player.getUuid();
|
||||||
Team targetTeam = this.teams.stream()
|
|
||||||
.filter(team -> team.users().stream().anyMatch(user -> user.uuid().equals(playerId)))
|
|
||||||
.findAny()
|
|
||||||
.orElseThrow(() -> new NoSuchElementException("Dein Account konnte nicht zugeordnet werden. Falls dies ein Fehler ist kontaktiere bitte einen Admin."));
|
|
||||||
|
|
||||||
if(!this.instances.containsKey(targetTeam)) {
|
Team targetTeam;
|
||||||
Lobby instance = new Lobby(targetTeam);
|
synchronized(this.teamLock) {
|
||||||
this.instances.put(targetTeam, instance);
|
targetTeam = this.teams.stream()
|
||||||
|
.filter(team -> team.users()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(user -> !user.dead() && user.uuid().equals(playerId)))
|
||||||
|
.reduce((a, b) -> {
|
||||||
|
throw new IllegalStateException("Zu deinem Account wurde mehr als ein Team gefunden. Bitte melde dies bei einem Admin!");
|
||||||
|
})
|
||||||
|
.orElseThrow(() -> new NoSuchElementException("Zu deinem Account wurde kein zugehöriges Team gefunden, da du entweder nicht angemeldet oder bereits ausgeschieden bist!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized(this.instances) {
|
||||||
|
if(!this.instances.containsKey(targetTeam)) {
|
||||||
|
Lobby instance = new Lobby(targetTeam);
|
||||||
|
this.instances.put(targetTeam, instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.instances.get(targetTeam);
|
return this.instances.get(targetTeam);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.mhsl.craftattack.teamLobby;
|
package eu.mhsl.craftattack.teamLobby;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.teamLobby.util.DisconnectInfo;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
||||||
@ -14,7 +15,6 @@ import java.io.InputStream;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static ConfigurationNode config;
|
private static ConfigurationNode config;
|
||||||
@ -66,8 +66,12 @@ public class Main {
|
|||||||
event.setSpawningInstance(lobby);
|
event.setSpawningInstance(lobby);
|
||||||
p.setRespawnPoint(lobby.spawnPoint);
|
p.setRespawnPoint(lobby.spawnPoint);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
event.getPlayer().kick(String.format("Login: %s", e.getMessage()));
|
new DisconnectInfo(
|
||||||
System.err.println(Arrays.toString(e.getStackTrace()));
|
"Login abgelehnt",
|
||||||
|
e.getMessage(),
|
||||||
|
"Wenn das ein Fehler ist, melde dich bitte bei einem Admin!",
|
||||||
|
event.getPlayer().getUuid()
|
||||||
|
).applyKick(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package eu.mhsl.craftattack.teamLobby.util;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record DisconnectInfo(String error, String description, String help, UUID user) {
|
||||||
|
public void applyKick(Player player) {
|
||||||
|
player.kick(this.getComponent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent() {
|
||||||
|
return Component.text()
|
||||||
|
.appendNewline().appendNewline()
|
||||||
|
.append(Component.text(this.error, NamedTextColor.DARK_RED)).appendNewline()
|
||||||
|
.append(Component.text(this.description, NamedTextColor.RED)).appendNewline().appendNewline()
|
||||||
|
.append(Component.text(this.help, NamedTextColor.GRAY)).appendNewline().appendNewline()
|
||||||
|
.append(Component.text(this.user.toString(), NamedTextColor.DARK_GRAY)).appendNewline()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Throwable extends Exception {
|
||||||
|
public String error;
|
||||||
|
public String description;
|
||||||
|
public String help;
|
||||||
|
public UUID user;
|
||||||
|
|
||||||
|
public Throwable(String error, String description, String help, UUID user) {
|
||||||
|
super(description);
|
||||||
|
this.error = error;
|
||||||
|
this.description = description;
|
||||||
|
this.help = help;
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisconnectInfo getDisconnectScreen() {
|
||||||
|
return new DisconnectInfo(this.error, this.description, this.help, this.user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user