mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-29 23:09:42 +01:00
Bukkit Listener + Task Systems now initialized by Dagger
This commit is contained in:
parent
86ba26e50e
commit
604496fb64
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -222,7 +222,7 @@ public class Session extends DataContainer implements DateHolder {
|
||||
}
|
||||
|
||||
private String getLongestWorldPlayed() {
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases_Old();
|
||||
if (worldTimes == null) {
|
||||
return "No World Time Data";
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public class WorldTimes {
|
||||
entry -> entry.getValue().getTotal() // GMTimes.getTotal
|
||||
));
|
||||
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases_Old();
|
||||
|
||||
Map<String, Long> playtimePerAlias = new HashMap<>();
|
||||
for (Map.Entry<String, Long> 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);
|
||||
|
@ -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
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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."));
|
||||
|
@ -22,6 +22,7 @@ public class SessionCache {
|
||||
|
||||
private static final Map<UUID, Session> activeSessions = new HashMap<>();
|
||||
|
||||
@Deprecated
|
||||
public static SessionCache getInstance() {
|
||||
SessionCache dataCache = CacheSystem.getInstance().getDataCache();
|
||||
Verify.nullCheck(dataCache, () -> new IllegalStateException("Data Cache was not initialized."));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
||||
|
@ -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<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
||||
|
@ -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<Session> cachedSession = SessionCache.getCachedSession(uuid);
|
||||
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
|
||||
|
@ -22,16 +22,13 @@ import java.util.Map;
|
||||
*/
|
||||
public class WorldAliasSettings {
|
||||
|
||||
private WorldAliasSettings() {
|
||||
/* Hide Constructor */
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get all World aliases in the config
|
||||
*
|
||||
* @return Map: Original name, Alias
|
||||
*/
|
||||
public static Map<String, String> getAliases() {
|
||||
@Deprecated
|
||||
public static Map<String, String> getAliases_Old() {
|
||||
ConfigNode aliasSect = getAliasSection();
|
||||
|
||||
Map<String, String> 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();
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -47,7 +47,7 @@ public class WorldPie extends AbstractPieChartWithDrilldown {
|
||||
}
|
||||
|
||||
private Map<String, GMTimes> getGMTimesPerAlias() {
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases_Old();
|
||||
|
||||
Map<String, GMTimes> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user