Search in sources :

Example 1 with MapDisplay

use of com.bergerkiller.bukkit.common.map.MapDisplay in project BKCommonLib by bergerhealer.

the class CommonMapController method handleMapShowEvent.

private synchronized void handleMapShowEvent(MapShowEvent event) {
    // Check if there are other map displays that should be shown to the player automatically
    // This uses the 'isGlobal()' property of the display
    MapDisplayInfo info = CommonMapController.this.getInfo(event.getMapUUID());
    boolean hasDisplay = false;
    if (info != null) {
        for (MapSession session : info.sessions) {
            if (session.display.isGlobal()) {
                session.display.addOwner(event.getPlayer());
                hasDisplay = true;
                break;
            }
        }
    }
    // When defined in the NBT of the item, construct the Map Display automatically
    CommonTagCompound tag = ItemUtil.getMetaTag(event.getMapItem(), false);
    if (tag != null && !hasDisplay) {
        String pluginName = tag.getValue("mapDisplayPlugin", String.class);
        String displayClassName = tag.getValue("mapDisplayClass", String.class);
        if (pluginName != null && displayClassName != null) {
            Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
            Class<?> displayClass = null;
            if (plugin != null) {
                try {
                    displayClass = plugin.getClass().getClassLoader().loadClass(displayClassName);
                    if (!MapDisplay.class.isAssignableFrom(displayClass)) {
                        displayClass = null;
                    }
                } catch (ClassNotFoundException e) {
                }
            }
            if (displayClass != null && !event.hasDisplay()) {
                try {
                    MapDisplay display = (MapDisplay) displayClass.newInstance();
                    event.setDisplay((JavaPlugin) plugin, display);
                    ;
                } catch (InstantiationException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    CommonUtil.callEvent(event);
}
Also used : MapDisplay(com.bergerkiller.bukkit.common.map.MapDisplay) CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) MapSession(com.bergerkiller.bukkit.common.map.MapSession) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Aggregations

MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)1 MapSession (com.bergerkiller.bukkit.common.map.MapSession)1 CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)1 Plugin (org.bukkit.plugin.Plugin)1 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)1