57 lines
2.1 KiB
Java
57 lines
2.1 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.Core;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class Regen implements Listener {
|
|
|
|
private final ArrayList<CustomPlayer> a = new ArrayList<>();
|
|
private final ArrayList<CustomPlayer> b = new ArrayList<>();
|
|
|
|
@EventHandler
|
|
public void onRegainHealth(EntityRegainHealthEvent e) {
|
|
if (e.getEntity() instanceof Player) {
|
|
CustomPlayer p = CustomPlayer.getPlayer((Player) e.getEntity());
|
|
|
|
if (p.getFoodLevel() > 16 && e.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
|
|
if (a.contains(p) && b.contains(p)) {
|
|
a.remove(p);
|
|
}
|
|
if (e.getAmount() > 1.0) {
|
|
p.setFoodLevel(0);
|
|
//TODO: change to real warn reason
|
|
p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks");
|
|
return;
|
|
}
|
|
if (!b.contains(p) && !a.contains(p)) {
|
|
a.add(p);
|
|
b.add(p);
|
|
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
|
if (!a.contains(p)) {
|
|
p.setFoodLevel(0);
|
|
b.remove(p);
|
|
//TODO: change to real warn reason
|
|
p.warn(WarnReason.SPAM, null, "https://players.univento.eu/" + p.getUniqueId().toString() + "/hacks");
|
|
} else if (a.contains(p)) {
|
|
a.remove(p);
|
|
b.remove(p);
|
|
}
|
|
}, 10L);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |