mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-24 03:05:28 +01:00
Initial bukket work, now compileable
This commit is contained in:
parent
3c7f164823
commit
80f9435a1a
38
build.xml
38
build.xml
@ -1,16 +1,11 @@
|
||||
<project name="dynmap" default="dist" basedir=".">
|
||||
<!-- Change the following two properties to the correct jar files -->
|
||||
<property name="minecraftserver.jar" location="../../minecraft_server.jar"/>
|
||||
<property name="hmod.jar" location="../../Minecraft_Mod.jar"/>
|
||||
<property name="pluginname" value="dynmap"/>
|
||||
<property name="bukkit.jar" location="../../bukkit.jar"/>
|
||||
<property name="plugins" location="../../plugins/"/>
|
||||
|
||||
<property name="minecraft" location="../../"/>
|
||||
<property name="plugins" location="${minecraft}/plugins/"/>
|
||||
<property name="http_root" location="/srv/http/dynmap/"/>
|
||||
|
||||
<property name="src" location="src"/>
|
||||
<property name="bin" location="bin"/>
|
||||
<property name="dist" location="dist"/>
|
||||
<property name="web" location="web"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${bin}"/>
|
||||
@ -19,38 +14,25 @@
|
||||
<target name="compile" depends="init">
|
||||
<javac srcdir="${src}" destdir="${bin}" includeantruntime="false">
|
||||
<classpath>
|
||||
<pathelement location="${hmod.jar}"/>
|
||||
<pathelement location="${minecraftserver.jar}"/>
|
||||
<pathelement location="${bukkit.jar}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="compile">
|
||||
<mkdir dir="${dist}"/>
|
||||
<jar jarfile="${dist}/map.jar" basedir="${bin}"/>
|
||||
<jar jarfile="${dist}/${pluginname}.jar">
|
||||
<fileset dir="${bin}"/>
|
||||
<fileset file="${src}/plugin.yml"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="deploy" depends="dist">
|
||||
<copy file="${dist}/map.jar" todir="${plugins}"/>
|
||||
<copy file="colors.txt" todir="${minecraft}"/>
|
||||
<copy todir="${http_root}">
|
||||
<fileset dir="web"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="release" depends="dist">
|
||||
<delete file="dynmap.zip"/>
|
||||
<zip destfile="dynmap.zip">
|
||||
<zipfileset dir="." includes="README.md" fullpath="readme.txt"/>
|
||||
<zipfileset dir="." includes="build.xml"/>
|
||||
<zipfileset dir="${dist}" includes="*.jar"/>
|
||||
<zipfileset dir="${src}" includes="*.java" prefix="src/"/>
|
||||
<zipfileset dir="${web}" includes="**" prefix="web/"/>
|
||||
</zip>
|
||||
<copy file="${dist}/${pluginname}.jar" todir="${plugins}"/>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${bin}"/>
|
||||
<delete dir="${dist}"/>
|
||||
</target>
|
||||
</project>
|
||||
</project>
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DMFlatFileSource extends FlatFileSource {
|
||||
public class DMFlatFileSource{/* extends FlatFileSource {
|
||||
public List<Warp> getAllWarps() {
|
||||
return this.warps;
|
||||
}
|
||||
|
||||
public List<Warp> getAllHomes() {
|
||||
return this.homes;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DMMySQLSource extends MySQLSource {
|
||||
public class DMMySQLSource{/* extends MySQLSource {
|
||||
public List<Warp> getAllWarps() {
|
||||
return this.warps;
|
||||
}
|
||||
|
||||
public List<Warp> getAllHomes() {
|
||||
return this.homes;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.event.block.*;
|
||||
|
||||
public class MapListener extends PluginListener {
|
||||
public class MapListener extends BlockListener {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
private MapManager mgr;
|
||||
|
||||
@ -12,6 +14,14 @@ public class MapListener extends PluginListener {
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlaced(BlockPlacedEvent event) {
|
||||
Block blockPlaced = event.getBlock();
|
||||
if(mgr.touch(blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ()))
|
||||
mgr.debug(/*player.getName() + */" touch " + blockPlaced.getX() + "," + blockPlaced.getY() + "," + blockPlaced.getZ() + " from onBlockCreate");
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked, int itemInHand)
|
||||
{
|
||||
@ -147,5 +157,5 @@ public class MapListener extends PluginListener {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -30,11 +30,15 @@ import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.*;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class MapManager extends Thread {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
public map etc;
|
||||
|
||||
/* dimensions of a map tile */
|
||||
public static final int tileWidth = 128;
|
||||
public static final int tileHeight = 128;
|
||||
@ -93,7 +97,7 @@ public class MapManager extends Thread {
|
||||
public String debugPlayer = null;
|
||||
|
||||
/* hashmap of signs */
|
||||
public HashMap<String, Warp> signs = null;
|
||||
//public HashMap<String, Warp> signs = null;
|
||||
|
||||
/* cache this many zoomed-out tiles */
|
||||
public static final int zoomCacheSize = 64;
|
||||
@ -121,13 +125,14 @@ public class MapManager extends Thread {
|
||||
Server s = etc.getServer();
|
||||
Player p = s.getPlayer(debugPlayer);
|
||||
if(p == null) return;
|
||||
p.sendMessage("Map> " + Colors.Red + msg);
|
||||
p.sendMessage("Map> " + Color.RED + msg);
|
||||
}
|
||||
|
||||
public MapManager()
|
||||
public MapManager(map plugin)
|
||||
{
|
||||
etc = plugin;
|
||||
/* load configuration */
|
||||
PropertiesFile properties;
|
||||
/*PropertiesFile properties;
|
||||
|
||||
properties = new PropertiesFile("server.properties");
|
||||
try {
|
||||
@ -140,7 +145,21 @@ public class MapManager extends Thread {
|
||||
generatePortraits = !properties.getString("map-generateportraits", "0").equals("0");
|
||||
} catch(Exception ex) {
|
||||
log.log(Level.SEVERE, "Exception while reading properties for dynamic map", ex);
|
||||
}*/
|
||||
tilepath = "/srv/http/dynmap/tiles/";
|
||||
colorsetpath = "colors.txt";
|
||||
signspath = "signs.txt";
|
||||
serverport = 8123;
|
||||
datasource = "flatfile";
|
||||
showmarkers = "all";
|
||||
{
|
||||
showSpawn = true;
|
||||
showHomes = true;
|
||||
showWarps = true;
|
||||
showSigns = true;
|
||||
showPlayers = true;
|
||||
}
|
||||
generatePortraits = false;
|
||||
|
||||
tileStore = new HashMap<Long, MapTile>();
|
||||
staleTiles = new LinkedList<MapTile>();
|
||||
@ -149,9 +168,9 @@ public class MapManager extends Thread {
|
||||
caveTileUpdates = new LinkedList<TileUpdate>();
|
||||
zoomCache = new Cache<String, BufferedImage>(zoomCacheSize);
|
||||
|
||||
signs = new HashMap<String, Warp>();
|
||||
// signs = new HashMap<String, Warp>();
|
||||
|
||||
loadShowOptions();
|
||||
// loadShowOptions();
|
||||
}
|
||||
|
||||
/* tile X for position x */
|
||||
@ -199,7 +218,7 @@ public class MapManager extends Thread {
|
||||
/* load colorset */
|
||||
File cfile = new File(colorsetpath);
|
||||
|
||||
loadSigns();
|
||||
//loadSigns();
|
||||
|
||||
try {
|
||||
Scanner scanner = new Scanner(cfile);
|
||||
@ -442,7 +461,7 @@ public class MapManager extends Thread {
|
||||
if(t == null) {
|
||||
/* no maptile exists, need to create one */
|
||||
|
||||
t = new MapTile(px, py, ztilex(px), ztiley(py));
|
||||
t = new MapTile(etc, px, py, ztilex(px), ztiley(py));
|
||||
tileStore.put(key, t);
|
||||
return t;
|
||||
} else {
|
||||
@ -485,11 +504,12 @@ public class MapManager extends Thread {
|
||||
open.add(first);
|
||||
|
||||
Server s = etc.getServer();
|
||||
World w = etc.getWorld();
|
||||
|
||||
while(open.size() > 0) {
|
||||
MapTile t = open.remove(open.size() - 1);
|
||||
if(t.stale) continue;
|
||||
int h = s.getHighestBlockY(t.mx, t.mz);
|
||||
int h = w.getHighestBlockYAt(t.mx, t.mz);
|
||||
|
||||
log.info("walking: " + t.mx + ", " + t.mz + ", h = " + h);
|
||||
if(h < 1)
|
||||
@ -651,7 +671,7 @@ public class MapManager extends Thread {
|
||||
}
|
||||
|
||||
/* adds a sign to the map */
|
||||
public boolean addSign(Player player, String name, double px, double py, double pz)
|
||||
/* public boolean addSign(Player player, String name, double px, double py, double pz)
|
||||
{
|
||||
if (signs.containsKey(name))
|
||||
{
|
||||
@ -675,10 +695,10 @@ public class MapManager extends Thread {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* removes a sign from the map */
|
||||
public boolean removeSign(Player player, String name)
|
||||
/* public boolean removeSign(Player player, String name)
|
||||
{
|
||||
if (signs.containsKey(name))
|
||||
{
|
||||
@ -702,10 +722,10 @@ public class MapManager extends Thread {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* teleports a user to a sign */
|
||||
public boolean teleportToSign(Player player, String name)
|
||||
/* public boolean teleportToSign(Player player, String name)
|
||||
{
|
||||
if (signs.containsKey(name))
|
||||
{
|
||||
@ -719,10 +739,10 @@ public class MapManager extends Thread {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
/* load the map sign file */
|
||||
private void loadSigns()
|
||||
/* private void loadSigns()
|
||||
{
|
||||
Scanner scanner = null;
|
||||
try
|
||||
@ -779,10 +799,10 @@ public class MapManager extends Thread {
|
||||
{
|
||||
if (scanner != null) scanner.close();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/* save the map sign file */
|
||||
private void saveSigns() throws IOException
|
||||
/* private void saveSigns() throws IOException
|
||||
{
|
||||
Writer out = null;
|
||||
try
|
||||
@ -809,11 +829,11 @@ public class MapManager extends Thread {
|
||||
{
|
||||
if (out != null) out.close();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/* TODO: Is there a cleaner way to get warps/homes than using custom DataSource classes to expose the protected properties? */
|
||||
|
||||
protected List<Warp> loadWarps()
|
||||
/* protected List<Warp> loadWarps()
|
||||
{
|
||||
List<Warp> warps = null;
|
||||
|
||||
@ -940,5 +960,5 @@ public class MapManager extends Thread {
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Server;
|
||||
|
||||
public class MapTile {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
@ -27,9 +29,11 @@ public class MapTile {
|
||||
/* whether the cave map of this tile needs to be updated */
|
||||
boolean staleCave = false;
|
||||
|
||||
private map etc;
|
||||
/* create new MapTile */
|
||||
public MapTile(int px, int py, int zpx, int zpy)
|
||||
public MapTile(map etc, int px, int py, int zpx, int zpy)
|
||||
{
|
||||
this.etc = etc;
|
||||
this.px = px;
|
||||
this.py = py;
|
||||
this.zpx = zpx;
|
||||
@ -51,17 +55,19 @@ public class MapTile {
|
||||
|
||||
int x, z;
|
||||
Server s = etc.getServer();
|
||||
World w = etc.getWorld();
|
||||
|
||||
for(x=x1; x<x2; x+=16) {
|
||||
for(z=z1; z<z2; z+=16) {
|
||||
if(!s.isChunkLoaded(x, 0, z)) {
|
||||
log.info("map render loading chunk: " + x + ", 0, " + z);
|
||||
if(!w.isChunkLoaded(w.getChunkAt(x, z))) {
|
||||
log.info("chunk not loaded: " + x + ", 0, " + z);
|
||||
/*
|
||||
|
||||
try {
|
||||
s.loadChunk(x, 0, z);
|
||||
} catch(Exception e) {
|
||||
log.log(Level.SEVERE, "Caught exception from loadChunk!", e);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,10 +84,11 @@ public class MapTile {
|
||||
|
||||
int x, z;
|
||||
Server s = etc.getServer();
|
||||
World w = etc.getWorld();
|
||||
|
||||
for(x=x1; x<x2; x+=16) {
|
||||
for(z=z1; z<z2; z+=16) {
|
||||
if(!s.isChunkLoaded(x, 0, z)) {
|
||||
if(!w.isChunkLoaded(w.getChunkAt(x, z))) {
|
||||
// Will try to load chunk.
|
||||
//log.info("chunk not loaded: " + x + ", " + z + " for tile " + this.toString());
|
||||
|
||||
@ -380,12 +387,12 @@ public class MapTile {
|
||||
private Color scan(MapManager mgr, int x, int y, int z, int seq)
|
||||
{
|
||||
Server s = etc.getServer();
|
||||
|
||||
World w = etc.getWorld();
|
||||
for(;;) {
|
||||
if(y < 0)
|
||||
return Color.BLUE;
|
||||
|
||||
int id = s.getBlockIdAt(x, y, z);
|
||||
int id = w.getBlockAt(x, y, z).getTypeID();
|
||||
|
||||
switch(seq) {
|
||||
case 0:
|
||||
@ -438,13 +445,14 @@ public class MapTile {
|
||||
private Color caveScan(MapManager mgr, int x, int y, int z, int seq)
|
||||
{
|
||||
Server s = etc.getServer();
|
||||
World w = etc.getWorld();
|
||||
boolean air = true;
|
||||
|
||||
for(;;) {
|
||||
if(y < 0)
|
||||
return Color.BLACK;
|
||||
|
||||
int id = s.getBlockIdAt(x, y, z);
|
||||
int id = w.getBlockAt(x, y, z).getTypeID();
|
||||
|
||||
switch(seq) {
|
||||
case 0:
|
||||
|
@ -1,53 +1,54 @@
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class WebServer extends Thread {
|
||||
|
||||
public static final String VERSION = "Huncraft";
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private ServerSocket sock = null;
|
||||
private boolean running = false;
|
||||
|
||||
private MapManager mgr;
|
||||
|
||||
public WebServer(int port, MapManager mgr) throws IOException
|
||||
{
|
||||
this.mgr = mgr;
|
||||
sock = new ServerSocket(port, 5, InetAddress.getByName("127.0.0.1"));
|
||||
running = true;
|
||||
start();
|
||||
log.info("map WebServer started on port " + port);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
while (running) {
|
||||
try {
|
||||
Socket socket = sock.accept();
|
||||
WebServerRequest requestThread = new WebServerRequest(socket, mgr);
|
||||
requestThread.start();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.info("map WebServer.run() stops with IOException");
|
||||
break;
|
||||
}
|
||||
}
|
||||
log.info("map WebServer run() exiting");
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
try {
|
||||
if(sock != null) {
|
||||
sock.close();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
log.info("map stop() got IOException while closing socket");
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import org.bukkit.*;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class WebServer extends Thread {
|
||||
|
||||
public static final String VERSION = "Huncraft";
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private ServerSocket sock = null;
|
||||
private boolean running = false;
|
||||
|
||||
private MapManager mgr;
|
||||
|
||||
public WebServer(int port, MapManager mgr) throws IOException
|
||||
{
|
||||
this.mgr = mgr;
|
||||
sock = new ServerSocket(port, 5, InetAddress.getByName("127.0.0.1"));
|
||||
running = true;
|
||||
start();
|
||||
log.info("map WebServer started on port " + port);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
while (running) {
|
||||
try {
|
||||
Socket socket = sock.accept();
|
||||
WebServerRequest requestThread = new WebServerRequest(socket, mgr);
|
||||
requestThread.start();
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.info("map WebServer.run() stops with IOException");
|
||||
break;
|
||||
}
|
||||
}
|
||||
log.info("map WebServer run() exiting");
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
try {
|
||||
if(sock != null) {
|
||||
sock.close();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
log.info("map stop() got IOException while closing socket");
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
@ -1,145 +1,149 @@
|
||||
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 {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private Socket sock;
|
||||
private MapManager mgr;
|
||||
|
||||
public WebServerRequest(Socket socket, MapManager mgr)
|
||||
{
|
||||
sock = socket;
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
private static void sendHeader(BufferedOutputStream out, int code, String contentType, long contentLength, long lastModified) throws IOException
|
||||
{
|
||||
out.write(("HTTP/1.0 " + code + " OK\r\n" +
|
||||
"Date: " + new Date().toString() + "\r\n" +
|
||||
"Server: JibbleWebServer/1.0\r\n" +
|
||||
"Content-Type: " + contentType + "\r\n" +
|
||||
"Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n" +
|
||||
((contentLength != -1) ? "Content-Length: " + contentLength + "\r\n" : "") +
|
||||
"Last-modified: " + new Date(lastModified).toString() + "\r\n" +
|
||||
"\r\n").getBytes());
|
||||
}
|
||||
|
||||
private static void sendError(BufferedOutputStream out, int code, String message) throws IOException
|
||||
{
|
||||
message = message + "<hr>" + WebServer.VERSION;
|
||||
sendHeader(out, code, "text/html", message.length(), System.currentTimeMillis());
|
||||
out.write(message.getBytes());
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
InputStream reader = null;
|
||||
try {
|
||||
sock.setSoTimeout(30000);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
|
||||
BufferedOutputStream out = new BufferedOutputStream(sock.getOutputStream());
|
||||
|
||||
String request = in.readLine();
|
||||
if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) {
|
||||
// Invalid request type (no "GET")
|
||||
sendError(out, 500, "Invalid Method.");
|
||||
return;
|
||||
}
|
||||
|
||||
String path = request.substring(4, request.length() - 9);
|
||||
|
||||
int current = (int) (System.currentTimeMillis() / 1000);
|
||||
long cutoff = 0;
|
||||
|
||||
if(path.charAt(0) == '/') {
|
||||
try {
|
||||
cutoff = ((long) Integer.parseInt(path.substring(1))) * 1000;
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(current + " " + etc.getServer().getRelativeTime() + "\n");
|
||||
|
||||
if (mgr.showPlayers) {
|
||||
for(Player player : etc.getServer().getPlayerList()) {
|
||||
sb.append(player.getName() + " player " + player.getX() + " " + player.getY() + " " + player.getZ() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showSigns) {
|
||||
for(Warp sign : mgr.signs.values())
|
||||
{
|
||||
sb.append(sign.Name + " sign " + sign.Location.x + " " + sign.Location.y + " " + sign.Location.z + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showWarps) {
|
||||
List<Warp> warps = mgr.loadWarps();
|
||||
|
||||
if (warps != null) {
|
||||
for(Warp warp : warps) {
|
||||
sb.append(warp.Name + " warp " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showHomes) {
|
||||
List<Warp> homes = mgr.loadHomes();
|
||||
|
||||
if (homes != null) {
|
||||
for(Warp warp : homes) {
|
||||
sb.append(warp.Name + " home " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showSpawn) {
|
||||
Location spawnLocation = etc.getServer().getSpawnLocation();
|
||||
|
||||
sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n");
|
||||
}
|
||||
|
||||
synchronized(mgr.lock) {
|
||||
for(TileUpdate tu : mgr.tileUpdates) {
|
||||
if(tu.at >= cutoff) {
|
||||
sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " t\n");
|
||||
}
|
||||
}
|
||||
|
||||
for(TileUpdate tu : mgr.caveTileUpdates) {
|
||||
if(tu.at >= cutoff) {
|
||||
sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " c\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.write(sb.toString().getBytes());
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
}
|
||||
catch (Exception anye) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
import org.bukkit.*;
|
||||
|
||||
public class WebServerRequest extends Thread {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
private Socket sock;
|
||||
private MapManager mgr;
|
||||
private map etc;
|
||||
|
||||
public WebServerRequest(Socket socket, MapManager mgr)
|
||||
{
|
||||
this.etc = mgr.etc;
|
||||
sock = socket;
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
private static void sendHeader(BufferedOutputStream out, int code, String contentType, long contentLength, long lastModified) throws IOException
|
||||
{
|
||||
out.write(("HTTP/1.0 " + code + " OK\r\n" +
|
||||
"Date: " + new Date().toString() + "\r\n" +
|
||||
"Server: JibbleWebServer/1.0\r\n" +
|
||||
"Content-Type: " + contentType + "\r\n" +
|
||||
"Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n" +
|
||||
((contentLength != -1) ? "Content-Length: " + contentLength + "\r\n" : "") +
|
||||
"Last-modified: " + new Date(lastModified).toString() + "\r\n" +
|
||||
"\r\n").getBytes());
|
||||
}
|
||||
|
||||
private static void sendError(BufferedOutputStream out, int code, String message) throws IOException
|
||||
{
|
||||
message = message + "<hr>" + WebServer.VERSION;
|
||||
sendHeader(out, code, "text/html", message.length(), System.currentTimeMillis());
|
||||
out.write(message.getBytes());
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
InputStream reader = null;
|
||||
try {
|
||||
sock.setSoTimeout(30000);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
|
||||
BufferedOutputStream out = new BufferedOutputStream(sock.getOutputStream());
|
||||
|
||||
String request = in.readLine();
|
||||
if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) {
|
||||
// Invalid request type (no "GET")
|
||||
sendError(out, 500, "Invalid Method.");
|
||||
return;
|
||||
}
|
||||
|
||||
String path = request.substring(4, request.length() - 9);
|
||||
|
||||
int current = (int) (System.currentTimeMillis() / 1000);
|
||||
long cutoff = 0;
|
||||
|
||||
if(path.charAt(0) == '/') {
|
||||
try {
|
||||
cutoff = ((long) Integer.parseInt(path.substring(1))) * 1000;
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
//sb.append(current + " " + etc.getServer().getRelativeTime() + "\n");
|
||||
sb.append(current + " " + 0 +"\n");
|
||||
|
||||
if (mgr.showPlayers) {
|
||||
for(Player player : etc.getServer().getOnlinePlayers()) {
|
||||
sb.append(player.getName() + " player " + player.getLocation().getX() + " " + player.getLocation().getY() + " " + player.getLocation().getZ() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*if (mgr.showSigns) {
|
||||
for(Warp sign : mgr.signs.values())
|
||||
{
|
||||
sb.append(sign.Name + " sign " + sign.Location.getX() + " " + sign.Location.getY() + " " + sign.Location.getZ() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showWarps) {
|
||||
List<Warp> warps = mgr.loadWarps();
|
||||
|
||||
if (warps != null) {
|
||||
for(Warp warp : warps) {
|
||||
sb.append(warp.Name + " warp " + warp.Location.getX() + " " + warp.Location.getY() + " " + warp.Location.getZ() + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showHomes) {
|
||||
List<Warp> homes = mgr.loadHomes();
|
||||
|
||||
if (homes != null) {
|
||||
for(Warp warp : homes) {
|
||||
sb.append(warp.Name + " home " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mgr.showSpawn) {
|
||||
Location spawnLocation = etc.getServer().getSpawnLocation();
|
||||
|
||||
sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n");
|
||||
}*/
|
||||
|
||||
synchronized(mgr.lock) {
|
||||
for(TileUpdate tu : mgr.tileUpdates) {
|
||||
if(tu.at >= cutoff) {
|
||||
sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " t\n");
|
||||
}
|
||||
}
|
||||
|
||||
for(TileUpdate tu : mgr.caveTileUpdates) {
|
||||
if(tu.at >= cutoff) {
|
||||
sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " c\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.write(sb.toString().getBytes());
|
||||
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
}
|
||||
catch (Exception anye) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
33
src/map.java
33
src/map.java
@ -1,7 +1,14 @@
|
||||
import java.util.logging.Logger;
|
||||
import java.io.IOException;
|
||||
|
||||
public class map extends Plugin {
|
||||
import java.io.File;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.plugin.*;
|
||||
import org.bukkit.plugin.java.*;
|
||||
|
||||
public class map extends JavaPlugin {
|
||||
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
@ -9,11 +16,20 @@ public class map extends Plugin {
|
||||
private MapManager mgr = null;
|
||||
private MapListener listener = null;
|
||||
|
||||
public map(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, plugin, cLoader);
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return getServer().getWorlds()[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
public void onEnable() {
|
||||
log.info("Map INIT");
|
||||
|
||||
mgr = new MapManager();
|
||||
mgr = new MapManager(this);
|
||||
mgr.startManager();
|
||||
|
||||
try {
|
||||
@ -26,7 +42,7 @@ public class map extends Plugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
public void onDisable() {
|
||||
log.info("Map UNINIT");
|
||||
|
||||
mgr.stopManager();
|
||||
@ -37,9 +53,10 @@ public class map extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
|
||||
public void registerEvents() {
|
||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, listener, Priority.Normal, this);
|
||||
//getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DESTROYED, listener, Priority.Normal, this);
|
||||
/* etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this, PluginListener.Priority.MEDIUM);
|
||||
etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this, PluginListener.Priority.MEDIUM);
|
||||
@ -52,6 +69,6 @@ public class map extends Plugin {
|
||||
etc.getInstance().addCommand("/addsign", " [name] - adds a named sign to the map");
|
||||
etc.getInstance().addCommand("/removesign", " [name] - removes a named sign to the map");
|
||||
etc.getInstance().addCommand("/listsigns", " - list all named signs");
|
||||
etc.getInstance().addCommand("/tpsign", " [name] - teleport to a named sign");
|
||||
etc.getInstance().addCommand("/tpsign", " [name] - teleport to a named sign");*/
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
Set map.js tileUrl to this folder
|
||||
Also set map-tilepath in server.properties to point to this folder.
|
||||
Set map.js tileUrl to this folder
|
||||
Also set map-tilepath in server.properties to point to this folder.
|
||||
New tile images will be generated here by the plugin
|
@ -1,2 +1,2 @@
|
||||
default.aspx is not required for all installations.
|
||||
default.aspx is not required for all installations.
|
||||
If you are running a windows server with IIS, it may help in your setup.
|
Loading…
Reference in New Issue
Block a user