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);
}
Aggregations