2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-09-10 06:26:15 +02:00
|
|
|
import com.massivecraft.factions.Conf;
|
2011-09-24 12:04:49 +02:00
|
|
|
import com.massivecraft.factions.struct.ChatMode;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2018-08-05 03:32:36 +02:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
2014-12-08 00:12:52 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
2011-09-10 06:26:15 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
public class CmdChat extends FCommand {
|
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
public CmdChat() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("c");
|
|
|
|
this.aliases.add("chat");
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
//this.requiredArgs.add("");
|
|
|
|
this.optionalArgs.put("mode", "next");
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.CHAT)
|
|
|
|
.playerOnly()
|
|
|
|
.memberOnly()
|
|
|
|
.brigadier(ChatBrigadier.class)
|
|
|
|
.build();
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
|
|
|
if (!Conf.factionOnlyChat) {
|
|
|
|
context.msg(TL.COMMAND_CHAT_DISABLED.toString());
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
String modeString = context.argAsString(0);
|
|
|
|
ChatMode modeTarget = context.fPlayer.getChatMode().getNext();
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
if (modeString != null) {
|
|
|
|
modeString = modeString.toLowerCase();
|
|
|
|
// Only allow Mods and higher rank to switch to this channel.
|
|
|
|
if (modeString.startsWith("m")) {
|
|
|
|
if (!context.fPlayer.getRole().isAtLeast(Role.MODERATOR)) {
|
|
|
|
context.msg(TL.COMMAND_CHAT_MOD_ONLY);
|
|
|
|
return;
|
|
|
|
} else modeTarget = ChatMode.MOD;
|
|
|
|
} else if (modeString.startsWith("p")) {
|
|
|
|
modeTarget = ChatMode.PUBLIC;
|
|
|
|
} else if (modeString.startsWith("a")) {
|
|
|
|
modeTarget = ChatMode.ALLIANCE;
|
|
|
|
} else if (modeString.startsWith("f")) {
|
|
|
|
modeTarget = ChatMode.FACTION;
|
|
|
|
} else if (modeString.startsWith("t")) {
|
|
|
|
modeTarget = ChatMode.TRUCE;
|
|
|
|
} else {
|
|
|
|
context.msg(TL.COMMAND_CHAT_INVALIDMODE);
|
2019-08-24 19:18:50 +02:00
|
|
|
return;
|
2019-09-15 11:02:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
context.fPlayer.setChatMode(modeTarget);
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
switch (context.fPlayer.getChatMode()) {
|
|
|
|
case MOD:
|
|
|
|
context.msg(TL.COMMAND_CHAT_MODE_MOD);
|
|
|
|
break;
|
|
|
|
case PUBLIC:
|
|
|
|
context.msg(TL.COMMAND_CHAT_MODE_PUBLIC);
|
|
|
|
break;
|
|
|
|
case ALLIANCE:
|
|
|
|
context.msg(TL.COMMAND_CHAT_MODE_ALLIANCE);
|
|
|
|
break;
|
|
|
|
case TRUCE:
|
|
|
|
context.msg(TL.COMMAND_CHAT_MODE_TRUCE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
context.msg(TL.COMMAND_CHAT_MODE_FACTION);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-22 00:58:33 +01:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_CHAT_DESCRIPTION;
|
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
|
2019-09-15 11:02:53 +02:00
|
|
|
protected class ChatBrigadier implements BrigadierProvider {
|
|
|
|
@Override
|
|
|
|
public ArgumentBuilder<Object, ?> get(ArgumentBuilder<Object, ?> parent) {
|
|
|
|
return parent.then(LiteralArgumentBuilder.literal("public"))
|
|
|
|
.then(LiteralArgumentBuilder.literal("mod"))
|
|
|
|
.then(LiteralArgumentBuilder.literal("alliance"))
|
|
|
|
.then(LiteralArgumentBuilder.literal("faction"))
|
|
|
|
.then(LiteralArgumentBuilder.literal("truce"));
|
|
|
|
}
|
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|