Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.78 KB | None | 0 0
  1. package www.headplay.es.Generadores;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Color;
  8. import org.bukkit.FireworkEffect;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.Sound;
  12. import org.bukkit.block.Sign;
  13. import org.bukkit.entity.Firework;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.entity.EntityType;
  16. import org.bukkit.event.EventHandler;
  17. import org.bukkit.event.Listener;
  18. import org.bukkit.event.block.Action;
  19. import org.bukkit.event.block.SignChangeEvent;
  20. import org.bukkit.event.inventory.InventoryClickEvent;
  21. import org.bukkit.event.player.PlayerInteractEvent;
  22. import org.bukkit.inventory.Inventory;
  23. import org.bukkit.inventory.ItemStack;
  24. import org.bukkit.inventory.meta.FireworkMeta;
  25. import org.bukkit.inventory.meta.ItemMeta;
  26. import org.bukkit.plugin.Plugin;
  27. import org.bukkit.plugin.java.JavaPlugin;
  28. import org.bukkit.util.Vector;
  29.  
  30. public class IronGenerador extends JavaPlugin implements Listener{
  31.    
  32.     private static Inventory ironMenu;
  33.     private ItemStack Info;
  34.     private ItemStack Up;
  35.     private ItemMeta InfoM;
  36.        
  37.     private ItemMeta UpM;
  38.     private Location ironSign;
  39.     public boolean gameStarted = true;
  40.     HashMap<String, Location> ironSpawners = new HashMap<>();
  41.         private static ArrayList<Location> signs;
  42.    
  43.         @Override
  44.     public void onEnable(){
  45.         getServer().getPluginManager().registerEvents(this, this);
  46.     }  
  47.         public static void show(Player p) {
  48.                 p.openInventory(ironMenu);
  49.         }
  50.         public void up(Player player){
  51.             Firework fw = (Firework)player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
  52.             FireworkMeta fwmeta = fw.getFireworkMeta();
  53.             FireworkEffect.Builder builder = FireworkEffect.builder();
  54.             builder.withTrail();
  55.             builder.withFlicker();
  56.             builder.withColor(Color.WHITE);
  57.             builder.withColor(Color.WHITE);
  58.             builder.withColor(Color.WHITE);
  59.             builder.withColor(Color.WHITE);
  60.             builder.withColor(Color.SILVER);
  61.             builder.withColor(Color.SILVER);
  62.             builder.withColor(Color.SILVER);
  63.             builder.withColor(Color.SILVER);
  64.             builder.with(FireworkEffect.Type.BALL);
  65.            
  66.             fwmeta.addEffects(new FireworkEffect[] { builder.build() });
  67.             fwmeta.setPower((int).9);
  68.             fw.setFireworkMeta(fwmeta);
  69.         }
  70.            
  71.        
  72.         @EventHandler
  73.         public void onPlaceSign(SignChangeEvent s) {
  74.                 Player p = s.getPlayer();
  75.                 ItemStack i = null;
  76.             if (s.getLine(0).equalsIgnoreCase("[Hierro]")) {           
  77.                 s.setLine(0, "§lGenerador");
  78.                 s.setLine(1, "§cHierro");
  79.                 s.setLine(2, "Nivel 1");
  80.                 s.setLine(3, "§7Click Derecho");
  81.                
  82.                 Location spawner = s.getBlock().getLocation();
  83.                 ironSpawners.put("spawner", spawner);
  84.                 i = new ItemStack(Material.IRON_BLOCK);
  85.                 int z = p.getLocation().getBlockX();
  86.                 int y = p.getLocation().getBlockY();
  87.                 int x = p.getLocation().getBlockZ();
  88.                 s.getBlock().getLocation().getWorld().getBlockAt(x - 1, y, z).setType(i.getType());
  89.             }
  90.         }
  91.        
  92.         @EventHandler
  93.         public void onPlayerInteract(PlayerInteractEvent e) {
  94.             Player p = e.getPlayer();
  95.                 if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
  96.                    if (e.getClickedBlock().getState() instanceof Sign) {
  97.                        
  98.                         final Sign s = (Sign) e.getClickedBlock().getState();
  99.                        
  100.                         if (s.getLine(1).equalsIgnoreCase("§cHierro")) {
  101.                             ironSign = ironSpawners.get("spawner");
  102.                            
  103.                             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  104.                                 @Override
  105.                                 public void run() {
  106.                                     if (s.getLine(2).equalsIgnoreCase("Nivel 1")) {
  107.                                     ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
  108.                                     }
  109.                                 }
  110.                               }, 0L, 4 * 20L);
  111.                            
  112.                             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  113.                                 @Override
  114.                                 public void run() {
  115.                                     if (s.getLine(2).equalsIgnoreCase("Nivel 2")) {
  116.                                     ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
  117.                                     }
  118.                                 }
  119.                               }, 0L, 3 * 20L);
  120.                            
  121.                             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  122.                                 @Override
  123.                                 public void run() {
  124.                                     if (s.getLine(2).equalsIgnoreCase("Nivel 3")) {
  125.                                     ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
  126.                                     }
  127.                                 }
  128.                               }, 0L, 2 * 20L);
  129.                            
  130.                             Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  131.                                 @Override
  132.                                 public void run() {
  133.                                     if (s.getLine(2).equalsIgnoreCase("Nivel 4")) {
  134.                                     ironSign.getWorld().dropItemNaturally(ironSign, new ItemStack(Material.IRON_INGOT)).setVelocity(new Vector(0, 0, 0));
  135.                                     }
  136.                                 }
  137.                               }, 0L, 20L);
  138.                         }
  139.                        
  140.                         if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 1"))) {
  141.                            
  142.                             ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 1");
  143.                            
  144.                             //Nivel 1
  145.                             Info = new ItemStack(Material.IRON_INGOT);
  146.                             InfoM = Info.getItemMeta();        
  147.                             InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 1");                        
  148.                             ArrayList<String> InfoL = new ArrayList<>();
  149.                             InfoL.add("§9Produccion: 1.0 segundos");                          
  150.                             InfoM.setLore(InfoL);
  151.                             Info.setItemMeta(InfoM);
  152.                                    
  153.                             Up = new ItemStack(Material.EXP_BOTTLE);
  154.                             UpM = Up.getItemMeta();        
  155.                             UpM.setDisplayName("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 2");                        
  156.                             ArrayList<String> UpL = new ArrayList<>();
  157.                             UpL.add("§9Produccion: 0.75 segundos");
  158.                             UpL.add("§r");
  159.                             UpL.add("§3Costo: §e20 §2Hierro");                          
  160.                             UpM.setLore(UpL);
  161.                             Up.setItemMeta(UpM);
  162.                                
  163.                             ironMenu.setItem(11, Info);
  164.                             ironMenu.setItem(15, Up);
  165.                            
  166.                             show(p);
  167.                     }
  168.                        
  169.                         if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 2"))){
  170.      
  171.                             ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 2");
  172.                            
  173.                             //Nivel 2
  174.                             Info = new ItemStack(Material.IRON_INGOT);
  175.                             InfoM = Info.getItemMeta();        
  176.                             InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 2");                        
  177.                             ArrayList<String> InfoL = new ArrayList<>();
  178.                             InfoL.add("§9Produccion: 0.75 segundos");                         
  179.                             InfoM.setLore(InfoL);
  180.                             Info.setItemMeta(InfoM);
  181.                                    
  182.                             Up = new ItemStack(Material.EXP_BOTTLE);
  183.                             UpM = Up.getItemMeta();        
  184.                             UpM.setDisplayName("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 3");                        
  185.                             ArrayList<String> UpL = new ArrayList<>();
  186.                             UpL.add("§9Produccion: 0.5 segundos");
  187.                             UpL.add("§r");
  188.                             UpL.add("§3Costo: §e20 §2Oro");                         
  189.                             UpM.setLore(UpL);
  190.                             Up.setItemMeta(UpM);
  191.                                
  192.                             ironMenu.setItem(11, Info);
  193.                             ironMenu.setItem(15, Up);
  194.                            
  195.                             show(p);
  196.                     }
  197.                        
  198.                         if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 3"))){
  199.                    
  200.                             ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 3");
  201.                            
  202.                             //Nivel 3
  203.                             Info = new ItemStack(Material.IRON_INGOT);
  204.                             InfoM = Info.getItemMeta();        
  205.                             InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 3");                        
  206.                             ArrayList<String> InfoL = new ArrayList<>();
  207.                             InfoL.add("§9Produccion: 0.5 segundos");                          
  208.                             InfoM.setLore(InfoL);
  209.                             Info.setItemMeta(InfoM);
  210.                                    
  211.                             Up = new ItemStack(Material.EXP_BOTTLE);
  212.                             UpM = Up.getItemMeta();        
  213.                             UpM.setDisplayName("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 4");                        
  214.                             ArrayList<String> UpL = new ArrayList<>();
  215.                             UpL.add("§9Produccion: 0.25 segundos");
  216.                             UpL.add("§r");
  217.                             UpL.add("§3Costo: §e50 §2Oro");                         
  218.                             UpM.setLore(UpL);
  219.                             Up.setItemMeta(UpM);
  220.                                
  221.                             ironMenu.setItem(11, Info);
  222.                             ironMenu.setItem(15, Up);
  223.                            
  224.                             show(p);
  225.                     }
  226.                        
  227.                         if ((s.getLine(1).equalsIgnoreCase("§cHierro")) && (s.getLine(2).equalsIgnoreCase("Nivel 4"))){
  228.                            
  229.                             ironMenu = Bukkit.getServer().createInventory(null, 27, "§7Generador Hierro §2- Nivel 4");
  230.                            
  231.                             //Nivel 3
  232.                             Info = new ItemStack(Material.IRON_INGOT);
  233.                             InfoM = Info.getItemMeta();        
  234.                             InfoM.setDisplayName("§2Generador de §7Hierro §2- Nivel 4");                        
  235.                             ArrayList<String> InfoL = new ArrayList<>();
  236.                             InfoL.add("§9Produccion: 0.25 segundos");                         
  237.                             InfoM.setLore(InfoL);
  238.                             Info.setItemMeta(InfoM);
  239.                                    
  240.                             Up = new ItemStack(Material.EXP_BOTTLE);
  241.                             UpM = Up.getItemMeta();        
  242.                             UpM.setDisplayName("§2Nivel Maximo");
  243.                             Up.setItemMeta(UpM);
  244.                                
  245.                             ironMenu.setItem(11, Info);
  246.                             ironMenu.setItem(15, Up);
  247.                            
  248.                             show(p);
  249.                     }
  250.                 }
  251.         }
  252.        
  253.         @EventHandler
  254.         public void onInventoryClick(InventoryClickEvent e) {
  255.           Player p = (Player) e.getWhoClicked();
  256.            
  257.            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 2")) {
  258.                e.setCancelled(true);
  259.                
  260.                if (p.getInventory().contains(Material.IRON_INGOT, 20)) {
  261.                p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.IRON_INGOT, 20) });
  262.                p.getLocation().getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
  263.                
  264.                Sign s = (Sign) ironSign.getBlock().getState();
  265.                
  266.                s.setLine(2, "Nivel 2");
  267.                s.update();
  268.                
  269.                
  270.                p.closeInventory();
  271.                
  272.                }
  273.            
  274.            else {
  275.                  p.sendMessage("§cNo tienes suficiente hierro!");
  276.                      p.closeInventory();
  277.            }
  278.           }
  279.          
  280.            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 3")) {
  281.                e.setCancelled(true);
  282.                
  283.                if (p.getInventory().contains(Material.GOLD_INGOT, 20)) {
  284.                p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.GOLD_INGOT, 20) });
  285.                p.getLocation().getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
  286.                
  287.                Sign s = (Sign) ironSign.getBlock().getState();
  288.                
  289.                s.setLine(2, "Nivel 3");
  290.                s.update();
  291.                
  292.                up(p);
  293.                p.closeInventory();
  294.                }
  295.            
  296.            else {
  297.                  p.sendMessage("§cNo tienes suficiente oro!");
  298.                      p.closeInventory();
  299.             }
  300.            }
  301.            
  302.            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§2Mejorar a: §2Generador de §7Hierro §2- Nivel 4")) {
  303.                e.setCancelled(true);
  304.                
  305.                if (p.getInventory().contains(Material.GOLD_INGOT, 50)) {
  306.                p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.GOLD_INGOT, 50) });
  307.                p.getLocation().getWorld().playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
  308.                
  309.                Sign s = (Sign) ironSign.getBlock().getState();
  310.                
  311.                s.setLine(2, "Nivel 4");
  312.                s.update();
  313.                
  314.                up(p);
  315.                p.closeInventory();
  316.                
  317.                }
  318.            
  319.            else {
  320.                  p.sendMessage("§cNo tienes suficiente oro!");
  321.                      p.closeInventory();
  322.            }
  323.           }
  324.            
  325.            else{
  326.                e.setCancelled(true);
  327.               }
  328.     }
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement