use of com.bergerkiller.bukkit.common.map.util.MapUUID in project BKCommonLib by bergerhealer.
the class CommonMapController method storeStaticMapId.
/**
* Forces a particular map Id to stay static (unchanging) and stores it
* as such in the mappings. No tiling is possible with static map Ids.
*
* @param mapId
*/
private synchronized void storeStaticMapId(int mapId) {
if (storeDynamicMapId(mapUUIDById.get(mapId)) != mapId) {
MapUUID mapUUID = new MapUUID(CommonMapUUIDStore.getStaticMapUUID(mapId), 0, 0);
mapUUIDById.put(mapId, mapUUID);
mapIdByUUID.put(mapUUID, mapId);
}
}
use of com.bergerkiller.bukkit.common.map.util.MapUUID in project BKCommonLib by bergerhealer.
the class CommonMapController method updateMapItem.
/**
* Updates the information of a map item, refreshing all item frames
* and player inventories storing the item. Map displays are also
* updated.
*
* @param oldItem that was changed
* @param newItem the old item was changed into
*/
public synchronized void updateMapItem(ItemStack oldItem, ItemStack newItem) {
if (oldItem == null) {
throw new IllegalArgumentException("oldItem is null");
} else if (!CraftItemStackHandle.T.isAssignableFrom(oldItem)) {
// Ensure CraftItemStack
oldItem = ItemUtil.createItem(oldItem);
}
if (newItem != null && !CraftItemStackHandle.T.isAssignableFrom(newItem)) {
// Ensure CraftItemStack
newItem = ItemUtil.createItem(newItem);
}
boolean unchanged = isItemUnchanged(oldItem, newItem);
UUID oldMapUUID = CommonMapUUIDStore.getMapUUID(oldItem);
if (oldMapUUID != null) {
// Change in the inventories of all player owners
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerInventory inv = player.getInventory();
for (int i = 0; i < inv.getSize(); i++) {
UUID mapUUID = CommonMapUUIDStore.getMapUUID(inv.getItem(i));
if (oldMapUUID.equals(mapUUID)) {
if (unchanged) {
PlayerUtil.setItemSilently(player, i, newItem);
} else {
inv.setItem(i, newItem);
}
}
}
}
// All item frames that show this same map
for (ItemFrameInfo itemFrameInfo : CommonPlugin.getInstance().getMapController().getItemFrames()) {
if (itemFrameInfo.lastMapUUID != null && oldMapUUID.equals(itemFrameInfo.lastMapUUID.getUUID())) {
if (unchanged) {
// When unchanged set the item in the metadata without causing a refresh
DataWatcher data = EntityHandle.fromBukkit(itemFrameInfo.itemFrame).getDataWatcher();
DataWatcher.Item<ItemStack> dataItem = data.getItem(EntityItemFrameHandle.DATA_ITEM);
dataItem.setValue(newItem, dataItem.isChanged());
} else {
// When changed, set it normally so the item is refreshed
itemFrameInfo.itemFrameHandle.setItem(newItem);
this.itemFrameUpdateList.prioritize(itemFrameInfo.updateEntry);
}
}
}
// All map displays showing this item
MapDisplayInfo info = maps.get(oldMapUUID);
if (info != null) {
for (MapSession session : info.getSessions()) {
session.display.setMapItemSilently(newItem);
}
}
}
}
use of com.bergerkiller.bukkit.common.map.util.MapUUID in project BKCommonLib by bergerhealer.
the class CommonMapController method cleanupUnusedUUIDs.
protected synchronized void cleanupUnusedUUIDs(Set<MapUUID> existingMapUUIDs) {
HashSet<MapUUID> idsToRemove = new HashSet<MapUUID>(mapIdByUUID.keySet());
idsToRemove.removeAll(existingMapUUIDs);
for (MapUUID toRemove : idsToRemove) {
// Clean up the map display information first
MapDisplayInfo displayInfo = maps.get(toRemove.getUUID());
if (displayInfo != null) {
if (displayInfo.getSessions().isEmpty()) {
MapDisplayInfo removed = maps.remove(toRemove.getUUID());
if (removed != null) {
mapsValues.remove(removed);
removed.onRemoved();
}
} else {
// still has an active session; cannot remove
continue;
}
}
// Clean up from bi-directional mapping
Integer mapId = mapIdByUUID.remove(toRemove);
if (mapId != null) {
mapUUIDById.remove(mapId.intValue());
}
// Clean up from 'dirty' set (probably never needed)
dirtyMapUUIDSet.removeAll(toRemove.getUUID());
}
}
Aggregations