Skip to content

Instantly share code, notes, and snippets.

@FerusGrim
Created May 18, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FerusGrim/66b2b93e96e856dd617b to your computer and use it in GitHub Desktop.
Save FerusGrim/66b2b93e96e856dd617b to your computer and use it in GitHub Desktop.
package com.voxelwars.util.proxy;
import com.voxelwars.VoxelWarsMod;
import com.voxelwars.VoxelWarsPlugin;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import java.io.File;
import java.util.Optional;
public final class VoxelWars {
private static VoxelWarsMod singleton;
public static void setSingleton(VoxelWarsMod singleton) {
if (VoxelWars.singleton != null) {
throw new IllegalStateException("Cannot redefine VoxelWarsMod singleton!");
}
VoxelWars.singleton = singleton;
}
public static VoxelWarsMod getSingleton() {
return VoxelWars.singleton;
}
public static VoxelWarsPlugin getPluginContainer() {
return VoxelWars.singleton.getPluginContainer();
}
public static Game getGame() {
return VoxelWars.singleton.getGame();
}
public static Logger getLogger() {
return VoxelWars.singleton.getLogger();
}
public static File getConfigDir() {
return VoxelWars.singleton.getConfigDir();
}
}
package com.voxelwars;
import com.voxelwars.config.Config;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import java.io.File;
public class VoxelWarsMod {
private final VoxelWarsPlugin pluginContainer;
private final Game game;
private final Logger logger;
private final File configDir;
public VoxelWarsMod(VoxelWarsPlugin pluginContainer, Game game, Logger logger, File configDir) {
this.pluginContainer = pluginContainer;
this.game = game;
this.logger = logger;
this.configDir = configDir;
}
public VoxelWarsPlugin getPluginContainer() {
return this.pluginContainer;
}
public Game getGame() {
return this.game;
}
public Logger getLogger() {
return this.logger;
}
public File getConfigDir() {
return this.configDir;
}
}
package com.voxelwars;
import com.google.inject.Inject;
import com.voxelwars.config.ConfigPath;
import com.voxelwars.util.proxy.VoxelWars;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.state.InitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.service.config.ConfigDir;
import java.io.*;
@Plugin(id = "voxelwars", name = "VoxelWars", version = "1.0-SNAPSHOT")
public class VoxelWarsPlugin {
@Inject private Game game;
@Inject private Logger logger;
@Inject @ConfigDir(sharedRoot = false) private File configDir;
@Subscribe public void onInit(InitializationEvent event) {
VoxelWars.setSingleton(new VoxelWarsMod(this, this.game, this.logger, this.configDir));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment