Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. package net.Krymz.Explode;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Random;
  5.  
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.entity.Egg;
  10. import org.bukkit.entity.Entity;
  11. import org.bukkit.entity.EntityType;
  12. import org.bukkit.entity.FallingBlock;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.entity.EntityExplodeEvent;
  18. import org.bukkit.event.entity.ProjectileHitEvent;
  19. import org.bukkit.event.player.PlayerInteractEvent;
  20. import org.bukkit.inventory.ItemStack;
  21.  
  22. public class Explode implements Listener{
  23.  
  24. @SuppressWarnings("unused")
  25. private Main plugin;
  26. public Explode(Main listener) {
  27. this.plugin = listener;
  28. }
  29.  
  30. @EventHandler
  31. public void onProjectileHit(ProjectileHitEvent e) {
  32. if (e.getEntity() instanceof Egg && e.getEntity().getShooter() instanceof Player) {
  33. e.getEntity().getWorld().createExplosion(e.getEntity().getLocation(), 4.0f, false);
  34. return;
  35. }
  36. return;
  37. }
  38.  
  39. @SuppressWarnings("deprecation")
  40. @EventHandler
  41. public void Egg(PlayerInteractEvent e) {
  42. if (e.getAction() == Action.RIGHT_CLICK_BLOCK
  43. || e.getAction() == Action.RIGHT_CLICK_AIR) {
  44. if (e.getPlayer().getItemInHand() != null) {
  45. if (e.getPlayer().getItemInHand().getType() == Material.EGG) {
  46. e.getPlayer().getInventory().addItem(new ItemStack(Material.EGG, 1));
  47. }
  48. }
  49. }
  50. }
  51.  
  52. @SuppressWarnings("deprecation")
  53. @EventHandler
  54. public void Tnt(final PlayerInteractEvent e) {
  55. if (e.getAction() == Action.RIGHT_CLICK_BLOCK
  56. || e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
  57. if (e.getPlayer().getItemInHand() != null) {
  58. if (e.getPlayer().getItemInHand().getType() == Material.TNT) {
  59. final Entity tnt = e.getPlayer().getWorld().spawnEntity(e.getPlayer().getEyeLocation(), EntityType.PRIMED_TNT);
  60. tnt.setVelocity(e.getPlayer().getLocation().getDirection().multiply(1.5));
  61. }
  62. }
  63. }
  64. }
  65.  
  66. public static HashMap<Block, Location> blocklist = new HashMap<Block, Location>();
  67. @SuppressWarnings("deprecation")
  68. @EventHandler
  69. public void onBlockEvent(EntityExplodeEvent e){
  70. for(Block block : e.blockList()){
  71. FallingBlock falling = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
  72. float x = (float) (Math.random() * randomNum(-2,2));
  73. float y = (float) (Math.random() * randomNum(1,2));
  74. float z = (float) (Math.random() * randomNum(-2,2));
  75. falling.setVelocity(block.getLocation().getDirection().setX(x).setY(y).setZ(z));
  76. }
  77. }
  78.  
  79.  
  80. public static int randomNum(int Low, int High){
  81. Random r = new Random();
  82. int R = r.nextInt(High-Low) + Low;
  83. return R;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement