optimize command register
This commit is contained in:
parent
26af0865f7
commit
26f4a8e6a6
@ -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
|
||||
|
24
src/main/java/expvintl/tools/commands/KeepInvCommand.java
Normal file
24
src/main/java/expvintl/tools/commands/KeepInvCommand.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
42
src/main/java/expvintl/tools/commands/TpAcceptCommand.java
Normal file
42
src/main/java/expvintl/tools/commands/TpAcceptCommand.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
38
src/main/java/expvintl/tools/commands/TpRejectCommand.java
Normal file
38
src/main/java/expvintl/tools/commands/TpRejectCommand.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user