2020-07-14 04:27:55 +00:00
|
|
|
package me.totalfreedom.tfguilds.command;
|
|
|
|
|
|
|
|
import me.totalfreedom.tfguilds.Common;
|
|
|
|
import me.totalfreedom.tfguilds.guild.Guild;
|
|
|
|
import me.totalfreedom.tfguilds.util.GUtil;
|
2020-08-02 01:48:15 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2020-07-14 04:27:55 +00:00
|
|
|
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 MOTDSubcommand 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)
|
2020-07-29 21:03:05 +00:00
|
|
|
{
|
2020-08-14 20:13:14 +00:00
|
|
|
sender.sendMessage(tl(PREFIX + "Proper usage: /g motd <set <motd> | clear>"));
|
|
|
|
return true;
|
2020-07-29 21:03:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 04:27:55 +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-14 04:27:55 +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-14 04:27:55 +00:00
|
|
|
if (!guild.hasModerator(player.getName()))
|
|
|
|
{
|
|
|
|
sender.sendMessage(ChatColor.RED + "You can't modify your guild's MOTD!");
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-14 04:27:55 +00:00
|
|
|
if (args.length >= 3)
|
|
|
|
{
|
|
|
|
if (args[1].equalsIgnoreCase("set"))
|
|
|
|
{
|
|
|
|
String motd = StringUtils.join(args, " ", 2, args.length);
|
|
|
|
guild.setMotd(motd);
|
|
|
|
guild.save();
|
|
|
|
sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(motd) + "%p% as the new MOTD of your guild%p%."));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-29 21:03:05 +00:00
|
|
|
|
2020-07-14 04:27:55 +00:00
|
|
|
if (!args[1].equalsIgnoreCase("clear"))
|
2020-07-29 21:03:05 +00:00
|
|
|
{
|
2020-07-14 04:27:55 +00:00
|
|
|
return false;
|
2020-07-29 21:03:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 04:27:55 +00:00
|
|
|
guild.setMotd(null);
|
|
|
|
guild.save();
|
|
|
|
sender.sendMessage(tl(PREFIX + "Cleared your guild's MOTD."));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|