Config conversion
This commit is contained in:
parent
fdcab1acb2
commit
7866ddbe06
16 changed files with 87 additions and 128 deletions
|
@ -115,7 +115,7 @@ public final class DPUtils {
|
|||
*/
|
||||
public static String botmention() {
|
||||
if (DiscordPlugin.plugin == null) return "#bot";
|
||||
return channelMention(DiscordPlugin.plugin.commandChannel().get());
|
||||
return channelMention(DiscordPlugin.plugin.commandChannel.get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,28 +88,28 @@ public abstract class DiscordConnectedPlayer extends DiscordSenderBase implement
|
|||
|
||||
@Override
|
||||
public boolean teleport(Location location) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
if (module.allowFakePlayerTeleports.get())
|
||||
this.location = location;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
if (module.allowFakePlayerTeleports.get())
|
||||
this.location = location;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Entity destination) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
if (module.allowFakePlayerTeleports.get())
|
||||
this.location = destination.getLocation();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Entity destination, PlayerTeleportEvent.TeleportCause cause) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
if (module.allowFakePlayerTeleports.get())
|
||||
this.location = destination.getLocation();
|
||||
return true;
|
||||
}
|
||||
|
@ -227,6 +227,7 @@ public abstract class DiscordConnectedPlayer extends DiscordSenderBase implement
|
|||
return GameMode.SPECTATOR;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private final Player.Spigot spigot = new Player.Spigot() {
|
||||
@Override
|
||||
public InetSocketAddress getRawAddress() {
|
||||
|
|
|
@ -52,13 +52,11 @@ public class DiscordPlugin extends ButtonPlugin {
|
|||
/**
|
||||
* The prefix to use with Discord commands like /role. It only works in the bot channel.
|
||||
*/
|
||||
private ConfigData<Character> prefix() {
|
||||
return getIConfig().getData("prefix", '/', str -> ((String) str).charAt(0), Object::toString);
|
||||
}
|
||||
private final ConfigData<Character> prefix = getIConfig().getData("prefix", '/', str -> ((String) str).charAt(0), Object::toString);
|
||||
|
||||
public static char getPrefix() {
|
||||
if (plugin == null) return '/';
|
||||
return plugin.prefix().get();
|
||||
return plugin.prefix.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,23 +77,21 @@ public class DiscordPlugin extends ButtonPlugin {
|
|||
/**
|
||||
* The (bot) channel to use for Discord commands like /role.
|
||||
*/
|
||||
public ConfigData<Snowflake> commandChannel() {
|
||||
return DPUtils.snowflakeData(getIConfig(), "commandChannel", 0L);
|
||||
}
|
||||
public ConfigData<Snowflake> commandChannel = DPUtils.snowflakeData(getIConfig(), "commandChannel", 0L);
|
||||
|
||||
/**
|
||||
* The role that allows using mod-only Discord commands.
|
||||
* If empty (''), then it will only allow for the owner.
|
||||
*/
|
||||
public ConfigData<Mono<Role>> modRole() {
|
||||
return DPUtils.roleData(getIConfig(), "modRole", "Moderator");
|
||||
}
|
||||
public ConfigData<Mono<Role>> modRole;
|
||||
|
||||
/**
|
||||
* The invite link to show by /discord invite. If empty, it defaults to the first invite if the bot has access.
|
||||
*/
|
||||
public ConfigData<String> inviteLink() {
|
||||
return getIConfig().getData("inviteLink", "");
|
||||
public ConfigData<String> inviteLink = getIConfig().getData("inviteLink", "");
|
||||
|
||||
private void setupConfig() {
|
||||
modRole = DPUtils.roleData(getIConfig(), "modRole", "Moderator");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -175,7 +171,8 @@ public class DiscordPlugin extends ButtonPlugin {
|
|||
mainServer().set(Optional.of(mainServer)); //Save in config
|
||||
}
|
||||
SafeMode = false;
|
||||
DPUtils.disableIfConfigErrorRes(null, commandChannel(), DPUtils.getMessageChannel(commandChannel()));
|
||||
setupConfig();
|
||||
DPUtils.disableIfConfigErrorRes(null, commandChannel, DPUtils.getMessageChannel(commandChannel));
|
||||
//Won't disable, just prints the warning here
|
||||
|
||||
CommonListeners.register(dc.getEventDispatcher());
|
||||
|
|
|
@ -27,48 +27,36 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
|
|||
/**
|
||||
* Channel to post new posts.
|
||||
*/
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> channel() {
|
||||
return DPUtils.channelData(getConfig(), "channel");
|
||||
}
|
||||
public final ReadOnlyConfigData<Mono<MessageChannel>> channel = DPUtils.channelData(getConfig(), "channel");
|
||||
|
||||
/**
|
||||
* Channel where distinguished (moderator) posts go.
|
||||
*/
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> modChannel() {
|
||||
return DPUtils.channelData(getConfig(), "modChannel");
|
||||
}
|
||||
private final ReadOnlyConfigData<Mono<MessageChannel>> modChannel = DPUtils.channelData(getConfig(), "modChannel");
|
||||
|
||||
/**
|
||||
* Automatically unpins all messages except the last few. Set to 0 or >50 to disable
|
||||
*/
|
||||
private ConfigData<Short> keepPinned() {
|
||||
return getConfig().getData("keepPinned", (short) 40);
|
||||
}
|
||||
private final ConfigData<Short> keepPinned = getConfig().getData("keepPinned", (short) 40);
|
||||
|
||||
private ConfigData<Long> lastAnnouncementTime() {
|
||||
return getConfig().getData("lastAnnouncementTime", 0L);
|
||||
}
|
||||
private final ConfigData<Long> lastAnnouncementTime = getConfig().getData("lastAnnouncementTime", 0L);
|
||||
|
||||
private ConfigData<Long> lastSeenTime() {
|
||||
return getConfig().getData("lastSeenTime", 0L);
|
||||
}
|
||||
private final ConfigData<Long> lastSeenTime = getConfig().getData("lastSeenTime", 0L);
|
||||
|
||||
/**
|
||||
* The subreddit to pull the posts from
|
||||
*/
|
||||
private ConfigData<String> subredditURL() {
|
||||
return getConfig().getData("subredditURL", "https://www.reddit.com/r/ChromaGamers");
|
||||
}
|
||||
private final ConfigData<String> subredditURL = getConfig().getData("subredditURL", "https://www.reddit.com/r/ChromaGamers");
|
||||
|
||||
private static boolean stop = false;
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigError(this, channel(), modChannel())) return;
|
||||
if (DPUtils.disableIfConfigError(this, channel, modChannel)) return;
|
||||
stop = false; //If not the first time
|
||||
val keepPinned = keepPinned().get();
|
||||
if (keepPinned == 0) return;
|
||||
Flux<Message> msgs = channel().get().flatMapMany(MessageChannel::getPinnedMessages);
|
||||
val kp = keepPinned.get();
|
||||
if (kp == 0) return;
|
||||
Flux<Message> msgs = channel.get().flatMapMany(MessageChannel::getPinnedMessages).takeLast(kp);
|
||||
msgs.subscribe(Message::unpin);
|
||||
new Thread(this::AnnouncementGetterThreadMethod).start();
|
||||
}
|
||||
|
@ -86,12 +74,12 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
|
|||
Thread.sleep(10000);
|
||||
continue;
|
||||
}
|
||||
String body = TBMCCoreAPI.DownloadString(subredditURL().get() + "/new/.json?limit=10");
|
||||
String body = TBMCCoreAPI.DownloadString(subredditURL.get() + "/new/.json?limit=10");
|
||||
JsonArray json = new JsonParser().parse(body).getAsJsonObject().get("data").getAsJsonObject()
|
||||
.get("children").getAsJsonArray();
|
||||
StringBuilder msgsb = new StringBuilder();
|
||||
StringBuilder modmsgsb = new StringBuilder();
|
||||
long lastanntime = lastAnnouncementTime().get();
|
||||
long lastanntime = lastAnnouncementTime.get();
|
||||
for (int i = json.size() - 1; i >= 0; i--) {
|
||||
JsonObject item = json.get(i).getAsJsonObject();
|
||||
final JsonObject data = item.get("data").getAsJsonObject();
|
||||
|
@ -104,9 +92,10 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
|
|||
distinguished = distinguishedjson.getAsString();
|
||||
String permalink = "https://www.reddit.com" + data.get("permalink").getAsString();
|
||||
long date = data.get("created_utc").getAsLong();
|
||||
if (date > lastSeenTime().get())
|
||||
lastSeenTime().set(date);
|
||||
else if (date > lastAnnouncementTime().get()) {
|
||||
if (date > lastSeenTime.get())
|
||||
lastSeenTime.set(date);
|
||||
else if (date > lastAnnouncementTime.get()) {
|
||||
//noinspection ConstantConditions
|
||||
do {
|
||||
val reddituserclass = ChromaGamerBase.getTypeForFolder("reddit");
|
||||
if (reddituserclass == null)
|
||||
|
@ -125,13 +114,13 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
|
|||
}
|
||||
}
|
||||
if (msgsb.length() > 0)
|
||||
channel().get().flatMap(ch -> ch.createMessage(msgsb.toString()))
|
||||
channel.get().flatMap(ch -> ch.createMessage(msgsb.toString()))
|
||||
.flatMap(Message::pin).subscribe();
|
||||
if (modmsgsb.length() > 0)
|
||||
modChannel().get().flatMap(ch -> ch.createMessage(modmsgsb.toString()))
|
||||
modChannel.get().flatMap(ch -> ch.createMessage(modmsgsb.toString()))
|
||||
.flatMap(Message::pin).subscribe();
|
||||
if (lastAnnouncementTime().get() != lastanntime)
|
||||
lastAnnouncementTime().set(lastanntime); // If sending succeeded
|
||||
if (lastAnnouncementTime.get() != lastanntime)
|
||||
lastAnnouncementTime.set(lastanntime); // If sending succeeded
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class DebugCommand extends ICommand2DC {
|
|||
.switchIfEmpty(sender.getMessage().getAuthor() //Support DMs
|
||||
.map(u -> u.asMember(DiscordPlugin.mainServer.getId()))
|
||||
.orElse(Mono.empty()))
|
||||
.flatMap(m -> DiscordPlugin.plugin.modRole().get()
|
||||
.flatMap(m -> DiscordPlugin.plugin.modRole.get()
|
||||
.map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId())))
|
||||
.switchIfEmpty(Mono.fromSupplier(() -> DiscordPlugin.mainServer.getOwnerId().asLong() == m.getId().asLong()))) //Role not found
|
||||
.onErrorReturn(false).subscribe(success -> {
|
||||
|
|
|
@ -83,16 +83,14 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
|
|||
private static ExceptionListenerModule instance;
|
||||
|
||||
public static Mono<MessageChannel> getChannel() {
|
||||
if (instance != null) return instance.channel().get();
|
||||
if (instance != null) return instance.channel.get();
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The channel to post the errors to.
|
||||
*/
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> channel() {
|
||||
return DPUtils.channelData(getConfig(), "channel");
|
||||
}
|
||||
private final ReadOnlyConfigData<Mono<MessageChannel>> channel = DPUtils.channelData(getConfig(), "channel");
|
||||
|
||||
/**
|
||||
* The role to ping if an error occurs. Set to empty ('') to disable.
|
||||
|
@ -103,7 +101,7 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
|
|||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigError(this, channel())) return;
|
||||
if (DPUtils.disableIfConfigError(this, channel)) return;
|
||||
instance = this;
|
||||
Bukkit.getPluginManager().registerEvents(new ExceptionListenerModule(), getPlugin());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new DebugMessageListener(), getPlugin());
|
||||
|
|
|
@ -54,25 +54,21 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
|
|||
/**
|
||||
* Questions that the bot will choose a random answer to give to.
|
||||
*/
|
||||
private ConfigData<String[]> serverReady() {
|
||||
return getConfig().getData("serverReady", () -> new String[]{"when will the server be open",
|
||||
"when will the server be ready", "when will the server be done", "when will the server be complete",
|
||||
"when will the server be finished", "when's the server ready", "when's the server open",
|
||||
"vhen vill ze server be open?"});
|
||||
}
|
||||
private final ConfigData<String[]> serverReady = getConfig().getData("serverReady", () -> new String[]{
|
||||
"when will the server be open", "when will the server be ready", "when will the server be done",
|
||||
"when will the server be complete", "when will the server be finished", "when's the server ready",
|
||||
"when's the server open", "vhen vill ze server be open?"});
|
||||
|
||||
/**
|
||||
* Answers for a recognized question. Selected randomly.
|
||||
*/
|
||||
private ConfigData<ArrayList<String>> serverReadyAnswers() {
|
||||
return getConfig().getData("serverReadyAnswers", () -> Lists.newArrayList(serverReadyStrings));
|
||||
}
|
||||
private final ConfigData<ArrayList<String>> serverReadyAnswers = getConfig().getData("serverReadyAnswers", () -> Lists.newArrayList(serverReadyStrings));
|
||||
|
||||
private static final Random serverReadyRandom = new Random();
|
||||
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<>(0);
|
||||
|
||||
private void createUsableServerReadyStrings() {
|
||||
IntStream.range(0, serverReadyAnswers().get().size())
|
||||
IntStream.range(0, serverReadyAnswers.get().size())
|
||||
.forEach(i -> FunModule.usableServerReadyStrings.add((short) i));
|
||||
}
|
||||
|
||||
|
@ -109,12 +105,12 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
|
|||
}
|
||||
lastlistp = (short) Bukkit.getOnlinePlayers().size(); //Didn't handle
|
||||
if (!TBMCCoreAPI.IsTestServer()
|
||||
&& Arrays.stream(fm.serverReady().get()).anyMatch(msglowercased::contains)) {
|
||||
&& Arrays.stream(fm.serverReady.get()).anyMatch(msglowercased::contains)) {
|
||||
int next;
|
||||
if (usableServerReadyStrings.size() == 0)
|
||||
fm.createUsableServerReadyStrings();
|
||||
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
|
||||
DPUtils.reply(message, Mono.empty(), fm.serverReadyAnswers().get().get(next)).subscribe();
|
||||
DPUtils.reply(message, Mono.empty(), fm.serverReadyAnswers.get().get(next)).subscribe();
|
||||
return false; //Still process it as a command/mcchat if needed
|
||||
}
|
||||
return false;
|
||||
|
@ -136,9 +132,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
|
|||
/**
|
||||
* The channel to post the full house to.
|
||||
*/
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> fullHouseChannel() {
|
||||
return DPUtils.channelData(getConfig(), "fullHouseChannel");
|
||||
}
|
||||
private final ReadOnlyConfigData<Mono<MessageChannel>> fullHouseChannel = DPUtils.channelData(getConfig(), "fullHouseChannel");
|
||||
|
||||
private static long lasttime = 0;
|
||||
|
||||
|
@ -146,7 +140,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
|
|||
val fm = ComponentManager.getIfEnabled(FunModule.class);
|
||||
if (fm == null) return;
|
||||
if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 != 0) return;
|
||||
fm.fullHouseChannel().get()
|
||||
fm.fullHouseChannel.get()
|
||||
.filter(ch -> ch instanceof GuildChannel)
|
||||
.flatMap(channel -> fm.fullHouseDevRole(((GuildChannel) channel).getGuild()).get()
|
||||
.filter(role -> event.getOld().map(p -> p.getStatus().equals(Status.OFFLINE)).orElse(false))
|
||||
|
|
|
@ -42,8 +42,8 @@ public class CommonListeners {
|
|||
return def;
|
||||
if (FunModule.executeMemes(event.getMessage()))
|
||||
return def;
|
||||
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
|
||||
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.commandChannel());
|
||||
val commandChannel = DiscordPlugin.plugin.commandChannel.get();
|
||||
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.commandChannel);
|
||||
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
|
||||
(commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|
||||
|| mch instanceof PrivateChannel
|
||||
|
|
|
@ -97,7 +97,7 @@ public class ChannelconCommand extends ICommand2DC {
|
|||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender, String channelID) {
|
||||
val message = sender.getMessage();
|
||||
if (!module.allowCustomChat().get()) {
|
||||
if (!module.allowCustomChat.get()) {
|
||||
sender.sendMessage("channel connection is not allowed on this Minecraft server.");
|
||||
return true;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class ChannelconCommand extends ICommand2DC {
|
|||
if (checkPerms(message, channel)) 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.");
|
||||
val chan = Channel.getChannels().filter(ch -> ch.ID.equalsIgnoreCase(channelID) || (Arrays.stream(ch.IDs().get()).anyMatch(cid -> cid.equalsIgnoreCase(channelID)))).findAny();
|
||||
val chan = Channel.getChannels().filter(ch -> ch.ID.equalsIgnoreCase(channelID) || (Arrays.stream(ch.IDs.get()).anyMatch(cid -> cid.equalsIgnoreCase(channelID)))).findAny();
|
||||
if (!chan.isPresent()) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW)
|
||||
DPUtils.reply(message, channel, "MC channel with ID '" + channelID + "' not found! The ID is the command for it without the /.").subscribe();
|
||||
return true;
|
||||
|
|
|
@ -24,7 +24,7 @@ public class MCChatCommand extends ICommand2DC {
|
|||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender) {
|
||||
if (!module.allowPrivateChat().get()) {
|
||||
if (!module.allowPrivateChat.get()) {
|
||||
sender.sendMessage("using the private chat is not allowed on this Minecraft server.");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -77,14 +77,14 @@ public class MCChatListener implements Listener {
|
|||
e = se.getKey();
|
||||
time = se.getValue();
|
||||
|
||||
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName().get()) + "] " //
|
||||
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName.get()) + "] " //
|
||||
+ ("Minecraft".equals(e.getOrigin()) ? "" : "[" + e.getOrigin().charAt(0) + "]") //
|
||||
+ (DPUtils.sanitizeStringNoEscape(ChromaUtils.getDisplayName(e.getSender())));
|
||||
val color = e.getChannel().Color().get();
|
||||
val color = e.getChannel().Color.get();
|
||||
final Consumer<EmbedCreateSpec> embed = ecs -> {
|
||||
ecs.setDescription(e.getMessage()).setColor(Color.of(color.getRed(),
|
||||
color.getGreen(), color.getBlue()));
|
||||
String url = module.profileURL().get();
|
||||
String url = module.profileURL.get();
|
||||
if (e.getSender() instanceof Player)
|
||||
DPUtils.embedWithHead(ecs, authorPlayer, e.getSender().getName(),
|
||||
url.length() > 0 ? url + "?type=minecraft&id="
|
||||
|
@ -121,7 +121,7 @@ public class MCChatListener implements Listener {
|
|||
|| ((DiscordSenderBase) e.getSender()).getChannel().getId().asLong() != id.asLong();
|
||||
|
||||
if (e.getChannel().isGlobal()
|
||||
&& (e.isFromCommand() || isdifferentchannel.test(module.chatChannel().get())))
|
||||
&& (e.isFromCommand() || isdifferentchannel.test(module.chatChannel.get())))
|
||||
doit.accept(MCChatUtils.lastmsgdata == null
|
||||
? MCChatUtils.lastmsgdata = new MCChatUtils.LastMsgData(module.chatChannelMono().block(), null)
|
||||
: MCChatUtils.lastmsgdata);
|
||||
|
@ -238,7 +238,7 @@ public class MCChatListener implements Listener {
|
|||
var prefix = DiscordPlugin.getPrefix();
|
||||
return ev.getMessage().getChannel().filter(channel -> {
|
||||
timings.printElapsed("Filter 1");
|
||||
return !(ev.getMessage().getChannelId().asLong() != module.chatChannel().get().asLong()
|
||||
return !(ev.getMessage().getChannelId().asLong() != module.chatChannel.get().asLong()
|
||||
&& !(channel instanceof PrivateChannel
|
||||
&& author.map(u -> MCChatPrivate.isMinecraftChatEnabled(u.getId().asString())).orElse(false))
|
||||
&& !hasCustomChat); //Chat isn't enabled on this channel
|
||||
|
@ -383,7 +383,7 @@ public class MCChatListener implements Listener {
|
|||
return;
|
||||
try {
|
||||
String mcpackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||
if (!module.enableVanillaCommands().get())
|
||||
if (!module.enableVanillaCommands.get())
|
||||
Bukkit.dispatchCommand(dsender, cmd);
|
||||
else if (mcpackage.contains("1_12"))
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
|
|
|
@ -62,7 +62,7 @@ public class MCChatUtils {
|
|||
|
||||
public static void updatePlayerList() {
|
||||
val mod = getModule();
|
||||
if (mod == null || !mod.showPlayerListOnDC().get()) return;
|
||||
if (mod == null || !mod.showPlayerListOnDC.get()) return;
|
||||
if (lastmsgdata != null)
|
||||
updatePL(lastmsgdata);
|
||||
MCChatCustom.lastmsgCustom.forEach(MCChatUtils::updatePL);
|
||||
|
@ -254,7 +254,7 @@ public class MCChatUtils {
|
|||
*/
|
||||
public static void resetLastMessage(Channel channel) {
|
||||
if (notEnabled()) return;
|
||||
if (channel.getId().asLong() == module.chatChannel().get().asLong()) {
|
||||
if (channel.getId().asLong() == module.chatChannel.get().asLong()) {
|
||||
(lastmsgdata == null ? lastmsgdata = new LastMsgData(module.chatChannelMono().block(), null)
|
||||
: lastmsgdata).message = null;
|
||||
return;
|
||||
|
@ -277,7 +277,7 @@ public class MCChatUtils {
|
|||
public static void callEventExcludingSome(Event event) {
|
||||
if (notEnabled()) return;
|
||||
val second = staticExcludedPlugins.get(event.getClass());
|
||||
String[] first = module.excludedPlugins().get();
|
||||
String[] first = module.excludedPlugins.get();
|
||||
String[] both = second == null ? first
|
||||
: Arrays.copyOf(first, first.length + second.size());
|
||||
int i = first.length;
|
||||
|
|
|
@ -9,7 +9,6 @@ import buttondevteam.lib.player.TBMCYEEHAWEvent;
|
|||
import com.earth2me.essentials.CommandSource;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
||||
|
@ -30,9 +29,14 @@ import reactor.core.publisher.Mono;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
class MCListener implements Listener {
|
||||
private final MinecraftChatModule module;
|
||||
private final ConfigData<Mono<Role>> muteRole;
|
||||
|
||||
public MCListener(MinecraftChatModule module) {
|
||||
this.module = module;
|
||||
muteRole = DPUtils.roleData(module.getConfig(), "muteRole", "Muted");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
|
@ -105,13 +109,9 @@ class MCListener implements Listener {
|
|||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(msg), base, ChannelconBroadcast.AFK, false).subscribe();
|
||||
}
|
||||
|
||||
private ConfigData<Mono<Role>> muteRole() {
|
||||
return DPUtils.roleData(module.getConfig(), "muteRole", "Muted");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMute(MuteStatusChangeEvent e) {
|
||||
final Mono<Role> role = muteRole().get();
|
||||
final Mono<Role> role = muteRole.get();
|
||||
if (role == null) return;
|
||||
final CommandSource source = e.getAffected().getSource();
|
||||
if (!source.isPlayer())
|
||||
|
@ -126,7 +126,7 @@ class MCListener implements Listener {
|
|||
user.addRole(r.getId());
|
||||
else
|
||||
user.removeRole(r.getId());
|
||||
val modlog = module.modlogChannel().get();
|
||||
val modlog = module.modlogChannel.get();
|
||||
String msg = (e.getValue() ? "M" : "Unm") + "uted user: " + user.getUsername() + "#" + user.getDiscriminator();
|
||||
module.log(msg);
|
||||
if (modlog != null)
|
||||
|
|
|
@ -49,36 +49,28 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
|||
/**
|
||||
* The channel to use as the public Minecraft chat - everything public gets broadcasted here
|
||||
*/
|
||||
public ReadOnlyConfigData<Snowflake> chatChannel() {
|
||||
return DPUtils.snowflakeData(getConfig(), "chatChannel", 0L);
|
||||
}
|
||||
public ReadOnlyConfigData<Snowflake> chatChannel = DPUtils.snowflakeData(getConfig(), "chatChannel", 0L);
|
||||
|
||||
public Mono<MessageChannel> chatChannelMono() {
|
||||
return DPUtils.getMessageChannel(chatChannel().getPath(), chatChannel().get());
|
||||
return DPUtils.getMessageChannel(chatChannel.getPath(), chatChannel.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The channel where the plugin can log when it mutes a player on Discord because of a Minecraft mute
|
||||
*/
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> modlogChannel() {
|
||||
return DPUtils.channelData(getConfig(), "modlogChannel");
|
||||
}
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> modlogChannel = DPUtils.channelData(getConfig(), "modlogChannel");
|
||||
|
||||
/**
|
||||
* The plugins to exclude from fake player events used for the 'mcchat' command - some plugins may crash, add them here
|
||||
*/
|
||||
public ConfigData<String[]> excludedPlugins() {
|
||||
return getConfig().getData("excludedPlugins", new String[]{"ProtocolLib", "LibsDisguises", "JourneyMapServer"});
|
||||
}
|
||||
public ConfigData<String[]> excludedPlugins = getConfig().getData("excludedPlugins", new String[]{"ProtocolLib", "LibsDisguises", "JourneyMapServer"});
|
||||
|
||||
/**
|
||||
* If this setting is on then players logged in through the 'mcchat' command will be able to teleport using plugin commands.
|
||||
* They can then use commands like /tpahere to teleport others to that place.<br />
|
||||
* If this is off, then teleporting will have no effect.
|
||||
*/
|
||||
public ConfigData<Boolean> allowFakePlayerTeleports() {
|
||||
return getConfig().getData("allowFakePlayerTeleports", false);
|
||||
}
|
||||
public ConfigData<Boolean> allowFakePlayerTeleports = getConfig().getData("allowFakePlayerTeleports", false);
|
||||
|
||||
/**
|
||||
* If this is on, each chat channel will have a player list in their description.
|
||||
|
@ -86,40 +78,30 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
|||
* Note that it will replace <b>everything</b> above the first and below the 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);
|
||||
}
|
||||
public ConfigData<Boolean> showPlayerListOnDC = 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);
|
||||
}
|
||||
public ConfigData<Boolean> allowCustomChat = 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);
|
||||
}
|
||||
public ConfigData<Boolean> allowPrivateChat = getConfig().getData("allowPrivateChat", true);
|
||||
|
||||
/**
|
||||
* If set, message authors appearing on Discord will link to this URL. A 'type' and 'id' parameter will be added with the user's platform (Discord, Minecraft, ...) and ID.
|
||||
*/
|
||||
public ConfigData<String> profileURL() {
|
||||
return getConfig().getData("profileURL", "");
|
||||
}
|
||||
public ConfigData<String> profileURL = getConfig().getData("profileURL", "");
|
||||
|
||||
/**
|
||||
* Enables support for running vanilla commands through Discord, if you ever need it.
|
||||
*/
|
||||
public ConfigData<Boolean> enableVanillaCommands() {
|
||||
return getConfig().getData("enableVanillaCommands", true);
|
||||
}
|
||||
public ConfigData<Boolean> enableVanillaCommands = getConfig().getData("enableVanillaCommands", true);
|
||||
|
||||
/**
|
||||
* Whether players logged on from Discord (mcchat command) should be recognised by other plugins. Some plugins might break if it's turned off.
|
||||
|
@ -134,7 +116,7 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
|||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigErrorRes(this, chatChannel(), chatChannelMono()))
|
||||
if (DPUtils.disableIfConfigErrorRes(this, chatChannel, chatChannelMono()))
|
||||
return;
|
||||
listener = new MCChatListener(this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
|
||||
|
@ -268,6 +250,6 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
|
|||
*/
|
||||
private void sendStateMessage(Color color, String message, String extra) {
|
||||
MCChatUtils.forCustomAndAllMCChat(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> ecs.setColor(color)
|
||||
.setTitle(message).setDescription(extra))), ChannelconBroadcast.RESTART, false).block();
|
||||
.setTitle(message).setDescription(extra)).onErrorResume(t -> Mono.empty())), ChannelconBroadcast.RESTART, false).block();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class DiscordMCCommand extends ICommand2MC {
|
|||
})
|
||||
public void invite(CommandSender sender) {
|
||||
if (checkSafeMode(sender)) return;
|
||||
String invi = DiscordPlugin.plugin.inviteLink().get();
|
||||
String invi = DiscordPlugin.plugin.inviteLink.get();
|
||||
if (invi.length() > 0) {
|
||||
sender.sendMessage("§bInvite link: " + invi);
|
||||
return;
|
||||
|
|
|
@ -42,9 +42,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
|||
/**
|
||||
* The channel where the bot logs when it detects a role change that results in a new game role or one being removed.
|
||||
*/
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> logChannel() {
|
||||
return DPUtils.channelData(getConfig(), "logChannel");
|
||||
}
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> logChannel = DPUtils.channelData(getConfig(), "logChannel");
|
||||
|
||||
/**
|
||||
* The role color that is used by game roles.
|
||||
|
@ -59,7 +57,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
|||
val grm = ComponentManager.getIfEnabled(GameRoleModule.class);
|
||||
if (grm == null) return;
|
||||
val GameRoles = grm.GameRoles;
|
||||
val logChannel = grm.logChannel().get();
|
||||
val logChannel = grm.logChannel.get();
|
||||
Predicate<Role> notMainServer = r -> r.getGuildId().asLong() != DiscordPlugin.mainServer.getId().asLong();
|
||||
if (roleEvent instanceof RoleCreateEvent) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||
|
|
Loading…
Reference in a new issue