2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.commands.chat;
|
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
import co.aikar.commands.BaseCommand;
|
|
|
|
import co.aikar.commands.BukkitCommandIssuer;
|
|
|
|
import co.aikar.commands.annotation.CommandAlias;
|
|
|
|
import co.aikar.commands.annotation.Conditions;
|
|
|
|
import co.aikar.commands.annotation.Default;
|
|
|
|
import com.gmail.nossr50.commands.CommandManager;
|
|
|
|
import com.gmail.nossr50.datatypes.chat.ChatChannel;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.party.Party;
|
2020-10-27 00:31:02 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.party.PartyManager;
|
2020-10-27 21:09:01 +01:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2020-10-27 00:31:02 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2020-10-27 21:09:01 +01:00
|
|
|
@CommandAlias("p|partychat|pchat") //Kept for historical reasons
|
2020-10-27 00:31:02 +01:00
|
|
|
public class PartyChatCommand extends BaseCommand {
|
|
|
|
private final @NotNull mcMMO pluginRef;
|
2013-06-07 00:48:25 +02:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
public PartyChatCommand(@NotNull mcMMO pluginRef) {
|
|
|
|
this.pluginRef = pluginRef;
|
|
|
|
}
|
2019-04-13 00:17:05 +02:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
@Default
|
|
|
|
@Conditions(CommandManager.PARTY_CONDITION)
|
|
|
|
public void processCommand(String[] args) {
|
|
|
|
BukkitCommandIssuer bukkitCommandIssuer = (BukkitCommandIssuer) getCurrentCommandIssuer();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
if(args == null || args.length == 0) {
|
|
|
|
//Process with no arguments
|
|
|
|
if(bukkitCommandIssuer.isPlayer()) {
|
|
|
|
McMMOPlayer mmoPlayer = UserManager.getPlayer(bukkitCommandIssuer.getPlayer());
|
|
|
|
pluginRef.getChatManager().setOrToggleChatChannel(mmoPlayer, ChatChannel.PARTY);
|
|
|
|
} else {
|
|
|
|
//Not support for console
|
|
|
|
mcMMO.p.getLogger().info("You cannot switch chat channels as console, please provide full arguments.");
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2020-10-27 00:31:02 +01:00
|
|
|
} else {
|
|
|
|
//Here we split the logic, consoles need to target a party name and players do not
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
/*
|
|
|
|
* Player Logic
|
|
|
|
*/
|
|
|
|
if(bukkitCommandIssuer.getIssuer() instanceof Player) {
|
|
|
|
McMMOPlayer mmoPlayer = UserManager.getPlayer(bukkitCommandIssuer.getPlayer());
|
|
|
|
processCommandArgsPlayer(mmoPlayer, args);
|
|
|
|
/*
|
|
|
|
* Console Logic
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
processCommandArgsConsole(args);
|
2014-02-10 16:07:43 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2020-10-27 00:31:02 +01:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
/**
|
|
|
|
* Processes the command with arguments for a {@link McMMOPlayer}
|
|
|
|
* @param mmoPlayer target player
|
|
|
|
* @param args command arguments
|
|
|
|
*/
|
|
|
|
private void processCommandArgsPlayer(@NotNull McMMOPlayer mmoPlayer, @NotNull String[] args) {
|
|
|
|
//Player is not toggling and is chatting directly to party
|
|
|
|
pluginRef.getChatManager().processPlayerMessage(mmoPlayer, args, ChatChannel.PARTY);
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
/**
|
|
|
|
* Processes the command with arguments for a {@link com.gmail.nossr50.chat.author.ConsoleAuthor}
|
|
|
|
* @param args command arguments
|
|
|
|
*/
|
|
|
|
private void processCommandArgsConsole(@NotNull String[] args) {
|
|
|
|
if(args.length <= 1) {
|
|
|
|
//Only specific a party and not the message
|
|
|
|
mcMMO.p.getLogger().severe("You need to specify a party name and then write a message afterwards.");
|
|
|
|
} else {
|
|
|
|
//Grab party
|
|
|
|
Party targetParty = PartyManager.getParty(args[0]);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2020-10-27 00:31:02 +01:00
|
|
|
if(targetParty != null) {
|
2020-10-27 21:09:01 +01:00
|
|
|
pluginRef.getChatManager().processConsoleMessage(StringUtils.buildStringAfterNthElement(args, 1), targetParty);
|
2020-10-27 00:31:02 +01:00
|
|
|
} else {
|
|
|
|
mcMMO.p.getLogger().severe("A party with that name doesn't exist!");
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|