Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Maquinas.alex;
- import java.io.File;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Set;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockPlaceEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.inventory.meta.PotionMeta;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import com.gmail.filoghost.holographicdisplays.api.Hologram;
- import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
- import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
- import net.milkbowl.vault.economy.Economy;
- import java.sql.Connection;
- import java.sql.Statement;
- public class Main extends JavaPlugin implements Listener {
- Connection c = null;
- Statement sta = null;
- String table_prefix = null;
- Main main = this;
- public HashMap < String, List < Location >> Maquinas = new HashMap < > ();
- Integer maquinasloop = null;
- private HashMap < Location, Boolean > MaquinaAtiva = new HashMap < > ();
- private HashMap < Block, Boolean > CercaStatus = new HashMap < > ();
- private HashMap < Block, Boolean > HologramaStatus = new HashMap < > ();
- private HashMap < Player, Block > BlockInfo = new HashMap < > ();
- public static Economy dinheiro = null;
- public static Hologram hologram;
- public void onEnable() {
- main = this;
- PluginManager pm = getServer().getPluginManager();
- pm.registerEvents(this, this);
- Dados();
- saveDefaultConfig();
- setupEconomy();
- if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
- getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
- getLogger().severe("*** This plugin will be disabled. ***");
- this.setEnabled(false);
- return;
- }
- }
- public void onDisable() {
- try {
- c.close();
- } catch (Exception e) {}
- try {
- sta.close();
- } catch (Exception e) {}
- }
- public static boolean setupEconomy() {
- if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
- return false;
- }
- RegisteredServiceProvider < Economy > rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
- if (rsp == null) {
- return false;
- }
- dinheiro = rsp.getProvider();
- return dinheiro != null;
- }
- private void Dados() {
- try {
- if (getConfig().getString("MySQL.Ativo").equalsIgnoreCase("Sim")) {
- 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"));
- table_prefix = getConfig().getString("MySQL.Prefix");
- } else {
- File db = new File("plugins/" + getDescription().getName() + "/Dados.db");
- if (!db.exists()) {
- db.createNewFile();
- }
- Class.forName("org.sqlite.JDBC");
- c = DriverManager.getConnection("jdbc:sqlite:plugins/" + getDescription().getName() + "/Dados.db");
- table_prefix = "Maquinas";
- }
- sta = c.createStatement();
- 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));");
- } catch (Exception e) {
- Bukkit.getPluginManager().disablePlugin(this);
- }
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (!(sender instanceof Player)) {
- return true;
- }
- Player p = (Player) sender;
- if (cmd.getName().equalsIgnoreCase("emaquinas")) {
- if (p.hasPermission("admin.use")) {
- for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
- for (String update: getConfig().getStringList("Maquinas." + maquinas + ".Updates")) {
- for (String comb: getConfig().getStringList("Maquinas." + maquinas + ".Combustiveis")) {
- ItemStack m2 = new ItemStack(ItemGet(update.split("\\\\")[0], 1, update.split("\\\\")[1]));
- ItemStack m3 = new ItemStack(ItemGet(comb.split("\\\\")[0], 1, comb.split("\\\\")[1]));
- p.getPlayer().getInventory().addItem(m3);
- p.getPlayer().getInventory().addItem(m2);
- ItemStack MaquinaItem = ItemGet(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[0], 1, getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[1].replace("@lvl", "1"));
- ItemMeta MIM = MaquinaItem.getItemMeta();
- List < String > Lore = MIM.getLore();
- Lore.add("§0{1}[" + maquinas + "]");
- MIM.setLore(Lore);
- MaquinaItem.setItemMeta(MIM);
- p.getPlayer().getInventory().addItem(MaquinaItem);
- }
- }
- }
- }else {
- p.sendMessage("§cVocê não tem permissão para digitar esté comando");
- }
- }
- return false;
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void Click(InventoryClickEvent e) {
- for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
- Player p = (Player) e.getWhoClicked();
- Double balance = dinheiro.getBalance(p.getName());
- if (e.getInventory().getName().equals("Maquina De " + maquinas)) {
- e.setCancelled(true);
- if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("331", 1, "[N]{&cClique para da upgrade}[N]"))) {
- try {
- 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() + "';");
- if (rs.next()) {
- Integer lvl = rs.getInt("lvl");
- for (String lvls: getConfig().getStringList("Levels")) {
- if (lvl == Integer.parseInt(lvls.split("\\\\")[0])) {
- if (lvl != getConfig().getInt("Maquinas." + maquinas + ".LevelMax")) {
- if (MaquinaAtiva.get(BlockInfo.get(p).getLocation()) == null || !MaquinaAtiva.get(BlockInfo.get(p).getLocation())) {
- if (balance >= Integer.parseInt(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0])) {
- 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() + "';");
- p.sendMessage("Você colocou update na maquina de " + maquinas + " agora ela está no lv." + (lvl + 1));
- hologram.clearLines();
- MaquinaStatus(BlockInfo.get(p), p, 2);
- dinheiro.withdrawPlayer(p.getName(), Integer.parseInt(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0]));
- p.closeInventory();
- } else {
- p.sendMessage("§cVocê não tem $" + Integer.parseInt(getConfig().getString("Maquinas." + maquinas + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0]) + " para da update");
- }
- } else {
- p.sendMessage("§cVocê não pode da update enquanto a maquina está ativa");
- }
- } else {
- p.sendMessage("§cSua maquina já está no level máximo");
- }
- }
- }
- }
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:5", 1, "[N]{&a&lAtivar Cerca}[N]"))) {
- CercaStatus.put(BlockInfo.get(p), true);
- Cerca(BlockInfo.get(p));
- ItemStack item = ItemGet("35:14", 1, "[N]{&4&lDesativar Cerca}[N]");
- e.getInventory().getContents()[10].setType(item.getType());
- e.getInventory().getContents()[10].setItemMeta(item.getItemMeta());
- p.closeInventory();
- }
- if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:14", 1, "[N]{&4&lDesativar Cerca}[N]"))) {
- CercaStatus.put(BlockInfo.get(p), false);
- CercaRemove(BlockInfo.get(p));
- ItemStack item = ItemGet("35:5", 1, "[N]{&a&lAtivar Cerca}[N]");
- e.getInventory().getContents()[10].setType(item.getType());
- e.getInventory().getContents()[10].setItemMeta(item.getItemMeta());
- p.closeInventory();
- }
- if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]"))) {
- HologramaStatus.put(BlockInfo.get(p), true);
- if (MaquinaAtiva.get(BlockInfo.get(p).getLocation()) == null || !MaquinaAtiva.get(BlockInfo.get(p).getLocation())) {
- MaquinaStatus(BlockInfo.get(p), p, 0);
- MaquinaStatus(BlockInfo.get(p), p, 2);
- } else {
- MaquinaStatus(BlockInfo.get(p), p, 0);
- MaquinaStatus(BlockInfo.get(p), p, 1);
- }
- ItemStack item = ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]");
- e.getInventory().getContents()[16].setType(item.getType());
- e.getInventory().getContents()[16].setItemMeta(item.getItemMeta());
- p.closeInventory();
- }
- if (e.getCurrentItem() != null && e.getCurrentItem().isSimilar(ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]"))) {
- HologramaStatus.put(BlockInfo.get(p), false);
- MaquinaStatus(BlockInfo.get(p), p, 0);
- ItemStack item = ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]");
- e.getInventory().getContents()[16].setType(item.getType());
- e.getInventory().getContents()[16].setItemMeta(item.getItemMeta());
- p.closeInventory();
- }
- }
- }
- }
- private void Cerca(Block b) {
- World world = b.getLocation().getWorld();
- double locX = b.getLocation().getX();
- double locZ = b.getLocation().getZ();
- locX -= 3;
- locZ -= 3;
- for (int i = 0; i <= 5; i++) {
- locX += 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.FENCE);
- }
- for (int i = 0; i <= 5; i++) {
- locZ += 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.FENCE);
- }
- for (int i = 0; i <= 5; i++) {
- locX -= 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.FENCE);
- }
- for (int i = 0; i <= 5; i++) {
- locZ -= 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.FENCE);
- }
- }
- private void CercaRemove(Block b) {
- World world = b.getLocation().getWorld();
- double locX = b.getLocation().getX();
- double locZ = b.getLocation().getZ();
- locX -= 3;
- locZ -= 3;
- for (int i = 0; i <= 5; i++) {
- locX += 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.AIR);
- }
- for (int i = 0; i <= 5; i++) {
- locZ += 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.AIR);
- }
- for (int i = 0; i <= 5; i++) {
- locX -= 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.AIR);
- }
- for (int i = 0; i <= 5; i++) {
- locZ -= 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- xs.getBlock().setType(Material.AIR);
- }
- }
- private boolean VeriCerca(Block b) {
- World world = b.getLocation().getWorld();
- double locX = b.getLocation().getX();
- double locZ = b.getLocation().getZ();
- locX -= 3;
- locZ -= 3;
- for (int i = 0; i <= 5; i++) {
- locX += 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- if (xs.getBlock().getType() == Material.FENCE) {
- return true;
- }
- }
- for (int i = 0; i <= 5; i++) {
- locZ += 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- if (xs.getBlock().getType() == Material.FENCE) {
- return true;
- }
- }
- for (int i = 0; i <= 5; i++) {
- locX -= 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- if (xs.getBlock().getType() == Material.FENCE) {
- return true;
- }
- }
- for (int i = 0; i <= 5; i++) {
- locZ -= 1;
- Location xs = new Location(world, locX, b.getLocation().getY(), locZ);
- if (xs.getBlock().getType() == Material.FENCE) {
- return true;
- }
- }
- return false;
- }
- private void MaquinaStatus(Block b, Player p, Integer s) {
- if (s == 0) {
- for (Hologram hologram: HologramsAPI.getHolograms((Plugin) this)) {
- Location hologramLoc = hologram.getLocation();
- if (b.getLocation().add(0.5, 2.5, 0.5).distance(hologramLoc) < 0.5) {
- hologram.delete();
- }
- }
- } else {
- try {
- 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() + "';");
- if (rs.next()) {
- Integer lvl = rs.getInt("lvl");
- String Player = rs.getString("player");
- String tipo = rs.getString("tipo");
- Location local = b.getLocation().add(0.5, 2.5, 0.5);
- hologram = HologramsAPI.createHologram(this, local);
- TextLine test = hologram.appendTextLine("Maquina");
- TextLine test2 = hologram.appendTextLine("Maquina2");
- TextLine test3 = hologram.appendTextLine("Maquina3");
- TextLine test4 = hologram.appendTextLine("Maquina4");
- test.setText("§fMaquina De §9" + tipo);
- test2.setText("§fDono §6" + Player);
- test3.setText("§fStatus " + ((s == 1) ? "§aAtivo" : "§4Desativado"));
- test4.setText("§fLv " + (lvl));
- }
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- }
- @EventHandler
- public void QuebraMaquina(BlockBreakEvent e) {
- if (e.getPlayer() instanceof Player) {
- Player p = e.getPlayer();
- Block bloco = e.getBlock();
- if (MaquinaAtiva.get(bloco.getLocation()) == null || !MaquinaAtiva.get(bloco.getLocation())) {
- try {
- 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() + "';");
- if (rs.next()) {
- e.setCancelled(true);
- e.getBlock().getWorld().getBlockAt(e.getBlock().getLocation()).setType(Material.AIR);
- String lvl = rs.getString("lvl");
- String tipo = rs.getString("tipo");
- 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() + "';");
- p.sendMessage("Está maquina foi removida com sucesso");
- ItemStack MaquinaItem = ItemGet(getConfig().getString("Maquinas." + tipo + ".item").split("\\\\")[0], 1, getConfig().getString("Maquinas." + tipo + ".item").split("\\\\")[1].replace("@lvl", lvl));
- ItemMeta MIM = MaquinaItem.getItemMeta();
- List < String > Lore = MIM.getLore();
- Lore.add("§0{" + lvl + "}[" + tipo + "]");
- MIM.setLore(Lore);
- MaquinaItem.setItemMeta(MIM);
- e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), MaquinaItem);
- MaquinaStatus(bloco, p, 0);
- CercaStatus.put(bloco, null);
- HologramaStatus.put(bloco, null);
- }
- MaquinaAtiva.put(bloco.getLocation(), false);
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- } else {
- e.setCancelled(true);
- p.sendMessage("§4Você não pode quebra a maquina enquanto ela está ativa");
- }
- }
- }
- @EventHandler
- public void ColocaMaquina(BlockPlaceEvent e) {
- if (e.getPlayer() instanceof Player) {
- Player p = e.getPlayer();
- Block bloco = e.getBlockPlaced();
- String tipo = "";
- String lvl = "1";
- for (String lore: e.getPlayer().getItemInHand().getItemMeta().getLore()) {
- if (lore.contains("§0{") && lore.contains("}[") && lore.contains("]")) {
- lvl = lore.split("\\{")[1].split("\\}")[0];
- tipo = lore.split("\\[")[1].split("\\]")[0];
- }
- }
- if (!(tipo.equals(""))) {
- try {
- CercaStatus.put(bloco, false);
- HologramaStatus.put(bloco, true);
- Location local = bloco.getLocation().add(0.5, 2.5, 0.5);
- hologram = HologramsAPI.createHologram(this, local);
- TextLine test = hologram.appendTextLine("Maquina");
- TextLine test2 = hologram.appendTextLine("Maquina2");
- TextLine test3 = hologram.appendTextLine("Maquina3");
- TextLine test4 = hologram.appendTextLine("Maquina4");
- test.setText("§fMaquina De §9" + tipo);
- test2.setText("§fDono §6" + p.getPlayer().getName());
- test3.setText("§fStatus §4Desativado");
- test4.setText("§fLv §6" + lvl);
- p.sendMessage("Maquina de " + tipo + " colocada com sucesso");
- 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')");
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- }
- }
- @EventHandler
- public void Clicanamaquina(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- BlockInfo.put(p, p.getTargetBlock((Set < Material > ) null, 5));
- try {
- 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() + "';");
- if (rs.next()) {
- Integer Drops = 0;
- Integer Alex = 0;
- Integer lvl = rs.getInt("lvl");
- String tipo = rs.getString("tipo");
- String Player = rs.getString("player");
- if (Player.equals(p.getPlayer().getName())) {
- if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
- for (String lvls: getConfig().getStringList("Levels")) {
- if (lvl == Integer.parseInt(lvls.split("\\\\")[0])) {
- Drops = Integer.parseInt(lvls.split("\\\\")[1]);
- Alex = Integer.parseInt(getConfig().getString("Maquinas." + tipo + ".item").split("\\\\")[2]) * Integer.parseInt(lvls.split("\\\\")[0]);
- Inventory inv = Bukkit.createInventory(null, 27, "Maquina De " + tipo); {
- inv.setItem(13, ItemGet("331", 1, "[N]{&cClique para da upgrade}[N]"));
- 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))));
- inv.setItem(1, ItemGet("85", 1, "[N]{&4Cerca}[N][L]{||&7Cerca para proteger a maquina}[L]"));
- inv.setItem(7, ItemGet("102", 1, "[N]{&4Holograma 1.8+}[N][L]{||&7Holograma da maquina}[L]"));
- inv.setItem(16, ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]"));
- inv.setItem(16, ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]"));
- if (HologramaStatus.get(BlockInfo.get(p)) == null) {
- HologramaStatus.put(BlockInfo.get(p), false);
- }
- if (CercaStatus.get(BlockInfo.get(p)) == null) {
- CercaStatus.put(BlockInfo.get(p), VeriCerca(BlockInfo.get(p)));
- }
- if (CercaStatus.get(BlockInfo.get(p)) == false) {
- inv.setItem(10, ItemGet("35:5", 1, "[N]{&a&lAtivar Cerca}[N]"));
- } else {
- inv.setItem(10, ItemGet("35:14", 1, "[N]{&4&lDesativar Cerca}[N]"));
- }
- if (HologramaStatus.get(BlockInfo.get(p)) == false) {
- inv.setItem(16, ItemGet("35:5", 1, "[N]{&a&lAtivar Holograma 1.8+}[N]"));;
- } else {
- inv.setItem(16, ItemGet("35:14", 1, "[N]{&4&lDesativar Holograma 1.8+}[N]"));
- }
- }
- p.openInventory(inv);
- }
- }
- }
- } else {
- p.sendMessage("§aEstá maquina pertence ao " + Player);
- }
- }
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- @EventHandler
- public void Combus(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- ItemStack hand = p.getItemInHand();
- int amount = hand.getAmount();
- Block bloco = p.getTargetBlock((Set < Material > ) null, 5);
- for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
- for (String com: getConfig().getStringList("Maquinas." + maquinas + ".Combustiveis")) {
- if (e.getPlayer().getItemInHand().isSimilar(ItemGet(com.split("\\\\")[0], 1, com.split("\\\\")[1]))) {
- e.setCancelled(true);
- if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
- if (MaquinaAtiva.get(bloco.getLocation()) == null || !MaquinaAtiva.get(bloco.getLocation())) {
- try {
- 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() + "';");
- if (rs.next()) {
- if (amount > 1) {
- hand.setAmount(amount - 1);
- } else {
- p.setItemInHand(new ItemStack(Material.AIR));
- }
- p.sendMessage("Você colocou combustivel na maquina");
- 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() + "';");
- this.startmaquinas(bloco.getLocation().add(+0.5, 2, +0.5), p, bloco);
- }
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- } else {
- p.sendMessage("Sua maquina já está ativa");
- }
- }
- }
- }
- }
- }
- private void startmaquinas(Location l, Player p, Block b) {
- MaquinaAtiva.put(b.getLocation(), true);
- hologram.clearLines();
- MaquinaStatus(b, p, 1);
- try {
- 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() + "';");
- if (rs.next()) {
- for (String lvls: getConfig().getStringList("Levels")) {
- Integer tempo = Integer.parseInt(lvls.split("\\\\")[2]);
- Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- int seconds = Integer.parseInt(lvls.split("\\\\")[3]);
- Integer Drops = 0;
- Integer hero = rs.getInt("multi");
- Integer lvl = rs.getInt("lvl");
- public void run() {
- for (String maquinas: getConfig().getConfigurationSection("Maquinas").getKeys(false)) {
- for (String item: getConfig().getStringList("Maquinas." + maquinas + ".drops")) {
- if (lvl == Integer.parseInt(lvls.split("\\\\")[0])) {
- Drops = Integer.parseInt(lvls.split("\\\\")[1]) * (hero);
- if (seconds >= 0) {
- b.getLocation().getWorld().dropItem(b.getLocation(), new ItemStack(ItemGet(item.split("\\\\")[0], Drops, item.split("\\\\")[1])));
- seconds--;
- }
- if (seconds == 0) {
- p.sendMessage("Sua maquina parou de funcionar");
- MaquinaAtiva.put(b.getLocation(), false);
- seconds--;
- MaquinaStatus(b, p, 0);
- MaquinaStatus(b, p, 2);
- }
- }
- }
- }
- }
- }, 0L, tempo * 20L);
- }
- }
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- @SuppressWarnings("deprecation")
- public ItemStack ItemGet(String id, Integer quantidade, String meta) {
- Short ID = 0;
- Short Data = 0;
- if (id.contains(":")) {
- String[] IDData = id.split(":");
- ID = Short.valueOf(IDData[0]);
- Data = Short.valueOf(IDData[1]);
- } else {
- ID = Short.valueOf(id);
- Data = 0;
- }
- ItemStack Item = new ItemStack(ID);
- ItemMeta Meta = Item.getItemMeta();
- if (meta.contains("[E]{") && meta.contains("}[E]")) {
- for (String EncaBase: Arrays.asList(meta.split("\\[E]\\{")[1].split("\\}\\[E]")[0].split(","))) {
- String[] EncaPut = EncaBase.split(":");
- Meta.addEnchant(Enchantment.getById(Integer.parseInt(EncaPut[0])), Integer.parseInt(EncaPut[1]), true);
- }
- }
- if (meta.contains("[L]{") && meta.contains("}[L]")) {
- Meta.setLore(Arrays.asList(meta.split("\\[L]\\{")[1].split("\\}\\[L]")[0].replace("&", "§").split("(\\|\\|)")));
- }
- if (meta.contains("[N]{") && meta.contains("}[N]")) {
- Meta.setDisplayName(meta.split("\\[N]\\{")[1].split("\\}\\[N]")[0].replace("&", "§"));
- }
- if (meta.contains("[P]{") && meta.contains("}[P]") && (ID == 373 || ID == 438 || ID == 441)) {
- PotionMeta PMeta = (PotionMeta) Meta;
- for (String PosinBase: Arrays.asList(meta.split("\\[P]\\{")[1].split("\\}\\[P]")[0].split(","))) {
- String[] PosinPut = PosinBase.split(":");
- PMeta.addCustomEffect(new PotionEffect(PotionEffectType.getById(Integer.parseInt(PosinPut[0])), Integer.parseInt(PosinPut[1]), Integer.parseInt(PosinPut[2])), true);
- }
- Item.setItemMeta(PMeta);
- } else {
- Item.setItemMeta(Meta);
- }
- Item.setDurability(Data);
- Item.setAmount(quantidade);
- return (Item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement