1.14 support, better error handling #108
4 changed files with 42 additions and 2 deletions
|
@ -90,6 +90,10 @@ public class ChannelconCommand extends ICommand2DC {
|
|||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender, String channelID) {
|
||||
val message = sender.getMessage();
|
||||
if (!module.allowCustomChat().get()) {
|
||||
sender.sendMessage("channel connection is not allowed on this Minecraft server.");
|
||||
return true;
|
||||
}
|
||||
if (checkPerms(message)) return true;
|
||||
if (MCChatCustom.hasCustomChat(message.getChannelId()))
|
||||
return respond(sender, "this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
||||
|
|
|
@ -9,6 +9,7 @@ import buttondevteam.lib.TBMCCoreAPI;
|
|||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
|
@ -17,10 +18,17 @@ import lombok.val;
|
|||
"It can be useful if you don't want your messages to be visible, for example when talking in a private channel.", //
|
||||
"You can also run all of the ingame commands you have access to using this command, if you have your accounts connected." //
|
||||
})
|
||||
@RequiredArgsConstructor
|
||||
public class MCChatCommand extends ICommand2DC {
|
||||
|
||||
private final MinecraftChatModule module;
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender) {
|
||||
if (!module.allowPrivateChat().get()) {
|
||||
sender.sendMessage("using the private chat is not allowed on this Minecraft server.");
|
||||
return true;
|
||||
}
|
||||
val message = sender.getMessage();
|
||||
val channel = message.getChannel().block();
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent") val author = message.getAuthor().get();
|
||||
|
|
|
@ -53,7 +53,8 @@ public class MCChatUtils {
|
|||
private static HashMap<Class<? extends Event>, HashSet<String>> staticExcludedPlugins = new HashMap<>();
|
||||
|
||||
public static void updatePlayerList() {
|
||||
if (notEnabled()) return;
|
||||
val mod = getModule();
|
||||
if (mod == null || !mod.showPlayerListOnDC().get()) return;
|
||||
if (lastmsgdata != null)
|
||||
updatePL(lastmsgdata);
|
||||
MCChatCustom.lastmsgCustom.forEach(MCChatUtils::updatePL);
|
||||
|
|
|
@ -77,6 +77,33 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
|||
return getConfig().getData("allowFakePlayerTeleports", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is on, each chat channel will have a player list in their description.
|
||||
* It only gets added if there's no description yet or there are (at least) two lines of "----" following each other.
|
||||
* Note that it will replace <b>everything</b> between the first and last "----" but it will only detect exactly four dashes.
|
||||
* So if you want to use dashes for something else in the description, make sure it's either less or more dashes in one line.
|
||||
*/
|
||||
public ConfigData<Boolean> showPlayerListOnDC() {
|
||||
return getConfig().getData("showPlayerListOnDC", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This setting controls whether custom chat connections can be <i>created</i> (existing connections will always work).
|
||||
* Custom chat connections can be created using the channelcon command and they allow players to display town chat in a Discord channel for example.
|
||||
* See the channelcon command for more details.
|
||||
*/
|
||||
public ConfigData<Boolean> allowCustomChat() {
|
||||
return getConfig().getData("allowCustomChat", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This setting allows you to control if players can DM the bot to log on the server from Discord.
|
||||
* This allows them to both chat and perform any command they can in-game.
|
||||
*/
|
||||
public ConfigData<Boolean> allowPrivateChat() {
|
||||
return getConfig().getData("allowPrivateChat", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigErrorRes(this, chatChannel(), chatChannelMono()))
|
||||
|
@ -84,7 +111,7 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
|||
listener = new MCChatListener(this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
|
||||
getPlugin().getManager().registerCommand(new MCChatCommand());
|
||||
getPlugin().getManager().registerCommand(new MCChatCommand(this));
|
||||
getPlugin().getManager().registerCommand(new ChannelconCommand(this));
|
||||
|
||||
val chcons = getConfig().getConfig().getConfigurationSection("chcons");
|
||||
|
|
Loading…
Reference in a new issue