- Renamed markers.csv to markers.txt

- Changed format of markers.txt to colon delimited instead of comma (no need to change anything, plugin will read both types and save in the new format)
- Added support for warps/homes/spawn from data source (either flatfile or mysql)
- Renamed images to be more specific to what they represent (marker = marker.png) for you customizers.
- Added fix to mapUpdate to keep marker/player names from conflicting
This commit is contained in:
fescen9 2010-12-10 06:48:09 +00:00
parent cf2f585364
commit dfbd69f64e
14 changed files with 183 additions and 85 deletions

13
DMFlatFileSource.java Normal file
View File

@ -0,0 +1,13 @@
/* FlatFileSource class wrapper to expose protected properties */
import java.util.List;
public class DMFlatFileSource extends FlatFileSource {
public List<Warp> getAllWarps() {
return this.warps;
}
public List<Warp> getAllHomes() {
return this.homes;
}
}

13
DMMySQLSource.java Normal file
View File

@ -0,0 +1,13 @@
/* MySQLSource class wrapper to expose protected properties */
import java.util.List;
public class DMMySQLSource extends MySQLSource {
public List<Warp> getAllWarps() {
return this.warps;
}
public List<Warp> getAllHomes() {
return this.homes;
}
}

View File

@ -1,11 +1,19 @@
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.List;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -14,17 +22,9 @@ import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Vector;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
public class MapManager extends Thread {
@ -66,7 +66,7 @@ public class MapManager extends Thread {
public String tilepath = "tiles/";
/* path to markers file */
public String markerpath = "markers.csv";
public String markerpath = "markers.txt";
/* port to run web server on */
public int serverport = 8123;
@ -110,7 +110,7 @@ public class MapManager extends Thread {
try {
tilepath = properties.getString("map-tilepath", "tiles/");
colorsetpath = properties.getString("map-colorsetpath", "colors.txt");
markerpath = properties.getString("map-markerpath", "markers.csv");
markerpath = properties.getString("map-markerpath", "markers.txt");
serverport = Integer.parseInt(properties.getString("map-serverport", "8123"));
} catch(Exception ex) {
log.log(Level.SEVERE, "Exception while reading properties for dynamic map", ex);
@ -590,7 +590,7 @@ public class MapManager extends Thread {
}
catch(IOException e)
{
log.log(Level.SEVERE, "Failed to save markers.csv", e);
log.log(Level.SEVERE, "Failed to save markers.txt", e);
}
return false;
@ -613,7 +613,7 @@ public class MapManager extends Thread {
}
catch(IOException e)
{
log.log(Level.SEVERE, "Failed to save markers.csv", e);
log.log(Level.SEVERE, "Failed to save markers.txt", e);
}
}
else
@ -656,14 +656,27 @@ public class MapManager extends Thread {
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
String[] values = line.split(",");
MapMarker marker = new MapMarker();
marker.name = values[0];
marker.owner = values[1];
marker.px = Double.parseDouble(values[2]);
marker.py = Double.parseDouble(values[3]);
marker.pz = Double.parseDouble(values[4]);
markers.put(marker.name, marker);
String[] values = line.split(":");
// If user has old style of file (CSV)
if (values.length != 5)
{
values = line.split(",");
}
if (values.length == 5)
{
MapMarker marker = new MapMarker();
marker.name = values[0];
marker.owner = values[1];
marker.px = Double.parseDouble(values[2]);
marker.py = Double.parseDouble(values[3]);
marker.pz = Double.parseDouble(values[4]);
markers.put(marker.name, marker);
}
else
{
log.log(Level.INFO, "Failed to load marker: " + values[0]);
}
}
}
catch(FileNotFoundException e)
@ -688,7 +701,7 @@ public class MapManager extends Thread {
while(it.hasNext())
{
MapMarker marker = it.next();
String line = marker.name + "," + marker.owner + "," + marker.px + "," + marker.py + "," + marker.pz + "\r\n";
String line = marker.name + ":" + marker.owner + ":" + marker.px + ":" + marker.py + ":" + marker.pz + "\n";
out.write(line);
}
}
@ -698,7 +711,7 @@ public class MapManager extends Thread {
}
catch(FileNotFoundException e)
{
log.log(Level.SEVERE, "markers.csv not found", e);
log.log(Level.SEVERE, "markers.txt not found", e);
}
finally
{
@ -706,41 +719,53 @@ public class MapManager extends Thread {
}
}
/* load the warps file (doesn't work with SQL data source) */
/* find a way to load this from the server itself, loading the file each time isn't good */
public ArrayList<Warp> loadWarps()
/* TODO: Is there a cleaner way to get warps/homes than using custom DataSource classes to expose the protected properties? */
protected List<Warp> loadWarps()
{
ArrayList<Warp> warps = new ArrayList<Warp>();
Scanner scanner = null;
try
{
scanner = new Scanner(new FileInputStream("warps.txt"), "UTF-8");
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
String[] values = line.split(":");
Warp warp = new Warp();
warp.Name = values[0];
warp.Location = new Location(
Double.parseDouble(values[1]),
Double.parseDouble(values[2]),
Double.parseDouble(values[3]),
Float.parseFloat(values[4]),
Float.parseFloat(values[5])
);
warps.add(warp);
}
}
catch(FileNotFoundException e)
{
PropertiesFile props = new PropertiesFile("server.properties");
}
finally
{
if (scanner != null) scanner.close();
}
return warps;
List<Warp> warps = null;
if (props.getString("data-source").equals("flatfile")) {
DMFlatFileSource dataSource = new DMFlatFileSource();
dataSource.initialize();
dataSource.loadWarps();
dataSource.loadHomes();
warps = dataSource.getAllWarps();
}
else if (props.getString("data-source").equals("mysql")) {
DMMySQLSource dataSource = new DMMySQLSource();
dataSource.initialize();
dataSource.loadWarps();
dataSource.loadHomes();
warps = dataSource.getAllWarps();
}
return warps;
}
protected List<Warp> loadHomes()
{
PropertiesFile props = new PropertiesFile("server.properties");
List<Warp> homes = null;
if (props.getString("data-source").equals("flatfile")) {
DMFlatFileSource dataSource = new DMFlatFileSource();
dataSource.initialize();
dataSource.loadWarps();
dataSource.loadHomes();
homes = dataSource.getAllHomes();
}
else if (props.getString("data-source").equals("mysql")) {
DMMySQLSource dataSource = new DMMySQLSource();
dataSource.initialize();
dataSource.loadWarps();
dataSource.loadHomes();
homes = dataSource.getAllHomes();
}
return homes;
}
}

View File

@ -1,7 +1,11 @@
import java.io.*;
import java.net.*;
import java.util.*;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
public class WebServerRequest extends Thread {
@ -77,14 +81,25 @@ public class WebServerRequest extends Thread {
sb.append(marker.name + " marker " + marker.owner + " " + marker.px + " " + marker.py + " " + marker.pz + "\n");
}
// TODO: Find a way to load the warps from the server. Currently loading the from the flatfile over and over...
ArrayList<Warp> warps = mgr.loadWarps();
List<Warp> warps = mgr.loadWarps();
List<Warp> homes = mgr.loadHomes();
for(Warp warp : warps)
{
sb.append(warp.Name + " warp unknown " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n");
Location spawnLocation = etc.getServer().getSpawnLocation();
if (warps != null) {
for(Warp warp : warps) {
sb.append(warp.Name + " warp unknown " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n");
}
}
if (homes != null) {
for(Warp warp : homes) {
sb.append(warp.Name + " home " + warp.Name + " " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n");
}
}
sb.append("Spawn spawn none " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n");
synchronized(mgr.lock) {
for(TileUpdate tu : mgr.tileUpdates) {
if(tu.at >= cutoff) {

View File

@ -1,9 +1,24 @@
@ECHO OFF
CD E:\Users\Fescen9\workspace\DynamicMap\branches\fescen9
del *.class
del ..\..\..\map.jar
CD E:\Projects\DynamicMap\branches\fescen9
CALL clean.bat
MKDIR plugins
MKDIR plugins\web
MKDIR plugins\web\tiles
MKDIR plugins\web\up
javac *.java -cp ..\..\..\Minecraft_Mod.jar;..\..\..\minecraft_server.jar
jar cvf ..\..\..\map.jar *.class
jar cvf plugins\map.jar *.class
COPY colors.txt .\plugins
COPY readme.txt .\plugins
COPY .\web\*.* .\plugins\web
COPY .\web\tiles\*.* .\plugins\web\tiles
COPY .\web\up\*.* .\plugins\web\up
CALL "C:\Program Files\WinRAR\Rar.exe" a -m5 -ed -r DynamicMap.rar .\plugins\*.*
PAUSE

View File

@ -1,5 +1,7 @@
@ECHO OFF
CD E:\Users\Fescen9\workspace\DynamicMap\branches\fescen9
del *.class
del ..\..\..\map.jar
CD E:\Projects\DynamicMap\branches\fescen9
DEL /Q *.rar
DEL /Q *.class
RMDIR /S /Q .\plugins

BIN
web/home.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

View File

@ -21,10 +21,14 @@
</div>
<div id="controls">
<form action="#" method="get">
<img src="watch.png" alt="warps" title="Warps" />
<img src="warp.png" alt="Warps" title="Warps" />
<input type="checkbox" checked="checked" id="showWarps" /><br />
<img src="sign.png" alt="marker" title="Markers" />
<input type="checkbox" checked="checked" id="showMarkers" />
<img src="marker.png" alt="Markers" title="Markers" />
<input type="checkbox" checked="checked" id="showMarkers" /><br />
<img src="home.png" alt="Homes" title="Homes" />
<input type="checkbox" checked="checked" id="showHomes" /><br />
<img src="spawn.png" alt="Spawn" title="Spawn" />
<input type="checkbox" checked="checked" id="showSpawn" /><br />
</form>
</div>
<div id="link"></div>

View File

@ -1,6 +1,6 @@
var setup = {
tileUrl: 'http://www.yourdomain.com/minecraft/tiles/',
updateUrl: 'http://www.yourdomain.com/minecraft/up/',
updateUrl: 'http://www.yourdomain.com/minecraft/up/', // Or if using ASP.NET: http://www.yourdomain.com/minecraft/up/default.aspx?lasttimestamp=
updateRate: 2000 //Seconds the map should poll for updates. (Seconds) * 1000. The default is 2000 (every 2 seconds).
};
@ -566,6 +566,8 @@ function makeRequest(url, func, type, fail, post, contenttype)
var loggedin = new Array();
var showWarps = document.getElementById('showWarps').checked;
var showMarkers = document.getElementById('showMarkers').checked;
var showHomes = document.getElementById('showHomes').checked;
var showSpawn = document.getElementById('showSpawn').checked;
lasttimestamp = rows[0];
delete rows[0];
@ -574,6 +576,12 @@ function makeRequest(url, func, type, fail, post, contenttype)
for(var line in rows) {
var p = rows[line].split(' ');
// Hack to keep duplicate markers/warps/players from conflicting with eachother
if(p.length == 6) {
p[0] = p[0] + '<span style="display:none;">' + p[1] + '</span>';
}
loggedin[p[0]] = 1;
if(p[0] == '') continue;
@ -599,22 +607,25 @@ function makeRequest(url, func, type, fail, post, contenttype)
labelClass: "labels",
clickable: false,
flat: true,
icon: new google.maps.MarkerImage('marker.png', new google.maps.Size(28, 28), new google.maps.Point(0, 0), new google.maps.Point(14, 14))
icon: new google.maps.MarkerImage('player.png', new google.maps.Size(28, 28), new google.maps.Point(0, 0), new google.maps.Point(14, 14))
});
markers[p[0]] = marker;
}
} else if(p.length == 6) {
var image = 'sign.png';
if (p[1] == 'warp')
{
image = 'watch.png';
}
var image = p[1] + '.png';
var hideMarker = (
(p[1] == 'warp' && showWarps == false) ||
(p[1] == 'marker' && showMarkers == false) ||
(p[1] == 'home' && showHomes == false) ||
(p[1] == 'spawn' && showSpawn == false)
);
if(p[0] in markers) {
var m = markers[p[0]];
if ((p[1] == 'warp' && showWarps == false) || (p[1] == 'marker' && showMarkers == false)) {
if (hideMarker) {
m.setMap(null);
continue;
}
@ -625,7 +636,7 @@ function makeRequest(url, func, type, fail, post, contenttype)
var converted = fromWorldToLatLng(p[3], p[4], p[5]);
m.setPosition(converted);
} else {
if ((p[1] == 'warp' && showWarps == false) || (p[1] == 'marker' && showMarkers == false)) {
if (hideMarker) {
continue;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 620 B

After

Width:  |  Height:  |  Size: 681 B

BIN
web/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 681 B

BIN
web/spawn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB