Search in sources :

Example 1 with MapDisplayInfo

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

the class CommonMapController method onDisable.

/**
 * Cleans up all running map displays and de-initializes all map display logic
 */
public void onDisable(CommonPlugin plugin) {
    if (this.isEnabled) {
        this.isEnabled = false;
        // If reloading, save current map id state to avoid glitches
        CommonMapReloadFile.save(plugin, reloadFile -> {
            // Add static reserved / dynamic map ids
            for (Map.Entry<MapUUID, Integer> entry : mapIdByUUID.entrySet()) {
                MapUUID mapUUID = entry.getKey();
                if (mapUUID.isStaticUUID()) {
                    reloadFile.staticReservedIds.add(entry.getValue());
                } else {
                    reloadFile.addDynamicMapId(mapUUID, entry.getValue());
                }
            }
            // Add information about all item frames and what display they displayed last
            for (Map.Entry<Integer, ItemFrameInfo> entry : itemFrames.entrySet()) {
                ItemFrameInfo info = entry.getValue();
                if (info.lastMapUUID != null) {
                    reloadFile.addItemFrameDisplayUUID(entry.getKey().intValue(), info.lastMapUUID);
                }
            }
        });
        for (MapDisplayInfo map : this.mapsValues.cloneAsIterable()) {
            for (MapSession session : new ArrayList<MapSession>(map.getSessions())) {
                session.display.setRunning(false);
            }
        }
    }
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo) ArrayList(java.util.ArrayList) MapSession(com.bergerkiller.bukkit.common.map.MapSession) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) IntHashMap(com.bergerkiller.bukkit.common.wrappers.IntHashMap) HashMap(java.util.HashMap) OutputTypeMap(com.bergerkiller.mountiplex.reflection.util.OutputTypeMap) ItemFrameInfo(com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo) MapUUID(com.bergerkiller.bukkit.common.map.util.MapUUID)

Example 2 with MapDisplayInfo

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

the class CommonMapController method getInfo.

/**
 * Gets the Map display information for a map item displayed in an item frame.
 * All frames showing the same map will return the same {@link #MapDisplayInfo}.
 * If the item frame does not show a map, null is returned.
 *
 * @param itemFrame to get the map information for
 * @return map display info
 */
public synchronized MapDisplayInfo getInfo(ItemFrame itemFrame) {
    ItemFrameInfo frameInfo = itemFrames.get(itemFrame.getEntityId());
    if (frameInfo != null) {
        if (frameInfo.lastMapUUID == null) {
            return null;
        }
        MapDisplayInfo info = maps.get(frameInfo.lastMapUUID.getUUID());
        if (info == null) {
            info = new MapDisplayInfo(this, frameInfo.lastMapUUID.getUUID());
            maps.put(frameInfo.lastMapUUID.getUUID(), info);
            mapsValues.add(info);
        }
        return info;
    }
    return getInfo(getItemFrameItem(itemFrame));
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo) ItemFrameInfo(com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo)

Example 3 with MapDisplayInfo

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

the class CommonMapController method getInfo.

/**
 * Gets the Map display information for a certain map item UUID.
 * Creates a new instance if none exists yet. Returns null if
 * the input UUID is null.
 *
 * @param mapUUID The Unique ID of the map
 * @return display info for this UUID, or null if mapUUID is null
 */
public synchronized MapDisplayInfo getInfo(UUID mapUUID) {
    if (mapUUID == null) {
        return null;
    } else {
        return maps.computeIfAbsent(mapUUID, uuid -> {
            MapDisplayInfo info = new MapDisplayInfo(this, uuid);
            mapsValues.add(info);
            return info;
        });
    }
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)

Example 4 with MapDisplayInfo

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

the class MapSession method onOwnerAdded.

private void onOwnerAdded(Owner owner) {
    // Add to map display by-player mapping
    MapDisplayInfo info = this.display.getMapInfo();
    if (info != null) {
        MapDisplayInfo.ViewStack views = info.getOrCreateViewStack(owner.player);
        if (views.stack.isEmpty()) {
            views.stack.addLast(this.display);
        } else {
            MapDisplay previousDisplay = views.stack.getLast();
            if (previousDisplay != this.display) {
                previousDisplay.removeOwner(owner.player);
                views.stack.addLast(previousDisplay);
                views.stack.addLast(this.display);
            }
        }
    }
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)

Example 5 with MapDisplayInfo

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

the class MapDisplay method initialize.

/**
 * Initializes this Map Display, setting the owner plugin and what map it represents.
 * If this display is already initialized for this plugin and map, this method does nothing.
 *
 * @param plugin owner
 * @param mapItem on which map is displayed
 */
private void initialize(JavaPlugin plugin, ItemStack mapItem) {
    if (plugin == null) {
        throw new IllegalArgumentException("Plugin can not be null");
    }
    MapDisplayInfo mapInfo = CommonPlugin.getInstance().getMapController().getInfo(mapItem);
    if (mapInfo == null) {
        throw new IllegalArgumentException("Map Item is not of a valid map");
    }
    if (this.plugin != null) {
        if (this.plugin != plugin) {
            throw new IllegalArgumentException("This Map Display was already initialized for another plugin");
        }
        if (this.info != mapInfo) {
            throw new IllegalArgumentException("This Map Display was already initialized for a different map");
        }
    } else {
        this.plugin = plugin;
        this.info = mapInfo;
        this._item = mapItem.clone();
        this._oldItem = ItemUtil.cloneItem(this._item);
    }
    this.setRunning(true);
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)

Aggregations

MapDisplayInfo (com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)11 ItemFrameInfo (com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo)4 MapSession (com.bergerkiller.bukkit.common.map.MapSession)3 MapUUID (com.bergerkiller.bukkit.common.map.util.MapUUID)3 MapDisplay (com.bergerkiller.bukkit.common.map.MapDisplay)2 CommonPlugin (com.bergerkiller.bukkit.common.internal.CommonPlugin)1 MapDisplayProperties (com.bergerkiller.bukkit.common.map.MapDisplayProperties)1 MapLookPosition (com.bergerkiller.bukkit.common.map.util.MapLookPosition)1 DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)1 IntHashMap (com.bergerkiller.bukkit.common.wrappers.IntHashMap)1 OutputTypeMap (com.bergerkiller.mountiplex.reflection.util.OutputTypeMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1