org.bukkit.Nameable Java Examples

The following examples show how to use org.bukkit.Nameable. 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: BlockPlacer.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void placeBlock(ItemStack item, Block facedBlock, Dispenser dispenser) {
    facedBlock.setType(item.getType());

    if (item.hasItemMeta()) {
        ItemMeta meta = item.getItemMeta();

        if (meta.hasDisplayName()) {
            BlockState blockState = facedBlock.getState();

            if ((blockState instanceof Nameable)) {
                ((Nameable) blockState).setCustomName(meta.getDisplayName());
            }

            // Update block state after changing name
            blockState.update();
        }

    }

    facedBlock.getWorld().playEffect(facedBlock.getLocation(), Effect.STEP_SOUND, item.getType());

    if (dispenser.getInventory().containsAtLeast(item, 2)) {
        dispenser.getInventory().removeItem(new CustomItem(item, 1));
    }
    else {
        Slimefun.runSync(() -> dispenser.getInventory().removeItem(item), 2L);
    }
}
 
Example #2
Source File: InventoryGui.java    From InventoryGui with MIT License 3 votes vote down vote up
/**
 * Replace some placeholders in the with values regarding the gui's state. Replaced color codes.<br>
 * The placeholders are:<br>
 * <tt>%plugin%</tt>    - The name of the plugin that this gui is from.<br>
 * <tt>%owner%</tt>     - The name of the owner of this gui. Will be an empty string when the owner is null.<br>
 * <tt>%title%</tt>     - The title of this GUI.<br>
 * <tt>%page%</tt>      - The current page that this gui is on.<br>
 * <tt>%nextpage%</tt>  - The next page. "none" if there is no next page.<br>
 * <tt>%prevpage%</tt>  - The previous page. "none" if there is no previous page.<br>
 * <tt>%pages%</tt>     - The amount of pages that this gui has.
 * @param text          The text to replace the placeholders in
 * @param replacements  Additional repplacements. i = placeholder, i+1 = replacements
 * @return      The text with all placeholders replaced
 */
public String replaceVars(String text, String... replacements) {
    text = replace(replace(text, replacements),
            "plugin", plugin.getName(),
            "owner", owner instanceof Nameable ? ((Nameable) owner).getCustomName() : "",
            "title", title,
            "page", String.valueOf(getPageNumber() + 1),
            "nextpage", getPageNumber() + 1 < getPageAmount() ? String.valueOf(getPageNumber() + 2) : "none",
            "prevpage", getPageNumber() > 0 ? String.valueOf(getPageNumber()) : "none",
            "pages", String.valueOf(getPageAmount())
    );
    return ChatColor.translateAlternateColorCodes('&', text);
}