Core/src/main/java/eu/univento/core/antihack/modules/AutoRespawn.java

37 lines
1.2 KiB
Java

/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.core.antihack.modules;
import eu.univento.commons.player.warn.WarnReason;
import eu.univento.core.api.player.CustomPlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import java.util.HashMap;
public class AutoRespawn implements Listener {
private final HashMap<CustomPlayer, Long> time = new HashMap<>();
@EventHandler
public void onDeath(PlayerDeathEvent e) {
time.put(CustomPlayer.getPlayer(e.getEntity()), System.currentTimeMillis());
}
@EventHandler
public void onRespawn(PlayerRespawnEvent e) {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
if(time.containsKey(p)) {
if(System.currentTimeMillis() - time.get(p) <= 200L) {
//TODO: change to real warn reason
p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks");
}
time.remove(p);
}
}
}