Localized GUI Captcha
This commit is contained in:
parent
fcc34c28aa
commit
010874586a
@ -7,7 +7,10 @@ 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.message.MessageKey;
|
||||||
|
import fr.xephi.authme.message.Messages;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
|
import fr.xephi.authme.service.CommonService;
|
||||||
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;
|
||||||
@ -43,6 +46,10 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
@Inject
|
@Inject
|
||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
|
@Inject
|
||||||
|
private Messages messages;
|
||||||
|
@Inject
|
||||||
|
private CommonService service;
|
||||||
|
|
||||||
private PacketAdapter chatPacketListener;
|
private PacketAdapter chatPacketListener;
|
||||||
private PacketAdapter windowPacketListener;
|
private PacketAdapter windowPacketListener;
|
||||||
@ -85,7 +92,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
closeReasonMap.put(player, "verified");
|
closeReasonMap.put(player, "verified");
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
player.sendMessage("§a验证完成");
|
messages.send(player, MessageKey.GUI_CAPTCHA_VERIFIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +106,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
if (!authmeApi.isRegistered(name) && !isNpc(playerunreg)) {
|
if (!authmeApi.isRegistered(name) && !isNpc(playerunreg)) {
|
||||||
if (isBedrockPlayer(playerunreg.getUniqueId())) {
|
if (isBedrockPlayer(playerunreg.getUniqueId())) {
|
||||||
closeReasonMap.put(playerunreg, "verified");
|
closeReasonMap.put(playerunreg, "verified");
|
||||||
playerunreg.sendMessage("§a基岩版自动验证完成");
|
messages.send(playerunreg, MessageKey.GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bukkitService.runTaskAsynchronously(() -> {
|
bukkitService.runTaskAsynchronously(() -> {
|
||||||
@ -120,12 +127,12 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
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));
|
||||||
Inventory menu = Bukkit.createInventory(playerunreg, 27, randomString + "请验证你是真人");
|
Inventory menu = Bukkit.createInventory(playerunreg, 27, messages.retrieveSingle(playerunreg, MessageKey.GUI_CAPTCHA_WINDOW_NAME, randomString));
|
||||||
ItemStack item = new ItemStack(Material.REDSTONE_BLOCK);
|
ItemStack item = new ItemStack(Material.REDSTONE_BLOCK);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
try {
|
try {
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
meta.setDisplayName("§a" + randomString + "§a我是真人");
|
meta.setDisplayName(messages.retrieveSingle(playerunreg, MessageKey.GUI_CAPTCHA_CLICKABLE_NAME, randomString));
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
@ -146,7 +153,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
bukkitService.runTask(() -> {
|
bukkitService.runTask(() -> {
|
||||||
bukkitService.runTaskLater(() -> {
|
bukkitService.runTaskLater(() -> {
|
||||||
if (!closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
if (!closeReasonMap.containsKey(playerunreg) && !authmeApi.isRegistered(playerunreg.getName())) {
|
||||||
playerunreg.kickPlayer("§c验证超时");
|
playerunreg.kickPlayer(service.retrieveSingleMessage(playerunreg, MessageKey.GUI_CAPTCHA_KICK_TIMEOUT));
|
||||||
timesLeft = 3; // Reset the attempt counter
|
timesLeft = 3; // Reset the attempt counter
|
||||||
}
|
}
|
||||||
}, finalTimeOut * 20L);
|
}, finalTimeOut * 20L);
|
||||||
@ -160,19 +167,19 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
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) {
|
||||||
bukkitService.runTask(() -> {
|
bukkitService.runTask(() -> {
|
||||||
playerunreg.kickPlayer("§c请先完成人机验证!");
|
playerunreg.kickPlayer(service.retrieveSingleMessage(playerunreg, MessageKey.GUI_CAPTCHA_KICK_FAILED));
|
||||||
});
|
});
|
||||||
timesLeft = 3;
|
timesLeft = 3;
|
||||||
} else {
|
} else {
|
||||||
--timesLeft;
|
--timesLeft;
|
||||||
if (timesLeft <= 0) {
|
if (timesLeft <= 0) {
|
||||||
bukkitService.runTask(() -> {
|
bukkitService.runTask(() -> {
|
||||||
playerunreg.kickPlayer("§c请先完成人机验证!");
|
playerunreg.kickPlayer(service.retrieveSingleMessage(playerunreg, MessageKey.GUI_CAPTCHA_KICK_FAILED));
|
||||||
});
|
});
|
||||||
timesLeft = 3;
|
timesLeft = 3;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerunreg.sendMessage("§c请先完成验证!,你还有" + timesLeft + "次机会");
|
messages.send(playerunreg, MessageKey.GUI_CAPTCHA_RETRY_MESSAGE, String.valueOf(timesLeft));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
random_num.set(random_blockpos.nextInt(26));
|
random_num.set(random_blockpos.nextInt(26));
|
||||||
bukkitService.runTask(() -> {
|
bukkitService.runTask(() -> {
|
||||||
@ -191,7 +198,7 @@ public class GuiCaptchaHandler implements Listener {
|
|||||||
@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())) {
|
||||||
playerunreg.sendMessage("§c请先完成验证!");
|
messages.send(playerunreg, MessageKey.GUI_CAPTCHA_DENIED_MESSAGE);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,13 +4,59 @@ package fr.xephi.authme.message;
|
|||||||
* Keys for translatable messages managed by {@link Messages}.
|
* Keys for translatable messages managed by {@link Messages}.
|
||||||
*/
|
*/
|
||||||
public enum MessageKey {
|
public enum MessageKey {
|
||||||
/** In order to use this command you must be authenticated! */
|
/**
|
||||||
|
* %random Verification
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_WINDOW_NAME("gui_captcha.captcha_window_name", "%random"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* %random I am human
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_CLICKABLE_NAME("gui_captcha.captcha_clickable_name", "%random"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verification failed, you have %times retries left
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_RETRY_MESSAGE("gui_captcha.message_on_retry", "%times"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bedrock verification success!
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_VERIFIED_AUTO_BEDROCK("gui_captcha.bedrock_auto_verify_success"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Please be verified before chatting!
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_DENIED_MESSAGE("gui_captcha.denied_message_sending"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verification timed out!
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_KICK_TIMEOUT("gui_captcha.kick_on_timeout"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Please complete the verification!
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_KICK_FAILED("gui_captcha.kick_on_failed"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verification success!
|
||||||
|
*/
|
||||||
|
GUI_CAPTCHA_VERIFIED("gui_captcha.success"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In order to use this command you must be authenticated!
|
||||||
|
*/
|
||||||
DENIED_COMMAND("error.denied_command"),
|
DENIED_COMMAND("error.denied_command"),
|
||||||
|
|
||||||
/** A player with the same IP is already in game! */
|
/**
|
||||||
|
* A player with the same IP is already in game!
|
||||||
|
*/
|
||||||
SAME_IP_ONLINE("on_join_validation.same_ip_online"),
|
SAME_IP_ONLINE("on_join_validation.same_ip_online"),
|
||||||
|
|
||||||
/** In order to chat you must be authenticated! */
|
/**
|
||||||
|
* In order to chat you must be authenticated!
|
||||||
|
*/
|
||||||
DENIED_CHAT("error.denied_chat"),
|
DENIED_CHAT("error.denied_chat"),
|
||||||
|
|
||||||
/** AntiBot protection mode is enabled! You have to wait some minutes before joining the server. */
|
/** AntiBot protection mode is enabled! You have to wait some minutes before joining the server. */
|
||||||
|
|||||||
@ -149,6 +149,7 @@ public class MessageUpdater {
|
|||||||
.put("verification", "Verification code")
|
.put("verification", "Verification code")
|
||||||
.put("time", "Time units")
|
.put("time", "Time units")
|
||||||
.put("two_factor", "Two-factor authentication")
|
.put("two_factor", "Two-factor authentication")
|
||||||
|
.put("gui_captcha", "3rd party features: GUI Captcha")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Set<String> addedKeys = new HashSet<>();
|
Set<String> addedKeys = new HashSet<>();
|
||||||
|
|||||||
@ -155,3 +155,14 @@ time:
|
|||||||
hours: 'hours'
|
hours: 'hours'
|
||||||
day: 'day'
|
day: 'day'
|
||||||
days: 'days'
|
days: 'days'
|
||||||
|
|
||||||
|
# 3rd party features: GUI Captcha
|
||||||
|
gui_captcha:
|
||||||
|
success: '&aVerification success!'
|
||||||
|
bedrock_auto_verify_success: '&aBedrock verification success!'
|
||||||
|
captcha_window_name: '%random Verification'
|
||||||
|
captcha_clickable_name: '%random I am human'
|
||||||
|
message_on_retry: '&cVerification failed, you have %times retries left'
|
||||||
|
denied_message_sending: '&cPlease be verified before chatting!'
|
||||||
|
kick_on_failed: '&cPlease complete the verification!'
|
||||||
|
kick_on_timeout: '&cVerification timed out!'
|
||||||
|
|||||||
@ -154,13 +154,24 @@ time:
|
|||||||
|
|
||||||
# Two-factor authentication
|
# Two-factor authentication
|
||||||
two_factor:
|
two_factor:
|
||||||
code_created: '&7您正在激活双重验证, 请打开 &a%url &7扫描二维码'
|
code_created: '&7您正在激活双重验证, 请打开 &a%url &7扫描二维码'
|
||||||
confirmation_required: '&7请输入“/totp confirm <验证码>”来确认激活双重验证'
|
confirmation_required: '&7请输入“/totp confirm <验证码>”来确认激活双重验证'
|
||||||
code_required: '&c请输入“/totp code <验证码>”来提交验证码'
|
code_required: '&c请输入“/totp code <验证码>”来提交验证码'
|
||||||
already_enabled: '&a双重验证已启用'
|
already_enabled: '&a双重验证已启用'
|
||||||
enable_error_no_code: '&c验证码丢失'
|
enable_error_no_code: '&c验证码丢失'
|
||||||
enable_success: '&a已成功启用双重验证'
|
enable_success: '&a已成功启用双重验证'
|
||||||
enable_error_wrong_code: '&c验证码错误或者已经过期,请重新执行“/totp add”'
|
enable_error_wrong_code: '&c验证码错误或者已经过期,请重新执行“/totp add”'
|
||||||
not_enabled_error: '&c双重验证未在您的账号上启用,请使用“/totp add”来启用'
|
not_enabled_error: '&c双重验证未在您的账号上启用,请使用“/totp add”来启用'
|
||||||
removed_success: '&c双重验证已从您的账号上禁用'
|
removed_success: '&c双重验证已从您的账号上禁用'
|
||||||
invalid_code: '&c无效的验证码'
|
invalid_code: '&c无效的验证码'
|
||||||
|
|
||||||
|
# 3rd party features: GUI Captcha
|
||||||
|
gui_captcha:
|
||||||
|
success: '&a*** 验证完成 ***'
|
||||||
|
bedrock_auto_verify_success: '&a*** 基岩版自动验证完成 ***'
|
||||||
|
captcha_window_name: '&k%random&r&n请验证你是真人'
|
||||||
|
captcha_clickable_name: '&k%random&r&n我是真人'
|
||||||
|
message_on_retry: '&c验证失败,你还有 %times 次机会'
|
||||||
|
denied_message_sending: '&c请先完成验证再聊天!'
|
||||||
|
kick_on_failed: '&c请先完成验证!'
|
||||||
|
kick_on_timeout: '&c验证超时'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user