From caa4cd8ecba35c423e8ffd8f3b5349f58fca29df Mon Sep 17 00:00:00 2001 From: joethei Date: Sat, 30 Apr 2016 07:36:43 +0200 Subject: [PATCH] first commit --- .../java/eu/univento/teamvento/TeamVento.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/main/java/eu/univento/teamvento/TeamVento.java diff --git a/src/main/java/eu/univento/teamvento/TeamVento.java b/src/main/java/eu/univento/teamvento/TeamVento.java new file mode 100644 index 0000000..1623f2e --- /dev/null +++ b/src/main/java/eu/univento/teamvento/TeamVento.java @@ -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 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"); + } +} \ No newline at end of file