Search in sources :

Example 1 with MapDisplayProperties

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

the class CommonMapController method handleMapShowEvent.

@SuppressWarnings("deprecation")
protected 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.getSessions()) {
            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
    // Do not do this when one was already assigned (global, or during event handling)
    // We initialize the display the next tick using the plugin owner's task to avoid
    // BKCommonLib showing up in timings when onAttached() is slow.
    MapDisplayProperties properties = MapDisplayProperties.of(event.getMapItem());
    if (!hasDisplay && !event.hasDisplay() && properties != null) {
        Class<? extends MapDisplay> displayClass = properties.getMapDisplayClass();
        if (displayClass != null) {
            Plugin plugin = properties.getPlugin();
            if (plugin instanceof JavaPlugin) {
                try {
                    MapDisplay display = displayClass.newInstance();
                    event.setDisplay((JavaPlugin) plugin, display);
                } catch (InstantiationException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    CommonUtil.callEvent(event);
}
Also used : MapDisplayProperties(com.bergerkiller.bukkit.common.map.MapDisplayProperties) MapDisplay(com.bergerkiller.bukkit.common.map.MapDisplay) MapDisplayInfo(com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) MapSession(com.bergerkiller.bukkit.common.map.MapSession) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) CommonPlugin(com.bergerkiller.bukkit.common.internal.CommonPlugin)

Aggregations

CommonPlugin (com.bergerkiller.bukkit.common.internal.CommonPlugin)1 MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)1 MapDisplayProperties (com.bergerkiller.bukkit.common.map.MapDisplayProperties)1 MapSession (com.bergerkiller.bukkit.common.map.MapSession)1 MapDisplayInfo (com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)1 Plugin (org.bukkit.plugin.Plugin)1 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)1