package cn.citycraft.GuiACK.listen; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import cn.citycraft.GuiACK.GuiACK; import cn.citycraft.GuiACK.gui.VerifyGui; import cn.citycraft.GuiACK.runnable.TaskManager; import cn.citycraft.GuiACK.runnable.VerifyTask; public class PlayerListen implements Listener { GuiACK plugin; public PlayerListen(GuiACK plugin) { this.plugin = plugin; } @EventHandler public void onCloseInv(InventoryCloseEvent e) { String guiname = e.getView().getTitle(); if (!guiname.startsWith(VerifyGui.invname)) return; Player p = (Player) e.getPlayer(); if (VerifyGui.checklist.contains(p.getName())) { if (p.isOnline()) Bukkit.getScheduler().runTaskLater(plugin, new VerifyTask(p), 3); return; } } @EventHandler public void onItemClick(InventoryClickEvent e) { Inventory inv = e.getInventory(); String guiname = inv.getName(); if (!guiname.startsWith(VerifyGui.invname)) return; if (!(e.getWhoClicked() instanceof Player)) return; e.setCancelled(true); Player p = (Player) e.getWhoClicked(); ItemStack ci = e.getCurrentItem(); if (ci == null || ci.getType() == Material.AIR) return; if (!ci.getItemMeta().hasDisplayName()) return; String clickName = ci.getItemMeta().getDisplayName(); VerifyGui.playerlist.remove(p.getName()); if (!guiname.endsWith(clickName)) p.kickPlayer("§c验证码选择错误 请重新登录!"); else { plugin.economy.depositPlayer(p, plugin.reward); p.sendMessage("§a验证成功 奖励金钱: " + plugin.reward); VerifyGui.checklist.remove(p.getName()); p.closeInventory(); } } @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { Player p = e.getPlayer(); TaskManager.add(p); } @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { Player p = e.getPlayer(); TaskManager.remove(p); VerifyGui.checklist.remove(p.getName()); VerifyGui.playerlist.remove(p.getName()); } }