Search in sources :

Example 1 with MySQLDatabase

use of pl.plajer.villagedefense3.database.MySQLDatabase in project Village_Defense by Plajer.

the class Main method onEnable.

@Override
public void onEnable() {
    version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
    new ConfigurationManager(this);
    LanguageManager.init(this);
    if (!(getVersion().equalsIgnoreCase("v1_8_R3") || getVersion().equalsIgnoreCase("v1_9_R1") || getVersion().equalsIgnoreCase("v1_11_R1") || getVersion().equalsIgnoreCase("v1_12_R1"))) {
        BigTextUtils.thisVersionIsNotSupported();
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Your server version is not supported by Village Defense!");
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Sadly, we must shut off. Maybe you consider changing your server version?");
        forceDisable = true;
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    try {
        Class.forName("org.spigotmc.SpigotConfig");
    } catch (Exception e) {
        BigTextUtils.thisVersionIsNotSupported();
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Your server software is not supported by Village Defense!");
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "We support only Spigot and Spigot forks only! Shutting off...");
        forceDisable = true;
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    // check if using releases before 2.1.0
    if (LanguageManager.getLanguageFile().isSet("STATS-AboveLine") && LanguageManager.getLanguageFile().isSet("SCOREBOARD-Zombies")) {
        migrateToNewFormat();
    }
    // check if using releases 2.1.0+
    if (LanguageManager.getLanguageFile().isSet("File-Version") && getConfig().isSet("Config-Version")) {
        migrateToNewFormat();
    }
    LanguageManager.saveDefaultLanguageFile();
    saveDefaultConfig();
    debug = getConfig().getBoolean("Debug");
    if (Main.isDebugged()) {
        System.out.println("[Village Debugger] Village Defense setup started!");
    }
    setupFiles();
    debugChecker();
    LanguageMigrator.languageFileUpdate();
    setupLocale();
    initializeClasses();
    String currentVersion = "v" + Bukkit.getPluginManager().getPlugin("VillageDefense").getDescription().getVersion();
    if (getConfig().getBoolean("Update-Notifier.Enabled")) {
        try {
            UpdateChecker.checkUpdate(currentVersion);
            String latestVersion = UpdateChecker.getLatestVersion();
            if (latestVersion != null) {
                latestVersion = "v" + latestVersion;
                if (latestVersion.contains("b")) {
                    Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[VillageDefense] Your software is ready for update! However it's a BETA VERSION. Proceed with caution.");
                    Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[VillageDefense] Current version %old%, latest version %new%".replaceAll("%old%", currentVersion).replaceAll("%new%", latestVersion));
                } else {
                    BigTextUtils.updateIsHere();
                    Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Your Village Defense plugin is up to date! Download it to keep with latest changes and fixes.");
                    Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Disable this option in config.yml if you wish.");
                    Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "Current version: " + ChatColor.RED + currentVersion + ChatColor.YELLOW + " Latest version: " + ChatColor.GREEN + latestVersion);
                }
            }
        } catch (Exception ex) {
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[VillageDefense] An error occured while checking for update!");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Please check internet connection or check for update via WWW site directly!");
            Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "WWW site https://www.spigotmc.org/resources/minigame-village-defence-1-12-and-1-8-8.41869/");
        }
    }
    STARTING_TIMER_TIME = getConfig().getInt("Starting-Waiting-Time");
    MINI_ZOMBIE_SPEED = (float) getConfig().getDouble("Mini-Zombie-Speed");
    ZOMBIE_SPEED = (float) getConfig().getDouble("Zombie-Speed");
    databaseActivated = getConfig().getBoolean("DatabaseActivated");
    inventoryManagerEnabled = getConfig().getBoolean("InventoryManager");
    if (databaseActivated) {
        database = new MySQLDatabase(this);
    } else {
        fileStats = new FileStats(this);
    }
    bossbarEnabled = getConfig().getBoolean("Bossbar-Enabled");
    if (is1_8_R3()) {
        bossbarEnabled = false;
    }
    getServer().getPluginManager().registerEvents(this, this);
    BreakFenceListener listener = new BreakFenceListener();
    listener.runTaskTimer(this, 1L, 20L);
    setupGameKits();
    SpecialItem.loadAll();
    registerArenas();
    new ShopManager();
    // we must start it after instances load!
    signManager = new SignManager(this);
    chatFormat = getConfig().getBoolean("ChatFormat-Enabled");
    ConfigurationSection cs = getConfig().getConfigurationSection("CustomPermissions");
    for (String key : cs.getKeys(false)) {
        customPermissions.put(key, getConfig().getInt("CustomPermissions." + key));
        if (isDebugged()) {
            System.out.println("[Village Debugger] Loaded custom permission " + key + "!");
        }
    }
    for (Player p : Bukkit.getOnlinePlayers()) {
        UserManager.registerUser(p.getUniqueId());
    }
    if (databaseActivated) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            MySQLConnectionUtils.loadPlayerStats(p, this);
        }
    } else {
        fileStats.loadStatsForPlayersOnline();
    }
    StatsStorage.plugin = this;
    setupPermissions();
}
Also used : SignManager(pl.plajer.villagedefense3.handlers.SignManager) Player(org.bukkit.entity.Player) BreakFenceListener(pl.plajer.villagedefense3.creatures.BreakFenceListener) FileStats(pl.plajer.villagedefense3.database.FileStats) MySQLDatabase(pl.plajer.villagedefense3.database.MySQLDatabase) ShopManager(pl.plajer.villagedefense3.handlers.ShopManager) ConfigurationManager(pl.plajer.villagedefense3.handlers.ConfigurationManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with MySQLDatabase

use of pl.plajer.villagedefense3.database.MySQLDatabase in project Village_Defense by Plajer.

the class MySQLConnectionUtils method loadPlayerStats.

public static void loadPlayerStats(Player player, Main plugin) {
    boolean b = false;
    MySQLDatabase database = plugin.getMySQLDatabase();
    ResultSet resultSet = database.executeQuery("SELECT UUID from playerstats WHERE UUID='" + player.getUniqueId().toString() + "'");
    try {
        if (!resultSet.next()) {
            database.insertPlayer(player.getUniqueId().toString());
            b = true;
        }
        int gamesplayed;
        int zombiekills;
        int highestwave;
        int deaths;
        int xp;
        int level;
        int orbs;
        gamesplayed = database.getStat(player.getUniqueId().toString(), "gamesplayed");
        zombiekills = database.getStat(player.getUniqueId().toString(), "kills");
        highestwave = database.getStat(player.getUniqueId().toString(), "highestwave");
        deaths = database.getStat(player.getUniqueId().toString(), "deaths");
        xp = database.getStat(player.getUniqueId().toString(), "xp");
        level = database.getStat(player.getUniqueId().toString(), "level");
        orbs = database.getStat(player.getUniqueId().toString(), "orbs");
        User user = UserManager.getUser(player.getUniqueId());
        user.setInt("gamesplayed", gamesplayed);
        user.setInt("kills", zombiekills);
        user.setInt("highestwave", highestwave);
        user.setInt("deaths", deaths);
        user.setInt("xp", xp);
        user.setInt("level", level);
        user.setInt("orbs", orbs);
        b = true;
    } catch (SQLException e1) {
        System.out.print("CONNECTION FAILED FOR PLAYER " + player.getName());
        e1.printStackTrace();
        BigTextUtils.errorOccured();
        Bukkit.getConsoleSender().sendMessage("Cannot save contents to MySQL database!");
        Bukkit.getConsoleSender().sendMessage("Check configuration of mysql.yml file or disable mysql option in config.yml");
    }
    if (!b) {
        try {
            if (!resultSet.next()) {
                database.insertPlayer(player.getUniqueId().toString());
            }
            int gamesplayed;
            int zombiekills;
            int highestwave;
            int deaths;
            int xp;
            int level;
            int orbs;
            gamesplayed = database.getStat(player.getUniqueId().toString(), "gamesplayed");
            zombiekills = database.getStat(player.getUniqueId().toString(), "kills");
            highestwave = database.getStat(player.getUniqueId().toString(), "highestwave");
            deaths = database.getStat(player.getUniqueId().toString(), "deaths");
            xp = database.getStat(player.getUniqueId().toString(), "xp");
            level = database.getStat(player.getUniqueId().toString(), "level");
            orbs = database.getStat(player.getUniqueId().toString(), "orbs");
            User user = UserManager.getUser(player.getUniqueId());
            user.setInt("gamesplayed", gamesplayed);
            user.setInt("kills", zombiekills);
            user.setInt("highestwave", highestwave);
            user.setInt("deaths", deaths);
            user.setInt("xp", xp);
            user.setInt("level", level);
            user.setInt("orbs", orbs);
        } catch (SQLException e1) {
            System.out.print("CONNECTION FAILED TWICE FOR PLAYER " + player.getName());
            e1.printStackTrace();
            BigTextUtils.errorOccured();
            Bukkit.getConsoleSender().sendMessage("Cannot save contents to MySQL database!");
            Bukkit.getConsoleSender().sendMessage("Check configuration of mysql.yml file or disable mysql option in config.yml");
        }
    }
}
Also used : User(pl.plajer.villagedefense3.User) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) MySQLDatabase(pl.plajer.villagedefense3.database.MySQLDatabase)

Aggregations

MySQLDatabase (pl.plajer.villagedefense3.database.MySQLDatabase)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 Player (org.bukkit.entity.Player)1 User (pl.plajer.villagedefense3.User)1 BreakFenceListener (pl.plajer.villagedefense3.creatures.BreakFenceListener)1 FileStats (pl.plajer.villagedefense3.database.FileStats)1 ConfigurationManager (pl.plajer.villagedefense3.handlers.ConfigurationManager)1 ShopManager (pl.plajer.villagedefense3.handlers.ShopManager)1 SignManager (pl.plajer.villagedefense3.handlers.SignManager)1