ninja.leaping.configurate.objectmapping.serialize.TypeSerializers Java Examples

The following examples show how to use ninja.leaping.configurate.objectmapping.serialize.TypeSerializers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualChestItemStackSerializer.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
VirtualChestItemStackSerializer(VirtualChestPlugin plugin)
{
    this.plugin = plugin;
    this.serializers = TypeSerializers.getDefaultSerializers().newChild()
            .registerType(TypeToken.of(Text.class), TEXT_SERIALIZER)
            .registerType(ITEM_ENCHANTMENT, ITEM_ENCHANTMENT_SERIALIZER)
            .registerType(TypeToken.of(GameProfile.class), GAME_PROFILE_SERIALIZER);
}
 
Example #2
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setSerializers(
                        TypeSerializers.getDefaultSerializers().newChild().registerType(TypeToken.of(IpSet.class), new IpSet.IpSetSerializer()))
                .setHeader(GriefPreventionPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #3
Source File: VotifierModule.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public void onInit(GameInitializationEvent event) {
    if (!Sponge.getPluginManager().getPlugin("nuvotifier").isPresent()) {
        return;
    }
    Sponge.getEventManager().registerListeners(UltimateCore.get(), new VotifierListener());
    UltimateCore.get().getTickService().addRunnable("votifier", new VotifierTickRunnable());

    //Config
    TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Vote.class), new VoteSerializer());
    this.config = new RawModuleConfig("votifier");

    onReload(null);
}
 
Example #4
Source File: BloodModule.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public void onInit(GameInitializationEvent event) {
    //Config
    TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(BloodEffect.class), new BloodEffect.BloodEffectSerializer());
    config = new RawModuleConfig("blood");
    //Check if all entity types are in the config
    CommentedConfigurationNode node = config.get();
    boolean modified = false;
    //For every entitytype, if it doesnt exist in the config add it
    for (EntityType type : Sponge.getRegistry().getAllOf(CatalogTypes.ENTITY_TYPE)) {
        if (!Living.class.isAssignableFrom(type.getEntityClass())) {
            continue;
        }
        //If entitytype is not in config
        if (node.getNode("types", type.getId(), "enabled").getValue() == null) {
            modified = true;
            CommentedConfigurationNode typenode = node.getNode("types", type.getId());
            try {
                typenode.setValue(TypeToken.of(BloodEffect.class), BloodEffects.DEFAULT);
            } catch (ObjectMappingException e) {
                ErrorLogger.log(e, "Failed to set default blood effect.");
            }
        }
    }
    if (modified) {
        config.save(node);
    }
    //Load blood effects from config
    BloodEffects.reload();
    //Listeners
    Sponge.getEventManager().registerListeners(UltimateCore.get(), new BloodListener());
}
 
Example #5
Source File: AutomessageModule.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public void onInit(GameInitializationEvent event) {
    //Config
    TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Automessage.class), new AutomessageSerializer());
    config = new RawModuleConfig("automessage");
    //Runnables
    try {
        for (Automessage message : config.get().getNode("automessages").getList(TypeToken.of(Automessage.class))) {
            message.start();
        }
    } catch (ObjectMappingException e) {
        ErrorLogger.log(e, "Failed to load automessages from config.");
    }
}
 
Example #6
Source File: EagleFactionsPlugin.java    From EagleFactions with MIT License 4 votes vote down vote up
private void registerTypeSerializers()
{
    TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(Claim.class), new ClaimTypeSerializer());
    TypeSerializers.getDefaultSerializers().registerType(new TypeToken<Set<Claim>>(){}, new ClaimSetTypeSerializer());
}
 
Example #7
Source File: WebBooksServlet.java    From Web-API with MIT License 4 votes vote down vote up
public static void onRegister() {
    TypeSerializers.getDefaultSerializers().registerType(
            TypeToken.of(WebBook.class), new WebBookConfigSerializer());
}
 
Example #8
Source File: WebAPI.java    From Web-API with MIT License 4 votes vote down vote up
@Listener
public void onPreInitialization(GamePreInitializationEvent event) {
    WebAPI.instance = this;

    Timings.STARTUP.startTiming();

    Platform platform = Sponge.getPlatform();
    spongeApi = platform.getContainer(Component.API).getVersion().orElse(null);
    spongeGame = platform.getContainer(Component.GAME).getVersion().orElse(null);
    spongeImpl = platform.getContainer(Component.IMPLEMENTATION).getVersion().orElse(null);
    pluginList = Sponge.getPluginManager().getPlugins().stream()
            .map(p -> p.getId() + ": " + p.getVersion().orElse(null))
            .collect(Collectors.joining("; \n"));

    // Create our config directory if it doesn't exist
    if (!Files.exists(configPath)) {
        try {
            Files.createDirectories(configPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Reusable sync executor to run code on main server thread
    syncExecutor = Sponge.getScheduler().createSyncExecutor(this);
    asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this);

    // Register custom serializers
    TypeSerializers.getDefaultSerializers().registerType(
            TypeToken.of(WebHook.class), new WebHookSerializer());
    TypeSerializers.getDefaultSerializers().registerType(
            TypeToken.of(UserPermissionStruct.class), new UserPermissionStructSerializer());
    TypeSerializers.getDefaultSerializers().registerType(
            TypeToken.of(PermissionStruct.class), new PermissionStructSerializer());

    // Setup services
    this.blockService = new BlockService();
    this.cacheService = new CacheService();
    this.linkService = new LinkService();
    this.messageService = new InteractiveMessageService();
    this.securityService = new SecurityService();
    this.serializeService = new SerializeService();
    this.serverService = new ServerService();
    this.servletService = new ServletService();
    this.webHookService = new WebHookService();
    this.userService = new UserService();

    // Register services
    ServiceManager serviceMan = Sponge.getServiceManager();
    serviceMan.setProvider(this, BlockService.class, blockService);
    serviceMan.setProvider(this, CacheService.class, cacheService);
    serviceMan.setProvider(this, LinkService.class, linkService);
    serviceMan.setProvider(this, InteractiveMessageService.class, messageService);
    serviceMan.setProvider(this, SecurityService.class, securityService);
    serviceMan.setProvider(this, SerializeService.class, serializeService);
    serviceMan.setProvider(this, ServerService.class, serverService);
    serviceMan.setProvider(this, ServletService.class, servletService);
    serviceMan.setProvider(this, WebHookService.class, webHookService);
    serviceMan.setProvider(this, UserService.class, userService);

    // Register events of services
    EventManager evenMan = Sponge.getEventManager();
    evenMan.registerListeners(this, cacheService);
    evenMan.registerListeners(this, linkService);
    evenMan.registerListeners(this, webHookService);

    // Swagger setup stuff
    ModelConverters.getInstance().addConverter(new SwaggerModelConverter());

    Timings.STARTUP.stopTiming();
}