timeout kick

This commit is contained in:
Gitea 2023-01-10 12:42:21 +08:00
parent 8d63abd40d
commit 284eb28183
3 changed files with 47 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package expvintl.tools;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -7,13 +8,18 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.List;
public class LoginHandler implements Listener {
private List<String> loggedPlayer=new ArrayList<>();
private YamlConfiguration cfg=Tools.loginConfig;
private final List<String> loggedPlayer=new ArrayList<>();
private final YamlConfiguration cfg=Tools.loginConfig;
private Plugin plugin;
public LoginHandler(Plugin plugin){
this.plugin=plugin;
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event){
if(!isLogged(event.getPlayer().getName())) event.setCancelled(true);
@ -67,6 +73,9 @@ public class LoginHandler implements Listener {
}else{
event.getPlayer().sendMessage("您似乎没有注册,请使用 \"/reg 密码 确认密码\" 来注册!");
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,()->{
event.getPlayer().kickPlayer("登录验证超时!");
},1200L);
}
public List<String> getLoggedPlayer(){
return loggedPlayer;

View File

@ -1,5 +1,6 @@
package expvintl.tools;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -10,7 +11,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.Random;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@ -23,7 +23,7 @@ public final class Tools extends JavaPlugin {
public void onEnable() {
// Plugin startup logic
logger.info("Plugin Enabled!");
loginHandler=new LoginHandler();
loginHandler=new LoginHandler(this);
getServer().getPluginManager().registerEvents(loginHandler,this);
}
@ -83,6 +83,7 @@ public final class Tools extends JavaPlugin {
}
loginHandler.getLoggedPlayer().add(sender.getName());
sender.sendMessage("登录成功!");
Bukkit.getScheduler().cancelTasks(this);
return true;
} else {
sender.sendMessage("缺少参数!");
@ -105,11 +106,40 @@ public final class Tools extends JavaPlugin {
}
loginHandler.getLoggedPlayer().add(sender.getName());
sender.sendMessage("登录成功!");
Bukkit.getScheduler().cancelTasks(this);
return true;
}else {
sender.sendMessage("参数错误!");
return false;
}
case "cp":
if(args.length==1){
if(loginHandler.isRegistered(sender.getName())&&loginHandler.isLogged(sender.getName())){
if (args[0].length() < 6 || args[0].length() > 16) {
sender.sendMessage("密码不能少于6位或大于16位!");
return true;
}
if(!Pattern.matches("[A-Za-z0-9.-_]+",args[0])){
sender.sendMessage("密码包含非法字符!\n请使用 大小写字母数字.-_等字符");
return true;
}
loginConfig.set(sender.getName(),args[0]);
try {
loginConfig.save(cfgPath);
} catch (IOException e) {
logger.warning(e.getMessage());
sender.sendMessage("密码保存失败!");
return true;
}
sender.sendMessage("密码修改成功!");
}else{
sender.sendMessage("您未注册或登录,无权修改密码!");
}
return true;
}else{
sender.sendMessage("缺少参数!");
return false;
}
case "kill":
if(args.length>0){
sender.sendMessage(args[0]+" 死了");

View File

@ -12,8 +12,11 @@ commands:
description: "传送到某个位置"
usage: "用法: /tp <玩家名> <x> <y> <z>"
reg:
description: "注册用户"
description: "注册用户"
usage: "用法: /reg 密码 确认密码"
l:
description: "登录账户"
usage: "用法: /l 密码"
cp:
description: "修改用户密码"
usage: "用法: /cp 新密码"