From 7230abf5af40411668ff3bf5074eea31e5a446f9 Mon Sep 17 00:00:00 2001 From: Davo8888 Date: Fri, 14 Jun 2019 12:02:29 +0200 Subject: [PATCH] Update to WG 7.0.1 beta 01, WE 7.0.1 snapshot and Dynmap 3.0 beta 4 --- .../worldguard/DynmapWorldGuardPlugin.java | 934 ++++++++++-------- .../org/dynmap/worldguard/MetricsLite.java | 526 ++++------ src/main/resources/plugin.yml | 2 +- 3 files changed, 691 insertions(+), 771 deletions(-) diff --git a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java index 52940e7..eab1ded 100644 --- a/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java +++ b/src/main/java/org/dynmap/worldguard/DynmapWorldGuardPlugin.java @@ -1,16 +1,31 @@ package org.dynmap.worldguard; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.World; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.domains.DefaultDomain; +import com.sk89q.worldguard.domains.PlayerDomain; +import com.sk89q.worldguard.protection.flags.BooleanFlag; +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionType; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; - import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -18,493 +33,534 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.server.PluginEnableEvent; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.DynmapAPI; import org.dynmap.markers.AreaMarker; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerSet; -import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.World; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.domains.DefaultDomain; -import com.sk89q.worldguard.domains.PlayerDomain; -import com.sk89q.worldguard.internal.platform.WorldGuardPlatform; -import com.sk89q.worldguard.protection.flags.BooleanFlag; -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.sk89q.worldguard.protection.regions.RegionContainer; -import com.sk89q.worldguard.protection.regions.RegionType; -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"; - Plugin dynmap; - DynmapAPI api; - MarkerAPI markerapi; - BooleanFlag boost_flag; - int updatesPerTick = 20; - FileConfiguration cfg; - MarkerSet set; - long updperiod; - boolean use3d; - String infowindow; - AreaStyle defstyle; - Map cusstyle; - Map cuswildstyle; - Map ownerstyle; - Set visible; - Set hidden; - boolean stop; - int maxdepth; - @Override - public void onLoad() { - log = this.getLogger(); - this.registerCustomFlags(); + +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"; + Plugin dynmap; + DynmapAPI api; + MarkerAPI markerapi; + BooleanFlag boost_flag; + int updatesPerTick = 20; + + FileConfiguration cfg; + MarkerSet set; + long updperiod; + boolean use3d; + String infowindow; + AreaStyle defstyle; + Map cusstyle; + Map cuswildstyle; + Map ownerstyle; + Set visible; + Set hidden; + boolean stop; + int maxdepth; + + public void onLoad() { + log = getLogger(); + registerCustomFlags(); + } + + + private static class AreaStyle + { + String strokecolor; + String unownedstrokecolor; + double strokeopacity; + int strokeweight; + String fillcolor; + double fillopacity; + String label; + + AreaStyle(FileConfiguration cfg, String path, AreaStyle def) { + this.strokecolor = cfg.getString(String.valueOf(path) + ".strokeColor", def.strokecolor); + this.unownedstrokecolor = cfg.getString(String.valueOf(path) + ".unownedStrokeColor", def.unownedstrokecolor); + this.strokeopacity = cfg.getDouble(String.valueOf(path) + ".strokeOpacity", def.strokeopacity); + this.strokeweight = cfg.getInt(String.valueOf(path) + ".strokeWeight", def.strokeweight); + this.fillcolor = cfg.getString(String.valueOf(path) + ".fillColor", def.fillcolor); + this.fillopacity = cfg.getDouble(String.valueOf(path) + ".fillOpacity", def.fillopacity); + this.label = cfg.getString(String.valueOf(path) + ".label", null); } + - private static class AreaStyle { - String strokecolor; - String unownedstrokecolor; - double strokeopacity; - int strokeweight; - String fillcolor; - double fillopacity; - String label; + AreaStyle(FileConfiguration cfg, String path) { + this.strokecolor = cfg.getString(String.valueOf(path) + ".strokeColor", "#FF0000"); + this.unownedstrokecolor = cfg.getString(String.valueOf(path) + ".unownedStrokeColor", "#00FF00"); + this.strokeopacity = cfg.getDouble(String.valueOf(path) + ".strokeOpacity", 0.8D); + this.strokeweight = cfg.getInt(String.valueOf(path) + ".strokeWeight", 3); + this.fillcolor = cfg.getString(String.valueOf(path) + ".fillColor", "#FF0000"); + this.fillopacity = cfg.getDouble(String.valueOf(path) + ".fillOpacity", 0.35D); + } + } - AreaStyle(FileConfiguration cfg, String path, AreaStyle def) { - strokecolor = cfg.getString(path+".strokeColor", def.strokecolor); - unownedstrokecolor = cfg.getString(path+".unownedStrokeColor", def.unownedstrokecolor); - strokeopacity = cfg.getDouble(path+".strokeOpacity", def.strokeopacity); - strokeweight = cfg.getInt(path+".strokeWeight", def.strokeweight); - fillcolor = cfg.getString(path+".fillColor", def.fillcolor); - fillopacity = cfg.getDouble(path+".fillOpacity", def.fillopacity); - label = cfg.getString(path+".label", null); - } - AreaStyle(FileConfiguration cfg, String path) { - strokecolor = cfg.getString(path+".strokeColor", "#FF0000"); - unownedstrokecolor = cfg.getString(path+".unownedStrokeColor", "#00FF00"); - strokeopacity = cfg.getDouble(path+".strokeOpacity", 0.8); - strokeweight = cfg.getInt(path+".strokeWeight", 3); - fillcolor = cfg.getString(path+".fillColor", "#FF0000"); - fillopacity = cfg.getDouble(path+".fillOpacity", 0.35); - } + + public static void info(String msg) { log.log(Level.INFO, msg); } + + + + + public static void severe(String msg) { log.log(Level.SEVERE, msg); } + + + private Map resareas = new HashMap(); + + + private String formatInfoWindow(ProtectedRegion region, AreaMarker m) { + String v = "
" + this.infowindow + "
"; + v = v.replace("%regionname%", m.getLabel()); + v = v.replace("%playerowners%", region.getOwners().toPlayersString(WorldGuard.getInstance().getProfileCache())); + v = v.replace("%groupowners%", region.getOwners().toGroupsString()); + v = v.replace("%playermembers%", region.getMembers().toPlayersString(WorldGuard.getInstance().getProfileCache())); + v = v.replace("%groupmembers%", region.getMembers().toGroupsString()); + if (region.getParent() != null) { + v = v.replace("%parent%", region.getParent().getId()); + } else { + v = v.replace("%parent%", ""); + } + v = v.replace("%priority%", String.valueOf(region.getPriority())); + Map, Object> map = region.getFlags(); + String flgs = ""; + for (Flag f : map.keySet()) { + flgs = String.valueOf(flgs) + f.getName() + ": " + map.get(f).toString() + "
"; } - - public static void info(String msg) { - log.log(Level.INFO, msg); + return v.replace("%flags%", flgs); + } + + + + private boolean isVisible(String id, String worldname) { + if (this.visible != null && this.visible.size() > 0 && + !this.visible.contains(id) && !this.visible.contains("world:" + worldname) && + !this.visible.contains(String.valueOf(worldname) + "/" + id)) { + return false; } - public static void severe(String msg) { - log.log(Level.SEVERE, msg); + if (this.hidden != null && this.hidden.size() > 0 && ( + this.hidden.contains(id) || this.hidden.contains("world:" + worldname) || this.hidden.contains(String.valueOf(worldname) + "/" + id))) { + return false; } - - private Map resareas = new HashMap(); + return true; + } - private String formatInfoWindow(ProtectedRegion region, AreaMarker m) { - String v = "
"+infowindow+"
"; - v = v.replace("%regionname%", m.getLabel()); - v = v.replace("%playerowners%", region.getOwners().toPlayersString(WorldGuard.getInstance().getProfileCache())); - v = v.replace("%groupowners%", region.getOwners().toGroupsString()); - v = v.replace("%playermembers%", region.getMembers().toPlayersString(WorldGuard.getInstance().getProfileCache())); - v = v.replace("%groupmembers%", region.getMembers().toGroupsString()); - if(region.getParent() != null) - v = v.replace("%parent%", region.getParent().getId()); - else - v = v.replace("%parent%", ""); - v = v.replace("%priority%", String.valueOf(region.getPriority())); - Map, Object> map = region.getFlags(); - String flgs = ""; - for(Flag f : map.keySet()) { - flgs += f.getName() + ": " + map.get(f).toString() + "
"; - } - v = v.replace("%flags%", flgs); - return v; + + private void addStyle(String resid, String worldid, AreaMarker m, ProtectedRegion region) { + AreaStyle as = (AreaStyle)this.cusstyle.get(String.valueOf(worldid) + "/" + resid); + if (as == null) { + as = (AreaStyle)this.cusstyle.get(resid); } - - private boolean isVisible(String id, String worldname) { - if((visible != null) && (visible.size() > 0)) { - if((visible.contains(id) == false) && (visible.contains("world:" + worldname) == false) && - (visible.contains(worldname + "/" + id) == false)) { - return false; - } - } - if((hidden != null) && (hidden.size() > 0)) { - if(hidden.contains(id) || hidden.contains("world:" + worldname) || hidden.contains(worldname + "/" + id)) - return false; + if (as == null) { + for (String wc : this.cuswildstyle.keySet()) { + + String[] tok = wc.split("\\|"); + if (tok.length == 1 && resid.startsWith(tok[0])) { + as = (AreaStyle)this.cuswildstyle.get(wc); continue; + } if (tok.length >= 2 && resid.startsWith(tok[0]) && resid.endsWith(tok[1])) { + as = (AreaStyle)this.cuswildstyle.get(wc); } - return true; + } } + - private void addStyle(String resid, String worldid, AreaMarker m, ProtectedRegion region) { - AreaStyle as = cusstyle.get(worldid + "/" + resid); - if(as == null) { - as = cusstyle.get(resid); - } - if(as == null) { /* Check for wildcard style matches */ - for(String wc : cuswildstyle.keySet()) { - String[] tok = wc.split("\\|"); - if((tok.length == 1) && resid.startsWith(tok[0])) - as = cuswildstyle.get(wc); - else if((tok.length >= 2) && resid.startsWith(tok[0]) && resid.endsWith(tok[1])) - as = cuswildstyle.get(wc); + if (as == null && + !this.ownerstyle.isEmpty()) { + + DefaultDomain dd = region.getOwners(); + PlayerDomain pd = dd.getPlayerDomain(); + if (pd != null) { + + for (String p1 : pd.getPlayers()) { + if (as == null) { + + as = (AreaStyle)this.ownerstyle.get(p1.toLowerCase()); + if (as != null) { + break; } - } - if(as == null) { /* Check for owner style matches */ - if(ownerstyle.isEmpty() != true) { - DefaultDomain dd = region.getOwners(); - PlayerDomain pd = dd.getPlayerDomain(); - if(pd != null) { - for(String p : pd.getPlayers()) { - if(as == null) { - as = ownerstyle.get(p.toLowerCase()); - if (as != null) break; - } - } - if (as == null) { - for(UUID uuid : pd.getUniqueIds()) { - as = ownerstyle.get(uuid.toString()); - if (as != null) break; - } - } - if (as == null) { - for(String p : pd.getPlayers()) { - if (p != null) { - as = ownerstyle.get(p.toLowerCase()); - if (as != null) break; - } - } - } - } - if (as == null) { - Set grp = dd.getGroups(); - if(grp != null) { - for(String p : grp) { - as = ownerstyle.get(p.toLowerCase()); - if (as != null) break; - } - } - } + } + } + if (as == null) { + for (UUID uuid : pd.getUniqueIds()) { + + as = (AreaStyle)this.ownerstyle.get(uuid.toString()); + if (as != null) { + break; } + } } - if(as == null) - as = defstyle; - - boolean unowned = false; - if((region.getOwners().getPlayers().size() == 0) && - (region.getOwners().getUniqueIds().size() == 0 )&& - (region.getOwners().getGroups().size() == 0)) { - unowned = true; - } - int sc = 0xFF0000; - int fc = 0xFF0000; - try { - if(unowned) - sc = Integer.parseInt(as.unownedstrokecolor.substring(1), 16); - else - sc = Integer.parseInt(as.strokecolor.substring(1), 16); - fc = Integer.parseInt(as.fillcolor.substring(1), 16); - } catch (NumberFormatException nfx) { - } - m.setLineStyle(as.strokeweight, as.strokeopacity, sc); - m.setFillStyle(as.fillopacity, fc); - if(as.label != null) { - m.setLabel(as.label); + if (as == null) { + for (Iterator tok = pd.getPlayers().iterator(); tok.hasNext(); ) { + + String p = (String)tok.next(); + if (p != null) { + + as = (AreaStyle)this.ownerstyle.get(p.toLowerCase()); + if (as != null) { + break; + } + } + } } - if (boost_flag != null) { - Boolean b = region.getFlag(boost_flag); - m.setBoostFlag((b == null)?false:b.booleanValue()); + } + if (as == null) { + + Set grp = dd.getGroups(); + if (grp != null) { + for (String p1 : grp) { + + as = (AreaStyle)this.ownerstyle.get(p1.toLowerCase()); + if (as != null) { + break; + } + } } + } + } + if (as == null) { + as = this.defstyle; + } + boolean unowned = false; + if (region.getOwners().getPlayers().size() == 0 && + region.getOwners().getUniqueIds().size() == 0 && + region.getOwners().getGroups().size() == 0) { + unowned = true; + } + int sc = 16711680; + int fc = 16711680; + + try { + if (unowned) { + sc = Integer.parseInt(as.unownedstrokecolor.substring(1), 16); + } else { + sc = Integer.parseInt(as.strokecolor.substring(1), 16); + } + fc = Integer.parseInt(as.fillcolor.substring(1), 16); } + catch (NumberFormatException numberFormatException) {} + m.setLineStyle(as.strokeweight, as.strokeopacity, sc); + m.setFillStyle(as.fillopacity, fc); + if (as.label != null) { + m.setLabel(as.label); + } + if (this.boost_flag != null) { + + Boolean b = (Boolean)region.getFlag(this.boost_flag); + m.setBoostFlag((b == null) ? false : b.booleanValue()); + } + } + + + private void handleRegion(World world, ProtectedRegion region, Map newmap) { + String name = region.getId(); + + name = String.valueOf(name.substring(0, 1).toUpperCase()) + name.substring(1); + double[] x = null; + double[] z = null; + if (isVisible(region.getId(), world.getName())) { + + String id = region.getId(); + RegionType tn = region.getType(); + BlockVector3 l0 = region.getMinimumPoint(); + BlockVector3 l1 = region.getMaximumPoint(); + if (tn == RegionType.CUBOID) { + + x = new double[4]; + z = new double[4]; + x[0] = l0.getX(); z[0] = l0.getZ(); + x[1] = l0.getX(); z[1] = l1.getZ() + 1.0D; + x[2] = l1.getX() + 1.0D; z[2] = l1.getZ() + 1.0D; + x[3] = l1.getX() + 1.0D; z[3] = l0.getZ(); + } + else if (tn == RegionType.POLYGON) { - /* Handle specific region */ - private void handleRegion(World world, ProtectedRegion region, Map newmap) { - String name = region.getId(); - /* Make first letter uppercase */ - name = name.substring(0, 1).toUpperCase() + name.substring(1); - double[] x = null; - double[] z = null; - - /* Handle areas */ - if(isVisible(region.getId(), world.getName())) { - String id = region.getId(); - RegionType tn = region.getType(); - BlockVector3 l0 = region.getMinimumPoint(); - BlockVector3 l1 = region.getMaximumPoint(); + ProtectedPolygonalRegion ppr = (ProtectedPolygonalRegion)region; + List points = ppr.getPoints(); + x = new double[points.size()]; + z = new double[points.size()]; + for (int i = 0; i < points.size(); i++) { + + BlockVector2 pt = (BlockVector2)points.get(i); + x[i] = pt.getX(); z[i] = pt.getZ(); + } + } else { + return; + } - if(tn == RegionType.CUBOID) { /* Cubiod region? */ - /* Make outline */ - x = new double[4]; - z = new double[4]; - x[0] = l0.getX(); z[0] = l0.getZ(); - x[1] = l0.getX(); z[1] = l1.getZ()+1.0; - x[2] = l1.getX() + 1.0; z[2] = l1.getZ()+1.0; - x[3] = l1.getX() + 1.0; z[3] = l0.getZ(); - } - else if(tn == RegionType.POLYGON) { - ProtectedPolygonalRegion ppr = (ProtectedPolygonalRegion)region; - List points = ppr.getPoints(); - x = new double[points.size()]; - z = new double[points.size()]; - for(int i = 0; i < points.size(); i++) { - BlockVector2 pt = points.get(i); - x[i] = pt.getX(); z[i] = pt.getZ(); - } - } - else { /* Unsupported type */ - return; - } - String markerid = world.getName() + "_" + id; - AreaMarker m = resareas.remove(markerid); /* Existing area? */ - if(m == null) { - m = set.createAreaMarker(markerid, name, false, world.getName(), x, z, false); - if(m == null) - return; - } - else { - m.setCornerLocations(x, z); /* Replace corner locations */ - m.setLabel(name); /* Update label */ - } - if(use3d) { /* If 3D? */ - m.setRangeY(l1.getY()+1.0, l0.getY()); - } - /* Set line and fill properties */ - addStyle(id, world.getName(), m, region); + + String markerid = String.valueOf(world.getName()) + "_" + id; + AreaMarker m = (AreaMarker)this.resareas.remove(markerid); + if (m == null) { + + m = this.set.createAreaMarker(markerid, name, false, world.getName(), x, z, false); + + } + else { + + m.setCornerLocations(x, z); + m.setLabel(name); + } + if (this.use3d) { + m.setRangeY(l1.getY() + 1.0D, l0.getY()); + } + addStyle(id, world.getName(), m, region); + + String desc = formatInfoWindow(region, m); + + m.setDescription(desc); + + newmap.put(markerid, m); + } + } + + private class UpdateJob + implements Runnable + { + Map newmap = new HashMap(); + List worldsToDo = null; + List regionsToDo = null; + World curworld = null; - /* Build popup */ - String desc = formatInfoWindow(region, m); - m.setDescription(desc); /* Set popup */ - /* Add to map */ - newmap.put(markerid, m); - } - } - private class UpdateJob implements Runnable { - Map newmap = new HashMap(); /* Build new map */ - List worldsToDo = null; - List regionsToDo = null; - World curworld = null; + public void run() { + if (DynmapWorldGuardPlugin.this.stop) { + return; + } + + if (this.worldsToDo == null) { - public void run() { - if (stop) { - return; - } - // If worlds list isn't primed, prime it - if (worldsToDo == null) { - List w = Bukkit.getWorlds(); - worldsToDo = new ArrayList(); - for (org.bukkit.World wrld : w) { - worldsToDo.add(WorldGuard.getInstance().getPlatform().getMatcher().getWorldByName(wrld.getName())); - } - } - while (regionsToDo == null) { // No pending regions for world - if (worldsToDo.isEmpty()) { // No more worlds? - /* Now, review old map - anything left is gone */ - for(AreaMarker oldm : resareas.values()) { - oldm.deleteMarker(); - } - /* And replace with new map */ - resareas = newmap; - // Set up for next update (new job) - getServer().getScheduler().scheduleSyncDelayedTask(DynmapWorldGuardPlugin.this, new UpdateJob(), updperiod); - return; - } - else { - curworld = worldsToDo.remove(0); - RegionContainer rc = WorldGuard.getInstance().getPlatform().getRegionContainer(); - RegionManager rm = rc.get(curworld); /* Get region manager for world */ - if(rm != null) { - Map regions = rm.getRegions(); /* Get all the regions */ - if ((regions != null) && (regions.isEmpty() == false)) { - regionsToDo = new ArrayList(regions.values()); - } - } - } - } - /* Now, process up to limit regions */ - for (int i = 0; i < updatesPerTick; i++) { - if (regionsToDo.isEmpty()) { - regionsToDo = null; - break; - } - ProtectedRegion pr = regionsToDo.remove(regionsToDo.size()-1); - int depth = 1; - ProtectedRegion p = pr; - while(p.getParent() != null) { - depth++; - p = p.getParent(); - } - if(depth > maxdepth) - continue; - handleRegion(curworld, pr, newmap); - } - // Tick next step in the job - getServer().getScheduler().scheduleSyncDelayedTask(DynmapWorldGuardPlugin.this, this, 1); - } - } - - private class OurServerListener implements Listener { - @EventHandler(priority=EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - Plugin p = event.getPlugin(); - String name = p.getDescription().getName(); - if(name.equals("dynmap")) { - Plugin wg = p.getServer().getPluginManager().getPlugin("WorldGuard"); - if(wg != null && wg.isEnabled()) - activate(); - } else if(name.equals("WorldGuard") && dynmap.isEnabled()) { - activate(); - } - } - } - - public void onEnable() { - info("initializing"); - PluginManager pm = getServer().getPluginManager(); - /* Get dynmap */ - dynmap = pm.getPlugin("dynmap"); - if(dynmap == null) { - severe("Cannot find dynmap!"); - return; - } - api = (DynmapAPI)dynmap; /* Get API */ - /* Get WorldGuard */ - Plugin wgp = pm.getPlugin("WorldGuard"); - if(wgp == null) { - severe("Cannot find WorldGuard!"); - return; + List w = Bukkit.getWorlds(); + this.worldsToDo = new ArrayList(); + for (org.bukkit.World wrld : w) { + this.worldsToDo.add(WorldGuard.getInstance().getPlatform().getMatcher().getWorldByName(wrld.getName())); } + } + while (this.regionsToDo == null) { - getServer().getPluginManager().registerEvents(new OurServerListener(), this); + if (this.worldsToDo.isEmpty()) { + + for (AreaMarker oldm : DynmapWorldGuardPlugin.this.resareas.values()) { + oldm.deleteMarker(); + } + DynmapWorldGuardPlugin.this.resareas = this.newmap; + + DynmapWorldGuardPlugin.this.getServer().getScheduler().scheduleSyncDelayedTask(DynmapWorldGuardPlugin.this, new UpdateJob(DynmapWorldGuardPlugin.this, DynmapWorldGuardPlugin.this), DynmapWorldGuardPlugin.this.updperiod); + return; + } + this.curworld = (World)this.worldsToDo.remove(0); + RegionContainer rc = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionManager rm = rc.get(this.curworld); + if (rm != null) { + + Map regions = rm.getRegions(); + if (regions != null && !regions.isEmpty()) { + this.regionsToDo = new ArrayList(regions.values()); + } + } + } + for (int i = 0; i < DynmapWorldGuardPlugin.this.updatesPerTick; i++) { - /* If both enabled, activate */ - if(dynmap.isEnabled() && wgp.isEnabled()) - activate(); - /* Start up metrics */ - try { - MetricsLite ml = new MetricsLite(this); - ml.start(); - } catch (IOException iox) { - + if (this.regionsToDo.isEmpty()) { + + this.regionsToDo = null; + break; + } + ProtectedRegion pr = (ProtectedRegion)this.regionsToDo.remove(this.regionsToDo.size() - 1); + int depth = 1; + ProtectedRegion p = pr; + while (p.getParent() != null) { + + depth++; + p = p.getParent(); + } + if (depth <= DynmapWorldGuardPlugin.this.maxdepth) { + DynmapWorldGuardPlugin.this.handleRegion(this.curworld, pr, this.newmap); } + } + DynmapWorldGuardPlugin.this.getServer().getScheduler().scheduleSyncDelayedTask(DynmapWorldGuardPlugin.this, this, 1L); } - private void registerCustomFlags() { - try { - BooleanFlag bf = new BooleanFlag(BOOST_FLAG); - FlagRegistry fr = WorldGuard.getInstance().getFlagRegistry(); - fr.register(bf); - boost_flag = bf; - } catch (Exception x) { - log.info("Error registering flag - " + x.getMessage()); - } - if (boost_flag == null) { - log.info("Custom flag '" + BOOST_FLAG + "' not registered"); + private UpdateJob(DynmapWorldGuardPlugin dynmapWorldGuardPlugin, DynmapWorldGuardPlugin dynmapWorldGuardPlugin2) {} + } + + private class OurServerListener + implements Listener { + private OurServerListener(Object object, Object object2) {} + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(PluginEnableEvent event) { + Plugin p = event.getPlugin(); + String name = p.getDescription().getName(); + if (name.equals("dynmap")) { + + Plugin wg = p.getServer().getPluginManager().getPlugin("WorldGuard"); + if (wg != null && wg.isEnabled()) { + DynmapWorldGuardPlugin.this.activate(); } + } + else if (name.equals("WorldGuard") && DynmapWorldGuardPlugin.this.dynmap.isEnabled()) { + + DynmapWorldGuardPlugin.this.activate(); + } } + } + + + public void onEnable() { + info("initializing"); + PluginManager pm = getServer().getPluginManager(); - private boolean reload = false; + this.dynmap = pm.getPlugin("dynmap"); + if (this.dynmap == null) { + + severe("Cannot find dynmap!"); + return; + } + this.api = (DynmapAPI)this.dynmap; - private void activate() { - /* Now, get markers API */ - markerapi = api.getMarkerAPI(); - if(markerapi == null) { - severe("Error loading dynmap marker API!"); - return; - } - /* Load configuration */ - if(reload) { - this.reloadConfig(); - } - else { - reload = true; - } - FileConfiguration cfg = getConfig(); - cfg.options().copyDefaults(true); /* Load defaults, if needed */ - this.saveConfig(); /* Save updates, if needed */ - - /* Now, add marker set for mobs (make it transient) */ - set = markerapi.getMarkerSet("worldguard.markerset"); - if(set == null) - set = markerapi.createMarkerSet("worldguard.markerset", cfg.getString("layer.name", "WorldGuard"), null, false); - else - set.setMarkerSetLabel(cfg.getString("layer.name", "WorldGuard")); - if(set == null) { - severe("Error creating marker set"); - return; - } - int minzoom = cfg.getInt("layer.minzoom", 0); - if(minzoom > 0) - set.setMinZoom(minzoom); - set.setLayerPriority(cfg.getInt("layer.layerprio", 10)); - set.setHideByDefault(cfg.getBoolean("layer.hidebydefault", false)); - use3d = cfg.getBoolean("use3dregions", false); - infowindow = cfg.getString("infowindow", DEF_INFOWINDOW); - maxdepth = cfg.getInt("maxdepth", 16); - updatesPerTick = cfg.getInt("updates-per-tick", 20); + Plugin wgp = pm.getPlugin("WorldGuard"); + if (wgp == null) { + + severe("Cannot find WorldGuard!"); + return; + } + getServer().getPluginManager().registerEvents(new OurServerListener(null, null), this); + if (this.dynmap.isEnabled() && wgp.isEnabled()) { + activate(); + } + + try { + MetricsLite ml = new MetricsLite(this); + ml.start(); + } + catch (IOException iOException) {} + } - /* Get style information */ - defstyle = new AreaStyle(cfg, "regionstyle"); - cusstyle = new HashMap(); - ownerstyle = new HashMap(); - cuswildstyle = new HashMap(); - ConfigurationSection sect = cfg.getConfigurationSection("custstyle"); - if(sect != null) { - Set ids = sect.getKeys(false); - - for(String id : ids) { - if(id.indexOf('|') >= 0) - cuswildstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle)); - else - cusstyle.put(id, new AreaStyle(cfg, "custstyle." + id, defstyle)); - } - } - sect = cfg.getConfigurationSection("ownerstyle"); - if(sect != null) { - Set ids = sect.getKeys(false); - - for(String id : ids) { - ownerstyle.put(id.toLowerCase(), new AreaStyle(cfg, "ownerstyle." + id, defstyle)); - } - } - List vis = cfg.getStringList("visibleregions"); - if(vis != null) { - visible = new HashSet(vis); - } - List hid = cfg.getStringList("hiddenregions"); - if(hid != null) { - hidden = new HashSet(hid); - } - /* Set up update job - based on periond */ - int per = cfg.getInt("update.period", 300); - if(per < 15) per = 15; - updperiod = (long)(per*20); - stop = false; - - getServer().getScheduler().scheduleSyncDelayedTask(this, new UpdateJob(), 40); /* First time is 2 seconds */ - - info("version " + this.getDescription().getVersion() + " is activated"); + + private void registerCustomFlags() { + try { + BooleanFlag bf = new BooleanFlag("dynmap-boost"); + FlagRegistry fr = WorldGuard.getInstance().getFlagRegistry(); + fr.register(bf); + this.boost_flag = bf; + } + catch (Exception x) { + + log.info("Error registering flag - " + x.getMessage()); + } + if (this.boost_flag == null) { + log.info("Custom flag 'dynmap-boost' not registered"); } + } - public void onDisable() { - if(set != null) { - set.deleteMarkerSet(); - set = null; - } - resareas.clear(); - stop = true; + + private boolean reload = false; + + private void activate() { + this.markerapi = this.api.getMarkerAPI(); + if (this.markerapi == null) { + + severe("Error loading dynmap marker API!"); + return; + } + if (this.reload) { + reloadConfig(); + } else { + this.reload = true; + } + FileConfiguration cfg = getConfig(); + cfg.options().copyDefaults(true); + saveConfig(); + + this.set = this.markerapi.getMarkerSet("worldguard.markerset"); + if (this.set == null) { + this.set = this.markerapi.createMarkerSet("worldguard.markerset", cfg.getString("layer.name", "WorldGuard"), null, false); + } else { + this.set.setMarkerSetLabel(cfg.getString("layer.name", "WorldGuard")); + } + if (this.set == null) { + + severe("Error creating marker set"); + return; + } + int minzoom = cfg.getInt("layer.minzoom", 0); + if (minzoom > 0) { + this.set.setMinZoom(minzoom); } + this.set.setLayerPriority(cfg.getInt("layer.layerprio", 10)); + this.set.setHideByDefault(cfg.getBoolean("layer.hidebydefault", false)); + this.use3d = cfg.getBoolean("use3dregions", false); + this.infowindow = cfg.getString("infowindow", "
%regionname%
Owner %playerowners%
Flags
%flags%
"); + this.maxdepth = cfg.getInt("maxdepth", 16); + this.updatesPerTick = cfg.getInt("updates-per-tick", 20); + + this.defstyle = new AreaStyle(cfg, "regionstyle"); + this.cusstyle = new HashMap(); + this.ownerstyle = new HashMap(); + this.cuswildstyle = new HashMap(); + ConfigurationSection sect = cfg.getConfigurationSection("custstyle"); + if (sect != null) { + + Set ids = sect.getKeys(false); + for (String id : ids) { + if (id.indexOf('|') >= 0) { + this.cuswildstyle.put(id, new AreaStyle(cfg, "custstyle." + id, this.defstyle)); continue; + } + this.cusstyle.put(id, new AreaStyle(cfg, "custstyle." + id, this.defstyle)); + } + } + + sect = cfg.getConfigurationSection("ownerstyle"); + if (sect != null) { + + Set ids = sect.getKeys(false); + for (String id : ids) { + this.ownerstyle.put(id.toLowerCase(), new AreaStyle(cfg, "ownerstyle." + id, this.defstyle)); + } + } + List vis = cfg.getStringList("visibleregions"); + if (vis != null) { + this.visible = new HashSet(vis); + } + Object hid = cfg.getStringList("hiddenregions"); + if (hid != null) { + this.hidden = new HashSet((Collection)hid); + } + int per = cfg.getInt("update.period", 300); + if (per < 15) { + per = 15; + } + this.updperiod = (per * 20); + this.stop = false; + + getServer().getScheduler().scheduleSyncDelayedTask(this, new UpdateJob(null, null), 40L); + + info("version " + getDescription().getVersion() + " is activated"); + } + + public void onDisable() { + if (this.set != null) { + + this.set.deleteMarkerSet(); + this.set = null; + } + this.resareas.clear(); + this.stop = true; + } } diff --git a/src/main/java/org/dynmap/worldguard/MetricsLite.java b/src/main/java/org/dynmap/worldguard/MetricsLite.java index 911af3b..cb23c81 100644 --- a/src/main/java/org/dynmap/worldguard/MetricsLite.java +++ b/src/main/java/org/dynmap/worldguard/MetricsLite.java @@ -1,40 +1,5 @@ -/* - * Copyright 2011 Tyler Blair. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and contributors and should not be interpreted as representing official policies, - * either expressed or implied, of anybody else. - */ - package org.dynmap.worldguard; -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.scheduler.BukkitTask; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -45,314 +10,213 @@ import java.net.Proxy; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; +import java.util.Collection; import java.util.UUID; import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.file.YamlConfigurationOptions; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scheduler.BukkitTask; -public class MetricsLite { - - /** - * The current revision number - */ - private final static int REVISION = 5; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://mcstats.org"; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/report/%s"; - - /** - * Interval of time to ping (in minutes) - */ - private final static int PING_INTERVAL = 10; - - /** - * The plugin this metrics submits for - */ - private final Plugin plugin; - - /** - * The plugin configuration file - */ - private final YamlConfiguration configuration; - - /** - * The plugin configuration file - */ - private final File configurationFile; - - /** - * Unique server id - */ - private final String guid; - - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - - /** - * Id of the scheduled task - */ - private volatile BukkitTask taskId = null; - - public MetricsLite(Plugin plugin) throws IOException { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.plugin = plugin; - - // load the config - configurationFile = getConfigFile(); - configuration = YamlConfiguration.loadConfiguration(configurationFile); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - - // Do we need to create the file? - if (configuration.get("guid", null) == null) { - configuration.options().header("http://mcstats.org").copyDefaults(true); - configuration.save(configurationFile); - } - - // Load the guid then - guid = configuration.getString("guid"); +public class MetricsLite +{ + private static final int REVISION = 5; + private static final String BASE_URL = "http://mcstats.org"; + private static final String REPORT_URL = "/report/%s"; + private static final int PING_INTERVAL = 10; + private final Plugin plugin; + private final YamlConfiguration configuration; + private final File configurationFile; + private final String guid; + private final Object optOutLock = new Object(); + private volatile BukkitTask taskId = null; + + public MetricsLite(Plugin plugin) + throws IOException + { + if (plugin == null) { + throw new IllegalArgumentException("Plugin cannot be null"); } - - /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send - * the initial data to the metrics backend, and then after that it will post in increments of - * PING_INTERVAL * 1200 ticks. - * - * @return True if statistics measuring is running, otherwise false. - */ - public boolean start() { - synchronized (optOutLock) { - // Did we opt out? - if (isOptOut()) { - return false; - } - - // Is metrics already running? - if (taskId != null) { - return true; - } - - // Begin hitting the server with glorious data - taskId = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - - private boolean firstPost = true; - - public void run() { - try { - // This has to be synchronized or it can collide with the disable method. - synchronized (optOutLock) { - // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && (taskId != null)) { - taskId.cancel(); - taskId = null; - } - } - - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch (IOException e) { - //Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); - } - } - }, 0, PING_INTERVAL * 1200); - - return true; - } + this.plugin = plugin; + + this.configurationFile = getConfigFile(); + this.configuration = YamlConfiguration.loadConfiguration(this.configurationFile); + + this.configuration.addDefault("opt-out", Boolean.valueOf(false)); + this.configuration.addDefault("guid", UUID.randomUUID().toString()); + if (this.configuration.get("guid", null) == null) + { + this.configuration.options().header("http://mcstats.org").copyDefaults(true); + this.configuration.save(this.configurationFile); } - - /** - * Has the server owner denied plugin metrics? - * - * @return true if metrics should be opted out of it - */ - public boolean isOptOut() { - synchronized(optOutLock) { - try { - // Reload the metrics file - configuration.load(getConfigFile()); - } catch (IOException ex) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - return true; - } catch (InvalidConfigurationException ex) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - return true; + this.guid = this.configuration.getString("guid"); + } + + public boolean start() + { + synchronized (this.optOutLock) + { + if (isOptOut()) { + return false; + } + if (this.taskId != null) { + return true; + } + this.taskId = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() + { + private boolean firstPost = true; + + public void run() + { + try + { + synchronized (MetricsLite.this.optOutLock) + { + if ((MetricsLite.this.isOptOut()) && (MetricsLite.this.taskId != null)) + { + MetricsLite.this.taskId.cancel(); + MetricsLite.this.taskId = null; + } } - return configuration.getBoolean("opt-out", false); + MetricsLite.this.postPlugin(!this.firstPost); + + this.firstPost = false; + } + catch (IOException localIOException) {} } + }, 0L, 12000L); + + return true; } - - /** - * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. - * - * @throws IOException - */ - public void enable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) { - configuration.set("opt-out", false); - configuration.save(configurationFile); - } - - // Enable Task, if it is not running - if (taskId == null) { - start(); - } - } + } + + public boolean isOptOut() + { + synchronized (this.optOutLock) + { + try + { + this.configuration.load(getConfigFile()); + } + catch (IOException ex) + { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + return true; + } + catch (InvalidConfigurationException ex) + { + Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); + return true; + } + return this.configuration.getBoolean("opt-out", false); } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws IOException - */ - public void disable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (!isOptOut()) { - configuration.set("opt-out", true); - configuration.save(configurationFile); - } - - // Disable Task, if it is running - if (taskId != null) { - taskId.cancel(); - taskId = null; - } - } + } + + public void enable() + throws IOException + { + synchronized (this.optOutLock) + { + if (isOptOut()) + { + this.configuration.set("opt-out", Boolean.valueOf(false)); + this.configuration.save(this.configurationFile); + } + if (this.taskId == null) { + start(); + } } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use - // is to abuse the plugin object we already have - // plugin.getDataFolder() => base/plugins/PluginA/ - // pluginsFolder => base/plugins/ - // The base is not necessarily relative to the startup directory. - File pluginsFolder = plugin.getDataFolder().getParentFile(); - - // return => base/plugins/PluginMetrics/config.yml - return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); + } + + public void disable() + throws IOException + { + synchronized (this.optOutLock) + { + if (!isOptOut()) + { + this.configuration.set("opt-out", Boolean.valueOf(true)); + this.configuration.save(this.configurationFile); + } + if (this.taskId != null) + { + this.taskId.cancel(); + this.taskId = null; + } } - - /** - * Generic method that posts a plugin to the metrics website - */ - private void postPlugin(boolean isPing) throws IOException { - // The plugin's description file containg all of the plugin data such as name, version, author, etc - final PluginDescriptionFile description = plugin.getDescription(); - - // Construct the post data - final StringBuilder data = new StringBuilder(); - data.append(encode("guid")).append('=').append(encode(guid)); - encodeDataPair(data, "version", description.getVersion()); - encodeDataPair(data, "server", Bukkit.getVersion()); - encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().size())); - encodeDataPair(data, "revision", String.valueOf(REVISION)); - - // If we're pinging, append it - if (isPing) { - encodeDataPair(data, "ping", "true"); - } - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName()))); - - // Connect to the website - URLConnection connection; - - // Mineshafter creates a socks proxy, so we can safely bypass it - // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) { - connection = url.openConnection(Proxy.NO_PROXY); - } else { - connection = url.openConnection(); - } - - connection.setDoOutput(true); - - // Write the data - final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); - writer.write(data.toString()); - writer.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - final String response = reader.readLine(); - - // close resources - writer.close(); - reader.close(); - - if (response == null || response.startsWith("ERR")) { - throw new IOException(response); //Throw the exception - } - //if (response.startsWith("OK")) - We should get "OK" followed by an optional description if everything goes right + } + + public File getConfigFile() + { + File pluginsFolder = this.plugin.getDataFolder().getParentFile(); + + return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); + } + + private void postPlugin(boolean isPing) + throws IOException + { + PluginDescriptionFile description = this.plugin.getDescription(); + + StringBuilder data = new StringBuilder(); + data.append(encode("guid")).append('=').append(encode(this.guid)); + encodeDataPair(data, "version", description.getVersion()); + encodeDataPair(data, "server", Bukkit.getVersion()); + encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().size())); + encodeDataPair(data, "revision", String.valueOf(5)); + if (isPing) { + encodeDataPair(data, "ping", "true"); } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (Exception e) { - return false; - } + URL url = new URL("http://mcstats.org" + String.format("/report/%s", new Object[] { encode(this.plugin.getDescription().getName()) })); + URLConnection connection; + URLConnection connection1; + if (isMineshafterPresent()) { + connection1 = url.openConnection(Proxy.NO_PROXY); + } else { + connection1 = url.openConnection(); } - - /** - *

Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first - * key/value pair MUST be included manually, e.g:

- * - * StringBuffer data = new StringBuffer(); - * data.append(encode("guid")).append('=').append(encode(guid)); - * encodeDataPair(data, "version", description.getVersion()); - * - * - * @param buffer the stringbuilder to append the data pair onto - * @param key the key value - * @param value the value - */ - private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException { - buffer.append('&').append(encode(key)).append('=').append(encode(value)); + connection1.setDoOutput(true); + + OutputStreamWriter writer = new OutputStreamWriter(connection1.getOutputStream()); + writer.write(data.toString()); + writer.flush(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(connection1.getInputStream())); + String response = reader.readLine(); + + writer.close(); + reader.close(); + if ((response == null) || (response.startsWith("ERR"))) { + throw new IOException(response); } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String encode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); + } + + private boolean isMineshafterPresent() + { + try + { + Class.forName("mineshafter.MineServer"); + return true; } - -} \ No newline at end of file + catch (Exception e) {} + return false; + } + + private static void encodeDataPair(StringBuilder buffer, String key, String value) + throws UnsupportedEncodingException + { + buffer.append('&').append(encode(key)).append('=').append(encode(value)); + } + + private static String encode(String text) + throws UnsupportedEncodingException + { + return URLEncoder.encode(text, "UTF-8"); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a5dddbe..c99cc2f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Dynmap-WorldGuard main: org.dynmap.worldguard.DynmapWorldGuardPlugin -version: "${project.version}" +version: "1.1-beta-3" author: mikeprimm depend: [ dynmap, WorldGuard ]