Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onEntityExplode(EntityExplodeEvent e) {
- if (e.getEntityType() != EntityType.PRIMED_TNT) {
- return;
- }
- TNTPrimed entity = (TNTPrimed) e.getEntity();
- ArrayList<Block> blocks = new ArrayList<Block>(e.blockList());
- for (Block b : blocks) {
- if (b.getType() == Material.TNT) {
- e.blockList().remove(b);
- Location loc = b.getLocation();
- b.setType(Material.AIR);
- TNTPrimed tnt = (TNTPrimed) loc.getWorld().spawn(loc.add(0.5D, 0.25D, 0.5D), TNTPrimed.class);
- tnt.setVelocity(new Vector(0.0D, 0.25D, 0.0D));
- tnt.setFuseTicks(20);
- if (entity.getSource() != null) {
- EntityLiving nmsEntityLiving = ((CraftLivingEntity) entity.getSource()).getHandle();
- EntityTNTPrimed nmsTNT = ((CraftTNTPrimed) tnt).getHandle();
- try {
- Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
- sourceField.setAccessible(true);
- sourceField.set(nmsTNT, nmsEntityLiving);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
- }
- }
- @EventHandler
- public void onClickTNT(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.TNT)
- && (e.getPlayer().getItemInHand().getType() == Material.FLINT_AND_STEEL)) {
- Location loc = e.getClickedBlock().getLocation();
- e.getClickedBlock().setType(Material.AIR);
- ItemStack hand = p.getItemInHand();
- short durability = hand.getDurability();
- hand.setDurability((short) (durability + 1));
- if (durability >= 63) {
- p.getInventory().remove(hand);
- }
- TNTPrimed tnt = (TNTPrimed) loc.getWorld().spawn(loc.add(0.5D, 0.25D, 0.5D), TNTPrimed.class);
- EntityLiving nmsEntityLiving = ((CraftLivingEntity) p).getHandle();
- EntityTNTPrimed nmsTNT = ((CraftTNTPrimed) tnt).getHandle();
- try {
- Field sourceField = EntityTNTPrimed.class.getDeclaredField("source");
- sourceField.setAccessible(true);
- sourceField.set(nmsTNT, nmsEntityLiving);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- tnt.setVelocity(new Vector(0.0D, 0.25D, 0.0D));
- e.setCancelled(true);
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement