From 5d4ccdca206ccc839346be865aaeabca44795873 Mon Sep 17 00:00:00 2001 From: RoboMWM Date: Fri, 7 Oct 2016 19:29:36 -0700 Subject: [PATCH] Completely remove PlayerData#LastLogin Not tested, but other than maintaining SQL storage "compatibility" I've removed all usages of it. It doesn't seem to be used at all anyways other than to be stored since commit f935806b45ea216ea9b268f51a1fde6508891e5f removed its purpose. Addresses a request in #22 --- pom.xml | 8 ++--- .../GriefPrevention/DatabaseDataStore.java | 6 ++-- .../GriefPrevention/FlatFileDataStore.java | 36 +++++++++---------- .../GriefPrevention/GriefPrevention.java | 2 +- .../GriefPrevention/PlayerData.java | 32 ----------------- .../GriefPrevention/PlayerEventHandler.java | 4 +-- 6 files changed, 27 insertions(+), 61 deletions(-) diff --git a/pom.xml b/pom.xml index b2b95ae..d665e12 100644 --- a/pom.xml +++ b/pom.xml @@ -56,10 +56,10 @@ - com.destroystokyo.paper - paper-api - 1.10.2-R0.1-SNAPSHOT - provided + org.bukkit + bukkit + 1.10.2-R0.1-SNAPSHOT + provided diff --git a/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java b/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java index c6875fa..6dbe6b6 100644 --- a/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java @@ -500,8 +500,7 @@ public class DatabaseDataStore extends DataStore //if data for this player exists, use it if(results.next()) - { - playerData.setLastLogin(results.getTimestamp("lastlogin")); + { playerData.setAccruedClaimBlocks(results.getInt("accruedblocks")); playerData.setBonusClaimBlocks(results.getInt("bonusblocks")); } @@ -531,9 +530,10 @@ public class DatabaseDataStore extends DataStore try { this.refreshDataConnection(); + OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(playerID)); SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String dateString = sqlFormat.format(playerData.getLastLogin()); + String dateString = sqlFormat.format(new Date(player.getLastPlayed())); Statement statement = databaseConnection.createStatement(); statement.execute("DELETE FROM griefprevention_playerdata WHERE name='" + playerID.toString() + "';"); diff --git a/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java b/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java index 17737c7..8fc1397 100644 --- a/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java @@ -613,20 +613,20 @@ public class FlatFileDataStore extends DataStore List lines = Files.readLines(playerFile, Charset.forName("UTF-8")); Iterator iterator = lines.iterator(); - //first line is last login timestamp - String lastLoginTimestampString = iterator.next(); - - //convert that to a date and store it - DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); - try - { - playerData.setLastLogin(dateFormat.parse(lastLoginTimestampString)); - } - catch(ParseException parseException) - { - GriefPrevention.AddLogEntry("Unable to load last login for \"" + playerFile.getName() + "\"."); - playerData.setLastLogin(null); - } + //first line is last login timestamp //RoboMWM - not using this anymore +// String lastLoginTimestampString = iterator.next(); +// +// //convert that to a date and store it +// DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); +// try +// { +// playerData.setLastLogin(dateFormat.parse(lastLoginTimestampString)); +// } +// catch(ParseException parseException) +// { +// GriefPrevention.AddLogEntry("Unable to load last login for \"" + playerFile.getName() + "\"."); +// playerData.setLastLogin(null); +// } //second line is accrued claim blocks String accruedBlocksString = iterator.next(); @@ -683,10 +683,10 @@ public class FlatFileDataStore extends DataStore StringBuilder fileContent = new StringBuilder(); try { - //first line is last login timestamp - if(playerData.getLastLogin() == null) playerData.setLastLogin(new Date()); - DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); - fileContent.append(dateFormat.format(playerData.getLastLogin())); + //first line is last login timestamp //RoboMWM - no longer storing/using + //if(playerData.getLastLogin() == null) playerData.setLastLogin(new Date()); + //DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); + //fileContent.append(dateFormat.format(playerData.getLastLogin())); fileContent.append("\n"); //second line is accrued claim blocks diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index cfe4af5..122e3ee 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -776,7 +776,7 @@ public class GriefPrevention extends JavaPlugin catch(NoSuchMethodError e) { this.getLogger().severe("You are running an old version of Java which is susceptible to security exploits. Please update to Java 8."); - this.getLogger().severe("If you are on a shared host, tell your hosting provider to update, as Java 7 is End of Life."); + this.getLogger().severe("If you are on a shared host, tell your hosting provider to update, as Java 7 is End of Life, and you're missing out on security and performance improvements"); this.getLogger().severe("If they refuse, I'd suggesting switching to a more secure and responsive host."); this.getLogger().severe("But if you truly have absolutely no choice, then please download the Java 7 version of GriefPrevention."); getServer().getPluginManager().disablePlugin(this); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerData.java b/src/me/ryanhamshire/GriefPrevention/PlayerData.java index d3c716c..c97ed91 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerData.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerData.java @@ -83,9 +83,6 @@ public class PlayerData //whether the player was kicked (set and used during logout) boolean wasKicked = false; - - //spam - private Date lastLogin = null; //when the player last logged into the server //visualization public Visualization currentVisualization = null; @@ -216,41 +213,12 @@ public class PlayerData { this.bonusClaimBlocks = bonusClaimBlocks; } - - public Date getLastLogin() - { - if(this.lastLogin == null) this.loadDataFromSecondaryStorage(); - return this.lastLogin; - } - - public void setLastLogin(Date lastLogin) - { - this.lastLogin = lastLogin; - } private void loadDataFromSecondaryStorage() { //reach out to secondary storage to get any data there PlayerData storageData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(this.playerID); - //fill in any missing pieces - if(this.lastLogin == null) - { - if(storageData.lastLogin != null) - { - this.lastLogin = storageData.lastLogin; - } - else - { - //default last login date value to 5 minutes ago to ensure a brand new player can log in - //see login cooldown feature, PlayerEventHandler.onPlayerLogin() - //if the player successfully logs in, this value will be overwritten with the current date and time - Calendar fiveMinutesBack = Calendar.getInstance(); - fiveMinutesBack.add(Calendar.MINUTE, -5); - this.lastLogin = fiveMinutesBack.getTime(); - } - } - if(this.accruedClaimBlocks == null) { if(storageData.accruedClaimBlocks != null) diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 18406fa..1fec824 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -627,7 +627,6 @@ class PlayerEventHandler implements Listener long now = nowDate.getTime(); PlayerData playerData = this.dataStore.getPlayerData(playerID); playerData.lastSpawn = now; - playerData.setLastLogin(nowDate); this.lastLoginThisServerSessionMap.put(playerID, nowDate); //if newish, prevent chat until he's moved a bit to prove he's not a bot @@ -1870,8 +1869,7 @@ class PlayerEventHandler implements Listener { claim = claim.parent; } - PlayerData otherPlayerData = this.dataStore.getPlayerData(claim.ownerID); - Date lastLogin = otherPlayerData.getLastLogin(); + Date lastLogin = new Date(Bukkit.getOfflinePlayer(claim.ownerID).getLastPlayed()); Date now = new Date(); long daysElapsed = (now.getTime() - lastLogin.getTime()) / (1000 * 60 * 60 * 24);