package de.steev.bm; import de.steev.bm.Commands.back; import de.steev.bm.Listener.BedListener; import de.steev.bm.Listener.InteractListener; import de.steev.bm.Listener.KillListener; import de.steev.bm.Manager.GameManager; import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.io.IOException; import java.util.UUID; public class BetterMinecraft extends JavaPlugin implements Listener { // Global Variables that might come helpfull later public int playerInBed = 0; public World world; String version = "1.2"; // Custom Playerdata File private File playerdata; private FileConfiguration playerDataConfig; private final String playerdatafilename = "playerdata.yml"; private static String prefix = ChatColor.GRAY + "[" + ChatColor.AQUA + "BetterMinecraft" + ChatColor.GRAY + "]"; private GameManager gameManager; // Handles initialisation public void onEnable() { // Messaging this.getLogger().info(prefix + ChatColor.WHITE + "Plugin Startet"); this.getLogger().info(prefix + ChatColor.WHITE + "Initializing Gamemanager"); gameManager = new GameManager(this); this.saveDefaultConfig(); // Registers Events this.getLogger().info(prefix + ChatColor.WHITE + "Lade Events"); this.getServer().getPluginManager().registerEvents(new BedListener(this.gameManager), this); this.getServer().getPluginManager().registerEvents(new KillListener(this.gameManager), this); this.getServer().getPluginManager().registerEvents(new InteractListener(this.gameManager), this); this.getServer().getPluginManager().registerEvents(this, this); this.getCommand("back").setExecutor(new back(this.gameManager)); // PlayerData playerdata = new File(this.getDataFolder(), playerdatafilename); playerDataConfig = YamlConfiguration.loadConfiguration(playerdata); saveplayerdata(); // More Messaging this.getLogger().info(ChatColor.AQUA + "Ich bin Fertig :D"); } @EventHandler void onPlayerJoin(PlayerJoinEvent e) { Player p = (Player) e.getPlayer(); UUID uuid = p.getUniqueId(); // prevent this allways resetting the job count if (this.playerDataConfig.get(uuid + "." + version + ".read") == null) { p.sendMessage("================= Better Minecraft " + version + " ================="); p.sendMessage("Command: /back eingefügt"); p.sendMessage("====================================================="); this.playerDataConfig.set(uuid + ".name", p.getName()); this.playerDataConfig.set(uuid + "." + version + ".read", "true"); saveplayerdata(); } } void saveplayerdata() { try { playerDataConfig.save(playerdata); } catch (IOException e) { this.getLogger().warning("Unable to save " + playerdatafilename); // shouldn't really happen, but save // throws the exception } } public FileConfiguration getPlayerDataConfig(){ return this.playerDataConfig; } public static String LoggerPrefix(){ return prefix; } public void onDisable() { // Even more Messaging this.getLogger().info(ChatColor.AQUA + "Ich geh dann mal :c"); } }