Improved code style
This commit is contained in:
parent
73c3cea778
commit
f8dd410d96
@ -124,6 +124,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called when the server enables the plugin.
|
* Method called when the server enables the plugin.
|
||||||
*/
|
*/
|
||||||
@ -233,13 +234,13 @@ public class AuthMe extends JavaPlugin {
|
|||||||
if (settings.getProperty(SecuritySettings.FORCE_LOGIN_BEDROCK) && settings.getProperty(HooksSettings.HOOK_FLOODGATE_PLAYER) && getServer().getPluginManager().getPlugin("floodgate") != null) {
|
if (settings.getProperty(SecuritySettings.FORCE_LOGIN_BEDROCK) && settings.getProperty(HooksSettings.HOOK_FLOODGATE_PLAYER) && getServer().getPluginManager().getPlugin("floodgate") != null) {
|
||||||
getServer().getPluginManager().registerEvents(new BedrockAutoLoginListener((Plugin) this), this);
|
getServer().getPluginManager().registerEvents(new BedrockAutoLoginListener((Plugin) this), this);
|
||||||
}
|
}
|
||||||
if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
// if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
||||||
getServer().getPluginManager().registerEvents(new GuiCaptchaHandler((Plugin) this), this);
|
// getServer().getPluginManager().registerEvents(new GuiCaptchaHandler((Plugin) this), this);
|
||||||
logger.info("(Beta)GUICaptcha is enabled successfully!");
|
// logger.info("(Beta)GUICaptcha is enabled successfully!");
|
||||||
logger.info("These features are still in early development, if you encountered any problem, please report.");
|
// logger.info("These features are still in early development, if you encountered any problem, please report.");
|
||||||
} else if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
|
// } else if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||||
logger.warning("ProtocolLib is not loaded, can't enable GUI Captcha.");
|
// logger.warning("ProtocolLib is not loaded, can't enable GUI Captcha.");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Load the version and build number of the plugin from the description file.
|
* Load the version and build number of the plugin from the description file.
|
||||||
@ -335,6 +336,16 @@ public class AuthMe extends JavaPlugin {
|
|||||||
pluginManager.registerEvents(injector.getSingleton(EntityListener.class), this);
|
pluginManager.registerEvents(injector.getSingleton(EntityListener.class), this);
|
||||||
pluginManager.registerEvents(injector.getSingleton(ServerListener.class), this);
|
pluginManager.registerEvents(injector.getSingleton(ServerListener.class), this);
|
||||||
|
|
||||||
|
//Register 3rd party listeners
|
||||||
|
if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
||||||
|
pluginManager.registerEvents(injector.getSingleton(GuiCaptchaHandler.class), this);
|
||||||
|
logger.info("(Beta)GUICaptcha is enabled successfully!");
|
||||||
|
logger.info("These features are still in early development, if you encountered any problem, please report.");
|
||||||
|
} else if (settings.getProperty(SecuritySettings.GUI_CAPTCHA) && getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||||
|
logger.warning("ProtocolLib is not loaded, can't enable GUI Captcha.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Try to register 1.8+ player listeners
|
// Try to register 1.8+ player listeners
|
||||||
if (isClassLoaded("org.bukkit.event.entity.EntityPickupItemEvent") && isClassLoaded("org.bukkit.event.player.PlayerSwapHandItemsEvent")) {
|
if (isClassLoaded("org.bukkit.event.entity.EntityPickupItemEvent") && isClassLoaded("org.bukkit.event.player.PlayerSwapHandItemsEvent")) {
|
||||||
pluginManager.registerEvents(injector.getSingleton(PlayerListenerHigherThan18.class), this);
|
pluginManager.registerEvents(injector.getSingleton(PlayerListenerHigherThan18.class), this);
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import com.comphenix.protocol.events.PacketAdapter;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||||
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
@ -22,8 +23,8 @@ 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;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -34,11 +35,15 @@ import java.util.logging.Level;
|
|||||||
import static fr.xephi.authme.util.PlayerUtils.isNpc;
|
import static fr.xephi.authme.util.PlayerUtils.isNpc;
|
||||||
import static org.bukkit.Bukkit.getLogger;
|
import static org.bukkit.Bukkit.getLogger;
|
||||||
import static org.bukkit.Bukkit.getServer;
|
import static org.bukkit.Bukkit.getServer;
|
||||||
|
|
||||||
public class GuiCaptchaHandler implements Listener {
|
public class GuiCaptchaHandler implements Listener {
|
||||||
//define AuthMeApi
|
//define AuthMeApi
|
||||||
private final AuthMeApi authmeApi = AuthMeApi.getInstance();
|
private final AuthMeApi authmeApi = AuthMeApi.getInstance();
|
||||||
|
@Inject
|
||||||
|
private BukkitService bukkitService;
|
||||||
|
@Inject
|
||||||
|
private AuthMe plugin;
|
||||||
|
|
||||||
private final Plugin plugin;
|
|
||||||
private PacketAdapter chatPacketListener;
|
private PacketAdapter chatPacketListener;
|
||||||
private PacketAdapter windowPacketListener;
|
private PacketAdapter windowPacketListener;
|
||||||
//define timesLeft
|
//define timesLeft
|
||||||
@ -55,8 +60,7 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
|
|
||||||
int howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
|
int howLongIsRandomString = (howManyRandom.nextInt(3) + 1);
|
||||||
|
|
||||||
public GuiCaptchaHandler(Plugin plugin) {
|
public GuiCaptchaHandler() {
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBedrockPlayer(UUID uuid) {
|
private boolean isBedrockPlayer(UUID uuid) {
|
||||||
@ -83,7 +87,6 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.sendMessage("§a验证完成");
|
player.sendMessage("§a验证完成");
|
||||||
}
|
}
|
||||||
//force to string
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +102,7 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
playerunreg.sendMessage("§a基岩版自动验证完成");
|
playerunreg.sendMessage("§a基岩版自动验证完成");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
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++) {
|
||||||
@ -113,7 +116,7 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
sb.append(randomChar);
|
sb.append(randomChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
randomString = sb.toString();
|
randomString = sb.toString();
|
||||||
Random random_blockpos = new Random();
|
Random random_blockpos = new Random();
|
||||||
AtomicInteger random_num = new AtomicInteger(random_blockpos.nextInt(26));
|
AtomicInteger random_num = new AtomicInteger(random_blockpos.nextInt(26));
|
||||||
@ -133,15 +136,15 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
if (AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > 0) {
|
if (AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > 0) {
|
||||||
long timeOut = AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT);
|
long timeOut = AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT);
|
||||||
if (AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > AuthMe.settings.getProperty(RestrictionSettings.TIMEOUT)) {
|
if (AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) > AuthMe.settings.getProperty(RestrictionSettings.TIMEOUT)) {
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
getLogger().warning("AuthMe detected that your GUI captcha timeout seconds(" + AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) + ") is bigger than the Login timeout seconds(" +
|
getLogger().warning("AuthMe detected that your GUI captcha timeout seconds(" + AuthMe.settings.getProperty(SecuritySettings.GUI_CAPTCHA_TIMEOUT) + ") is bigger than the Login timeout seconds(" +
|
||||||
AuthMe.settings.getProperty(RestrictionSettings.TIMEOUT) + "). To prevent issues, we will let the GUI captcha follow the Login timeout seconds, please check and modify your config.");
|
AuthMe.settings.getProperty(RestrictionSettings.TIMEOUT) + "). To prevent issues, we will let the GUI captcha follow the Login timeout seconds, please check and modify your config.");
|
||||||
});
|
});
|
||||||
timeOut = AuthMe.settings.getProperty(RestrictionSettings.TIMEOUT);
|
timeOut = AuthMe.settings.getProperty(RestrictionSettings.TIMEOUT);
|
||||||
}
|
}
|
||||||
long finalTimeOut = timeOut;
|
long finalTimeOut = timeOut;
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> {
|
bukkitService.runTaskLater(() -> {
|
||||||
if (!closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
if (!closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
||||||
playerunreg.kickPlayer("§c验证超时");
|
playerunreg.kickPlayer("§c验证超时");
|
||||||
timesLeft = 3; // Reset the attempt counter
|
timesLeft = 3; // Reset the attempt counter
|
||||||
@ -150,20 +153,20 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
windowPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CLOSE_WINDOW) {
|
windowPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CLOSE_WINDOW) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
if (event.getPlayer() == playerunreg && !closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
if (event.getPlayer() == playerunreg && !closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
||||||
if (timesLeft <= 0) {
|
if (timesLeft <= 0) {
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
playerunreg.kickPlayer("§c请先完成人机验证!");
|
playerunreg.kickPlayer("§c请先完成人机验证!");
|
||||||
});
|
});
|
||||||
timesLeft = 3;
|
timesLeft = 3;
|
||||||
} else {
|
} else {
|
||||||
--timesLeft;
|
--timesLeft;
|
||||||
if (timesLeft <= 0) {
|
if (timesLeft <= 0) {
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
playerunreg.kickPlayer("§c请先完成人机验证!");
|
playerunreg.kickPlayer("§c请先完成人机验证!");
|
||||||
});
|
});
|
||||||
timesLeft = 3;
|
timesLeft = 3;
|
||||||
@ -172,7 +175,7 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
playerunreg.sendMessage("§c请先完成验证!,你还有" + timesLeft + "次机会");
|
playerunreg.sendMessage("§c请先完成验证!,你还有" + timesLeft + "次机会");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
random_num.set(random_blockpos.nextInt(26));
|
random_num.set(random_blockpos.nextInt(26));
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
menu.setItem(random_num.get(), item);
|
menu.setItem(random_num.get(), item);
|
||||||
playerunreg.openInventory(menu);
|
playerunreg.openInventory(menu);
|
||||||
@ -183,7 +186,7 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
};
|
};
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(windowPacketListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(windowPacketListener);
|
||||||
});
|
});
|
||||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
bukkitService.runTask(() -> {
|
||||||
chatPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
chatPacketListener = new PacketAdapter(this.plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceiving(PacketEvent event) {
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
@ -237,7 +240,7 @@ public class GuiCaptchaHandler implements Listener{
|
|||||||
if (!authmeApi.isRegistered(name)) {
|
if (!authmeApi.isRegistered(name)) {
|
||||||
if (AuthMe.settings.getProperty(SecuritySettings.DELETE_UNVERIFIED_PLAYER_DATA) && !closeReasonMap.containsKey(player)) {
|
if (AuthMe.settings.getProperty(SecuritySettings.DELETE_UNVERIFIED_PLAYER_DATA) && !closeReasonMap.containsKey(player)) {
|
||||||
closeReasonMap.remove(player);
|
closeReasonMap.remove(player);
|
||||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> {
|
bukkitService.runTaskLater(() -> {
|
||||||
if (!player.isOnline()) {
|
if (!player.isOnline()) {
|
||||||
deletePlayerData(playerUUID);
|
deletePlayerData(playerUUID);
|
||||||
deletePlayerStats(playerUUID);
|
deletePlayerStats(playerUUID);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user