Search in sources :

Example 6 with LocaleManager

use of dev.rosewood.rosestacker.manager.LocaleManager in project RoseStacker by Rosewood-Development.

the class RoseCommand method onStats.

@Subcommand("stats")
@CommandPermission("rosestacker.stats")
public void onStats(CommandSender sender) {
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    int threadAmount = stackManager.getStackingThreads().size();
    int entityStackAmount = stackManager.getStackedEntities().size();
    int itemStackAmount = stackManager.getStackedItems().size();
    int blockStackAmount = stackManager.getStackedBlocks().size();
    int spawnerStackAmount = stackManager.getStackedSpawners().size();
    int entityAmount = stackManager.getStackedEntities().values().stream().mapToInt(Stack::getStackSize).sum();
    int itemAmount = stackManager.getStackedItems().values().stream().mapToInt(Stack::getStackSize).sum();
    int blockAmount = stackManager.getStackedBlocks().values().stream().mapToInt(Stack::getStackSize).sum();
    int spawnerAmount = stackManager.getStackedSpawners().values().stream().mapToInt(Stack::getStackSize).sum();
    localeManager.sendMessage(sender, "command-stats-header");
    localeManager.sendSimpleMessage(sender, "command-stats-threads", StringPlaceholders.single("amount", threadAmount));
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-entities", StringPlaceholders.builder("stackAmount", entityStackAmount).addPlaceholder("total", entityAmount).build());
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-items", StringPlaceholders.builder("stackAmount", itemStackAmount).addPlaceholder("total", itemAmount).build());
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-blocks", StringPlaceholders.builder("stackAmount", blockStackAmount).addPlaceholder("total", blockAmount).build());
    localeManager.sendSimpleMessage(sender, "command-stats-stacked-spawners", StringPlaceholders.builder("stackAmount", spawnerStackAmount).addPlaceholder("total", spawnerAmount).build());
}
Also used : StackManager(dev.rosewood.rosestacker.manager.StackManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 7 with LocaleManager

use of dev.rosewood.rosestacker.manager.LocaleManager in project RoseStacker by Rosewood-Development.

the class RoseCommand method onConvert.

@Subcommand("convert")
@CommandPermission("rosestacker.convert")
@CommandCompletion("@conversionType")
public void onConvert(CommandSender sender, StackPlugin stackPlugin) {
    ConversionManager conversionManager = this.rosePlugin.getManager(ConversionManager.class);
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    if (conversionManager.convert(stackPlugin)) {
        localeManager.sendMessage(sender, "command-convert-converted", StringPlaceholders.single("plugin", stackPlugin.name()));
    } else {
        localeManager.sendMessage(sender, "command-convert-failed", StringPlaceholders.single("plugin", stackPlugin.name()));
    }
}
Also used : ConversionManager(dev.rosewood.rosestacker.manager.ConversionManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 8 with LocaleManager

use of dev.rosewood.rosestacker.manager.LocaleManager in project RoseStacker by Rosewood-Development.

the class RoseCommand method onTranslate.

@Subcommand("translate")
@CommandPermission("rosestacker.translate")
@CommandCompletion("@translationLocales *")
public void onTranslate(CommandSender sender, String locale, @Optional String spawnerFormat) {
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    StackSettingManager stackSettingManager = this.rosePlugin.getManager(StackSettingManager.class);
    if (spawnerFormat == null) {
        spawnerFormat = "{}";
        localeManager.sendMessage(sender, "command-translate-spawner-format");
    }
    if (!spawnerFormat.contains("{}")) {
        localeManager.sendMessage(sender, "command-translate-spawner-format-invalid");
        return;
    }
    localeManager.sendMessage(sender, "command-translate-loading");
    String finalSpawnerFormat = spawnerFormat;
    localeManager.getMinecraftTranslationValues(locale, response -> {
        if (response.getResult() == Result.FAILURE) {
            localeManager.sendMessage(sender, "command-translate-failure");
            return;
        }
        if (response.getResult() == Result.INVALID_LOCALE) {
            localeManager.sendMessage(sender, "command-translate-invalid-locale");
            return;
        }
        CommentedFileConfiguration blockStackConfig = CommentedFileConfiguration.loadConfiguration(stackSettingManager.getBlockSettingsFile());
        CommentedFileConfiguration entityStackConfig = CommentedFileConfiguration.loadConfiguration(stackSettingManager.getEntitySettingsFile());
        CommentedFileConfiguration itemStackConfig = CommentedFileConfiguration.loadConfiguration(stackSettingManager.getItemSettingsFile());
        CommentedFileConfiguration spawnerStackConfig = CommentedFileConfiguration.loadConfiguration(stackSettingManager.getSpawnerSettingsFile());
        Map<Material, String> materialValues = response.getMaterialValues();
        Map<EntityType, String> entityValues = response.getEntityValues();
        for (Entry<Material, String> entry : materialValues.entrySet()) {
            Material material = entry.getKey();
            String value = entry.getValue();
            if (blockStackConfig.isConfigurationSection(material.name()))
                blockStackConfig.set(material.name() + ".display-name", value);
            if (itemStackConfig.isConfigurationSection(material.name()))
                itemStackConfig.set(material.name() + ".display-name", value);
        }
        for (Entry<EntityType, String> entry : entityValues.entrySet()) {
            EntityType entityType = entry.getKey();
            String value = entry.getValue();
            if (entityStackConfig.isConfigurationSection(entityType.name()))
                entityStackConfig.set(entityType.name() + ".display-name", value);
            if (spawnerStackConfig.isConfigurationSection(entityType.name())) {
                String name = finalSpawnerFormat.replaceAll(Pattern.quote("{}"), value);
                spawnerStackConfig.set(entityType.name() + ".display-name", name);
            }
        }
        blockStackConfig.save();
        entityStackConfig.save();
        itemStackConfig.save();
        spawnerStackConfig.save();
        Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
            this.rosePlugin.reload();
            localeManager.sendMessage(sender, "command-translate-success");
        });
    });
}
Also used : EntityType(org.bukkit.entity.EntityType) CommentedFileConfiguration(dev.rosewood.rosegarden.config.CommentedFileConfiguration) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) Material(org.bukkit.Material) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Example 9 with LocaleManager

use of dev.rosewood.rosestacker.manager.LocaleManager in project RoseStacker by Rosewood-Development.

the class StackedBlockGui method buildGui.

/**
 * Builds the GUI from scratch
 */
private void buildGui() {
    this.guiContainer = GuiFactory.createContainer();
    List<Integer> paginatedSlots = new ArrayList<>();
    for (int i = 10; i <= 16; i++) paginatedSlots.add(i);
    for (int i = 19; i <= 25; i++) paginatedSlots.add(i);
    for (int i = 28; i <= 34; i++) paginatedSlots.add(i);
    for (int i = 37; i <= 43; i++) paginatedSlots.add(i);
    List<Integer> borderSlots = new ArrayList<>();
    for (int i = 0; i <= 8; i++) borderSlots.add(i);
    for (int i = 9; i <= 36; i += 9) borderSlots.add(i);
    for (int i = 17; i <= 44; i += 9) borderSlots.add(i);
    for (int i = 46; i <= 52; i += 2) borderSlots.add(i);
    borderSlots.addAll(Arrays.asList(45, 53));
    ItemStack borderItem = new ItemStack(GuiHelper.parseMaterial(Setting.BLOCK_GUI_BORDER_MATERIAL.getString()));
    ItemMeta itemMeta = borderItem.getItemMeta();
    if (itemMeta != null) {
        itemMeta.setDisplayName(" ");
        itemMeta.addItemFlags(ItemFlag.values());
        borderItem.setItemMeta(itemMeta);
    }
    List<Integer> destroyBorderSlots = new ArrayList<>();
    for (int i = 0; i <= 26; i++) destroyBorderSlots.add(i);
    destroyBorderSlots.removeAll(Arrays.asList(12, 14));
    GuiScreenSection editableSection = GuiFactory.createScreenSection(paginatedSlots);
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    BlockStackSettings stackSettings = this.stackedBlock.getStackSettings();
    GuiStringHelper pageBackString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-page-back", StringPlaceholders.empty()));
    GuiStringHelper destroyString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-destroy", StringPlaceholders.empty()));
    GuiStringHelper pageForwardString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-page-forward", StringPlaceholders.empty()));
    GuiStringHelper confirmDestroyString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-destroy-confirm", StringPlaceholders.empty()));
    GuiStringHelper confirmCancelString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-destroy-cancel", StringPlaceholders.empty()));
    List<ItemStack> stackItems = GuiUtil.getMaterialAmountAsItemStacks(this.stackedBlock.getBlock().getType(), this.stackedBlock.getStackSize());
    int pages = (int) Math.ceil((double) stackItems.size() / paginatedSlots.size()) + 1;
    while (stackItems.size() < pages * paginatedSlots.size()) stackItems.add(new ItemStack(Material.AIR));
    GuiScreen mainScreen = GuiFactory.createScreen(this.guiContainer, GuiSize.ROWS_SIX).setTitle(localeManager.getLocaleMessage("gui-stacked-block-title", StringPlaceholders.single("name", stackSettings.getDisplayName()))).setEditableSection(editableSection, stackItems, this::updateStackedBlock).setEditFilters(GuiFactory.createScreenEditFilters().setWhitelist(this.stackedBlock.getBlock().getType()).setAllowModified(false)).addButtonAt(47, GuiFactory.createButton().setIcon(Material.PAPER).setName(pageBackString.getName()).setLore(pageBackString.getLore()).setClickAction(event -> ClickAction.PAGE_BACKWARDS).setFlags(GuiButtonFlag.HIDE_IF_FIRST_PAGE).setHiddenReplacement(borderItem)).addButtonAt(49, GuiFactory.createButton().setIcon(Material.BARRIER).setName(destroyString.getName()).setLore(destroyString.getLore()).setClickAction(event -> ClickAction.TRANSITION_FORWARDS)).addButtonAt(51, GuiFactory.createButton().setIcon(Material.PAPER).setName(pageForwardString.getName()).setLore(pageForwardString.getLore()).setClickAction(event -> ClickAction.PAGE_FORWARDS).setFlags(GuiButtonFlag.HIDE_IF_LAST_PAGE).setHiddenReplacement(borderItem));
    for (int slot : borderSlots) mainScreen.addItemStackAt(slot, borderItem);
    GuiScreen confirmScreen = GuiFactory.createScreen(this.guiContainer, GuiSize.ROWS_THREE).setTitle(localeManager.getLocaleMessage("gui-stacked-block-destroy-title", StringPlaceholders.single("name", stackSettings.getDisplayName()))).addButtonAt(12, GuiFactory.createButton().setIcon(Material.EMERALD_BLOCK).setName(confirmDestroyString.getName()).setLore(confirmDestroyString.getLore()).setClickAction(event -> {
        this.destroyStackedBlock((Player) event.getWhoClicked());
        return ClickAction.NOTHING;
    })).addButtonAt(14, GuiFactory.createButton().setIcon(Material.REDSTONE_BLOCK).setName(confirmCancelString.getName()).setLore(confirmCancelString.getLore()).setClickAction(event -> ClickAction.TRANSITION_BACKWARDS));
    for (int slot : destroyBorderSlots) confirmScreen.addItemStackAt(slot, borderItem);
    this.guiContainer.addScreen(mainScreen);
    this.guiContainer.addScreen(confirmScreen);
    this.guiFramework.getGuiManager().registerGui(this.guiContainer);
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) GuiFactory(dev.rosewood.guiframework.GuiFactory) Arrays(java.util.Arrays) GuiSize(dev.rosewood.guiframework.gui.GuiSize) ItemMeta(org.bukkit.inventory.meta.ItemMeta) RoseStacker(dev.rosewood.rosestacker.RoseStacker) Player(org.bukkit.entity.Player) ClickAction(dev.rosewood.guiframework.gui.ClickAction) ItemUtils(dev.rosewood.rosestacker.utils.ItemUtils) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) GuiUtil(dev.rosewood.guiframework.framework.util.GuiUtil) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) FrameworkView(dev.rosewood.guiframework.framework.gui.FrameworkView) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) GuiScreenSection(dev.rosewood.guiframework.gui.screen.GuiScreenSection) BlockUnstackEvent(dev.rosewood.rosestacker.event.BlockUnstackEvent) BlockStackEvent(dev.rosewood.rosestacker.event.BlockStackEvent) Setting(dev.rosewood.rosestacker.manager.ConfigurationManager.Setting) GuiButtonFlag(dev.rosewood.guiframework.gui.GuiButtonFlag) GuiScreen(dev.rosewood.guiframework.gui.screen.GuiScreen) Sound(org.bukkit.Sound) RosePlugin(dev.rosewood.rosegarden.RosePlugin) BlockStackSettings(dev.rosewood.rosestacker.stack.settings.BlockStackSettings) ItemStack(org.bukkit.inventory.ItemStack) StackManager(dev.rosewood.rosestacker.manager.StackManager) List(java.util.List) GuiStringHelper(dev.rosewood.rosestacker.gui.GuiHelper.GuiStringHelper) GuiFramework(dev.rosewood.guiframework.GuiFramework) GuiContainer(dev.rosewood.guiframework.gui.GuiContainer) Collections(java.util.Collections) GuiScreenSection(dev.rosewood.guiframework.gui.screen.GuiScreenSection) ArrayList(java.util.ArrayList) BlockStackSettings(dev.rosewood.rosestacker.stack.settings.BlockStackSettings) GuiStringHelper(dev.rosewood.rosestacker.gui.GuiHelper.GuiStringHelper) GuiScreen(dev.rosewood.guiframework.gui.screen.GuiScreen) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

LocaleManager (dev.rosewood.rosestacker.manager.LocaleManager)9 Subcommand (co.aikar.commands.annotation.Subcommand)6 CommandPermission (co.aikar.commands.annotation.CommandPermission)5 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)4 StackManager (dev.rosewood.rosestacker.manager.StackManager)4 Material (org.bukkit.Material)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 CatchUnknown (co.aikar.commands.annotation.CatchUnknown)1 Default (co.aikar.commands.annotation.Default)1 OnlinePlayer (co.aikar.commands.bukkit.contexts.OnlinePlayer)1 GuiFactory (dev.rosewood.guiframework.GuiFactory)1 GuiFramework (dev.rosewood.guiframework.GuiFramework)1 FrameworkView (dev.rosewood.guiframework.framework.gui.FrameworkView)1 GuiUtil (dev.rosewood.guiframework.framework.util.GuiUtil)1 ClickAction (dev.rosewood.guiframework.gui.ClickAction)1 GuiButtonFlag (dev.rosewood.guiframework.gui.GuiButtonFlag)1 GuiContainer (dev.rosewood.guiframework.gui.GuiContainer)1 GuiSize (dev.rosewood.guiframework.gui.GuiSize)1 GuiScreen (dev.rosewood.guiframework.gui.screen.GuiScreen)1