Advertisement
Guest User

Untitled

a guest
Jan 5th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.77 KB | None | 0 0
  1. package me.thewalkingplay.janaina;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.List;
  6. import java.util.logging.Filter;
  7. import java.util.logging.LogRecord;
  8. import java.util.logging.Logger;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.plugin.PluginManager;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import org.bukkit.scheduler.BukkitScheduler;
  16.  
  17. import com.mysql.jdbc.Connection;
  18. import com.mysql.jdbc.PreparedStatement;
  19.  
  20. import me.thewalkingplay.janaina.buildMode.BuildActions;
  21. import me.thewalkingplay.janaina.buildMode.BuildCommand;
  22. import me.thewalkingplay.janaina.chair.ChairEvent;
  23. import me.thewalkingplay.janaina.chair.ExitChairEvent;
  24. import me.thewalkingplay.janaina.chat.ChatEvent;
  25. import me.thewalkingplay.janaina.chat.MuteCommand;
  26. import me.thewalkingplay.janaina.chat.MuteManager;
  27. import me.thewalkingplay.janaina.chat.TextChannel;
  28. import me.thewalkingplay.janaina.chat.UnmuteCommand;
  29. import me.thewalkingplay.janaina.chuva.RainHandler;
  30. import me.thewalkingplay.janaina.classes.Classes;
  31. import me.thewalkingplay.janaina.classes.EscolherClasse;
  32. import me.thewalkingplay.janaina.classes.SelecionarClasse;
  33. import me.thewalkingplay.janaina.classes.skills.Guerreiro;
  34. import me.thewalkingplay.janaina.classes.skills.Mago;
  35. import me.thewalkingplay.janaina.leash.leashHolder;
  36. import me.thewalkingplay.janaina.login.LoginCommands;
  37. import me.thewalkingplay.janaina.login.LoginEvents;
  38. import me.thewalkingplay.janaina.mysql.MySQL;
  39. import me.thewalkingplay.janaina.player.CustomPlayer;
  40. import me.thewalkingplay.janaina.player.PlayerJoin;
  41. import me.thewalkingplay.janaina.social.PlayerInteraction;
  42. import me.thewalkingplay.janaina.spawns.SpawnPoint;
  43. import me.thewalkingplay.janaina.spawns.SpawnRunnable;
  44. import me.thewalkingplay.janaina.spawns.Spawns;
  45. import me.thewalkingplay.janaina.warps.WarpCreator;
  46. import me.thewalkingplay.janaina.worlds.WorldTeleportCommand;
  47.  
  48. public class Main extends JavaPlugin {
  49.  
  50. /*
  51. * MySQL connection configs ans params being
  52. * @server the address of the server
  53. * @port the server port (by default it's 3306)
  54. * @db the database name
  55. * @user the phpmyadmin user
  56. * @passql the above user's pass
  57. */
  58.  
  59. String server = "localhost";
  60. String port = "3306";
  61. String db = "server";
  62. String user = "db_server";
  63. String passsql = "123";
  64. MySQL sql = new MySQL(server, port, db, user, passsql);
  65. public Connection c = null;
  66.  
  67. Filter f = new Filter() {
  68.  
  69. @Override
  70. public boolean isLoggable(LogRecord record) {
  71. return !(record.getMessage().contains("/login") || record.getMessage().contains("/changepass"));
  72. }
  73. };
  74.  
  75. Logger logger = Bukkit.getServer().getLogger();
  76.  
  77. @Override
  78. public void onEnable() {
  79. for (Player p : Bukkit.getOnlinePlayers()) {
  80. p.sendMessage(ChatColor.GREEN + "Janaína v1.0 loadada!");
  81. }
  82.  
  83. logger.setFilter(f);
  84.  
  85. logger.info("----------------------------------------");
  86. logger.info("--------------[ LOADING ]---------------");
  87. logger.info("----------------------------------------");
  88. logger.info("- Registering events... -");
  89.  
  90. /*
  91. *
  92. * Register all the events contained in the plugin,
  93. * the ones with (this) contains main class on the
  94. * constructor.
  95. *
  96. */
  97.  
  98. PluginManager pm = Bukkit.getPluginManager();
  99. pm.registerEvents(new PlayerJoin(this), this);
  100. pm.registerEvents(new SelecionarClasse(), this);
  101. pm.registerEvents(new BuildActions(), this);
  102. pm.registerEvents(new leashHolder(), this);
  103. pm.registerEvents(new ChatEvent(), this);
  104. pm.registerEvents(new ChairEvent(), this);
  105. pm.registerEvents(new ExitChairEvent(), this);
  106. pm.registerEvents(new PlayerInteraction(), this);
  107. pm.registerEvents(new LoginEvents(), this);
  108.  
  109. pm.registerEvents(new Guerreiro(this), this);
  110. pm.registerEvents(new Mago(), this);
  111.  
  112. logger.info("- Done! -");
  113. logger.info("----------------------------------------");
  114. logger.info("- Registering commands... -");
  115.  
  116. getCommand("classes").setExecutor(new EscolherClasse());
  117. getCommand("setspawn").setExecutor(new Spawns());
  118. getCommand("buildmode").setExecutor(new BuildCommand());
  119. getCommand("mute").setExecutor(new MuteCommand());
  120. getCommand("unmute").setExecutor(new UnmuteCommand());
  121. getCommand("login").setExecutor(new LoginCommands());
  122. getCommand("changepass").setExecutor(new LoginCommands());
  123. getCommand("warp").setExecutor(new WarpCreator());
  124. getCommand("test").setExecutor(new me.thewalkingplay.janaina.batata.TestCommand());
  125. getCommand("tptw").setExecutor(new WorldTeleportCommand(this));
  126.  
  127. logger.info("- Done! -");
  128. logger.info("----------------------------------------");
  129. logger.info("- Opening MySQL connection... -");
  130. logger.info("- -");
  131. logger.info("- Using: -");
  132. logger.info("- Host: " + server);
  133. logger.info("- User: " + user);
  134. logger.info("- Database: " + db);
  135. logger.info("- -");
  136. logger.info("- Connecting... -");
  137.  
  138. try {
  139. c = sql.openConnection();
  140. } catch (ClassNotFoundException e) {
  141. logger.info("ERRO: ClassNotFoundException in: " + e.getMessage());
  142. e.printStackTrace();
  143. } catch (SQLException e) {
  144. logger.info("ERRO: SQLException in: " + e.getMessage());
  145. e.printStackTrace();
  146. }
  147.  
  148. logger.info("- Done! -");
  149. logger.info("----------------------------------------");
  150. logger.info("- Registering players... -");
  151.  
  152. if (getConfig().getConfigurationSection("players") != null) {
  153. int players = 0;
  154. for (String s : getConfig().getConfigurationSection("players").getKeys(false)) {
  155.  
  156. // config information gathering
  157. double money = getConfig().getDouble("players." + s + ".money");
  158. Classes classe = Classes.getClasse(getConfig().getString("players." + s + ".classe"));
  159. int forca = getConfig().getInt("players." + s + ".forca");
  160. int defesa = getConfig().getInt("players." + s + ".defesa");
  161. int mobilidade = getConfig().getInt("players." + s + ".mobilidade");
  162. int xp = getConfig().getInt("players." + s + ".xp");
  163. int lvl = getConfig().getInt("players." + s + ".lvl");
  164. int skill1 = getConfig().getInt("players." + s + ".skill1");
  165. int skill2 = getConfig().getInt("players." + s + ".skill2");
  166. int skill3 = getConfig().getInt("players." + s + ".skill3");
  167. CustomPlayer cp = new CustomPlayer(s, classe, money, lvl, xp, forca, defesa, mobilidade, skill1, skill2, skill3);
  168.  
  169. // databse information gathering
  170. try {
  171. PreparedStatement ps = (PreparedStatement) sql.openConnection().prepareStatement("SELECT * FROM users WHERE nick = ?");
  172. ps.setString(1, s);
  173.  
  174. ResultSet res = ps.executeQuery();
  175. res.next();
  176.  
  177. String pass = res.getString("pass");
  178. cp.setGoodPass(pass);
  179.  
  180. } catch (SQLException e) {
  181. e.printStackTrace();
  182. } catch (ClassNotFoundException e) {
  183. e.printStackTrace();
  184. }
  185.  
  186.  
  187. cp.setPassChanged(false);
  188. CustomPlayer.addCPlayer(cp);
  189. players++;
  190. }
  191. logger.info("- -");
  192. logger.info("- Found " + players + " players");
  193. }
  194.  
  195. logger.info("- Done! -");
  196. logger.info("----------------------------------------");
  197. logger.info("- Registering muted players... -");
  198.  
  199. if (getConfig().getStringList("muted") != null) {
  200. List<String> muted = getConfig().getStringList("muted");
  201. for(String s : muted) {
  202. MuteManager.mute(CustomPlayer.getCustomPlayer(s));
  203. }
  204. }
  205.  
  206. logger.info("- Done! -");
  207. logger.info("----------------------------------------");
  208. logger.info("- Registering schedulers... -");
  209.  
  210. BukkitScheduler scheduler = getServer().getScheduler();
  211. scheduler.scheduleSyncRepeatingTask(this, new SpawnRunnable(), 20L, 20L);
  212.  
  213. logger.info("- Done! -");
  214. logger.info("----------------------------------------");
  215. logger.info("- Registering Text Channels... -");
  216.  
  217. if (getConfig().getStringList("txtchannels").size() > 0) {
  218. List<String> tc = getConfig().getStringList("txtchannels");
  219. for (String s : tc) {
  220. TextChannel t = new TextChannel(s);
  221. TextChannel.addTextChannel(t);
  222.  
  223. }
  224. } else {
  225. TextChannel t = new TextChannel("all");
  226. TextChannel.addTextChannel(t);
  227. logger.info("- Theres no text channels, creating a -");
  228. logger.info("- new default one named 'all'... -");
  229. }
  230.  
  231. logger.info("- Done! -");
  232. logger.info("----------------------------------------");
  233.  
  234. for (Player p : Bukkit.getOnlinePlayers()) {
  235. TextChannel.getByName("all").addPlayer(p);
  236. }
  237.  
  238. }
  239.  
  240. @SuppressWarnings("deprecation")
  241. @Override
  242. public void onDisable() {
  243.  
  244. // -----------------------------------------[ SALVAR NA CONFIG ]--------------------------------------------------
  245.  
  246. // PLAYERS
  247. for (CustomPlayer cp : CustomPlayer.getAllCPlayers()) {
  248. getConfig().set("players." + cp.getName() + ".money", cp.getMoney());
  249. getConfig().set("players." + cp.getName() + ".classe", cp.getClasse().toString());
  250. getConfig().set("players." + cp.getName() + ".forca", cp.getForca());
  251. getConfig().set("players." + cp.getName() + ".defesa", cp.getDefesa());
  252. getConfig().set("players." + cp.getName() + ".mobilidade", cp.getMobilidade());
  253. getConfig().set("players." + cp.getName() + ".xp", cp.getXp());
  254. getConfig().set("players." + cp.getName() + ".lvl", cp.getLevel());
  255.  
  256. // update db if user changed pass
  257. if (cp.changedPass()) {
  258. try {
  259. PreparedStatement ps = (PreparedStatement) sql.openConnection().prepareStatement("UPDATE users SET pass = ? WHERE nick = ?");
  260. ps.setString(1, cp.getGoodPass());
  261. ps.setString(2, cp.getName());
  262.  
  263. ps.execute();
  264. } catch (SQLException exc) {
  265. exc.printStackTrace();
  266. } catch (ClassNotFoundException e) {
  267. e.printStackTrace();
  268. }
  269. }
  270.  
  271.  
  272. }
  273.  
  274. // SPAWNPOINTS
  275. for (SpawnPoint sp : SpawnPoint.getAllSpawns()) {
  276. getConfig().set("spawns." + sp.getMob().getName() + "." + sp.getLevel() + "", "CONTINUAR AQUI");
  277. }
  278.  
  279. // TEXT CHANNELS
  280. getConfig().set("txtchannels", "");
  281. if (TextChannel.getAllTextChannels().size() > 0) {
  282. getConfig().set("txtchannels", TextChannel.getAllTxtChNames());
  283. }
  284.  
  285. // MUTED PLAYERS
  286. getConfig().set("muted", "");
  287. if (MuteManager.getAllMutedPlayers() != null) {
  288. getConfig().set("muted", MuteManager.getNames());
  289. }
  290.  
  291. // WORLDS WITHOUT RAIN
  292. RainHandler.saveBlockedWorlds();
  293.  
  294. saveConfig();
  295. }
  296.  
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement