Search in sources :

Example 1 with ConversionHandler

use of dev.rosewood.rosestacker.conversion.handler.ConversionHandler in project RoseStacker by Rosewood-Development.

the class ConversionManager method convertChunkEntities.

/**
 * Runs the chunk data conversion for any conversion handlers
 *
 * @param chunkEntities The entities in the chunk to convert
 */
public void convertChunkEntities(List<Entity> chunkEntities) {
    Set<StackType> requiredStackTypes = new HashSet<>();
    for (ConversionHandler conversionHandler : this.conversionHandlers) requiredStackTypes.add(conversionHandler.getRequiredDataStackType());
    Map<StackType, Set<ConversionData>> conversionData = this.dataManager.getConversionData(chunkEntities, requiredStackTypes);
    Set<Stack<?>> convertedStacks = new HashSet<>();
    for (ConversionHandler conversionHandler : this.conversionHandlers) {
        Set<ConversionData> data;
        if (conversionHandler.shouldUseChunkEntities()) {
            data = new HashSet<>();
            switch(conversionHandler.getRequiredDataStackType()) {
                case ENTITY:
                    for (Entity entity : chunkEntities) if (entity.getType() != EntityType.DROPPED_ITEM)
                        data.add(new ConversionData(entity));
                    break;
                case ITEM:
                    for (Entity entity : chunkEntities) if (entity.getType() == EntityType.DROPPED_ITEM)
                        data.add(new ConversionData(entity));
                    break;
                default:
                    break;
            }
        } else {
            data = conversionData.get(conversionHandler.getRequiredDataStackType());
        }
        if (data.isEmpty())
            continue;
        convertedStacks.addAll(conversionHandler.handleConversion(data));
    }
    // Update nametags synchronously
    if (!convertedStacks.isEmpty())
        Bukkit.getScheduler().runTask(this.rosePlugin, () -> convertedStacks.forEach(Stack::updateDisplay));
}
Also used : Entity(org.bukkit.entity.Entity) StackType(dev.rosewood.rosestacker.stack.StackType) HashSet(java.util.HashSet) Set(java.util.Set) ConversionHandler(dev.rosewood.rosestacker.conversion.handler.ConversionHandler) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) HashSet(java.util.HashSet) Stack(dev.rosewood.rosestacker.stack.Stack)

Example 2 with ConversionHandler

use of dev.rosewood.rosestacker.conversion.handler.ConversionHandler in project RoseStacker by Rosewood-Development.

the class CommandManager method reload.

@Override
public void reload() {
    LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
    ConversionManager conversionManager = this.rosePlugin.getManager(ConversionManager.class);
    StackSettingManager stackSettingManager = this.rosePlugin.getManager(StackSettingManager.class);
    // Load custom message strings
    Map<String, String> acfCoreMessages = localeManager.getAcfCoreMessages();
    Map<String, String> acfMinecraftMessages = localeManager.getAcfMinecraftMessages();
    for (Entry<String, String> entry : acfCoreMessages.entrySet()) this.commandManager.getLocales().addMessage(Locale.ENGLISH, MessageKey.of("acf-core." + entry.getKey()), HexUtils.colorify(localeManager.getLocaleMessage("prefix") + entry.getValue()));
    for (Entry<String, String> entry : acfMinecraftMessages.entrySet()) this.commandManager.getLocales().addMessage(Locale.ENGLISH, MessageKey.of("acf-minecraft." + entry.getKey()), HexUtils.colorify(localeManager.getLocaleMessage("prefix") + entry.getValue()));
    CommandCompletions<BukkitCommandCompletionContext> completions = this.commandManager.getCommandCompletions();
    completions.registerStaticCompletion("stackableBlockMaterial", () -> stackSettingManager.getStackableBlockTypes().stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    completions.registerStaticCompletion("spawnableSpawnerEntityType", () -> stackSettingManager.getStackableSpawnerTypes().stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    completions.registerStaticCompletion("spawnableEggEntityType", () -> stackSettingManager.getStackableEntityTypes().stream().filter(x -> {
        EntityStackSettings stackSettings = stackSettingManager.getEntityStackSettings(x);
        return stackSettings.getEntityTypeData().getSpawnEggMaterial() != null;
    }).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    completions.registerAsyncCompletion("blockStackAmounts", ctx -> {
        Material blockType = ctx.getContextValue(Material.class);
        if (blockType == null)
            return Collections.emptyList();
        BlockStackSettings blockStackSettings = stackSettingManager.getBlockStackSettings(blockType);
        int maxStackAmount = blockStackSettings.getMaxStackSize();
        return Arrays.asList(String.valueOf(maxStackAmount), String.valueOf(maxStackAmount / 2), String.valueOf(maxStackAmount / 4), "<amount>");
    });
    completions.registerAsyncCompletion("spawnerStackAmounts", ctx -> {
        EntityType entityType = ctx.getContextValue(EntityType.class);
        if (entityType == null)
            return Collections.emptySet();
        SpawnerStackSettings spawnerStackSettings = stackSettingManager.getSpawnerStackSettings(entityType);
        int maxStackAmount = spawnerStackSettings.getMaxStackSize();
        return Arrays.asList(String.valueOf(maxStackAmount), String.valueOf(maxStackAmount / 2), String.valueOf(maxStackAmount / 4), "<amount>");
    });
    completions.registerAsyncCompletion("entityStackAmounts", ctx -> {
        EntityType entityType = ctx.getContextValue(EntityType.class);
        if (entityType == null)
            return Collections.emptySet();
        EntityStackSettings entityStackSettings = stackSettingManager.getEntityStackSettings(entityType);
        int maxStackAmount = entityStackSettings.getMaxStackSize();
        return Arrays.asList(String.valueOf(maxStackAmount), String.valueOf(maxStackAmount / 2), String.valueOf(maxStackAmount / 4), "<amount>");
    });
    completions.registerStaticCompletion("giveAmounts", () -> IntStream.rangeClosed(1, 5).mapToObj(String::valueOf).collect(Collectors.toList()));
    completions.registerStaticCompletion("clearallType", () -> Stream.of(ClearallType.values()).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    completions.registerStaticCompletion("stackType", () -> Stream.of(StackType.values()).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    completions.registerAsyncCompletion("conversionType", ctx -> conversionManager.getEnabledConverters().stream().map(Enum::name).collect(Collectors.toSet()));
    completions.registerAsyncCompletion("conversionEnabledType", ctx -> conversionManager.getEnabledHandlers().stream().map(ConversionHandler::getRequiredDataStackType).map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet()));
    completions.registerAsyncCompletion("translationLocales", ctx -> localeManager.getPossibleTranslationLocales());
    this.commandManager.getCommandConditions().addCondition(int.class, "limits", (c, exec, value) -> {
        if (value == null)
            return;
        if (c.hasConfig("min") && c.getConfigValue("min", 0) > value)
            throw new ConditionFailedException(MessageKeys.PLEASE_SPECIFY_AT_LEAST, "{min}", String.valueOf(c.getConfigValue("min", 0)));
        if (c.hasConfig("max") && c.getConfigValue("max", Integer.MAX_VALUE) < value)
            throw new ConditionFailedException(MessageKeys.PLEASE_SPECIFY_AT_MOST, "{max}", String.valueOf(c.getConfigValue("max", Integer.MAX_VALUE)));
    });
}
Also used : EntityStackSettings(dev.rosewood.rosestacker.stack.settings.EntityStackSettings) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) ConversionHandler(dev.rosewood.rosestacker.conversion.handler.ConversionHandler) Material(org.bukkit.Material) BlockStackSettings(dev.rosewood.rosestacker.stack.settings.BlockStackSettings) EntityType(org.bukkit.entity.EntityType) ConditionFailedException(co.aikar.commands.ConditionFailedException) BukkitCommandCompletionContext(co.aikar.commands.BukkitCommandCompletionContext)

Aggregations

ConversionHandler (dev.rosewood.rosestacker.conversion.handler.ConversionHandler)2 BukkitCommandCompletionContext (co.aikar.commands.BukkitCommandCompletionContext)1 ConditionFailedException (co.aikar.commands.ConditionFailedException)1 ConversionData (dev.rosewood.rosestacker.conversion.ConversionData)1 Stack (dev.rosewood.rosestacker.stack.Stack)1 StackType (dev.rosewood.rosestacker.stack.StackType)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 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Material (org.bukkit.Material)1 Entity (org.bukkit.entity.Entity)1 EntityType (org.bukkit.entity.EntityType)1