diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 9497e350e..237ca59fc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -23,7 +23,11 @@ import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.command.PlanCommand; import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.common.*; -import com.djrapitops.plan.modules.server.*; +import com.djrapitops.plan.modules.server.ServerAPIModule; +import com.djrapitops.plan.modules.server.ServerDataCacheModule; +import com.djrapitops.plan.modules.server.ServerDatabaseModule; +import com.djrapitops.plan.modules.server.ServerInfoSystemModule; +import com.djrapitops.plan.modules.server.bukkit.BukkitConfigModule; import com.djrapitops.plan.modules.server.bukkit.BukkitInfoModule; import com.djrapitops.plan.system.BukkitSystem; import com.djrapitops.plan.system.locale.Locale; @@ -56,7 +60,7 @@ import java.util.logging.Logger; APFModule.class, ExportModule.class, VersionCheckModule.class, - ServerConfigModule.class, + BukkitConfigModule.class, LocaleModule.class, BukkitInfoModule.class, ServerDatabaseModule.class, diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index 985fa5eed..f0dbe3151 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -8,9 +8,9 @@ import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.command.PlanBungeeCommand; import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.common.*; -import com.djrapitops.plan.modules.server.ServerConfigModule; import com.djrapitops.plan.modules.server.ServerDatabaseModule; import com.djrapitops.plan.modules.server.ServerInfoSystemModule; +import com.djrapitops.plan.modules.server.bukkit.BukkitConfigModule; import com.djrapitops.plan.system.BungeeSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.PluginLang; @@ -38,7 +38,7 @@ import java.io.InputStream; APFModule.class, ExportModule.class, VersionCheckModule.class, - ServerConfigModule.class, + BukkitConfigModule.class, LocaleModule.class, ServerDatabaseModule.class, WebServerSystemModule.class, diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java index 6555cdd7e..49063218b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanSponge.java @@ -4,7 +4,11 @@ import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.command.PlanCommand; import com.djrapitops.plan.modules.APFModule; import com.djrapitops.plan.modules.common.*; -import com.djrapitops.plan.modules.server.*; +import com.djrapitops.plan.modules.server.ServerAPIModule; +import com.djrapitops.plan.modules.server.ServerDataCacheModule; +import com.djrapitops.plan.modules.server.ServerDatabaseModule; +import com.djrapitops.plan.modules.server.ServerInfoSystemModule; +import com.djrapitops.plan.modules.server.bukkit.BukkitConfigModule; import com.djrapitops.plan.modules.server.sponge.SpongeInfoModule; import com.djrapitops.plan.system.SpongeSystem; import com.djrapitops.plan.system.locale.Locale; @@ -43,7 +47,7 @@ import java.io.InputStream; APFModule.class, ExportModule.class, VersionCheckModule.class, - ServerConfigModule.class, + BukkitConfigModule.class, LocaleModule.class, ServerDatabaseModule.class, ServerDataCacheModule.class, diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java index 58f094a85..cc548ce01 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java @@ -222,7 +222,7 @@ public class Session extends DataContainer implements DateHolder { } private String getLongestWorldPlayed() { - Map aliases = WorldAliasSettings.getAliases(); + Map aliases = WorldAliasSettings.getAliases_Old(); if (worldTimes == null) { return "No World Time Data"; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java index 1554528bb..d78ea39b9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java @@ -177,7 +177,7 @@ public class WorldTimes { entry -> entry.getValue().getTotal() // GMTimes.getTotal )); - Map aliases = WorldAliasSettings.getAliases(); + Map aliases = WorldAliasSettings.getAliases_Old(); Map playtimePerAlias = new HashMap<>(); for (Map.Entry entry : playtimePerWorld.entrySet()) { @@ -186,7 +186,7 @@ public class WorldTimes { if (!aliases.containsKey(worldName)) { aliases.put(worldName, worldName); - WorldAliasSettings.addWorld(worldName); + WorldAliasSettings.addWorld_Old(worldName); } String alias = aliases.get(worldName); diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/server/ServerConfigModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitConfigModule.java similarity index 76% rename from Plan/src/main/java/com/djrapitops/plan/modules/server/ServerConfigModule.java rename to Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitConfigModule.java index 0c34bf44f..b748729b4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/modules/server/ServerConfigModule.java +++ b/Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitConfigModule.java @@ -1,4 +1,4 @@ -package com.djrapitops.plan.modules.server; +package com.djrapitops.plan.modules.server.bukkit; import com.djrapitops.plan.system.settings.config.ConfigSystem; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -13,11 +13,11 @@ import dagger.Provides; * @author Rsl1122 */ @Module -public class ServerConfigModule { +public class BukkitConfigModule { @Provides - ConfigSystem provideConfigSystem() { - return new ServerConfigSystem(); + ConfigSystem provideConfigSystem(ServerConfigSystem serverConfigSystem) { + return serverConfigSystem; } @Provides diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeConfigModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeConfigModule.java new file mode 100644 index 000000000..195bcb00f --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeConfigModule.java @@ -0,0 +1,33 @@ +package com.djrapitops.plan.modules.server.sponge; + +import com.djrapitops.plan.system.settings.config.ConfigSystem; +import com.djrapitops.plan.system.settings.config.PlanConfig; +import com.djrapitops.plan.system.settings.config.SpongeConfigSystem; +import com.djrapitops.plan.system.settings.theme.Theme; +import dagger.Module; +import dagger.Provides; + +/** + * Dagger module for Bukkit Configuration. + * + * @author Rsl1122 + */ +@Module +public class SpongeConfigModule { + + @Provides + ConfigSystem provideConfigSystem(SpongeConfigSystem spongeConfigSystem) { + return spongeConfigSystem; + } + + @Provides + PlanConfig provideConfig(ConfigSystem configSystem) { + return configSystem.getConfig(); + } + + @Provides + Theme provideTheme(ConfigSystem configSystem) { + return configSystem.getTheme(); + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java index 82283bb43..5823a4f81 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/BukkitSystem.java @@ -30,16 +30,17 @@ import javax.inject.Inject; public class BukkitSystem extends PlanSystem implements ServerSystem { @Inject - public BukkitSystem(Plan plugin, - VersionCheckSystem versionCheckSystem, + public BukkitSystem(VersionCheckSystem versionCheckSystem, FileSystem fileSystem, ConfigSystem serverConfigSystem, InfoSystem serverInfoSystem, BukkitServerInfo serverInfo, + DBSystem serverDBSystem, + BukkitListenerSystem bukkitListenerSystem, + BukkitTaskSystem bukkitTaskSystem, + ExportSystem exportSystem, HookHandler hookHandler, PlanAPI planAPI, - ExportSystem exportSystem, - DBSystem serverDBSystem, ShutdownHook shutdownHook ) { this.versionCheckSystem = versionCheckSystem; @@ -47,8 +48,8 @@ public class BukkitSystem extends PlanSystem implements ServerSystem { this.configSystem = serverConfigSystem; this.exportSystem = exportSystem; this.databaseSystem = serverDBSystem; - listenerSystem = new BukkitListenerSystem(plugin); - taskSystem = new BukkitTaskSystem(plugin); + listenerSystem = bukkitListenerSystem; + taskSystem = bukkitTaskSystem; infoSystem = serverInfoSystem; this.serverInfo = serverInfo; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java index 786b98f71..a6e0e5b58 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/CacheSystem.java @@ -27,6 +27,7 @@ public class CacheSystem implements SubSystem { this.geolocationCache = geolocationCache; } + @Deprecated public static CacheSystem getInstance() { CacheSystem cacheSystem = PlanSystem.getInstance().getCacheSystem(); Verify.nullCheck(cacheSystem, () -> new IllegalStateException("Cache System was not initialized.")); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java index 4697d138b..b584d6407 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java @@ -22,6 +22,7 @@ public class SessionCache { private static final Map activeSessions = new HashMap<>(); + @Deprecated public static SessionCache getInstance() { SessionCache dataCache = CacheSystem.getInstance().getDataCache(); Verify.nullCheck(dataCache, () -> new IllegalStateException("Data Cache was not initialized.")); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/BukkitListenerSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/BukkitListenerSystem.java index 5a569f154..5436ddcd1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/BukkitListenerSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/BukkitListenerSystem.java @@ -4,24 +4,50 @@ import com.djrapitops.plan.Plan; import com.djrapitops.plan.system.listeners.bukkit.*; import org.bukkit.event.HandlerList; +import javax.inject.Inject; + public class BukkitListenerSystem extends ListenerSystem { private final Plan plugin; + private final PlayerOnlineListener playerOnlineListener; + private final ChatListener chatListener; + private final GameModeChangeListener gamemodeChangeListener; + private final WorldChangeListener worldChangeListener; + private final CommandListener commandListener; + private final DeathEventListener deathEventListener; + private final AFKListener afkListener; - public BukkitListenerSystem(Plan plugin) { + @Inject + public BukkitListenerSystem(Plan plugin, + PlayerOnlineListener playerOnlineListener, + ChatListener chatListener, + GameModeChangeListener gamemodeChangeListener, + WorldChangeListener worldChangeListener, + CommandListener commandListener, + DeathEventListener deathEventListener, + AFKListener afkListener + ) { this.plugin = plugin; + + this.playerOnlineListener = playerOnlineListener; + this.chatListener = chatListener; + this.gamemodeChangeListener = gamemodeChangeListener; + this.worldChangeListener = worldChangeListener; + this.commandListener = commandListener; + this.deathEventListener = deathEventListener; + this.afkListener = afkListener; } @Override protected void registerListeners() { plugin.registerListener( - new PlayerOnlineListener(), - new ChatListener(), - new GamemodeChangeListener(), - new WorldChangeListener(), - new CommandPreprocessListener(plugin), - new DeathEventListener(), - new AFKListener() + playerOnlineListener, + chatListener, + gamemodeChangeListener, + worldChangeListener, + commandListener, + deathEventListener, + afkListener ); PlayerOnlineListener.setCountKicks(true); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java index 2b7f51409..4957aac87 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/AFKListener.java @@ -2,7 +2,8 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.system.afk.AFKTracker; import com.djrapitops.plan.system.settings.Permissions; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -12,6 +13,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerMoveEvent; +import javax.inject.Inject; import java.util.UUID; /** @@ -25,7 +27,14 @@ import java.util.UUID; public class AFKListener implements Listener { // Static so that /reload does not cause afk tracking to fail. - public static final AFKTracker AFK_TRACKER = new AFKTracker(); + static final AFKTracker AFK_TRACKER = new AFKTracker(); + + private final ErrorHandler errorHandler; + + @Inject + public AFKListener(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } private void event(PlayerEvent event) { try { @@ -39,7 +48,7 @@ public class AFKListener implements Listener { AFK_TRACKER.performedAction(uuid, time); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/ChatListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/ChatListener.java index e98b53f5a..26ac1a0ad 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/ChatListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/ChatListener.java @@ -2,13 +2,15 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.player.NameProcessor; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; +import javax.inject.Inject; import java.util.UUID; /** @@ -18,11 +20,13 @@ import java.util.UUID; */ public class ChatListener implements Listener { - /** - * ChatEvent listener. - * - * @param event Fired Event - */ + private final ErrorHandler errorHandler; + + @Inject + public ChatListener(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + @EventHandler(priority = EventPriority.MONITOR) public void onChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) { @@ -32,7 +36,7 @@ public class ChatListener implements Listener { try { actOnChatEvent(event); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandPreprocessListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java similarity index 85% rename from Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandPreprocessListener.java rename to Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java index 2757a017c..f82f28c70 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandPreprocessListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java @@ -5,36 +5,32 @@ import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.CommandProcessor; import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Settings; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.command.Command; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import javax.inject.Inject; + /** * Event Listener for PlayerCommandPreprocessEvents. * * @author Rsl1122 */ -public class CommandPreprocessListener implements Listener { +public class CommandListener implements Listener { private final Plan plugin; + private final ErrorHandler errorHandler; - /** - * Class Constructor. - * - * @param plugin Current instance of Plan - */ - public CommandPreprocessListener(Plan plugin) { + @Inject + public CommandListener(Plan plugin, ErrorHandler errorHandler) { this.plugin = plugin; + this.errorHandler = errorHandler; } - /** - * Command use listener. - * - * @param event Fired event. - */ @EventHandler(priority = EventPriority.MONITOR) public void onPlayerCommand(PlayerCommandPreprocessEvent event) { boolean hasIgnorePermission = event.getPlayer().hasPermission(Permissions.IGNORE_COMMAND_USE.getPermission()); @@ -45,7 +41,7 @@ public class CommandPreprocessListener implements Listener { try { actOnCommandEvent(event); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java index 2c9f22743..3a97e7673 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/DeathEventListener.java @@ -5,7 +5,8 @@ import com.djrapitops.plan.data.store.mutators.formatting.Formatters; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.player.KillProcessor; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.utilities.Format; import org.bukkit.Material; import org.bukkit.entity.*; @@ -17,6 +18,8 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.projectiles.ProjectileSource; +import javax.inject.Inject; + /** * Event Listener for EntityDeathEvents. * @@ -24,11 +27,13 @@ import org.bukkit.projectiles.ProjectileSource; */ public class DeathEventListener implements Listener { - /** - * Command use listener. - * - * @param event Fired event. - */ + private final ErrorHandler errorHandler; + + @Inject + public DeathEventListener(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void onDeath(EntityDeathEvent event) { @@ -51,7 +56,7 @@ public class DeathEventListener implements Listener { handleKill(time, dead, killerEntity); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/GamemodeChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/GameModeChangeListener.java similarity index 74% rename from Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/GamemodeChangeListener.java rename to Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/GameModeChangeListener.java index 8387b9d78..240ba1dbe 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/GamemodeChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/GameModeChangeListener.java @@ -3,13 +3,15 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.settings.WorldAliasSettings; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerGameModeChangeEvent; +import javax.inject.Inject; import java.util.Optional; import java.util.UUID; @@ -18,13 +20,15 @@ import java.util.UUID; * * @author Rsl1122 */ -public class GamemodeChangeListener implements Listener { +public class GameModeChangeListener implements Listener { + + private final ErrorHandler errorHandler; + + @Inject + public GameModeChangeListener(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } - /** - * GM Change Event Listener. - * - * @param event Fired Event. - */ @EventHandler(priority = EventPriority.MONITOR) public void onGameModeChange(PlayerGameModeChangeEvent event) { if (event.isCancelled()) { @@ -33,7 +37,7 @@ public class GamemodeChangeListener implements Listener { try { actOnEvent(event); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } @@ -44,7 +48,7 @@ public class GamemodeChangeListener implements Listener { String gameMode = event.getNewGameMode().name(); String worldName = player.getWorld().getName(); - WorldAliasSettings.addWorld(worldName); + WorldAliasSettings.addWorld_Old(worldName); Optional cachedSession = SessionCache.getCachedSession(uuid); cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time)); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index 7e6e629ce..07d91e51e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -6,7 +6,8 @@ import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.info.NetworkPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor; import com.djrapitops.plan.system.processing.processors.player.*; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.task.RunnableFactory; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -17,6 +18,7 @@ import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; +import javax.inject.Inject; import java.net.InetAddress; import java.util.UUID; @@ -30,10 +32,21 @@ public class PlayerOnlineListener implements Listener { private static boolean countKicks = true; + private final SessionCache sessionCache; + private final ErrorHandler errorHandler; + private final RunnableFactory runnableFactory; + public static void setCountKicks(boolean value) { countKicks = value; } + @Inject + public PlayerOnlineListener(SessionCache sessionCache, RunnableFactory runnableFactory, ErrorHandler errorHandler) { + this.sessionCache = sessionCache; + this.runnableFactory = runnableFactory; + this.errorHandler = errorHandler; + } + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerLogin(PlayerLoginEvent event) { try { @@ -43,7 +56,7 @@ public class PlayerOnlineListener implements Listener { boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED; Processing.submit(new BanAndOpProcessor(uuid, () -> banned, op)); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } @@ -64,7 +77,7 @@ public class PlayerOnlineListener implements Listener { UUID uuid = event.getPlayer().getUniqueId(); Processing.submit(new KickProcessor(uuid)); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } @@ -73,7 +86,7 @@ public class PlayerOnlineListener implements Listener { try { actOnJoinEvent(event); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } @@ -94,9 +107,9 @@ public class PlayerOnlineListener implements Listener { String playerName = player.getName(); String displayName = player.getDisplayName(); - SessionCache.getInstance().cacheSession(uuid, new Session(uuid, time, world, gm)); + sessionCache.cacheSession(uuid, new Session(uuid, time, world, gm)); - RunnableFactory.createNew("Player Register: " + uuid, + runnableFactory.create("Player Register: " + uuid, new RegisterProcessor(uuid, player::getFirstPlayed, playerName, new IPUpdateProcessor(uuid, address, time), new NameProcessor(uuid, playerName, displayName), @@ -111,7 +124,7 @@ public class PlayerOnlineListener implements Listener { try { actOnQuitEvent(event); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/WorldChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/WorldChangeListener.java index 60ad98cfb..f93a7cf31 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/WorldChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/WorldChangeListener.java @@ -3,24 +3,33 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.settings.WorldAliasSettings; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; +import javax.inject.Inject; import java.util.Optional; import java.util.UUID; public class WorldChangeListener implements Listener { + private final ErrorHandler errorHandler; + + @Inject + public WorldChangeListener(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + @EventHandler(priority = EventPriority.MONITOR) public void onWorldChange(PlayerChangedWorldEvent event) { try { actOnEvent(event); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } @@ -33,7 +42,7 @@ public class WorldChangeListener implements Listener { String worldName = player.getWorld().getName(); String gameMode = player.getGameMode().name(); - WorldAliasSettings.addWorld(worldName); + WorldAliasSettings.addWorld_Old(worldName); Optional cachedSession = SessionCache.getCachedSession(uuid); cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time)); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeGMChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeGMChangeListener.java index 490b8ebb1..ae219ec35 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeGMChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeGMChangeListener.java @@ -40,7 +40,7 @@ public class SpongeGMChangeListener { String gameMode = event.getGameMode().getName().toUpperCase(); String worldName = player.getWorld().getName(); - WorldAliasSettings.addWorld(worldName); + WorldAliasSettings.addWorld_Old(worldName); Optional cachedSession = SessionCache.getCachedSession(uuid); cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time)); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeWorldChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeWorldChangeListener.java index 8d674ef71..8ef7cf568 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeWorldChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongeWorldChangeListener.java @@ -43,7 +43,7 @@ public class SpongeWorldChangeListener { String worldName = event.getToTransform().getExtent().getName(); String gameMode = getGameMode(player); - WorldAliasSettings.addWorld(worldName); + WorldAliasSettings.addWorld_Old(worldName); Optional cachedSession = SessionCache.getCachedSession(uuid); cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time)); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java index 0f5aaab27..93a98f9c5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java @@ -21,17 +21,14 @@ import java.util.Map; * @author Rsl1122 */ public class WorldAliasSettings { - - private WorldAliasSettings() { - /* Hide Constructor */ - } /** * Used to get all World aliases in the config * * @return Map: Original name, Alias */ - public static Map getAliases() { + @Deprecated + public static Map getAliases_Old() { ConfigNode aliasSect = getAliasSection(); Map aliasMap = new HashMap<>(); @@ -53,7 +50,8 @@ public class WorldAliasSettings { * * @param world World name */ - public static void addWorld(String world) { + @Deprecated + public static void addWorld_Old(String world) { ConfigNode aliasSect = getAliasSection(); String previousValue = aliasSect.getConfigNode(world).getValue(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ServerConfigSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ServerConfigSystem.java index d499799e0..aa38d3e83 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ServerConfigSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/ServerConfigSystem.java @@ -6,6 +6,7 @@ package com.djrapitops.plan.system.settings.config; import com.djrapitops.plan.system.file.FileSystem; +import javax.inject.Inject; import java.io.IOException; /** @@ -17,8 +18,15 @@ import java.io.IOException; */ public class ServerConfigSystem extends ConfigSystem { + protected final FileSystem fileSystem; + + @Inject + public ServerConfigSystem(FileSystem fileSystem) { + this.fileSystem = fileSystem; + } + @Override protected void copyDefaults() throws IOException { - config.copyDefaults(FileSystem.readFromResource_Old("config.yml")); + config.copyDefaults(fileSystem.readFromResource("config.yml")); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/SpongeConfigSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/SpongeConfigSystem.java index ce5f05ce8..f341778c9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/config/SpongeConfigSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/config/SpongeConfigSystem.java @@ -3,8 +3,9 @@ package com.djrapitops.plan.system.settings.config; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.settings.Settings; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.console.PluginLogger; +import javax.inject.Inject; import java.io.IOException; /** @@ -14,11 +15,19 @@ import java.io.IOException; */ public class SpongeConfigSystem extends ServerConfigSystem { + private final PluginLogger logger; + private boolean firstInstall; + @Inject + public SpongeConfigSystem(FileSystem fileSystem, PluginLogger logger) { + super(fileSystem); + this.logger = logger; + } + @Override public void enable() throws EnableException { - firstInstall = !FileSystem.getConfigFile_Old().exists(); + firstInstall = !fileSystem.getConfigFile().exists(); super.enable(); } @@ -26,12 +35,13 @@ public class SpongeConfigSystem extends ServerConfigSystem { protected void copyDefaults() throws IOException { super.copyDefaults(); if (firstInstall) { - Log.info("§eWebServer and Geolocations disabled by default on Sponge servers. You can enable them in the config:"); - Log.info("§e " + Settings.WEBSERVER_DISABLED.getPath()); - Log.info("§e " + Settings.DATA_GEOLOCATIONS.getPath()); - Settings.WEBSERVER_DISABLED.set(true); - Settings.DATA_GEOLOCATIONS.set(false); - Settings.save(); + logger.info("§eWebServer and Geolocations disabled by default on Sponge servers. You can enable them in the config:"); + logger.info("§e " + Settings.WEBSERVER_DISABLED.getPath()); + logger.info("§e " + Settings.DATA_GEOLOCATIONS.getPath()); + + config.set(Settings.WEBSERVER_DISABLED, true); + config.set(Settings.DATA_GEOLOCATIONS, false); + config.save(); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java index 899bb2cb0..b90182fcd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java @@ -9,8 +9,11 @@ import com.djrapitops.plan.system.tasks.server.BukkitTPSCountTimer; import com.djrapitops.plan.system.tasks.server.PaperTPSCountTimer; import com.djrapitops.plan.system.tasks.server.PingCountTimer; import com.djrapitops.plugin.api.Check; +import com.djrapitops.plugin.task.RunnableFactory; import org.bukkit.Bukkit; +import javax.inject.Inject; + /** * TaskSystem responsible for registering tasks for Bukkit. * @@ -20,8 +23,9 @@ public class BukkitTaskSystem extends ServerTaskSystem { private final Plan plugin; - public BukkitTaskSystem(Plan plugin) { - super(plugin.getRunnableFactory(), + @Inject + public BukkitTaskSystem(Plan plugin, RunnableFactory runnableFactory) { + super(runnableFactory, Check.isPaperAvailable() ? new PaperTPSCountTimer(plugin) : new BukkitTPSCountTimer(plugin) diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/pie/WorldPie.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/pie/WorldPie.java index 4ca3e0747..6f03b1e98 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/pie/WorldPie.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/pie/WorldPie.java @@ -47,7 +47,7 @@ public class WorldPie extends AbstractPieChartWithDrilldown { } private Map getGMTimesPerAlias() { - Map aliases = WorldAliasSettings.getAliases(); + Map aliases = WorldAliasSettings.getAliases_Old(); Map gmTimesPerAlias = new HashMap<>(); @@ -59,7 +59,7 @@ public class WorldPie extends AbstractPieChartWithDrilldown { if (!aliases.containsKey(worldName)) { aliases.put(worldName, worldName); - WorldAliasSettings.addWorld(worldName); + WorldAliasSettings.addWorld_Old(worldName); } String alias = aliases.get(worldName);