PrimedTnt

Discussion in 'Plugin Development' started by creepers84, May 18, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    creepers84

    How (in one line of code) would I spawn a PrimedTnt where the player is standing. Don't worry about how it gets there etc.. I have it covered. Thanks
     
  2. Offline

    GodzOfMadness

    creepers84 player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT);
     
  3. Offline

    Ivan

    world.spawnEntity(EntityType.PrimedTNT,location) I'm guessing.
     
  4. Offline

    creepers84

    Thankyou! While we are on the topic. How can I make it so that you Right_CLick it automatically throws a stack of rotten flesh and then 3 seconds later that stack explodes and the entity disappears + No block damage?
     
  5. Offline

    GodzOfMadness

    creepers84
    Listen to the PlayerInteractEvent
    If the action == Action.RIGHT_CLICK_BLOCK then
    make an ItemStack(stack of rotten flesh)
    Then drop the item on the floor and set the Item variable to it
    like so:
    Item item = player.getWorld().dropItem(location, ItemStack);
    then you could set the item pickup delay to deny them to pick it up
    item.setPickupDelay(...);
    make a scheduler as so
    final Item thrown = item;
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable(){
    public void run(){
    thrown.getWorld().createExplosion(x, y, z, power, setFire, breakBlocks)
    }
    }, ticks);

    EDIT:
    Forgot to mention that it takes 20 ticks for every second so 3 seconds in ticks would be 60 ticks
     
  6. Offline

    creepers84

    I have this:
    Code:
    @EventHandler
    public void onPlayerInteract11111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 2) { 
                  if(player.hasPermission("zombie.fire")){
                      ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                      Item item1 = player.getWorld().dropItem(Location, item);
                      item1.setPickupDelay(60);
                      final Item thrown = item1;
                      Bukkit.getScheduler().runTaskLater(plugin, new Runnable(){
                      public void run(){
                      thrown.getWorld().strikeLightning(location);
                      }
                      }, 60);
    the: Item item1 = player.getWorld().dropItem(Location, item);
    and the: thrown.getWorld().strikeLightning(location);
    Don't work as the Location is underlined in red. Btw I changed it to lightning instead.
     
  7. Offline

    GodzOfMadness

    creepers84 After you strike the lightning you should remove the item from the world just in case.
    For the error under location just replace it with the location you want it to spawn at.
     
  8. Offline

    creepers84

    The Item location... So what would I put?
     
  9. Offline

    GodzOfMadness

    creepers84 Where ever you want the item to drop. You could drop the item where you clicked the block.
    event.getClickedBlock().getLocation();
     
  10. Offline

    creepers84

    Ok... But then how can I remove the Locations from the line?
     
  11. Offline

    GodzOfMadness

    creepers84 What do you mean? Like how to remove the error?
     
  12. Offline

    creepers84

    Urm.... LOL I don't know what Im fretting about:
    Code:
    @EventHandler
    public void onPlayerInteract11111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 2) { 
                  if(player.hasPermission("zombie.fire")){
                      final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                      Item item1 = player.getWorld().dropItem(event.getClickedBlock().getLocation(), item);
                      event.getClickedBlock().getLocation();
                      item1.setPickupDelay(60);
                      Bukkit.getScheduler().runTaskLater(plugin, new Runnable(){
                      public void run(){
                      thrown.getWorld().strikeLightning(item);
                      }
                      }, 60);
    Will this work? The thrown.getWorld().strikeLightning(item); is not working though the thrown is underlined in red. =( lol
     
  13. Offline

    GodzOfMadness

    creepers84 The reason it's giving an error is that you didn't create a variable 'thrown'. Just above Bukkit.getScheduler() create the variable. final Item thrown = item1;
    and after you strike the lightning just for safe keeping if the lightning doesn't remove the item, type thrown.remove();
    It will remove the entity from the world.
     
  14. Offline

    creepers84

    I have this now:
    Code:
    public void onPlayerInteract11111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 2) { 
                  if(player.hasPermission("zombie.fire")){
                      final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                      Item item1 = player.getWorld().dropItem(event.getClickedBlock().getLocation(), item);
                      Bukkit.getScheduler();
                      final Item thrown = item1;
                      event.getClickedBlock().getLocation();
                      item1.setPickupDelay(60);
                      Bukkit.getScheduler().runTaskLater(plugin, new Runnable(){
                      public void run(){
                      thrown.getWorld().strikeLightning(item);
                      thrown.remove();
                      }
                      }, 60);
    This Section:
    Code:
     thrown.getWorld().strikeLightning(item);
    The StrikeLightning is now underlined =(
     
  15. Offline

    GodzOfMadness

    I suggest you remove the event.getClickedBlock().getLocation(); line from your code. It's doing nothing. Keep the one in your parameter. Also move final Item thrown = item1; after item1.setPickupDelay(60); So you have an exact copy of the item you are going to remove. Replace 'item' in the strikeLightning method with thrown.getLocation()
     
  16. Offline

    creepers84

    Thanks, but I just tested the code on my server and it doesn't work =( here:
    Code:
    @EventHandler
    public void onPlayerInteract11111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 2) { 
                  if(player.hasPermission("zombie.fire")){
                      final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                      Item item1 = player.getWorld().dropItem(event.getClickedBlock().getLocation(), item);
                      Bukkit.getScheduler();
                      item1.setPickupDelay(60);
                      final Item thrown = item1;
                      Bukkit.getScheduler().runTaskLater(plugin, new Runnable(){
                      public void run(){
                      thrown.getWorld().strikeLightning(thrown.getLocation());
                      thrown.remove();
                      }
                      }, 60);
     
    }
                  }
              }
        }
    }
     
  17. Offline

    GodzOfMadness

    creepers84 is the item id that your holding 397? and the durability equal to two? and also do you have permission for zombie.fire? Also why do you have Bukkit.getScheduler() randomly in your code. You should remove that, it's before item1.setPickupDelay(60); If all of that is true then it should work.
     
  18. Offline

    creepers84

    I have Amended all of this and it still doesn't work. When I click the Zombie Head in-game it causes a Call event error on the console....
     
  19. Offline

    GodzOfMadness

  20. Offline

    creepers84

    [​IMG] and [​IMG]

    Goto: http://postimg.org/image/f023m8fp1/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  21. Offline

    GodzOfMadness

    creepers84 What's on line 83 in your onPlayerInteract method?
     
  22. Offline

    creepers84

    How do I see the numbers?
     
  23. Offline

    GodzOfMadness

    creepers84 If you're using eclipse just right click on this blue bar on the left hand side and click "Show Line Numbers."
     
  24. Offline

    creepers84

    It's:
    Code:
     Item item1 = player.getWorld().dropItem(event.getClickedBlock().getLocation(), item);
     
  25. Offline

    GodzOfMadness

    creepers84 Oops i forgot that you were checking for if they clicked in the air. The error is that it's trying to get a block that is null. Here try this.
    Code:
     "@"EventHandler
        public void onPlayerInteract11111(PlayerInteractEvent event) {
            final Player player = event.getPlayer();
            if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
                int blockId = player.getItemInHand().getType().getId();
                int blockSubId = player.getItemInHand().getDurability();
                if (blockId == 397 && blockSubId == 2) {
                    if (player.hasPermission("zombie.fire")) {
                        final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                        Item item1 = player.getWorld().dropItem(player.getEyeLocation(), item);
                        Bukkit.getScheduler();
                        item1.setPickupDelay(60);
                        item1.setVelocity(player.getEyeLocation().getDirection().multiply(1.5D));
                        final Item thrown = item1;
                        Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
                            public void run() {
                                thrown.getWorld().strikeLightning(thrown.getLocation());
                                thrown.remove();
                            }
                        }, 60);
     
                    }
                }
            }
        }
    Just remove the " " for the @EventHandler
    What i did was set the drop location at your eye sight, then i multiplied the direction you were looking at by 1.5 so the item would be thrown from your location.
     
  26. Offline

    creepers84

    Any ideas?

    The itemstack is thrown, but not removed and the lightning doesn't strike. =P

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  27. Offline

    GodzOfMadness

    creepers84 on the bottom where "60" is, replace it with 60L
     
  28. Offline

    creepers84

    Still Nothing.... It creates another long error on the console too!
     
  29. Offline

    GodzOfMadness

    creepers84 If it shows an error then show me the stack trace.
     
  30. Offline

    creepers84

Thread Status:
Not open for further replies.

Share This Page