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