Initial bukket work, now compileable

This commit is contained in:
FrozenCow 2011-01-03 23:15:58 +01:00
parent 3c7f164823
commit 80f9435a1a
11 changed files with 314 additions and 272 deletions

View File

@ -1,16 +1,11 @@
<project name="dynmap" default="dist" basedir="."> <project name="dynmap" default="dist" basedir=".">
<!-- Change the following two properties to the correct jar files --> <property name="pluginname" value="dynmap"/>
<property name="minecraftserver.jar" location="../../minecraft_server.jar"/> <property name="bukkit.jar" location="../../bukkit.jar"/>
<property name="hmod.jar" location="../../Minecraft_Mod.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="src" location="src"/>
<property name="bin" location="bin"/> <property name="bin" location="bin"/>
<property name="dist" location="dist"/> <property name="dist" location="dist"/>
<property name="web" location="web"/>
<target name="init"> <target name="init">
<mkdir dir="${bin}"/> <mkdir dir="${bin}"/>
@ -19,34 +14,21 @@
<target name="compile" depends="init"> <target name="compile" depends="init">
<javac srcdir="${src}" destdir="${bin}" includeantruntime="false"> <javac srcdir="${src}" destdir="${bin}" includeantruntime="false">
<classpath> <classpath>
<pathelement location="${hmod.jar}"/> <pathelement location="${bukkit.jar}"/>
<pathelement location="${minecraftserver.jar}"/>
</classpath> </classpath>
</javac> </javac>
</target> </target>
<target name="dist" depends="compile"> <target name="dist" depends="compile">
<mkdir dir="${dist}"/> <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>
<target name="deploy" depends="dist"> <target name="deploy" depends="dist">
<copy file="${dist}/map.jar" todir="${plugins}"/> <copy file="${dist}/${pluginname}.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>
</target> </target>
<target name="clean"> <target name="clean">

View File

@ -2,12 +2,12 @@
import java.util.List; import java.util.List;
public class DMFlatFileSource extends FlatFileSource { public class DMFlatFileSource{/* extends FlatFileSource {
public List<Warp> getAllWarps() { public List<Warp> getAllWarps() {
return this.warps; return this.warps;
} }
public List<Warp> getAllHomes() { public List<Warp> getAllHomes() {
return this.homes; return this.homes;
} }*/
} }

View File

@ -2,12 +2,12 @@
import java.util.List; import java.util.List;
public class DMMySQLSource extends MySQLSource { public class DMMySQLSource{/* extends MySQLSource {
public List<Warp> getAllWarps() { public List<Warp> getAllWarps() {
return this.warps; return this.warps;
} }
public List<Warp> getAllHomes() { public List<Warp> getAllHomes() {
return this.homes; return this.homes;
} }*/
} }

View File

@ -2,8 +2,10 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.logging.Logger; 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 static final Logger log = Logger.getLogger("Minecraft");
private MapManager mgr; private MapManager mgr;
@ -12,6 +14,14 @@ public class MapListener extends PluginListener {
this.mgr = mgr; 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 @Override
public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked, int itemInHand) public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked, int itemInHand)
{ {
@ -147,5 +157,5 @@ public class MapListener extends PluginListener {
} }
return false; return false;
} }*/
} }

View File

@ -30,11 +30,15 @@ import java.util.Vector;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.*;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
public class MapManager extends Thread { public class MapManager extends Thread {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
public map etc;
/* dimensions of a map tile */ /* dimensions of a map tile */
public static final int tileWidth = 128; public static final int tileWidth = 128;
public static final int tileHeight = 128; public static final int tileHeight = 128;
@ -93,7 +97,7 @@ public class MapManager extends Thread {
public String debugPlayer = null; public String debugPlayer = null;
/* hashmap of signs */ /* hashmap of signs */
public HashMap<String, Warp> signs = null; //public HashMap<String, Warp> signs = null;
/* cache this many zoomed-out tiles */ /* cache this many zoomed-out tiles */
public static final int zoomCacheSize = 64; public static final int zoomCacheSize = 64;
@ -121,13 +125,14 @@ public class MapManager extends Thread {
Server s = etc.getServer(); Server s = etc.getServer();
Player p = s.getPlayer(debugPlayer); Player p = s.getPlayer(debugPlayer);
if(p == null) return; 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 */ /* load configuration */
PropertiesFile properties; /*PropertiesFile properties;
properties = new PropertiesFile("server.properties"); properties = new PropertiesFile("server.properties");
try { try {
@ -140,7 +145,21 @@ public class MapManager extends Thread {
generatePortraits = !properties.getString("map-generateportraits", "0").equals("0"); generatePortraits = !properties.getString("map-generateportraits", "0").equals("0");
} catch(Exception ex) { } catch(Exception ex) {
log.log(Level.SEVERE, "Exception while reading properties for dynamic map", 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>(); tileStore = new HashMap<Long, MapTile>();
staleTiles = new LinkedList<MapTile>(); staleTiles = new LinkedList<MapTile>();
@ -149,9 +168,9 @@ public class MapManager extends Thread {
caveTileUpdates = new LinkedList<TileUpdate>(); caveTileUpdates = new LinkedList<TileUpdate>();
zoomCache = new Cache<String, BufferedImage>(zoomCacheSize); zoomCache = new Cache<String, BufferedImage>(zoomCacheSize);
signs = new HashMap<String, Warp>(); // signs = new HashMap<String, Warp>();
loadShowOptions(); // loadShowOptions();
} }
/* tile X for position x */ /* tile X for position x */
@ -199,7 +218,7 @@ public class MapManager extends Thread {
/* load colorset */ /* load colorset */
File cfile = new File(colorsetpath); File cfile = new File(colorsetpath);
loadSigns(); //loadSigns();
try { try {
Scanner scanner = new Scanner(cfile); Scanner scanner = new Scanner(cfile);
@ -442,7 +461,7 @@ public class MapManager extends Thread {
if(t == null) { if(t == null) {
/* no maptile exists, need to create one */ /* 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); tileStore.put(key, t);
return t; return t;
} else { } else {
@ -485,11 +504,12 @@ public class MapManager extends Thread {
open.add(first); open.add(first);
Server s = etc.getServer(); Server s = etc.getServer();
World w = etc.getWorld();
while(open.size() > 0) { while(open.size() > 0) {
MapTile t = open.remove(open.size() - 1); MapTile t = open.remove(open.size() - 1);
if(t.stale) continue; 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); log.info("walking: " + t.mx + ", " + t.mz + ", h = " + h);
if(h < 1) if(h < 1)
@ -651,7 +671,7 @@ public class MapManager extends Thread {
} }
/* adds a sign to the map */ /* 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)) if (signs.containsKey(name))
{ {
@ -675,10 +695,10 @@ public class MapManager extends Thread {
} }
return false; return false;
} }*/
/* removes a sign from the map */ /* removes a sign from the map */
public boolean removeSign(Player player, String name) /* public boolean removeSign(Player player, String name)
{ {
if (signs.containsKey(name)) if (signs.containsKey(name))
{ {
@ -702,10 +722,10 @@ public class MapManager extends Thread {
} }
return false; return false;
} }*/
/* teleports a user to a sign */ /* teleports a user to a sign */
public boolean teleportToSign(Player player, String name) /* public boolean teleportToSign(Player player, String name)
{ {
if (signs.containsKey(name)) if (signs.containsKey(name))
{ {
@ -719,10 +739,10 @@ public class MapManager extends Thread {
} }
return false; return false;
} }*/
/* load the map sign file */ /* load the map sign file */
private void loadSigns() /* private void loadSigns()
{ {
Scanner scanner = null; Scanner scanner = null;
try try
@ -779,10 +799,10 @@ public class MapManager extends Thread {
{ {
if (scanner != null) scanner.close(); if (scanner != null) scanner.close();
} }
} }*/
/* save the map sign file */ /* save the map sign file */
private void saveSigns() throws IOException /* private void saveSigns() throws IOException
{ {
Writer out = null; Writer out = null;
try try
@ -809,11 +829,11 @@ public class MapManager extends Thread {
{ {
if (out != null) out.close(); 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? */ /* 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; List<Warp> warps = null;
@ -940,5 +960,5 @@ public class MapManager extends Thread {
} }
return success; return success;
} }*/
} }

View File

@ -8,6 +8,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bukkit.World;
import org.bukkit.Server;
public class MapTile { public class MapTile {
protected static final Logger log = Logger.getLogger("Minecraft"); 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 */ /* whether the cave map of this tile needs to be updated */
boolean staleCave = false; boolean staleCave = false;
private map etc;
/* create new MapTile */ /* 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.px = px;
this.py = py; this.py = py;
this.zpx = zpx; this.zpx = zpx;
@ -51,17 +55,19 @@ public class MapTile {
int x, z; int x, z;
Server s = etc.getServer(); Server s = etc.getServer();
World w = etc.getWorld();
for(x=x1; x<x2; x+=16) { for(x=x1; x<x2; x+=16) {
for(z=z1; z<z2; z+=16) { for(z=z1; z<z2; z+=16) {
if(!s.isChunkLoaded(x, 0, z)) { if(!w.isChunkLoaded(w.getChunkAt(x, z))) {
log.info("map render loading chunk: " + x + ", 0, " + z); log.info("chunk not loaded: " + x + ", 0, " + z);
/*
try { try {
s.loadChunk(x, 0, z); s.loadChunk(x, 0, z);
} catch(Exception e) { } catch(Exception e) {
log.log(Level.SEVERE, "Caught exception from loadChunk!", e); log.log(Level.SEVERE, "Caught exception from loadChunk!", e);
} }*/
} }
} }
} }
@ -78,10 +84,11 @@ public class MapTile {
int x, z; int x, z;
Server s = etc.getServer(); Server s = etc.getServer();
World w = etc.getWorld();
for(x=x1; x<x2; x+=16) { for(x=x1; x<x2; x+=16) {
for(z=z1; z<z2; z+=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. // Will try to load chunk.
//log.info("chunk not loaded: " + x + ", " + z + " for tile " + this.toString()); //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) private Color scan(MapManager mgr, int x, int y, int z, int seq)
{ {
Server s = etc.getServer(); Server s = etc.getServer();
World w = etc.getWorld();
for(;;) { for(;;) {
if(y < 0) if(y < 0)
return Color.BLUE; return Color.BLUE;
int id = s.getBlockIdAt(x, y, z); int id = w.getBlockAt(x, y, z).getTypeID();
switch(seq) { switch(seq) {
case 0: case 0:
@ -438,13 +445,14 @@ public class MapTile {
private Color caveScan(MapManager mgr, int x, int y, int z, int seq) private Color caveScan(MapManager mgr, int x, int y, int z, int seq)
{ {
Server s = etc.getServer(); Server s = etc.getServer();
World w = etc.getWorld();
boolean air = true; boolean air = true;
for(;;) { for(;;) {
if(y < 0) if(y < 0)
return Color.BLACK; return Color.BLACK;
int id = s.getBlockIdAt(x, y, z); int id = w.getBlockAt(x, y, z).getTypeID();
switch(seq) { switch(seq) {
case 0: case 0:

View File

@ -1,6 +1,7 @@
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
import org.bukkit.*;
import java.util.logging.Logger; import java.util.logging.Logger;

View File

@ -7,15 +7,18 @@ import java.net.Socket;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.*;
public class WebServerRequest extends Thread { public class WebServerRequest extends Thread {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
private Socket sock; private Socket sock;
private MapManager mgr; private MapManager mgr;
private map etc;
public WebServerRequest(Socket socket, MapManager mgr) public WebServerRequest(Socket socket, MapManager mgr)
{ {
this.etc = mgr.etc;
sock = socket; sock = socket;
this.mgr = mgr; this.mgr = mgr;
} }
@ -71,18 +74,19 @@ public class WebServerRequest extends Thread {
sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis()); sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis());
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(current + " " + etc.getServer().getRelativeTime() + "\n"); //sb.append(current + " " + etc.getServer().getRelativeTime() + "\n");
sb.append(current + " " + 0 +"\n");
if (mgr.showPlayers) { if (mgr.showPlayers) {
for(Player player : etc.getServer().getPlayerList()) { for(Player player : etc.getServer().getOnlinePlayers()) {
sb.append(player.getName() + " player " + player.getX() + " " + player.getY() + " " + player.getZ() + "\n"); sb.append(player.getName() + " player " + player.getLocation().getX() + " " + player.getLocation().getY() + " " + player.getLocation().getZ() + "\n");
} }
} }
if (mgr.showSigns) { /*if (mgr.showSigns) {
for(Warp sign : mgr.signs.values()) for(Warp sign : mgr.signs.values())
{ {
sb.append(sign.Name + " sign " + sign.Location.x + " " + sign.Location.y + " " + sign.Location.z + "\n"); sb.append(sign.Name + " sign " + sign.Location.getX() + " " + sign.Location.getY() + " " + sign.Location.getZ() + "\n");
} }
} }
@ -91,7 +95,7 @@ public class WebServerRequest extends Thread {
if (warps != null) { if (warps != null) {
for(Warp warp : warps) { for(Warp warp : warps) {
sb.append(warp.Name + " warp " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); sb.append(warp.Name + " warp " + warp.Location.getX() + " " + warp.Location.getY() + " " + warp.Location.getZ() + "\n");
} }
} }
} }
@ -110,7 +114,7 @@ public class WebServerRequest extends Thread {
Location spawnLocation = etc.getServer().getSpawnLocation(); Location spawnLocation = etc.getServer().getSpawnLocation();
sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n"); sb.append("Spawn spawn " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n");
} }*/
synchronized(mgr.lock) { synchronized(mgr.lock) {
for(TileUpdate tu : mgr.tileUpdates) { for(TileUpdate tu : mgr.tileUpdates) {

View File

@ -1,7 +1,14 @@
import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.IOException; 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"); protected static final Logger log = Logger.getLogger("Minecraft");
@ -9,11 +16,20 @@ public class map extends Plugin {
private MapManager mgr = null; private MapManager mgr = null;
private MapListener listener = 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 @Override
public void enable() { public void onEnable() {
log.info("Map INIT"); log.info("Map INIT");
mgr = new MapManager(); mgr = new MapManager(this);
mgr.startManager(); mgr.startManager();
try { try {
@ -26,7 +42,7 @@ public class map extends Plugin {
} }
@Override @Override
public void disable() { public void onDisable() {
log.info("Map UNINIT"); log.info("Map UNINIT");
mgr.stopManager(); mgr.stopManager();
@ -37,9 +53,10 @@ public class map extends Plugin {
} }
} }
@Override public void registerEvents() {
public void initialize() { getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, listener, Priority.Normal, this);
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM); //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_CREATED, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_DESTROYED, 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); 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("/addsign", " [name] - adds a named sign to the map");
etc.getInstance().addCommand("/removesign", " [name] - removes 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("/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");*/
} }
} }