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.

82 lines
1.7 KiB

package com.entryrise.afkguard.gui.inputs;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
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.PlayerEditBookEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import com.entryrise.afkguard.Main;
import com.entryrise.afkguard.utils.VersionMgr;
public abstract class GUIBookInput extends GUIInput<List<String>> {
private static ItemStack editbook;
private Inventory inv;
private Set<HumanEntity> ents = new HashSet<HumanEntity>();
static {
editbook = new ItemStack(VersionMgr.getWritableBook());
BookMeta bmeta = (BookMeta) editbook.getItemMeta();
bmeta.setDisplayName("§d§4EdItB00k");
}
public Inventory getInv() {
return inv;
}
public void setInv(Inventory inv) {
this.inv = inv;
}
@EventHandler(priority = EventPriority.LOW)
public void onChat(PlayerEditBookEvent e) {
if (e.isCancelled()) {
return;
}
Player p = e.getPlayer();
if (!ents.contains(p)) {
return;
}
e.setCancelled(true);
for (HumanEntity ent : ents) {
ent.openInventory(inv);
}
HandlerList.unregisterAll(this);
onResult(Arrays.asList(e.getNewBookMeta().getPage(0).split("\n")));
}
public GUIBookInput(Inventory inv) {
this.setInv(inv);
for (HumanEntity ent : inv.getViewers()) {
ents.add(ent);
ent.closeInventory();
Player p = (Player) ent;
VersionMgr.openBook(p, editbook);
}
Bukkit.getPluginManager().registerEvents(this, Main.p);
}
}