Processors (ProcessorFactory), KillProcessors simplified

This commit is contained in:
Rsl1122 2018-09-02 12:30:37 +03:00
parent 8c75e936d6
commit f9f82315e0
38 changed files with 485 additions and 217 deletions

View File

@ -8,7 +8,7 @@ import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.info.InspectCacheRequestProcessor;
import com.djrapitops.plan.system.processing.processors.info.InfoProcessors;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.MiscUtils;
@ -34,6 +34,7 @@ public class InspectCommand extends CommandNode {
private final Locale locale;
private final Database database;
private final WebServer webServer;
private final InfoProcessors processorFactory;
private final Processing processing;
private final ConnectionSystem connectionSystem;
private final UUIDUtility uuidUtility;
@ -42,6 +43,7 @@ public class InspectCommand extends CommandNode {
@Inject
public InspectCommand(
Locale locale,
InfoProcessors processorFactory,
Processing processing,
Database database,
WebServer webServer,
@ -50,6 +52,7 @@ public class InspectCommand extends CommandNode {
ErrorHandler errorHandler
) {
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
this.processorFactory = processorFactory;
this.processing = processing;
this.connectionSystem = connectionSystem;
setArguments("<player>");
@ -90,7 +93,7 @@ public class InspectCommand extends CommandNode {
}
checkWebUserAndNotify(sender);
processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, this::sendInspectMsg));
processing.submit(processorFactory.inspectCacheRequestProcessor(uuid, sender, playerName, this::sendInspectMsg));
} catch (DBOpException e) {
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
errorHandler.log(L.ERROR, this.getClass(), e);

View File

@ -1,7 +1,6 @@
package com.djrapitops.plan.data.store.containers;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.store.Key;
import com.djrapitops.plan.data.store.keys.NetworkKeys;
import com.djrapitops.plan.data.store.keys.ServerKeys;
@ -22,7 +21,6 @@ import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.HashMap;
import java.util.Map;
@ -71,14 +69,9 @@ public class NetworkContainer extends DataContainer {
if (container != null) {
return Optional.of(container);
}
try {
AnalysisContainer analysisContainer = new AnalysisContainer(database.fetch().getServerContainer(serverUUID));
serverContainers.put(serverUUID, analysisContainer);
return Optional.of(analysisContainer);
} catch (DBOpException e) {
Log.toLog(this.getClass(), e);
}
return Optional.empty();
}
private void addConstants() {

View File

@ -91,4 +91,8 @@ public class Formatters {
return builder.toString();
};
}
public static Formatter<String> entityName() {
return name -> new Format(name).removeNumbers().removeSymbols().capitalize().toString();
}
}

View File

@ -52,6 +52,7 @@ public class DataCache extends SessionCache implements SubSystem {
displayNames.clear();
}
@Deprecated
public static DataCache getInstance() {
DataCache dataCache = CacheSystem.getInstance().getDataCache();
Verify.nullCheck(dataCache, () -> new IllegalStateException("Data Cache was not initialized."));

View File

@ -1,7 +1,7 @@
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.plan.system.processing.processors.player.PlayerProcessors;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.bukkit.entity.Player;
@ -20,14 +20,17 @@ import java.util.UUID;
*/
public class ChatListener implements Listener {
private final PlayerProcessors processorFactory;
private final Processing processing;
private final ErrorHandler errorHandler;
@Inject
public ChatListener(
PlayerProcessors processorFactory,
Processing processing,
ErrorHandler errorHandler
) {
this.processorFactory = processorFactory;
this.processing = processing;
this.errorHandler = errorHandler;
}
@ -50,6 +53,6 @@ public class ChatListener implements Listener {
UUID uuid = p.getUniqueId();
String name = p.getName();
String displayName = p.getDisplayName();
processing.submit(new NameProcessor(uuid, name, displayName));
processing.submit(processorFactory.nameProcessor(uuid, name, displayName));
}
}

View File

@ -2,7 +2,7 @@ package com.djrapitops.plan.system.listeners.bukkit;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.CommandProcessor;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.logging.L;
@ -23,16 +23,19 @@ import javax.inject.Inject;
public class CommandListener implements Listener {
private final Plan plugin;
private final Processors processors;
private final Processing processing;
private final ErrorHandler errorHandler;
@Inject
public CommandListener(
Plan plugin,
Processors processors,
Processing processing,
ErrorHandler errorHandler
) {
this.plugin = plugin;
this.processors = processors;
this.processing = processing;
this.errorHandler = errorHandler;
}
@ -67,7 +70,7 @@ public class CommandListener implements Listener {
commandName = command.getName();
}
}
processing.submit(new CommandProcessor(commandName));
processing.submit(processors.commandProcessor(commandName));
}
private Command getBukkitCommand(String commandName) {

View File

@ -4,10 +4,10 @@ import com.djrapitops.plan.data.container.Session;
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.plan.system.processing.processors.player.MobKillProcessor;
import com.djrapitops.plan.system.processing.processors.player.PlayerKillProcessor;
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.*;
import org.bukkit.event.EventHandler;
@ -19,6 +19,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.projectiles.ProjectileSource;
import javax.inject.Inject;
import java.util.UUID;
/**
* Event Listener for EntityDeathEvents.
@ -59,27 +60,28 @@ public class DeathEventListener implements Listener {
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent;
Entity killerEntity = entityDamageByEntityEvent.getDamager();
handleKill(time, dead, killerEntity);
UUID uuid = dead instanceof Player ? dead.getUniqueId() : null;
handleKill(time, uuid, killerEntity);
} catch (Exception e) {
errorHandler.log(L.ERROR, this.getClass(), e);
}
}
private void handleKill(long time, LivingEntity dead, Entity killerEntity) {
KillProcessor processor = null;
private void handleKill(long time, UUID victimUUID, Entity killerEntity) {
Runnable processor = null;
if (killerEntity instanceof Player) {
processor = handlePlayerKill(time, dead, (Player) killerEntity);
processor = handlePlayerKill(time, victimUUID, (Player) killerEntity);
} else if (killerEntity instanceof Tameable) {
processor = handlePetKill(time, dead, (Tameable) killerEntity);
processor = handlePetKill(time, victimUUID, (Tameable) killerEntity);
} else if (killerEntity instanceof Projectile) {
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
processor = handleProjectileKill(time, victimUUID, (Projectile) killerEntity);
}
if (processor != null) {
processing.submit(processor);
}
}
private KillProcessor handlePlayerKill(long time, LivingEntity dead, Player killer) {
private Runnable handlePlayerKill(long time, UUID victimUUID, Player killer) {
Material itemInHand;
try {
itemInHand = killer.getInventory().getItemInMainHand().getType();
@ -91,10 +93,14 @@ public class DeathEventListener implements Listener {
}
}
return new KillProcessor(killer.getUniqueId(), time, dead, Formatters.itemName().apply(itemInHand.name()));
String weaponName = Formatters.itemName().apply(itemInHand.name());
return victimUUID != null
? new PlayerKillProcessor(killer.getUniqueId(), time, victimUUID, weaponName)
: new MobKillProcessor(killer.getUniqueId());
}
private KillProcessor handlePetKill(long time, LivingEntity dead, Tameable tameable) {
private Runnable handlePetKill(long time, UUID victimUUID, Tameable tameable) {
if (!tameable.isTamed()) {
return null;
}
@ -112,22 +118,23 @@ public class DeathEventListener implements Listener {
name = tameable.getClass().getSimpleName();
}
return new KillProcessor(owner.getUniqueId(), time, dead,
new Format(name).removeNumbers().removeSymbols().capitalize().toString()
);
return victimUUID != null
? new PlayerKillProcessor(owner.getUniqueId(), time, victimUUID, Formatters.entityName().apply(name))
: new MobKillProcessor(owner.getUniqueId());
}
private KillProcessor handleProjectileKill(long time, LivingEntity dead, Projectile projectile) {
private Runnable handleProjectileKill(long time, UUID victimUUID, Projectile projectile) {
ProjectileSource source = projectile.getShooter();
if (!(source instanceof Player)) {
return null;
}
Player player = (Player) source;
String projectileName = Formatters.entityName().apply(projectile.getType().name());
return new KillProcessor(player.getUniqueId(), time, dead,
new Format(projectile.getType().name()).capitalize().toString()
);
return victimUUID != null
? new PlayerKillProcessor(player.getUniqueId(), time, victimUUID, projectileName)
: new MobKillProcessor(player.getUniqueId());
}
}

View File

@ -3,9 +3,9 @@ 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.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.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.task.RunnableFactory;
@ -32,6 +32,8 @@ public class PlayerOnlineListener implements Listener {
private static boolean countKicks = true;
private final PlanConfig config;
private final Processors processors;
private final Processing processing;
private final SessionCache sessionCache;
private final ErrorHandler errorHandler;
@ -43,11 +45,15 @@ public class PlayerOnlineListener implements Listener {
@Inject
public PlayerOnlineListener(
PlanConfig config,
Processors processors,
Processing processing,
SessionCache sessionCache,
RunnableFactory runnableFactory,
ErrorHandler errorHandler
) {
this.config = config;
this.processors = processors;
this.processing = processing;
this.sessionCache = sessionCache;
this.runnableFactory = runnableFactory;
@ -61,7 +67,7 @@ public class PlayerOnlineListener implements Listener {
UUID uuid = event.getPlayer().getUniqueId();
boolean op = event.getPlayer().isOp();
boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED;
processing.submit(new BanAndOpProcessor(uuid, () -> banned, op));
processing.submit(processors.player().banAndOpProcessor(uuid, () -> banned, op));
} catch (Exception e) {
errorHandler.log(L.ERROR, this.getClass(), e);
}
@ -82,7 +88,7 @@ public class PlayerOnlineListener implements Listener {
return;
}
UUID uuid = event.getPlayer().getUniqueId();
processing.submit(new KickProcessor(uuid));
processing.submit(processors.player().kickProcessor(uuid));
} catch (Exception e) {
errorHandler.log(L.ERROR, this.getClass(), e);
}
@ -116,14 +122,16 @@ public class PlayerOnlineListener implements Listener {
sessionCache.cacheSession(uuid, new Session(uuid, time, world, gm));
boolean gatheringGeolocations = config.isTrue(Settings.DATA_GEOLOCATIONS);
runnableFactory.create("Player Register: " + uuid,
new RegisterProcessor(uuid, player::getFirstPlayed, playerName,
new IPUpdateProcessor(uuid, address, time),
new NameProcessor(uuid, playerName, displayName),
new PlayerPageUpdateProcessor(uuid)
processors.player().registerProcessor(uuid, player::getFirstPlayed, playerName,
gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null,
processors.player().nameProcessor(uuid, playerName, displayName),
processors.info().playerPageUpdateProcessor(uuid)
)
).runTaskAsynchronously();
processing.submit(new NetworkPageUpdateProcessor());
processing.submit(processors.info().networkPageUpdateProcessor());
}
@EventHandler(priority = EventPriority.MONITOR)
@ -142,9 +150,9 @@ public class PlayerOnlineListener implements Listener {
AFKListener.AFK_TRACKER.loggedOut(uuid, time);
processing.submit(new BanAndOpProcessor(uuid, player::isBanned, player.isOp()));
processing.submit(new EndSessionProcessor(uuid, time));
processing.submit(new NetworkPageUpdateProcessor());
processing.submit(new PlayerPageUpdateProcessor(uuid));
processing.submit(processors.player().banAndOpProcessor(uuid, player::isBanned, player.isOp()));
processing.submit(processors.player().endSessionProcessor(uuid, time));
processing.submit(processors.info().networkPageUpdateProcessor());
processing.submit(processors.info().playerPageUpdateProcessor(uuid));
}
}

View File

@ -8,9 +8,9 @@ import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.info.PlayerPageUpdateProcessor;
import com.djrapitops.plan.system.processing.processors.player.BungeePlayerRegisterProcessor;
import com.djrapitops.plan.system.processing.processors.player.IPUpdateProcessor;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.webserver.cache.PageId;
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
import com.djrapitops.plugin.logging.L;
@ -33,6 +33,8 @@ import java.util.UUID;
*/
public class PlayerOnlineListener implements Listener {
private final PlanConfig config;
private final Processors processors;
private final Processing processing;
private final SessionCache sessionCache;
private final ServerInfo serverInfo;
@ -40,11 +42,15 @@ public class PlayerOnlineListener implements Listener {
@Inject
public PlayerOnlineListener(
PlanConfig config,
Processors processors,
Processing processing,
SessionCache sessionCache,
ServerInfo serverInfo,
ErrorHandler errorHandler
) {
this.config = config;
this.processors = processors;
this.processing = processing;
this.sessionCache = sessionCache;
this.serverInfo = serverInfo;
@ -58,14 +64,16 @@ public class PlayerOnlineListener implements Listener {
UUID uuid = player.getUniqueId();
String name = player.getName();
InetAddress address = player.getAddress().getAddress();
long now = System.currentTimeMillis();
long time = System.currentTimeMillis();
sessionCache.cacheSession(uuid, new Session(uuid, now, "", ""));
sessionCache.cacheSession(uuid, new Session(uuid, time, "", ""));
processing.submit(new BungeePlayerRegisterProcessor(uuid, name, now,
new IPUpdateProcessor(uuid, address, now))
);
processing.submit(new PlayerPageUpdateProcessor(uuid));
boolean gatheringGeolocations = config.isTrue(Settings.DATA_GEOLOCATIONS);
processing.submit(processors.player().bungeeRegisterProcessor(uuid, name, time,
gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null
));
processing.submit(processors.info().playerPageUpdateProcessor(uuid));
ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID()));
} catch (Exception e) {
errorHandler.log(L.WARN, this.getClass(), e);
@ -79,7 +87,7 @@ public class PlayerOnlineListener implements Listener {
UUID uuid = player.getUniqueId();
sessionCache.endSession(uuid, System.currentTimeMillis());
processing.submit(new PlayerPageUpdateProcessor(uuid));
processing.submit(processors.info().playerPageUpdateProcessor(uuid));
ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID()));
} catch (Exception e) {
errorHandler.log(L.WARN, this.getClass(), e);
@ -92,10 +100,10 @@ public class PlayerOnlineListener implements Listener {
ProxiedPlayer player = event.getPlayer();
UUID uuid = player.getUniqueId();
long now = System.currentTimeMillis();
long time = System.currentTimeMillis();
// Replaces the current session in the cache.
sessionCache.cacheSession(uuid, new Session(uuid, now, "", ""));
processing.submit(new PlayerPageUpdateProcessor(uuid));
sessionCache.cacheSession(uuid, new Session(uuid, time, "", ""));
processing.submit(processors.info().playerPageUpdateProcessor(uuid));
} catch (Exception e) {
errorHandler.log(L.WARN, this.getClass(), e);
}

View File

@ -1,7 +1,7 @@
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.plan.system.processing.processors.player.PlayerProcessors;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.spongepowered.api.entity.living.player.Player;
@ -20,14 +20,17 @@ import java.util.UUID;
*/
public class SpongeChatListener {
private final PlayerProcessors processorFactory;
private final Processing processing;
private ErrorHandler errorHandler;
@Inject
public SpongeChatListener(
PlayerProcessors processorFactory,
Processing processing,
ErrorHandler errorHandler
) {
this.processorFactory = processorFactory;
this.processing = processing;
this.errorHandler = errorHandler;
}
@ -49,7 +52,7 @@ public class SpongeChatListener {
UUID uuid = player.getUniqueId();
String name = player.getName();
String displayName = player.getDisplayNameData().displayName().get().toPlain();
processing.submit(new NameProcessor(uuid, name, displayName));
processing.submit(processorFactory.nameProcessor(uuid, name, displayName));
}
}

View File

@ -1,7 +1,7 @@
package com.djrapitops.plan.system.listeners.sponge;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.CommandProcessor;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.logging.L;
@ -24,14 +24,17 @@ import java.util.Optional;
*/
public class SpongeCommandListener {
private final Processors processors;
private final Processing processing;
private ErrorHandler errorHandler;
@Inject
public SpongeCommandListener(
Processors processors,
Processing processing,
ErrorHandler errorHandler
) {
this.processors = processors;
this.processing = processing;
this.errorHandler = errorHandler;
}
@ -65,7 +68,7 @@ public class SpongeCommandListener {
commandName = existingCommand.get().getPrimaryAlias();
}
}
processing.submit(new CommandProcessor(commandName));
processing.submit(processors.commandProcessor(commandName));
}
}

View File

@ -4,10 +4,10 @@ import com.djrapitops.plan.data.container.Session;
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.plan.system.processing.processors.player.MobKillProcessor;
import com.djrapitops.plan.system.processing.processors.player.PlayerKillProcessor;
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;
import org.spongepowered.api.entity.Entity;
@ -69,26 +69,29 @@ public class SpongeDeathListener {
}
private void handleKill(long time, Living dead, Entity killerEntity) {
SpongeKillProcessor processor = null;
Runnable processor = null;
UUID victimUUID = getUUID(dead);
if (killerEntity instanceof Player) {
processor = handlePlayerKill(time, dead, (Player) killerEntity);
processor = handlePlayerKill(time, victimUUID, (Player) killerEntity);
} else if (killerEntity instanceof Wolf) {
processor = handleWolfKill(time, dead, (Wolf) killerEntity);
processor = handleWolfKill(time, victimUUID, (Wolf) killerEntity);
} else if (killerEntity instanceof Projectile) {
processor = handleProjectileKill(time, dead, (Projectile) killerEntity);
processor = handleProjectileKill(time, victimUUID, (Projectile) killerEntity);
}
if (processor != null) {
processing.submit(processor);
}
}
private SpongeKillProcessor handlePlayerKill(long time, Living dead, Player killer) {
private Runnable handlePlayerKill(long time, UUID victimUUID, Player killer) {
Optional<ItemStack> inMainHand = killer.getItemInHand(HandTypes.MAIN_HAND);
ItemStack inHand = inMainHand.orElse(killer.getItemInHand(HandTypes.OFF_HAND).orElse(ItemStack.empty()));
ItemType type = inHand.isEmpty() ? ItemTypes.AIR : inHand.getType();
return new SpongeKillProcessor(killer.getUniqueId(), time, getUUID(dead), Formatters.itemName().apply(type.getName()));
return victimUUID != null
? new PlayerKillProcessor(killer.getUniqueId(), time, victimUUID, Formatters.itemName().apply(type.getName()))
: new MobKillProcessor(killer.getUniqueId());
}
private UUID getUUID(Living dead) {
@ -98,26 +101,33 @@ public class SpongeDeathListener {
return null;
}
private SpongeKillProcessor handleWolfKill(long time, Living dead, Wolf wolf) {
private Runnable handleWolfKill(long time, UUID victimUUID, Wolf wolf) {
Optional<Optional<UUID>> owner = wolf.get(Keys.TAMED_OWNER);
return owner.map(ownerUUID -> ownerUUID.map(
uuid -> new SpongeKillProcessor(uuid, time, getUUID(dead), "Wolf")
// Has been tamed
return owner.map(ownerUUID ->
// Has tame owner
ownerUUID.map(uuid ->
// Player or mob
victimUUID != null
? new PlayerKillProcessor(uuid, time, victimUUID, "Wolf")
: new MobKillProcessor(uuid)
).orElse(null)).orElse(null);
}
private SpongeKillProcessor handleProjectileKill(long time, Living dead, Projectile projectile) {
private Runnable handleProjectileKill(long time, UUID victimUUID, Projectile projectile) {
ProjectileSource source = projectile.getShooter();
if (!(source instanceof Player)) {
return null;
}
Player player = (Player) source;
String projectileName = Formatters.entityName().apply(projectile.getType().getName());
return new SpongeKillProcessor(player.getUniqueId(), time, getUUID(dead),
new Format(projectile.getType().getName()).capitalize().toString()
);
return victimUUID != null
? new PlayerKillProcessor(player.getUniqueId(), time, victimUUID, projectileName)
: new MobKillProcessor(player.getUniqueId());
}
}

View File

@ -3,9 +3,9 @@ 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.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.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.task.RunnableFactory;
@ -33,6 +33,8 @@ import java.util.UUID;
*/
public class SpongePlayerListener {
private final PlanConfig config;
private final Processors processors;
private final Processing processing;
private SessionCache sessionCache;
private RunnableFactory runnableFactory;
@ -40,11 +42,15 @@ public class SpongePlayerListener {
@Inject
public SpongePlayerListener(
PlanConfig config,
Processors processors,
Processing processing,
SessionCache sessionCache,
RunnableFactory runnableFactory,
ErrorHandler errorHandler
) {
this.config = config;
this.processors = processors;
this.processing = processing;
this.sessionCache = sessionCache;
this.runnableFactory = runnableFactory;
@ -64,14 +70,14 @@ public class SpongePlayerListener {
GameProfile profile = event.getProfile();
UUID uuid = profile.getUniqueId();
boolean banned = isBanned(profile);
processing.submit(new BanAndOpProcessor(uuid, () -> banned, false));
processing.submit(processors.player().banAndOpProcessor(uuid, () -> banned, false));
}
@Listener(order = Order.POST)
public void onKick(KickPlayerEvent event) {
try {
UUID uuid = event.getTargetEntity().getUniqueId();
processing.submit(new KickProcessor(uuid));
processing.submit(processors.player().kickProcessor(uuid));
} catch (Exception e) {
errorHandler.log(L.ERROR, this.getClass(), e);
}
@ -117,14 +123,16 @@ public class SpongePlayerListener {
sessionCache.cacheSession(uuid, new Session(uuid, time, world, gm));
boolean gatheringGeolocations = config.isTrue(Settings.DATA_GEOLOCATIONS);
runnableFactory.create("Player Register: " + uuid,
new RegisterProcessor(uuid, () -> time, playerName,
new IPUpdateProcessor(uuid, address, time),
new NameProcessor(uuid, playerName, displayName),
new PlayerPageUpdateProcessor(uuid)
processors.player().registerProcessor(uuid, () -> time, playerName,
gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null,
processors.player().nameProcessor(uuid, playerName, displayName),
processors.info().playerPageUpdateProcessor(uuid)
)
).runTaskAsynchronously();
processing.submit(new NetworkPageUpdateProcessor());
processing.submit(processors.info().networkPageUpdateProcessor());
}
@Listener(order = Order.POST)
@ -144,9 +152,9 @@ public class SpongePlayerListener {
SpongeAFKListener.AFK_TRACKER.loggedOut(uuid, time);
boolean banned = isBanned(player.getProfile());
processing.submit(new BanAndOpProcessor(uuid, () -> banned, false));
processing.submit(new EndSessionProcessor(uuid, time));
processing.submit(new NetworkPageUpdateProcessor());
processing.submit(new PlayerPageUpdateProcessor(uuid));
processing.submit(processors.player().banAndOpProcessor(uuid, () -> banned, false));
processing.submit(processors.player().endSessionProcessor(uuid, time));
processing.submit(processors.info().networkPageUpdateProcessor());
processing.submit(processors.info().playerPageUpdateProcessor(uuid));
}
}

View File

@ -16,10 +16,11 @@ public class CommandProcessor implements CriticalRunnable {
private final String command;
private Database database;
private final Database database;
public CommandProcessor(String command) {
CommandProcessor(String command, Database database) {
this.command = command;
this.database = database;
}
@Override

View File

@ -0,0 +1,53 @@
package com.djrapitops.plan.system.processing.processors;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.processors.info.InfoProcessors;
import com.djrapitops.plan.system.processing.processors.player.PlayerProcessors;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
/**
* Factory for creating Runnables to run with {@link com.djrapitops.plan.system.processing.Processing}.
*
* @author Rsl1122
*/
@Singleton
public class Processors {
private final PlayerProcessors playerProcessors;
private final InfoProcessors infoProcessors;
private final Lazy<Database> database;
@Inject
public Processors(
PlayerProcessors playerProcessors,
InfoProcessors infoProcessors,
Lazy<Database> database
) {
this.playerProcessors = playerProcessors;
this.infoProcessors = infoProcessors;
this.database = database;
}
public TPSInsertProcessor tpsInsertProcessor(List<TPS> tpsList) {
return new TPSInsertProcessor(tpsList, database.get());
}
public CommandProcessor commandProcessor(String command) {
return new CommandProcessor(command, database.get());
}
public PlayerProcessors player() {
return playerProcessors;
}
public InfoProcessors info() {
return infoProcessors;
}
}

View File

@ -20,22 +20,23 @@ public class TPSInsertProcessor implements CriticalRunnable {
private final List<TPS> tpsList;
private Database database;
private final Database database;
public TPSInsertProcessor(List<TPS> tpsList) {
TPSInsertProcessor(List<TPS> tpsList, Database database) {
this.tpsList = tpsList;
this.database = database;
}
@Override
public void run() {
List<TPS> history = tpsList;
final long lastDate = history.get(history.size() - 1).getDate();
final double averageTPS = history.stream().mapToDouble(TPS::getTicksPerSecond).average().orElse(0);
final int peakPlayersOnline = history.stream().mapToInt(TPS::getPlayers).max().orElse(0);
final double averageCPUUsage = history.stream().mapToDouble(TPS::getCPUUsage).average().orElse(0);
final long averageUsedMemory = (long) history.stream().mapToLong(TPS::getUsedMemory).average().orElse(0);
final int averageEntityCount = (int) history.stream().mapToInt(TPS::getEntityCount).average().orElse(0);
final int averageChunksLoaded = (int) history.stream().mapToInt(TPS::getChunksLoaded).average().orElse(0);
long lastDate = history.get(history.size() - 1).getDate();
double averageTPS = history.stream().mapToDouble(TPS::getTicksPerSecond).average().orElse(0);
int peakPlayersOnline = history.stream().mapToInt(TPS::getPlayers).max().orElse(0);
double averageCPUUsage = history.stream().mapToDouble(TPS::getCPUUsage).average().orElse(0);
long averageUsedMemory = (long) history.stream().mapToLong(TPS::getUsedMemory).average().orElse(0);
int averageEntityCount = (int) history.stream().mapToInt(TPS::getEntityCount).average().orElse(0);
int averageChunksLoaded = (int) history.stream().mapToInt(TPS::getChunksLoaded).average().orElse(0);
TPS tps = TPSBuilder.get()
.date(lastDate)

View File

@ -0,0 +1,57 @@
package com.djrapitops.plan.system.processing.processors.info;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.task.RunnableFactory;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.UUID;
import java.util.function.BiConsumer;
/**
* Factory for creating Runnables related to {@link InfoSystem} to run with {@link com.djrapitops.plan.system.processing.Processing}.
*
* @author Rsl1122
*/
@Singleton
public class InfoProcessors {
private final Lazy<InfoSystem> infoSystem;
private final Lazy<WebExceptionLogger> webExceptionLogger;
private final Lazy<RunnableFactory> runnableFactory;
@Inject
public InfoProcessors(
Lazy<InfoSystem> infoSystem,
Lazy<WebExceptionLogger> webExceptionLogger,
Lazy<RunnableFactory> runnableFactory
) {
this.infoSystem = infoSystem;
this.webExceptionLogger = webExceptionLogger;
this.runnableFactory = runnableFactory;
}
public InspectCacheRequestProcessor inspectCacheRequestProcessor(
UUID uuid,
ISender sender,
String playerName,
BiConsumer<ISender, String> msgSender
) {
return new InspectCacheRequestProcessor(uuid, sender, playerName, msgSender,
infoSystem.get(), webExceptionLogger.get()
);
}
public NetworkPageUpdateProcessor networkPageUpdateProcessor() {
return new NetworkPageUpdateProcessor(infoSystem.get(), webExceptionLogger.get());
}
public PlayerPageUpdateProcessor playerPageUpdateProcessor(UUID uuid) {
return new PlayerPageUpdateProcessor(uuid,
infoSystem.get(), webExceptionLogger.get(), runnableFactory.get()
);
}
}

View File

@ -7,7 +7,7 @@ package com.djrapitops.plan.system.processing.processors.info;
import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plugin.command.ISender;
import java.util.UUID;
@ -25,31 +25,36 @@ public class InspectCacheRequestProcessor implements Runnable {
private final String playerName;
private final BiConsumer<ISender, String> msgSender;
private InfoSystem infoSystem;
private final InfoSystem infoSystem;
private final WebExceptionLogger webExceptionLogger;
public InspectCacheRequestProcessor(
InspectCacheRequestProcessor(
UUID uuid,
ISender sender,
String playerName,
BiConsumer<ISender, String> msgSender
BiConsumer<ISender, String> msgSender,
InfoSystem infoSystem,
WebExceptionLogger webExceptionLogger
) {
this.uuid = uuid;
this.sender = sender;
this.playerName = playerName;
this.msgSender = msgSender;
this.infoSystem = infoSystem;
this.webExceptionLogger = webExceptionLogger;
}
@Override
public void run() {
SessionCache.refreshActiveSessionsState();
webExceptionLogger.logIfOccurs(this.getClass(), () -> {
try {
infoSystem.generateAndCachePlayerPage(uuid);
msgSender.accept(sender, playerName);
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
| NotFoundException | NoServersException e) {
sender.sendMessage("§c" + e.getMessage());
} catch (WebException e) {
Log.toLog(this.getClass(), e);
}
}
});
}
}

View File

@ -4,9 +4,8 @@
*/
package com.djrapitops.plan.system.processing.processors.info;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
/**
* Processor for updating the network page.
@ -15,14 +14,19 @@ import com.djrapitops.plugin.api.utility.log.Log;
*/
public class NetworkPageUpdateProcessor implements Runnable {
private InfoSystem infoSystem;
private final InfoSystem infoSystem;
private final WebExceptionLogger webExceptionLogger;
NetworkPageUpdateProcessor(
InfoSystem infoSystem,
WebExceptionLogger webExceptionLogger
) {
this.infoSystem = infoSystem;
this.webExceptionLogger = webExceptionLogger;
}
@Override
public void run() {
try {
infoSystem.updateNetworkPage();
} catch (WebException e) {
Log.toLog(this.getClass(), e);
}
webExceptionLogger.logIfOccurs(this.getClass(), infoSystem::updateNetworkPage);
}
}

View File

@ -13,17 +13,26 @@ public class PlayerPageUpdateProcessor implements Runnable {
private final UUID uuid;
private InfoSystem infoSystem;
private WebExceptionLogger webExceptionLogger;
private final InfoSystem infoSystem;
private final WebExceptionLogger webExceptionLogger;
private final RunnableFactory runnableFactory;
public PlayerPageUpdateProcessor(UUID uuid) {
PlayerPageUpdateProcessor(
UUID uuid,
InfoSystem infoSystem,
WebExceptionLogger webExceptionLogger,
RunnableFactory runnableFactory
) {
this.uuid = uuid;
this.infoSystem = infoSystem;
this.webExceptionLogger = webExceptionLogger;
this.runnableFactory = runnableFactory;
}
@Override
public void run() {
if (!infoSystem.getConnectionSystem().isServerAvailable() || Check.isBungeeAvailable()) {
RunnableFactory.createNew("Generate Inspect page: " + uuid, new AbsRunnable() {
runnableFactory.create("Generate Inspect page: " + uuid, new AbsRunnable() {
@Override
public void run() {
try {

View File

@ -21,12 +21,16 @@ public class BanAndOpProcessor implements Runnable {
private final Supplier<Boolean> banned;
private final boolean op;
private Database database;
private final Database database;
public BanAndOpProcessor(UUID uuid, Supplier<Boolean> banned, boolean op) {
BanAndOpProcessor(
UUID uuid, Supplier<Boolean> banned, boolean op,
Database database
) {
this.uuid = uuid;
this.banned = banned;
this.op = op;
this.database = database;
}
@Override

View File

@ -15,20 +15,27 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class BungeePlayerRegisterProcessor implements CriticalRunnable {
public class BungeeRegisterProcessor implements CriticalRunnable {
private final UUID uuid;
private final String name;
private final long registered;
private final Runnable[] afterProcess;
private Processing processing;
private Database database;
private final Processing processing;
private final Database database;
public BungeePlayerRegisterProcessor(UUID uuid, String name, long registered, Runnable... afterProcess) {
BungeeRegisterProcessor(
UUID uuid, String name, long registered,
Processing processing,
Database database,
Runnable... afterProcess
) {
this.uuid = uuid;
this.name = name;
this.registered = registered;
this.processing = processing;
this.database = database;
this.afterProcess = afterProcess;
}

View File

@ -19,13 +19,16 @@ public class EndSessionProcessor implements CriticalRunnable {
private final UUID uuid;
private final long time;
public EndSessionProcessor(UUID uuid, long time) {
private final SessionCache sessionCache;
EndSessionProcessor(UUID uuid, long time, SessionCache sessionCache) {
this.uuid = uuid;
this.time = time;
this.sessionCache = sessionCache;
}
@Override
public void run() {
SessionCache.getInstance().endSession(uuid, time);
sessionCache.endSession(uuid, time);
}
}

View File

@ -9,7 +9,6 @@ import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.CriticalRunnable;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log;
import java.net.InetAddress;
import java.security.NoSuchAlgorithmException;
@ -26,23 +25,27 @@ public class IPUpdateProcessor implements CriticalRunnable {
private final InetAddress ip;
private final long time;
private Database database;
private final Database database;
public IPUpdateProcessor(UUID uuid, InetAddress ip, long time) {
IPUpdateProcessor(
UUID uuid, InetAddress ip, long time,
Database database
) {
this.uuid = uuid;
this.ip = ip;
this.time = time;
this.database = database;
}
@Override
public void run() {
if (Settings.DATA_GEOLOCATIONS.isTrue()) {
String country = GeolocationCache.getCountry(ip.getHostAddress());
try {
String country = GeolocationCache.getCountry(ip.getHostAddress());
GeoInfo geoInfo = new GeoInfo(ip, country, time);
database.save().geoInfo(uuid, geoInfo);
} catch (NoSuchAlgorithmException e) {
Log.toLog(this.getClass(), e);
} catch (NoSuchAlgorithmException ignore) {
// Ignored, SHA-256 should be available
}
}
}

View File

@ -18,10 +18,11 @@ public class KickProcessor implements CriticalRunnable {
private final UUID uuid;
private Database database;
private final Database database;
public KickProcessor(UUID uuid) {
KickProcessor(UUID uuid, Database database) {
this.uuid = uuid;
this.database = database;
}
@Override

View File

@ -1,11 +1,8 @@
package com.djrapitops.plan.system.processing.processors.player;
import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.processing.CriticalRunnable;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.Optional;
import java.util.UUID;
@ -19,26 +16,17 @@ import java.util.UUID;
* @author Rsl1122
* @since 4.0.0
*/
public class KillProcessor implements CriticalRunnable {
public class MobKillProcessor implements CriticalRunnable {
private final UUID uuid;
private final LivingEntity dead;
private final String weaponName;
private final long time;
/**
* Constructor.
*
* @param uuid UUID of the killer.
* @param time Epoch ms the event occurred.
* @param dead Dead entity (Mob or Player)
* @param weaponName Weapon used.
*/
public KillProcessor(UUID uuid, long time, LivingEntity dead, String weaponName) {
public MobKillProcessor(UUID uuid) {
this.uuid = uuid;
this.time = time;
this.dead = dead;
this.weaponName = weaponName;
}
@Override
@ -49,11 +37,6 @@ public class KillProcessor implements CriticalRunnable {
}
Session session = cachedSession.get();
if (dead instanceof Player) {
Player deadPlayer = (Player) dead;
session.playerKilled(new PlayerKill(deadPlayer.getUniqueId(), weaponName, time));
} else {
session.mobKilled();
}
}
}

View File

@ -25,17 +25,23 @@ public class NameProcessor implements CriticalRunnable {
private final String playerName;
private final Nickname nickname;
private Database database;
private final Database database;
private final DataCache dataCache;
public NameProcessor(UUID uuid, String playerName, String displayName) {
NameProcessor(
UUID uuid, String playerName, String displayName,
Database database,
DataCache dataCache
) {
this.uuid = uuid;
this.playerName = playerName;
this.nickname = new Nickname(displayName, System.currentTimeMillis(), ServerInfo.getServerUUID_Old());
this.database = database;
this.dataCache = dataCache;
}
@Override
public void run() {
DataCache dataCache = DataCache.getInstance();
String cachedName = dataCache.getName(uuid);
String cachedDisplayName = dataCache.getDisplayName(uuid);

View File

@ -26,11 +26,15 @@ public class PingInsertProcessor implements CriticalRunnable {
private final UUID uuid;
private final List<DateObj<Integer>> pingList;
private Database database;
private final Database database;
public PingInsertProcessor(UUID uuid, List<DateObj<Integer>> pingList) {
public PingInsertProcessor(
UUID uuid, List<DateObj<Integer>> pingList,
Database database
) {
this.uuid = uuid;
this.pingList = pingList;
this.database = database;
}
@Override

View File

@ -15,42 +15,38 @@ import java.util.UUID;
* Adds PlayerKill or a Mob kill to the active Session.
*
* @author Rsl1122
* @since 4.3.0
* @since 4.0.0
*/
public class SpongeKillProcessor implements CriticalRunnable {
public class PlayerKillProcessor implements CriticalRunnable {
private final UUID uuid;
private final UUID deadUUID;
private final UUID killer;
private final UUID victim;
private final String weaponName;
private final long time;
/**
* Constructor.
*
* @param uuid UUID of the killer.
* @param killer UUID of the killer.
* @param time Epoch ms the event occurred.
* @param deadUUID Dead entity (Mob or Player)
* @param victim Dead entity (Mob or Player)
* @param weaponName Weapon used.
*/
public SpongeKillProcessor(UUID uuid, long time, UUID deadUUID, String weaponName) {
this.uuid = uuid;
public PlayerKillProcessor(UUID killer, long time, UUID victim, String weaponName) {
this.killer = killer;
this.time = time;
this.deadUUID = deadUUID;
this.victim = victim;
this.weaponName = weaponName;
}
@Override
public void run() {
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
Optional<Session> cachedSession = SessionCache.getCachedSession(killer);
if (!cachedSession.isPresent()) {
return;
}
Session session = cachedSession.get();
if (deadUUID != null) {
session.playerKilled(new PlayerKill(deadUUID, weaponName, time));
} else {
session.mobKilled();
}
session.playerKilled(new PlayerKill(victim, weaponName, time));
}
}

View File

@ -0,0 +1,71 @@
package com.djrapitops.plan.system.processing.processors.player;
import com.djrapitops.plan.data.store.objects.DateObj;
import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.Processing;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.net.InetAddress;
import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;
/**
* Factory for creating Runnables related to Player data to run with {@link com.djrapitops.plan.system.processing.Processing}.
*
* @author Rsl1122
*/
@Singleton
public class PlayerProcessors {
private final Lazy<Processing> processing;
private final Lazy<Database> database;
private final Lazy<DataCache> dataCache;
@Inject
public PlayerProcessors(
Lazy<Processing> processing,
Lazy<Database> database,
Lazy<DataCache> dataCache
) {
this.processing = processing;
this.database = database;
this.dataCache = dataCache;
}
public BanAndOpProcessor banAndOpProcessor(UUID uuid, Supplier<Boolean> banned, boolean op) {
return new BanAndOpProcessor(uuid, banned, op, database.get());
}
public BungeeRegisterProcessor bungeeRegisterProcessor(UUID uuid, String name, long registered, Runnable... afterProcess) {
return new BungeeRegisterProcessor(uuid, name, registered, processing.get(), database.get(), afterProcess);
}
public EndSessionProcessor endSessionProcessor(UUID uuid, long time) {
return new EndSessionProcessor(uuid, time, dataCache.get());
}
public IPUpdateProcessor ipUpdateProcessor(UUID uuid, InetAddress ip, long time) {
return new IPUpdateProcessor(uuid, ip, time, database.get());
}
public KickProcessor kickProcessor(UUID uuid) {
return new KickProcessor(uuid, database.get());
}
public NameProcessor nameProcessor(UUID uuid, String playerName, String displayName) {
return new NameProcessor(uuid, playerName, displayName, database.get(), dataCache.get());
}
public PingInsertProcessor pingInsertProcessor(UUID uuid, List<DateObj<Integer>> pingList) {
return new PingInsertProcessor(uuid, pingList, database.get());
}
public RegisterProcessor registerProcessor(UUID uuid, Supplier<Long> registered, String name, Runnable... afterProcess) {
return new RegisterProcessor(uuid, registered, name, processing.get(), database.get(), afterProcess);
}
}

View File

@ -26,13 +26,19 @@ public class RegisterProcessor extends AbsRunnable {
private final String name;
private final Runnable[] afterProcess;
private Processing processing;
private Database database;
private final Processing processing;
private final Database database;
public RegisterProcessor(UUID uuid, Supplier<Long> registered, String name, Runnable... afterProcess) {
RegisterProcessor(
UUID uuid, Supplier<Long> registered, String name,
Processing processing, Database database,
Runnable... afterProcess
) {
this.uuid = uuid;
this.registered = registered;
this.name = name;
this.processing = processing;
this.database = database;
this.afterProcess = afterProcess;
}

View File

@ -2,7 +2,7 @@ package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -20,13 +20,20 @@ public abstract class TPSCountTimer extends AbsRunnable {
protected final List<TPS> history;
protected final Processors processors;
protected final Processing processing;
protected final PluginLogger logger;
protected final ErrorHandler errorHandler;
protected int latestPlayersOnline = 0;
public TPSCountTimer(Processing processing, PluginLogger logger, ErrorHandler errorHandler) {
public TPSCountTimer(
Processors processors,
Processing processing,
PluginLogger logger,
ErrorHandler errorHandler
) {
this.processors = processors;
this.processing = processing;
this.logger = logger;
this.errorHandler = errorHandler;
@ -42,7 +49,7 @@ public abstract class TPSCountTimer extends AbsRunnable {
addNewTPSEntry(nanoTime, now);
if (history.size() >= 60) {
processing.submit(new TPSInsertProcessor(new ArrayList<>(history)));
processing.submit(processors.tpsInsertProcessor(new ArrayList<>(history)));
history.clear();
}
} catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -18,12 +19,13 @@ public class BungeeTPSCountTimer extends TPSCountTimer {
@Inject
public BungeeTPSCountTimer(
Processors processors,
Processing processing,
ServerProperties serverProperties,
PluginLogger logger,
ErrorHandler errorHandler
) {
super(processing, logger, errorHandler);
super(processors, processing, logger, errorHandler);
this.serverProperties = serverProperties;
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
@ -26,12 +27,13 @@ public class BukkitTPSCountTimer extends TPSCountTimer {
@Inject
public BukkitTPSCountTimer(
Plan plugin,
Processors processors,
Processing processing,
ServerProperties serverProperties,
PluginLogger logger,
ErrorHandler errorHandler
) {
super(processing, logger, errorHandler);
super(processors, processing, logger, errorHandler);
this.plugin = plugin;
this.serverProperties = serverProperties;
lastCheckNano = -1;

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.bukkit.World;
@ -15,12 +16,13 @@ public class PaperTPSCountTimer extends BukkitTPSCountTimer {
@Inject
public PaperTPSCountTimer(
Plan plugin,
Processors processors,
Processing processing,
ServerProperties serverProperties,
PluginLogger logger,
ErrorHandler errorHandler
) {
super(plugin, processing, serverProperties, logger, errorHandler);
super(plugin, processors, processing, serverProperties, logger, errorHandler);
}
@Override

View File

@ -25,7 +25,7 @@ package com.djrapitops.plan.system.tasks.server;
import com.djrapitops.plan.data.store.objects.DateObj;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.player.PingInsertProcessor;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.utilities.java.Reflection;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
@ -92,14 +92,17 @@ public class PingCountTimer extends AbsRunnable implements Listener {
private final Map<UUID, List<DateObj<Integer>>> playerHistory;
private final Processors processors;
private final Processing processing;
private final RunnableFactory runnableFactory;
@Inject
public PingCountTimer(
Processors processors,
Processing processing,
RunnableFactory runnableFactory
) {
this.processors = processors;
this.processing = processing;
this.runnableFactory = runnableFactory;
playerHistory = new HashMap<>();
@ -129,7 +132,7 @@ public class PingCountTimer extends AbsRunnable implements Listener {
}
history.add(new DateObj<>(time, ping));
if (history.size() >= 30) {
processing.submit(new PingInsertProcessor(uuid, new ArrayList<>(history)));
processing.submit(processors.player().pingInsertProcessor(uuid, new ArrayList<>(history)));
history.clear();
}
} else {

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.Processors;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.logging.console.PluginLogger;
@ -24,12 +25,13 @@ public class SpongeTPSCountTimer extends TPSCountTimer {
@Inject
public SpongeTPSCountTimer(
Processors processors,
Processing processing,
ServerProperties serverProperties,
PluginLogger logger,
ErrorHandler errorHandler
) {
super(processing, logger, errorHandler);
super(processors, processing, logger, errorHandler);
this.serverProperties = serverProperties;
lastCheckNano = -1;
}

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
import com.djrapitops.plan.system.database.databases.sql.tables.*;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor;
import com.djrapitops.plan.utilities.Base64Util;
import com.djrapitops.plan.utilities.SHA256Hash;
import com.djrapitops.plugin.StaticHolder;
@ -857,23 +856,6 @@ public class SQLiteTest {
assertEquals(createWorldTimes(), worldTimesOfServer);
}
@Test
public void testRegisterProcessorRegisterException() {
assertFalse(db.getUsersTable().isRegistered(playerUUID));
assertFalse(db.getUserInfoTable().isRegistered(playerUUID));
System.out.println("\n- Running RegisterProcessors -");
List<RegisterProcessor> processors = new ArrayList<>();
for (int i = 0; i < 200; i++) {
processors.add(new RegisterProcessor(playerUUID, () -> 500L, "name"));
}
for (RegisterProcessor processor : processors) {
processor.run();
}
System.out.println("- RegisterProcessors Run -\n");
assertTrue(db.getUsersTable().isRegistered(playerUUID));
assertTrue(db.getUserInfoTable().isRegistered(playerUUID));
}
@Test
public void testRegister() {
assertFalse(db.check().isPlayerRegistered(playerUUID));