From d2bfa99ebdf505b832081eec8478bd4847fe95b4 Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Mon, 14 Nov 2022 10:14:04 +0100 Subject: [PATCH 01/10] added IntelliJ files to Git ignore list --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 408c231..eb0e1a5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ # netbeans /nbproject +# IntelliJ IDEA +/.idea/ + # we use maven! /build.xml @@ -22,4 +25,4 @@ /manifest.mf # Mac filesystem dust -/.DS_Store \ No newline at end of file +/.DS_Store From 50b0a72b9ea42680fb3b71a72bff783bf761aacb Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Mon, 14 Nov 2022 11:24:16 +0100 Subject: [PATCH 02/10] added configuration property to enable visibility by WorldGuard flags --- src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 74d9aad..441206b 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -66,6 +66,7 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { Set hidden; boolean stop; int maxdepth; + boolean visibilityByFlags = false; @Override public void onLoad() { @@ -452,6 +453,7 @@ private void activate() { infowindow = cfg.getString("infowindow", DEF_INFOWINDOW); maxdepth = cfg.getInt("maxdepth", 16); updatesPerTick = cfg.getInt("updates-per-tick", 20); + visibilityByFlags = cfg.getBoolean("visibility-by-flags", false); /* Get style information */ defstyle = new AreaStyle(cfg, "regionstyle"); From bf2f6f16d1aef2f239082e64937f24bd62858e2f Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Mon, 14 Nov 2022 11:34:12 +0100 Subject: [PATCH 03/10] added visibility WorldGuard flag --- .../worldguard/DynmapWorldGuardPlugin.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 441206b..89b8624 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -11,6 +11,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; @@ -47,10 +48,12 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { private static Logger log; private static final String DEF_INFOWINDOW = "
%regionname%
Owner %playerowners%
Flags
%flags%
"; public static final String BOOST_FLAG = "dynmap-boost"; + public static final String VISIBLE_FLAG = "dynmap-showonmap"; Plugin dynmap; DynmapAPI api; MarkerAPI markerapi; BooleanFlag boost_flag; + BooleanFlag visible_flag; int updatesPerTick = 20; FileConfiguration cfg; @@ -401,9 +404,10 @@ public void onEnable() { } private void registerCustomFlags() { + FlagRegistry fr = WorldGuard.getInstance().getFlagRegistry(); + try { BooleanFlag bf = new BooleanFlag(BOOST_FLAG); - FlagRegistry fr = WorldGuard.getInstance().getFlagRegistry(); fr.register(bf); boost_flag = bf; } catch (Exception x) { @@ -412,6 +416,17 @@ private void registerCustomFlags() { if (boost_flag == null) { log.info("Custom flag '" + BOOST_FLAG + "' not registered"); } + + try { + BooleanFlag visibleFlag = new BooleanFlag(VISIBLE_FLAG); + fr.register(visibleFlag); + visible_flag = visibleFlag; + } catch (FlagConflictException ex) { + log.info("Error registering flag - " + ex.getMessage()); + } + if (visible_flag == null) { + log.info("Custom flag '" + VISIBLE_FLAG + "' not registered"); + } } private boolean reload = false; From 931ea87572360fc5e37c7fef5906427986dd8d4a Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Mon, 14 Nov 2022 11:38:58 +0100 Subject: [PATCH 04/10] added hide by default configuration option --- .../java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 89b8624..56aff0d 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -69,7 +69,8 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { Set hidden; boolean stop; int maxdepth; - boolean visibilityByFlags = false; + boolean visibilityByFlagsEnable = false; + boolean visibilityByFlagsDefault = true; @Override public void onLoad() { @@ -468,7 +469,8 @@ private void activate() { infowindow = cfg.getString("infowindow", DEF_INFOWINDOW); maxdepth = cfg.getInt("maxdepth", 16); updatesPerTick = cfg.getInt("updates-per-tick", 20); - visibilityByFlags = cfg.getBoolean("visibility-by-flags", false); + visibilityByFlagsEnable = cfg.getBoolean("visibility-by-flags.enable", false); + visibilityByFlagsDefault = cfg.getBoolean("visibility-by-flags.hide-by-default", true); /* Get style information */ defstyle = new AreaStyle(cfg, "regionstyle"); From 39ffc7a3b86e44e607c33ee73b3b8609ba0fa889 Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Mon, 14 Nov 2022 16:27:29 +0100 Subject: [PATCH 05/10] added visibility check by WorldGuard flags --- .../worldguard/DynmapWorldGuardPlugin.java | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 56aff0d..cf19cf0 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -44,16 +44,20 @@ import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionType; +import javax.annotation.Nullable; + public class DynmapWorldGuardPlugin extends JavaPlugin { private static Logger log; private static final String DEF_INFOWINDOW = "
%regionname%
Owner %playerowners%
Flags
%flags%
"; public static final String BOOST_FLAG = "dynmap-boost"; public static final String VISIBLE_FLAG = "dynmap-showonmap"; + public static final String HIDE_FLAG = "dynmap-hideonmap"; Plugin dynmap; DynmapAPI api; MarkerAPI markerapi; BooleanFlag boost_flag; BooleanFlag visible_flag; + BooleanFlag hide_flag; int updatesPerTick = 20; FileConfiguration cfg; @@ -69,8 +73,8 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { Set hidden; boolean stop; int maxdepth; - boolean visibilityByFlagsEnable = false; - boolean visibilityByFlagsDefault = true; + boolean vbfEnable = false; + boolean vbfHideByDefault = true; @Override public void onLoad() { @@ -151,6 +155,31 @@ private boolean isVisible(String id, String worldname) { } return true; } + + private boolean isVisible( + final @Nullable ProtectedRegion region, + final @Nullable World world + ) { + if (region == null || world == null) + return false; + + if (!(this.isVisible(region.getId(), world.getName()))) + return false; + + if (vbfEnable) { + Boolean hideFlag = region.getFlag(hide_flag); + if (hideFlag != null && hideFlag) + return false; + + if (vbfHideByDefault) { + Boolean visibleFlag = region.getFlag(visible_flag); + if (visibleFlag == null || !visibleFlag) + return false; + } + } + + return true; + } private void addStyle(String resid, String worldid, AreaMarker m, ProtectedRegion region) { AreaStyle as = cusstyle.get(worldid + "/" + resid); @@ -242,7 +271,7 @@ private void handleRegion(World world, ProtectedRegion region, Map Date: Tue, 15 Nov 2022 15:44:04 +0100 Subject: [PATCH 06/10] merged two WorldGuard flags into one --- .../worldguard/DynmapWorldGuardPlugin.java | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index cf19cf0..9e9ea7e 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -51,13 +51,11 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { private static final String DEF_INFOWINDOW = "
%regionname%
Owner %playerowners%
Flags
%flags%
"; public static final String BOOST_FLAG = "dynmap-boost"; public static final String VISIBLE_FLAG = "dynmap-showonmap"; - public static final String HIDE_FLAG = "dynmap-hideonmap"; Plugin dynmap; DynmapAPI api; MarkerAPI markerapi; BooleanFlag boost_flag; BooleanFlag visible_flag; - BooleanFlag hide_flag; int updatesPerTick = 20; FileConfiguration cfg; @@ -167,15 +165,12 @@ private boolean isVisible( return false; if (vbfEnable) { - Boolean hideFlag = region.getFlag(hide_flag); - if (hideFlag != null && hideFlag) - return false; + Boolean visibleFlag = region.getFlag(visible_flag); - if (vbfHideByDefault) { - Boolean visibleFlag = region.getFlag(visible_flag); - if (visibleFlag == null || !visibleFlag) - return false; - } + if (visibleFlag == null) + return !vbfHideByDefault; + + return visibleFlag; } return true; @@ -457,17 +452,6 @@ private void registerCustomFlags() { if (visible_flag == null) { log.info("Custom flag '" + VISIBLE_FLAG + "' not registered"); } - - try { - BooleanFlag hideFlag = new BooleanFlag(HIDE_FLAG); - fr.register(hideFlag); - hide_flag = hideFlag; - } catch (FlagConflictException ex) { - log.info("Error registering flag - " + ex.getMessage()); - } - if (hide_flag == null) { - log.info("Custom flag '" + HIDE_FLAG + "' not registered"); - } } private boolean reload = false; From 60421bc3ce89df4d8d0b72ecc0733389e6a3f596 Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Tue, 15 Nov 2022 15:46:32 +0100 Subject: [PATCH 07/10] reformatted source code --- .../worldguard/DynmapWorldGuardPlugin.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 9e9ea7e..4963a4d 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -71,7 +71,7 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { Set hidden; boolean stop; int maxdepth; - boolean vbfEnable = false; + boolean vbfEnable = false; boolean vbfHideByDefault = true; @Override @@ -158,17 +158,20 @@ private boolean isVisible( final @Nullable ProtectedRegion region, final @Nullable World world ) { - if (region == null || world == null) + if (region == null || world == null) { return false; + } - if (!(this.isVisible(region.getId(), world.getName()))) + if (!(this.isVisible(region.getId(), world.getName()))) { return false; + } if (vbfEnable) { Boolean visibleFlag = region.getFlag(visible_flag); - if (visibleFlag == null) + if (visibleFlag == null) { return !vbfHideByDefault; + } return visibleFlag; } @@ -493,8 +496,14 @@ private void activate() { infowindow = cfg.getString("infowindow", DEF_INFOWINDOW); maxdepth = cfg.getInt("maxdepth", 16); updatesPerTick = cfg.getInt("updates-per-tick", 20); - vbfEnable = cfg.getBoolean("visibility-by-flags.enable", false); - vbfHideByDefault = cfg.getBoolean("visibility-by-flags.hide-by-default", true); + vbfEnable = cfg.getBoolean( + "visibility-by-flags.enable", + false + ); + vbfHideByDefault = cfg.getBoolean( + "visibility-by-flags.hide-by-default", + true + ); /* Get style information */ defstyle = new AreaStyle(cfg, "regionstyle"); From 577bac324d40baa6a6fc29114542e23caf156849 Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Mon, 14 Nov 2022 21:35:35 +0100 Subject: [PATCH 08/10] added configuration options to default config file --- src/main/resources/config.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1fa8105..a137a10 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -52,3 +52,8 @@ maxdepth: 16 # Limit number of regions processed per tick (avoid lag spikes on servers with lots of regions) updates-per-tick: 20 + +# Control the visibility of regions by WorldGuard flags +visibility-by-flags: + enable: false + hide-by-default: true From 2e6761705f4fef9c1edd637eb639ce539fa70b72 Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Tue, 15 Nov 2022 16:37:56 +0100 Subject: [PATCH 09/10] added descriptive comments to default configuration file --- .../java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java | 4 ++-- src/main/resources/config.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 4963a4d..9645574 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -178,7 +178,7 @@ private boolean isVisible( return true; } - + private void addStyle(String resid, String worldid, AreaMarker m, ProtectedRegion region) { AreaStyle as = cusstyle.get(worldid + "/" + resid); if(as == null) { @@ -456,7 +456,7 @@ private void registerCustomFlags() { log.info("Custom flag '" + VISIBLE_FLAG + "' not registered"); } } - + private boolean reload = false; private void activate() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a137a10..232c12d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -55,5 +55,7 @@ updates-per-tick: 20 # Control the visibility of regions by WorldGuard flags visibility-by-flags: + # Enable the feature to use WorldGuard flags to control visibility of regions enable: false + # Hide regions, without the 'dynmap-showonmap' WorldGuard flag hide-by-default: true From f2081a063bddfdcd99d2a4de8f73378a8eb094d6 Mon Sep 17 00:00:00 2001 From: ChrissW-R1 Date: Wed, 16 Nov 2022 13:00:52 +0100 Subject: [PATCH 10/10] removed unused attribute initialization --- .../org/dynmap/worldguard/DynmapWorldGuardPlugin.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 9645574..9f65f71 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -71,8 +71,8 @@ public class DynmapWorldGuardPlugin extends JavaPlugin { Set hidden; boolean stop; int maxdepth; - boolean vbfEnable = false; - boolean vbfHideByDefault = true; + boolean vbfEnabled; + boolean vbfHideByDefault; @Override public void onLoad() { @@ -166,7 +166,7 @@ private boolean isVisible( return false; } - if (vbfEnable) { + if (vbfEnabled) { Boolean visibleFlag = region.getFlag(visible_flag); if (visibleFlag == null) { @@ -496,7 +496,7 @@ private void activate() { infowindow = cfg.getString("infowindow", DEF_INFOWINDOW); maxdepth = cfg.getInt("maxdepth", 16); updatesPerTick = cfg.getInt("updates-per-tick", 20); - vbfEnable = cfg.getBoolean( + vbfEnabled = cfg.getBoolean( "visibility-by-flags.enable", false );