user cant message themselves now and added tab complete to some command

This commit is contained in:
night0721 2022-07-10 22:38:41 +01:00
parent 5f55a90a7e
commit caba15bb3b
2 changed files with 36 additions and 7 deletions

View file

@ -4,7 +4,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class MessageCommand extends Command { public class MessageCommand extends Command {
@ -24,12 +27,16 @@ public class MessageCommand extends Command {
if (args.length >= 2) { if (args.length >= 2) {
if(Bukkit.getPlayerExact(args[0]) != null) { if(Bukkit.getPlayerExact(args[0]) != null) {
Player target = Bukkit.getPlayerExact(args[0]); Player target = Bukkit.getPlayerExact(args[0]);
StringBuilder builder = new StringBuilder(); if(!target.equals(player)) {
for(int i = 1; i < args.length; i++) { StringBuilder builder = new StringBuilder();
builder.append(args[i]).append(" "); for(int i = 1; i < args.length; i++) {
builder.append(args[i]).append(" ");
}
player.sendMessage(ChatColor.DARK_AQUA + "TO " + ChatColor.RED + target.getName() + ChatColor.WHITE + " : " + builder);
target.sendMessage(ChatColor.DARK_AQUA + "FROM " + ChatColor.RED + player.getName() + ChatColor.WHITE + " : " + builder);
} else {
player.sendMessage(ChatColor.RED + "You cannot send message to yourself");
} }
player.sendMessage(ChatColor.DARK_AQUA + "TO " + ChatColor.RED + target.getName() + ChatColor.WHITE + " : " + builder);
target.sendMessage(ChatColor.DARK_AQUA + "FROM " + ChatColor.RED + player.getName() + ChatColor.WHITE + " : " + builder);
} else { } else {
player.sendMessage(ChatColor.RED + "You cannot send message to offline players"); player.sendMessage(ChatColor.RED + "You cannot send message to offline players");
} }
@ -41,6 +48,13 @@ public class MessageCommand extends Command {
@Override @Override
public List<String> onTabComplete(CommandSender sender, String[] args) { public List<String> onTabComplete(CommandSender sender, String[] args) {
return null; if(args.length == 1) {
List<String> names = new ArrayList<>();
for(Player player: Bukkit.getOnlinePlayers()) {
names.add(player.getName());
}
return StringUtil.copyPartialMatches(args[0], names, new ArrayList<>());
}
return new ArrayList<>();
} }
} }

View file

@ -9,7 +9,9 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -69,6 +71,19 @@ public class RankCommand extends Command {
@Override @Override
public List<String> onTabComplete(CommandSender sender, String[] args) { public List<String> onTabComplete(CommandSender sender, String[] args) {
return null; if(args.length == 1) {
List<String> names = new ArrayList<>();
for(Player player: Bukkit.getOnlinePlayers()) {
names.add(player.getName());
}
return StringUtil.copyPartialMatches(args[0], names, new ArrayList<>());
} else if(args.length == 2) {
List<String> roles = new ArrayList<>();
for(Rank rank : Rank.values()){
roles.add(rank.name());
}
return StringUtil.copyPartialMatches(args[1], roles, new ArrayList<>());
}
return new ArrayList<>();
} }
} }