Advertisement
Guest User

Untitled

a guest
Dec 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.30 KB | None | 0 0
  1. package Maquinas.alex;
  2.  
  3. import java.io.File;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.util.Arrays;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Set;
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Location;
  12. import org.bukkit.Material;
  13. import org.bukkit.World;
  14. import org.bukkit.block.Block;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.enchantments.Enchantment;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.event.EventHandler;
  20. import org.bukkit.event.Listener;
  21. import org.bukkit.event.block.Action;
  22. import org.bukkit.event.block.BlockBreakEvent;
  23. import org.bukkit.event.block.BlockPlaceEvent;
  24. import org.bukkit.event.inventory.InventoryClickEvent;
  25. import org.bukkit.event.player.PlayerInteractEvent;
  26. import org.bukkit.inventory.Inventory;
  27. import org.bukkit.inventory.ItemStack;
  28. import org.bukkit.inventory.meta.ItemMeta;
  29. import org.bukkit.inventory.meta.PotionMeta;
  30. import org.bukkit.plugin.Plugin;
  31. import org.bukkit.plugin.PluginManager;
  32. import org.bukkit.plugin.RegisteredServiceProvider;
  33. import org.bukkit.plugin.java.JavaPlugin;
  34. import org.bukkit.potion.PotionEffect;
  35. import org.bukkit.potion.PotionEffectType;
  36.  
  37. import com.gmail.filoghost.holographicdisplays.api.Hologram;
  38. import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
  39. import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
  40.  
  41. import net.milkbowl.vault.economy.Economy;
  42.  
  43. import java.sql.Connection;
  44. import java.sql.Statement;
  45.  
  46. public class Main extends JavaPlugin implements Listener {
  47.  
  48. Connection c = null;
  49. Statement sta = null;
  50. String table_prefix = null;
  51. Main main = this;
  52. public HashMap < String, List < Location >> Maquinas = new HashMap < > ();
  53. Integer maquinasloop = null;
  54. private HashMap < Location, Boolean > MaquinaAtiva = new HashMap < > ();
  55. private HashMap < Block, Boolean > CercaStatus = new HashMap < > ();
  56. private HashMap < Block, Boolean > HologramaStatus = new HashMap < > ();
  57. private HashMap < Player, Block > BlockInfo = new HashMap < > ();
  58. public static Economy dinheiro = null;
  59. public static Hologram hologram;
  60. public void onEnable() {
  61. main = this;
  62. PluginManager pm = getServer().getPluginManager();
  63. pm.registerEvents(this, this);
  64. Dados();
  65. saveDefaultConfig();
  66. setupEconomy();
  67. if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
  68. getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
  69. getLogger().severe("*** This plugin will be disabled. ***");
  70. this.setEnabled(false);
  71. return;
  72. }
  73. }
  74. public void onDisable() {
  75. try {
  76. c.close();
  77. } catch (Exception e) {}
  78. try {
  79. sta.close();
  80. } catch (Exception e) {}
  81. }
  82. public static boolean setupEconomy() {
  83. if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
  84. return false;
  85. }
  86. RegisteredServiceProvider < Economy > rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
  87. if (rsp == null) {
  88. return false;
  89. }
  90. dinheiro = rsp.getProvider();
  91. return dinheiro != null;
  92. }
  93.  
  94. private void Dados() {
  95. try {
  96. if (getConfig().getString("MySQL.Ativo").equalsIgnoreCase("Sim")) {
  97. c = DriverManager.getConnection("jdbc:mysql://" + getConfig().getString("MySQL.Hostname") + ":" + getConfig().getString("MySQL.Port") + "/" + getConfig().getString("MySQL.Database"), getConfig().getString("MySQL.Username"), getConfig().getString("MySQL.Password"));
  98. table_prefix = getConfig().getString("MySQL.Prefix");
  99. } else {
  100. File db = new File("plugins/" + getDescription().getName() + "/Dados.db");
  101. if (!db.exists()) {
  102. db.createNewFile();
  103. }
  104. Class.forName("org.sqlite.JDBC");
  105. c = DriverManager.getConnection("jdbc:sqlite:plugins/" + getDescription().getName() + "/Dados.db");
  106. table_prefix = "Maquinas";
  107.  
  108. }
  109. sta = c.createStatement();
  110. sta.executeUpdate("CREATE TABLE IF NOT EXISTS " + table_prefix + "_maquina (player VARCHAR(64), world VARCHAR(64), x VARCHAR(64), y VARCHAR(64), z VARCHAR(64), combu VARCHAR(64), lvl VARCHAR(64), tipo VARCHAR(64), multi VARCHAR(64));");
  111. } catch (Exception e) {
  112. Bukkit.getPluginManager().disablePlugin(this);
  113. }
  114.  
  115. }
  116. @Override
  117. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  118. if (!(sender instanceof Player)) {
  119. return true;
  120. }
  121. Player p = (Player) sender;
  122. if (cmd.getName().equalsIgnoreCase("emaquinas")) {
  123. if (p.hasPermission("admin.use")) {
  124. for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
  125. for (String update: getConfig().getStringList("Maquinas." + maquinas + ".Updates")) {
  126. for (String comb: getConfig().getStringList("Maquinas." + maquinas + ".Combustiveis")) {
  127. ItemStack m2 = new ItemStack(ItemGet(update.split("\\\\")[0], 1, update.split("\\\\")[1]));
  128. ItemStack m3 = new ItemStack(ItemGet(comb.split("\\\\")[0], 1, comb.split("\\\\")[1]));
  129. p.getPlayer().getInventory().addItem(m3);
  130. p.getPlayer().getInventory().addItem(m2);
  131. ItemStack MaquinaItem = ItemGet(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[0], 1, getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[1].replace("@lvl", "1"));
  132. ItemMeta MIM = MaquinaItem.getItemMeta();
  133. List < String > Lore = MIM.getLore();
  134. Lore.add("§0{1}[" + maquinas + "]");
  135. MIM.setLore(Lore);
  136. MaquinaItem.setItemMeta(MIM);
  137. p.getPlayer().getInventory().addItem(MaquinaItem);
  138. }
  139. }
  140. }
  141. }else {
  142. p.sendMessage("§cVocê não tem permissão para digitar esté comando");
  143. }
  144. }
  145. return false;
  146. }
  147. @SuppressWarnings("deprecation")
  148. @EventHandler
  149. public void Click(InventoryClickEvent e) {
  150. for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
  151. Player p = (Player) e.getWhoClicked();
  152. Double balance = dinheiro.getBalance(p.getName());
  153. if (e.getInventory().getName().equals("Maquina De " + maquinas)) {
  154. e.setCancelled(true);
  155. if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("331", 1, "[N]{&cClique para da upgrade}[N]"))) {
  156. try {
  157. ResultSet rs = sta.executeQuery("SELECT * FROM " + table_prefix + "_maquina WHERE x = '" + BlockInfo.get(p).getLocation().getBlockX() + "' AND y = '" + BlockInfo.get(p).getLocation().getBlockY() + "' AND z = '" + BlockInfo.get(p).getLocation().getBlockZ() + "' AND world = '" + BlockInfo.get(p).getLocation().getWorld().getName() + "';");
  158. if (rs.next()) {
  159. Integer lvl = rs.getInt("lvl");
  160. for (String lvls: getConfig().getStringList("Levels")) {
  161. if (lvl == Integer.parseInt(lvls.split("\\\\")[0])) {
  162. if (lvl != getConfig().getInt("Maquinas." + maquinas + ".LevelMax")) {
  163. if (MaquinaAtiva.get(BlockInfo.get(p).getLocation()) == null || !MaquinaAtiva.get(BlockInfo.get(p).getLocation())) {
  164. if (balance >= Integer.parseInt(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0])) {
  165. sta.executeUpdate("UPDATE " + table_prefix + "_maquina SET lvl = '" + (lvl + 1) + "' WHERE x = '" + BlockInfo.get(p).getLocation().getBlockX() + "' AND y = '" + BlockInfo.get(p).getLocation().getBlockY() + "' AND z = '" + BlockInfo.get(p).getLocation().getBlockZ() + "' AND world = '" + BlockInfo.get(p).getLocation().getWorld().getName() + "';");
  166. p.sendMessage("Você colocou update na maquina de " + maquinas + " agora ela está no lv." + (lvl + 1));
  167. hologram.clearLines();
  168. MaquinaStatus(BlockInfo.get(p), p, 2);
  169. dinheiro.withdrawPlayer(p.getName(), Integer.parseInt(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0]));
  170. p.closeInventory();
  171. } else {
  172. p.sendMessage("§cVocê não tem $" + Integer.parseInt(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0]) + " para da update");
  173. }
  174. } else {
  175. p.sendMessage("§cVocê não pode da update enquanto a maquina está ativa");
  176. }
  177. } else {
  178. p.sendMessage("§cSua maquina já está no level máximo");
  179. }
  180. }
  181. }
  182.  
  183. }
  184. } catch (Exception e2) {
  185. e2.printStackTrace();
  186. }
  187. }
  188. if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:5", 1, "[N]{&a&lAtivar Cerca}[N]"))) {
  189. CercaStatus.put(BlockInfo.get(p), true);
  190. Cerca(BlockInfo.get(p));
  191. ItemStack item = ItemGet("35:14", 1, "[N]{&4&lDesativar Cerca}[N]");
  192. e.getInventory().getContents()[10].setType(item.getType());
  193. e.getInventory().getContents()[10].setItemMeta(item.getItemMeta());
  194. p.closeInventory();
  195. }
  196. if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:14", 1, "[N]{&4&lDesativar Cerca}[N]"))) {
  197. CercaStatus.put(BlockInfo.get(p), false);
  198. CercaRemove(BlockInfo.get(p));
  199. ItemStack item = ItemGet("35:5", 1, "[N]{&a&lAtivar Cerca}[N]");
  200. e.getInventory().getContents()[10].setType(item.getType());
  201. e.getInventory().getContents()[10].setItemMeta(item.getItemMeta());
  202. p.closeInventory();
  203. }
  204. if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]"))) {
  205. HologramaStatus.put(BlockInfo.get(p), true);
  206. if (MaquinaAtiva.get(BlockInfo.get(p).getLocation()) == null || !MaquinaAtiva.get(BlockInfo.get(p).getLocation())) {
  207. MaquinaStatus(BlockInfo.get(p), p, 0);
  208. MaquinaStatus(BlockInfo.get(p), p, 2);
  209. } else {
  210. MaquinaStatus(BlockInfo.get(p), p, 0);
  211. MaquinaStatus(BlockInfo.get(p), p, 1);
  212. }
  213. ItemStack item = ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]");
  214. e.getInventory().getContents()[16].setType(item.getType());
  215. e.getInventory().getContents()[16].setItemMeta(item.getItemMeta());
  216. p.closeInventory();
  217. }
  218. if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]"))) {
  219. HologramaStatus.put(BlockInfo.get(p), false);
  220. MaquinaStatus(BlockInfo.get(p), p, 0);
  221. ItemStack item = ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]");
  222. e.getInventory().getContents()[16].setType(item.getType());
  223. e.getInventory().getContents()[16].setItemMeta(item.getItemMeta());
  224. p.closeInventory();
  225. }
  226. }
  227. }
  228. }
  229. private void Cerca(Block b) {
  230. World world = b.getLocation().getWorld();
  231. double locX = b.getLocation().getX();
  232. double locZ = b.getLocation().getZ();
  233. locX -= 3;
  234. locZ -= 3;
  235. for (int i = 0; i <= 5; i++) {
  236. locX += 1;
  237. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  238. xs.getBlock().setType(Material.FENCE);
  239. }
  240. for (int i = 0; i <= 5; i++) {
  241. locZ += 1;
  242. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  243. xs.getBlock().setType(Material.FENCE);
  244. }
  245. for (int i = 0; i <= 5; i++) {
  246. locX -= 1;
  247. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  248. xs.getBlock().setType(Material.FENCE);
  249. }
  250. for (int i = 0; i <= 5; i++) {
  251. locZ -= 1;
  252. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  253. xs.getBlock().setType(Material.FENCE);
  254. }
  255. }
  256. private void CercaRemove(Block b) {
  257. World world = b.getLocation().getWorld();
  258. double locX = b.getLocation().getX();
  259. double locZ = b.getLocation().getZ();
  260. locX -= 3;
  261. locZ -= 3;
  262. for (int i = 0; i <= 5; i++) {
  263. locX += 1;
  264. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  265. xs.getBlock().setType(Material.AIR);
  266. }
  267. for (int i = 0; i <= 5; i++) {
  268. locZ += 1;
  269. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  270. xs.getBlock().setType(Material.AIR);
  271. }
  272. for (int i = 0; i <= 5; i++) {
  273. locX -= 1;
  274. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  275. xs.getBlock().setType(Material.AIR);
  276. }
  277. for (int i = 0; i <= 5; i++) {
  278. locZ -= 1;
  279. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  280. xs.getBlock().setType(Material.AIR);
  281. }
  282. }
  283.  
  284.  
  285. private boolean VeriCerca(Block b) {
  286. World world = b.getLocation().getWorld();
  287. double locX = b.getLocation().getX();
  288. double locZ = b.getLocation().getZ();
  289. locX -= 3;
  290. locZ -= 3;
  291. for (int i = 0; i <= 5; i++) {
  292. locX += 1;
  293. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  294. if (xs.getBlock().getType() == Material.FENCE) {
  295. return true;
  296. }
  297. }
  298. for (int i = 0; i <= 5; i++) {
  299. locZ += 1;
  300. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  301. if (xs.getBlock().getType() == Material.FENCE) {
  302. return true;
  303. }
  304. }
  305. for (int i = 0; i <= 5; i++) {
  306. locX -= 1;
  307. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  308. if (xs.getBlock().getType() == Material.FENCE) {
  309. return true;
  310. }
  311. }
  312. for (int i = 0; i <= 5; i++) {
  313. locZ -= 1;
  314. Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
  315. if (xs.getBlock().getType() == Material.FENCE) {
  316. return true;
  317. }
  318. }
  319. return false;
  320. }
  321.  
  322. private void MaquinaStatus(Block b, Player p, Integer s) {
  323. if (s == 0) {
  324. for (Hologram hologram: HologramsAPI.getHolograms((Plugin) this)) {
  325. Location hologramLoc = hologram.getLocation();
  326. if (b.getLocation().add(0.5, 2.5, 0.5).distance(hologramLoc) < 0.5) {
  327. hologram.delete();
  328. }
  329. }
  330. } else {
  331. try {
  332. ResultSet rs = sta.executeQuery("SELECT * FROM " + table_prefix + "_maquina WHERE x = '" + b.getLocation().getBlockX() + "' AND y = '" + b.getLocation().getBlockY() + "' AND z = '" + b.getLocation().getBlockZ() + "' AND world = '" + b.getLocation().getWorld().getName() + "';");
  333. if (rs.next()) {
  334. Integer lvl = rs.getInt("lvl");
  335. String Player = rs.getString("player");
  336. String tipo = rs.getString("tipo");
  337. Location local = b.getLocation().add(0.5, 2.5, 0.5);
  338. hologram = HologramsAPI.createHologram(this, local);
  339. TextLine test = hologram.appendTextLine("Maquina");
  340. TextLine test2 = hologram.appendTextLine("Maquina2");
  341. TextLine test3 = hologram.appendTextLine("Maquina3");
  342. TextLine test4 = hologram.appendTextLine("Maquina4");
  343. test.setText("§fMaquina De §9" + tipo);
  344. test2.setText("§fDono §6" + Player);
  345. test3.setText("§fStatus " + ((s == 1) ? "§aAtivo" : "§4Desativado"));
  346. test4.setText("§fLv " + (lvl));
  347. }
  348. } catch (Exception e2) {
  349. e2.printStackTrace();
  350. }
  351. }
  352. }
  353. @EventHandler
  354. public void QuebraMaquina(BlockBreakEvent e) {
  355. if (e.getPlayer() instanceof Player) {
  356. Player p = e.getPlayer();
  357. Block bloco = e.getBlock();
  358. if (MaquinaAtiva.get(bloco.getLocation()) == null || !MaquinaAtiva.get(bloco.getLocation())) {
  359. try {
  360. ResultSet rs = sta.executeQuery("SELECT * FROM " + table_prefix + "_maquina WHERE x = '" + bloco.getLocation().getBlockX() + "' AND y = '" + bloco.getLocation().getBlockY() + "' AND z = '" + bloco.getLocation().getBlockZ() + "' AND world = '" + bloco.getLocation().getWorld().getName() + "';");
  361. if (rs.next()) {
  362. e.setCancelled(true);
  363. e.getBlock().getWorld().getBlockAt(e.getBlock().getLocation()).setType(Material.AIR);
  364. String lvl = rs.getString("lvl");
  365. String tipo = rs.getString("tipo");
  366. sta.executeUpdate("DELETE FROM " + table_prefix + "_maquina WHERE x = '" + bloco.getLocation().getBlockX() + "' AND y = '" + bloco.getLocation().getBlockY() + "' AND z = '" + bloco.getLocation().getBlockZ() + "' AND world = '" + bloco.getLocation().getWorld().getName() + "';");
  367. p.sendMessage("Está maquina foi removida com sucesso");
  368. ItemStack MaquinaItem = ItemGet(getConfig().getString("Maquinas." + tipo + ".item").split("\\\\")[0], 1, getConfig().getString("Maquinas." + tipo + ".item").split("\\\\")[1].replace("@lvl", lvl));
  369. ItemMeta MIM = MaquinaItem.getItemMeta();
  370. List < String > Lore = MIM.getLore();
  371. Lore.add("§0{" + lvl + "}[" + tipo + "]");
  372. MIM.setLore(Lore);
  373. MaquinaItem.setItemMeta(MIM);
  374. e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), MaquinaItem);
  375. MaquinaStatus(bloco, p, 0);
  376. CercaStatus.put(bloco, null);
  377. HologramaStatus.put(bloco, null);
  378. }
  379. MaquinaAtiva.put(bloco.getLocation(), false);
  380. } catch (Exception e2) {
  381. e2.printStackTrace();
  382. }
  383. } else {
  384. e.setCancelled(true);
  385. p.sendMessage("§4Você não pode quebra a maquina enquanto ela está ativa");
  386. }
  387. }
  388. }
  389. @EventHandler
  390. public void ColocaMaquina(BlockPlaceEvent e) {
  391. if (e.getPlayer() instanceof Player) {
  392. Player p = e.getPlayer();
  393. Block bloco = e.getBlockPlaced();
  394. String tipo = "";
  395. String lvl = "1";
  396. for (String lore: e.getPlayer().getItemInHand().getItemMeta().getLore()) {
  397. if (lore.contains("§0{") && lore.contains("}[") && lore.contains("]")) {
  398. lvl = lore.split("\\{")[1].split("\\}")[0];
  399. tipo = lore.split("\\[")[1].split("\\]")[0];
  400. }
  401. }
  402. if (!(tipo.equals(""))) {
  403. try {
  404. CercaStatus.put(bloco, false);
  405. HologramaStatus.put(bloco, true);
  406. Location local = bloco.getLocation().add(0.5, 2.5, 0.5);
  407. hologram = HologramsAPI.createHologram(this, local);
  408. TextLine test = hologram.appendTextLine("Maquina");
  409. TextLine test2 = hologram.appendTextLine("Maquina2");
  410. TextLine test3 = hologram.appendTextLine("Maquina3");
  411. TextLine test4 = hologram.appendTextLine("Maquina4");
  412. test.setText("§fMaquina De §9" + tipo);
  413. test2.setText("§fDono §6" + p.getPlayer().getName());
  414. test3.setText("§fStatus §4Desativado");
  415. test4.setText("§fLv §6" + lvl);
  416. p.sendMessage("Maquina de " + tipo + " colocada com sucesso");
  417. sta.executeUpdate("INSERT INTO " + table_prefix + "_maquina (player, world, x, y, z, combu, lvl, tipo, multi) VALUES ('" + e.getPlayer().getName() + "', '" + bloco.getWorld().getName() + "', '" + bloco.getLocation().getBlockX() + "', '" + bloco.getLocation().getBlockY() + "', '" + bloco.getLocation().getBlockZ() + "', '0', '" + lvl + "', '" + tipo + "', '1')");
  418. } catch (Exception e2) {
  419. e2.printStackTrace();
  420. }
  421. }
  422. }
  423. }
  424. @EventHandler
  425. public void Clicanamaquina(PlayerInteractEvent e) {
  426. Player p = e.getPlayer();
  427. BlockInfo.put(p, p.getTargetBlock((Set < Material > ) null, 5));
  428. try {
  429. ResultSet rs = sta.executeQuery("SELECT * FROM " + table_prefix + "_maquina WHERE x = '" + BlockInfo.get(p).getLocation().getBlockX() + "' AND y = '" + BlockInfo.get(p).getLocation().getBlockY() + "' AND z = '" + BlockInfo.get(p).getLocation().getBlockZ() + "' AND world = '" + BlockInfo.get(p).getLocation().getWorld().getName() + "';");
  430. if (rs.next()) {
  431. Integer Drops = 0;
  432. Integer Alex = 0;
  433. Integer lvl = rs.getInt("lvl");
  434. String tipo = rs.getString("tipo");
  435. String Player = rs.getString("player");
  436. if (Player.equals(p.getPlayer().getName())) {
  437. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
  438. for (String lvls: getConfig().getStringList("Levels")) {
  439. if (lvl == Integer.parseInt(lvls.split("\\\\")[0])) {
  440. Drops = Integer.parseInt(lvls.split("\\\\")[1]);
  441. Alex = Integer.parseInt(getConfig().getString("Maquinas." + tipo + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0]);
  442. Inventory inv = Bukkit.createInventory(null, 27, "Maquina De " + tipo); {
  443. inv.setItem(13, ItemGet("331", 1, "[N]{&cClique para da upgrade}[N]"));
  444. inv.setItem(4, ItemGet("340", 1, "[N]{&cUpdate Da Maquina De @maquina}[N][L]{||&fLv Da Maquina &6@lvl||&fQuantidade De Drop &6@Drops||&fQuantas vezes vai dropa &6@Quant||&fTempo de cada drop &6@Temp &fSegundo(s)||||&fPreço Do Update &6$@money}[L]".replace("@lvl", Integer.toString(lvl)).replace("@maquina", tipo).replace("@Drops", Integer.toString(Drops)).replace("@Quant", lvls.split("\\\\")[3]).replace("@Temp", lvls.split("\\\\")[2]).replace("@money", Integer.toString(Alex))));
  445. inv.setItem(1, ItemGet("85", 1, "[N]{&4Cerca}[N][L]{||&7Cerca para proteger a maquina}[L]"));
  446. inv.setItem(7, ItemGet("102", 1, "[N]{&4Holograma 1.8+}[N][L]{||&7Holograma da maquina}[L]"));
  447. inv.setItem(16, ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]"));
  448. inv.setItem(16, ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]"));
  449. if (HologramaStatus.get(BlockInfo.get(p)) == null) {
  450. HologramaStatus.put(BlockInfo.get(p), false);
  451. }
  452. if (CercaStatus.get(BlockInfo.get(p)) == null) {
  453. CercaStatus.put(BlockInfo.get(p), VeriCerca(BlockInfo.get(p)));
  454. }
  455. if (CercaStatus.get(BlockInfo.get(p)) == false) {
  456. inv.setItem(10, ItemGet("35:5", 1, "[N]{&a&lAtivar Cerca}[N]"));
  457. } else {
  458. inv.setItem(10, ItemGet("35:14", 1, "[N]{&4&lDesativar Cerca}[N]"));
  459. }
  460. if (HologramaStatus.get(BlockInfo.get(p)) == false) {
  461. inv.setItem(16, ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]"));;
  462. } else {
  463. inv.setItem(16, ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]"));
  464. }
  465. }
  466. p.openInventory(inv);
  467. }
  468. }
  469. }
  470. } else {
  471. p.sendMessage("§aEstá maquina pertence ao " + Player);
  472. }
  473. }
  474. } catch (Exception e2) {
  475. e2.printStackTrace();
  476. }
  477. }
  478. @EventHandler
  479. public void Combus(PlayerInteractEvent e) {
  480. Player p = e.getPlayer();
  481. ItemStack hand = p.getItemInHand();
  482. int amount = hand.getAmount();
  483. Block bloco = p.getTargetBlock((Set < Material > ) null, 5);
  484. for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
  485. for (String com: getConfig().getStringList("Maquinas." + maquinas + ".Combustiveis")) {
  486. if (e.getPlayer().getItemInHand().isSimilar(ItemGet(com.split("\\\\")[0], 1, com.split("\\\\")[1]))) {
  487. e.setCancelled(true);
  488. if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
  489. if (MaquinaAtiva.get(bloco.getLocation()) == null || !MaquinaAtiva.get(bloco.getLocation())) {
  490. try {
  491. ResultSet rs = sta.executeQuery("SELECT * FROM " + table_prefix + "_maquina WHERE x = '" + bloco.getLocation().getBlockX() + "' AND y = '" + bloco.getLocation().getBlockY() + "' AND z = '" + bloco.getLocation().getBlockZ() + "' AND world = '" + bloco.getLocation().getWorld().getName() + "';");
  492. if (rs.next()) {
  493. if (amount > 1) {
  494. hand.setAmount(amount - 1);
  495. } else {
  496. p.setItemInHand(new ItemStack(Material.AIR));
  497. }
  498. p.sendMessage("Você colocou combustivel na maquina");
  499. sta.executeUpdate("UPDATE " + table_prefix + "_maquina SET multi = '" + com.split("\\\\")[2] + "' WHERE x = '" + bloco.getLocation().getBlockX() + "' AND y = '" + bloco.getLocation().getBlockY() + "' AND z = '" + bloco.getLocation().getBlockZ() + "' AND world = '" + bloco.getLocation().getWorld().getName() + "';");
  500. this.startmaquinas(bloco.getLocation().add(+0.5, 2, +0.5), p, bloco);
  501. }
  502. } catch (Exception e2) {
  503. e2.printStackTrace();
  504. }
  505. } else {
  506. p.sendMessage("Sua maquina já está ativa");
  507. }
  508. }
  509. }
  510. }
  511. }
  512. }
  513. private void startmaquinas(Location l, Player p, Block b) {
  514. MaquinaAtiva.put(b.getLocation(), true);
  515. hologram.clearLines();
  516. MaquinaStatus(b, p, 1);
  517. try {
  518. ResultSet rs = sta.executeQuery("SELECT * FROM " + table_prefix + "_maquina WHERE x = '" + b.getLocation().getBlockX() + "' AND y = '" + b.getLocation().getBlockY() + "' AND z = '" + b.getLocation().getBlockZ() + "' AND world = '" + b.getLocation().getWorld().getName() + "';");
  519. if (rs.next()) {
  520. for (String lvls: getConfig().getStringList("Levels")) {
  521. Integer tempo = Integer.parseInt(lvls.split("\\\\")[2]);
  522. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  523. int seconds = Integer.parseInt(lvls.split("\\\\")[3]);
  524. Integer Drops = 0;
  525. Integer hero = rs.getInt("multi");
  526. Integer lvl = rs.getInt("lvl");
  527. public void run() {
  528. for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
  529. for (String item: getConfig().getStringList("Maquinas." + maquinas + ".drops")) {
  530. if (lvl == Integer.parseInt(lvls.split("\\\\")[0])) {
  531. Drops = Integer.parseInt(lvls.split("\\\\")[1]) * (hero);
  532. if (seconds >= 0) {
  533. b.getLocation().getWorld().dropItem(b.getLocation(), new ItemStack(ItemGet(item.split("\\\\")[0], Drops, item.split("\\\\")[1])));
  534. seconds--;
  535. }
  536. if (seconds == 0) {
  537. p.sendMessage("Sua maquina parou de funcionar");
  538. MaquinaAtiva.put(b.getLocation(), false);
  539. seconds--;
  540. MaquinaStatus(b, p, 0);
  541. MaquinaStatus(b, p, 2);
  542. }
  543. }
  544. }
  545. }
  546. }
  547. }, 0L, tempo * 20L);
  548. }
  549. }
  550. } catch (Exception e2) {
  551. e2.printStackTrace();
  552. }
  553. }
  554. @SuppressWarnings("deprecation")
  555. public ItemStack ItemGet(String id, Integer quantidade, String meta) {
  556. Short ID = 0;
  557. Short Data = 0;
  558. if (id.contains(":")) {
  559. String[] IDData = id.split(":");
  560. ID = Short.valueOf(IDData[0]);
  561. Data = Short.valueOf(IDData[1]);
  562. } else {
  563. ID = Short.valueOf(id);
  564. Data = 0;
  565. }
  566. ItemStack Item = new ItemStack(ID);
  567. ItemMeta Meta = Item.getItemMeta();
  568. if (meta.contains("[E]{") && meta.contains("}[E]")) {
  569. for (String EncaBase: Arrays.asList(meta.split("\\[E]\\{")[1].split("\\}\\[E]")[0].split(","))) {
  570. String[] EncaPut = EncaBase.split(":");
  571. Meta.addEnchant(Enchantment.getById(Integer.parseInt(EncaPut[0])), Integer.parseInt(EncaPut[1]), true);
  572. }
  573. }
  574. if (meta.contains("[L]{") && meta.contains("}[L]")) {
  575. Meta.setLore(Arrays.asList(meta.split("\\[L]\\{")[1].split("\\}\\[L]")[0].replace("&", "§").split("(\\|\\|)")));
  576. }
  577. if (meta.contains("[N]{") && meta.contains("}[N]")) {
  578. Meta.setDisplayName(meta.split("\\[N]\\{")[1].split("\\}\\[N]")[0].replace("&", "§"));
  579. }
  580. if (meta.contains("[P]{") && meta.contains("}[P]") && (ID == 373 || ID == 438 || ID == 441)) {
  581. PotionMeta PMeta = (PotionMeta) Meta;
  582. for (String PosinBase: Arrays.asList(meta.split("\\[P]\\{")[1].split("\\}\\[P]")[0].split(","))) {
  583. String[] PosinPut = PosinBase.split(":");
  584. PMeta.addCustomEffect(new PotionEffect(PotionEffectType.getById(Integer.parseInt(PosinPut[0])), Integer.parseInt(PosinPut[1]), Integer.parseInt(PosinPut[2])), true);
  585. }
  586. Item.setItemMeta(PMeta);
  587. } else {
  588. Item.setItemMeta(Meta);
  589. }
  590. Item.setDurability(Data);
  591. Item.setAmount(quantidade);
  592. return (Item);
  593. }
  594. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement