From 9635ade7594bf2eeb1698947cd85059ecc35eed6 Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 12 May 2017 14:42:12 +0300 Subject: [PATCH] Fix for incorrect player data caching on player quit and delayed save Small fix for bp check and NULL block --- .classpath | 37 ++++++++---- .project | 60 ++++++++++--------- com/gamingmesh/jobs/Jobs.java | 8 ++- com/gamingmesh/jobs/PlayerManager.java | 7 +-- .../jobs/config/GeneralConfigManager.java | 11 +++- com/gamingmesh/jobs/container/JobsPlayer.java | 16 ++++- com/gamingmesh/jobs/dao/JobsDAO.java | 4 +- .../jobs/listeners/JobsPaymentListener.java | 2 +- 8 files changed, 92 insertions(+), 53 deletions(-) diff --git a/.classpath b/.classpath index f27d03c8..2a6198a7 100644 --- a/.classpath +++ b/.classpath @@ -1,16 +1,27 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/.project b/.project index cf8ba2bf..4c9d97e5 100644 --- a/.project +++ b/.project @@ -1,27 +1,33 @@ - - - Jobs - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.ui.externaltools.ExternalToolBuilder - full,incremental, - - - LaunchConfigHandle - <project>/.externalToolBuilders/Create jar file.launch - - - - - - org.eclipse.jdt.core.javanature - - + + + Jobs + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/Create jar file.launch + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index 2ca550d3..3f8cb1bb 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -1041,9 +1041,11 @@ public class Jobs extends JavaPlugin { } //need to update bp - BlockProtection bp = BpManager.getBp(block.getLocation()); - if (bp != null) - bp.setPaid(true); + if (block != null) { + BlockProtection bp = BpManager.getBp(block.getLocation()); + if (bp != null) + bp.setPaid(true); + } } } diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 153ba456..50c731b7 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -175,15 +175,12 @@ public class PlayerManager { * @param playername */ public void playerQuit(Player player) { - JobsPlayer jPlayer = this.removePlayer(player); - if (jPlayer == null) - jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + JobsPlayer jPlayer = this.getJobsPlayer(player); if (jPlayer == null) return; - addPlayerToCache(jPlayer); if (Jobs.getGCManager().saveOnDisconnect()) { - jPlayer.save(); jPlayer.onDisconnect(); + jPlayer.save(); } else { jPlayer.onDisconnect(); } diff --git a/com/gamingmesh/jobs/config/GeneralConfigManager.java b/com/gamingmesh/jobs/config/GeneralConfigManager.java index 32dfbc29..3724ae40 100644 --- a/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -29,6 +29,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -283,6 +284,14 @@ public class GeneralConfigManager { return locale; } + public boolean canPerformActionInWorld(Entity ent) { + if (ent == null) + return true; + if (ent.getWorld() == null) + return true; + return canPerformActionInWorld(ent.getWorld()); + } + public boolean canPerformActionInWorld(Player player) { if (player == null) return true; @@ -414,7 +423,7 @@ public class GeneralConfigManager { "Player data is always periodically auto-saved and autosaved during a clean shutdown.", "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); saveOnDisconnect = c.get("save-on-disconnect", false); - + c.getW().addComment("selectionTool", "Tool used when selecting bounds for restricted area"); getSelectionTooldID = c.get("selectionTool", 294); if (Material.getMaterial(Jobs.getGCManager().getSelectionTooldID) == null) diff --git a/com/gamingmesh/jobs/container/JobsPlayer.java b/com/gamingmesh/jobs/container/JobsPlayer.java index 38e0166c..536ee172 100644 --- a/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/com/gamingmesh/jobs/container/JobsPlayer.java @@ -168,8 +168,14 @@ public class JobsPlayer { * @return the player */ public Player getPlayer() { - if (this.playerUUID != null) - this.player = Bukkit.getPlayer(this.playerUUID); + if (this.playerUUID != null){ + Player p = Bukkit.getPlayer(this.playerUUID); + if (p != null){ + this.player = p; + this.OffPlayer = p; + this.userName = player.getName(); + } + } return this.player; } @@ -625,6 +631,11 @@ public class JobsPlayer { dao.recordPlayersLimits(this); dao.updateSeen(this); setSaved(true); + + if (this.getPlayer() == null || !this.getPlayer().isOnline()){ + Jobs.getPlayerManager().addPlayerToCache(this); + Jobs.getPlayerManager().removePlayer(this.getPlayer()); + } } // } } @@ -644,6 +655,7 @@ public class JobsPlayer { // Jobs.getJobsDAO().savePoints(this); clearBossMaps(); isOnline = false; + Jobs.getPlayerManager().addPlayerToCache(this); } public void clearBossMaps() { diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 6625f8eb..205237fd 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -53,6 +53,7 @@ import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.container.PlayerPoints; import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.economy.PaymentData; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.TimeManage; /** @@ -923,6 +924,7 @@ public abstract class JobsDAO { * @param jobInfo - the information getting saved */ public void save(JobsPlayer player) { + Debug.D("saving player data " + player.getUserName()); JobsConnection conn = getConnection(); if (conn == null) return; @@ -1277,7 +1279,7 @@ public abstract class JobsDAO { Jobs.getBpManager().timer += System.currentTimeMillis() - t; } if (i > 0) { - String message = ChatColor.translateAlternateColorCodes('&', "&6[Jobs] loaded " + i + " block protection entries. " + Jobs.getBpManager().timer); + String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] loaded " + i + " block protection entries. " + Jobs.getBpManager().timer); Bukkit.getServer().getConsoleSender().sendMessage(message); } } catch (SQLException e) { diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 1cc47b22..0cd2a5aa 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -1041,7 +1041,7 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onTntExplode(EntityExplodeEvent event) { //disabling plugin in world - if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity())) return; // make sure plugin is enabled if (!this.plugin.isEnabled())