Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.thewalkingplay.janaina;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.List;
- import java.util.logging.Filter;
- import java.util.logging.LogRecord;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.PreparedStatement;
- import me.thewalkingplay.janaina.buildMode.BuildActions;
- import me.thewalkingplay.janaina.buildMode.BuildCommand;
- import me.thewalkingplay.janaina.chair.ChairEvent;
- import me.thewalkingplay.janaina.chair.ExitChairEvent;
- import me.thewalkingplay.janaina.chat.ChatEvent;
- import me.thewalkingplay.janaina.chat.MuteCommand;
- import me.thewalkingplay.janaina.chat.MuteManager;
- import me.thewalkingplay.janaina.chat.TextChannel;
- import me.thewalkingplay.janaina.chat.UnmuteCommand;
- import me.thewalkingplay.janaina.chuva.RainHandler;
- import me.thewalkingplay.janaina.classes.Classes;
- import me.thewalkingplay.janaina.classes.EscolherClasse;
- import me.thewalkingplay.janaina.classes.SelecionarClasse;
- import me.thewalkingplay.janaina.classes.skills.Guerreiro;
- import me.thewalkingplay.janaina.classes.skills.Mago;
- import me.thewalkingplay.janaina.leash.leashHolder;
- import me.thewalkingplay.janaina.login.LoginCommands;
- import me.thewalkingplay.janaina.login.LoginEvents;
- import me.thewalkingplay.janaina.mysql.MySQL;
- import me.thewalkingplay.janaina.player.CustomPlayer;
- import me.thewalkingplay.janaina.player.PlayerJoin;
- import me.thewalkingplay.janaina.social.PlayerInteraction;
- import me.thewalkingplay.janaina.spawns.SpawnPoint;
- import me.thewalkingplay.janaina.spawns.SpawnRunnable;
- import me.thewalkingplay.janaina.spawns.Spawns;
- import me.thewalkingplay.janaina.warps.WarpCreator;
- import me.thewalkingplay.janaina.worlds.WorldTeleportCommand;
- public class Main extends JavaPlugin {
- /*
- * MySQL connection configs ans params being
- * @server the address of the server
- * @port the server port (by default it's 3306)
- * @db the database name
- * @user the phpmyadmin user
- * @passql the above user's pass
- */
- String server = "localhost";
- String port = "3306";
- String db = "server";
- String user = "db_server";
- String passsql = "123";
- MySQL sql = new MySQL(server, port, db, user, passsql);
- public Connection c = null;
- Filter f = new Filter() {
- @Override
- public boolean isLoggable(LogRecord record) {
- return !(record.getMessage().contains("/login") || record.getMessage().contains("/changepass"));
- }
- };
- Logger logger = Bukkit.getServer().getLogger();
- @Override
- public void onEnable() {
- for (Player p : Bukkit.getOnlinePlayers()) {
- p.sendMessage(ChatColor.GREEN + "Janaína v1.0 loadada!");
- }
- logger.setFilter(f);
- logger.info("----------------------------------------");
- logger.info("--------------[ LOADING ]---------------");
- logger.info("----------------------------------------");
- logger.info("- Registering events... -");
- /*
- *
- * Register all the events contained in the plugin,
- * the ones with (this) contains main class on the
- * constructor.
- *
- */
- PluginManager pm = Bukkit.getPluginManager();
- pm.registerEvents(new PlayerJoin(this), this);
- pm.registerEvents(new SelecionarClasse(), this);
- pm.registerEvents(new BuildActions(), this);
- pm.registerEvents(new leashHolder(), this);
- pm.registerEvents(new ChatEvent(), this);
- pm.registerEvents(new ChairEvent(), this);
- pm.registerEvents(new ExitChairEvent(), this);
- pm.registerEvents(new PlayerInteraction(), this);
- pm.registerEvents(new LoginEvents(), this);
- pm.registerEvents(new Guerreiro(this), this);
- pm.registerEvents(new Mago(), this);
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- logger.info("- Registering commands... -");
- getCommand("classes").setExecutor(new EscolherClasse());
- getCommand("setspawn").setExecutor(new Spawns());
- getCommand("buildmode").setExecutor(new BuildCommand());
- getCommand("mute").setExecutor(new MuteCommand());
- getCommand("unmute").setExecutor(new UnmuteCommand());
- getCommand("login").setExecutor(new LoginCommands());
- getCommand("changepass").setExecutor(new LoginCommands());
- getCommand("warp").setExecutor(new WarpCreator());
- getCommand("test").setExecutor(new me.thewalkingplay.janaina.batata.TestCommand());
- getCommand("tptw").setExecutor(new WorldTeleportCommand(this));
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- logger.info("- Opening MySQL connection... -");
- logger.info("- -");
- logger.info("- Using: -");
- logger.info("- Host: " + server);
- logger.info("- User: " + user);
- logger.info("- Database: " + db);
- logger.info("- -");
- logger.info("- Connecting... -");
- try {
- c = sql.openConnection();
- } catch (ClassNotFoundException e) {
- logger.info("ERRO: ClassNotFoundException in: " + e.getMessage());
- e.printStackTrace();
- } catch (SQLException e) {
- logger.info("ERRO: SQLException in: " + e.getMessage());
- e.printStackTrace();
- }
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- logger.info("- Registering players... -");
- if (getConfig().getConfigurationSection("players") != null) {
- int players = 0;
- for (String s : getConfig().getConfigurationSection("players").getKeys(false)) {
- // config information gathering
- double money = getConfig().getDouble("players." + s + ".money");
- Classes classe = Classes.getClasse(getConfig().getString("players." + s + ".classe"));
- int forca = getConfig().getInt("players." + s + ".forca");
- int defesa = getConfig().getInt("players." + s + ".defesa");
- int mobilidade = getConfig().getInt("players." + s + ".mobilidade");
- int xp = getConfig().getInt("players." + s + ".xp");
- int lvl = getConfig().getInt("players." + s + ".lvl");
- int skill1 = getConfig().getInt("players." + s + ".skill1");
- int skill2 = getConfig().getInt("players." + s + ".skill2");
- int skill3 = getConfig().getInt("players." + s + ".skill3");
- CustomPlayer cp = new CustomPlayer(s, classe, money, lvl, xp, forca, defesa, mobilidade, skill1, skill2, skill3);
- // databse information gathering
- try {
- PreparedStatement ps = (PreparedStatement) sql.openConnection().prepareStatement("SELECT * FROM users WHERE nick = ?");
- ps.setString(1, s);
- ResultSet res = ps.executeQuery();
- res.next();
- String pass = res.getString("pass");
- cp.setGoodPass(pass);
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- cp.setPassChanged(false);
- CustomPlayer.addCPlayer(cp);
- players++;
- }
- logger.info("- -");
- logger.info("- Found " + players + " players");
- }
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- logger.info("- Registering muted players... -");
- if (getConfig().getStringList("muted") != null) {
- List<String> muted = getConfig().getStringList("muted");
- for(String s : muted) {
- MuteManager.mute(CustomPlayer.getCustomPlayer(s));
- }
- }
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- logger.info("- Registering schedulers... -");
- BukkitScheduler scheduler = getServer().getScheduler();
- scheduler.scheduleSyncRepeatingTask(this, new SpawnRunnable(), 20L, 20L);
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- logger.info("- Registering Text Channels... -");
- if (getConfig().getStringList("txtchannels").size() > 0) {
- List<String> tc = getConfig().getStringList("txtchannels");
- for (String s : tc) {
- TextChannel t = new TextChannel(s);
- TextChannel.addTextChannel(t);
- }
- } else {
- TextChannel t = new TextChannel("all");
- TextChannel.addTextChannel(t);
- logger.info("- Theres no text channels, creating a -");
- logger.info("- new default one named 'all'... -");
- }
- logger.info("- Done! -");
- logger.info("----------------------------------------");
- for (Player p : Bukkit.getOnlinePlayers()) {
- TextChannel.getByName("all").addPlayer(p);
- }
- }
- @SuppressWarnings("deprecation")
- @Override
- public void onDisable() {
- // -----------------------------------------[ SALVAR NA CONFIG ]--------------------------------------------------
- // PLAYERS
- for (CustomPlayer cp : CustomPlayer.getAllCPlayers()) {
- getConfig().set("players." + cp.getName() + ".money", cp.getMoney());
- getConfig().set("players." + cp.getName() + ".classe", cp.getClasse().toString());
- getConfig().set("players." + cp.getName() + ".forca", cp.getForca());
- getConfig().set("players." + cp.getName() + ".defesa", cp.getDefesa());
- getConfig().set("players." + cp.getName() + ".mobilidade", cp.getMobilidade());
- getConfig().set("players." + cp.getName() + ".xp", cp.getXp());
- getConfig().set("players." + cp.getName() + ".lvl", cp.getLevel());
- // update db if user changed pass
- if (cp.changedPass()) {
- try {
- PreparedStatement ps = (PreparedStatement) sql.openConnection().prepareStatement("UPDATE users SET pass = ? WHERE nick = ?");
- ps.setString(1, cp.getGoodPass());
- ps.setString(2, cp.getName());
- ps.execute();
- } catch (SQLException exc) {
- exc.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- // SPAWNPOINTS
- for (SpawnPoint sp : SpawnPoint.getAllSpawns()) {
- getConfig().set("spawns." + sp.getMob().getName() + "." + sp.getLevel() + "", "CONTINUAR AQUI");
- }
- // TEXT CHANNELS
- getConfig().set("txtchannels", "");
- if (TextChannel.getAllTextChannels().size() > 0) {
- getConfig().set("txtchannels", TextChannel.getAllTxtChNames());
- }
- // MUTED PLAYERS
- getConfig().set("muted", "");
- if (MuteManager.getAllMutedPlayers() != null) {
- getConfig().set("muted", MuteManager.getNames());
- }
- // WORLDS WITHOUT RAIN
- RainHandler.saveBlockedWorlds();
- saveConfig();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement