Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visibility flags #74

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# netbeans
/nbproject

# IntelliJ IDEA
/.idea/

# we use maven!
/build.xml

Expand All @@ -22,4 +25,4 @@
/manifest.mf

# Mac filesystem dust
/.DS_Store
/.DS_Store
60 changes: 56 additions & 4 deletions src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,14 +44,18 @@
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 = "<div class=\"infowindow\"><span style=\"font-size:120%;\">%regionname%</span><br /> Owner <span style=\"font-weight:bold;\">%playerowners%</span><br />Flags<br /><span style=\"font-weight:bold;\">%flags%</span></div>";
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;
Expand All @@ -66,6 +71,8 @@ public class DynmapWorldGuardPlugin extends JavaPlugin {
Set<String> hidden;
boolean stop;
int maxdepth;
boolean vbfEnabled;
boolean vbfHideByDefault;

@Override
public void onLoad() {
Expand Down Expand Up @@ -146,7 +153,32 @@ 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 (vbfEnabled) {
Boolean visibleFlag = region.getFlag(visible_flag);

if (visibleFlag == null) {
return !vbfHideByDefault;
}

return visibleFlag;
}

return true;
}

private void addStyle(String resid, String worldid, AreaMarker m, ProtectedRegion region) {
AreaStyle as = cusstyle.get(worldid + "/" + resid);
if(as == null) {
Expand Down Expand Up @@ -237,7 +269,7 @@ private void handleRegion(World world, ProtectedRegion region, Map<String, AreaM
double[] z = null;

/* Handle areas */
if(isVisible(region.getId(), world.getName())) {
if(isVisible(region, world)) {
String id = region.getId();
RegionType tn = region.getType();
BlockVector3 l0 = region.getMinimumPoint();
Expand Down Expand Up @@ -400,9 +432,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) {
Expand All @@ -411,8 +444,19 @@ 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;

private void activate() {
Expand Down Expand Up @@ -452,6 +496,14 @@ private void activate() {
infowindow = cfg.getString("infowindow", DEF_INFOWINDOW);
maxdepth = cfg.getInt("maxdepth", 16);
updatesPerTick = cfg.getInt("updates-per-tick", 20);
vbfEnabled = 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");
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ 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 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