93 lines
3.3 KiB
Java
93 lines
3.3 KiB
Java
package wtf.beatrice.limbomanager;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.configuration.InvalidConfigurationException;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import wtf.beatrice.limbomanager.commands.Spawn;
|
|
import wtf.beatrice.limbomanager.listeners.*;
|
|
import wtf.beatrice.limbomanager.objects.LocationCheckRunnable;
|
|
import wtf.beatrice.limbomanager.objects.WorldGenerator;
|
|
import wtf.beatrice.limbomanager.utils.FileUtils;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
public class LimboManager extends JavaPlugin {
|
|
|
|
private PluginManager pluginManager;
|
|
private static String schematicsFolderPath;
|
|
private static LimboManager instance;
|
|
|
|
@Override
|
|
public void onEnable()
|
|
{
|
|
instance = this;
|
|
pluginManager = Bukkit.getServer().getPluginManager();
|
|
|
|
// register commands
|
|
getCommand("spawn").setExecutor(new Spawn());
|
|
|
|
// register listeners
|
|
pluginManager.registerEvents(new PlayerChecker(), this);
|
|
pluginManager.registerEvents(new PlayerTeleporter(), this);
|
|
pluginManager.registerEvents(new CommandCanceller(), this);
|
|
pluginManager.registerEvents(new RiskyBlocksHandler(), this);
|
|
pluginManager.registerEvents(new WorldLoadHandler(), this);
|
|
pluginManager.registerEvents(new PlayerChatManager(), this);
|
|
|
|
SuperListener superListener = new SuperListener();
|
|
pluginManager.registerEvents(superListener, this);
|
|
superListener.doStuff();
|
|
|
|
// no need to check if folder exists, it will just skip creation.
|
|
getDataFolder().mkdirs();
|
|
schematicsFolderPath = getDataFolder().getAbsolutePath() + File.separator + "schematics";
|
|
getSchematicsFolder().mkdirs();
|
|
String configPath = getDataFolder().getAbsolutePath() + File.separator + "config.yml";
|
|
File config = new File(configPath);
|
|
FileUtils.copyFileFromSrc(config);
|
|
YamlConfiguration configuration = new YamlConfiguration();
|
|
try {
|
|
configuration.load(config);
|
|
Cache.setConfiguration(configuration);
|
|
} catch (IOException | InvalidConfigurationException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
// cache some config variables
|
|
Cache.islandWalkingRange = configuration.getInt("sizing.allowed-range");
|
|
Cache.islandsDistance = configuration.getInt("sizing.island-distance");
|
|
|
|
// start location check runnable
|
|
Cache.locationCheckRunnable = new LocationCheckRunnable();
|
|
Cache.locationCheckRunnable.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, Cache.locationCheckRunnable, 10L, 5L);
|
|
|
|
// create limbo world
|
|
WorldGenerator worldGenerator = new WorldGenerator();
|
|
worldGenerator.generateWorld();
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onDisable()
|
|
{
|
|
|
|
// cancel running tasks
|
|
|
|
if(Cache.locationCheckRunnable != null && Cache.locationCheckRunnable.task != null)
|
|
{
|
|
Bukkit.getScheduler().cancelTask(Cache.locationCheckRunnable.task.getTaskId());
|
|
}
|
|
}
|
|
|
|
public static LimboManager getInstance()
|
|
{
|
|
return instance;
|
|
}
|
|
|
|
public static File getSchematicsFolder() {
|
|
return new File(schematicsFolderPath);
|
|
}
|
|
} |