tpa command

This commit is contained in:
Gitea 2023-01-10 16:15:38 +08:00
parent 284eb28183
commit cf0c5d2dcb
3 changed files with 80 additions and 4 deletions

View File

@ -16,7 +16,7 @@ import java.util.List;
public class LoginHandler implements Listener {
private final List<String> loggedPlayer=new ArrayList<>();
private final YamlConfiguration cfg=Tools.loginConfig;
private Plugin plugin;
private final Plugin plugin;
public LoginHandler(Plugin plugin){
this.plugin=plugin;
}
@ -73,9 +73,7 @@ public class LoginHandler implements Listener {
}else{
event.getPlayer().sendMessage("您似乎没有注册,请使用 \"/reg 密码 确认密码\" 来注册!");
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,()->{
event.getPlayer().kickPlayer("登录验证超时!");
},1200L);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,()-> event.getPlayer().kickPlayer("登录验证超时!"),1200L);
}
public List<String> getLoggedPlayer(){
return loggedPlayer;

View File

@ -10,6 +10,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@ -19,6 +21,7 @@ public final class Tools extends JavaPlugin {
public static YamlConfiguration loginConfig;
private final String cfgPath=getDataFolder().getPath()+"/PlayerLoginData.yml";
Logger logger=getLogger();
private final Map<String,String> reqQueue=new HashMap<>();
@Override
public void onEnable() {
// Plugin startup logic
@ -173,6 +176,71 @@ public final class Tools extends JavaPlugin {
return false;
}
return true;
case "tpa":
if(args.length==1){
Player target=getServer().getPlayer(args[0]);
if(Objects.isNull(target)) {
sender.sendMessage("玩家不存在或离线!");
return true;
}
sender.sendMessage("请求已发送给 "+ target.getName());
String jsonMsg="[{\"text\":\""+sender.getName()+" 希望传送到你的位置\\n\"},{\"text\":\"[点击接受]\",\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/tpaccept\"}},{\"text\":\" [点击拒绝]\",\"color\":\"red\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/tpreject\"}}]";
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),"tellraw "+target.getName()+" "+jsonMsg);
reqQueue.put(sender.getName(),target.getName());
Bukkit.getScheduler().scheduleSyncDelayedTask(this,()->{
reqQueue.remove(sender.getName());
target.sendMessage(sender.getName()+" 的传送请求已过期!");
sender.sendMessage(target.getName()+" 的传送请求已过期!");
},600);
return true;
}else{
sender.sendMessage("缺少玩家参数!");
return false;
}
case "tpaccept":
//标记所有键
for(String pl:reqQueue.keySet()){
//确定队列中存在传送目标玩家
if(reqQueue.get(pl).equals(sender.getName())){
Player tpSender=Bukkit.getPlayer(pl);
if(Objects.isNull(tpSender)){
sender.sendMessage("请求发送者已离线或不存在!");
return true;
}
//传送玩家
tpSender.teleport(player);
sender.sendMessage("传送中...");
tpSender.sendMessage("传送中...");
//从队列中删除
reqQueue.remove(pl);
return true;
}
}
sender.sendMessage("没有传送请求或请求已过期!");
return true;
case "tpreject":
//标记所有键
for(String pl:reqQueue.keySet()){
//确定队列中存在传送目标玩家
if(reqQueue.get(pl).equals(sender.getName())){
Player s=Bukkit.getPlayer(pl);
if(Objects.isNull(s))
{
sender.sendMessage("已拒绝传送请求!");
//从队列中删除
reqQueue.remove(pl);
return true;
}
sender.sendMessage("已拒绝传送请求!");
s.sendMessage(sender.getName()+" 拒绝了您的传送请求!");
//从队列中删除
reqQueue.remove(pl);
return true;
}
}
sender.sendMessage("没有传送请求或请求已过期!");
return true;
}
return true;
}
@ -180,5 +248,6 @@ public final class Tools extends JavaPlugin {
@Override
public void onDisable() {
// Plugin shutdown logic
getServer().broadcastMessage("插件已被重载,请重新登录或注册!");
}
}

View File

@ -20,3 +20,12 @@ commands:
cp:
description: "修改用户密码"
usage: "用法: /cp 新密码"
tpa:
description: "传送到某个玩家"
usage: "用法: /tpa 玩家"
tpaccept:
description: "接受传送请求"
usage: "用法: /tpaccept"
tpreject:
description: "拒绝传送请求"
usage: "用法: /tpreject"