Search in sources :

Example 1 with SerdesCommons

use of eu.okaeri.configs.serdes.commons.SerdesCommons in project FunnyGuilds by FunnyGuilds.

the class ConfigurationFactory method createTablistConfiguration.

public TablistConfiguration createTablistConfiguration(File tablistConfigurationFile) {
    return ConfigManager.create(TablistConfiguration.class, (it) -> {
        it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesCommons());
        it.withSerdesPack(registry -> {
            registry.register(new NumberRangeTransformer());
            registry.register(new TablistPageSerializer());
            registry.register(new SkinTextureSerializer());
        });
        it.withBindFile(tablistConfigurationFile);
        it.saveDefaults();
        it.load(true);
        it.migrate(new T0001_Update_player_list_animated());
    });
}
Also used : YamlBukkitConfigurer(eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer) T0001_Update_player_list_animated(net.dzikoysk.funnyguilds.config.migration.T0001_Update_player_list_animated) SkinTextureSerializer(net.dzikoysk.funnyguilds.config.serdes.SkinTextureSerializer) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) NumberRangeTransformer(net.dzikoysk.funnyguilds.config.serdes.NumberRangeTransformer) TablistPageSerializer(net.dzikoysk.funnyguilds.config.tablist.TablistPageSerializer) OkaeriValidator(eu.okaeri.configs.validator.okaeri.OkaeriValidator)

Example 2 with SerdesCommons

use of eu.okaeri.configs.serdes.commons.SerdesCommons in project FunnyGuilds by FunnyGuilds.

the class ConfigurationFactory method createPluginConfiguration.

public PluginConfiguration createPluginConfiguration(File pluginConfigurationFile) {
    return ConfigManager.create(PluginConfiguration.class, (it) -> {
        it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesCommons());
        it.withSerdesPack(registry -> {
            registry.register(new RawStringTransformer());
            registry.register(new MaterialTransformer());
            registry.register(new ItemStackTransformer());
            registry.register(new EntityTypeTransformer());
            registry.register(new FunnyTimeTransformer());
            registry.register(new RangeFormattingTransformer());
            registry.register(new VectorSerializer());
        });
        it.withBindFile(pluginConfigurationFile);
        it.withLogger(FunnyGuilds.getInstance().getLogger());
        it.saveDefaults();
        it.load(true);
        it.migrate(new P0001_Fix_freecam_compensation_key_case(), new P0002_Migrate_old_heart_configuration(), new P0003_Migrate_old_tnt_protection_configuration(), new P0004_Migrate_tablist_into_separate_file(), new P0005_Fix_heart_configuration_centery_key());
    });
}
Also used : ItemStackTransformer(net.dzikoysk.funnyguilds.config.serdes.ItemStackTransformer) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) P0004_Migrate_tablist_into_separate_file(net.dzikoysk.funnyguilds.config.migration.P0004_Migrate_tablist_into_separate_file) FunnyTimeTransformer(net.dzikoysk.funnyguilds.config.serdes.FunnyTimeTransformer) RawStringTransformer(net.dzikoysk.funnyguilds.config.serdes.RawStringTransformer) YamlBukkitConfigurer(eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer) P0001_Fix_freecam_compensation_key_case(net.dzikoysk.funnyguilds.config.migration.P0001_Fix_freecam_compensation_key_case) P0003_Migrate_old_tnt_protection_configuration(net.dzikoysk.funnyguilds.config.migration.P0003_Migrate_old_tnt_protection_configuration) EntityTypeTransformer(net.dzikoysk.funnyguilds.config.serdes.EntityTypeTransformer) RangeFormattingTransformer(net.dzikoysk.funnyguilds.config.serdes.RangeFormattingTransformer) VectorSerializer(net.dzikoysk.funnyguilds.config.serdes.VectorSerializer) P0002_Migrate_old_heart_configuration(net.dzikoysk.funnyguilds.config.migration.P0002_Migrate_old_heart_configuration) MaterialTransformer(net.dzikoysk.funnyguilds.config.serdes.MaterialTransformer) P0005_Fix_heart_configuration_centery_key(net.dzikoysk.funnyguilds.config.migration.P0005_Fix_heart_configuration_centery_key) OkaeriValidator(eu.okaeri.configs.validator.okaeri.OkaeriValidator)

Example 3 with SerdesCommons

use of eu.okaeri.configs.serdes.commons.SerdesCommons in project FunnyGuilds by FunnyGuilds.

the class FunnybinRequest method execute.

@Override
public void execute() throws Exception {
    List<FunnybinResponse> sentPastes = new ArrayList<>();
    for (int i = 0; i < files.size(); i++) {
        String fileName = files.get(i);
        File file;
        String content = null;
        PasteType type = PasteType.OTHER;
        sender.sendMessage(ChatColor.GREEN + "Wysylam plik: " + ChatColor.AQUA + (i + 1) + ChatColor.GREEN + "/" + ChatColor.AQUA + files.size() + ChatColor.GREEN + "...");
        if ("log".equals(fileName)) {
            file = new File("logs/latest.log");
            type = PasteType.LOGS;
        } else if ("config".equals(fileName)) {
            file = null;
            type = PasteType.CONFIG;
            PluginConfiguration config = ConfigManager.create(PluginConfiguration.class, (it) -> {
                it.withConfigurer(new YamlBukkitConfigurer(), new SerdesCommons());
                it.withBindFile(FunnyGuilds.getInstance().getPluginConfigurationFile());
                it.load();
            });
            config.mysql.hostname = "<CUT>";
            config.mysql.database = "<CUT>";
            config.mysql.user = "<CUT>";
            config.mysql.password = "<CUT>";
            content = config.saveToString();
        } else {
            file = new File(fileName);
        }
        if (content == null) {
            try {
                content = Files.asCharSource(file, StandardCharsets.UTF_8).read();
            } catch (FileNotFoundException e) {
                sender.sendMessage(ChatColor.RED + "Podany plik: " + fileName + " nie istnieje");
                continue;
            } catch (IOException e) {
                sender.sendMessage(ChatColor.RED + "Podany plik: " + fileName + " nie mogl być otworzony (szczegoly w konsoli)");
                FunnyGuilds.getPluginLogger().error("Failed to open a file: " + fileName, e);
                continue;
            }
        }
        try {
            sentPastes.add(FunnyTelemetry.postToFunnybin(content, type, fileName));
        } catch (IOException e) {
            sender.sendMessage(ChatColor.RED + "Podany plik: " + fileName + " nie mogl byc wyslany (szczegoly w konsoli)");
            FunnyGuilds.getPluginLogger().error("Failed to submit a paste: " + fileName, e);
        }
    }
    if (sentPastes.size() == 1) {
        sender.sendMessage(ChatColor.GREEN + "Plik wyslany. Link: " + ChatColor.AQUA + sentPastes.get(0).getShortUrl());
        return;
    }
    sender.sendMessage(ChatColor.GREEN + "Tworze paczke z wyslanych plikow...");
    try {
        FunnybinResponse response = FunnyTelemetry.createBundle(sentPastes.stream().map(FunnybinResponse::getUuid).collect(Collectors.toList()));
        sender.sendMessage(ChatColor.GREEN + "Paczka wyslana. Link: " + ChatColor.AQUA + response.getShortUrl());
    } catch (IOException e) {
        sender.sendMessage(ChatColor.RED + "Wystapil blad podczas tworzenia paczki. ");
        FunnyGuilds.getPluginLogger().error("Failed to submit a bundle. Files: " + files, e);
    }
}
Also used : Arrays(java.util.Arrays) CommandSender(org.bukkit.command.CommandSender) IOException(java.io.IOException) YamlBukkitConfigurer(eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) ArrayList(java.util.ArrayList) DefaultConcurrencyRequest(net.dzikoysk.funnyguilds.concurrency.util.DefaultConcurrencyRequest) List(java.util.List) PasteType(net.dzikoysk.funnyguilds.telemetry.PasteType) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) Files(com.google.common.io.Files) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) Optional(java.util.Optional) ChatColor(org.bukkit.ChatColor) ConfigManager(eu.okaeri.configs.ConfigManager) FunnybinResponse(net.dzikoysk.funnyguilds.telemetry.FunnybinResponse) Collections(java.util.Collections) FunnyTelemetry(net.dzikoysk.funnyguilds.telemetry.FunnyTelemetry) FunnybinResponse(net.dzikoysk.funnyguilds.telemetry.FunnybinResponse) PasteType(net.dzikoysk.funnyguilds.telemetry.PasteType) ArrayList(java.util.ArrayList) SerdesCommons(eu.okaeri.configs.serdes.commons.SerdesCommons) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) YamlBukkitConfigurer(eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) File(java.io.File)

Aggregations

SerdesCommons (eu.okaeri.configs.serdes.commons.SerdesCommons)3 YamlBukkitConfigurer (eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer)3 OkaeriValidator (eu.okaeri.configs.validator.okaeri.OkaeriValidator)2 Files (com.google.common.io.Files)1 ConfigManager (eu.okaeri.configs.ConfigManager)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)1 DefaultConcurrencyRequest (net.dzikoysk.funnyguilds.concurrency.util.DefaultConcurrencyRequest)1 PluginConfiguration (net.dzikoysk.funnyguilds.config.PluginConfiguration)1 P0001_Fix_freecam_compensation_key_case (net.dzikoysk.funnyguilds.config.migration.P0001_Fix_freecam_compensation_key_case)1 P0002_Migrate_old_heart_configuration (net.dzikoysk.funnyguilds.config.migration.P0002_Migrate_old_heart_configuration)1