feat: kick Player if not in Team

This commit is contained in:
Simon Giesel 2020-05-19 22:33:57 +02:00
parent fd2a1b7953
commit 3d07798315
2 changed files with 25 additions and 2 deletions

View file

@ -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());

View file

@ -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")