first commit

This commit is contained in:
Johannes Theiner 2016-04-30 07:36:43 +02:00
commit caa4cd8ecb
1 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,93 @@
package eu.univento.teamvento;
import eu.univento.core.api.server.ServerSettings;
import eu.univento.teamvento.commands.*;
import eu.univento.teamvento.listener.Events;
import eu.univento.teamvento.listener.JoinQuit;
import eu.univento.teamvento.listener.PositionSetter;
import eu.univento.teamvento.utils.PlotManager;
import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
/**
* @author joethei
* @version 0.1
*/
public class TeamVento extends JavaPlugin {
private static File file = new File("plugins/Core", "worlds.yml");
private static 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;
}
private static Logger logger = Bukkit.getLogger();
private static void log(Level level, String string) {
logger.log(level, "[" + getInstance().getDescription().getName() + "] " + string);
}
@Override
public void onEnable() {
instance = this;
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new JoinQuit(), this);
pm.registerEvents(new Events(), this);
pm.registerEvents(new PositionSetter(), this);
new Setloc(this, "setloc" , "sets locations");
new Prebuild(this, "prebuild", "sets players to prebuild mode");
new WorldTP(this, "worldtp", "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 WorldList(this, "worldlist", "lists all worlds", "wl");
for(String world : cfg.getStringList("worlds")) {
Bukkit.createWorld(new WorldCreator(world));
World loadedWorld = Bukkit.getWorld(world);
loadedWorld.setDifficulty(Difficulty.PEACEFUL);
loadedWorld.setPVP(false);
}
ServerSettings.setGameMode(GameMode.CREATIVE);
PlotManager.update();
log(Level.INFO, "Plugin ver." + getDescription().getVersion() + " gestartet");
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> Bukkit.getWorlds().stream().filter(world -> world.getTime() > 7698).forEach(world -> world.setTime(0)), 100 * 20L, 20L);
}
@Override
public void onDisable() {
ArrayList<String> worlds = Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toCollection(ArrayList::new));
cfg.set("worlds", worlds);
try {
cfg.save(file);
} catch (IOException e) {
e.printStackTrace();
}
log(Level.INFO, "Plugin beendet");
}
}