Search in sources :

Example 1 with LocaleManager

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

the class RoseCommand method onCommand.

@Default
@CatchUnknown
public void onCommand(CommandSender sender) {
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    String baseColor = localeManager.getLocaleMessage("base-command-color");
    localeManager.sendCustomMessage(sender, baseColor + "Running <g:#8A2387:#E94057:#F27121>RoseStacker" + baseColor + " v" + this.rosePlugin.getDescription().getVersion());
    localeManager.sendCustomMessage(sender, baseColor + "Plugin created by: <g:#41e0f0:#ff8dce>" + this.rosePlugin.getDescription().getAuthors().get(0));
    localeManager.sendSimpleMessage(sender, "base-command-help");
}
Also used : LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) CatchUnknown(co.aikar.commands.annotation.CatchUnknown) Default(co.aikar.commands.annotation.Default)

Example 2 with LocaleManager

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

the class BlockListener method tryDropSpawners.

/**
 * Tries to drop spawners that a player broke
 *
 * @param player The Player
 * @param dropLocation The location to drop the items
 * @param spawnedType The type of entity the spawner spawns
 * @param amount The amount to try to drop
 * @param placedByPlayer whether or not the spawner was placed by a player
 * @return true if spawners weren't protected, false otherwise
 */
private boolean tryDropSpawners(Player player, Location dropLocation, EntityType spawnedType, int amount, boolean placedByPlayer) {
    ItemStack itemInHand = player.getInventory().getItemInMainHand();
    if (dropLocation.getWorld() == null)
        return true;
    if (player.getGameMode() == GameMode.CREATIVE) {
        if (!Setting.SPAWNER_DROP_IN_CREATIVE.getBoolean())
            return true;
    } else {
        if (!itemInHand.getType().name().endsWith("PICKAXE"))
            return true;
    }
    if ((Setting.SPAWNER_SILK_TOUCH_REQUIRED.getBoolean() || Setting.SPAWNER_ADVANCED_PERMISSIONS.getBoolean()) && player.getGameMode() != GameMode.CREATIVE) {
        int destroyAmount = 0;
        int silkTouchLevel = itemInHand.getEnchantmentLevel(Enchantment.SILK_TOUCH);
        boolean destroyFromMissingPermission;
        boolean hasAdvNoSilkPermission = player.hasPermission("rosestacker.nosilk." + spawnedType.name().toLowerCase());
        boolean hasAdvSilkTouchPermission = player.hasPermission("rosestacker.silktouch." + spawnedType.name().toLowerCase());
        if (Setting.SPAWNER_ADVANCED_PERMISSIONS.getBoolean()) {
            boolean hasPermission = hasAdvNoSilkPermission;
            if (silkTouchLevel > 0)
                hasPermission |= hasAdvSilkTouchPermission;
            destroyFromMissingPermission = !hasPermission;
        } else {
            destroyFromMissingPermission = Setting.SPAWNER_SILK_TOUCH_REQUIRE_PERMISSION.getBoolean() && !player.hasPermission("rosestacker.silktouch");
        }
        if (destroyFromMissingPermission)
            destroyAmount = amount;
        if (!(Setting.SPAWNER_SILK_TOUCH_ONLY_NATURAL.getBoolean() && placedByPlayer) && (!Setting.SPAWNER_ADVANCED_PERMISSIONS.getBoolean() || !hasAdvNoSilkPermission) && (!Setting.SPAWNER_SILK_TOUCH_GUARANTEE.getBoolean() || silkTouchLevel < 2)) {
            double chance = StackerUtils.getSilkTouchChanceRaw(player) / 100;
            for (int i = 0, n = amount - destroyAmount; i < n; i++) {
                boolean passesChance = StackerUtils.passesChance(chance);
                if (!passesChance || silkTouchLevel == 0)
                    destroyAmount++;
            }
        }
        if (destroyAmount > amount)
            destroyAmount = amount;
        amount -= destroyAmount;
        if (destroyAmount > 0) {
            if (Setting.SPAWNER_SILK_TOUCH_PROTECT.getBoolean() && (silkTouchLevel <= 0 || destroyFromMissingPermission)) {
                LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
                if (Setting.SPAWNER_ADVANCED_PERMISSIONS.getBoolean()) {
                    if (hasAdvSilkTouchPermission) {
                        localeManager.sendMessage(player, "spawner-advanced-break-silktouch-no-permission");
                    } else {
                        localeManager.sendMessage(player, "spawner-advanced-break-no-permission");
                    }
                } else {
                    localeManager.sendMessage(player, "spawner-silk-touch-protect");
                }
                return false;
            }
            StackerUtils.dropExperience(dropLocation, 15 * destroyAmount, 43 * destroyAmount, 15 * destroyAmount);
        }
    }
    if (amount <= 0)
        return true;
    List<ItemStack> items;
    if (Setting.SPAWNER_BREAK_ENTIRE_STACK_INTO_SEPARATE.getBoolean()) {
        items = new ArrayList<>();
        for (int i = 0; i < amount; i++) items.add(ItemUtils.getSpawnerAsStackedItemStack(spawnedType, 1));
    } else {
        items = Collections.singletonList(ItemUtils.getSpawnerAsStackedItemStack(spawnedType, amount));
    }
    if (Setting.SPAWNER_DROP_TO_INVENTORY.getBoolean()) {
        ItemUtils.dropItemsToPlayer(player, items);
    } else {
        this.rosePlugin.getManager(StackManager.class).preStackItems(items, dropLocation);
    }
    return true;
}
Also used : StackManager(dev.rosewood.rosestacker.manager.StackManager) LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with LocaleManager

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

the class RoseCommand method onHelp.

@Subcommand("help")
public void onHelp(CommandSender sender) {
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    localeManager.sendMessage(sender, "command-help-title");
    localeManager.sendSimpleMessage(sender, "command-convert-description");
    localeManager.sendSimpleMessage(sender, "command-clearall-description");
    localeManager.sendSimpleMessage(sender, "command-give-description");
    localeManager.sendSimpleMessage(sender, "command-help-description");
    localeManager.sendSimpleMessage(sender, "command-reload-description");
    localeManager.sendSimpleMessage(sender, "command-stacktool-description");
    localeManager.sendSimpleMessage(sender, "command-stats-description");
    localeManager.sendSimpleMessage(sender, "command-translate-description");
}
Also used : LocaleManager(dev.rosewood.rosestacker.manager.LocaleManager) Subcommand(co.aikar.commands.annotation.Subcommand)

Example 4 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 5 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)

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