update
This commit is contained in:
parent
d1fc832d2d
commit
764b2788ae
@ -23,7 +23,6 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -58,7 +57,6 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
@Inject
|
@Inject
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
private StringBuilder sb;
|
|
||||||
|
|
||||||
private PacketAdapter chatPacketListener;
|
private PacketAdapter chatPacketListener;
|
||||||
private PacketAdapter windowPacketListener;
|
private PacketAdapter windowPacketListener;
|
||||||
@ -73,7 +71,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
String randomString = "";
|
String randomString = "";
|
||||||
Random randomItemSet = new Random();
|
Random randomItemSet = new Random();
|
||||||
Random howManyRandom = new Random();
|
Random howManyRandom = new Random();
|
||||||
|
private boolean isPacketListenersActive = false;
|
||||||
|
|
||||||
int howLongIsRandomString;
|
int howLongIsRandomString;
|
||||||
|
|
||||||
@ -87,27 +85,15 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void removePacketListeners() {
|
private void addPacketListeners() {
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(windowPacketListener);
|
if (!isPacketListenersActive) {
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(chatPacketListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(windowPacketListener);
|
||||||
}
|
ProtocolLibrary.getProtocolManager().addPacketListener(chatPacketListener);
|
||||||
|
isPacketListenersActive = true;
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
|
||||||
sb = new StringBuilder();
|
|
||||||
howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
|
|
||||||
for (int i = 0; i < howLongIsRandomString; i++) {
|
|
||||||
//生成随机索引号
|
|
||||||
int index = randomItemSet.nextInt(randomSet.length());
|
|
||||||
|
|
||||||
// 从字符串中获取由索引 index 指定的字符
|
|
||||||
char randomChar = randomSet.charAt(index);
|
|
||||||
|
|
||||||
// 将字符追加到字符串生成器
|
|
||||||
sb.append(randomChar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (event.getWhoClicked() instanceof Player) {
|
if (event.getWhoClicked() instanceof Player) {
|
||||||
@ -145,18 +131,18 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bukkitService.runTaskAsynchronously(() -> {
|
bukkitService.runTaskAsynchronously(() -> {
|
||||||
// StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
// howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
|
howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
|
||||||
// for (int i = 0; i < howLongIsRandomString; i++) {
|
for (int i = 0; i < howLongIsRandomString; i++) {
|
||||||
// //生成随机索引号
|
//生成随机索引号
|
||||||
// int index = randomItemSet.nextInt(randomSet.length());
|
int index = randomItemSet.nextInt(randomSet.length());
|
||||||
//
|
|
||||||
// // 从字符串中获取由索引 index 指定的字符
|
// 从字符串中获取由索引 index 指定的字符
|
||||||
// char randomChar = randomSet.charAt(index);
|
char randomChar = randomSet.charAt(index);
|
||||||
//
|
|
||||||
// // 将字符追加到字符串生成器
|
// 将字符追加到字符串生成器
|
||||||
// sb.append(randomChar);
|
sb.append(randomChar);
|
||||||
// }
|
}
|
||||||
bukkitService.runTask(() -> {
|
bukkitService.runTask(() -> {
|
||||||
randomString = sb.toString();
|
randomString = sb.toString();
|
||||||
Random random_blockpos = new Random();
|
Random random_blockpos = new Random();
|
||||||
@ -211,8 +197,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(windowPacketListener);
|
addPacketListeners();
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(chatPacketListener);
|
|
||||||
//Open captcha inventory
|
//Open captcha inventory
|
||||||
menu.setItem(random_num.get(), item);
|
menu.setItem(random_num.get(), item);
|
||||||
playerunreg.openInventory(menu);
|
playerunreg.openInventory(menu);
|
||||||
@ -240,6 +225,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void deletePlayerData(UUID playerUUID) {
|
private void deletePlayerData(UUID playerUUID) {
|
||||||
// 获取服务器的存储文件夹路径
|
// 获取服务器的存储文件夹路径
|
||||||
File serverFolder = Bukkit.getServer().getWorldContainer();
|
File serverFolder = Bukkit.getServer().getWorldContainer();
|
||||||
@ -294,10 +280,8 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
deleteAuthMePlayerData(playerUUID);
|
deleteAuthMePlayerData(playerUUID);
|
||||||
}
|
}
|
||||||
}, 100L);
|
}, 100L);
|
||||||
removePacketListeners();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
removePacketListeners();
|
|
||||||
closeReasonMap.remove(player);
|
closeReasonMap.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user