2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.chat;
|
|
|
|
|
2013-06-07 00:48:25 +02:00
|
|
|
import com.gmail.nossr50.chat.ChatManager;
|
|
|
|
import com.gmail.nossr50.chat.ChatManagerFactory;
|
2014-03-03 18:27:45 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-07-15 14:44:13 +02:00
|
|
|
import com.gmail.nossr50.datatypes.chat.ChatMode;
|
2014-03-03 18:27:45 +01:00
|
|
|
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-12 02:06:26 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-12 02:06:26 +01:00
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2013-03-28 17:57:49 +01:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabExecutor;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.StringUtil;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
public abstract class ChatCommand implements TabExecutor {
|
2013-10-29 20:38:20 +01:00
|
|
|
private ChatMode chatMode;
|
2013-06-07 00:48:25 +02:00
|
|
|
protected ChatManager chatManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public ChatCommand(ChatMode chatMode) {
|
|
|
|
this.chatMode = chatMode;
|
2013-06-07 00:48:25 +02:00
|
|
|
this.chatManager = ChatManagerFactory.getChatManager(mcMMO.p, chatMode);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2013-10-29 20:38:20 +01:00
|
|
|
McMMOPlayer mcMMOPlayer;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
switch (args.length) {
|
|
|
|
case 0:
|
2013-03-12 02:06:26 +01:00
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2014-08-20 06:23:19 +02:00
|
|
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
mcMMOPlayer = UserManager.getPlayer(sender.getName());
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
if (mcMMOPlayer.isChatEnabled(chatMode)) {
|
|
|
|
disableChatMode(mcMMOPlayer, sender);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-10-29 20:38:20 +01:00
|
|
|
enableChatMode(mcMMOPlayer, sender);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.shouldEnableToggle(args[0])) {
|
2019-04-18 22:58:50 +02:00
|
|
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-12 02:06:26 +01:00
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
enableChatMode(UserManager.getPlayer(sender.getName()), sender);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
if (CommandUtils.shouldDisableToggle(args[0])) {
|
2019-04-18 22:58:50 +02:00
|
|
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-12 02:06:26 +01:00
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
disableChatMode(UserManager.getPlayer(sender.getName()), sender);
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallthrough
|
|
|
|
|
|
|
|
default:
|
|
|
|
handleChatSending(sender, args);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 17:57:49 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<String>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
protected String buildChatMessage(String[] args, int index) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append(args[index]);
|
|
|
|
|
|
|
|
for (int i = index + 1; i < args.length; i++) {
|
|
|
|
builder.append(" ");
|
|
|
|
builder.append(args[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
2013-06-07 00:48:25 +02:00
|
|
|
protected String getDisplayName(CommandSender sender) {
|
|
|
|
return (sender instanceof Player) ? ((Player) sender).getDisplayName() : LocaleLoader.getString("Commands.Chat.Console");
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
protected abstract void handleChatSending(CommandSender sender, String[] args);
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
private void enableChatMode(McMMOPlayer mcMMOPlayer, CommandSender sender) {
|
2013-03-12 02:06:26 +01:00
|
|
|
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-11 17:42:57 +01:00
|
|
|
if (chatMode == ChatMode.PARTY && (mcMMOPlayer.getParty().getLevel() < Config.getInstance().getPartyFeatureUnlockLevel(PartyFeature.CHAT))) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.1"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
mcMMOPlayer.enableChat(chatMode);
|
2013-03-01 06:52:01 +01:00
|
|
|
sender.sendMessage(chatMode.getEnabledMessage());
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
private void disableChatMode(McMMOPlayer mcMMOPlayer, CommandSender sender) {
|
2013-03-12 02:06:26 +01:00
|
|
|
if (chatMode == ChatMode.PARTY && mcMMOPlayer.getParty() == null) {
|
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:38:20 +01:00
|
|
|
mcMMOPlayer.disableChat(chatMode);
|
2013-03-01 06:52:01 +01:00
|
|
|
sender.sendMessage(chatMode.getDisabledMessage());
|
|
|
|
}
|
|
|
|
}
|