user cant message themselves now and added tab complete to some command
This commit is contained in:
parent
5f55a90a7e
commit
caba15bb3b
2 changed files with 36 additions and 7 deletions
|
@ -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]);
|
||||||
|
if(!target.equals(player)) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for(int i = 1; i < args.length; i++) {
|
for(int i = 1; i < args.length; i++) {
|
||||||
builder.append(args[i]).append(" ");
|
builder.append(args[i]).append(" ");
|
||||||
}
|
}
|
||||||
player.sendMessage(ChatColor.DARK_AQUA + "TO " + ChatColor.RED + target.getName() + ChatColor.WHITE + " : " + builder);
|
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);
|
target.sendMessage(ChatColor.DARK_AQUA + "FROM " + ChatColor.RED + player.getName() + ChatColor.WHITE + " : " + builder);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + "You cannot send message to yourself");
|
||||||
|
}
|
||||||
} 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<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue