TeamVento/src/main/java/eu/univento/teamvento/TeamVento.java

102 lines
3.9 KiB
Java

package eu.univento.teamvento;
import eu.univento.core.Core;
import eu.univento.core.api.Config;
import eu.univento.core.api.server.ServerSettings;
import eu.univento.teamvento.commands.*;
import eu.univento.teamvento.listener.*;
import eu.univento.teamvento.utils.PlotManager;
import eu.univento.teamvento.utils.VoidGenerator;
import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
/**
* @author joethei
* @version 0.1
*/
public class TeamVento extends JavaPlugin {
private static final File file = new File("plugins/Core", "worlds.yml");
private static final FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
public static File getConfigFile() {
return file;
}
public static FileConfiguration getCfg() {
return cfg;
}
private static TeamVento instance;
public static TeamVento getInstance() {
return instance;
}
@Override
public void onEnable() {
Core.getInstance().registerPlugin(this);
instance = this;
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new JoinQuit(), this);
pm.registerEvents(new Events(), this);
pm.registerEvents(new PositionSetter(), this);
pm.registerEvents(new SignInteract(), this);
pm.registerEvents(new MenuEvents(), this);
new Setloc(this, "setloc", "sets locations");
new WorldTP(this, "worldteleport", "teleports players to other worlds", "wtp");
new WorldCreate(this, "worldcreate", "creates new worlds", "wc");
new WorldImport(this, "worldimport", "imports worlds", "wi");
new Set(this, "set", "sets the material of selected blocks");
new Sel(this, "sel", "removes block selection");
new WorldList(this, "worldlist", "lists all worlds", "wl");
new PlotInfo(this, "plotinfo", "info about a plot", "pi");
new Pack(this, "pack", "sets resource pack");
for(String world : getCfg().getKeys(true)) {
String generator = getCfg().getString(world);
WorldCreator creator = new WorldCreator(world);
creator.generateStructures(false);
if(generator.equals("normal")) {
creator.environment(World.Environment.NORMAL);
creator.type(WorldType.NORMAL);
}
if(generator.equals("flat")) {
creator.environment(World.Environment.NORMAL);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
}
if(generator.equals("void")) {
creator.generator(new VoidGenerator());
creator.type(WorldType.CUSTOMIZED);
creator.generateStructures(false);
}
Bukkit.createWorld(creator);
World loadedWorld = Bukkit.getWorld(world);
loadedWorld.setDifficulty(Difficulty.PEACEFUL);
loadedWorld.setPVP(false);
loadedWorld.setAnimalSpawnLimit(0);
}
ServerSettings.setGameMode(GameMode.CREATIVE);
ServerSettings.setBuild(false);
PlotManager.update();
PlotManager.setLastPlot(PlotManager.getPlotByOwner(Config.readString("lastPlot")));
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> Bukkit.getWorlds().stream().filter(world -> world.getTime() > 7698).forEach(world -> world.setTime(0)), 100 * 20L, 20L);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> Events.redstone = 0, 1L, 10 * 20L);
}
@Override
public void onDisable() {
Config.write(PlotManager.getLastPlot().getOwner().toString());
Bukkit.getWorld("plots").getLivingEntities().forEach(Entity::remove);
Core.getInstance().unregisterPlugin(this);
}
}