From 83b45966904f642227e34b695652bf7152d6da09 Mon Sep 17 00:00:00 2001 From: bloodshot Date: Wed, 24 Jul 2019 00:04:02 -0400 Subject: [PATCH] Fix claim visuals not reverting properly. Fixes #1 * Fix version. * Ignore '_nextClaimID' file during GP Bukkit migration. --- .../src/main/java/com/griefdefender/GDPlayerData.java | 10 +++++++++- .../java/com/griefdefender/GriefDefenderPlugin.java | 5 ++--- .../src/main/java/com/griefdefender/claim/GDClaim.java | 4 +++- .../com/griefdefender/command/CommandGDVersion.java | 8 +------- .../com/griefdefender/listener/BlockEventHandler.java | 2 ++ .../migrator/GriefPreventionMigrator.java | 4 ++++ 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/com/griefdefender/GDPlayerData.java b/bukkit/src/main/java/com/griefdefender/GDPlayerData.java index 25c4117..a299d57 100644 --- a/bukkit/src/main/java/com/griefdefender/GDPlayerData.java +++ b/bukkit/src/main/java/com/griefdefender/GDPlayerData.java @@ -180,8 +180,9 @@ public void revertActiveVisual(Player player) { this.visualRevertTask = null; } + GDClaim claim = null; if (this.visualClaimId != null) { - GDClaim claim = (GDClaim) GriefDefenderPlugin.getInstance().dataStore.getClaim(this.worldUniqueId, this.visualClaimId); + claim = (GDClaim) GriefDefenderPlugin.getInstance().dataStore.getClaim(this.worldUniqueId, this.visualClaimId); if (claim != null) { claim.playersWatching.remove(this.playerID); } @@ -193,6 +194,13 @@ public void revertActiveVisual(Player player) { for (int i = 0; i < this.visualBlocks.size(); i++) { BlockSnapshot snapshot = this.visualBlocks.get(i).getOriginal(); + // If original block does not exist, do not send to player + if (NMSUtil.getInstance().getBlockData(snapshot.getLocation().getBlock()) != snapshot.getState()) { + if (claim != null) { + claim.markVisualDirty = true; + } + continue; + } NMSUtil.getInstance().sendBlockChange(player, snapshot); } } diff --git a/bukkit/src/main/java/com/griefdefender/GriefDefenderPlugin.java b/bukkit/src/main/java/com/griefdefender/GriefDefenderPlugin.java index 17b6ae9..2b7b4a2 100644 --- a/bukkit/src/main/java/com/griefdefender/GriefDefenderPlugin.java +++ b/bukkit/src/main/java/com/griefdefender/GriefDefenderPlugin.java @@ -189,15 +189,14 @@ public class GriefDefenderPlugin { public static final String MOD_ID = "GriefDefender"; public static final String API_VERSION = GriefDefenderPlugin.class.getPackage().getSpecificationVersion(); public static final String IMPLEMENTATION_NAME = GriefDefenderPlugin.class.getPackage().getImplementationTitle(); - public static final String IMPLEMENTATION_VERSION = GriefDefenderPlugin.class.getPackage().getImplementationVersion(); - public static String VERSION = "1.0.0"; + public static final String IMPLEMENTATION_VERSION = GriefDefenderPlugin.class.getPackage().getImplementationVersion() == null ? "unknown" : GriefDefenderPlugin.class.getPackage().getImplementationVersion(); private Path configPath = Paths.get(".", "plugins", "GriefDefender"); public MessageStorage messageStorage; public MessageDataConfig messageData; public Map worldGeneratorRandoms = new HashMap<>(); public static ClaimBlockSystem CLAIM_BLOCK_SYSTEM; - public static final String CONFIG_HEADER = "1.0.0\n" + public static final String CONFIG_HEADER = IMPLEMENTATION_VERSION + "\n" + "# If you need help with the configuration or have any issues related to GriefDefender,\n" + "# create a ticket on https://github.com/bloodmc/GriefDefender/issues.\n" + "# Note: If you have not purchased GriefDefender, please consider doing so to get \n" diff --git a/bukkit/src/main/java/com/griefdefender/claim/GDClaim.java b/bukkit/src/main/java/com/griefdefender/claim/GDClaim.java index db5bc55..5cefc2b 100644 --- a/bukkit/src/main/java/com/griefdefender/claim/GDClaim.java +++ b/bukkit/src/main/java/com/griefdefender/claim/GDClaim.java @@ -131,6 +131,7 @@ public class GDClaim implements Claim { private UUID ownerUniqueId; public boolean cuboid = false; + public boolean markVisualDirty = false; protected ClaimStorageData claimStorage; protected IClaimData claimData; @@ -243,8 +244,9 @@ public void setType(ClaimType type) { } public ClaimVisual getVisualizer() { - if (this.claimVisual == null) { + if (this.claimVisual == null || this.markVisualDirty) { this.claimVisual = new ClaimVisual(this, ClaimVisual.getClaimVisualType(this)); + this.markVisualDirty = false; } return this.claimVisual; } diff --git a/bukkit/src/main/java/com/griefdefender/command/CommandGDVersion.java b/bukkit/src/main/java/com/griefdefender/command/CommandGDVersion.java index 2a24db2..087c2f7 100644 --- a/bukkit/src/main/java/com/griefdefender/command/CommandGDVersion.java +++ b/bukkit/src/main/java/com/griefdefender/command/CommandGDVersion.java @@ -47,16 +47,10 @@ public class CommandGDVersion extends BaseCommand { @Subcommand("version") public void execute(CommandSender src) { - String version = GriefDefenderPlugin.IMPLEMENTATION_VERSION; - if (version == null) { - version = "unknown"; - } - Component gpVersion = TextComponent.builder("") .append(GriefDefenderPlugin.GD_TEXT) .append("Running ") - // TODO : Use version from manifest - .append("GriefDefender " + GriefDefenderPlugin.VERSION, TextColor.AQUA) + .append("GriefDefender " + GriefDefenderPlugin.IMPLEMENTATION_VERSION, TextColor.AQUA) .build(); Component bukkitVersion = TextComponent.builder("") .append(GriefDefenderPlugin.GD_TEXT) diff --git a/bukkit/src/main/java/com/griefdefender/listener/BlockEventHandler.java b/bukkit/src/main/java/com/griefdefender/listener/BlockEventHandler.java index 676f062..1162455 100644 --- a/bukkit/src/main/java/com/griefdefender/listener/BlockEventHandler.java +++ b/bukkit/src/main/java/com/griefdefender/listener/BlockEventHandler.java @@ -526,6 +526,8 @@ public void onBlockBreak(BlockBreakEvent event) { GriefDefenderPlugin.sendClaimDenyMessage(targetClaim, player, message); } event.setCancelled(true); + } else { + targetClaim.markVisualDirty = true; } GDTimings.BLOCK_BREAK_EVENT.stopTiming(); diff --git a/bukkit/src/main/java/com/griefdefender/migrator/GriefPreventionMigrator.java b/bukkit/src/main/java/com/griefdefender/migrator/GriefPreventionMigrator.java index 8b996c3..9493489 100644 --- a/bukkit/src/main/java/com/griefdefender/migrator/GriefPreventionMigrator.java +++ b/bukkit/src/main/java/com/griefdefender/migrator/GriefPreventionMigrator.java @@ -76,6 +76,10 @@ public static void migrate(World world, Path gpClassicDataPath) throws FileNotFo int claimId = Integer.parseInt(file.getName().replaceFirst("[.][^.]+$", "")); idToUUID.put(claimId, UUID.randomUUID()); } catch (NumberFormatException e) { + if (file.getName().equalsIgnoreCase("_nextClaimID")) { + // GP keeps track of next claim ID in this file so we can safely ignore the exception + continue; + } e.printStackTrace(); continue; }