Search in sources :

Example 1 with StringPlaceholders

use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseGarden by Rosewood-Development.

the class EnumArgumentHandler method handleInternal.

@Override
protected T handleInternal(RoseCommandArgumentInfo argumentInfo, ArgumentParser argumentParser) {
    String input = argumentParser.next();
    T[] enumConstants = this.getHandledType().getEnumConstants();
    Optional<T> value = Stream.of(enumConstants).filter(x -> x.name().equalsIgnoreCase(input)).findFirst();
    if (!value.isPresent()) {
        String messageKey;
        StringPlaceholders placeholders = StringPlaceholders.builder("enum", this.handledType.getSimpleName()).addPlaceholder("input", input).addPlaceholder("types", Stream.of(enumConstants).map(x -> x.name().toLowerCase()).collect(Collectors.joining(", "))).build();
        if (enumConstants.length <= 10) {
            messageKey = "argument-handler-enum-list";
        } else {
            messageKey = "argument-handler-enum";
        }
        throw new HandledArgumentException(messageKey, placeholders);
    }
    return value.get();
}
Also used : RoseCommandArgumentInfo(dev.rosewood.rosegarden.command.framework.RoseCommandArgumentInfo) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) RoseCommandArgumentHandler(dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler) ArgumentParser(dev.rosewood.rosegarden.command.framework.ArgumentParser) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) Collectors(java.util.stream.Collectors) RosePlugin(dev.rosewood.rosegarden.RosePlugin) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders)

Example 2 with StringPlaceholders

use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseStacker by Rosewood-Development.

the class ItemUtils method getSpawnerAsStackedItemStack.

public static ItemStack getSpawnerAsStackedItemStack(EntityType entityType, int amount) {
    ItemStack itemStack = new ItemStack(Material.SPAWNER);
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta == null)
        return itemStack;
    SpawnerStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getSpawnerStackSettings(entityType);
    StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
    String displayString;
    if (amount == 1) {
        displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display-single", placeholders);
    } else {
        displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display", placeholders);
    }
    itemMeta.setDisplayName(displayString);
    // Set the lore, if defined
    List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-spawner", placeholders);
    if (!lore.isEmpty())
        itemMeta.setLore(lore);
    // Set the spawned type directly onto the spawner item for hopeful compatibility with other plugins
    BlockStateMeta blockStateMeta = (BlockStateMeta) itemMeta;
    CreatureSpawner creatureSpawner = (CreatureSpawner) blockStateMeta.getBlockState();
    creatureSpawner.setSpawnedType(entityType);
    blockStateMeta.setBlockState(creatureSpawner);
    itemStack.setItemMeta(itemMeta);
    // Set stack size and spawned entity type
    NMSHandler nmsHandler = NMSAdapter.getHandler();
    itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
    itemStack = nmsHandler.setItemStackNBT(itemStack, "EntityType", entityType.name());
    return itemStack;
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) ItemStack(org.bukkit.inventory.ItemStack) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) ItemMeta(org.bukkit.inventory.meta.ItemMeta) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 3 with StringPlaceholders

use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseStacker by Rosewood-Development.

the class ItemUtils method getEntityAsStackedItemStack.

public static ItemStack getEntityAsStackedItemStack(EntityType entityType, int amount) {
    EntityStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getEntityStackSettings(entityType);
    Material spawnEggMaterial = stackSettings.getEntityTypeData().getSpawnEggMaterial();
    if (spawnEggMaterial == null)
        return null;
    ItemStack itemStack = new ItemStack(spawnEggMaterial);
    if (amount == 1)
        return itemStack;
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta == null)
        return itemStack;
    StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
    String displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("entity-stack-display-spawn-egg", placeholders);
    itemMeta.setDisplayName(displayString);
    // Set the lore, if defined
    List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-entity", placeholders);
    if (!lore.isEmpty())
        itemMeta.setLore(lore);
    itemStack.setItemMeta(itemMeta);
    // Set stack size
    NMSHandler nmsHandler = NMSAdapter.getHandler();
    itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
    return itemStack;
}
Also used : EntityStackSettings(dev.rosewood.rosestacker.stack.settings.EntityStackSettings) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) Material(org.bukkit.Material) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) ItemStack(org.bukkit.inventory.ItemStack) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 4 with StringPlaceholders

use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseStacker by Rosewood-Development.

the class ItemUtils method getBlockAsStackedItemStack.

public static ItemStack getBlockAsStackedItemStack(Material material, int amount) {
    ItemStack itemStack = new ItemStack(material);
    if (amount == 1)
        return itemStack;
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta == null)
        return itemStack;
    BlockStackSettings stackSettings = RoseStacker.getInstance().getManager(StackSettingManager.class).getBlockStackSettings(material);
    StringPlaceholders placeholders = StringPlaceholders.builder("amount", amount).addPlaceholder("name", stackSettings.getDisplayName()).build();
    String displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("block-stack-display", placeholders);
    itemMeta.setDisplayName(displayString);
    // Set the lore, if defined
    List<String> lore = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessages("stack-item-lore-block", placeholders);
    if (!lore.isEmpty())
        itemMeta.setLore(lore);
    itemStack.setItemMeta(itemMeta);
    // Set stack size
    NMSHandler nmsHandler = NMSAdapter.getHandler();
    itemStack = nmsHandler.setItemStackNBT(itemStack, "StackSize", amount);
    return itemStack;
}
Also used : StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) ItemStack(org.bukkit.inventory.ItemStack) BlockStackSettings(dev.rosewood.rosestacker.stack.settings.BlockStackSettings) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 5 with StringPlaceholders

use of dev.rosewood.rosegarden.utils.StringPlaceholders in project RoseGarden by Rosewood-Development.

the class PluginUpdateManager method onPlayerJoin.

/**
 * Called when a player joins and notifies ops if an update is available
 *
 * @param event The join event
 */
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    if (this.updateVersion == null || !player.isOp())
        return;
    String website = this.rosePlugin.getDescription().getWebsite();
    String updateMessage = "&eAn update for <g:#8A2387:#E94057:#F27121>" + this.rosePlugin.getName() + " &e(&bv%new%&e) is available! You are running &bv%current%&e." + (website != null ? " " + website : "");
    StringPlaceholders placeholders = StringPlaceholders.builder("new", this.updateVersion).addPlaceholder("current", this.rosePlugin.getDescription().getVersion()).build();
    RoseGardenUtils.sendMessage(player, updateMessage, placeholders);
}
Also used : StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Aggregations

StringPlaceholders (dev.rosewood.rosegarden.utils.StringPlaceholders)6 LocaleManager (dev.rosewood.rosestacker.manager.LocaleManager)3 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)3 NMSHandler (dev.rosewood.rosestacker.nms.NMSHandler)3 ItemStack (org.bukkit.inventory.ItemStack)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 RosePlugin (dev.rosewood.rosegarden.RosePlugin)1 ArgumentParser (dev.rosewood.rosegarden.command.framework.ArgumentParser)1 RoseCommand (dev.rosewood.rosegarden.command.framework.RoseCommand)1 RoseCommandArgumentHandler (dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler)1 RoseCommandArgumentInfo (dev.rosewood.rosegarden.command.framework.RoseCommandArgumentInfo)1 RoseExecutable (dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable)1 AbstractLocaleManager (dev.rosewood.rosegarden.manager.AbstractLocaleManager)1 BlockStackSettings (dev.rosewood.rosestacker.stack.settings.BlockStackSettings)1 EntityStackSettings (dev.rosewood.rosestacker.stack.settings.EntityStackSettings)1 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1