AFKGuard allows you to detect even the most tricky AFK machines and cheats, by being fully configurable and accessible!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.7 KiB

package com.entryrise.afkguard.gui.inputs;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.Inventory;
import com.entryrise.afkguard.Main;
public abstract class GUIChatInput extends GUIInput<String> {
private Inventory inv;
private Set<HumanEntity> ents = new HashSet<HumanEntity>();
public Inventory getInv() {
return inv;
}
public void setInv(Inventory inv) {
this.inv = inv;
}
@EventHandler(priority = EventPriority.LOW)
public void onCommand(PlayerCommandPreprocessEvent e) {
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
if (!ents.contains(p)) {
return;
}
e.setCancelled(true);
p.sendMessage("You can't execute commands while inputting in a GUI.");
}
@EventHandler(priority = EventPriority.LOW)
public void onChat(AsyncPlayerChatEvent e) {
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
if (!ents.contains(p)) {
return;
}
String chat = e.getMessage();
e.setCancelled(true);
for (HumanEntity ent : ents) {
ent.openInventory(inv);
}
HandlerList.unregisterAll(this);
onResult(chat);
}
public GUIChatInput(Inventory inv) {
this.setInv(inv);
for (HumanEntity ent : inv.getViewers()) {
ents.add(ent);
ent.closeInventory();
}
Bukkit.getPluginManager().registerEvents(this, Main.p);
}
}