diff --git a/src/main/java/expvintl/tools/Tools.java b/src/main/java/expvintl/tools/Tools.java index 889f82d..b0cf93a 100644 --- a/src/main/java/expvintl/tools/Tools.java +++ b/src/main/java/expvintl/tools/Tools.java @@ -1,6 +1,9 @@ package expvintl.tools; +import expvintl.tools.commands.KeepInvCommand; import expvintl.tools.commands.TeleportAtCommand; +import expvintl.tools.commands.TpAcceptCommand; +import expvintl.tools.commands.TpRejectCommand; import expvintl.tools.commands.auth.ChangePasswordCommand; import expvintl.tools.commands.auth.LoginCommand; import expvintl.tools.commands.auth.RegisterCommand; @@ -80,6 +83,9 @@ public final class Tools extends JavaPlugin { getCommand("reg").setExecutor(new RegisterCommand()); getCommand("cp").setExecutor(new ChangePasswordCommand()); getCommand("tpa").setExecutor(new TeleportAtCommand()); + getCommand("tpaccept").setExecutor(new TpAcceptCommand()); + getCommand("tpreject").setExecutor(new TpRejectCommand()); + getCommand("keepinv").setExecutor(new KeepInvCommand()); } private void DisableBukkitCommands(){ try { @@ -119,73 +125,6 @@ public final class Tools extends JavaPlugin { initConfigs(); } - @Override - public boolean onCommand(CommandSender sender,Command command,String label,String[] args) { - Player player=this.getServer().getPlayer(sender.getName()); - if(Objects.isNull(player)){ - sender.sendMessage("玩家不存在!"); - return true; - } - switch(label) { - 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; - case "keepinv": - if(args.length==1){ - Bukkit.getWorlds().forEach(world -> { - boolean result=Boolean.parseBoolean(args[0]); - world.setGameRule(GameRule.KEEP_INVENTORY,result); - sender.sendMessage(String.format("已为 %s %s死亡不掉落",world.getName(), Boolean.TRUE.equals(world.getGameRuleValue(GameRule.KEEP_INVENTORY)) ?"开启":"关闭")); - }); - }else{ - sender.sendMessage("参数不够!"); - return false; - } - return true; - } - return true; - } - @Override public void onDisable() { // Plugin shutdown logic diff --git a/src/main/java/expvintl/tools/commands/KeepInvCommand.java b/src/main/java/expvintl/tools/commands/KeepInvCommand.java new file mode 100644 index 0000000..e312a6b --- /dev/null +++ b/src/main/java/expvintl/tools/commands/KeepInvCommand.java @@ -0,0 +1,24 @@ +package expvintl.tools.commands; + +import org.bukkit.Bukkit; +import org.bukkit.GameRule; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class KeepInvCommand implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(args.length==1){ + Bukkit.getWorlds().forEach(world -> { + boolean result=Boolean.parseBoolean(args[0]); + world.setGameRule(GameRule.KEEP_INVENTORY,result); + sender.sendMessage(String.format("宸蹭负 %s %s姝讳骸涓嶆帀钀",world.getName(), Boolean.TRUE.equals(world.getGameRuleValue(GameRule.KEEP_INVENTORY)) ?"寮鍚":"鍏抽棴")); + }); + }else{ + sender.sendMessage("鍙傛暟涓嶅!"); + return false; + } + return true; + } +} diff --git a/src/main/java/expvintl/tools/commands/TpAcceptCommand.java b/src/main/java/expvintl/tools/commands/TpAcceptCommand.java new file mode 100644 index 0000000..ad1778d --- /dev/null +++ b/src/main/java/expvintl/tools/commands/TpAcceptCommand.java @@ -0,0 +1,42 @@ +package expvintl.tools.commands; + +import expvintl.tools.Tools; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Objects; + +public class TpAcceptCommand implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, Command command,String label,String[] args) { + Tools t= Tools.INSTANCE; + Player player=Bukkit.getServer().getPlayer(sender.getName()); + if(Objects.isNull(player)){ + sender.sendMessage("鐜╁涓嶅瓨鍦!"); + return true; + } + //鏍囪鎵鏈夐敭 + for(String pl:t.reqQueue.keySet()){ + //纭畾闃熷垪涓瓨鍦ㄤ紶閫佺洰鏍囩帺瀹 + if(t.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("浼犻佷腑..."); + //浠庨槦鍒椾腑鍒犻櫎 + t.reqQueue.remove(pl); + return true; + } + } + sender.sendMessage("娌℃湁浼犻佽姹傛垨璇锋眰宸茶繃鏈!"); + return true; + } +} diff --git a/src/main/java/expvintl/tools/commands/TpRejectCommand.java b/src/main/java/expvintl/tools/commands/TpRejectCommand.java new file mode 100644 index 0000000..be4cd96 --- /dev/null +++ b/src/main/java/expvintl/tools/commands/TpRejectCommand.java @@ -0,0 +1,38 @@ +package expvintl.tools.commands; + +import expvintl.tools.Tools; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Objects; + +public class TpRejectCommand implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender,Command command,String label,String[] args) { + Tools t= Tools.INSTANCE; + //鏍囪鎵鏈夐敭 + for(String pl:t.reqQueue.keySet()){ + //纭畾闃熷垪涓瓨鍦ㄤ紶閫佺洰鏍囩帺瀹 + if(t.reqQueue.get(pl).equals(sender.getName())){ + Player s= Bukkit.getPlayer(pl); + if(Objects.isNull(s)) + { + sender.sendMessage("宸叉嫆缁濅紶閫佽姹!"); + //浠庨槦鍒椾腑鍒犻櫎 + t.reqQueue.remove(pl); + return true; + } + sender.sendMessage("宸叉嫆缁濅紶閫佽姹!"); + s.sendMessage(sender.getName()+" 鎷掔粷浜嗘偍鐨勪紶閫佽姹!"); + //浠庨槦鍒椾腑鍒犻櫎 + t.reqQueue.remove(pl); + return true; + } + } + sender.sendMessage("娌℃湁浼犻佽姹傛垨璇锋眰宸茶繃鏈!"); + return true; + } +}