From 42afebc8bbae04027436693e63a1c8ad1a3cf918 Mon Sep 17 00:00:00 2001 From: Mats Date: Tue, 13 Feb 2024 13:27:22 +0100 Subject: [PATCH] Implement actual log levels --- .../oamapmigrator/database/MapDBService.java | 4 +- .../internal/NetworkedRepositoryCommit.java | 2 +- .../client/client/VistasRedisClient.java | 6 +- .../client/listeners/PlayerListener.java | 2 +- .../vistas/client/redis/RedisConnection.java | 2 +- .../client/redis/SimpleRedisClient.java | 2 +- .../server/networking/VistasRedisServer.java | 10 +- .../vistas/client/users/ServerUserHooks.java | 14 +-- .../vistas/client/users/VistasUser.java | 2 +- .../craftmend/vistas/server/VistasServer.java | 4 +- .../server/base/VistasConfiguration.java | 10 +- .../craftmend/openaudiomc/OpenAudioMc.java | 6 +- .../api/impl/event/ApiEventDriver.java | 6 +- .../api/interfaces/ExternalModule.java | 2 +- .../openaudiomc/bungee/OpenAudioMcBungee.java | 5 +- .../configuration/BungeeConfiguration.java | 14 +-- .../listeners/PlayerConnectionListener.java | 12 +-- .../player/objects/BungeePlayerSelector.java | 2 +- .../punishments/LitebansIntegration.java | 3 +- .../authentication/AuthenticationService.java | 2 +- .../driver/PluginTokenProvider.java | 8 +- .../generic/backups/BackupService.java | 15 ++- .../generic/client/session/ClientAuth.java | 4 +- .../generic/commands/CommandService.java | 3 +- .../generic/database/DatabaseService.java | 6 +- .../generic/database/internal/Repository.java | 4 +- .../environment/GlobalConstantService.java | 3 +- .../generic/events/internal/EventMethod.java | 3 +- .../generic/logging/LogAdapter.java | 45 +++++++++ .../openaudiomc/generic/logging/Logger.java | 9 -- .../generic/logging/OpenAudioLogger.java | 96 +++++++++++-------- .../logging/platform/GenericLogAdapter.java | 55 +++++++++++ .../logging/platform/SpigotLogger.java | 27 ------ .../generic/logging/platform/StdOutLog.java | 52 ++++++++++ .../generic/migrations/MigrationWorker.java | 12 ++- .../interfaces/SimpleMigration.java | 2 +- .../migrations/AddAutoClaimMigration.java | 2 +- .../migrations/AddConfigKeyMigration.java | 2 +- .../migrations/AliasDatabaseMigration.java | 4 +- .../migrations/PredictiveCacheMigration.java | 6 +- .../migrations/RegionDatabaseMigration.java | 4 +- .../migrations/SpeakerDatabaseMigration.java | 4 +- .../generic/mojang/MojangLookupService.java | 8 +- .../networking/DefaultNetworkingService.java | 23 ++--- .../addapter/AbstractPacketAdapter.java | 4 +- .../addapter/StandardPacketAdapter.java | 2 +- .../certificate/CertificateHelper.java | 3 +- .../networking/drivers/ClientDriver.java | 13 +-- .../drivers/NotificationDriver.java | 6 +- .../networking/drivers/SystemDriver.java | 8 +- .../handler/AccountUpdateNotification.java | 2 +- .../drivers/handler/AdminNotification.java | 2 +- .../networking/interfaces/SocketDriver.java | 4 +- ...IoConnector.java => SocketConnection.java} | 31 ++---- .../generic/oac/OpenaudioAccountService.java | 24 ++--- .../platform/interfaces/TaskService.java | 2 +- .../generic/proxy/messages/PacketManager.java | 10 +- .../generic/proxy/messages/PacketWriter.java | 3 +- .../BungeeCordPacketManager.java | 2 +- .../generic/rd/RestDirectService.java | 13 ++- .../generic/rd/ports/PortChecker.java | 4 +- .../rd/routes/TokenInvalidateRoute.java | 2 +- .../generic/redis/RedisChannelListener.java | 3 +- .../generic/redis/RedisService.java | 6 +- .../packets/adapter/RedisTypeAdapter.java | 2 +- .../resources/ExternalResourceLoader.java | 2 +- .../resources/RuntimeDependencyService.java | 4 +- .../openaudiomc/generic/rest/RestRequest.java | 2 +- .../openaudiomc/generic/service/Service.java | 2 +- .../generic/service/ServiceManager.java | 6 +- .../generic/state/StateService.java | 2 +- .../generic/utils/data/TemporalFaker.java | 4 +- .../voicechat/bus/VoiceApiConnection.java | 11 ++- .../generic/voicechat/bus/VoiceWebsocket.java | 8 +- .../openaudiomc/spigot/OpenAudioMcSpigot.java | 21 ++-- .../subcommands/voice/VoiceModSubCommand.java | 4 +- .../configuration/SpigotConfiguration.java | 7 +- .../players/objects/SpigotPlayerSelector.java | 2 +- .../modules/playlists/PlaylistService.java | 2 +- .../predictive/PredictiveMediaService.java | 4 +- .../punishments/EssentialsIntegration.java | 2 +- .../punishments/LitebansIntegration.java | 2 +- .../spigot/modules/regions/RegionModule.java | 22 ++--- .../spigot/modules/shortner/AliasService.java | 7 +- .../spigot/modules/show/objects/Show.java | 3 +- .../modules/speakers/SpeakerService.java | 16 ++-- .../tasks/SpeakerGarbageCollection.java | 10 +- .../modules/speakers/utils/SpeakerUtils.java | 2 +- .../voicechat/SpigotVoiceChatService.java | 6 +- .../voicechat/VoiceChannelService.java | 15 ++- .../dependency/SpigotDependencyService.java | 4 +- .../spigot/services/server/ServerService.java | 2 +- .../spigot/services/threading/Executor.java | 6 +- .../velocity/OpenAudioMcVelocity.java | 4 +- .../configuration/VelocityConfiguration.java | 14 +-- .../objects/VelocityPlayerSelector.java | 2 +- 96 files changed, 469 insertions(+), 382 deletions(-) create mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/LogAdapter.java delete mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/Logger.java create mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/GenericLogAdapter.java delete mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/SpigotLogger.java create mode 100644 plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/StdOutLog.java rename plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/{SocketIoConnector.java => SocketConnection.java} (84%) diff --git a/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/MapDBService.java b/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/MapDBService.java index 59a8d1c0b..e36cdf1f8 100644 --- a/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/MapDBService.java +++ b/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/MapDBService.java @@ -33,7 +33,7 @@ public MapDBService() { } public void shutdown() { - OpenAudioLogger.toConsole("Closing database"); + OpenAudioLogger.info("Closing database"); database.commit(); database.close(); databaseMap.clear(); @@ -46,7 +46,7 @@ public Repository getRepository(Class dataClass) { } // create database - OpenAudioLogger.toConsole("Registering storage table for " + dataClass.getSimpleName()); + OpenAudioLogger.info("Registering storage table for " + dataClass.getSimpleName()); Repository createdTable = new Repository<>(); createdTable.onCreate(this, this.database, dataClass); databaseMap.put(dataClass, createdTable); diff --git a/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/internal/NetworkedRepositoryCommit.java b/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/internal/NetworkedRepositoryCommit.java index 900fa8ab6..c314d7f24 100644 --- a/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/internal/NetworkedRepositoryCommit.java +++ b/modules/mapdb-migrator/src/main/java/com/craftmend/oamapmigrator/database/internal/NetworkedRepositoryCommit.java @@ -40,7 +40,7 @@ public void commit() { Class dataStore = (Class) Class.forName(repositoryTypeClass); dbs.getRepository(dataStore).saveString(key, dataString); } catch (ClassNotFoundException e) { - OpenAudioLogger.toConsole("Couldn't commit " + repositoryTypeClass + " because the class type is unknown"); + OpenAudioLogger.info("Couldn't commit " + repositoryTypeClass + " because the class type is unknown"); } } diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java index d14dae63f..965da594f 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java @@ -36,7 +36,7 @@ public VistasRedisClient(Configuration configuration) { configuration.getBoolean(StorageKey.REDIS_USE_SSL), configuration.getString(StorageKey.REDIS_SENTINEL_MASTER_SET), packetEvents, - "deputy_to_server" + "vistas_to_server" ); EventApi.getInstance().registerHandler(SpigotAudioCommandEvent.class, event -> { @@ -83,11 +83,11 @@ public VistasRedisClient(Configuration configuration) { } public void sendPacket(AbstractPacketPayload packet) { - redis.publish("server_to_deputy", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, null))); + redis.publish("server_to_vistas", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, null))); } public void sendPacket(AbstractPacketPayload packet, UUID serverId) { - redis.publish("server_to_deputy", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, serverId))); + redis.publish("server_to_vistas", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, serverId))); } } diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/listeners/PlayerListener.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/listeners/PlayerListener.java index 5721cddee..5da8f0aae 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/listeners/PlayerListener.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/listeners/PlayerListener.java @@ -37,7 +37,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { User user = OpenAudioMc.resolveDependency(UserHooks.class).byUuid(event.getPlayer().getUniqueId()); if (user == null) { - OpenAudioLogger.toConsole("WARNING! Vistas player join user is null"); + OpenAudioLogger.warn("Vistas player join user is null"); return; } diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/RedisConnection.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/RedisConnection.java index 9f8e7ff45..3dd2ee221 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/RedisConnection.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/RedisConnection.java @@ -45,7 +45,7 @@ public RedisConnection(String host, uri = builder.build(); } - OpenAudioLogger.toConsole("Connecting to redis server: " + uri.toString()); + OpenAudioLogger.info("Connecting to redis server: " + uri.toString()); redisClient = RedisClient.create(uri); redisClient.setOptions(ClientOptions.builder().autoReconnect(true).build()); diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/SimpleRedisClient.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/SimpleRedisClient.java index 164ff86d4..b7eddd6a0 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/SimpleRedisClient.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/redis/SimpleRedisClient.java @@ -23,7 +23,7 @@ public SimpleRedisClient(String host, this.listenerConnection = new RedisConnection(host, port, password, useSSL, sentinelMasterSet) .connectPubSub(); - // listen to packets from Spigot To Deputy + // listen to packets from Spigot To vistas this.listenerConnection.getPubSubHandler().subscribe(channels); this.listenerConnection.addPubSubListener(new RedisPubSubAdapter() { // received data diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/server/networking/VistasRedisServer.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/server/networking/VistasRedisServer.java index 1ae8c3f67..467de439a 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/server/networking/VistasRedisServer.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/server/networking/VistasRedisServer.java @@ -43,7 +43,7 @@ public VistasRedisServer(Configuration configuration) { configuration.getBoolean(StorageKey.REDIS_USE_SSL), configuration.getString(StorageKey.REDIS_SENTINEL_MASTER_SET), packetEvents, - "server_to_deputy" + "server_to_vistas" ); packetEvents.registerPacket(UserJoinPacket.class).setHandler(joinPacket -> { @@ -67,7 +67,7 @@ public VistasRedisServer(Configuration configuration) { User sender = OpenAudioMc.resolveDependency(UserHooks.class).byUuid(userExecuteAudioCommandPacket.getPlayerUuid()); if (sender == null) { - OpenAudioLogger.toConsole("User " + userExecuteAudioCommandPacket.getPlayerUuid() + " is not online, but tried to execute a command"); + OpenAudioLogger.warn("User " + userExecuteAudioCommandPacket.getPlayerUuid() + " is not online, but tried to execute a command"); return; } authenticationDriver.activateToken(sender, userExecuteAudioCommandPacket.getArgs()[0]); @@ -124,13 +124,13 @@ public VistasRedisServer(Configuration configuration) { packetEvents.registerPacket(WrappedProxyPacket.class).setHandler(wrappedProxyPacket -> { MinecraftServer installation = getService(ServerUserHooks.class).registerServerIfNew(wrappedProxyPacket.getServerId()); if (installation == null) { - OpenAudioLogger.toConsole("Warning! couldn't handle a packet from a server, because, well, I don't have it registered lol " + wrappedProxyPacket.getServerId()); + OpenAudioLogger.warn("couldn't handle a packet from a server, because, well, I don't have it registered lol " + wrappedProxyPacket.getServerId()); return; } User user = OpenAudioMc.resolveDependency(UserHooks.class).byUuid(wrappedProxyPacket.getPlayerId()); if (wrappedProxyPacket.getPacket() == null) { - System.out.println("WARNING! nill packet for " + user.getName()); + OpenAudioLogger.warn("nill packet for " + user.getName()); return; } OpenAudioMc.getService(ProxyHostService.class).onPacketReceive(user, wrappedProxyPacket.getPacket()); @@ -138,7 +138,7 @@ public VistasRedisServer(Configuration configuration) { } public void sendPacket(AbstractPacketPayload packet, UUID targetServerId) { - redis.publish("deputy_to_server", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, targetServerId))); + redis.publish("vistas_to_server", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, targetServerId))); } } diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/ServerUserHooks.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/ServerUserHooks.java index 85e1b78b5..59edd84cb 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/ServerUserHooks.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/ServerUserHooks.java @@ -37,11 +37,11 @@ public void startGc() { } } - for (VistasUser deputyUser : removeMe) { - OpenAudioLogger.toConsole("Kicking garbage connection for " + deputyUser.getName()); - deputyUser.handleDefiniteDisconnect(); - OpenAudioMc.getService(NetworkingService.class).remove(deputyUser.getUniqueId()); - remoteUsers.remove(deputyUser.getUniqueId()); + for (VistasUser vistasUser : removeMe) { + OpenAudioLogger.info("Kicking garbage connection for " + vistasUser.getName()); + vistasUser.handleDefiniteDisconnect(); + OpenAudioMc.getService(NetworkingService.class).remove(vistasUser.getUniqueId()); + remoteUsers.remove(vistasUser.getUniqueId()); } }, 20, 20); } @@ -124,13 +124,13 @@ public void onUserJoin(String playerName, UUID playerUuid, UUID serverId, String MinecraftServer dpi = remoteInstallation.get(serverId); VistasUser du = registerUserIfNew(playerUuid, playerName, ip); du.registerInServer(serverId); - OpenAudioLogger.toConsole(playerName + " got claimed by server " + serverId.toString()); + OpenAudioLogger.info(playerName + " got claimed by server " + serverId.toString()); } public void onUserLeave(String playerName, UUID playerUuid, UUID serverId) { MinecraftServer dpi = remoteInstallation.get(serverId); VistasUser du = registerUserIfNew(playerUuid, playerName); du.removeServer(serverId); - OpenAudioLogger.toConsole(playerName + " left server " + serverId.toString()); + OpenAudioLogger.info(playerName + " left server " + serverId.toString()); } } diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/VistasUser.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/VistasUser.java index 4fcc74197..ba346d329 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/VistasUser.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/users/VistasUser.java @@ -81,7 +81,7 @@ public void removeServer(UUID s) { } public void handleDefiniteDisconnect() { - OpenAudioLogger.toConsole("Handling disconnect for " + getName()); + OpenAudioLogger.info("Handling disconnect for " + getName()); OpenAudioMc.getService(NetworkingService.class).getClient(uuid).kickConnection(); } diff --git a/modules/vistas-server/src/main/java/com/craftmend/vistas/server/VistasServer.java b/modules/vistas-server/src/main/java/com/craftmend/vistas/server/VistasServer.java index 770212e22..b3e6bede0 100644 --- a/modules/vistas-server/src/main/java/com/craftmend/vistas/server/VistasServer.java +++ b/modules/vistas-server/src/main/java/com/craftmend/vistas/server/VistasServer.java @@ -36,7 +36,7 @@ public VistasServer() { instance = this; File basePath = new File(VistasConfiguration.BASE_PATH); if (!basePath.exists()) { - OpenAudioLogger.toConsole("Creating base path"); + OpenAudioLogger.info("Creating base path"); basePath.mkdir(); } } @@ -99,7 +99,7 @@ public Configuration getConfigurationProvider() { @Override public String getPluginVersion() { - return "deputy-latest"; + return "vistas-latest"; } @Override diff --git a/modules/vistas-server/src/main/java/com/craftmend/vistas/server/base/VistasConfiguration.java b/modules/vistas-server/src/main/java/com/craftmend/vistas/server/base/VistasConfiguration.java index f7d343cbf..d2244a947 100644 --- a/modules/vistas-server/src/main/java/com/craftmend/vistas/server/base/VistasConfiguration.java +++ b/modules/vistas-server/src/main/java/com/craftmend/vistas/server/base/VistasConfiguration.java @@ -43,7 +43,7 @@ public class VistasConfiguration extends Service implements Configuration { @Inject @SneakyThrows public VistasConfiguration() { - OpenAudioLogger.toConsole("Using storage base path " + BASE_PATH); + OpenAudioLogger.info("Using storage base path " + BASE_PATH); MagicValue.overWrite(MagicValue.STORAGE_DIRECTORY, new File(VistasConfiguration.BASE_PATH)); reloadConfig(); } @@ -74,7 +74,7 @@ private Object resolve(String key, StorageLocation location) { } public void set(String key, Object value, StorageLocation location) { - OpenAudioLogger.toConsole("Setting " + key + " to " + value); + OpenAudioLogger.info("Setting " + key + " to " + value); Map haystack = null; switch (location) { case DATA_FILE: @@ -102,7 +102,7 @@ public void set(String key, Object value, StorageLocation location) { @SneakyThrows @Override public void saveAll(boolean ignoreConfig) { - OpenAudioLogger.toConsole("Saving files..."); + OpenAudioLogger.info("Saving files..."); DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); @@ -269,12 +269,12 @@ public void reloadConfig() { configFile = new File(BASE_PATH + "/config.yml"); if (!dataFile.exists()) { - OpenAudioLogger.toConsole("Creating data.yml"); + OpenAudioLogger.info("Creating data.yml"); dataFile = new File(FileUtil.exportResource("/data.yml", OpenAudioMc.class, new File(BASE_PATH))); } if (!configFile.exists()) { - OpenAudioLogger.toConsole("Creating config.yml"); + OpenAudioLogger.info("Creating config.yml"); configFile = new File(FileUtil.exportResource("/config.yml", OpenAudioMc.class, new File(BASE_PATH))); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java b/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java index 1fef033dc..a8c9aa669 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java @@ -90,12 +90,12 @@ public OpenAudioMc(OpenAudioInvoker invoker) throws Exception { MagicValue.loadArguments(); if (env != null && !env.equals("")) { SERVER_ENVIRONMENT = ServerEnvironment.valueOf(env); - OpenAudioLogger.toConsole("WARNING! STARTING IN " + env + " MODE!"); + OpenAudioLogger.info("WARNING! STARTING IN " + env + " MODE!"); } // random bullshit, go! instance = this; - OpenAudioLogger.toConsole("Initializing build " + BUILD.getBuildNumber() + " by " + BUILD.getBuildAuthor()); + OpenAudioLogger.info("Starting OpenAudioMc, build " + BUILD.getBuildNumber() + " by " + BUILD.getBuildAuthor()); // load core internal API's which are heavily used by the rest of the plugin serviceManager.loadServices( @@ -180,7 +180,7 @@ public void disable() { serviceManager.getService(NetworkingService.class).stop(); } } catch (NoClassDefFoundError exception) { - OpenAudioLogger.toConsole("Bukkit already unloaded the OA+ classes, can't kill tokens."); + OpenAudioLogger.warn("Core dependencies were already unloaded by the classloader, skipping shutdown"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ApiEventDriver.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ApiEventDriver.java index 41d3e756e..56903adbc 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ApiEventDriver.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ApiEventDriver.java @@ -88,7 +88,7 @@ public HandlerHolder on(Class eventType) { String methodThatInvoked = e.getMethodName(); String classThatInvoked = e.getClassName(); int lineThatInvoked = e.getLineNumber(); - OpenAudioLogger.toConsole("Deprecated event listener registration, please use the new event system. Invoked from " + classThatInvoked + "#" + methodThatInvoked + ":" + lineThatInvoked); + OpenAudioLogger.warn("Deprecated event listener registration, please use the new event system. Invoked from " + classThatInvoked + "#" + methodThatInvoked + ":" + lineThatInvoked); // check if this event is supported here EventSupport support = getEventSupportFor(eventType); @@ -124,9 +124,7 @@ public T fire(T event) { try { subscriber.call(event); } catch (Exception e) { - OpenAudioLogger.handleException(e); - OpenAudioLogger.toConsole("Failed to handle an event handler"); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to handle an event (" + event.getClass().getSimpleName() + ") handler in " + subscriber.getHandler().getClass().getName()); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java index c43dd57d3..7adc5d843 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java @@ -16,7 +16,7 @@ public abstract class ExternalModule { public abstract void on(ModuleEvent event); protected void log(String message) { - OpenAudioLogger.toConsole("[module-" + getName() + "] " + message); + OpenAudioLogger.info("[module-" + getName() + "] " + message); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/OpenAudioMcBungee.java b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/OpenAudioMcBungee.java index b6e4f845e..3e5d3610c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/OpenAudioMcBungee.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/OpenAudioMcBungee.java @@ -79,11 +79,10 @@ public void onEnable() { // timing end and calc Instant finish = Instant.now(); - OpenAudioLogger.toConsole("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS"); + OpenAudioLogger.info("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS"); OpenAudioMc.getInstance().postBoot(); } catch (Exception e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to boot OpenAudioMc, please report this stacktrace"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/configuration/BungeeConfiguration.java b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/configuration/BungeeConfiguration.java index 79ba9d101..5d20b3061 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/configuration/BungeeConfiguration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/configuration/BungeeConfiguration.java @@ -38,7 +38,7 @@ public BungeeConfiguration() { dataConfig = getFile("data.yml"); mainConfig = getFile("config.yml"); - OpenAudioLogger.toConsole("Starting configuration module"); + OpenAudioLogger.info("Starting configuration module"); this.loadSettings(); } @@ -266,8 +266,7 @@ public void saveAll(boolean includeConfig) { } ConfigurationProvider.getProvider(YamlConfiguration.class).save(dataConfig, new File(OpenAudioMcBungee.getInstance().getDataFolder(), "data.yml")); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to save config/data"); } } @@ -294,8 +293,7 @@ private net.md_5.bungee.config.Configuration getFile(String filename) { try { load = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(OpenAudioMcBungee.getInstance().getDataFolder(), filename)); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Could not load file: " + filename); } return load; } @@ -310,8 +308,7 @@ private void saveDefaultFile(String filename, boolean hard) { try { Files.delete(file.toPath()); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Could not delete file: " + filename); } } @@ -319,8 +316,7 @@ private void saveDefaultFile(String filename, boolean hard) { try (InputStream in = OpenAudioMcBungee.getInstance().getResourceAsStream(filename)) { Files.copy(in, file.toPath()); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Could not save default file: " + filename); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/listeners/PlayerConnectionListener.java b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/listeners/PlayerConnectionListener.java index 863094957..d572d9395 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/listeners/PlayerConnectionListener.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/listeners/PlayerConnectionListener.java @@ -33,10 +33,8 @@ public class PlayerConnectionListener implements Listener { @EventHandler public void onPostLogin(PostLoginEvent event) { - OpenAudioLogger.toConsole("Post login for " + event.getPlayer().getName()); - if (!BungeeUtils.areEncodersReady(event.getPlayer())) { - OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not ready yet during postLogin, waiting for next event"); + OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not ready yet during postLogin, waiting for next event"); return; } @@ -56,13 +54,13 @@ public void onConnect(ServerConnectedEvent event) { )); if (!BungeeUtils.areEncodersReady(event.getPlayer())) { - OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not ready yet during connectEvent, waiting for next event"); + OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not ready yet during connectEvent, waiting for next event"); return; } // possibly polyfill the missing client if (!OpenAudioMc.getService(NetworkingService.class).hasClient(event.getPlayer().getUniqueId())) { - OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + "is not registered yet, forcing login during connect"); + OpenAudioLogger.warn("Player " + event.getPlayer().getName() + "is not registered yet, forcing login during connect"); OpenAudioMc.getService(NetworkingService.class).register(new BungeeUserAdapter(event.getPlayer()), null); } } @@ -70,12 +68,12 @@ public void onConnect(ServerConnectedEvent event) { @EventHandler public void onSwitch(ServerSwitchEvent event) { if (!BungeeUtils.areEncodersReady(event.getPlayer())) { - OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not ready yet during serverSwitch, waiting for next event"); + OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not ready yet during serverSwitch, waiting for next event"); } // did we have to skip the login packet? if (!OpenAudioMc.getService(NetworkingService.class).hasClient(event.getPlayer().getUniqueId())) { - OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not registered yet, forcing login during switch"); + OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not registered yet, forcing login during switch"); OpenAudioMc.getService(NetworkingService.class).register(new BungeeUserAdapter(event.getPlayer()), null); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/objects/BungeePlayerSelector.java b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/objects/BungeePlayerSelector.java index c25f35bf8..095291dce 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/objects/BungeePlayerSelector.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/player/objects/BungeePlayerSelector.java @@ -65,7 +65,7 @@ private List getPlayers(CommandSender commandSender) { if (proxiedPlayer != null) players.add(proxiedPlayer); } else { //you fucked it - OpenAudioLogger.toConsole("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments."); + OpenAudioLogger.warn("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments."); commandSender.sendMessage("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments."); } return players; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java index 1a418567c..0b3ff4a3c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java @@ -15,9 +15,8 @@ public void onLoad(String pluginName, Plugin plugin) { EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> { boolean isMuted = Database.get().isPlayerMuted(event.getClient().getActor().getUniqueId(), null); - if (isMuted) { - OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on LiteBans"); + OpenAudioLogger.warn("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on LiteBans"); event.setCancelled(true); } }); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/AuthenticationService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/AuthenticationService.java index 995083163..25a8bf176 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/AuthenticationService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/AuthenticationService.java @@ -44,7 +44,7 @@ public void onEnable() { public void initialize() { driver = new AuthenticationDriver(this); registrationProvider = new RestRequest(RegistrationResponse.class, Endpoint.REGISTER); - OpenAudioLogger.toConsole("Starting authentication module"); + OpenAudioLogger.info("Starting authentication module"); loadData(); explicitParentPublicKey = serverKeySet.getPublicKey(); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/driver/PluginTokenProvider.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/driver/PluginTokenProvider.java index c2b99255d..e9515180a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/driver/PluginTokenProvider.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/authentication/driver/PluginTokenProvider.java @@ -21,11 +21,11 @@ public void inject(TaskService ts, AuthenticationService as) { // create token if new if (config.getString(StorageKey.AUTH_PRIVATE_KEY) == null || config.getString(StorageKey.AUTH_PRIVATE_KEY).equals("not-set") || as.getAuthVersion() != as.getCurrentKeyVersion()) { - OpenAudioLogger.toConsole("Creating account..."); + OpenAudioLogger.info("Creating account..."); // am I a top level server? skip setup if that's the case if (OpenAudioMc.getInstance().getInvoker().isNodeServer()) { - OpenAudioLogger.toConsole("Skipping account setup since this isn't a master server, moving on with fake api keys."); + OpenAudioLogger.info("Skipping account setup since this isn't a master server, moving on with fake api keys."); as.getServerKeySet().setPrivateKey(new Key(UUID.randomUUID().toString())); as.getServerKeySet().setPublicKey(new Key(UUID.randomUUID().toString())); as.setSuccessful(true); @@ -39,7 +39,7 @@ public void inject(TaskService ts, AuthenticationService as) { as.initializeToken(response.getResponse(), config); as.setSuccessful(true); } else { - OpenAudioLogger.toConsole("Failed to request token. Error: " + response.getError().getMessage()); + OpenAudioLogger.info("Failed to request token. Error: " + response.getError().getMessage()); as.setSuccessful(false); } as.setNewAccount(true); @@ -47,7 +47,7 @@ public void inject(TaskService ts, AuthenticationService as) { } // paddle back - OpenAudioLogger.toConsole("This server already has an account, skipping sign up."); + OpenAudioLogger.info("This server already has an account, skipping sign up."); as.getServerKeySet().setPrivateKey(new Key(config.getString(StorageKey.AUTH_PRIVATE_KEY))); as.getServerKeySet().setPublicKey(new Key(config.getString(StorageKey.AUTH_PUBLIC_KEY))); as.setSuccessful(true); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/backups/BackupService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/backups/BackupService.java index 1db333392..19bf2d54e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/backups/BackupService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/backups/BackupService.java @@ -19,7 +19,7 @@ public void makeBackup(boolean force) { if (madeBackup) return; madeBackup = true; } - OpenAudioLogger.toConsole("Making a backup of your database, config, and data.yml"); + OpenAudioLogger.info("Making a backup of your database, config, and data.yml"); // check backups dir File backupRootDirectory = new File(MagicValue.STORAGE_DIRECTORY.get(File.class), File.separator + "backups"); @@ -27,7 +27,7 @@ public void makeBackup(boolean force) { backupRootDirectory.mkdir(); } - OpenAudioLogger.toConsole("Backup directory: " + backupRootDirectory.getAbsolutePath()); + OpenAudioLogger.info("Backup directory: " + backupRootDirectory.getAbsolutePath()); long unixTime = Instant.now().getEpochSecond(); // create current backup dir @@ -35,7 +35,7 @@ public void makeBackup(boolean force) { if (!backupDir.exists()) { backupDir.mkdir(); } else { - OpenAudioLogger.toConsole("Backup directory already exists"); + OpenAudioLogger.warn("Backup directory already exists"); } try { @@ -45,8 +45,7 @@ public void makeBackup(boolean force) { StandardCopyOption.REPLACE_EXISTING ); } catch (IOException e) { - OpenAudioLogger.toConsole("Failed to backup config.yml"); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to backup config.yml"); } try { @@ -56,8 +55,7 @@ public void makeBackup(boolean force) { StandardCopyOption.REPLACE_EXISTING ); } catch (IOException e) { - OpenAudioLogger.toConsole("Failed to backup data.yml"); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to backup data.yml"); } try { @@ -77,8 +75,7 @@ public void makeBackup(boolean force) { StandardCopyOption.REPLACE_EXISTING ); } catch (IOException e) { - OpenAudioLogger.toConsole("Failed to backup storm.db"); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to backup storm.db"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/ClientAuth.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/ClientAuth.java index 8677b5b7c..74ce807e0 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/ClientAuth.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/ClientAuth.java @@ -42,7 +42,7 @@ public void activateToken(User sender, String token) { activationAttempt.setWhenFailed((error) -> { sender.sendMessage(translateColors(StorageKey.MESSAGE_TOKEN_ACTIVATION_FAILED.getString())); - OpenAudioLogger.toConsole("Failed to activate token for " + sender.getName() + ", the code they entered is invalid or has expired."); + OpenAudioLogger.warn("Failed to activate token for " + sender.getName() + ", the code they entered is invalid or has expired."); }); activationAttempt.setWhenFinished((r) -> { @@ -82,7 +82,7 @@ public void publishSessionUrl() { Task sessionRequest = OpenAudioMc.getService(AuthenticationService.class).getDriver().createPlayerSession(client); sessionRequest.setWhenFailed((error) -> { - OpenAudioLogger.toConsole("Failed to create a session for " + client.getUser().getName() + ", error: " + error.getMessage()); + OpenAudioLogger.warn("Failed to create a session for " + client.getUser().getName() + ", error: " + error.getMessage()); client.getUser().sendMessage(translateColors(StorageKey.MESSAGE_SESSION_ERROR.getString())); }); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java index d33c99207..cf89915e0 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/CommandService.java @@ -211,9 +211,8 @@ public List getTabCompletions(CommandContext context, String[] args, Use return s; } catch (Exception e) { String message = "Error while tab-completing command " + context.name() + " with args " + Arrays.toString(args); - OpenAudioLogger.toConsole(message); sender.sendMessage(MagicValue.COMMAND_PREFIX.get(String.class) + "An error occurred while tab-completing this command. Please check the console for more information."); - e.printStackTrace(); + OpenAudioLogger.error(e, message); return new ArrayList<>(); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/DatabaseService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/DatabaseService.java index 7610fc261..a75f3cd89 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/DatabaseService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/DatabaseService.java @@ -75,13 +75,13 @@ public DatabaseService() { // migrate old data if there's a map.db if (new File(storageDir, "database.db").exists()) { - OpenAudioLogger.toConsole("Found old legacy database! loading the temporary module to replace it."); + OpenAudioLogger.warn("Found old legacy database! loading the temporary module to replace it."); getService(ModuleLoaderService.class).loadModFromFile(new File(storageDir, "modules/migrate.map-to-storm.jar")); } } public void shutdown() { - OpenAudioLogger.toConsole("Closing database"); + OpenAudioLogger.info("Closing database"); databaseMap.clear(); } @@ -91,7 +91,7 @@ public Repository getRepository(Class dataClass) { } // create database - OpenAudioLogger.toConsole("Registering storage table for " + dataClass.getSimpleName()); + OpenAudioLogger.info("Registering storage table for " + dataClass.getSimpleName()); Repository createdTable = new Repository<>(); createdTable.onCreate(this, this.storm, dataClass); databaseMap.put(dataClass, createdTable); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/internal/Repository.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/internal/Repository.java index 2f15c291d..08c2c7e1e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/internal/Repository.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/database/internal/Repository.java @@ -52,7 +52,7 @@ public void save(T data) { try { storm.save(data); } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to save a model. Trying again later (" + data.getClass().getSimpleName() + ")"); + OpenAudioLogger.warn("Failed to save a model. Trying again later (" + data.getClass().getSimpleName() + ")"); // try again in a second, if it failed again, log it as an error TaskService ts = OpenAudioMc.resolveDependency(TaskService.class); ts.schduleSyncDelayedTask(() -> { @@ -60,7 +60,7 @@ public void save(T data) { try { storm.save(data); } catch (Exception e1) { - OpenAudioLogger.toConsole("Error: Failed to update storm model " + data.getClass().getSimpleName()); + OpenAudioLogger.warn("Failed to save a model. This is a error. (" + data.getClass().getSimpleName() + ") (" + e.getClass().getSimpleName() + "/" + e1.getMessage() + ")"); } }); }, 20 * 5); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/environment/GlobalConstantService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/environment/GlobalConstantService.java index 2468d209c..109316a8a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/environment/GlobalConstantService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/environment/GlobalConstantService.java @@ -33,8 +33,7 @@ private void scheduleStatusUpdate() { .run() .getResponse(); } catch (Exception e) { - OpenAudioLogger.handleException(e); - // Failed to check + OpenAudioLogger.error(e, "Failed to check for updates"); } } ); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java index 0a45e6269..c8588996e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java @@ -25,8 +25,7 @@ public void invoke(Object event) { try { method.invoke(holder, event); } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to invoke event handler " + method.getName() + " in " + holder.getClass().getSimpleName() + " due to " + e.getMessage()); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to invoke event handler " + method.getName() + " in " + holder.getClass().getSimpleName()); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/LogAdapter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/LogAdapter.java new file mode 100644 index 000000000..92a2af68b --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/LogAdapter.java @@ -0,0 +1,45 @@ +package com.craftmend.openaudiomc.generic.logging; + +/** + * The LogAdapter us a custom logging interface used by OpenAudioMc across its various platforms + */ +public interface LogAdapter { + + /** + * Regular information logging + * @param message the message to log + */ + void info(String message); + + /** + * Log a debug message, along with debug information about its caller (class, method, and line number) + * @param message the message to log + */ + void debug(String message); + + /** + * Log an exception as cause, along with a human-readable message to provide some context + * @param e the exception to log + * @param message the message to log + */ + void error(Throwable e, String message); + + /** + * Log a warning message, similar to info, but with a different log level + * @param message the message to log + */ + void warn(String message); + + /** + * Enable or disable debug logging + * @param enable true to enable debug logging, false to disable + */ + void enableDebug(boolean enable); + + /** + * Check if debug logging is enabled + * @return true if debug logging is enabled, false if not + */ + boolean isDebugEnabled(); + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/Logger.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/Logger.java deleted file mode 100644 index 95d8780cd..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/Logger.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.craftmend.openaudiomc.generic.logging; - -public interface Logger { - void error(String s); - - void info(String s); - - boolean includePrefix(); -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/OpenAudioLogger.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/OpenAudioLogger.java index 49d594355..8543c8e4e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/OpenAudioLogger.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/OpenAudioLogger.java @@ -1,57 +1,77 @@ package com.craftmend.openaudiomc.generic.logging; -import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.generic.rest.ServerEnvironment; +import com.craftmend.openaudiomc.generic.logging.platform.StdOutLog; import lombok.Setter; +/** + * Static-accessible logging instance, with wrapper methods to prevent the instance + * to be accessed directly + * The log adapter can be set using {@link #setLogAdapter(LogAdapter)} to change the logging implementation. + */ public class OpenAudioLogger { - private static final String LOG_PREFIX = "[OpenAudioMc] "; - private static boolean muted = false; + @Setter + private static LogAdapter logAdapter = new StdOutLog(); - @Setter private static Logger logger = new Logger() { - - @Override - public void error(String s) { - System.err.println(s); - } - - @Override - public void info(String s) { - System.out.println(s); - } - - @Override - public boolean includePrefix() { - return true; - } - }; - - public static void toConsole(String message) { - if (muted) return; - logger.info((logger.includePrefix() ? LOG_PREFIX : "") + message); + /** + * Log a regular information message + * @param message the message to log + */ + public static void info(String message) { + logAdapter.info(message); } - public static void mute() { - muted = true; + /** + * Print debug information with the caller of this method (depth=1) + * @param message the message to log + */ + public static void debug(String message) { + debug(message, 1); } - public static void unmute() { - muted = false; + /** + * Print debug information with a custom depth for the caller. 0 would be the invocation, 1 its parent, etc + * @param message the message to log + * @param callerDepth the depth of the caller in the stack trace + */ + public static void debug(String message, int callerDepth) { + // get the class and method name of the caller + String caller = Thread.currentThread().getStackTrace()[2 + callerDepth].getFileName(); + String method = Thread.currentThread().getStackTrace()[2 + callerDepth].getMethodName(); + logAdapter.debug("[" + caller + ":" + method + "] " +message); } - public static void handleException(Throwable throwable) { - // don't do anything if this is prod, lol - if (OpenAudioMc.SERVER_ENVIRONMENT == ServerEnvironment.PRODUCTION) return; + /** + * Log an error message with a throwable + * @param e the throwable to log + * @param message the message to log + */ + public static void error(Throwable e, String message) { + logAdapter.error(e, message); + } - // get caller - StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace(); - StackTraceElement e = stacktrace[3]; + /** + * Write a warning message + * @param message the message to log + */ + public static void warn(String message) { + logAdapter.warn(message); + } - String methodThatFuckedUp = e.getMethodName(); + /** + * Enable or disable debug logging + * @param enable true to enable, false to disable + */ + public static void enableDebug(boolean enable) { + logAdapter.enableDebug(enable); + } - logger.error("Encountered an exception in " + methodThatFuckedUp); - throwable.printStackTrace(); + /** + * Check if debug logging is enabled + * @return true if debug logging is enabled + */ + public static boolean isDebugEnabled() { + return logAdapter.isDebugEnabled(); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/GenericLogAdapter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/GenericLogAdapter.java new file mode 100644 index 000000000..fb4cfa8b7 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/GenericLogAdapter.java @@ -0,0 +1,55 @@ +package com.craftmend.openaudiomc.generic.logging.platform; + +import com.craftmend.openaudiomc.generic.logging.LogAdapter; + +import java.util.logging.Logger; + +public class GenericLogAdapter implements LogAdapter { + + private final Logger genericLogger; + private static final String ANSI_CYAN = "\u001B[36m"; + private static final String ANSI_RESET = "\u001B[0m"; + private static final String ANSI_RED = "\u001B[31m"; + private static final String ANSI_YELLOW = "\u001B[33m"; + private boolean enableDebug = false; + + public GenericLogAdapter(Logger genericLogger) { + this.genericLogger = genericLogger; + } + + @Override + public void info(String message) { + genericLogger.info("[info] " + message); + } + + @Override + public void debug(String message) { + genericLogger.info("[debug] " + formatMessage(message, ANSI_CYAN)); + } + + @Override + public void error(Throwable e, String message) { + genericLogger.severe(ANSI_RED + "OpenAudioMc-Err: " + message + "\n" + e.toString() + ANSI_RESET); + e.printStackTrace(); + } + + @Override + public void warn(String message) { + genericLogger.warning(ANSI_YELLOW + "WARNING: " + message + ANSI_RESET); + } + + @Override + public void enableDebug(boolean enable) { + this.enableDebug = enable; + } + + @Override + public boolean isDebugEnabled() { + return enableDebug; + } + + private String formatMessage(String message, String colorCode) { + return colorCode + message + ANSI_RESET; + } +} + diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/SpigotLogger.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/SpigotLogger.java deleted file mode 100644 index eca1065f8..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/SpigotLogger.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.craftmend.openaudiomc.generic.logging.platform; - -import com.craftmend.openaudiomc.generic.logging.Logger; -import lombok.AllArgsConstructor; -import java.util.logging.Level; -import org.bukkit.plugin.java.JavaPlugin; - -@AllArgsConstructor -public class SpigotLogger implements Logger { - - private JavaPlugin plugin; - - @Override - public void error(String s) { - plugin.getLogger().log(Level.SEVERE, s); - } - - @Override - public void info(String s) { - plugin.getLogger().log(Level.INFO, s); - } - - @Override - public boolean includePrefix() { - return false; - } -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/StdOutLog.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/StdOutLog.java new file mode 100644 index 000000000..e6b9aabee --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/logging/platform/StdOutLog.java @@ -0,0 +1,52 @@ +package com.craftmend.openaudiomc.generic.logging.platform; + +import com.craftmend.openaudiomc.generic.logging.LogAdapter; + +/** + * The default logging interface targeting standard output, with some predefined colors for different log levels + */ +public class StdOutLog implements LogAdapter { + + private boolean enableDebug = false; + private static final String ANSI_RESET = "\u001B[0m"; + private static final String ANSI_RED = "\u001B[31m"; + private static final String ANSI_YELLOW = "\u001B[33m"; + private static final String ANSI_CYAN = "\u001B[36m"; + + @Override + public void info(String message) { + System.out.println("[OpenAudioMc-Info] " + formatMessage(message, ANSI_RESET)); + } + + @Override + public void debug(String message) { + if (!enableDebug) return; + System.out.println("[OpenAudioMc-Debug] " + formatMessage(message, ANSI_CYAN)); + } + + @Override + public void error(Throwable e, String message) { + System.err.println(ANSI_RED + "[OpenAudioMc-Err]: " + message + "\n" + e.toString() + ANSI_RESET); + e.printStackTrace(); + } + + @Override + public void warn(String message) { + System.out.println("[OpenAudioMc-Warn] " + ANSI_YELLOW + message + ANSI_RESET); + } + + @Override + public void enableDebug(boolean enable) { + this.enableDebug = enable; + } + + @Override + public boolean isDebugEnabled() { + return enableDebug; + } + + // Helper method to format the log message with color + private String formatMessage(String message, String colorCode) { + return colorCode + message + ANSI_RESET; + } +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java index c401e501d..84141e73b 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java @@ -65,15 +65,19 @@ public void handleMigrations() { for (SimpleMigration migration : migrations) { if (migration.shouldBeRun(this)) { OpenAudioMc.getService(BackupService.class).makeBackup(false); - OpenAudioLogger.toConsole("Migration Service: Running migration " + migration.getClass().getSimpleName()); - migration.execute(this); - OpenAudioLogger.toConsole("Migration Service: Finished migrating " + migration.getClass().getSimpleName()); + OpenAudioLogger.info("Migration Service: Running migration " + migration.getClass().getSimpleName()); + try { + migration.execute(this); + } catch (Exception e) { + OpenAudioLogger.error(e, "Migration Service: Failed to run migration " + migration.getClass().getSimpleName()); + } + OpenAudioLogger.info("Migration Service: Finished migrating " + migration.getClass().getSimpleName()); migrationsFinished++; } else { migrationsSkipped++; } } - OpenAudioLogger.toConsole("Skipped " + migrationsSkipped + "/" + migrations.length + " migrations."); + OpenAudioLogger.info("Skipped " + migrationsSkipped + "/" + migrations.length + " migrations."); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/interfaces/SimpleMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/interfaces/SimpleMigration.java index c9aaf3a39..cbf88faa4 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/interfaces/SimpleMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/interfaces/SimpleMigration.java @@ -67,7 +67,7 @@ protected void migrateFilesFromResources() { } if (oldValues.containsKey(key)) { - OpenAudioLogger.toConsole("Migrating " + key.getSubSection() + " from " + value + " to the new file"); + OpenAudioLogger.info("Migrating " + key.getSubSection() + " from " + value + " to the new file"); value = oldValues.get(key); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddAutoClaimMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddAutoClaimMigration.java index e02b7cf34..461c57f5f 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddAutoClaimMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddAutoClaimMigration.java @@ -20,7 +20,7 @@ public void execute(MigrationWorker migrationWorker) { forceOverwrittenValues.put(StorageKey.SETTINGS_VC_AUTOCLAIM.getSubSection(), false); migrateFilesFromResources(); // we've been running migrations, so we need to set it to false as to not break anything - OpenAudioLogger.toConsole("Overwriting default for " + getClass().getSimpleName() + " to maintain compatibility"); + OpenAudioLogger.info("Overwriting default for " + getClass().getSimpleName() + " to maintain compatibility"); Configuration config = OpenAudioMc.getInstance().getConfiguration(); forceOverwrittenValues.put(StorageKey.SETTINGS_VC_AUTOCLAIM.getSubSection(), false); config.setBoolean(StorageKey.SETTINGS_VC_AUTOCLAIM, false); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddConfigKeyMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddConfigKeyMigration.java index bf87e3013..ce1ce9679 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddConfigKeyMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AddConfigKeyMigration.java @@ -25,7 +25,7 @@ public boolean shouldBeRun(MigrationWorker migrationWorker) { @Override public void execute(MigrationWorker migrationWorker) { - OpenAudioLogger.toConsole("Migrating config key for: " + name); + OpenAudioLogger.info("Migrating config key for: " + name); migrateFilesFromResources(); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AliasDatabaseMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AliasDatabaseMigration.java index 0dc87d964..863368486 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AliasDatabaseMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/AliasDatabaseMigration.java @@ -22,12 +22,12 @@ public boolean shouldBeRun(MigrationWorker migrationWorker) { @Override public void execute(MigrationWorker migrationWorker) { - OpenAudioLogger.toConsole("Migrating aliases from the data.yml"); + OpenAudioLogger.info("Migrating aliases from the data.yml"); Configuration config = OpenAudioMc.getInstance().getConfiguration(); DatabaseService service = OpenAudioMc.getService(DatabaseService.class); for (String id : config.getStringSet("aliases", StorageLocation.DATA_FILE)) { - OpenAudioLogger.toConsole("Migrating alias " + id); + OpenAudioLogger.info("Migrating alias " + id); service.getRepository(Alias.class) .save(new Alias(id, config.getStringFromPath("aliases." + id, StorageLocation.DATA_FILE))); config.setString(StorageLocation.DATA_FILE, "aliases." + id, null); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/PredictiveCacheMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/PredictiveCacheMigration.java index fd93121c3..5a661f8e6 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/PredictiveCacheMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/PredictiveCacheMigration.java @@ -29,7 +29,7 @@ public boolean shouldBeRun(MigrationWorker migrationWorker) { @Override public void execute(MigrationWorker migrationWorker) { - OpenAudioLogger.toConsole("Migrating world audio heatmap"); + OpenAudioLogger.info("Migrating world audio heatmap"); DatabaseService service = OpenAudioMc.getService(DatabaseService.class); Repository repo = service.getRepository(StoredWorldChunk.class); try { @@ -43,7 +43,7 @@ public void execute(MigrationWorker migrationWorker) { for (Map.Entry entry : filemap.getData().entrySet()) { String name = entry.getKey(); SerializedAudioChunk.Chunk chunk = entry.getValue(); - OpenAudioLogger.toConsole("Migrating world section " + name); + OpenAudioLogger.info("Migrating world section " + name); StoredWorldChunk swc = new StoredWorldChunk(name, chunk); repo.save(swc); @@ -53,7 +53,7 @@ public void execute(MigrationWorker migrationWorker) { OpenAudioMcSpigot.getInstance().getDataFolder(), "cache.json" ).delete(); } catch (IOException e) { - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to migrate world audio heatmap"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/RegionDatabaseMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/RegionDatabaseMigration.java index 4e91421ac..83b28f593 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/RegionDatabaseMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/RegionDatabaseMigration.java @@ -24,12 +24,12 @@ public boolean shouldBeRun(MigrationWorker migrationWorker) { @Override public void execute(MigrationWorker migrationWorker) { - OpenAudioLogger.toConsole("Migrating regions from the data.yml"); + OpenAudioLogger.info("Migrating regions from the data.yml"); Configuration config = OpenAudioMc.getInstance().getConfiguration(); DatabaseService service = OpenAudioMc.getService(DatabaseService.class); for (String id : config.getStringSet("regions", StorageLocation.DATA_FILE)) { - OpenAudioLogger.toConsole("Migrating region " + id + " to the the new storage format"); + OpenAudioLogger.info("Migrating region " + id + " to the the new storage format"); String source = config.getStringFromPath("regions." + id, StorageLocation.DATA_FILE); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/SpeakerDatabaseMigration.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/SpeakerDatabaseMigration.java index 2ef89261a..8a19b2708 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/SpeakerDatabaseMigration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/migrations/SpeakerDatabaseMigration.java @@ -30,13 +30,13 @@ public boolean shouldBeRun(MigrationWorker migrationWorker) { @Override public void execute(MigrationWorker migrationWorker) { - OpenAudioLogger.toConsole("Migrating speakers from the data.yml"); + OpenAudioLogger.info("Migrating speakers from the data.yml"); Configuration config = OpenAudioMc.getInstance().getConfiguration(); DatabaseService service = OpenAudioMc.getService(DatabaseService.class); for (String id : config.getStringSet("speakers", StorageLocation.DATA_FILE)) { // check if said world is loaded - OpenAudioLogger.toConsole("Migrating speaker " + id); + OpenAudioLogger.info("Migrating speaker " + id); if (id.equals("none") || !isUuid(id)) { config.setString(StorageLocation.DATA_FILE, "speakers." + id, null); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/mojang/MojangLookupService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/mojang/MojangLookupService.java index a93fcf5f7..cc0e0b3aa 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/mojang/MojangLookupService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/mojang/MojangLookupService.java @@ -28,26 +28,26 @@ public class MojangLookupService extends Service { public MojangLookupService(DatabaseService databaseService, TaskService ts, OpenAudioMc openAudioMc) { profileRepository = databaseService.getRepository(MojangProfile.class); ts.scheduleAsyncRepeatingTask(() -> { - OpenAudioLogger.toConsole("Starting mojang cleanup, this can take a while..."); + OpenAudioLogger.info("Starting mojang cleanup, this can take a while..."); // check every hour if the server is empty if (openAudioMc.getInvoker().getUserHooks().getOnlineUsers().isEmpty()) { cleanup(); } - OpenAudioLogger.toConsole("Finished cleanup"); + OpenAudioLogger.info("Finished cleanup"); }, 36000 * 20, 36000 * 20); // once every 10 bloody hours } private void cleanup() { int removed = 0; - OpenAudioLogger.toConsole("Purging old accounts of inactive players"); + OpenAudioLogger.info("Purging old accounts of inactive players"); for (MojangProfile value : profileRepository.values()) { if (value.getLastSeen() == null || Duration.between(value.getLastSeen(), Instant.now()).getSeconds() > 604800) { removed++; profileRepository.delete(value); } } - OpenAudioLogger.toConsole("Removed the profile of " + removed + " players"); + OpenAudioLogger.info("Removed the profile of " + removed + " players"); } public void save(User user) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java index 316a61c61..54a5e479b 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java @@ -17,7 +17,7 @@ import com.craftmend.openaudiomc.generic.networking.interfaces.Authenticatable; import com.craftmend.openaudiomc.generic.networking.interfaces.INetworkingEvents; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; -import com.craftmend.openaudiomc.generic.networking.io.SocketIoConnector; +import com.craftmend.openaudiomc.generic.networking.io.SocketConnection; import com.craftmend.openaudiomc.generic.platform.Platform; import com.craftmend.openaudiomc.generic.platform.interfaces.TaskService; import com.craftmend.openaudiomc.generic.proxy.interfaces.UserHooks; @@ -37,7 +37,7 @@ public class DefaultNetworkingService extends NetworkingService { private final Set eventHandlers = new HashSet<>(); private final Map clientMap = new ConcurrentHashMap<>(); private final Map> packetHandlerMap = new HashMap<>(); - private SocketIoConnector socketIoConnector; + private SocketConnection socketConnection; private int packetThroughput = 0; public DefaultNetworkingService() { @@ -89,7 +89,7 @@ public void onModuleLoad() { } private void init() { - OpenAudioLogger.toConsole("Initializing socket connector"); + OpenAudioLogger.info("Initializing connection service..."); // set tick tack OpenAudioMc.resolveDependency(TaskService.class) @@ -99,11 +99,9 @@ private void init() { 20, 20); try { - socketIoConnector = new SocketIoConnector(OpenAudioMc.getService(AuthenticationService.class).getServerKeySet()); + socketConnection = new SocketConnection(OpenAudioMc.getService(AuthenticationService.class).getServerKeySet()); } catch (Exception e) { - OpenAudioLogger.handleException(e); - OpenAudioLogger.toConsole("The plugin could not start because of a connection problem when requesting the initial private key. Please contact the developers of this plugin."); - e.printStackTrace(); + OpenAudioLogger.error(e, "The plugin was unable to start because of a connection problem when requesting the initial private key. Please contact support in https://discord.openaudiomc.net/"); } } @@ -119,7 +117,7 @@ public void connectIfDown() { } // update state OpenAudioMc.getService(OpenaudioAccountService.class).startVoiceHandshake(); - OpenAudioMc.resolveDependency(TaskService.class).runAsync(() -> socketIoConnector.setupConnection()); + OpenAudioMc.resolveDependency(TaskService.class).runAsync(() -> socketConnection.setupConnection()); } /** @@ -131,7 +129,7 @@ public void connectIfDown() { @Override public void send(Authenticatable client, AbstractPacket packet) { for (INetworkingEvents event : getEvents()) event.onPacketSend(client, packet); - socketIoConnector.send(client, packet); + socketConnection.send(client, packet); } /** @@ -143,7 +141,7 @@ public void send(Authenticatable client, AbstractPacket packet) { @Override public void triggerPacket(AbstractPacket abstractPacket) { if (packetHandlerMap.get(abstractPacket.getPacketChannel()) == null) { - OpenAudioLogger.toConsole("Unknown handler for packet type " + abstractPacket.getPacketChannel().name()); + OpenAudioLogger.warn("Unknown handler for packet type " + abstractPacket.getPacketChannel().name()); return; } @@ -211,8 +209,7 @@ public void remove(UUID playerId) { try { handler.accept(client); } catch (Exception e) { - e.printStackTrace(); - OpenAudioLogger.toConsole("Failed to handle destroy listener " + id + " for " + client.getOwner().getName()); + OpenAudioLogger.error(e, "Failed to handle destroy listener " + id + " for " + client.getOwner().getName()); } }); @@ -249,7 +246,7 @@ public ClientConnection register(User player, @Nullable SerializableClient impor */ @Override public void stop() { - socketIoConnector.disconnect(); + socketConnection.disconnect(); } @Override diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/AbstractPacketAdapter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/AbstractPacketAdapter.java index 8a54a24c2..232245392 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/AbstractPacketAdapter.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/AbstractPacketAdapter.java @@ -57,7 +57,7 @@ public AbstractPacketPayload deserialize(JsonElement json, Type typeOfT, JsonDes return context.deserialize(element, loadClassModuleFallback("com.craftmend.openaudiomc.generic.networking.payloads." + type)); } catch (ClassNotFoundException cnfe) { - OpenAudioLogger.handleException(cnfe); + OpenAudioLogger.error(cnfe, "Failed to deserialize packet type " + type); throw new JsonParseException("Unknown element type: " + type, cnfe); } } @@ -91,7 +91,7 @@ private Class deepQueryClasses(String classname) throws ClassNotFoundExceptio for (ExternalModule module : OpenAudioMc.getService(ModuleLoaderService.class).getModules()) { try { if (!walkedClassLoader) { - OpenAudioLogger.toConsole("Handling a packet type that isn't in the native class loader, searching modules for the first time instead."); + OpenAudioLogger.info("Handling a packet type that isn't in the native class loader, searching modules for the first time instead."); walkedClassLoader = true; } return Class.forName(classname, true, module.getLoader()); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/StandardPacketAdapter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/StandardPacketAdapter.java index 008acd8f4..3865e99d7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/StandardPacketAdapter.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/addapter/StandardPacketAdapter.java @@ -36,7 +36,7 @@ public StandardPacket deserialize(JsonElement json, Type typeOfT, JsonDeserializ try { return context.deserialize(element, Class.forName(type)); } catch (ClassNotFoundException cnfe) { - OpenAudioLogger.handleException(cnfe); + OpenAudioLogger.error(cnfe, "Failed to deserialize packet " + json.getAsString()); throw new JsonParseException("Unknown element type: " + type, cnfe); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/certificate/CertificateHelper.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/certificate/CertificateHelper.java index d33ea820f..179aeb27c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/certificate/CertificateHelper.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/certificate/CertificateHelper.java @@ -51,8 +51,7 @@ public boolean verify(String hostname, SSLSession session) { } }); } catch (Exception e) { - OpenAudioLogger.handleException(e); - OpenAudioLogger.toConsole("Failed to middleman ssl, should probably be fine"); + OpenAudioLogger.warn("Failed to handle certificate middleware, this may cause issues with the connection to the OpenAudioMc API. Error: " + e.getMessage()); } return builder; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java index 9ad03604b..46b364a7c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java @@ -10,7 +10,7 @@ import com.craftmend.openaudiomc.generic.networking.interfaces.INetworkingEvents; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; import com.craftmend.openaudiomc.generic.networking.interfaces.SocketDriver; -import com.craftmend.openaudiomc.generic.networking.io.SocketIoConnector; +import com.craftmend.openaudiomc.generic.networking.io.SocketConnection; import com.craftmend.openaudiomc.generic.networking.payloads.AcknowledgeClientPayload; import io.socket.client.Ack; import io.socket.client.Socket; @@ -20,7 +20,7 @@ public class ClientDriver implements SocketDriver { @Override - public void boot(Socket socket, SocketIoConnector connector) { + public void boot(Socket socket, SocketConnection connector) { socket.on("acknowledgeClient", args -> { AcknowledgeClientPayload payload = (AcknowledgeClientPayload) OpenAudioMc.getGson().fromJson( args[0].toString(), @@ -45,7 +45,7 @@ public void boot(Socket socket, SocketIoConnector connector) { event.onClientOpen(authenticatable); } } else { - OpenAudioLogger.toConsole("Closing login attempt for " + authenticatable.getOwner().getName() + " because they are already connected."); + OpenAudioLogger.info("Closing login attempt for " + authenticatable.getOwner().getName() + " because they are already connected."); callback.call(false); } } @@ -58,15 +58,12 @@ public void boot(Socket socket, SocketIoConnector connector) { } catch (Exception e) { // ignore when we're shutting down if (OpenAudioMc.getInstance().isDisabled()) return; - OpenAudioLogger.handleException(e); - OpenAudioLogger.toConsole("An incoming packet was attempted to be parsed but failed horribly and it broke. Please update your plugin, of if this is already the latest version, let me know of this exception. The received data was: " + args[0].toString()); - e.printStackTrace(); + OpenAudioLogger.error(e, "An incoming packet was attempted to be parsed but failed horribly and it broke. Please update your plugin, of if this is already the latest version, let me know of this exception. The received data was: " + args[0].toString()); } }); } private Authenticatable findSession(UUID id) { - ClientConnection clientConnection = OpenAudioMc.getService(NetworkingService.class).getClient(id); - return clientConnection; + return OpenAudioMc.getService(NetworkingService.class).getClient(id); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/NotificationDriver.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/NotificationDriver.java index 69e6a50ee..66f81cd24 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/NotificationDriver.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/NotificationDriver.java @@ -9,7 +9,7 @@ import com.craftmend.openaudiomc.generic.networking.drivers.interfaces.NotificationHandler; import com.craftmend.openaudiomc.generic.networking.drivers.models.BackendNotification; import com.craftmend.openaudiomc.generic.networking.interfaces.SocketDriver; -import com.craftmend.openaudiomc.generic.networking.io.SocketIoConnector; +import com.craftmend.openaudiomc.generic.networking.io.SocketConnection; import io.socket.client.Socket; import java.util.HashMap; @@ -28,7 +28,7 @@ public class NotificationDriver implements SocketDriver { }}; @Override - public void boot(Socket socket, SocketIoConnector connector) { + public void boot(Socket socket, SocketConnection connector) { socket.on("oa-notification", args -> { BackendNotification payload = OpenAudioMc.getGson().fromJson(((String) args[args.length - 1]), BackendNotification.class); @@ -38,7 +38,7 @@ public void boot(Socket socket, SocketIoConnector connector) { // handle type NotificationHandler handler = handlers.get(payload.getNotificationType()); if (handler == null) { - OpenAudioLogger.toConsole("WARNING: Received notification " + payload.getNotificationType() + " but it doesn't have a handler. Is this plugin outdated?"); + OpenAudioLogger.warn("Received notification " + payload.getNotificationType() + " but it doesn't have a handler. Is this plugin outdated?"); } else { handler.handle(payload); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/SystemDriver.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/SystemDriver.java index ebdac792c..b96020f71 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/SystemDriver.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/SystemDriver.java @@ -10,7 +10,7 @@ import com.craftmend.openaudiomc.generic.storage.enums.StorageKey; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.networking.interfaces.SocketDriver; -import com.craftmend.openaudiomc.generic.networking.io.SocketIoConnector; +import com.craftmend.openaudiomc.generic.networking.io.SocketConnection; import com.craftmend.openaudiomc.generic.platform.Platform; import com.craftmend.openaudiomc.generic.state.states.ConnectedState; import com.craftmend.openaudiomc.generic.state.states.IdleState; @@ -27,7 +27,7 @@ public class SystemDriver implements SocketDriver { private Socket lastSocket; @Override - public void boot(Socket socket, SocketIoConnector connector) { + public void boot(Socket socket, SocketConnection connector) { this.lastSocket = socket; taskService.scheduleAsyncRepeatingTask(() -> { @@ -67,7 +67,7 @@ private void checkHeartbeatDelay() { // is the latest heartbeat older than 30 seconds? if (lastHeartbeat.plusSeconds(30).isBefore(Instant.now())) { - OpenAudioLogger.toConsole("Heartbeat timed out, disconnecting..."); + OpenAudioLogger.warn("Heartbeat timed out, disconnecting..."); // yes, it is. disconnect handleDisconnect(); // timeout state @@ -77,7 +77,7 @@ private void checkHeartbeatDelay() { long seconds = Duration.between(lastHeartbeat, Instant.now()).getSeconds(); if (seconds > 10) { // more than 5 seconds, so we're probably lagging - OpenAudioLogger.toConsole("Heartbeat is lagging " + seconds + " seconds behind, connection will reset if it doesn't recover soon"); + OpenAudioLogger.warn("Heartbeat is lagging " + seconds + " seconds behind, connection will reset if it doesn't recover soon"); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AccountUpdateNotification.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AccountUpdateNotification.java index 7180e9c38..ef2311485 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AccountUpdateNotification.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AccountUpdateNotification.java @@ -16,7 +16,7 @@ public class AccountUpdateNotification implements NotificationHandler { @Override public void handle(BackendNotification notificationData) { - OpenAudioLogger.toConsole("Updating craftmend account due to update push.."); + OpenAudioLogger.info("Updating OpenAudioMc account state due to update push.."); OpenAudioMc.getService(OpenaudioAccountService.class).syncAccount(); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AdminNotification.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AdminNotification.java index b18d43a3c..d64efa5be 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AdminNotification.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/handler/AdminNotification.java @@ -25,7 +25,7 @@ public void handle(BackendNotification notificationData) { String messageWithPrefix = MagicValue.COMMAND_PREFIX.get(String.class); messageWithPrefix += coloredMessage; - OpenAudioLogger.toConsole(coloredMessage); + OpenAudioLogger.warn(coloredMessage); for (ClientConnection client : OpenAudioMc.getService(NetworkingService.class).getClients()) { if (client.getUser().isAdministrator()) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/SocketDriver.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/SocketDriver.java index 08e4dc4c5..ba255223c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/SocketDriver.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/SocketDriver.java @@ -1,10 +1,10 @@ package com.craftmend.openaudiomc.generic.networking.interfaces; -import com.craftmend.openaudiomc.generic.networking.io.SocketIoConnector; +import com.craftmend.openaudiomc.generic.networking.io.SocketConnection; import io.socket.client.Socket; public interface SocketDriver { - void boot(Socket socket, SocketIoConnector connector); + void boot(Socket socket, SocketConnection connector); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketConnection.java similarity index 84% rename from plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java rename to plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketConnection.java index 2c931ef47..5a8174a56 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketConnection.java @@ -2,7 +2,6 @@ import com.craftmend.openaudiomc.OpenAudioMc; import com.craftmend.openaudiomc.api.EventApi; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; import com.craftmend.openaudiomc.generic.authentication.AuthenticationService; import com.craftmend.openaudiomc.generic.authentication.objects.ServerKeySet; import com.craftmend.openaudiomc.generic.events.events.StateChangeEvent; @@ -40,7 +39,7 @@ import java.time.Duration; import java.time.Instant; -public class SocketIoConnector { +public class SocketConnection { private Socket socket; @Getter @@ -57,7 +56,7 @@ public class SocketIoConnector { new ClientDriver(), }; - public SocketIoConnector(ServerKeySet keySet) { + public SocketConnection(ServerKeySet keySet) { this.keySet = keySet; } @@ -96,16 +95,11 @@ public void setupConnection() { keySet.getPublicKey().getValue() ); - // request a relay server - if (StorageKey.DEBUG_LOG_STATE_CHANGES.getBoolean()) { - OpenAudioLogger.toConsole("Requesting relay.."); - } - // schedule timeout check OpenAudioMc.resolveDependency(TaskService.class).schduleSyncDelayedTask(() -> { if (OpenAudioMc.getService(StateService.class).getCurrentState() instanceof AssigningRelayState) { - OpenAudioLogger.toConsole("Connecting timed out."); - OpenAudioMc.getService(StateService.class).setState(new IdleState("Connecting to the relay timed out")); + OpenAudioLogger.info("Connecting timed out."); + OpenAudioMc.getService(StateService.class).setState(new IdleState("Connecting to OpenAudioMc timed out")); } }, 20 * 35); @@ -115,11 +109,10 @@ public void setupConnection() { if (relayLoginRequest.hasError()) { OpenAudioMc.getService(StateService.class).setState(new IdleState("Failed to do the initial handshake. Error: " + relayLoginRequest.getError())); - OpenAudioLogger.toConsole("Failed to get relay host: " + relayLoginRequest.getError().getMessage()); + OpenAudioLogger.info("Failed to get instance: " + relayLoginRequest.getError().getMessage()); try { - throw new IOException("Failed to get relay! see console for error information"); + throw new IOException("Failed to get instance! see console for error information"); } catch (IOException e) { - OpenAudioLogger.handleException(e); e.printStackTrace(); } return; @@ -127,19 +120,15 @@ public void setupConnection() { RelayLoginResponse loginResponse = relayLoginRequest.getResponse(); Instant finish = Instant.now(); - if (StorageKey.DEBUG_LOG_STATE_CHANGES.getBoolean()) { - OpenAudioLogger.toConsole("Assigned relay: " + loginResponse.getRelay() + " request took " + Duration.between(request, finish).toMillis() + "MS"); - } + lastUsedRelay = loginResponse.getRelay(); - // setup socketio connection try { String endpoint = loginResponse.getRelayEndpoint(); endpoint = endpoint.replace("https", "http"); socket = IO.socket(endpoint, opts); } catch (URISyntaxException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Received an invalid endpoint"); } // register state to be connecting @@ -151,8 +140,8 @@ public void setupConnection() { // schedule timeout check OpenAudioMc.resolveDependency(TaskService.class).schduleSyncDelayedTask(() -> { if (OpenAudioMc.getService(StateService.class).getCurrentState() instanceof ConnectingState) { - OpenAudioLogger.toConsole("Connecting timed out."); - OpenAudioMc.getService(StateService.class).setState(new IdleState("Connecting to the relay timed out (socket)")); + OpenAudioLogger.warn("Connect timed out."); + OpenAudioMc.getService(StateService.class).setState(new IdleState("Connecting to the assigned instance timed out (socket)")); } }, 20 * 35); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java index 26afa7601..41c5a5ba0 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java @@ -63,7 +63,7 @@ public void onEnable() { // wait after buut if its a new account if (OpenAudioMc.getService(AuthenticationService.class).isNewAccount()) { delayedInit = true; - OpenAudioLogger.toConsole("Delaying account init because we're a fresh installation"); + OpenAudioLogger.info("Delaying account init because we're a fresh installation"); OpenAudioMc.resolveDependency(TaskService.class).schduleSyncDelayedTask(this::initialize, 20 * 3); } else { delayedInit = false; @@ -77,7 +77,7 @@ public void postBoot() { } private void initialize() { - OpenAudioLogger.toConsole("Initializing account details"); + OpenAudioLogger.info("Initializing account details"); syncAccount(); initialized = true; @@ -99,17 +99,17 @@ public void syncAccount() { // are there any errors? if (settingsRequest.hasError()) { - OpenAudioLogger.toConsole("Failed to sync account details. Error: " + settingsRequest.getError().getMessage()); - OpenAudioLogger.toConsole("This is probably because the account got deleted, or the server key is invalid."); + OpenAudioLogger.warn("Failed to sync account details. Error: " + settingsRequest.getError().getMessage()); + OpenAudioLogger.warn("This is probably because the account got deleted, or the server key is invalid."); if (!OpenAudioMc.getService(AuthenticationService.class).isNewAccount()) { // drop old Configuration config = OpenAudioMc.getInstance().getConfiguration(); config.setString(StorageKey.AUTH_PRIVATE_KEY, "not-set"); config.setString(StorageKey.AUTH_PUBLIC_KEY, "not-set"); - OpenAudioLogger.toConsole("This is not a new account, so I'm going to invalidate the server key and try again."); + OpenAudioLogger.warn("This is not a new account, so I'm going to invalidate the server key and try again."); TOKEN_PROVIDER.inject(taskService, OpenAudioMc.getService(AuthenticationService.class)); - OpenAudioLogger.toConsole("Retrying..."); + OpenAudioLogger.warn("Retrying..."); try { Thread.sleep(1000); } catch (InterruptedException e) { @@ -177,12 +177,12 @@ public void startVoiceHandshake(boolean ignoreLocal) { } if (OpenAudioMc.resolveDependency(UserHooks.class).getOnlineUsers().isEmpty()) { - OpenAudioLogger.toConsole("The server is empty! ignoring voice chat."); + OpenAudioLogger.info("The server is empty! ignoring voice chat."); return; } if (OpenAudioMc.SERVER_ENVIRONMENT == ServerEnvironment.PRODUCTION) { - OpenAudioLogger.toConsole("VoiceChat seems to be enabled for this account! Requesting RTC and Password..."); + OpenAudioLogger.info("Preparing voice chat..."); } // do magic, somehow fail, or login to the voice server isAttemptingVcConnect = true; @@ -196,7 +196,7 @@ public void startVoiceHandshake(boolean ignoreLocal) { SectionError errorCode = voiceLoginRequest.getError(); if (errorCode == SectionError.VOICECHAT_DISABLED) { - OpenAudioLogger.toConsole("Your account doesn't actually have permissions for voicechat, shutting down."); + OpenAudioLogger.warn("Voicechat is disabled for this server."); removeTag(CraftmendTag.VOICECHAT); isAttemptingVcConnect = false; lockVcAttempt = false; @@ -206,7 +206,7 @@ public void startVoiceHandshake(boolean ignoreLocal) { if (errorCode == SectionError.VOICECHAT_ALREADY_CONNECTED) { new RestRequest(NoResponse.class, Endpoint.VOICE_INVALIDATE_PASSWORD).run(); - OpenAudioLogger.toConsole("This server still has a session running with voice chat, terminating and trying again in 20 seconds."); + OpenAudioLogger.warn("This server still has a session running with voice chat, terminating and trying again in 20 seconds."); OpenAudioMc.resolveDependency(TaskService.class).schduleSyncDelayedTask(() -> { startVoiceHandshake(true); }, 20 * 20); @@ -216,7 +216,7 @@ public void startVoiceHandshake(boolean ignoreLocal) { if (errorCode == SectionError.SERVER_ERROR) { new RestRequest(NoResponse.class, Endpoint.VOICE_INVALIDATE_PASSWORD).run(); - OpenAudioLogger.toConsole("Failed to claim a voicechat session, terminating and trying again in 20 seconds."); + OpenAudioLogger.warn("Failed to claim a voicechat session, terminating and trying again in 20 seconds."); OpenAudioMc.resolveDependency(TaskService.class).schduleSyncDelayedTask(() -> { startVoiceHandshake(true); }, 20 * 20); @@ -224,7 +224,7 @@ public void startVoiceHandshake(boolean ignoreLocal) { return; } - OpenAudioLogger.toConsole("Failed to initialize voice chat. Error: " + errorCode.getMessage()); + OpenAudioLogger.warn("Failed to initialize voice chat. Error: " + errorCode.getMessage()); voiceApiConnection.setStatus(VoiceApiStatus.IDLE); isAttemptingVcConnect = false; lockVcAttempt = false; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/platform/interfaces/TaskService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/platform/interfaces/TaskService.java index f1334d5d1..843f1a027 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/platform/interfaces/TaskService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/platform/interfaces/TaskService.java @@ -14,7 +14,7 @@ public interface TaskService { default void notifyRunner() { StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace(); StackTraceElement e = stacktrace[3]; - OpenAudioLogger.toConsole("An async task was requested but server is already stopping, so I'm doing it now. Original requester was from " + e.getMethodName() + " in " + e.getFileName()); + OpenAudioLogger.info("An async task was requested but server is already stopping, so I'm doing it now. Original requester was from " + e.getMethodName() + " in " + e.getFileName()); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketManager.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketManager.java index 740774cdb..1c5498ead 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketManager.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketManager.java @@ -188,8 +188,7 @@ private void doPacket(PacketPlayer packetPlayer, DataInputStream dataInputStream } } catch (ClassNotFoundException ignored){ // silently ignore packets we don't know about } catch (Throwable e){ - OpenAudioLogger.toConsole("Error whilst receiving packet " + packetName); - e.printStackTrace(); + OpenAudioLogger.error(e, "Error whilst receiving packet " + packetName); } } @@ -205,8 +204,7 @@ public void dispatchReceivedPacket(Class packetClazz, try { method.invoke(packetListener, user, packet); } catch (InvocationTargetException e) { - OpenAudioLogger.toConsole("Error whilst passing packet to listener " + packetListener.getClass() + "#" + method.getName()); - e.printStackTrace(); + OpenAudioLogger.error(e, "Error whilst passing packet to listener " + packetListener.getClass() + "#" + method.getName()); } } } @@ -286,9 +284,7 @@ public void sendPacket(PacketPlayer packetPlayer, StandardPacket packet, boolean sendPluginMessage(packetPlayer, figureChannel(packet), packet.write().toByteArray()); } } catch (IOException e) { - OpenAudioLogger.handleException(e); - OpenAudioLogger.toConsole("Error whilst writing packet " + getClass().getSimpleName()); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to send packet/flush " + packet.getClass().getSimpleName()); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketWriter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketWriter.java index 9f871deaa..412824682 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketWriter.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/PacketWriter.java @@ -27,8 +27,7 @@ public PacketWriter(StandardPacket packet){ try { dataOutputStream.writeUTF(packet.getClass().getName()); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to write packet class name to packet"); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/implementations/BungeeCordPacketManager.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/implementations/BungeeCordPacketManager.java index e97e300bd..38ce06ce7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/implementations/BungeeCordPacketManager.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/messages/implementations/BungeeCordPacketManager.java @@ -30,7 +30,7 @@ public BungeeCordPacketManager(Plugin bungeePlugin, String channel){ protected void sendPluginMessage(PacketPlayer packetPlayer, String channel, byte[] bytes) { if (packetPlayer.getBungeePlayer().getServer() == null) { if (OpenAudioMc.BUILD.IS_TESTING) { - OpenAudioLogger.toConsole("Couldn't send bungee packet because the user moved"); + OpenAudioLogger.warn("Couldn't send bungee packet because the user isn't on a server"); } return; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/RestDirectService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/RestDirectService.java index 8a3bb33fb..6811958b8 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/RestDirectService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/RestDirectService.java @@ -51,7 +51,7 @@ public RestDirectService(AuthenticationService authenticationService) { public void boot() { // is it enabled? if (!StorageKey.CDN_ENABLED.getBoolean()) { - OpenAudioLogger.toConsole("CDN is disabled, skipping boot"); + OpenAudioLogger.info("The legacy cdn exporter is disabled, skipping boot."); return; } @@ -64,8 +64,7 @@ public void boot() { try { attemptServerBoot(); } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to start a cdn injector, falling back to http"); - OpenAudioLogger.toConsole("Error: " + e.getMessage()); + OpenAudioLogger.error(e, "Failed to start a cdn injector."); } } @@ -76,7 +75,7 @@ public RestDirectServer attemptServerBoot() { } if (StorageKey.CDN_IP_OVERWRITE.getString() != null && !StorageKey.CDN_IP_OVERWRITE.getString().equals("none")) { - OpenAudioLogger.toConsole("Attempting to use IP overwrite with " + StorageKey.CDN_IP_OVERWRITE.getString()); + OpenAudioLogger.info("Attempting to use IP overwrite with " + StorageKey.CDN_IP_OVERWRITE.getString()); ip = StorageKey.CDN_IP_OVERWRITE.getString(); } @@ -85,7 +84,7 @@ public RestDirectServer attemptServerBoot() { String verificationString = UUID.randomUUID().toString(); try { int timeout = StorageKey.CDN_TIMEOUT.getInt(); - OpenAudioLogger.toConsole("Attempting to start a cdn injector at port " + port + ". Timeout=" + timeout+"-seconds"); + OpenAudioLogger.info("Attempting to start a cdn injector at port " + port + ". Timeout=" + timeout+"-seconds"); RestDirectServer restDirectServer = new RestDirectServer(port, verificationString, this); // it booted! wow, that's, surprising actually // now verify it @@ -107,7 +106,7 @@ public RestDirectServer attemptServerBoot() { if (request.hasError()) { restDirectServer.stop(); - OpenAudioLogger.toConsole("The direct rest registration failed"); + OpenAudioLogger.warn("The direct rest registration failed"); return null; } @@ -119,7 +118,7 @@ public RestDirectServer attemptServerBoot() { e.printStackTrace(); } } - OpenAudioLogger.toConsole("Continuing without the RestDirect feature! None of the listed ports were accessible or available. Please contact support, your server/host might not be compatible!"); + OpenAudioLogger.info("Continuing without the RestDirect feature! None of the listed ports were accessible or available. Please contact support, your server/host might not be compatible!"); return null; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/ports/PortChecker.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/ports/PortChecker.java index 399616797..ded2ab07f 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/ports/PortChecker.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/ports/PortChecker.java @@ -36,12 +36,12 @@ public String url() { public PortCheckResponse test(String expectedResponse) { if (StorageKey.CDN_SKIP_VALIDATION.getBoolean()) { - OpenAudioLogger.toConsole("Was going to check if the cdn was running at " + url() + " but it was skipped by the config"); + OpenAudioLogger.warn("Was going to check if the cdn was running at " + url() + " but it was skipped by the config"); return PortCheckResponse.MATCH; } // anything goes on a test server lol - OpenAudioLogger.toConsole("Attaching cdn host to " + url()); + OpenAudioLogger.info("Attaching cdn host to " + url()); if (OpenAudioMc.SERVER_ENVIRONMENT == ServerEnvironment.DEVELOPMENT) { return PortCheckResponse.MATCH; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/routes/TokenInvalidateRoute.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/routes/TokenInvalidateRoute.java index 65aa5b9e9..2501577cb 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/routes/TokenInvalidateRoute.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rd/routes/TokenInvalidateRoute.java @@ -39,7 +39,7 @@ public HttpResponse onRequest(NanoHTTPD.IHTTPSession session) { } // ready save to do the thing - OpenAudioLogger.toConsole(cc.getUser().getName() + " activated a streamer mode reset"); + OpenAudioLogger.info(cc.getUser().getName() + " activated a streamer mode reset"); OpenAudioMc.getService(AuthenticationService.class).getDriver().removePlayerFromCache(clientUuid); cc.setAuth(new TokenFactory().build(cc)); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisChannelListener.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisChannelListener.java index 509cd18cf..d0a2029b0 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisChannelListener.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisChannelListener.java @@ -20,8 +20,7 @@ public RedisChannelListener() { sacreficcialPlayerPackets.put(value, value.getPacketClass().getConstructor().newInstance()); channelNameMap.put(value.getRedisChannelName(), value); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to create packet instance for " + value.name()); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisService.java index 630c7751b..cc4336281 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/RedisService.java @@ -81,7 +81,7 @@ public void onEnable() { if (!Configuration.getBoolean(StorageKey.REDIS_ENABLED)) return; enabled = true; - OpenAudioLogger.toConsole("Enabling redis service.."); + OpenAudioLogger.info("Enabling redis service.."); // Read Redis password final String redisPass = Configuration.getString(StorageKey.REDIS_PASSWORD); @@ -105,7 +105,7 @@ public void onEnable() { uri = builder.build(); } - OpenAudioLogger.toConsole("Connecting to redis server: " + uri.toString()); + OpenAudioLogger.info("Connecting to redis server: " + uri.toString()); // set up listener redisSub = RedisClient.create(uri); @@ -130,7 +130,7 @@ public void onEnable() { // enable command OpenAudioMc.getService(CommandService.class).registerSubCommands(CommandContext.OPENAUDIOMC, new RedisSubCommand(this)); - OpenAudioLogger.toConsole("Enabled redis service!"); + OpenAudioLogger.info("Enabled redis service!"); } public void sendMessage(ChannelKey key, OARedisPacket packet) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/packets/adapter/RedisTypeAdapter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/packets/adapter/RedisTypeAdapter.java index 30429716b..69e8b4f3f 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/packets/adapter/RedisTypeAdapter.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/redis/packets/adapter/RedisTypeAdapter.java @@ -54,7 +54,7 @@ public void handle(OARedisPacket received) { orp.setSenderUUID(UUID.fromString(senderUuid)); return orp; } catch (ClassNotFoundException cnfe) { - OpenAudioLogger.handleException(cnfe); + OpenAudioLogger.warn("Failed to adapt packet type " + type); throw new JsonParseException("Unknown element type: " + type, cnfe); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/ExternalResourceLoader.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/ExternalResourceLoader.java index 4c7e7011a..3eed47c67 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/ExternalResourceLoader.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/ExternalResourceLoader.java @@ -22,7 +22,7 @@ public ExternalResourceLoader(ClassLoader loaderClassLoader, File jarResourcePat String u = url.toString(); String[] parts = u.split(File.separator); String fn = parts[parts.length - 1]; - OpenAudioLogger.toConsole("Loading runtime resource " + fn); + OpenAudioLogger.info("Loading runtime resource " + fn); addJarToClasspath(url); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/RuntimeDependencyService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/RuntimeDependencyService.java index 87d6315a5..ef39c10a9 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/RuntimeDependencyService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/resources/RuntimeDependencyService.java @@ -25,12 +25,12 @@ public void load(JarSource source) throws MalformedURLException { // check if its already loaded for (LoadedDependency loadedDependency : loadedDependencies) { if (loadedDependency.getSource().getFileName().equals(source.getFileName())) { - OpenAudioLogger.toConsole("WARNING! Skipping resource " + source.getFileName() + " because it's already loaded"); + OpenAudioLogger.warn("Skipping resource " + source.getFileName() + " because it's already loaded"); return; } } // load and register - OpenAudioLogger.toConsole("Loading resource " + source.getFileName()); + OpenAudioLogger.info("Loading resource " + source.getFileName()); // download, mock this for now and just do it locally File magicallyHere = new File(MagicValue.STORAGE_DIRECTORY.get(File.class), "libs" + File.separator + source.getFileName()); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rest/RestRequest.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rest/RestRequest.java index 5e76b3089..ae58e9967 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/rest/RestRequest.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/rest/RestRequest.java @@ -171,7 +171,7 @@ private HttpRes preformRequest() { } if (OpenAudioMc.SERVER_ENVIRONMENT == ServerEnvironment.DEVELOPMENT) { - OpenAudioLogger.toConsole("Running in development mode, disabling SSL verification"); + OpenAudioLogger.warn("Running in development mode, disabling SSL verification"); clientBuilder = ignore(clientBuilder); } client = clientBuilder.build(); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/Service.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/Service.java index cdc5d51da..36eef5a35 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/Service.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/Service.java @@ -12,7 +12,7 @@ public void onDisable() { } public void log(String s) { - OpenAudioLogger.toConsole(getClass().getSimpleName() + ": " + s); + OpenAudioLogger.info(getClass().getSimpleName() + ": " + s); } public T getService(Class s) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/ServiceManager.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/ServiceManager.java index 09d9ba24d..5c6b4b926 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/ServiceManager.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/service/ServiceManager.java @@ -63,9 +63,9 @@ public Service loadService(Class target) { field.set(i, v); } else { if (v == null) { - OpenAudioLogger.toConsole("Field " + field.getName() + " in " + target.getSimpleName() + " is null, this is probably a bug"); + OpenAudioLogger.warn("Field " + field.getName() + " in " + target.getSimpleName() + " is null, this is probably a bug"); } else { - OpenAudioLogger.toConsole("WARNING! field " + field.getName() + " in " + target.getSimpleName() + " doesn't have the inject annotation, but it was resolved as " + v.getClass().getName()); + OpenAudioLogger.warn("field " + field.getName() + " in " + target.getSimpleName() + " doesn't have the inject annotation, but it was resolved as " + v.getClass().getName()); } } } @@ -75,7 +75,7 @@ public Service loadService(Class target) { i.onEnable(); return i; } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to load service: " + target.getName()); + OpenAudioLogger.warn("Failed to load service: " + target.getName() + " - " + e.getMessage()); throw e; } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java index 2f31861a7..73eab40a5 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java @@ -57,7 +57,7 @@ public void setState(State state) { EventApi.getInstance().callEvent(new StateChangeEvent(currentState, state)); if (StorageKey.DEBUG_LOG_STATE_CHANGES.getBoolean()) { - OpenAudioLogger.toConsole("Updating state to: " + state.getClass().getSimpleName() + " - " + state.getDescription()); + OpenAudioLogger.debug("Updating state to: " + state.getClass().getSimpleName() + " - " + state.getDescription(), 1); } this.currentState = state; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/utils/data/TemporalFaker.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/utils/data/TemporalFaker.java index 8a353eacc..7c869bfad 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/utils/data/TemporalFaker.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/utils/data/TemporalFaker.java @@ -28,7 +28,7 @@ public long getLong(TemporalField field) { if (field == INSTANT_SECONDS) { return seconds; } - OpenAudioLogger.toConsole("Invalid invocation to TemporalFaker getLong with field " + field.getDisplayName(Locale.US)); + OpenAudioLogger.warn("Invalid invocation to TemporalFaker getLong with field " + field.getDisplayName(Locale.US)); return 0; } @@ -37,7 +37,7 @@ public int get(TemporalField field) { if (field == NANO_OF_SECOND) { return nanos; } - OpenAudioLogger.toConsole("Invalid invocation to TemporalFaker get with field " + field.getDisplayName(Locale.US)); + OpenAudioLogger.warn("Invalid invocation to TemporalFaker get with field " + field.getDisplayName(Locale.US)); return 0; } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java index b3bf1f31a..8feeb116c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java @@ -121,9 +121,9 @@ public void start(String server, String password, int slots) { // start? boolean success = voiceWebsocket.start(); if (success) { - OpenAudioLogger.toConsole("Attempting to login to voice chat..."); + OpenAudioLogger.info("Attempting to login to voice chat..."); } else { - OpenAudioLogger.toConsole("Failed to initialize voice events."); + OpenAudioLogger.warn("Failed to initialize voice events."); status = VoiceApiStatus.IDLE; } }); @@ -147,16 +147,17 @@ private void onWsClose() { for (ClientConnection client : OpenAudioMc.getService(NetworkingService.class).getClients()) { if (client.getRtcSessionManager().isReady()) { client.getUser().sendMessage(Platform.translateColors(StorageKey.MESSAGE_VC_UNSTABLE.getString())); - client.kick(() -> {}); + client.kick(() -> { + OpenAudioLogger.warn("Kicked " + client.getUser().getName() + " because the voicechat connection was lost"); + }); } } - OpenAudioLogger.toConsole("Expected voicechat shut down."); } private void onWsOpen() { if (status == VoiceApiStatus.CONNECTED) return; Thread.currentThread().setName("OaVoiceAPI"); - OpenAudioLogger.toConsole("Connected to voicechat!"); + OpenAudioLogger.info("VoiceChat prepared and connected!"); status = VoiceApiStatus.CONNECTED; // seed online players pushEvent(VoiceServerEventType.HEARTBEAT, EMPTY_PAYLOAD); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceWebsocket.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceWebsocket.java index 17d6601e7..49196c3fd 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceWebsocket.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceWebsocket.java @@ -46,7 +46,7 @@ public boolean start() { // denied if (preAuthCheck.hasError()) { - OpenAudioLogger.toConsole("Failed to login to RTC, error: " + preAuthCheck.getError().getMessage()); + OpenAudioLogger.warn("Failed to login to RTC, error: " + preAuthCheck.getError().getMessage()); return false; } @@ -88,7 +88,7 @@ public void pushEventBody(String event) { @Override public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) { if (code != 1000) { - OpenAudioLogger.toConsole("RTC connection closed with code " + code + " and reason " + reason); + OpenAudioLogger.warn("RTC connection closed with code " + code + " and reason " + reason); } handleError(); } @@ -96,7 +96,7 @@ public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String rea @Override public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String reason) { if (code != 1000) { - OpenAudioLogger.toConsole("Voicechat ws closing: " + reason + " - " + code); + OpenAudioLogger.warn("Voicechat ws closing: " + reason + " - " + code); } handleError(); } @@ -105,7 +105,7 @@ public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String re public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nullable Response response) { String nullableMessage = ""; if (response != null) nullableMessage = response.message(); - OpenAudioLogger.toConsole("Voicechat ws error: " + t.getMessage() + " - " + nullableMessage); + OpenAudioLogger.warn("Voicechat ws error: " + t.getMessage() + " - " + nullableMessage); handleError(); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/OpenAudioMcSpigot.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/OpenAudioMcSpigot.java index 5f6d5152c..6dc1bf217 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/OpenAudioMcSpigot.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/OpenAudioMcSpigot.java @@ -4,14 +4,14 @@ import com.craftmend.openaudiomc.api.impl.RegistryApiImpl; import com.craftmend.openaudiomc.api.interfaces.AudioApi; import com.craftmend.openaudiomc.generic.environment.MagicValue; -import com.craftmend.openaudiomc.generic.logging.platform.SpigotLogger; +import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; +import com.craftmend.openaudiomc.generic.logging.platform.GenericLogAdapter; import com.craftmend.openaudiomc.generic.proxy.SpigotUserHooks; import com.craftmend.openaudiomc.generic.proxy.interfaces.UserHooks; import com.craftmend.openaudiomc.generic.state.StateService; import com.craftmend.openaudiomc.generic.storage.interfaces.Configuration; import com.craftmend.openaudiomc.generic.platform.interfaces.TaskService; import com.craftmend.openaudiomc.generic.platform.interfaces.OpenAudioInvoker; -import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; import com.craftmend.openaudiomc.generic.platform.Platform; import com.craftmend.openaudiomc.generic.state.states.WorkerState; @@ -81,10 +81,10 @@ public void onEnable() { MagicValue.loadArguments(); // set logger - OpenAudioLogger.setLogger(new SpigotLogger(this)); + OpenAudioLogger.setLogAdapter(new GenericLogAdapter(getLogger())); if (MagicValue.PLATFORM_FORCE_LATE_FIND.get(Boolean.class) != null && MagicValue.PLATFORM_FORCE_LATE_FIND.get(Boolean.class) && !bound) { - OpenAudioLogger.toConsole("Using late bind! not doing anything for now..."); + OpenAudioLogger.warn("Using late bind! not doing anything for now..."); bound = true; return; } @@ -136,12 +136,11 @@ public void onEnable() { // timing end and calc Instant finish = Instant.now(); - OpenAudioLogger.toConsole("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS"); + OpenAudioLogger.info("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS"); OpenAudioMc.getInstance().postBoot(); } catch (Exception e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "A fatal error occurred while enabling OpenAudioMc. The plugin will now disable itself."); Bukkit.getServer().getPluginManager().disablePlugin(this); } } @@ -151,12 +150,12 @@ public void onEnable() { */ @Override public void onDisable() { - OpenAudioLogger.toConsole("Shutting down"); + OpenAudioLogger.info("Shutting down"); OpenAudioMc.getService(SpigotPlayerService.class).onDisable(); OpenAudioMc.getService(PredictiveMediaService.class).onDisable(); openAudioMc.disable(); HandlerList.unregisterAll(this); - OpenAudioLogger.toConsole("Stopped OpenAudioMc. Goodbye."); + OpenAudioLogger.info("Stopped OpenAudioMc. Goodbye."); } public void registerEvents(Listener... listeners) { @@ -185,12 +184,12 @@ public Class getServiceClass() { // check if there's a forced service Class forced = ((RegistryApiImpl) AudioApi.getInstance().getRegistryApi()).getForcedService(); if (forced != null) { - OpenAudioLogger.toConsole("Using forced networking class " + forced.getName()); + OpenAudioLogger.warn("Using forced networking class " + forced.getName()); return forced; } proxyModule.refresh(); - OpenAudioLogger.toConsole("Using networking class " + proxyModule.getMode().getServiceClass().getName()); + OpenAudioLogger.info("Using networking class " + proxyModule.getMode().getServiceClass().getName()); return proxyModule.getMode().getServiceClass(); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/subcommands/voice/VoiceModSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/subcommands/voice/VoiceModSubCommand.java index 6ab9e5a7e..ee6c6bc2a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/subcommands/voice/VoiceModSubCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/subcommands/voice/VoiceModSubCommand.java @@ -32,11 +32,11 @@ public void onExecute(User sender, String[] args) { if (!client.getSession().isModerating()) { client.setModerating(true); - OpenAudioLogger.toConsole(sender.getName() + " started moderating"); + OpenAudioLogger.info(sender.getName() + " started moderating"); bcToStaff(sender.getName() + " started moderating"); } else { client.setModerating(false); - OpenAudioLogger.toConsole(sender.getName() + " stopped moderating"); + OpenAudioLogger.info(sender.getName() + " stopped moderating"); bcToStaff(sender.getName() + " stopped moderating"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/configuration/SpigotConfiguration.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/configuration/SpigotConfiguration.java index 71981cd06..d29d52f0f 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/configuration/SpigotConfiguration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/configuration/SpigotConfiguration.java @@ -34,12 +34,12 @@ public SpigotConfiguration(OpenAudioMcSpigot openAudioMcSpigot) { loadConfig(openAudioMcSpigot); - OpenAudioLogger.toConsole("Starting configuration module"); + OpenAudioLogger.info("Starting configuration module"); this.loadSettings(); } public void loadConfig(OpenAudioMcSpigot openAudioMcSpigot) { - OpenAudioLogger.toConsole("Using the main config file.."); + OpenAudioLogger.info("Using the main config file.."); openAudioMcSpigot.saveDefaultConfig(); mainConfig = openAudioMcSpigot.getConfig(); } @@ -299,8 +299,7 @@ public void saveAll(boolean includeConfig) { } dataConfig.save("plugins"+ File.separator + "OpenAudioMc" + File.separator + "data.yml"); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to save config/data"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/players/objects/SpigotPlayerSelector.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/players/objects/SpigotPlayerSelector.java index 5a03056a5..91e8dfda3 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/players/objects/SpigotPlayerSelector.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/players/objects/SpigotPlayerSelector.java @@ -132,7 +132,7 @@ else if (selector.length() <= 16) { } else { //you fucked it - OpenAudioLogger.toConsole("Invalid player query. Try something like @a, @p, username or other arguments."); + OpenAudioLogger.warn("Invalid player query. Try something like @a, @p, username or other arguments."); commandSender.sendMessage("Invalid player query. Try something like @a, @p, username or other arguments."); } return players; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/playlists/PlaylistService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/playlists/PlaylistService.java index 882729707..37ad74e5c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/playlists/PlaylistService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/playlists/PlaylistService.java @@ -50,7 +50,7 @@ public void saveAll() { // delete entries for (PlaylistEntry deletedEntry : value.getDeletedEntries()) { playlistEntryRepository.delete(deletedEntry); - OpenAudioLogger.toConsole("Deleted entry " + deletedEntry.getId() + " from playlist " + value.getName()); + OpenAudioLogger.warn("Deleted entry " + deletedEntry.getId() + " from playlist " + value.getName()); } value.getDeletedEntries().clear(); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/predictive/PredictiveMediaService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/predictive/PredictiveMediaService.java index 4c77f6c4f..b85974eeb 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/predictive/PredictiveMediaService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/predictive/PredictiveMediaService.java @@ -49,7 +49,7 @@ public void onEnable() { try { loadFromFile(); } catch (IOException e) { - OpenAudioLogger.toConsole("Failed to load chunk-cache from file."); + OpenAudioLogger.warn("Failed to load chunk-cache from file."); } } @@ -68,7 +68,7 @@ public void loadFromFile() throws IOException { public void onDisable() { // save - OpenAudioLogger.toConsole("Saving world cache..."); + OpenAudioLogger.info("Saving world cache..."); Repository repo = databaseService.getRepository(StoredWorldChunk.class); for (Map.Entry entry : chunkMapSerializer.serialize(chunkTracker).getData().entrySet()) { String name = entry.getKey(); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java index 71a16d209..f706841f2 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java @@ -18,7 +18,7 @@ public void onLoad(String pluginName, Plugin plugin) { User user = ((Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials")).getUser(event.getClient().getActor().getUniqueId()); if (user == null) return; if (user.isMuted()) { - OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on Essentials"); + OpenAudioLogger.warn("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on Essentials"); event.setCancelled(true); } }); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java index 75d70bb2b..b51b3fcfe 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java @@ -15,7 +15,7 @@ public void onLoad(String pluginName, Plugin plugin) { EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> { boolean isMuted = Database.get().isPlayerMuted(event.getClient().getActor().getUniqueId(), null); if (isMuted) { - OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on LiteBans"); + OpenAudioLogger.warn("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on LiteBans"); event.setCancelled(true); } }); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/regions/RegionModule.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/regions/RegionModule.java index a7004fdad..8fe3688d7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/regions/RegionModule.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/regions/RegionModule.java @@ -39,14 +39,14 @@ public class RegionModule { @Getter private Set regionsWithoutWorld = new HashSet<>(); public RegionModule(@Nullable AbstractRegionAdapter customAdapter) { - OpenAudioLogger.toConsole("Turns out you have WorldGuard installed! enabling regions and the region tasks.."); + OpenAudioLogger.info("Turns out you have WorldGuard installed! enabling regions and the region tasks.."); if (customAdapter == null) { if (OpenAudioMc.getService(ServerService.class).getVersion() == ServerVersion.MODERN) { - OpenAudioLogger.toConsole("Enabling the newer 1.13 regions"); + OpenAudioLogger.info("Enabling the newer 1.13 regions"); regionAdapter = new ModernRegionAdapter(this); } else { - OpenAudioLogger.toConsole("Unknown version. Falling back to the 1.8 to 1.12 region implementation."); + OpenAudioLogger.warn("Unknown version. Falling back to the 1.8 to 1.12 region implementation."); regionAdapter = new LegacyRegionAdapter(this); } } else { @@ -59,7 +59,7 @@ public RegionModule(@Nullable AbstractRegionAdapter customAdapter) { try { Class.forName("com.sk89q.worldguard.bukkit.WGBukkit"); } catch (ClassNotFoundException e) { - OpenAudioLogger.toConsole("Wrong world guard detection! re-switching to 1.13"); + OpenAudioLogger.warn("Wrong world guard detection! re-switching to 1.13"); regionAdapter = new ModernRegionAdapter(this); } } @@ -126,7 +126,7 @@ private void cleanDuplicates() { Collection allRegions = OpenAudioMc.getService(DatabaseService.class).getRepository(RegionProperties.class).values(); int totalCount = OpenAudioMc.getService(DatabaseService.class).getRepository(RegionProperties.class).count(); - OpenAudioLogger.toConsole("Scanning " + allRegions.size() + " regions for duplicates (out of " + totalCount + " total regions)"); + OpenAudioLogger.info("Scanning " + allRegions.size() + " regions for duplicates (out of " + totalCount + " total regions)"); //loop through all regions for (RegionProperties region : allRegions) { @@ -190,21 +190,20 @@ private void cleanDuplicates() { } if (discardedRegions.isEmpty()) { - OpenAudioLogger.toConsole("No duplicate regions found, skipping cleanup..."); + OpenAudioLogger.info("No duplicate regions found, skipping cleanup..."); return; } - OpenAudioLogger.toConsole("Found " + discardedRegions.size() + " duplicate regions with old ID's, making a backup and then cleaning up..."); + OpenAudioLogger.warn("Found " + discardedRegions.size() + " duplicate regions with old ID's, making a backup and then cleaning up..."); OpenAudioMc.getService(BackupService.class).makeBackup(true); // remove all old regions for (RegionProperties discardedRegion : discardedRegions) { - OpenAudioLogger.toConsole("Removing region " + discardedRegion.getRegionName() + " with ID " + discardedRegion.getId()); + OpenAudioLogger.info("Removing region " + discardedRegion.getRegionName() + " with ID " + discardedRegion.getId()); try { OpenAudioMc.getService(DatabaseService.class).getRepository(RegionProperties.class).delete(discardedRegion); } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to remove region " + discardedRegion.getRegionName() + " with ID " + discardedRegion.getId()); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to remove region " + discardedRegion.getRegionName() + " with ID " + discardedRegion.getId()); } } } @@ -258,8 +257,7 @@ public int mutateForMatchingWorld(RegionMutator mutator, String regionName, Stri mutator.feed(region, media); changedCount++; } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to mutate region " + regionName + " in world " + world); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to mutate region " + regionName + " in world " + world); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/shortner/AliasService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/shortner/AliasService.java index 09e787918..56a99a3d0 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/shortner/AliasService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/shortner/AliasService.java @@ -7,7 +7,6 @@ import com.craftmend.openaudiomc.generic.service.Service; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot; -import com.craftmend.openaudiomc.spigot.modules.regions.objects.RegionProperties; import com.craftmend.openaudiomc.spigot.modules.shortner.data.Alias; import com.craftmend.openaudiomc.spigot.modules.shortner.middleware.AliasMiddleware; import lombok.Getter; @@ -30,7 +29,7 @@ public class AliasService extends Service { public String translate(String name) { Alias target = aliasMap.get(name.toLowerCase()); if (target == null) { - OpenAudioLogger.toConsole("Warning! The alias '" + name + "' was used but doesn't have a source attached to it"); + OpenAudioLogger.warn("The alias '" + name + "' was used but doesn't have a source attached to it"); return name; } return target.getTarget(); @@ -38,7 +37,7 @@ public String translate(String name) { @Override public void onEnable() { - OpenAudioLogger.toConsole("Loading aliases..."); + OpenAudioLogger.info("Loading aliases..."); OpenAudioMc.getService(MediaService.class).registerMutation("a:", new AliasMiddleware(this)); //load config @@ -69,6 +68,6 @@ public void onEnable() { OpenAudioMc.getService(DatabaseService.class).getRepository(Alias.class).delete(removeable); } - OpenAudioLogger.toConsole("Loaded " + aliasMap.size() + " aliases"); + OpenAudioLogger.info("Loaded " + aliasMap.size() + " aliases"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/objects/Show.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/objects/Show.java index d9d66816c..e72e8c65e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/objects/Show.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/objects/Show.java @@ -138,8 +138,7 @@ public Show save() { writer.flush(); writer.close(); } catch (IOException x) { - OpenAudioLogger.handleException(x); - System.err.format("IOException: %s%n", x); + OpenAudioLogger.error(x, "Failed to save show " + showName); } return this; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/SpeakerService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/SpeakerService.java index 1f27bdf67..c034a30b4 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/SpeakerService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/SpeakerService.java @@ -79,7 +79,7 @@ public void onEnable() { if (StorageKey.SETTINGS_SPEAKER_REDSTONE_TICK_ENABLED.getBoolean()) { int interval = StorageKey.SETTINGS_SPEAKER_REDSTONE_TICK_INTERVAL.getInt(); - OpenAudioLogger.toConsole("Starting redstone speaker tick task with interval " + interval + " ticks"); + OpenAudioLogger.info("Starting redstone speaker tick task with interval " + interval + " ticks"); Bukkit.getScheduler().scheduleAsyncRepeatingTask(OpenAudioMcSpigot.getInstance(), () -> { for (Speaker speaker : speakerMap.values()) { @@ -116,7 +116,7 @@ public void onEnable() { } }, interval, interval); } else { - OpenAudioLogger.toConsole("Redstone speaker tick task is disabled"); + OpenAudioLogger.info("Redstone speaker tick task is disabled"); } } @@ -129,21 +129,21 @@ private void initializeVersion() { version = OpenAudioMc.getService(ServerService.class).getVersion(); if (version == ServerVersion.MODERN) { - OpenAudioLogger.toConsole("Enabling the 1.13 speaker system"); + OpenAudioLogger.info("Enabling the 1.13 speaker system"); playerSkullItem = Material.PLAYER_HEAD; playerSkullBlock = Material.PLAYER_HEAD; } else { - OpenAudioLogger.toConsole("Enabling the 1.12 speaker system"); + OpenAudioLogger.info("Enabling the 1.12 speaker system"); try { - OpenAudioLogger.toConsole("Hooking speakers attempt 1.."); + OpenAudioLogger.info("Hooking speakers attempt 1.."); playerSkullItem = Material.valueOf("SKULL_ITEM"); playerSkullBlock = Material.valueOf("SKULL"); } catch (Exception e) { - OpenAudioLogger.toConsole("Failed hook speakers attempt 1.."); + OpenAudioLogger.info("Failed hook speakers attempt 1.."); } if (playerSkullItem == null) { - OpenAudioLogger.toConsole("Speakers failed to hook. Hooking to a block."); + OpenAudioLogger.info("Speakers failed to hook. Hooking to a block."); playerSkullItem = Material.JUKEBOX; playerSkullBlock = Material.JUKEBOX; } @@ -152,7 +152,7 @@ private void initializeVersion() { public Speaker registerSpeaker(Speaker speaker) { if (speaker.getLocation() == null) { - OpenAudioLogger.toConsole("WARNING! Registering speaker with nil location " + speaker.getSpeakerId()); + OpenAudioLogger.warn("Registering speaker with nil location " + speaker.getSpeakerId()); } speakerMap.put(speaker.getLocation(), speaker); return speaker; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java index 684c69502..b9df3b271 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/tasks/SpeakerGarbageCollection.java @@ -30,7 +30,7 @@ public SpeakerGarbageCollection(SpeakerService speakerService) { runTaskTimer(OpenAudioMcSpigot.getInstance(), 600, 600); OpenAudioMc.resolveDependency(TaskService.class).scheduleAsyncRepeatingTask(() -> { if (PROCESSED_SPEAKERS != 0) { - OpenAudioLogger.toConsole("The garbage collector found and processed " + PROCESSED_SPEAKERS + " broken speakers"); + OpenAudioLogger.info("The garbage collector found and processed " + PROCESSED_SPEAKERS + " broken speakers"); PROCESSED_SPEAKERS = 0; } }, 20 * 30, 20 * 30); @@ -63,7 +63,7 @@ public void run() { .forEach(speaker -> { MappedLocation mappedLocation = speaker.getLocation(); if (mappedLocation == null) { - OpenAudioLogger.toConsole("A speaker doesn't have a location, terminating"); + OpenAudioLogger.warn("A speaker doesn't have a location, terminating"); remove(speaker); return; } @@ -71,14 +71,14 @@ public void run() { // check if the chunk is loaded, if not, don't do shit lmao Location bukkitLocation = mappedLocation.toBukkit(); if (bukkitLocation == null || bukkitLocation.getWorld() == null) { - OpenAudioLogger.toConsole("Can't find world " + mappedLocation.getWorld() + " so speaker " + speaker.getSpeakerId() + " is being deleted"); + OpenAudioLogger.warn("Can't find world " + mappedLocation.getWorld() + " so speaker " + speaker.getSpeakerId() + " is being deleted"); remove(speaker); } else if (bukkitLocation.getChunk().isLoaded() || forceRun) { if (forceRun && !bukkitLocation.getChunk().isLoaded()) { - OpenAudioLogger.toConsole("Attempting to load chunk " + bukkitLocation.getChunk().toString() + " for a forced speaker check..."); + OpenAudioLogger.info("Attempting to load chunk " + bukkitLocation.getChunk().toString() + " for a forced speaker check..."); bukkitLocation.getChunk().load(); if (!bukkitLocation.getChunk().isLoaded()) { - OpenAudioLogger.toConsole("Failed to load chunk! please try again later..."); + OpenAudioLogger.warn("Failed to load chunk! please try again later..."); } return; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java index e7aec1bdb..55eda23ce 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java @@ -34,7 +34,7 @@ public class SpeakerUtils { .addReturnValue("getName", speakerSkin) .createProxy(); } catch (Exception e) { - OpenAudioLogger.toConsole("Failed to create a OfflinePlayer proxy class. This will cause issues with speakers on servers running post 1.20.2"); + OpenAudioLogger.warn("Failed to create a OfflinePlayer proxy class. This will cause issues with speakers on servers running post 1.20.2"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java index 7bc51873e..c539acbfb 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java @@ -182,17 +182,17 @@ public void onEnable() { // enable default rules if (StorageKey.SETTINGS_VOICE_FILTERS_GAMEMODE.getBoolean()) { - OpenAudioLogger.toConsole("Enabling voicechat gamemode filter"); + OpenAudioLogger.info("Enabling voicechat gamemode filter"); getService(FilterService.class).addCustomFilter(new GamemodeFilterCustom()); } if (StorageKey.SETTINGS_VOICE_FILTERS_TEAM.getBoolean()) { - OpenAudioLogger.toConsole("Enabling voicechat team filter"); + OpenAudioLogger.info("Enabling voicechat team filter"); getService(FilterService.class).addCustomFilter(new TeamFilterCustom()); } if (StorageKey.SETTINGS_VOICE_FILTERS_CHANNEL.getBoolean()) { - OpenAudioLogger.toConsole("Enabling voicechat channel filter"); + OpenAudioLogger.info("Enabling voicechat channel filter"); getService(FilterService.class).addCustomFilter(new PlayerInChannelFilter(networkingService)); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java index b32bb9204..56564409a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java @@ -52,12 +52,12 @@ public VoiceChannelService( // load static channels try { if (!StorageKey.SETTINGS_STATIC_CHANNELS_ENABLED.getBoolean()) { - OpenAudioLogger.toConsole("Static voice channels are disabled, skipping load.."); + OpenAudioLogger.info("Static voice channels are disabled, skipping load.."); return; } int loaded = 0; - OpenAudioLogger.toConsole("Loading static voice channels.."); + OpenAudioLogger.info("Loading static voice channels.."); for (Map obj : StorageKey.SETTINGS_STATIC_CHANNELS_BASE.getObjectList()) { // check if its valid boolean valid = obj.containsKey("name") && obj.get("name") instanceof String @@ -65,8 +65,8 @@ public VoiceChannelService( && obj.containsKey("requirePermission") && obj.get("requirePermission") instanceof Boolean; if (!valid) { - OpenAudioLogger.toConsole("Failed to load a static voice channel, invalid configuration. Read:"); - OpenAudioLogger.toConsole(obj.toString()); + OpenAudioLogger.warn("Failed to load a static voice channel, invalid configuration. Read:"); + OpenAudioLogger.warn(obj.toString()); continue; } @@ -76,15 +76,14 @@ public VoiceChannelService( this ); channelMap.put(staticChannel.getName(), staticChannel); - OpenAudioLogger.toConsole("Created static channel: " + staticChannel.getName()); + OpenAudioLogger.info("Created static channel: " + staticChannel.getName()); loaded++; } - OpenAudioLogger.toConsole("Loaded " + loaded + " static voice channels"); + OpenAudioLogger.info("Loaded " + loaded + " static voice channels"); } catch (Exception e) { - e.printStackTrace(); - OpenAudioLogger.toConsole("Failed to load voice channels, see error above"); + OpenAudioLogger.error(e, "Failed to load voice channels"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/dependency/SpigotDependencyService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/dependency/SpigotDependencyService.java index 8bc9fd8c2..354c68618 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/dependency/SpigotDependencyService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/dependency/SpigotDependencyService.java @@ -30,7 +30,7 @@ public void onEnable() { public SpigotDependencyService ifPluginEnabled(String pluginName, DependencyHandler handler) { if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) { - OpenAudioLogger.toConsole("Plugin " + pluginName + " is already enabled, running handler"); + OpenAudioLogger.info("Plugin " + pluginName + " is already enabled, running handler"); try { handler.onLoad(pluginName, Bukkit.getPluginManager().getPlugin(pluginName)); } catch (Exception e) { @@ -48,7 +48,7 @@ public SpigotDependencyService ifPluginEnabled(String pluginName, DependencyHand public void onLoad(PluginEnableEvent enableEvent) { List handlers = handlerMap.getOrDefault(enableEvent.getPlugin().getName(), new ArrayList<>()); for (DependencyHandler handler : handlers) { - OpenAudioLogger.toConsole("Plugin " + enableEvent.getPlugin().getName() + " is now enabled, running handler"); + OpenAudioLogger.info("Plugin " + enableEvent.getPlugin().getName() + " is now enabled, running handler"); try { handler.onLoad(enableEvent.getPlugin().getName(), enableEvent.getPlugin()); } catch (Exception e) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/server/ServerService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/server/ServerService.java index 7c4f6290b..94b9e1d3e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/server/ServerService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/server/ServerService.java @@ -34,6 +34,6 @@ public void onEnable() { version = ServerVersion.MODERN; } - OpenAudioLogger.toConsole("Detected version type: " + version); + OpenAudioLogger.info("Detected version type: " + version); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java index ed37c4702..037272f60 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/services/threading/Executor.java @@ -36,8 +36,7 @@ public void start() { try { task.run(); } catch (Exception e) { - OpenAudioLogger.toConsole(getClass().getName() + " failed"); - OpenAudioLogger.toConsole(e.toString()); + OpenAudioLogger.error(e, "Failed to execute executor task"); } } Instant end = Instant.now(); @@ -61,8 +60,7 @@ public void start() { try { Thread.sleep(delayTime); } catch (InterruptedException e) { - OpenAudioLogger.handleException(e); - OpenAudioLogger.toConsole(e.getMessage()); + OpenAudioLogger.error(e, "Failed to sleep executor thread"); } } }); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java index f768e52d1..701f1ae0f 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/OpenAudioMcVelocity.java @@ -80,13 +80,13 @@ public void onProxyInit(ProxyInitializeEvent e) { // timing end and calc Instant finish = Instant.now(); - OpenAudioLogger.toConsole("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS"); + OpenAudioLogger.info("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS"); this.messageReceiver.registerListener(new CommandPacketListener()); OpenAudioMc.getInstance().postBoot(); } catch (Exception ex) { - ex.printStackTrace(); + OpenAudioLogger.error(ex, "Failed to start OpenAudioMc"); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/configuration/VelocityConfiguration.java b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/configuration/VelocityConfiguration.java index 5a4246690..8f0402ee1 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/configuration/VelocityConfiguration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/configuration/VelocityConfiguration.java @@ -34,7 +34,7 @@ public VelocityConfiguration() { dataConfig = getFile("data.yml"); mainConfig = getFile("config.yml"); - OpenAudioLogger.toConsole("Starting configuration module"); + OpenAudioLogger.info("Starting configuration module"); this.loadSettings(); } @@ -308,8 +308,7 @@ public void saveAll(boolean ignored) { .setFile(data) .build().save(dataConfig); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to save config files"); } } @@ -341,8 +340,7 @@ private ConfigurationNode getFile(String filename) { try { return yamlLoader.load(); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to load file " + filename); } return null; } @@ -357,8 +355,7 @@ private void saveDefaultFile(String filename, boolean hard) { try { Files.delete(file.toPath()); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to delete file " + filename); } } @@ -366,8 +363,7 @@ private void saveDefaultFile(String filename, boolean hard) { try (InputStream in = OpenAudioMcVelocity.getInstance().getClass().getClassLoader().getResourceAsStream(filename)) { Files.copy(in, file.toPath()); } catch (IOException e) { - OpenAudioLogger.handleException(e); - e.printStackTrace(); + OpenAudioLogger.error(e, "Failed to save default file " + filename); } } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/player/objects/VelocityPlayerSelector.java b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/player/objects/VelocityPlayerSelector.java index 508a78ac0..7fd1abed7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/player/objects/VelocityPlayerSelector.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/velocity/modules/player/objects/VelocityPlayerSelector.java @@ -69,7 +69,7 @@ private List getPlayers(CommandSource source) { return Collections.singletonList(player.get()); } else { //you fucked it - OpenAudioLogger.toConsole("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments."); + OpenAudioLogger.warn("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments."); source.sendMessage(Component.text("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments.")); } return players;