feat: kick and ban player on death

This commit is contained in:
Simon Giesel 2020-05-03 20:54:27 +02:00
parent efe372e15b
commit db397894ed
2 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,39 @@
package de.cliffbreak.varo.listeners;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import de.cliffbreak.varo.Varo;
public class PlayerDeathListener implements Listener {
private final Varo plugin;
public PlayerDeathListener(final Varo plugin) {
this.plugin = plugin;
}
@EventHandler()
public void onPlayerDeath(final PlayerDeathEvent e) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
e.getEntity().kickPlayer("§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");
}
}, 20);
e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned)
e.getEntity().setGameMode(GameMode.SPECTATOR);
@SuppressWarnings("unchecked")
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
bans.add(e.getEntity().getUniqueId().toString().replace("-", ""));
this.plugin.config.set("Varo.Bans", bans);
this.plugin.saveConfiguration();
}
}

View file

@ -0,0 +1,28 @@
package de.cliffbreak.varo.listeners;
import java.util.ArrayList;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import de.cliffbreak.varo.Varo;
public class PlayerPreLoginListener implements Listener {
private final Varo plugin;
public PlayerPreLoginListener(final Varo plugin) {
this.plugin = plugin;
}
@EventHandler()
public void onPlayerPreLogin(final AsyncPlayerPreLoginEvent e) {
@SuppressWarnings("unchecked")
final ArrayList<String> bans = (ArrayList<String>) this.plugin.config.get("Varo.Bans");
if (bans.contains(e.getPlayerProfile().getId().toString().replace("-", ""))) {
e.disallow(Result.KICK_BANNED, "§4Du bist gestorben.\n \n§cDamit bist du aus §eVaro§c ausgeschieden.");
}
}
}