2020-07-13 00:40:11 +00:00
|
|
|
package me.totalfreedom.tfguilds.command;
|
|
|
|
|
|
|
|
import me.totalfreedom.tfguilds.Common;
|
|
|
|
import me.totalfreedom.tfguilds.guild.Guild;
|
|
|
|
import me.totalfreedom.tfguilds.util.GUtil;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class RemoveModSubcommand extends Common implements CommandExecutor
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
|
|
|
{
|
2020-07-15 00:20:25 +00:00
|
|
|
if (args.length == 1 || args.length > 3)
|
2020-07-29 21:03:05 +00:00
|
|
|
{
|
2020-07-15 00:20:25 +00:00
|
|
|
return false;
|
2020-07-29 21:03:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (args.length == 3)
|
|
|
|
{
|
|
|
|
if (!plugin.bridge.isAdmin(sender))
|
|
|
|
{
|
|
|
|
sender.sendMessage(NO_PERMS);
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
Guild guild = Guild.getGuild(args[1]);
|
|
|
|
if (guild == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
Player player = Bukkit.getPlayer(args[2]);
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage(PNF);
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (!guild.hasMember(player.getName()))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (!guild.hasModerator(player.getName()))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "This member is not a moderator for this guild!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
guild.removeModerator(player.getName());
|
|
|
|
sender.sendMessage(tl(PREFIX + "Removed %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
|
|
|
|
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a member of your guild."));
|
|
|
|
guild.save();
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (sender instanceof ConsoleCommandSender)
|
|
|
|
{
|
|
|
|
sender.sendMessage(NO_PERMS);
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
|
|
|
Player player = (Player)sender;
|
2020-07-13 00:40:11 +00:00
|
|
|
Guild guild = Guild.getGuild(player);
|
|
|
|
if (guild == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (!guild.getOwner().equals(player.getName()))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
Player n = Bukkit.getPlayer(args[1]);
|
|
|
|
if (n == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage(PNF);
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (!guild.hasMember(n.getName()))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
if (!guild.hasModerator(n.getName()))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "This member is not a moderator for your guild!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-13 00:40:11 +00:00
|
|
|
guild.removeModerator(n.getName());
|
|
|
|
sender.sendMessage(tl(PREFIX + "Removed %s%" + n.getName() + "%p% as a moderator for your guild."));
|
|
|
|
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a member of your guild."));
|
|
|
|
guild.save();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|