From 20eb3d8c3a6ed4d6038cd4a8d1ec8ceec8f224b8 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 25 May 2018 09:00:33 +0300 Subject: [PATCH] Added IPUpdateProcessor to Bungee, deprecated MiscUtils#getTime --- .../system/listeners/bukkit/PlayerOnlineListener.java | 2 +- .../system/listeners/bungee/PlayerOnlineListener.java | 9 ++++++--- .../player/BungeePlayerRegisterProcessor.java | 10 +++++++++- .../processors/player/IPUpdateProcessor.java | 3 ++- .../java/com/djrapitops/plan/utilities/MiscUtils.java | 1 + .../plan/utilities/html/tables/GeoInfoTable.java | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index eda55f727..ad024967f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -83,7 +83,7 @@ public class PlayerOnlineListener implements Listener { NotificationCenter.checkNotifications(player); UUID uuid = player.getUniqueId(); - long time = MiscUtils.getTime(); + long time = System.currentTimeMillis(); AFKListener.AFK_TRACKER.performedAction(uuid, time); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java index 0ddc35709..786a3cb35 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java @@ -6,7 +6,7 @@ package com.djrapitops.plan.system.listeners.bungee; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.player.BungeePlayerRegisterProcessor; -import com.djrapitops.plan.utilities.MiscUtils; +import com.djrapitops.plan.system.processing.processors.player.IPUpdateProcessor; import com.djrapitops.plugin.api.utility.log.Log; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PostLoginEvent; @@ -28,9 +28,12 @@ public class PlayerOnlineListener implements Listener { ProxiedPlayer player = event.getPlayer(); UUID uuid = player.getUniqueId(); String name = player.getName(); - long now = MiscUtils.getTime(); + String ip = player.getAddress().getAddress().getHostAddress(); + long now = System.currentTimeMillis(); - Processing.submit(new BungeePlayerRegisterProcessor(uuid, name, now)); + Processing.submit(new BungeePlayerRegisterProcessor(uuid, name, now, + new IPUpdateProcessor(uuid, ip, now)) + ); } catch (Exception e) { Log.toLog(this.getClass(), e); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java index f4884a374..84b330cf4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java @@ -7,6 +7,7 @@ package com.djrapitops.plan.system.processing.processors.player; import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.processing.CriticalRunnable; +import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plugin.api.utility.log.Log; import java.util.UUID; @@ -21,11 +22,13 @@ public class BungeePlayerRegisterProcessor implements CriticalRunnable { private final UUID uuid; private final String name; private final long registered; + private final Runnable[] afterProcess; - public BungeePlayerRegisterProcessor(UUID uuid, String name, long registered) { + public BungeePlayerRegisterProcessor(UUID uuid, String name, long registered, Runnable... afterProcess) { this.uuid = uuid; this.name = name; this.registered = registered; + this.afterProcess = afterProcess; } @Override @@ -38,6 +41,11 @@ public class BungeePlayerRegisterProcessor implements CriticalRunnable { database.save().registerNewUser(uuid, registered, name); } catch (DBException e) { Log.toLog(this.getClass(), e); + } finally { + for (Runnable process : afterProcess) { + Processing.submit(process); + } + } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java index 7bebbaea4..67a1cc211 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java @@ -38,7 +38,8 @@ public class IPUpdateProcessor implements CriticalRunnable { if (Settings.DATA_GEOLOCATIONS.isTrue()) { String country = GeolocationCache.getCountry(ip); try { - Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time)); + GeoInfo geoInfo = new GeoInfo(ip, country, time); + Database.getActive().save().geoInfo(uuid, geoInfo); } catch (DBException | UnsupportedEncodingException | NoSuchAlgorithmException e) { Log.toLog(this.getClass(), e); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java index 18a740eeb..a00bb2154 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java @@ -37,6 +37,7 @@ public class MiscUtils { * * @return Epoch ms. */ + @Deprecated public static long getTime() { return System.currentTimeMillis(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/GeoInfoTable.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/GeoInfoTable.java index 0191a70ee..c5342e856 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/GeoInfoTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/GeoInfoTable.java @@ -33,7 +33,7 @@ public class GeoInfoTable extends TableContainer { for (GeoInfo info : geoInfo) { long date = info.getLastUsed(); addRow( - displayIP ? FormatUtils.formatIP(info.getIp()) : "Hidden (Config)", + displayIP ? info.getIp() : "Hidden (Config)", info.getGeolocation(), date != 0 ? FormatUtils.formatTimeStampYear(date) : "-" );