Advertisement
Guest User

Listener

a guest
Apr 24th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.21 KB | None | 0 0
  1. package me.Afro_.SpecialArrows;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.entity.Arrow;
  8. import org.bukkit.entity.Entity;
  9. import org.bukkit.entity.Monster;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.entity.Projectile;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.entity.ProjectileHitEvent;
  15. import org.bukkit.event.inventory.InventoryClickEvent;
  16. import org.bukkit.inventory.Inventory;
  17. import org.bukkit.inventory.ItemStack;
  18. import org.bukkit.inventory.meta.ItemMeta;
  19. import org.bukkit.potion.PotionEffect;
  20. import org.bukkit.potion.PotionEffectType;
  21.  
  22. public class Listen implements Listener {
  23.  
  24.    
  25.     Inventory inv = Bukkit.getServer().createInventory(null, 18,
  26.             ChatColor.BLUE + "Arrow Effect Toggler");
  27.  
  28.     public void openGUI(Player player) {
  29.  
  30.         ItemStack explodei = new ItemStack(Material.TNT);
  31.         ItemMeta explodeiMeta = explodei.getItemMeta();
  32.         ItemStack lightningi = new ItemStack(Material.GOLD_AXE);
  33.         ItemMeta lightningiMeta = lightningi.getItemMeta();
  34.         ItemStack teleporti = new ItemStack(Material.ENDER_PEARL);
  35.         ItemMeta teleportiMeta = teleporti.getItemMeta();
  36.         ItemStack radiatei = new ItemStack(Material.ROTTEN_FLESH);
  37.         ItemMeta radiateiMeta = radiatei.getItemMeta();
  38.         ItemStack torchi = new ItemStack(Material.TORCH);
  39.         ItemMeta torchiMeta = torchi.getItemMeta();
  40.  
  41.         explodeiMeta.setDisplayName(ChatColor.RED + "Explode");
  42.         explodei.setItemMeta(explodeiMeta);
  43.  
  44.         lightningiMeta.setDisplayName(ChatColor.GOLD + "Lightning");
  45.         lightningi.setItemMeta(lightningiMeta);
  46.  
  47.         teleportiMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Teleport");
  48.         teleporti.setItemMeta(teleportiMeta);
  49.  
  50.         radiateiMeta.setDisplayName(ChatColor.DARK_GREEN + "Radiate");
  51.         radiatei.setItemMeta(radiateiMeta);
  52.  
  53.         torchiMeta.setDisplayName(ChatColor.YELLOW + "Torch");
  54.         torchi.setItemMeta(torchiMeta);
  55.  
  56.         // -2-4-6-8-
  57.  
  58.         inv.setItem(1, explodei);
  59.         inv.setItem(3, lightningi);
  60.         inv.setItem(5, teleporti);
  61.         inv.setItem(7, radiatei);
  62.         inv.setItem(13, torchi);
  63.  
  64.         player.openInventory(inv);
  65.     }
  66.    
  67.     @EventHandler
  68.     public void p(ProjectileHitEvent e) {
  69.         Projectile proj = e.getEntity();
  70.         Arrow arrow = (Arrow) proj;
  71.         final Player p = (Player) arrow.getShooter();
  72.         if (proj instanceof Arrow) {
  73.             if (arrow.getShooter() instanceof Player) {
  74.                 if (Main.explode.contains(p.getName())) {
  75.                     if (p.hasPermission("specialarrows.explode")) {
  76.                         if (Main.cooldown.contains(p.getName())) {
  77.                             p.sendMessage(ChatColor.RED
  78.                                     + "You must wait before using an effect again.");
  79.                             return;
  80.                         }
  81.                         arrow.getWorld()
  82.                                 .createExplosion(arrow.getLocation(), 5);
  83.                         Main.cooldown.add(p.getName());
  84.                         Bukkit.getServer().getScheduler()
  85.                                 .scheduleSyncDelayedTask(plugin, new Runnable() {
  86.                                     public void run() {
  87.                                         Main.cooldown.remove(p.getName());
  88.                                     }
  89.                                 }, 120);
  90.  
  91.                     }
  92.                 }
  93.                 if (Main.lightning.contains(p.getName())) {
  94.                     if (p.hasPermission("specialarrows.lightning")) {
  95.                         if (Main.cooldown.contains(p.getName())) {
  96.                             p.sendMessage(ChatColor.RED
  97.                                     + "You must wait before using an effect again.");
  98.                             return;
  99.                         }
  100.                         arrow.getWorld().strikeLightning(arrow.getLocation());
  101.                         Main.cooldown.add(p.getName());
  102.                         Bukkit.getServer().getScheduler()
  103.                                 .scheduleSyncDelayedTask(plugin, new Runnable() {
  104.                                     public void run() {
  105.                                         Main.cooldown.remove(p.getName());
  106.                                     }
  107.                                 }, 120);
  108.                     }
  109.                 }
  110.                 if (Main.teleport.contains(p.getName())) {
  111.                     if (p.hasPermission("specialarrows.teleport")) {
  112.                         if (Main.cooldown.contains(p.getName())) {
  113.                             p.sendMessage(ChatColor.RED
  114.                                     + "You must wait before using an effect again.");
  115.                             return;
  116.                         }
  117.                         p.teleport(arrow.getLocation());
  118.                         p.sendMessage(ChatColor.BLUE
  119.                                 + "You have been teleported!");
  120.                         Main.cooldown.add(p.getName());
  121.                         Bukkit.getServer().getScheduler()
  122.                                 .scheduleSyncDelayedTask(plugin, new Runnable() {
  123.                                     public void run() {
  124.                                         Main.cooldown.remove(p.getName());
  125.                                     }
  126.                                 }, 120);
  127.                         // 20 ticks = 1 second
  128.  
  129.                     }
  130.                 }
  131.                 if (Main.radiate.contains(p.getName())) {
  132.                     if (p.hasPermission("specialarrows.radiate")) {
  133.                         if (Main.cooldown.contains(p.getName())) {
  134.                             p.sendMessage(ChatColor.RED
  135.                                     + "You must wait before using an effect again.");
  136.                             return;
  137.                         }
  138.  
  139.                         for (Entity en : arrow.getNearbyEntities(5, 5, 5)) {
  140.  
  141.                             if (en instanceof Player || en instanceof Monster) {
  142.                                 ((Player) en).addPotionEffect(new PotionEffect(
  143.                                         PotionEffectType.POISON, 200, 1));
  144.                                 ((Monster) en)
  145.                                         .addPotionEffect(new PotionEffect(
  146.                                                 PotionEffectType.POISON, 200, 1));
  147.                                
  148.                                 ParticleEffect.SMOKE_LARGE.display(0, 0, 0, 5, 30, arrow.getLocation(), 10);
  149.                                
  150.                                 Main.cooldown.add(p.getName());
  151.                                 Bukkit.getServer()
  152.                                         .getScheduler()
  153.                                         .scheduleSyncDelayedTask(plugin,
  154.                                                 new Runnable() {
  155.                                                     public void run() {
  156.                                                         Main.cooldown.remove(p
  157.                                                                 .getName());
  158.                                                     }
  159.                                                 }, 120);
  160.                             }
  161.  
  162.                         }
  163.                     }
  164.  
  165.                 }
  166.                 if (Main.torch.contains(p.getName())) {
  167.                     if (p.hasPermission("specialarrows.torch")) {
  168.                         if (Main.cooldown.contains(p.getName())) {
  169.                             p.sendMessage(ChatColor.RED
  170.                                     + "You must wait before using an effect again.");
  171.                             return;
  172.                         }
  173.  
  174.                         Location loc = arrow.getLocation();
  175.                         loc.getBlock().setType(Material.TORCH);
  176.                         Bukkit.getServer().getScheduler()
  177.                                 .scheduleSyncDelayedTask(plugin, new Runnable() {
  178.                                     public void run() {
  179.                                         Main.cooldown.remove(p.getName());
  180.                                     }
  181.                                 }, 240);
  182.  
  183.                     }
  184.                    
  185.                 }
  186.             }
  187.         }
  188.     }
  189.    
  190.     @EventHandler
  191.     public void onInventoryClick(InventoryClickEvent e) {
  192.         if (!e.getInventory().equals(inv))
  193.             return;
  194.         else
  195.             e.setCancelled(true);
  196.         if (e.getCurrentItem().getItemMeta().getDisplayName()
  197.                 .contains("Explode")) {
  198.             if (Main.lightning.contains(e.getWhoClicked().getName())
  199.                     || Main.teleport.contains(e.getWhoClicked().getName())
  200.                     || Main.radiate.contains(e.getWhoClicked().getName())
  201.                     || Main.torch.contains(e.getWhoClicked().getName())) {
  202.                 e.getWhoClicked().sendMessage(
  203.                         ChatColor.RED
  204.                                 + "You can only have one toggled at a time!");
  205.             } else if (!Main.explode.contains(e.getWhoClicked().getName())) {
  206.                 Main.explode.add(e.getWhoClicked().getName());
  207.                 e.getWhoClicked()
  208.                         .sendMessage(
  209.                                 ChatColor.GREEN
  210.                                         + "Exploding arrows have been enabled!");
  211.             } else {
  212.                 Main.explode.remove(e.getWhoClicked().getName());
  213.                 e.getWhoClicked().sendMessage(
  214.                         ChatColor.RED + "Exploding arrows have been disabled.");
  215.             }
  216.         }
  217.         if (e.getCurrentItem().getItemMeta().getDisplayName()
  218.                 .contains("Lightning")) {
  219.             if (Main.teleport.contains(e.getWhoClicked().getName())
  220.                     || Main.explode.contains(e.getWhoClicked().getName())
  221.                     || Main.radiate.contains(e.getWhoClicked().getName())
  222.                     || Main.torch.contains(e.getWhoClicked().getName())) {
  223.                 e.getWhoClicked().sendMessage(
  224.                         ChatColor.RED
  225.                                 + "You can only have one toggled at a time!");
  226.             } else if (!Main.lightning.contains(e.getWhoClicked().getName())) {
  227.                 Main.lightning.add(e.getWhoClicked().getName());
  228.                 e.getWhoClicked()
  229.                         .sendMessage(
  230.                                 ChatColor.GREEN
  231.                                         + "Lightning arrows have been enabled!");
  232.             } else {
  233.                 Main.lightning.remove(e.getWhoClicked().getName());
  234.                 e.getWhoClicked().sendMessage(
  235.                         ChatColor.RED + "Lightning arrows have been disabled.");
  236.             }
  237.         }
  238.         if (e.getCurrentItem().getItemMeta().getDisplayName()
  239.                 .contains("Teleport")) {
  240.             if (Main.lightning.contains(e.getWhoClicked().getName())
  241.                     || Main.explode.contains(e.getWhoClicked().getName())
  242.                     || Main.radiate.contains(e.getWhoClicked().getName())
  243.                     || Main.torch.contains(e.getWhoClicked().getName())) {
  244.                 e.getWhoClicked().sendMessage(
  245.                         ChatColor.RED
  246.                                 + "You can only have one toggled at a time!");
  247.             } else if (!Main.teleport.contains(e.getWhoClicked().getName())) {
  248.                 Main.teleport.add(e.getWhoClicked().getName());
  249.                 e.getWhoClicked().sendMessage(
  250.                         ChatColor.GREEN
  251.                                 + "Teleporting arrows have been enabled!");
  252.             } else {
  253.                 Main.teleport.remove(e.getWhoClicked().getName());
  254.                 e.getWhoClicked().sendMessage(
  255.                         ChatColor.RED
  256.                                 + "Teleporting arrows have been disabled.");
  257.             }
  258.         }
  259.         if (e.getCurrentItem().getItemMeta().getDisplayName()
  260.                 .contains("Radiate")) {
  261.             if (Main.teleport.contains(e.getWhoClicked().getName())
  262.                     || Main.explode.contains(e.getWhoClicked().getName())
  263.                     || Main.lightning.contains(e.getWhoClicked().getName())
  264.                     || Main.torch.contains(e.getWhoClicked().getName())) {
  265.                 e.getWhoClicked().sendMessage(
  266.                         ChatColor.RED
  267.                                 + "You can only have one toggled at a time!");
  268.             } else if (!Main.radiate.contains(e.getWhoClicked().getName())) {
  269.                 Main.radiate.add(e.getWhoClicked().getName());
  270.                 e.getWhoClicked().sendMessage(
  271.                         ChatColor.GREEN + "Radiate arrows have been enabled!");
  272.             } else {
  273.                 Main.radiate.remove(e.getWhoClicked().getName());
  274.                 e.getWhoClicked().sendMessage(
  275.                         ChatColor.RED + "Radiate arrows have been disabled.");
  276.             }
  277.         }
  278.         if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Torch")) {
  279.             if (Main.teleport.contains(e.getWhoClicked().getName())
  280.                     || Main.explode.contains(e.getWhoClicked().getName())
  281.                     || Main.lightning.contains(e.getWhoClicked().getName())
  282.                     || Main.radiate.contains(e.getWhoClicked().getName())) {
  283.                 e.getWhoClicked().sendMessage(
  284.                         ChatColor.RED
  285.                                 + "You can only have one toggled at a time!");
  286.  
  287.             } else if (!Main.torch.contains(e.getWhoClicked().getName())) {
  288.                 Main.torch.add(e.getWhoClicked().getName());
  289.                 e.getWhoClicked().sendMessage(
  290.                         ChatColor.GREEN + "Torch arrows have been enabled!");
  291.             } else {
  292.                 Main.torch.remove(e.getWhoClicked().getName());
  293.                 e.getWhoClicked().sendMessage(
  294.                         ChatColor.RED + "Torch arrows have been disabled.");
  295.             }
  296.         }
  297.     }
  298.    
  299. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement