org.bukkit.block.DoubleChest Java Examples

The following examples show how to use org.bukkit.block.DoubleChest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameMap.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public void addChest(Chest chest, ChestPlacementType cpt) {
	ArrayList<CoordLoc> list;
	if (cpt == ChestPlacementType.NORMAL) {
		list = chests;
	} else {
		list = centerChests;
	}
	InventoryHolder ih = chest.getInventory().getHolder();
       if (ih instanceof DoubleChest) {
       	DoubleChest dc = (DoubleChest) ih;
		Chest left = (Chest) dc.getLeftSide();
		Chest right = (Chest) dc.getRightSide();
		CoordLoc locLeft = new CoordLoc(left.getX(), left.getY(), left.getZ());
		CoordLoc locRight = new CoordLoc(right.getX(), right.getY(), right.getZ());
		if (!(list.contains(locLeft) || list.contains(locRight))) {
			addChest(locLeft, cpt, true);
		}
       } else {
       	CoordLoc loc = new CoordLoc(chest.getX(), chest.getY(), chest.getZ());
           if (!list.contains(loc)){
			addChest(loc, cpt, true);
           }
       }
}
 
Example #2
Source File: ChestProtectListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemMove(InventoryMoveItemEvent e) {
    if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {

        if (e.getSource().getHolder() instanceof DoubleChest) {
            DoubleChest dc = (DoubleChest) e.getSource().getHolder();
            Chest r = (Chest) dc.getRightSide();
            Chest l = (Chest) dc.getLeftSide();

            if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) e.setCancelled(true);

        } else if (e.getSource().getHolder() instanceof Chest) {
            Chest c = (Chest) e.getSource().getHolder();

            if (shopUtils.isShop(c.getLocation())) e.setCancelled(true);
        }
    }
}
 
Example #3
Source File: ShopUpdateListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryUpdate(InventoryMoveItemEvent e) {
    if (!plugin.getHologramFormat().isDynamic()) return;

    Location loc = null;

    if (e.getSource().getHolder() instanceof Chest) {
        loc =  ((Chest) e.getSource().getHolder()).getLocation();
    } else if (e.getSource().getHolder() instanceof DoubleChest) {
        loc =  ((DoubleChest) e.getSource().getHolder()).getLocation();
    } else if (e.getDestination().getHolder() instanceof Chest) {
        loc =  ((Chest) e.getDestination().getHolder()).getLocation();
    } else if (e.getDestination().getHolder() instanceof DoubleChest) {
        loc =  ((DoubleChest) e.getDestination().getHolder()).getLocation();
    }

    if (loc != null) {
        Shop shop = plugin.getShopUtils().getShop(loc);
        if (shop != null) shop.updateHologramText();
    }
}
 
Example #4
Source File: GameMap.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public void removeChest(Chest chest) {
	InventoryHolder ih = chest.getInventory().getHolder();
	if (ih instanceof DoubleChest) {
		DoubleChest dc = (DoubleChest) ih;
		Chest left = (Chest) dc.getLeftSide();
		Chest right = (Chest) dc.getRightSide();
		CoordLoc locLeft = new CoordLoc(left.getX(), left.getY(), left.getZ());
		CoordLoc locRight = new CoordLoc(right.getX(), right.getY(), right.getZ());
		chests.remove(locLeft);
		centerChests.remove(locLeft);
		chests.remove(locRight);
		centerChests.remove(locLeft);
		saveArenaData();
	} else {
		CoordLoc loc = new CoordLoc(chest.getX(), chest.getY(), chest.getZ());
		chests.remove(loc);
		centerChests.remove(loc);
		saveArenaData();
	}

}
 
Example #5
Source File: WorthListener.java    From factions-top with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(InventoryCloseEvent event) {
    // Do nothing if a player did not close the inventory or if chest
    // events are disabled.
    if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
        return;
    }

    // Get cached values from when chest was opened and add the difference
    // to the worth manager.
    if (event.getInventory().getHolder() instanceof DoubleChest) {
        DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
        updateWorth((Chest) chest.getLeftSide());
        updateWorth((Chest) chest.getRightSide());
    }

    if (event.getInventory().getHolder() instanceof Chest) {
        updateWorth((Chest) event.getInventory().getHolder());
    }
}
 
Example #6
Source File: WorthListener.java    From factions-top with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void checkWorth(InventoryOpenEvent event) {
    // Do nothing if a player did not open the inventory or if chest events
    // are disabled.
    if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) {
        return;
    }

    Inventory inventory = event.getInventory();

    // Set all default worth values for this chest.
    if (inventory.getHolder() instanceof DoubleChest) {
        DoubleChest chest = (DoubleChest) inventory.getHolder();
        checkWorth((Chest) chest.getLeftSide());
        checkWorth((Chest) chest.getRightSide());
    }

    if (inventory.getHolder() instanceof Chest) {
        checkWorth((Chest) inventory.getHolder());
    }
}
 
Example #7
Source File: TPContainerListener.java    From Transport-Pipes with MIT License 6 votes vote down vote up
public Block checkForDoubleChestNeighbor(Block block) {
    if (block.getState() instanceof InventoryHolder) {
        if (((InventoryHolder) block.getState()).getInventory().getHolder() instanceof DoubleChest) {
            for (TPDirection dir : TPDirection.values()) {
                if (dir.isSide()) {
                    Block neighborBlock = block.getRelative(dir.getBlockFace());
                    if (neighborBlock.getState() instanceof InventoryHolder) {
                        if (((InventoryHolder) neighborBlock.getState()).getInventory().getHolder() instanceof DoubleChest) {
                            DoubleChest blockChest = (DoubleChest) ((InventoryHolder) block.getState()).getInventory().getHolder();
                            DoubleChest neighborBlockChest = (DoubleChest) ((InventoryHolder) neighborBlock.getState()).getInventory().getHolder();
                            if (blockChest.getLocation().equals(neighborBlockChest.getLocation())) {
                                return neighborBlock;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example #8
Source File: FillListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Return a predicate that applies a Filter to the given InventoryHolder,
 * or null if the InventoryHolder is not something that we should be filling.
 */
private static @Nullable Predicate<Filter> passesFilter(InventoryHolder holder) {
    if(holder instanceof DoubleChest) {
        final DoubleChest doubleChest = (DoubleChest) holder;
        return filter -> !filter.denies((Chest) doubleChest.getLeftSide()) ||
                         !filter.denies((Chest) doubleChest.getRightSide());
    } else if(holder instanceof BlockState) {
        return filter -> !filter.denies((BlockState) holder);
    } else if(holder instanceof Player) {
        // This happens with crafting inventories, and possibly other transient inventory types
        // Pretty sure we never want to fill an inventory held by the player
        return null;
    } else if(holder instanceof Entity) {
        return filter -> !filter.denies(new EntityQuery((Entity) holder));
    } else {
        // If we're not sure what it is, don't fill it
        return null;
    }
}
 
Example #9
Source File: InventoryHolderStorage.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public void setHolder(InventoryHolder holder) throws CivException {
	if (holder instanceof Player) {
		Player player = (Player)holder;
		playerName = player.getName();
		blockLocation = null;
		return;
	} 
	
	if (holder instanceof Chest) {
		Chest chest = (Chest)holder;
		playerName = null;
		blockLocation = chest.getLocation();
		return;
	} 
	
	if (holder instanceof DoubleChest) {
		DoubleChest dchest = (DoubleChest)holder;
		playerName = null;
		blockLocation = dchest.getLocation();
		return;
	}
	
	throw new CivException("Invalid holder passed to set holder:"+holder.toString());
}
 
Example #10
Source File: Shop.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Runs everything that needs to be called synchronously in order 
 * to prepare creating the hologram.
 */
private PreCreateResult preCreateHologram() {
    plugin.debug("Creating hologram (#" + id + ")");

    InventoryHolder ih = getInventoryHolder();

    if (ih == null) return null;

    Chest[] chests = new Chest[2];
    BlockFace face;

    if (ih instanceof DoubleChest) {
        DoubleChest dc = (DoubleChest) ih;
        Chest r = (Chest) dc.getRightSide();
        Chest l = (Chest) dc.getLeftSide();

        chests[0] = r;
        chests[1] = l;
    } else {
        chests[0] = (Chest) ih;
    }

    if (Utils.getMajorVersion() < 13) {
        face = ((org.bukkit.material.Directional) chests[0].getData()).getFacing();
    } else {
        face = ((Directional) chests[0].getBlockData()).getFacing();
    }

    return new PreCreateResult(ih.getInventory(), chests, face);
}
 
Example #11
Source File: QueueManager.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void run(){
	HashMap<Block,ItemStack[]>openedChests = GameManager.openedChest.get(id);
	if( openedChests == null ) { SurvivalGames.debug("Nothing to reset for id "+id); return; }
	SurvivalGames.debug("Resetting saved chests content for game "+id);
	for( Block chest: openedChests.keySet() ) {
		BlockState bs = chest.getState();
		if(bs instanceof Chest || bs instanceof DoubleChest){
			SurvivalGames.debug("Resetting chest at "+chest.getX()+","+chest.getY()+","+chest.getZ()+" to previous contents");
			Inventory inv = ((bs instanceof Chest))? ((Chest) bs).getBlockInventory()
			: ((DoubleChest)bs).getLeftSide().getInventory(); // should handle double chests correctly!
			// replace current contents with saved contents
			try {
				inv.setContents(openedChests.get(chest));
				if(SettingsManager.getInstance().getConfig().getBoolean("debug", false)) {
					for( ItemStack is: inv.getContents() ) {
						if( is != null ) {
							SurvivalGames.debug("Restored item "+ is.getType().name() + " DV " + is.getDurability() + " qty "+is.getAmount());
						}
					}
				}
			} catch(Exception e) {
			    SurvivalGames.warning("Problem resetting chest at " +chest.getX()+","+chest.getY()+","+chest.getZ()+" to original state!");
			}
		} else {
			SurvivalGames.warning("Block in saved chests map is no longer a chest?");
		}
	}
	// forget saved content, so that randomisation can occur
	SurvivalGames.debug("Emptying list of opened chests for game "+id);
	GameManager.openedChest.put(id, new HashMap < Block, ItemStack[] > ());
}
 
Example #12
Source File: ShopInteractListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
    if (!plugin.getHologramFormat().isDynamic()) return;

    Inventory chestInv = e.getInventory();

    if (!(chestInv.getHolder() instanceof Chest || chestInv.getHolder() instanceof DoubleChest)) {
        return;
    }

    Location loc = null;
    if (chestInv.getHolder() instanceof Chest) {
        loc = ((Chest) chestInv.getHolder()).getLocation();
    } else if (chestInv.getHolder() instanceof DoubleChest) {
        loc = ((DoubleChest) chestInv.getHolder()).getLocation();
    }

    final Shop shop = plugin.getShopUtils().getShop(loc);
    if (shop == null) return;

    new BukkitRunnable() {
        @Override
        public void run() {
            shop.updateHologramText();
        }
    }.runTaskLater(plugin, 1L);
}
 
Example #13
Source File: ChestManager.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void populateChest(Object chest, Vote cVote, boolean center) {
 	if (cVote == Vote.CHESTOP) {
 		if (center) {
 			fillChest(chest, opCenterChestItemList);
} else {
	fillChest(chest, opChestItemList);
}
 	} else if (cVote == Vote.CHESTBASIC) {
if (center) {
	fillChest(chest, basicCenterChestItemList);
} else {
	fillChest(chest, basicChestItemList);
}
 	} else if (cVote == Vote.CHESTNORMAL) {
 		if (center) {
	fillChest(chest, centerChestItemList);
} else {
	fillChest(chest, chestItemList);
}
 	} else {
 		Inventory inventory = null;
 		if (chest instanceof DoubleChest) {
 			inventory = ((DoubleChest) chest).getInventory();
 		} else if (chest instanceof Chest) {
 			inventory = ((Chest)chest).getInventory();
 		}
 		if (inventory != null) {
     		inventory.clear();
 		}
 	}
 }
 
Example #14
Source File: ChestManager.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private void fillChest(Object chest, Map<Integer, Inventory> fill) {
	Inventory inventory = null;
	if (chest instanceof Chest) {
		inventory = ((Chest) chest).getInventory();
	} else if (chest instanceof DoubleChest) {
		inventory = ((DoubleChest) chest).getInventory();
	}
	if (inventory != null) {
		inventory.clear();
		int added = 0;
		Collections.shuffle(randomLoc);
		Collections.shuffle(randomDLoc);
		for (int chance: fill.keySet()) {
			for (ItemStack item: fill.get(chance)) {
				if (item != null && !item.getType().equals(Material.AIR)) {
					if (chest instanceof Chest) {
						if (random.nextInt(100) + 1 <= chance) {
							inventory.setItem(randomLoc.get(added), item);
							added++;
							if (added >= inventory.getSize() - 1 || added >= SkyWarsReloaded.getCfg().getMaxChest()) {
								break;
							}
						}
					}
					if (chest instanceof DoubleChest) {
						if (random.nextInt(100) + 1 <= chance) {
							inventory.setItem(randomDLoc.get(added), item);
							added++;
							if (added >= inventory.getSize() - 1 || added >= SkyWarsReloaded.getCfg().getMaxDoubleChest()) {
								break;
							}
						}
					}
				}
			}
		}
	}
}
 
Example #15
Source File: ShopUtils.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Add a shop
 * @param shop Shop to add
 * @param addToDatabase Whether the shop should also be added to the database
 * @param callback Callback that - if succeeded - returns the ID the shop had or was given (as {@code int})
 */
public void addShop(Shop shop, boolean addToDatabase, Callback<Integer> callback) {
    InventoryHolder ih = shop.getInventoryHolder();
    plugin.debug("Adding shop... (#" + shop.getID() + ")");

    if (ih instanceof DoubleChest) {
        DoubleChest dc = (DoubleChest) ih;
        Chest r = (Chest) dc.getRightSide();
        Chest l = (Chest) dc.getLeftSide();

        plugin.debug("Added shop as double chest. (#" + shop.getID() + ")");

        shopLocation.put(r.getLocation(), shop);
        shopLocation.put(l.getLocation(), shop);
    } else {
        plugin.debug("Added shop as single chest. (#" + shop.getID() + ")");

        shopLocation.put(shop.getLocation(), shop);
    }

    if (addToDatabase) {
        if (shop.getShopType() != ShopType.ADMIN) {
            playerShopAmount.compute(shop.getVendor().getUniqueId(), (uuid, amount) -> amount == null ? new Counter(1) : amount.increment());
        }
        plugin.getShopDatabase().addShop(shop, callback);
    } else {
        if (callback != null) callback.callSyncResult(shop.getID());
    }

}
 
Example #16
Source File: ShopUtils.java    From ShopChest with MIT License 5 votes vote down vote up
/** Remove a shop. May not work properly if double chest doesn't exist!
 * @param shop Shop to remove
 * @param removeFromDatabase Whether the shop should also be removed from the database
 * @param callback Callback that - if succeeded - returns null
 * @see ShopUtils#removeShopById(int, boolean, Callback)
 */
public void removeShop(Shop shop, boolean removeFromDatabase, Callback<Void> callback) {
    plugin.debug("Removing shop (#" + shop.getID() + ")");

    if (shop.isCreated()) {
        InventoryHolder ih = shop.getInventoryHolder();

        if (ih instanceof DoubleChest) {
            DoubleChest dc = (DoubleChest) ih;
            Chest r = (Chest) dc.getRightSide();
            Chest l = (Chest) dc.getLeftSide();

            shopLocation.remove(r.getLocation());
            shopLocation.remove(l.getLocation());
        } else {
            shopLocation.remove(shop.getLocation());
        }

        shop.removeItem();
        shop.removeHologram();
    }

    if (removeFromDatabase) {
        if (shop.getShopType() != ShopType.ADMIN) {
            playerShopAmount.compute(shop.getVendor().getUniqueId(), (uuid, amount) -> amount == null ? new Counter() : amount.decrement());
        }
        plugin.getShopDatabase().removeShop(shop, callback);
    } else {
        if (callback != null) callback.callSyncResult(null);
    }
}
 
Example #17
Source File: Utils.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Get a set for the location(s) of the shop's chest(s)
 * @param shop The shop
 * @return A set of 1 or 2 locations
 */
public static Set<Location> getChestLocations(Shop shop) {
    Set<Location> chestLocations = new HashSet<>();
    InventoryHolder ih = shop.getInventoryHolder();
    if (ih instanceof DoubleChest) {
        DoubleChest dc = (DoubleChest) ih;
        chestLocations.add(((Chest) dc.getLeftSide()).getLocation());
        chestLocations.add(((Chest) dc.getRightSide()).getLocation());
    } else {
        chestLocations.add(shop.getLocation());
    }
    return chestLocations;
}
 
Example #18
Source File: IslandBlock.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paste this block at blockLoc
 * @param nms
 * @param blockLoc
 */
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
    // Only paste air if it is below the sea level and in the overworld
    Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
    block.setBiome(biome);
    nms.setBlockSuperFast(block, typeId, data, usePhysics);
    if (signText != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        // Sign
        Sign sign = (Sign) block.getState();
        int index = 0;
        for (String line : signText) {
            sign.setLine(index++, line);
        }
        sign.update(true, false);
    } else if (banner != null) {
        banner.set(block);
    } else if (skull != null){
        skull.set(block);
    } else if (pot != null){
        pot.set(nms, block);
    } else if (spawnerBlockType != null) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        CreatureSpawner cs = (CreatureSpawner)block.getState();
        cs.setSpawnedType(spawnerBlockType);
        //Bukkit.getLogger().info("DEBUG: setting spawner");
        cs.update(true, false);
    } else if (!chestContents.isEmpty()) {
        if (block.getTypeId() != typeId) {
            block.setTypeId(typeId);
        }
        //Bukkit.getLogger().info("DEBUG: inventory holder "+ block.getType());
        // Check if this is a double chest
        
        InventoryHolder chestBlock = (InventoryHolder) block.getState();
        //InventoryHolder iH = chestBlock.getInventory().getHolder();
        if (chestBlock instanceof DoubleChest) {
            //Bukkit.getLogger().info("DEBUG: double chest");
            DoubleChest doubleChest = (DoubleChest) chestBlock;
            for (ItemStack chestItem: chestContents.values()) {
                doubleChest.getInventory().addItem(chestItem);
            }
        } else {
            // Single chest
            for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
                //Bukkit.getLogger().info("DEBUG: " + en.getKey() + ","  + en.getValue());
                chestBlock.getInventory().setItem(en.getKey(), en.getValue());
            }
        }
    }
}
 
Example #19
Source File: ChestProtectListener.java    From ShopChest with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    final Player p = e.getPlayer();
    final Block b = e.getBlockPlaced();

    if (!b.getType().equals(Material.CHEST) && !b.getType().equals(Material.TRAPPED_CHEST)) {
        return;
    }
    
    Chest c = (Chest) b.getState();
    Block b2;

    // Can't use Utils::getChestLocations since inventory holder
    // has not been updated yet in this event (for 1.13+)

    if (Utils.getMajorVersion() < 13) {
        InventoryHolder ih = c.getInventory().getHolder();
        if (!(ih instanceof DoubleChest)) {
            return;
        }

        DoubleChest dc = (DoubleChest) ih;
        Chest l = (Chest) dc.getLeftSide();
        Chest r = (Chest) dc.getRightSide();

        if (b.getLocation().equals(l.getLocation())) {
            b2 = r.getBlock();
        } else {
            b2 = l.getBlock();
        }
    } else {
        org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();

        if (data.getType() == Type.SINGLE) {
            return;
        }

        BlockFace neighborFacing;

        switch (data.getFacing()) {
            case NORTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
                break;
            case EAST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
                break;
            case SOUTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
                break;
            case WEST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
                break;
            default:
                neighborFacing = null;
        }

        b2 = b.getRelative(neighborFacing);
    }

    final Shop shop = shopUtils.getShop(b2.getLocation());
    if (shop == null)
        return;

    plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));

    ShopExtendEvent event = new ShopExtendEvent(p, shop, b.getLocation());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled() && !p.hasPermission(Permissions.EXTEND_PROTECTED)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
        return;
    }

    if (!p.getUniqueId().equals(shop.getVendor().getUniqueId()) && !p.hasPermission(Permissions.EXTEND_OTHER)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_OTHERS));
        return;
    }

    if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
        return;
    }

    final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());

    shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
        @Override
        public void onResult(Void result) {
            newShop.create(true);
            shopUtils.addShop(newShop, true);
            plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
        }
    });
}
 
Example #20
Source File: CraftInventoryDoubleChest.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DoubleChest getHolder() {
    return new DoubleChest(this);
}
 
Example #21
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true) @SuppressWarnings("unused")
public void onCivilianClickItem(InventoryClickEvent event) {
    if (event.getClickedInventory() != null) {
        Location inventoryLocation = event.getClickedInventory().getLocation();
        UnloadedInventoryHandler.getInstance().updateInventoryAtLocation(inventoryLocation);
    }
    handleCustomItem(event.getCurrentItem(), event.getWhoClicked().getUniqueId());
    if (ConfigManager.getInstance().getAllowSharingCivsItems()) {
        return;
    }
    boolean shiftClick = event.getClick().isShiftClick() && event.getClickedInventory() != null &&
            event.getClickedInventory().equals(event.getWhoClicked().getInventory());
    boolean dragToChest = event.getClickedInventory() != null &&
            !event.getClickedInventory().equals(event.getWhoClicked().getInventory());

    if (event.getView().getTopInventory().getHolder() instanceof DoubleChest) {
        DoubleChest doubleChest = (DoubleChest) event.getView().getTopInventory().getHolder();
        Location leftLocation = ((Chest) doubleChest.getLeftSide()).getLocation();
        Location rightLocation = ((Chest) doubleChest.getRightSide()).getLocation();
        RegionManager.getInstance().removeCheckedRegion(leftLocation);
        RegionManager.getInstance().removeCheckedRegion(rightLocation);
    } else {
        if (event.getClickedInventory() != null &&
                event.getClickedInventory().getType() != InventoryType.ENDER_CHEST &&
                event.getView().getTopInventory().getType() != InventoryType.ENDER_CHEST) {
            try {
                RegionManager.getInstance().removeCheckedRegion(event.getView().getTopInventory().getLocation());
            } catch (NullPointerException npe) {
                // Doesn't matter if there's an error here
            }
        }
    }

    ItemStack stackInQuestion = shiftClick ? event.getCurrentItem() : event.getCursor();

    if (stackInQuestion == null || (!shiftClick && !dragToChest)) {
        return;
    }

    if (!CVItem.isCivsItem(stackInQuestion) || MenuManager.getInstance().hasMenuOpen(event.getWhoClicked().getUniqueId())) {
        return;
    }
    HumanEntity humanEntity = event.getWhoClicked();
    event.setCancelled(true);
    humanEntity.sendMessage(Civs.getPrefix() +
            LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity, LocaleConstants.PREVENT_CIVS_ITEM_SHARE));
}
 
Example #22
Source File: CraftInventoryDoubleChest.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DoubleChest getHolder() {
    return new DoubleChest(this);
}
 
Example #23
Source File: DoubleChestInventory.java    From Kettle with GNU General Public License v3.0 votes vote down vote up
DoubleChest getHolder();