use of com.bergerkiller.bukkit.common.internal.CommonMapController.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
*/
public 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.setRunning(true);
}
use of com.bergerkiller.bukkit.common.internal.CommonMapController.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) {
ViewStack views = info.getStack(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.internal.CommonMapController.MapDisplayInfo in project BKCommonLib by bergerhealer.
the class MapSession method update.
/**
* Updates the session. Returns false if the session should be ended.
*
* @return False when the session should be ended
*/
public boolean update() {
MapDisplayInfo info = this.display.getMapInfo();
if (info == null) {
// can't keep a session around for a map that does not exist!
return false;
}
// Update players and their input
this.hasHolders = false;
this.hasViewers = false;
this.hasNewViewers = false;
if (!this.onlineOwners.isEmpty()) {
Iterator<Owner> onlineIter = this.onlineOwners.iterator();
while (onlineIter.hasNext()) {
Owner owner = onlineIter.next();
// Update input
owner.input.doTick(this.display, owner.interceptInput);
// Check if online. Remove offline players if not set FOREVER
if (!owner.player.isOnline()) {
if (this.mode != MapSessionMode.FOREVER) {
this.owners.remove(owner.player.getUniqueId());
}
onOwnerRemoved(owner);
onlineIter.remove();
continue;
}
// Check if holding the map
PlayerInventory inv = owner.player.getInventory();
owner.controlling = info.isMap(inv.getItemInMainHand());
owner.holding = owner.controlling || info.isMap(inv.getItemInOffHand());
if (!owner.holding && this.mode == MapSessionMode.HOLDING) {
this.owners.remove(owner.player.getUniqueId());
onOwnerRemoved(owner);
onlineIter.remove();
continue;
}
// Check if viewing the map at all
owner.wasViewing = owner.viewing;
owner.viewing = owner.holding || info.frameViewers.contains(owner.player);
if (!owner.viewing && this.mode == MapSessionMode.VIEWING) {
this.owners.remove(owner.player.getUniqueId());
onOwnerRemoved(owner);
onlineIter.remove();
continue;
}
// Update state
this.hasHolders |= owner.holding;
this.hasViewers |= owner.viewing;
this.hasNewViewers |= owner.isNewViewer();
}
}
// Session end condition
switch(this.mode) {
case FOREVER:
return true;
case ONLINE:
return !onlineOwners.isEmpty();
case VIEWING:
return this.hasViewers;
case HOLDING:
return this.hasHolders;
}
return true;
}
use of com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo in project BKCommonLib by bergerhealer.
the class MapSession method onOwnerRemoved.
private void onOwnerRemoved(Owner owner) {
// Remove map display from by-player mapping
MapDisplayInfo info = this.display.getMapInfo();
if (info != null) {
ViewStack views = info.getStack(owner.player);
if (!views.stack.isEmpty() && views.stack.getLast() == this.display) {
// Stop intercepting input
owner.interceptInput = false;
owner.input.doTick(this.display, false);
// Remove self
views.stack.removeLast();
// If an older display is in the stack, switch to it
if (!views.stack.isEmpty()) {
views.stack.getLast().addOwner(owner.player);
}
} else {
// Simply remove the player from anywhere in the view stack
views.stack.remove(this.display);
}
}
}
Aggregations