Start sign support

This commit is contained in:
Mike Primm 2011-09-06 06:17:46 +08:00 committed by mikeprimm
parent e0fcca4b7f
commit 20e409b71f
3 changed files with 68 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerChatEvent;
@ -1152,7 +1153,7 @@ public class DynmapPlugin extends JavaPlugin {
case BLOCK_SPREAD:
case BLOCK_PISTON_EXTEND:
case BLOCK_PISTON_RETRACT:
pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Monitor, this);
pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Monitor, this);
break;
case WORLD_LOAD:
case CHUNK_LOAD:

View File

@ -1,21 +1,30 @@
package org.dynmap;
import org.dynmap.markers.impl.MarkerAPIImpl;
import org.dynmap.markers.impl.MarkerSignManager;
/**
* Markers component - ties in the component system, both on the server and client
*/
public class MarkersComponent extends ClientComponent {
private MarkerAPIImpl api;
private MarkerSignManager signmgr;
public MarkersComponent(DynmapPlugin plugin, ConfigurationNode configuration) {
super(plugin, configuration);
/* Register API with plugin */
api = MarkerAPIImpl.initializeMarkerAPI(plugin);
plugin.registerMarkerAPI(api);
/* If configuration has enabled sign support, prime it too */
if(configuration.getBoolean("enablesigns", true)) {
signmgr = MarkerSignManager.initializeSignManager(plugin);
}
}
@Override
public void dispose() {
if(signmgr != null) {
MarkerSignManager.terminateSignManager(this.plugin);
signmgr = null;
}
if(api != null) {
/* Clean up API registered with plugin */
plugin.registerMarkerAPI(null);

View File

@ -0,0 +1,56 @@
package org.dynmap.markers.impl;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.plugin.PluginManager;
import org.dynmap.DynmapPlugin;
import org.dynmap.Log;
public class MarkerSignManager {
private static MarkerSignManager mgr = null;
private static class SignListener extends BlockListener {
@Override
public void onSignChange(SignChangeEvent evt) {
if(evt.isCancelled() || (mgr == null))
return;
Log.info("onSignChange: '" + evt.getLine(0) + "','" + evt.getLine(1) + "','" + evt.getLine(2) + "','" + evt.getLine(3) + "'");
}
@Override
public void onBlockPlace(BlockPlaceEvent evt) {
if(evt.isCancelled() || (mgr == null))
return;
}
@Override
public void onBlockBreak(BlockBreakEvent evt) {
if(evt.isCancelled() || (mgr == null))
return;
}
}
private static SignListener sl = null; /* Do once - /dynmap reload doesn't reset listeners */
public static MarkerSignManager initializeSignManager(DynmapPlugin plugin) {
mgr = new MarkerSignManager();
if(sl == null) {
sl = new SignListener();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_PLACE, sl, Event.Priority.Low, plugin);
pm.registerEvent(Event.Type.BLOCK_BREAK, sl, Event.Priority.Low, plugin);
pm.registerEvent(Event.Type.SIGN_CHANGE, sl, Event.Priority.Low, plugin);
}
return mgr;
}
public static void terminateSignManager(DynmapPlugin plugin) {
mgr = null;
}
private static String getSignMarkerID(Location loc) {
return "$sign-" + loc.getWorld().getName() + "/" + loc.getBlockX() + "/" + loc.getBlockY() + "/" + loc.getBlockZ();
}
}