tab completion, fix more

This commit is contained in:
speedxx 2020-08-01 21:48:15 -04:00
parent 232b2788c5
commit cd61afd3c8
11 changed files with 106 additions and 8 deletions

View file

@ -6,7 +6,7 @@
<groupId>me.totalfreedom</groupId> <groupId>me.totalfreedom</groupId>
<artifactId>TFGuilds</artifactId> <artifactId>TFGuilds</artifactId>
<version>0.2.6</version> <version>0.2.7</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>TFGuilds</name> <name>TFGuilds</name>

View file

@ -2,7 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;

View file

@ -2,7 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;

View file

@ -1,11 +1,17 @@
package me.totalfreedom.tfguilds.command; package me.totalfreedom.tfguilds.command;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
public class GuildCommand extends Common implements CommandExecutor public class GuildCommand extends Common implements CommandExecutor, TabCompleter
{ {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
@ -65,4 +71,45 @@ public class GuildCommand extends Common implements CommandExecutor
} }
return new HelpSubcommand().onCommand(sender, command, label, args); return new HelpSubcommand().onCommand(sender, command, label, args);
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args)
{
Guild guild = Guild.getGuild(sender);
if (args.length == 1)
{
return Arrays.asList("addmod", "chat", "createrank", "create",
"deleterank", "disband", "help", "home", "info", "invite",
"join", "kick", "leave", "list", "motd", "removemod", "rename",
"roster", "setowner", "setrank", "setstate", "tag", "tp");
}
else if (args.length == 2)
{
switch (args[0])
{
case "home":
return Arrays.asList("set");
case "info":
case "join":
case "roster":
return Guild.getGuildList();
case "motd":
case "tag":
return Arrays.asList("set", "clear");
case "setstate":
return Arrays.asList("OPEN", "INVITE", "CLOSED");
case "invite":
return GUtil.getPlayerList();
case "deleterank":
return guild.getRankNames();
case "tp":
case "removemod":
case "addmod":
case "setowner":
case "kick":
return guild.getMembers();
}
}
return Collections.emptyList();
}
} }

View file

@ -2,8 +2,6 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;

View file

@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil; import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;

View file

@ -43,6 +43,12 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
return true; return true;
} }
if (guild.getModerators().contains(sender.getName()))
{
sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
return true;
}
if (!guild.hasMember(player.getName())) if (!guild.hasMember(player.getName()))
{ {
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!"); sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
@ -89,6 +95,12 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
return true; return true;
} }
if (n == player)
{
sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
return true;
}
if (!guild.hasMember(n.getName())) if (!guild.hasMember(n.getName()))
{ {
sender.sendMessage(ChatColor.RED + "This player is not in your guild!"); sender.sendMessage(ChatColor.RED + "This player is not in your guild!");

View file

@ -43,6 +43,12 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
return true; return true;
} }
if (guild.getOwner().contains(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is already the owner of that guild!");
return true;
}
if (!guild.hasMember(player.getName())) if (!guild.hasMember(player.getName()))
{ {
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!"); sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
@ -84,6 +90,12 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
return true; return true;
} }
if (n == player)
{
sender.sendMessage(ChatColor.RED + "You are already the owner of your guild.");
return true;
}
if (!guild.hasMember(n.getName())) if (!guild.hasMember(n.getName()))
{ {
sender.sendMessage(ChatColor.RED + "This player is not in your guild!"); sender.sendMessage(ChatColor.RED + "This player is not in your guild!");

View file

@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank; import me.totalfreedom.tfguilds.guild.GuildRank;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View file

@ -11,6 +11,7 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -398,6 +399,20 @@ public class Guild
return guild; return guild;
} }
public static Guild getGuild(CommandSender sender)
{
Guild guild = null;
for (String key : plugin.guilds.getKeys(false))
{
Guild kg = getGuild(key);
if (kg.getMembers().contains(sender.getName()))
{
guild = kg;
}
}
return guild;
}
public static boolean guildExists(String identifier) public static boolean guildExists(String identifier)
{ {
return plugin.guilds.contains(identifier); return plugin.guilds.contains(identifier);

View file

@ -1,6 +1,8 @@
package me.totalfreedom.tfguilds.util; package me.totalfreedom.tfguilds.util;
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -9,6 +11,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.entity.Player;
public class GUtil public class GUtil
{ {
@ -45,4 +48,15 @@ public class GUtil
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList( public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
"admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin"); "admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin");
public static List<String> getPlayerList()
{
List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers())
{
players.add(player.getName());
}
return players;
}
} }