diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java index 98e4838..79c672e 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerJoinQuitListener.java @@ -36,6 +36,9 @@ public class PlayerJoinQuitListener implements Listener { @EventHandler public void onPlayerQuit(final PlayerQuitEvent e) { e.setQuitMessage(null); + if (!this.plugin.getTeamManager().hasTeam(e.getPlayer())) { + return; + } if (!this.plugin.getBanUtils().isBanned(e.getPlayer().getUniqueId())) { this.plugin.getNPCManager().createClone(e.getPlayer()); Bukkit.broadcast(this.plugin.getMessageUtils().getServiceMessage(e.getPlayer().getName(), @@ -53,7 +56,11 @@ public class PlayerJoinQuitListener implements Listener { e.setJoinMessage(null); this.plugin.getNPCManager().syncClones(e.getPlayer()); - this.plugin.getTeamManager().setTeam(e.getPlayer()); + if (!this.plugin.getTeamManager().setTeam(e.getPlayer())) { + e.getPlayer().kickPlayer( + "§4§lFehler!\n \n§cDu bist keinem Team zugeordnet.\n \n§r§7Kontaktiere bitte die §f§l@Admins §r§7auf dem Discord-Server."); + return; + } // Inject PacketReader final PacketReader packetReader = new PacketReader(this.plugin, e.getPlayer()); diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java index 7222742..ff74159 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java @@ -140,7 +140,7 @@ public class TeamManager { } } - public void setTeam(final Player player) { + public boolean setTeam(final Player player) { final JSONArray jsonTeams = config.getArray("teams"); for (final Object jsonRawTeam : jsonTeams) { final JSONObject jsonTeam = (JSONObject) jsonRawTeam; @@ -150,11 +150,27 @@ public class TeamManager { for (final Team team : this.teams) { if (team.getName().equals(jsonTeam.get("name").toString())) { team.addEntry(player.getName()); + return true; } } } } } + return false; + } + + public boolean hasTeam(final Player player) { + final JSONArray jsonTeams = config.getArray("teams"); + for (final Object jsonRawTeam : jsonTeams) { + final JSONObject jsonTeam = (JSONObject) jsonRawTeam; + for (final Object rawPlayer : ((JSONArray) jsonTeam.get("players"))) { + final JSONObject jsonPlayer = (JSONObject) rawPlayer; + if (jsonPlayer.get("uuid").equals(player.getUniqueId().toString().replace("-", ""))) { + return true; + } + } + } + return false; } @SuppressWarnings("unchecked")