98 lines
3.3 KiB
Java
98 lines
3.3 KiB
Java
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.Listener.PrepareAnvilListener;
|
|
import de.steev.bm.Manager.GameManager;
|
|
import de.steev.bm.utils.Config;
|
|
import de.steev.bm.utils.exceptions.ConfigEntryExceptions;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.World;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
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.IOException;
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
import static de.steev.bm.utils.Constants.*;
|
|
|
|
public class BetterMinecraft extends JavaPlugin implements Listener {
|
|
|
|
// Global Variables that might come helpfull later
|
|
public int playerInBed = 0;
|
|
public World world;
|
|
|
|
// Custom Playerdata File
|
|
private Config playerData = new Config(playerDataFilename, this);
|
|
private GameManager gameManager;
|
|
|
|
// Handles initialisation
|
|
public void onEnable() {
|
|
// Messaging
|
|
this.getLogger().info(prefix + ChatColor.WHITE + "Plugin Startup");
|
|
this.getLogger().info(prefix + ChatColor.WHITE + "Initializing Gamemanager");
|
|
gameManager = new GameManager(this);
|
|
this.saveDefaultConfig();
|
|
|
|
// Registers Events
|
|
this.getLogger().info(prefix + ChatColor.WHITE + "Load 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(new PrepareAnvilListener(this.gameManager), this);
|
|
this.getServer().getPluginManager().registerEvents(this, this);
|
|
Objects.requireNonNull(this.getCommand("back")).setExecutor(new back(this.gameManager));
|
|
|
|
// PlayerData
|
|
try {
|
|
this.playerData.saveConfig(playerDataFilename);
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
// More Messaging
|
|
this.getLogger().info(ChatColor.AQUA + "Startup complete :D");
|
|
}
|
|
|
|
@EventHandler
|
|
void onPlayerJoin(PlayerJoinEvent e) {
|
|
Player p = (Player) e.getPlayer();
|
|
UUID uuid = p.getUniqueId();
|
|
|
|
try {
|
|
if (this.playerData.readBooleanFromConfig(uuid + "." + Version + ".read")) {
|
|
p.sendMessage("================= Better Minecraft " + Version + " =================");
|
|
p.sendMessage("Amboss Kostengrenze entfernt");
|
|
p.sendMessage("=====================================================");
|
|
|
|
this.playerData.writeStringToConfig(uuid + ".name", p.getName());
|
|
this.playerData.writeStringToConfig(uuid + "." + Version + ".read", "true");
|
|
this.playerData.saveConfig(playerDataFilename);
|
|
}
|
|
} catch (ConfigEntryExceptions cee) {
|
|
this.getLogger().warning("reading config failed with error: " + cee.getMessage());
|
|
} catch (IOException ioe) {
|
|
throw new RuntimeException(ioe);
|
|
}
|
|
}
|
|
|
|
public static String LoggerPrefix(){
|
|
return prefix;
|
|
}
|
|
|
|
public void onDisable() {
|
|
// Even more Messaging
|
|
this.getLogger().info(ChatColor.AQUA + "Ich geh dann mal :c");
|
|
}
|
|
|
|
public FileConfiguration getPlayerDataConfig() {
|
|
return this.playerData.getConfig();
|
|
}
|
|
} |