mirror of
https://e.coding.net/circlecloud/GuiACK.git
synced 2024-12-04 16:38:48 +00:00
fix select error while player join server already...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
51f7e90dd6
commit
6e30713886
@ -2,14 +2,17 @@ package cn.citycraft.GuiACK;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
import cn.citycraft.GuiACK.gui.VerifyGui;
|
||||
import cn.citycraft.GuiACK.listen.PlayerListen;
|
||||
import cn.citycraft.GuiACK.runnable.TaskManager;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
@ -22,7 +25,7 @@ public class GuiACK extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload") && sender.hasPermission("gack.reload")) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload") && (sender.hasPermission("gack.reload") || sender.isOp())) {
|
||||
onLoad();
|
||||
sender.sendMessage("配置文件已重载!");
|
||||
}
|
||||
@ -31,7 +34,6 @@ public class GuiACK extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerListen(this), this);
|
||||
if (setupEconomy()) {
|
||||
isEconomy = true;
|
||||
this.getLogger().info("发现Vault 载入数据...");
|
||||
@ -45,6 +47,10 @@ public class GuiACK extends JavaPlugin {
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerListen(this), this);
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
TaskManager.add(p);
|
||||
this.getLogger().info("图形化防挂机验证码加载完毕!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +59,7 @@ public class GuiACK extends JavaPlugin {
|
||||
tasktime = config.getInt("TaskTime");
|
||||
reward = config.getDouble("Reward");
|
||||
VerifyGui.init(config.getStringList("VerifyList"));
|
||||
TaskManager.init(this);
|
||||
}
|
||||
|
||||
public boolean setupEconomy() {
|
||||
|
@ -5,30 +5,28 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class VerifyGui {
|
||||
static List<String> verifylist = new ArrayList<String>();
|
||||
static List<String> playerlist = new ArrayList<String>();
|
||||
public static String invname = "§v§e§r§c防挂机验证 §3请选择验证码: ";
|
||||
public static List<String> verifylist;
|
||||
public static List<String> playerlist;
|
||||
public static List<String> checklist;
|
||||
public static String invname = "§c防挂机验证 §3请选择验证码: ";
|
||||
|
||||
public static void add(Player p) {
|
||||
playerlist.add(p.getName());
|
||||
}
|
||||
|
||||
public static boolean checkopen(Player p) {
|
||||
public static void checkopen(Player p) {
|
||||
if (playerlist.contains(p.getName()))
|
||||
return false;
|
||||
else {
|
||||
p.kickPlayer(ChatColor.RED + "验证码输入选择超时 请重新登录!");
|
||||
else
|
||||
open(p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(List<String> verifylist) {
|
||||
VerifyGui.verifylist = verifylist;
|
||||
playerlist = new ArrayList<String>();
|
||||
checklist = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public static void open(Player p) {
|
||||
@ -45,10 +43,7 @@ public class VerifyGui {
|
||||
Inventory inv = Bukkit.createInventory(null, 9, invname + list[ri].getItemMeta().getDisplayName());
|
||||
inv.setContents(list);
|
||||
p.openInventory(inv);
|
||||
add(p);
|
||||
}
|
||||
|
||||
public static void remove(Player p) {
|
||||
playerlist.remove(p.getName());
|
||||
playerlist.add(p.getName());
|
||||
checklist.add(p.getName());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cn.citycraft.GuiACK.listen;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -13,19 +11,15 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
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;
|
||||
|
||||
HashMap<String, BukkitTask> tasklist = new HashMap<String, BukkitTask>();
|
||||
|
||||
HashMap<String, Boolean> checklist = new HashMap<String, Boolean>();
|
||||
|
||||
public PlayerListen(GuiACK plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -35,16 +29,12 @@ public class PlayerListen implements Listener {
|
||||
String guiname = e.getView().getTitle();
|
||||
if (!guiname.startsWith(VerifyGui.invname))
|
||||
return;
|
||||
if (e.getInventory().getItem(0) == null)
|
||||
return;
|
||||
Player p = (Player) e.getPlayer();
|
||||
if (checklist.containsKey(p.getName()) && checklist.get(p.getName())) {
|
||||
checklist.put(p.getName(), false);
|
||||
VerifyGui.remove(p);
|
||||
if (VerifyGui.checklist.contains(p.getName())) {
|
||||
if (p.isOnline())
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new VerifyTask(p), 3);
|
||||
return;
|
||||
}
|
||||
if (p.isOnline())
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new VerifyTask(p), 3);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -63,13 +53,13 @@ public class PlayerListen implements Listener {
|
||||
if (!ci.getItemMeta().hasDisplayName())
|
||||
return;
|
||||
String clickName = ci.getItemMeta().getDisplayName();
|
||||
VerifyGui.remove(p);
|
||||
VerifyGui.playerlist.remove(p.getName());
|
||||
if (!guiname.endsWith(clickName))
|
||||
p.kickPlayer("§c验证码选择错误 请重新登录!");
|
||||
else {
|
||||
plugin.economy.depositPlayer(p, plugin.reward);
|
||||
p.sendMessage("§a验证成功 奖励金钱: " + plugin.reward);
|
||||
checklist.put(p.getName(), true);
|
||||
VerifyGui.checklist.remove(p.getName());
|
||||
p.closeInventory();
|
||||
}
|
||||
}
|
||||
@ -77,18 +67,14 @@ public class PlayerListen implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
int tasktime = plugin.tasktime * 20 * 60;
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(plugin, new VerifyTask(p), tasktime, tasktime);
|
||||
tasklist.put(p.getName(), task);
|
||||
TaskManager.add(p);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (tasklist.containsKey(p.getName()))
|
||||
tasklist.get(p.getName()).cancel();
|
||||
tasklist.remove(p.getName());
|
||||
checklist.remove(p.getName());
|
||||
VerifyGui.remove(p);
|
||||
TaskManager.remove(p);
|
||||
VerifyGui.checklist.remove(p.getName());
|
||||
VerifyGui.playerlist.remove(p.getName());
|
||||
}
|
||||
}
|
||||
|
32
src/main/java/cn/citycraft/GuiACK/runnable/TaskManager.java
Normal file
32
src/main/java/cn/citycraft/GuiACK/runnable/TaskManager.java
Normal file
@ -0,0 +1,32 @@
|
||||
package cn.citycraft.GuiACK.runnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import cn.citycraft.GuiACK.GuiACK;
|
||||
|
||||
public class TaskManager {
|
||||
static HashMap<String, BukkitTask> tasklist;
|
||||
static GuiACK plugin;
|
||||
static int tasktime;
|
||||
|
||||
public static void add(Player p) {
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(plugin, new VerifyTask(p), tasktime, tasktime);
|
||||
tasklist.put(p.getName(), task);
|
||||
}
|
||||
|
||||
public static void init(GuiACK plugin) {
|
||||
TaskManager.plugin = plugin;
|
||||
tasktime = plugin.tasktime * 20 * 60;
|
||||
tasklist = new HashMap<String, BukkitTask>();
|
||||
}
|
||||
|
||||
public static void remove(Player p) {
|
||||
if (tasklist.containsKey(p.getName()))
|
||||
tasklist.remove(p.getName()).cancel();
|
||||
}
|
||||
|
||||
}
|
@ -14,8 +14,8 @@ public class VerifyTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
if (p.isOnline())
|
||||
if (!VerifyGui.checkopen(p))
|
||||
p.kickPlayer("验证码输入超时 请重新登录!");
|
||||
VerifyGui.checkopen(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user