Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.40 KB | None | 0 0
  1. <>-- KnockIT --<>
  2.  
  3. @EventHandler
  4. public void onMove(PlayerMoveEvent e) {
  5. Player p = e.getPlayer();
  6.  
  7. File file = new File("plugins//KnockIT//locations.yml");
  8. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  9.  
  10. if ((p.getLocation().getY() < cfg.getDouble("Todesgrenze.Y")))
  11. {
  12. ItemStack stick = createItem(Material.STICK, 1, "§5Knüppel");
  13. stick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1);
  14.  
  15. ItemStack enterhaken = createItem(Material.FISHING_ROD, 1, "§5Enterhaken");
  16. ItemStack boots = createItem(Material.DIAMOND_BOOTS, 1, "§5Yeezy Boost 9000");
  17. ItemStack leave = createItem(Material.MAGMA_CREAM, 1, "§cZurück zur Lobby §7§o<Rechtsklick>");
  18.  
  19. PlayerHandler.clearPlayer(p);
  20.  
  21. Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
  22. public void run() {
  23. p.getInventory().setItem(0, stick);
  24. p.getInventory().setItem(1, enterhaken);
  25. p.getInventory().setItem(8, leave);
  26. p.getInventory().setBoots(boots);
  27. }
  28. }, 10L);
  29.  
  30. p.teleport(Main.getConfigManager().LoadLocation(Main.map + ".Spawn"));
  31. if (Main.killer.containsKey(p))
  32. {
  33. Player killer = (Player)Main.killer.get(p);
  34. p.sendMessage(Main.prefix + "§7Du wurdest von §e" + killer.getDisplayName() + " §7getötet!");
  35. killer.sendMessage(Main.prefix + "§7Du hast §e" + p.getDisplayName() + " §7getötet!");
  36.  
  37. p.playSound(p.getLocation(), Sound.ZOMBIE_DEATH, 1.0F, 1.0F);
  38. killer.playSound(killer.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
  39. killer.sendMessage(Main.prefix + "§a+1 Punkt");
  40. killer.sendMessage(me.cakegames.CoinsAPI.Main.global + "§a+1 Cake");
  41.  
  42. StatsAPI.addDeaths(p.getUniqueId().toString(), Integer.valueOf(1));
  43. StatsAPI.addKills(killer.getUniqueId().toString(), Integer.valueOf(1));
  44. StatsAPI.addPoints(killer.getUniqueId().toString(), Integer.valueOf(1));
  45. me.cakegames.CoinsAPI.CoinsAPI.addCakes(killer.getUniqueId().toString(), Integer.valueOf(1));
  46.  
  47. Main.killer.remove(killer);
  48.  
  49. killer.setLevel(killer.getLevel() + 1);
  50. PlayerHandler.clearPlayer(p);
  51. p.spigot().respawn();
  52.  
  53. Main.killer.remove(p);
  54. }
  55. else
  56. {
  57. p.sendMessage(Main.prefix + "§cDu bist runtergefallen!");
  58. StatsAPI.addDeaths(p.getUniqueId().toString(), Integer.valueOf(1));
  59. p.playSound(p.getLocation(), Sound.ZOMBIE_DEATH, 1.0F, 1.0F);
  60. PlayerHandler.clearPlayer(p);
  61. p.spigot().respawn();
  62. }
  63. }
  64. if (p.getHealth() < 20.0D) {
  65. p.setHealth(20.0D);
  66. }
  67. }
  68.  
  69. @EventHandler
  70. public void onDeath(PlayerDeathEvent e) {
  71. Player p = e.getEntity();
  72.  
  73. e.getDrops().clear();
  74. e.setDeathMessage(null);
  75. PlayerHandler.clearPlayer(p);
  76.  
  77. p.teleport(Main.getConfigManager().LoadLocation("Spawn"));
  78. }
  79.  
  80. @EventHandler
  81. public void onRespawn(PlayerRespawnEvent e) {
  82. Player p = e.getPlayer();
  83.  
  84. ItemStack stick = createItem(Material.STICK, 1, "§5Knüppel");
  85. stick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1);
  86.  
  87. ItemStack enterhaken = createItem(Material.FISHING_ROD, 1, "§5Enterhaken");
  88. ItemStack boots = createItem(Material.DIAMOND_BOOTS, 1, "§5Yeezy Boost 9000");
  89. ItemStack leave = createItem(Material.MAGMA_CREAM, 1, "§cZurück zur Lobby §7§o<Rechtsklick>");
  90.  
  91. Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
  92. public void run() {
  93. p.getInventory().setItem(0, stick);
  94. p.getInventory().setItem(1, enterhaken);
  95. p.getInventory().setItem(8, leave);
  96. p.getInventory().setBoots(boots);
  97. }
  98. }, 10L);
  99.  
  100. p.teleport(Main.getConfigManager().LoadLocation("Spawn"));
  101. }
  102.  
  103. @EventHandler
  104. public void onLogin(PlayerLoginEvent e)
  105. {
  106. Player p = e.getPlayer();
  107. if(Bukkit.getOnlinePlayers().size() >= Bukkit.getMaxPlayers()) {
  108. if(p.hasPermission("system.premiumjoin")) {
  109. for(Player players : Bukkit.getOnlinePlayers()) {
  110. if(!players.hasPermission("system.premiumjoin")) {
  111. players.kickPlayer(Main.system + "§cDu wurdest auf die Lobby gesendet, um einem Spieler mit §ehöheren Rang §cPlatz zu machen!");
  112. e.allow();
  113. return;
  114. }
  115. }
  116. e.disallow(null, Main.global + "§cDer Server ist voll!");
  117. }
  118. e.disallow(null, Main.global + "§cDer Server ist voll! §cDu brauchst ein §ehöheren Rang §cum trotzdem joinen zu können!");
  119. }
  120. }
  121.  
  122. public class MySQL
  123. {
  124. public static String username;
  125. public static String password;
  126. public static String database;
  127. public static String host;
  128. public static String port;
  129. public static Connection con;
  130.  
  131. public MySQL(String user, String pass, String host2, String dB) {}
  132.  
  133. public static void connect()
  134. {
  135. if (!isConnected()) {
  136. try
  137. {
  138. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
  139. System.out.println(Main.console + "Die MySQL Verbindung wurde erfolgreich hergestellt!");
  140. }
  141. catch (SQLException e)
  142. {
  143. e.printStackTrace();
  144. }
  145. }
  146. }
  147.  
  148. public static void close()
  149. {
  150. if (isConnected()) {
  151. try
  152. {
  153. con.close();
  154. System.out.println(Main.console + "Die MySQL Verbindung wurde erfolgreich getrennt!");
  155. }
  156. catch (SQLException e)
  157. {
  158. e.printStackTrace();
  159. }
  160. }
  161. }
  162.  
  163. public static boolean isConnected()
  164. {
  165. return con != null;
  166. }
  167.  
  168. public static void createTable()
  169. {
  170. if (isConnected()) {
  171. try
  172. {
  173. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS StatsAPI (UUID VARCHAR(100), POINTS int, KILLS int , DEATHS int)");
  174. }
  175. catch (SQLException e)
  176. {
  177. e.printStackTrace();
  178. }
  179. }
  180. }
  181.  
  182. public static void update(String qry)
  183. {
  184. if (isConnected()) {
  185. try
  186. {
  187. con.createStatement().executeUpdate(qry);
  188. }
  189. catch (SQLException e)
  190. {
  191. e.printStackTrace();
  192. }
  193. }
  194. }
  195.  
  196. public static ResultSet getResult(String qry)
  197. {
  198. ResultSet rs = null;
  199. try
  200. {
  201. Statement st = con.createStatement();
  202. rs = st.executeQuery(qry);
  203. }
  204. catch (SQLException e)
  205. {
  206. connect();
  207. System.err.println(e);
  208. }
  209. return rs;
  210. }
  211.  
  212. public static File getMySQLFile()
  213. {
  214. return new File("plugins/KnockIT", "MySQL.yml");
  215. }
  216.  
  217. public static FileConfiguration getMySQLFileConfiguration()
  218. {
  219. return YamlConfiguration.loadConfiguration(getMySQLFile());
  220. }
  221.  
  222. public static void setStandardMySQL()
  223. {
  224. FileConfiguration cfg = getMySQLFileConfiguration();
  225.  
  226. cfg.options().copyDefaults(true);
  227. cfg.addDefault("host", "127.0.0.1");
  228. cfg.addDefault("port", "3306");
  229. cfg.addDefault("database", "localhost");
  230. cfg.addDefault("username", "root");
  231. cfg.addDefault("password", "password");
  232. try
  233. {
  234. cfg.save(getMySQLFile());
  235. }
  236. catch (IOException e)
  237. {
  238. e.printStackTrace();
  239. }
  240. }
  241.  
  242. public static void readMySQL()
  243. {
  244. FileConfiguration cfg = getMySQLFileConfiguration();
  245. host = cfg.getString("host");
  246. port = cfg.getString("port");
  247. database = cfg.getString("database");
  248. username = cfg.getString("username");
  249. password = cfg.getString("password");
  250. }
  251.  
  252. public static Connection con;
  253.  
  254. public static boolean playerExists(String uuid)
  255. {
  256. try
  257. {
  258. ResultSet rs = MySQL.getResult("SELECT * FROM StatsAPI WHERE UUID='" + uuid + "'");
  259. if (rs.next()) {
  260. return rs.getString("UUID") != null;
  261. }
  262. return false;
  263. }
  264. catch (SQLException e)
  265. {
  266. e.printStackTrace();
  267. }
  268. return false;
  269. }
  270.  
  271. public static void createPlayer(String uuid)
  272. {
  273. if (!playerExists(uuid)) {
  274. MySQL.update("INSERT INTO StatsAPI (UUID, POINTS, KILLS, DEATHS) VALUES ('" + uuid + "', '0', '0', '0');");
  275. }
  276. }
  277.  
  278. public static Integer getPoints(String uuid)
  279. {
  280. Integer i = Integer.valueOf(0);
  281. if (playerExists(uuid))
  282. {
  283. try
  284. {
  285. ResultSet rs = MySQL.getResult("SELECT * FROM StatsAPI WHERE UUID='" + uuid + "'");
  286. if (rs.next()) {
  287. Integer.valueOf(rs.getInt("POINTS"));
  288. }
  289. i = Integer.valueOf(rs.getInt("POINTS"));
  290. }
  291. catch (SQLException e)
  292. {
  293. e.printStackTrace();
  294. }
  295. }
  296. else
  297. {
  298. createPlayer(uuid);
  299. getPoints(uuid);
  300. }
  301. return i;
  302. }
  303.  
  304. public static Integer getKills(String uuid)
  305. {
  306. Integer i = Integer.valueOf(0);
  307. if (playerExists(uuid))
  308. {
  309. try
  310. {
  311. ResultSet rs = MySQL.getResult("SELECT * FROM StatsAPI WHERE UUID='" + uuid + "'");
  312. if (rs.next()) {
  313. Integer.valueOf(rs.getInt("KILLS"));
  314. }
  315. i = Integer.valueOf(rs.getInt("KILLS"));
  316. }
  317. catch (SQLException e)
  318. {
  319. e.printStackTrace();
  320. }
  321. }
  322. else
  323. {
  324. createPlayer(uuid);
  325. getKills(uuid);
  326. }
  327. return i;
  328. }
  329.  
  330. public static Integer getDeaths(String uuid)
  331. {
  332. Integer i = Integer.valueOf(0);
  333. if (playerExists(uuid))
  334. {
  335. try
  336. {
  337. ResultSet rs = MySQL.getResult("SELECT * FROM StatsAPI WHERE UUID='" + uuid + "'");
  338. if (rs.next()) {
  339. Integer.valueOf(rs.getInt("DEATHS"));
  340. }
  341. i = Integer.valueOf(rs.getInt("DEATHS"));
  342. }
  343. catch (SQLException e)
  344. {
  345. e.printStackTrace();
  346. }
  347. }
  348. else
  349. {
  350. createPlayer(uuid);
  351. getDeaths(uuid);
  352. }
  353. return i;
  354. }
  355.  
  356. public static void setPoints(String uuid, Integer points)
  357. {
  358. if (playerExists(uuid))
  359. {
  360. MySQL.update("UPDATE StatsAPI SET POINTS='" + points + "' WHERE UUID='" + uuid + "'");
  361. }
  362. else
  363. {
  364. createPlayer(uuid);
  365. setPoints(uuid, points);
  366. }
  367. }
  368.  
  369. public static void setKills(String uuid, Integer kills)
  370. {
  371. if (playerExists(uuid))
  372. {
  373. MySQL.update("UPDATE StatsAPI SET KILLS='" + kills + "' WHERE UUID='" + uuid + "'");
  374. }
  375. else
  376. {
  377. createPlayer(uuid);
  378. setKills(uuid, kills);
  379. }
  380. }
  381.  
  382. public static void setDeaths(String uuid, Integer deaths)
  383. {
  384. if (playerExists(uuid))
  385. {
  386. MySQL.update("UPDATE StatsAPI SET DEATHS='" + deaths + "' WHERE UUID='" + uuid + "'");
  387. }
  388. else
  389. {
  390. createPlayer(uuid);
  391. setDeaths(uuid, deaths);
  392. }
  393. }
  394.  
  395. public static void addPoints(String uuid, Integer points)
  396. {
  397. if (playerExists(uuid))
  398. {
  399. setPoints(uuid, Integer.valueOf(getPoints(uuid).intValue() + points.intValue()));
  400. }
  401. else
  402. {
  403. createPlayer(uuid);
  404. addPoints(uuid, points);
  405. }
  406. }
  407.  
  408. public static void addKills(String uuid, Integer kills)
  409. {
  410. if (playerExists(uuid))
  411. {
  412. setKills(uuid, Integer.valueOf(getKills(uuid).intValue() + kills.intValue()));
  413. }
  414. else
  415. {
  416. createPlayer(uuid);
  417. addKills(uuid, kills);
  418. }
  419. }
  420.  
  421. public static void addDeaths(String uuid, Integer deaths)
  422. {
  423. if (playerExists(uuid))
  424. {
  425. setDeaths(uuid, Integer.valueOf(getDeaths(uuid).intValue() + deaths.intValue()));
  426. }
  427. else
  428. {
  429. createPlayer(uuid);
  430. addDeaths(uuid, deaths);
  431. }
  432. }
  433.  
  434. public static void removePoints(String uuid, Integer points)
  435. {
  436. if (playerExists(uuid))
  437. {
  438. setPoints(uuid, Integer.valueOf(getPoints(uuid).intValue() - points.intValue()));
  439. }
  440. else
  441. {
  442. createPlayer(uuid);
  443. removePoints(uuid, points);
  444. }
  445. }
  446.  
  447. public static void removeKills(String uuid, Integer kills)
  448. {
  449. if (playerExists(uuid))
  450. {
  451. setKills(uuid, Integer.valueOf(getKills(uuid).intValue() - kills.intValue()));
  452. }
  453. else
  454. {
  455. createPlayer(uuid);
  456. removeKills(uuid, kills);
  457. }
  458. }
  459.  
  460. public static void removeDeaths(String uuid, Integer deaths)
  461. {
  462. if (playerExists(uuid))
  463. {
  464. setKills(uuid, Integer.valueOf(getDeaths(uuid).intValue() - deaths.intValue()));
  465. }
  466. else
  467. {
  468. createPlayer(uuid);
  469. removeDeaths(uuid, deaths);
  470. }
  471. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement