Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package www.headplay.es.Generadores;
- import java.util.ArrayList;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.Color;
- import org.bukkit.FireworkEffect;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.block.Sign;
- import org.bukkit.entity.Firework;
- import org.bukkit.entity.Player;
- import org.bukkit.entity.EntityType;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.block.SignChangeEvent;
- 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.FireworkMeta;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.util.Vector;
- public class IronGenerador extends JavaPlugin implements Listener{
- private static Inventory ironMenu;
- private ItemStack Info;
- private ItemStack Up;
- private ItemMeta InfoM;
- private ItemMeta UpM;
- private Location ironSign;
- public boolean gameStarted = true;
- HashMap<String, Location> ironSpawners = new HashMap<>();
- private static ArrayList<Location> signs;
- @Override
- public void onEnable(){
- getServer().getPluginManager().registerEvents(this, this);
- }
- public static void show(Player p) {
- p.openInventory(ironMenu);
- }
- public void up(Player player){
- Firework fw = (Firework)player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
- FireworkMeta fwmeta = fw.getFireworkMeta();
- FireworkEffect.Builder builder = FireworkEffect.builder();
- builder.withTrail();
- builder.withFlicker();
- builder.withColor(Color.WHITE);
- builder.withColor(Color.WHITE);
- builder.withColor(Color.WHITE);
- builder.withColor(Color.WHITE);
- builder.withColor(Color.SILVER);
- builder.withColor(Color.SILVER);
- builder.withColor(Color.SILVER);
- builder.withColor(Color.SILVER);
- builder.with(FireworkEffect.Type.BALL);
- fwmeta.addEffects(new FireworkEffect[] { builder.build() });
- fwmeta.setPower((int).9);
- fw.setFireworkMeta(fwmeta);
- }
- @EventHandler
- public void onPlaceSign(SignChangeEvent s) {
- Player p = s.getPlayer();
- ItemStack i = null;
- if (s.getLine(0).equalsIgnoreCase("[Hierro]")) {
- s.setLine(0, "§lGenerador");
- s.setLine(1, "§cHierro");
- s.setLine(2, "Nivel 1");
- s.setLine(3, "§7Click Derecho");
- Location spawner = s.getBlock().getLocation();
- ironSpawners.put("spawner", spawner);
- i = new ItemStack(Material.IRON_BLOCK);
- int z = p.getLocation().getBlockX();
- int y = p.getLocation().getBlockY();
- int x = p.getLocation().getBlockZ();
- s.getBlock().getLocation().getWorld().getBlockAt(x - 1, y, z).setType(i.getType());
- }
- }
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
- if (e.getClickedBlock().getState() instanceof Sign) {
- final Sign s = (Sign) e.getClickedBlock().getState();
- if (s.getLine(1).equalsIgnoreCase("§cHierro")) {
- ironSign = ironSpawners.get("spawner");
- Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @Override
- public void run() {
- if (s.getLine(2).equalsIgnoreCase("Nivel 1")) {
- ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
- }
- }
- }, 0L, 4 * 20L);
- Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @Override
- public void run() {
- if (s.getLine(2).equalsIgnoreCase("Nivel 2")) {
- ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
- }
- }
- }, 0L, 3 * 20L);
- Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @Override
- public void run() {
- if (s.getLine(2).equalsIgnoreCase("Nivel 3")) {
- ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
- }
- }
- }, 0L, 2 * 20L);
- Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
- @Override
- public void run() {
- if (s.getLine(2).equalsIgnoreCase("Nivel 4")) {
- ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
- }
- }
- }, 0L, 20L);
- }
- if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 1"))) {
- ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 1");
- //Nivel 1
- Info = new ItemStack(Material.IRON_INGOT);
- InfoM = Info.getItemMeta();
- InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 1");
- ArrayList<String> InfoL = new ArrayList<>();
- InfoL.add("§9Produccion: 1.0 segundos");
- InfoM.setLore(InfoL);
- Info.setItemMeta(InfoM);
- Up = new ItemStack(Material.EXP_BOTTLE);
- UpM = Up.getItemMeta();
- UpM.setDisplayName("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 2");
- ArrayList<String> UpL = new ArrayList<>();
- UpL.add("§9Produccion: 0.75 segundos");
- UpL.add("§r");
- UpL.add("§3Costo: §e20 §2Hierro");
- UpM.setLore(UpL);
- Up.setItemMeta(UpM);
- ironMenu.setItem(11, Info);
- ironMenu.setItem(15, Up);
- show(p);
- }
- if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 2"))){
- ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 2");
- //Nivel 2
- Info = new ItemStack(Material.IRON_INGOT);
- InfoM = Info.getItemMeta();
- InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 2");
- ArrayList<String> InfoL = new ArrayList<>();
- InfoL.add("§9Produccion: 0.75 segundos");
- InfoM.setLore(InfoL);
- Info.setItemMeta(InfoM);
- Up = new ItemStack(Material.EXP_BOTTLE);
- UpM = Up.getItemMeta();
- UpM.setDisplayName("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 3");
- ArrayList<String> UpL = new ArrayList<>();
- UpL.add("§9Produccion: 0.5 segundos");
- UpL.add("§r");
- UpL.add("§3Costo: §e20 §2Oro");
- UpM.setLore(UpL);
- Up.setItemMeta(UpM);
- ironMenu.setItem(11, Info);
- ironMenu.setItem(15, Up);
- show(p);
- }
- if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 3"))){
- ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 3");
- //Nivel 3
- Info = new ItemStack(Material.IRON_INGOT);
- InfoM = Info.getItemMeta();
- InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 3");
- ArrayList<String> InfoL = new ArrayList<>();
- InfoL.add("§9Produccion: 0.5 segundos");
- InfoM.setLore(InfoL);
- Info.setItemMeta(InfoM);
- Up = new ItemStack(Material.EXP_BOTTLE);
- UpM = Up.getItemMeta();
- UpM.setDisplayName("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 4");
- ArrayList<String> UpL = new ArrayList<>();
- UpL.add("§9Produccion: 0.25 segundos");
- UpL.add("§r");
- UpL.add("§3Costo: §e50 §2Oro");
- UpM.setLore(UpL);
- Up.setItemMeta(UpM);
- ironMenu.setItem(11, Info);
- ironMenu.setItem(15, Up);
- show(p);
- }
- if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 4"))){
- ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 4");
- //Nivel 3
- Info = new ItemStack(Material.IRON_INGOT);
- InfoM = Info.getItemMeta();
- InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 4");
- ArrayList<String> InfoL = new ArrayList<>();
- InfoL.add("§9Produccion: 0.25 segundos");
- InfoM.setLore(InfoL);
- Info.setItemMeta(InfoM);
- Up = new ItemStack(Material.EXP_BOTTLE);
- UpM = Up.getItemMeta();
- UpM.setDisplayName("§2Nivel Maximo");
- Up.setItemMeta(UpM);
- ironMenu.setItem(11, Info);
- ironMenu.setItem(15, Up);
- show(p);
- }
- }
- }
- @EventHandler
- public void onInventoryClick(InventoryClickEvent e) {
- Player p = (Player) e.getWhoClicked();
- if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 2")) {
- e.setCancelled(true);
- if (p.getInventory().contains(Material.IRON_INGOT, 20)) {
- p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.IRON_INGOT, 20) });
- p.getLocation().getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
- Sign s = (Sign) ironSign.getBlock().getState();
- s.setLine(2, "Nivel 2");
- s.update();
- p.closeInventory();
- }
- else {
- p.sendMessage("§cNo tienes suficiente hierro!");
- p.closeInventory();
- }
- }
- if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 3")) {
- e.setCancelled(true);
- if (p.getInventory().contains(Material.GOLD_INGOT, 20)) {
- p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.GOLD_INGOT, 20) });
- p.getLocation().getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
- Sign s = (Sign) ironSign.getBlock().getState();
- s.setLine(2, "Nivel 3");
- s.update();
- up(p);
- p.closeInventory();
- }
- else {
- p.sendMessage("§cNo tienes suficiente oro!");
- p.closeInventory();
- }
- }
- if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 4")) {
- e.setCancelled(true);
- if (p.getInventory().contains(Material.GOLD_INGOT, 50)) {
- p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.GOLD_INGOT, 50) });
- p.getLocation().getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
- Sign s = (Sign) ironSign.getBlock().getState();
- s.setLine(2, "Nivel 4");
- s.update();
- up(p);
- p.closeInventory();
- }
- else {
- p.sendMessage("§cNo tienes suficiente oro!");
- p.closeInventory();
- }
- }
- else{
- e.setCancelled(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement