Search in sources :

Example 11 with MapSession

use of com.bergerkiller.bukkit.common.map.MapSession 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

MapSession (com.bergerkiller.bukkit.common.map.MapSession)11 MapUUID (com.bergerkiller.bukkit.common.map.util.MapUUID)5 MapDisplayTile (com.bergerkiller.bukkit.common.map.MapDisplayTile)4 ItemFrameInfo (com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo)3 MapDisplayInfo (com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)3 UUID (java.util.UUID)3 Player (org.bukkit.entity.Player)3 ItemStack (org.bukkit.inventory.ItemStack)3 PlayerInventory (org.bukkit.inventory.PlayerInventory)3 MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)2 DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)2 Plugin (org.bukkit.plugin.Plugin)2 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)2 CommonPlugin (com.bergerkiller.bukkit.common.internal.CommonPlugin)1 MapDisplayProperties (com.bergerkiller.bukkit.common.map.MapDisplayProperties)1 CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)1 IntHashMap (com.bergerkiller.bukkit.common.wrappers.IntHashMap)1 LongHashSet (com.bergerkiller.bukkit.common.wrappers.LongHashSet)1 EntityItemFrameHandle (com.bergerkiller.generated.net.minecraft.world.entity.decoration.EntityItemFrameHandle)1 OutputTypeMap (com.bergerkiller.mountiplex.reflection.util.OutputTypeMap)1