mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
Start sign support
This commit is contained in:
parent
e0fcca4b7f
commit
20e409b71f
@ -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;
|
||||
|
@ -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);
|
||||
|
56
src/main/java/org/dynmap/markers/impl/MarkerSignManager.java
Normal file
56
src/main/java/org/dynmap/markers/impl/MarkerSignManager.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user