Skip to content

Instantly share code, notes, and snippets.

@kinggoesgaming
Created March 28, 2016 00:59
Show Gist options
  • Save kinggoesgaming/7a4a47cd8dfef2c7a979 to your computer and use it in GitHub Desktop.
Save kinggoesgaming/7a4a47cd8dfef2c7a979 to your computer and use it in GitHub Desktop.
/*
* This file is part of FoundationsCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2016 - 2016 Hunar Roop (KingGoesGaming) Kahlon <http://www.kinggoesgaming.com>
* Copyright (c) Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.kinggoesgaming.foundations.core;
import com.google.inject.Inject;
import com.kinggoesgaming.foundations.api.services.ConfigurationService;
import com.kinggoesgaming.foundations.core.configs.GlobalConfig;
import com.kinggoesgaming.foundations.core.services.FoundationsConfigurationService;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.gson.GsonConfigurationLoader;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingEvent;
import org.spongepowered.api.plugin.Plugin;
import java.io.IOException;
/**
* The main class of the {@link FoundationsCore} plugin.
*/
@Plugin(
id = "com.kinggoesgaming.foundations.core"
)
public class FoundationsCore {
@Inject
private Logger logger;
private static String id = "com.kinggoesgaming.foundations.core";
private static ConfigurationNode headers;
private static ConfigurationNode targets;
public static String getId() {
return id;
}
public static ConfigurationNode getHeaders() {
return headers;
}
public static ConfigurationNode getTargets() {
return targets;
}
@Listener
public void onPreInitialization(GamePreInitializationEvent event) {
getLogger().info("Starting Foundations Core");
getLogger().info("Providing Services");
Sponge.getServiceManager().setProvider(this, ConfigurationService.class, new FoundationsConfigurationService());
try {
headers = GsonConfigurationLoader.builder().setURL(Sponge.getPluginManager().getPlugin(id).get().getAsset("util/headers.json").get().getUrl()).build().load();
targets = GsonConfigurationLoader.builder().setURL(Sponge.getPluginManager().getPlugin(id).get().getAsset("util/targets.json").get().getUrl()).build().load();
} catch (IOException e) {
e.printStackTrace();
}
}
@Listener
public void onInitialization(GameInitializationEvent event) {
Sponge.getServiceManager().provide(ConfigurationService.class).get().register(id, "global", new GlobalConfig());
try {
Sponge.getServiceManager().provide(ConfigurationService.class)
.get()
.get(id, "global")
.get()
.load();
getLogger().info(Sponge.getServiceManager().provide(ConfigurationService.class).get().get(id, "global").get().get().getNode("config", "save").getString());
} catch (IOException e) {
e.printStackTrace();
}
}
@Listener
public void onPostInitialization(GamePostInitializationEvent event) {
}
@Listener
public void onStopping(GameStoppingEvent event) {
}
public Logger getLogger() {
return logger;
}
public FoundationsCore getFoundationsCore() {
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment