Search in sources :

Example 1 with MapDisplayInfo

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);
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo)

Example 2 with MapDisplayInfo

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);
            }
        }
    }
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo) ViewStack(com.bergerkiller.bukkit.common.internal.CommonMapController.ViewStack)

Example 3 with MapDisplayInfo

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;
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Example 4 with MapDisplayInfo

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);
        }
    }
}
Also used : MapDisplayInfo(com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo) ViewStack(com.bergerkiller.bukkit.common.internal.CommonMapController.ViewStack)

Aggregations

MapDisplayInfo (com.bergerkiller.bukkit.common.internal.CommonMapController.MapDisplayInfo)4 ViewStack (com.bergerkiller.bukkit.common.internal.CommonMapController.ViewStack)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)1