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