Add logging 'proxy', centralize insufficient permission handling, improved toString, equals and hashCode implementations of 1st party Discord api entities

This commit is contained in:
Vankka 2022-01-15 14:45:50 +02:00
parent d3faafcece
commit 1068150f77
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
37 changed files with 236 additions and 191 deletions

View File

@ -84,7 +84,7 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
}
@Override
public Logger logger() {
public Logger platformLogger() {
return logger;
}

View File

@ -20,7 +20,7 @@ package com.discordsrv.bukkit;
import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import dev.vankka.mcdependencydownload.bukkit.bootstrap.BukkitBootstrap;
import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -21,8 +21,8 @@ package com.discordsrv.bukkit.console;
import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl;
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

View File

@ -70,7 +70,7 @@ public class BungeeDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionConf
}
@Override
public Logger logger() {
public Logger platformLogger() {
return logger;
}

View File

@ -20,7 +20,7 @@ package com.discordsrv.bungee;
import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import dev.vankka.mcdependencydownload.bungee.bootstrap.BungeeBootstrap;
import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader;
import net.md_5.bungee.api.plugin.Plugin;

View File

@ -21,7 +21,7 @@ package com.discordsrv.bungee.console;
import com.discordsrv.bungee.BungeeDiscordSRV;
import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

View File

@ -18,6 +18,8 @@
package com.discordsrv.common.logging;
import java.util.Locale;
public interface LogLevel {
LogLevel INFO = StandardLogLevel.INFO;
@ -28,7 +30,7 @@ public interface LogLevel {
static LogLevel of(String name) {
try {
return StandardLogLevel.valueOf(name);
return StandardLogLevel.valueOf(name.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException ignored) {
return new CustomLogLevel(name);
}

View File

@ -1,3 +1,21 @@
/*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* DiscordSRV's own implementation of SLF4J (relocated during runtime) that forwards log messages to the server's logger.
*/

View File

@ -39,8 +39,10 @@ import com.discordsrv.common.discord.details.DiscordConnectionDetailsImpl;
import com.discordsrv.common.event.bus.EventBusImpl;
import com.discordsrv.common.function.CheckedRunnable;
import com.discordsrv.common.integration.LuckPermsIntegration;
import com.discordsrv.common.logging.impl.DiscordSRVLogger;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.adapter.DependencyLoggerAdapter;
import com.discordsrv.common.logging.dependency.DependencyLoggingHandler;
import com.discordsrv.common.logging.impl.DependencyLoggingHandler;
import com.discordsrv.common.messageforwarding.discord.DiscordChatMessageModule;
import com.discordsrv.common.messageforwarding.discord.DiscordMessageMirroringModule;
import com.discordsrv.common.messageforwarding.game.JoinMessageModule;
@ -82,6 +84,7 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
private DiscordConnectionDetails discordConnectionDetails;
// DiscordSRV
private final DiscordSRVLogger logger;
private ChannelConfigHelper channelConfig;
private ModuleManager moduleManager;
private DiscordConnectionManager discordConnectionManager;
@ -91,6 +94,7 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
public AbstractDiscordSRV() {
ApiInstanceUtil.setInstance(this);
this.logger = new DiscordSRVLogger(this);
}
protected final void load() {
@ -141,6 +145,11 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
// DiscordSRV
@Override
public Logger logger() {
return logger;
}
@Override
public ChannelConfigHelper channelConfig() {
return channelConfig;

View File

@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
public interface DiscordSRV extends DiscordSRVApi {
// Platform
Logger logger();
Logger platformLogger();
Path dataDirectory();
Scheduler scheduler();
Console console();
@ -69,6 +69,9 @@ public interface DiscordSRV extends DiscordSRVApi {
@NotNull
DiscordAPIImpl discordAPI();
// Logger
Logger logger();
// Config
ConnectionConfigManager<? extends ConnectionConfig> connectionConfigManager();
ConnectionConfig connectionConfig();

View File

@ -94,24 +94,32 @@ public class ChannelUpdaterModule extends AbstractModule {
continue;
}
ChannelManager<?, ?> manager = channel.getManager();
boolean anythingChanged = false;
if (manager instanceof TextChannelManager && channel instanceof TextChannel
&& StringUtils.isNotEmpty(topicFormat)
&& !topicFormat.equals(((TextChannel) channel).getTopic())) {
anythingChanged = true;
manager = ((TextChannelManager) manager).setTopic(topicFormat);
}
if (StringUtils.isNotEmpty(nameFormat) && !nameFormat.equals(channel.getName())) {
anythingChanged = true;
manager = manager.setName(nameFormat);
}
try {
ChannelManager<?, ?> manager = channel.getManager();
boolean anythingChanged = false;
if (manager instanceof TextChannelManager && channel instanceof TextChannel
&& StringUtils.isNotEmpty(topicFormat)
&& !topicFormat.equals(((TextChannel) channel).getTopic())) {
anythingChanged = true;
manager = ((TextChannelManager) manager).setTopic(topicFormat);
}
if (StringUtils.isNotEmpty(nameFormat) && !nameFormat.equals(channel.getName())) {
anythingChanged = true;
manager = manager.setName(nameFormat);
}
if (!anythingChanged) {
continue;
}
if (!anythingChanged) {
discordSRV.logger().debug("Skipping updating channel " + channel + ": nothing changed");
continue;
}
manager.timeout(30, TimeUnit.SECONDS).queue();
manager.timeout(30, TimeUnit.SECONDS).queue(
null,
t -> discordSRV.logger().error("Failed to update channel " + channel, t)
);
} catch (Throwable t) {
discordSRV.logger().error("Failed to update channel " + channel, t);
}
}
}

View File

@ -51,7 +51,6 @@ import net.dv8tion.jda.api.entities.ThreadChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.Webhook;
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.requests.ErrorResponse;
import net.dv8tion.jda.api.requests.GatewayIntent;
import org.checkerframework.checker.index.qual.NonNegative;
@ -157,16 +156,10 @@ public class DiscordAPIImpl implements DiscordAPI {
}
futures.add(future.handle((threadChannel, t) -> {
if (t instanceof InsufficientPermissionException) {
discordSRV.logger().error(
"Unable to send message to channel " + channel
+ " because the bot is lacking the "
+ ((InsufficientPermissionException) t).getPermission().getName()
+ " permission");
throw new RuntimeException();
} else if (t != null) {
discordSRV.logger().error("Failed to find thread in channel " + channel, t);
throw new RuntimeException();
if (t != null) {
discordSRV.logger().error("Failed to deliver message to thread \""
+ threadConfig.threadName + "\" in channel " + channel, t);
throw new RuntimeException(); // Just here to fail the future
}
if (threadChannel != null) {

View File

@ -98,4 +98,9 @@ public class DiscordUserImpl implements DiscordUser {
public String getAsMention() {
return user.getAsMention();
}
@Override
public String toString() {
return "User:" + getUsername() + "(" + Long.toUnsignedString(getId()) + ")";
}
}

View File

@ -29,6 +29,7 @@ import com.discordsrv.common.discord.api.entity.message.util.SendableDiscordMess
import net.dv8tion.jda.api.entities.PrivateChannel;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
public class DiscordDMChannelImpl extends DiscordMessageChannelImpl<PrivateChannel> implements DiscordDMChannel {
@ -85,4 +86,22 @@ public class DiscordDMChannelImpl extends DiscordMessageChannelImpl<PrivateChann
public PrivateChannel getAsJDAPrivateChannel() {
return channel;
}
@Override
public String toString() {
return "DMChannel:" + user + "(" + Long.toUnsignedString(getId()) + ")";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiscordDMChannelImpl that = (DiscordDMChannelImpl) o;
return Objects.equals(user.getId(), that.user.getId());
}
@Override
public int hashCode() {
return Objects.hash(user.getId());
}
}

View File

@ -22,6 +22,8 @@ import com.discordsrv.api.discord.api.entity.channel.DiscordMessageChannel;
import com.discordsrv.common.DiscordSRV;
import net.dv8tion.jda.api.entities.*;
import java.util.Objects;
public abstract class DiscordMessageChannelImpl<T extends MessageChannel>
implements DiscordMessageChannel {
@ -56,4 +58,17 @@ public abstract class DiscordMessageChannelImpl<T extends MessageChannel>
public MessageChannel getAsJDAMessageChannel() {
return channel;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiscordGuildMessageChannelImpl<?> that = (DiscordGuildMessageChannelImpl<?>) o;
return Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
}

View File

@ -34,4 +34,9 @@ public class DiscordNewsChannelImpl
public NewsChannel getAsJDANewsChannel() {
return channel;
}
@Override
public String toString() {
return "NewsChannel:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
}

View File

@ -39,4 +39,8 @@ public class DiscordTextChannelImpl extends DiscordGuildMessageChannelImpl<TextC
return channel;
}
@Override
public String toString() {
return "TextChannel:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
}

View File

@ -105,4 +105,9 @@ public class DiscordThreadChannelImpl extends DiscordMessageChannelImpl<ThreadCh
public ThreadChannel getAsJDAThreadChannel() {
return channel;
}
@Override
public String toString() {
return "Thread:" + getName() + "(" + Long.toUnsignedString(getId()) + " in " + textChannel + ")";
}
}

View File

@ -109,4 +109,9 @@ public class DiscordGuildImpl implements DiscordGuild {
public int hashCode() {
return Objects.hash(getId());
}
@Override
public String toString() {
return "Guild:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
}

View File

@ -127,4 +127,9 @@ public class DiscordGuildMemberImpl extends DiscordUserImpl implements DiscordGu
return ComponentUtil.join(Component.text(suffix), components);
}
@Override
public String toString() {
return "ServerMember:" + super.toString() + "/" + getGuild();
}
}

View File

@ -62,4 +62,9 @@ public class DiscordRoleImpl implements DiscordRole {
public String getAsMention() {
return role.getAsMention();
}
@Override
public String toString() {
return "ServerRole:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
}

View File

@ -309,4 +309,9 @@ public class ReceivedDiscordMessageImpl extends SendableDiscordMessageImpl imple
return ComponentUtil.join(Component.text(suffix), components);
}
@Override
public String toString() {
return "ReceivedMessage:" + Long.toUnsignedString(getId()) + "/" + getChannel();
}
}

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.impl;
package com.discordsrv.common.logging.backend.impl;
import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.Logger;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.impl;
package com.discordsrv.common.logging.backend.impl;
import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.LogAppender;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.impl;
package com.discordsrv.common.logging.backend.impl;
import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.Logger;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.dependency;
package com.discordsrv.common.logging.impl;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.logging.LogLevel;

View File

@ -0,0 +1,59 @@
/*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.impl;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.Logger;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DiscordSRVLogger implements Logger {
private final DiscordSRV discordSRV;
public DiscordSRVLogger(DiscordSRV discordSRV) {
this.discordSRV = discordSRV;
}
@Override
public void log(@NotNull LogLevel logLevel, @Nullable String message, @Nullable Throwable throwable) {
if (logLevel == LogLevel.DEBUG || logLevel == LogLevel.TRACE || logLevel instanceof LogLevel.CustomLogLevel) {
// TODO: handle debug/trace
return;
}
if (throwable instanceof InsufficientPermissionException) {
Permission permission = ((InsufficientPermissionException) throwable).getPermission();
String msg = "The bot is missing the \"" + permission.getName() + "\" permission";
if (message == null) {
message = msg;
} else {
message += ": " + msg;
}
discordSRV.platformLogger().log(logLevel, message, null);
discordSRV.logger().debug(throwable);
return;
}
discordSRV.platformLogger().log(logLevel, message, throwable);
}
}

View File

@ -36,13 +36,14 @@ import com.discordsrv.common.config.main.channels.base.IChannelConfig;
import com.discordsrv.common.discord.api.entity.message.ReceivedDiscordMessageClusterImpl;
import com.discordsrv.common.function.OrDefault;
import com.discordsrv.common.module.type.AbstractModule;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CopyOnWriteArrayList;
@ -116,28 +117,21 @@ public abstract class AbstractGameMessageModule<T> extends AbstractModule {
}
String message = convertMessage(config, ComponentUtil.fromAPI(event.getMessage()));
List<CompletableFuture<ReceivedDiscordMessage>> messageFutures;
Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> messageFutures;
messageFutures = sendMessageToChannels(
config, format, messageChannels, message,
// Context
channelConfig, player
);
CompletableFuture.allOf(messageFutures.toArray(new CompletableFuture[0]))
CompletableFuture.allOf(messageFutures.keySet().toArray(new CompletableFuture[0]))
.whenComplete((vo, t2) -> {
List<ReceivedDiscordMessage> messages = new ArrayList<>();
for (CompletableFuture<ReceivedDiscordMessage> future : messageFutures) {
for (Map.Entry<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> entry : messageFutures.entrySet()) {
CompletableFuture<ReceivedDiscordMessage> future = entry.getKey();
if (future.isCompletedExceptionally()) {
future.exceptionally(t -> {
if (t instanceof InsufficientPermissionException) {
discordSRV.logger().error(
"Unable to send message to a Discord channel"
+ " because the bot is lacking the "
+ ((InsufficientPermissionException) t).getPermission().getName()
+ " permission");
} else {
discordSRV.logger().error("Failed to deliver a message to Discord", t);
}
discordSRV.logger().error("Failed to deliver a message to the " + entry.getValue() + " channel", t);
return null;
});
// Ignore ones that failed
@ -171,7 +165,7 @@ public abstract class AbstractGameMessageModule<T> extends AbstractModule {
);
}
public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels(
public Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> sendMessageToChannels(
OrDefault<T> config,
SendableDiscordMessage.Builder format,
List<DiscordMessageChannel> channels,
@ -184,9 +178,9 @@ public abstract class AbstractGameMessageModule<T> extends AbstractModule {
.applyPlaceholderService()
.build();
List<CompletableFuture<ReceivedDiscordMessage>> futures = new ArrayList<>();
Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> futures = new LinkedHashMap<>();
for (DiscordMessageChannel channel : channels) {
futures.add(channel.sendMessage(discordMessage));
futures.put(channel.sendMessage(discordMessage), channel);
}
return futures;

View File

@ -115,7 +115,7 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
}
@Override
public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels(
public Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> sendMessageToChannels(
OrDefault<MinecraftToDiscordChatConfig> config,
SendableDiscordMessage.Builder format,
List<DiscordMessageChannel> channels,
@ -137,7 +137,7 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
.add(channel);
}
List<CompletableFuture<ReceivedDiscordMessage>> futures = new ArrayList<>();
Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> futures = new LinkedHashMap<>();
OrDefault<MinecraftToDiscordChatConfig.Mentions> mentionConfig = config.map(cfg -> cfg.mentions);
// Format messages per-Guild
@ -179,13 +179,13 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
if (!text.isEmpty()) {
SendableDiscordMessage finalMessage = discordMessage.build();
for (DiscordMessageChannel channel : text) {
futures.add(channel.sendMessage(finalMessage));
futures.put(channel.sendMessage(finalMessage), channel);
}
}
if (!thread.isEmpty()) {
SendableDiscordMessage finalMessage = discordMessage.convertToNonWebhook().build();
for (DiscordMessageChannel channel : thread) {
futures.add(channel.sendMessage(finalMessage));
futures.put(channel.sendMessage(finalMessage), channel);
}
}
}

View File

@ -24,7 +24,7 @@ import com.discordsrv.common.config.manager.ConnectionConfigManager;
import com.discordsrv.common.config.manager.MainConfigManager;
import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import com.discordsrv.common.player.provider.AbstractPlayerProvider;
import com.discordsrv.common.scheduler.Scheduler;
import com.discordsrv.common.scheduler.StandardScheduler;
@ -44,7 +44,7 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
}
@Override
public Logger logger() {
public Logger platformLogger() {
return logger;
}

View File

@ -18,64 +18,30 @@
package com.discordsrv.config;
import com.discordsrv.api.discord.connection.DiscordConnectionDetails;
import com.discordsrv.api.event.bus.EventBus;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.channel.ChannelConfigHelper;
import com.discordsrv.common.component.ComponentFactory;
import com.discordsrv.common.AbstractDiscordSRV;
import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.manager.ConnectionConfigManager;
import com.discordsrv.common.config.manager.MainConfigManager;
import com.discordsrv.common.console.Console;
import com.discordsrv.common.discord.api.DiscordAPIImpl;
import com.discordsrv.common.discord.connection.DiscordConnectionManager;
import com.discordsrv.common.module.type.AbstractModule;
import com.discordsrv.common.module.type.Module;
import com.discordsrv.common.placeholder.PlaceholderServiceImpl;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.player.provider.AbstractPlayerProvider;
import com.discordsrv.common.scheduler.Scheduler;
import com.discordsrv.common.logging.Logger;
import net.dv8tion.jda.api.JDA;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
public class MockDiscordSRV implements DiscordSRV {
public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionConfig> {
@Override
public @NotNull Status status() {
return null;
}
@Override
public @NotNull EventBus eventBus() {
return null;
}
@Override
public @NotNull Optional<JDA> jda() {
return Optional.empty();
}
@Override
public @NotNull DiscordConnectionDetails discordConnectionDetails() {
return null;
}
@Override
public Logger logger() {
public Logger platformLogger() {
return null;
}
@Override
public Path dataDirectory() {
return Paths.get("");
return null;
}
@Override
@ -93,98 +59,18 @@ public class MockDiscordSRV implements DiscordSRV {
return null;
}
@Override
public @NotNull ComponentFactory componentFactory() {
return null;
}
@Override
public @NotNull PlaceholderServiceImpl placeholderService() {
return null;
}
@Override
public @NotNull AbstractPlayerProvider<?> playerProvider() {
return null;
}
@Override
public @NotNull DiscordAPIImpl discordAPI() {
public ConnectionConfigManager<ConnectionConfig> connectionConfigManager() {
return null;
}
@Override
public ConnectionConfigManager<? extends ConnectionConfig> connectionConfigManager() {
return null;
}
@Override
public ConnectionConfig connectionConfig() {
return null;
}
@Override
public MainConfigManager<? extends MainConfig> configManager() {
return null;
}
@Override
public MainConfig config() {
return null;
}
@Override
public ChannelConfigHelper channelConfig() {
return null;
}
@Override
public DiscordConnectionManager discordConnectionManager() {
return null;
}
@Override
public <T extends Module> T getModule(Class<T> moduleType) {
return null;
}
@Override
public void registerModule(AbstractModule module) {
}
@Override
public void unregisterModule(AbstractModule module) {
}
@Override
public Locale locale() {
return null;
}
@Override
public void setStatus(Status status) {
}
@Override
public void waitForStatus(Status status, long time, TimeUnit unit) throws InterruptedException {
}
@Override
public CompletableFuture<Void> invokeEnable() {
return null;
}
@Override
public CompletableFuture<Void> invokeDisable() {
return null;
}
@Override
public CompletableFuture<Void> invokeReload() {
public MainConfigManager<MainConfig> configManager() {
return null;
}
}

View File

@ -20,7 +20,7 @@ package com.discordsrv.sponge;
import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl;
import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import com.discordsrv.sponge.bootstrap.ISpongeBootstrap;
import dev.vankka.mcdependencydownload.bootstrap.AbstractBootstrap;
import dev.vankka.mcdependencydownload.bootstrap.classpath.JarInJarClasspathAppender;

View File

@ -71,7 +71,7 @@ public class SpongeDiscordSRV extends ServerDiscordSRV<MainConfig, ConnectionCon
}
@Override
public Logger logger() {
public Logger platformLogger() {
return logger;
}

View File

@ -20,7 +20,7 @@ package com.discordsrv.sponge.console;
import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl;
import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import com.discordsrv.sponge.SpongeDiscordSRV;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;

View File

@ -20,7 +20,7 @@ package com.discordsrv.velocity;
import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.SLF4JLoggerImpl;
import com.discordsrv.common.logging.backend.impl.SLF4JLoggerImpl;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;

View File

@ -72,7 +72,7 @@ public class VelocityDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionCo
}
@Override
public Logger logger() {
public Logger platformLogger() {
return logger;
}

View File

@ -20,7 +20,7 @@ package com.discordsrv.velocity.console;
import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl;
import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import com.discordsrv.velocity.VelocityDiscordSRV;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;