mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-06 10:49:44 +01:00
Sponge Listener + Task Systems now initialized by Dagger
This commit is contained in:
parent
604496fb64
commit
b66033f589
@ -36,10 +36,12 @@ public class SpongeSystem extends PlanSystem implements ServerSystem {
|
||||
ConfigSystem serverConfigSystem,
|
||||
InfoSystem serverInfoSystem,
|
||||
SpongeServerInfo serverInfo,
|
||||
SpongeListenerSystem spongeListenerSystem,
|
||||
SpongeTaskSystem spongeTaskSystem,
|
||||
DBSystem serverDBSystem,
|
||||
ExportSystem exportSystem,
|
||||
HookHandler hookHandler,
|
||||
PlanAPI planAPI,
|
||||
ExportSystem exportSystem,
|
||||
DBSystem serverDBSystem,
|
||||
ShutdownHook shutdownHook
|
||||
) {
|
||||
setTestSystem(this);
|
||||
@ -49,8 +51,8 @@ public class SpongeSystem extends PlanSystem implements ServerSystem {
|
||||
this.configSystem = serverConfigSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
this.databaseSystem = serverDBSystem;
|
||||
listenerSystem = new SpongeListenerSystem(plugin);
|
||||
taskSystem = new SpongeTaskSystem(plugin);
|
||||
listenerSystem = spongeListenerSystem;
|
||||
taskSystem = spongeTaskSystem;
|
||||
|
||||
infoSystem = serverInfoSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
|
@ -9,6 +9,7 @@ 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;
|
||||
|
@ -4,24 +4,51 @@ import com.djrapitops.plan.PlanSponge;
|
||||
import com.djrapitops.plan.system.listeners.sponge.*;
|
||||
import org.spongepowered.api.Sponge;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class SpongeListenerSystem extends ListenerSystem {
|
||||
|
||||
private final PlanSponge plugin;
|
||||
|
||||
public SpongeListenerSystem(PlanSponge plugin) {
|
||||
private final SpongeAFKListener afkListener;
|
||||
private final SpongeChatListener chatListener;
|
||||
private final SpongeCommandListener commandListener;
|
||||
private final SpongeDeathListener deathListener;
|
||||
private final SpongeGMChangeListener gmChangeListener;
|
||||
private final SpongePlayerListener playerListener;
|
||||
private final SpongeWorldChangeListener worldChangeListener;
|
||||
|
||||
@Inject
|
||||
public SpongeListenerSystem(PlanSponge plugin,
|
||||
SpongeAFKListener afkListener,
|
||||
SpongeChatListener chatListener,
|
||||
SpongeCommandListener commandListener,
|
||||
SpongeDeathListener deathListener,
|
||||
SpongeGMChangeListener gmChangeListener,
|
||||
SpongePlayerListener playerListener,
|
||||
SpongeWorldChangeListener worldChangeListener
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.afkListener = afkListener;
|
||||
this.chatListener = chatListener;
|
||||
this.commandListener = commandListener;
|
||||
this.deathListener = deathListener;
|
||||
this.gmChangeListener = gmChangeListener;
|
||||
this.playerListener = playerListener;
|
||||
this.worldChangeListener = worldChangeListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerListeners() {
|
||||
plugin.registerListener(
|
||||
new SpongeAFKListener(),
|
||||
new SpongeChatListener(),
|
||||
new SpongeCommandListener(),
|
||||
new SpongeDeathListener(),
|
||||
new SpongeGMChangeListener(),
|
||||
new SpongePlayerListener(),
|
||||
new SpongeWorldChangeListener()
|
||||
afkListener,
|
||||
chatListener,
|
||||
commandListener,
|
||||
deathListener,
|
||||
playerListener,
|
||||
gmChangeListener,
|
||||
worldChangeListener
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,8 @@ package com.djrapitops.plan.system.listeners.sponge;
|
||||
|
||||
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.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
@ -13,6 +14,7 @@ import org.spongepowered.api.event.entity.living.humanoid.player.TargetPlayerEve
|
||||
import org.spongepowered.api.event.filter.cause.First;
|
||||
import org.spongepowered.api.event.message.MessageChannelEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -25,6 +27,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SpongeAFKListener {
|
||||
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongeAFKListener(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
// Static so that /reload does not cause afk tracking to fail.
|
||||
public static final AFKTracker AFK_TRACKER = new AFKTracker();
|
||||
|
||||
@ -32,7 +41,7 @@ public class SpongeAFKListener {
|
||||
try {
|
||||
performedAction(event.getTargetEntity());
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +69,7 @@ public class SpongeAFKListener {
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
||||
performedAction(player);
|
||||
|
||||
|
||||
boolean isAfkCommand = event.getCommand().toLowerCase().startsWith("afk");
|
||||
if (isAfkCommand) {
|
||||
AFK_TRACKER.usedAfkCommand(player.getUniqueId(), System.currentTimeMillis());
|
||||
|
@ -2,13 +2,15 @@ package com.djrapitops.plan.system.listeners.sponge;
|
||||
|
||||
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.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.filter.cause.First;
|
||||
import org.spongepowered.api.event.message.MessageChannelEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -18,6 +20,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SpongeChatListener {
|
||||
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongeChatListener(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
|
||||
if (event.isCancelled()) {
|
||||
@ -27,7 +36,7 @@ public class SpongeChatListener {
|
||||
try {
|
||||
actOnChatEvent(player);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,8 @@ 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.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandMapping;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
@ -13,6 +14,7 @@ import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.command.SendCommandEvent;
|
||||
import org.spongepowered.api.event.filter.cause.First;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -22,6 +24,13 @@ import java.util.Optional;
|
||||
*/
|
||||
public class SpongeCommandListener {
|
||||
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongeCommandListener(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerCommand(SendCommandEvent event, @First Player player) {
|
||||
boolean hasIgnorePermission = player.hasPermission(Permissions.IGNORE_COMMAND_USE.getPermission());
|
||||
@ -31,7 +40,7 @@ public class SpongeCommandListener {
|
||||
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.SpongeKillProcessor;
|
||||
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.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.data.type.HandTypes;
|
||||
@ -22,6 +23,7 @@ import org.spongepowered.api.item.ItemType;
|
||||
import org.spongepowered.api.item.ItemTypes;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -32,6 +34,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SpongeDeathListener {
|
||||
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongeDeathListener(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onEntityDeath(DestructEntityEvent.Death event) {
|
||||
long time = System.currentTimeMillis();
|
||||
@ -50,7 +59,7 @@ public class SpongeDeathListener {
|
||||
handleKill(time, dead, killerEntity);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,14 @@ package com.djrapitops.plan.system.listeners.sponge;
|
||||
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.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.entity.living.humanoid.ChangeGameModeEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -19,6 +21,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SpongeGMChangeListener {
|
||||
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongeGMChangeListener(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onGMChange(ChangeGameModeEvent.TargetPlayer event) {
|
||||
if (event.isCancelled()) {
|
||||
@ -28,7 +37,7 @@ public class SpongeGMChangeListener {
|
||||
try {
|
||||
actOnGMChangeEvent(event);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.key.Keys;
|
||||
@ -20,6 +21,7 @@ import org.spongepowered.api.profile.GameProfile;
|
||||
import org.spongepowered.api.service.ProviderRegistration;
|
||||
import org.spongepowered.api.service.ban.BanService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -31,12 +33,23 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SpongePlayerListener {
|
||||
|
||||
private SessionCache sessionCache;
|
||||
private RunnableFactory runnableFactory;
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongePlayerListener(SessionCache sessionCache, RunnableFactory runnableFactory, ErrorHandler errorHandler) {
|
||||
this.sessionCache = sessionCache;
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onLogin(ClientConnectionEvent.Login event) {
|
||||
try {
|
||||
actOnLoginEvent(event);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +66,7 @@ public class SpongePlayerListener {
|
||||
UUID uuid = event.getTargetEntity().getUniqueId();
|
||||
Processing.submit(new KickProcessor(uuid));
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +84,7 @@ public class SpongePlayerListener {
|
||||
try {
|
||||
actOnJoinEvent(event);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,9 +108,9 @@ public class SpongePlayerListener {
|
||||
String playerName = player.getName();
|
||||
String displayName = player.getDisplayNameData().displayName().get().toPlain();
|
||||
|
||||
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, () -> time, playerName,
|
||||
new IPUpdateProcessor(uuid, address, time),
|
||||
new NameProcessor(uuid, playerName, displayName),
|
||||
@ -112,7 +125,7 @@ public class SpongePlayerListener {
|
||||
try {
|
||||
actOnQuitEvent(event);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,8 @@ package com.djrapitops.plan.system.listeners.sponge;
|
||||
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.spongepowered.api.data.key.Keys;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
|
||||
@ -12,6 +13,7 @@ import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.entity.MoveEntityEvent;
|
||||
import org.spongepowered.api.event.filter.cause.First;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -22,6 +24,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SpongeWorldChangeListener {
|
||||
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public SpongeWorldChangeListener(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onWorldChange(MoveEntityEvent.Teleport event, @First Player player) {
|
||||
if (event.isCancelled()) {
|
||||
@ -31,7 +40,7 @@ public class SpongeWorldChangeListener {
|
||||
try {
|
||||
actOnEvent(event, player);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,19 @@ package com.djrapitops.plan.system.tasks;
|
||||
|
||||
import com.djrapitops.plan.PlanSponge;
|
||||
import com.djrapitops.plan.system.tasks.server.SpongeTPSCountTimer;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class SpongeTaskSystem extends ServerTaskSystem {
|
||||
|
||||
private final PlanSponge plugin;
|
||||
|
||||
public SpongeTaskSystem(PlanSponge plugin) {
|
||||
super(plugin.getRunnableFactory(), new SpongeTPSCountTimer(plugin));
|
||||
@Inject
|
||||
public SpongeTaskSystem(PlanSponge plugin, RunnableFactory runnableFactory) {
|
||||
super(runnableFactory, new SpongeTPSCountTimer(plugin));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user