Initial Support for Regions system on dynmap
Included Worldguard support(default) Also residence support(incomplete)
This commit is contained in:
parent
d53b3bc340
commit
8e59f37995
6 changed files with 425 additions and 0 deletions
|
|
@ -6,6 +6,8 @@ import java.io.FileOutputStream;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -15,6 +17,7 @@ import org.bukkit.Server;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.bukkit.util.config.ConfigurationNode;
|
||||
import org.dynmap.web.Json;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
|
@ -28,6 +31,7 @@ class JsonTimerTask extends TimerTask {
|
|||
private Server server;
|
||||
private MapManager mapManager;
|
||||
private Configuration configuration;
|
||||
private ConfigurationNode regions;
|
||||
private static final JSONParser parser = new JSONParser();
|
||||
private long lastTimestamp = 0;
|
||||
|
||||
|
|
@ -36,6 +40,14 @@ class JsonTimerTask extends TimerTask {
|
|||
this.server = this.plugin.getServer();
|
||||
this.mapManager = this.plugin.getMapManager();
|
||||
this.configuration = config;
|
||||
//this.regions = configuration.getNode("web").getNode("components").getNode("regions");
|
||||
System.out.println();
|
||||
for(ConfigurationNode type : configuration.getNodeList("web.components", null))
|
||||
if(type.getString("type").equalsIgnoreCase("regions"))
|
||||
{
|
||||
this.regions = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
@ -77,6 +89,9 @@ class JsonTimerTask extends TimerTask {
|
|||
|
||||
//Handles Updates
|
||||
for (World world : this.server.getWorlds()) {
|
||||
if(regions.getBoolean("useworldpath", false))
|
||||
parseRegionFile(world.getName() + "/" + regions.getString("filename", "regions.yml"), regions.getString("filename", "regions.yml").replace(".", "_" + world.getName() + ".yml"));
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
|
||||
Client.Update update = new Client.Update();
|
||||
|
|
@ -111,5 +126,46 @@ class JsonTimerTask extends TimerTask {
|
|||
}
|
||||
}
|
||||
lastTimestamp = System.currentTimeMillis();
|
||||
|
||||
if (!regions.getBoolean("useworldpath", false))
|
||||
parseRegionFile(regions.getString("filename", "regions.yml"), regions.getString("filename", "regions.yml"));
|
||||
}
|
||||
|
||||
private void parseRegionFile(String regionFile, String outputFileName)
|
||||
{
|
||||
File outputFile;
|
||||
Configuration regionConfig = null;
|
||||
if(regions.getBoolean("useworldpath", false))
|
||||
{
|
||||
if(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile).exists())
|
||||
regionConfig = new Configuration(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile));
|
||||
else if(new File("plugins/"+regions.getString("name", "WorldGuard")+"/worlds", regionFile).exists())
|
||||
regionConfig = new Configuration(new File("plugins/"+regions.getString("name", "WorldGuard")+"/worlds", regionFile));
|
||||
}
|
||||
else
|
||||
regionConfig = new Configuration(new File("plugins/"+regions.getString("name", "WorldGuard"), regionFile));
|
||||
//File didn't exist
|
||||
if(regionConfig == null)
|
||||
return;
|
||||
regionConfig.load();
|
||||
|
||||
outputFileName = outputFileName.substring(0, outputFileName.lastIndexOf("."))+".json";
|
||||
|
||||
File webWorldPath = new File(this.configuration.getString("webpath", "web")+"/standalone/", outputFileName);
|
||||
Map<?, ?> regionData = (Map<?, ?>) regionConfig.getProperty(regions.getString("basenode", "regions"));
|
||||
if (webWorldPath.isAbsolute())
|
||||
outputFile = webWorldPath;
|
||||
else {
|
||||
outputFile = new File(plugin.getDataFolder(), webWorldPath.toString());
|
||||
}
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||
fos.write(Json.stringifyJson(regionData).getBytes());
|
||||
fos.close();
|
||||
} catch (FileNotFoundException ex) {
|
||||
log.log(Level.SEVERE, "Exception while writing JSON-file.", ex);
|
||||
} catch (IOException ioe) {
|
||||
log.log(Level.SEVERE, "Exception while writing JSON-file.", ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue