Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  2. public void onEntityExplode(EntityExplodeEvent e) {
  3. if (e.getEntityType() != EntityType.PRIMED_TNT) {
  4. return;
  5. }
  6. TNTPrimed entity = (TNTPrimed) e.getEntity();
  7.  
  8. ArrayList<Block> blocks = new ArrayList<Block>(e.blockList());
  9. for (Block b : blocks) {
  10. if (b.getType() == Material.TNT) {
  11. e.blockList().remove(b);
  12. Location loc = b.getLocation();
  13. b.setType(Material.AIR);
  14.  
  15. TNTPrimed tnt = (TNTPrimed) loc.getWorld().spawn(loc.add(0.5D, 0.25D, 0.5D), TNTPrimed.class);
  16. tnt.setVelocity(new Vector(0.0D, 0.25D, 0.0D));
  17. tnt.setFuseTicks(20);
  18. if (entity.getSource() != null) {
  19. EntityLiving nmsEntityLiving = ((CraftLivingEntity) entity.getSource()).getHandle();
  20. EntityTNTPrimed nmsTNT = ((CraftTNTPrimed) tnt).getHandle();
  21. try {
  22. Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
  23. sourceField.setAccessible(true);
  24. sourceField.set(nmsTNT, nmsEntityLiving);
  25. } catch (Exception ex) {
  26. ex.printStackTrace();
  27. }
  28. }
  29. }
  30. }
  31. }
  32.  
  33. @EventHandler
  34. public void onClickTNT(PlayerInteractEvent e) {
  35. Player p = e.getPlayer();
  36. if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.TNT)
  37. && (e.getPlayer().getItemInHand().getType() == Material.FLINT_AND_STEEL)) {
  38. Location loc = e.getClickedBlock().getLocation();
  39. e.getClickedBlock().setType(Material.AIR);
  40.  
  41. ItemStack hand = p.getItemInHand();
  42. short durability = hand.getDurability();
  43. hand.setDurability((short) (durability + 1));
  44. if (durability >= 63) {
  45. p.getInventory().remove(hand);
  46. }
  47. TNTPrimed tnt = (TNTPrimed) loc.getWorld().spawn(loc.add(0.5D, 0.25D, 0.5D), TNTPrimed.class);
  48. EntityLiving nmsEntityLiving = ((CraftLivingEntity) p).getHandle();
  49. EntityTNTPrimed nmsTNT = ((CraftTNTPrimed) tnt).getHandle();
  50. try {
  51. Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
  52. sourceField.setAccessible(true);
  53. sourceField.set(nmsTNT, nmsEntityLiving);
  54. } catch (Exception ex) {
  55. ex.printStackTrace();
  56. }
  57. tnt.setVelocity(new Vector(0.0D, 0.25D, 0.0D));
  58. e.setCancelled(true);
  59. return;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement