Solved Making a arrow rain

Discussion in 'Plugin Development' started by jimbo8, Nov 10, 2013.

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

    jimbo8

    Hey!

    We are making a feature for our plugin that makes arrows spawn above your head when you left click with a dragon egg in the air, and also which makes you get more health if you rightclick it.

    The problem is that the arrowspawning won't work, the health boost does, though.

    Here is our code:

    Code:java
    1. package me.adrian.plugin.Listeners;
    2.  
    3. import me.adrian.plugin.Testplugin1.Main;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.EntityType;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. public class BlockFood implements Listener {
    19. public static Main plugin;
    20.  
    21. public BlockFood(Main instance) {
    22. plugin = instance;
    23. }
    24.  
    25. @EventHandler
    26. public void onEat(PlayerInteractEvent e) {
    27. Player player = e.getPlayer();
    28. ItemStack m = new ItemStack(Material.DRAGON_EGG, 1);
    29. if (player.getItemInHand().getType() == Material.DRAGON_EGG) {
    30. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    31.  
    32. player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL,
    33. 1200, 96));
    34. player.addPotionEffect(new PotionEffect(
    35. PotionEffectType.HEALTH_BOOST, 1200, 104));
    36. player.setFoodLevel(20);
    37. player.setSaturation(1200);
    38. player.sendMessage(ChatColor.GREEN + "You ate a " + ChatColor.YELLOW
    39. + player.getItemInHand().getType() + ".");
    40. player.getInventory().removeItem(m);
    41.  
    42. }
    43. if(e.getAction() == Action.LEFT_CLICK_AIR){
    44. Location pl = e.getPlayer().getLocation();
    45. Location x = e.getPlayer().getLocation(x);
    46. Location z = e.getPlayer().getLocation(z);
    47.  
    48. e.getPlayer().sendMessage(ChatColor.GREEN + "You ate a " + ChatColor.YELLOW + e.getPlayer().getItemInHand().getType()+ ".");
    49. player.getInventory().removeItem(m);
    50.  
    51. Location loc = new Location(pl.getWorld(), x, pl.getY()+10, z);
    52.  
    53. loc.getWorld().spawnEntity(pl, EntityType.ARROW);
    54. e.getPlayer().sendMessage("Funker! :D");
    55. }
    56. }
    57.  
    58. }
    59. }
    60.  


    We might be on the totally other side of the world, but, yeah..

    Thanks!


    [EDIT]

    Also, i want 25 arrows to spawn 20 blocks over the player, any ideas? Not inside eachother, but with one block space between them. I also want 20 lightning strikes with TNT rain with about 2 seconds delay. If you wonder what it is for, it's to make the worth of the dragonegg higher on the server, mostly for PvP.
     
  2. Offline

    Ytry

    Try using this Location p1 = e.getPlayer().getWorld().getLocation();
     
  3. Offline

    jimbo8

    That won't work, as it's undefined. Anyways, it would still only spawn one arrow.

    I made it so it can spawn one arrow now;

    Code:java
    1. package me.adrian.plugin.Listeners;
    2.  
    3. import me.adrian.plugin.Testplugin1.Main;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.EntityType;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. public class BlockFood implements Listener {
    19. public static Main plugin;
    20.  
    21. public BlockFood(Main instance) {
    22. plugin = instance;
    23. }
    24.  
    25. @EventHandler
    26. public void onEat(PlayerInteractEvent e) {
    27. Player player = e.getPlayer();
    28. ItemStack m = new ItemStack(Material.DRAGON_EGG, 1);
    29. if (player.getItemInHand().getType() == Material.DRAGON_EGG) {
    30. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    31.  
    32. player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL,
    33. 1200, 96));
    34. player.addPotionEffect(new PotionEffect(
    35. PotionEffectType.HEALTH_BOOST, 1200, 104));
    36. player.setFoodLevel(20);
    37. player.setSaturation(1200);
    38. player.sendMessage(ChatColor.GREEN + "You ate a " + ChatColor.YELLOW
    39. + player.getItemInHand().getType() + ".");
    40. player.getInventory().removeItem(m);
    41.  
    42. }
    43. if(e.getAction() == Action.LEFT_CLICK_AIR){
    44. Location pl = e.getPlayer().getLocation();
    45.  
    46. e.getPlayer().sendMessage(ChatColor.GREEN + "You ate a " + ChatColor.YELLOW + e.getPlayer().getItemInHand().getType()+ ".");
    47. player.getInventory().removeItem(m);
    48.  
    49. pl.getWorld().spawnEntity(pl, EntityType.ARROW);
    50. e.getPlayer().sendMessage("Funker! :D");
    51. }
    52. }
    53.  
    54. }
    55. }
    56.  


    It does spawn ONE arrow, but i'm not really sure how to make it spawn 20 blocks in the air, and 20 arrows at once.
     
  4. Offline

    NinjaWAffles

    Something like this should work:

    Code:Java
    1. Location plLoc = new Location(e.getPlayer().getWorld(), e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY() + 20, e.getPlayer().getLocation().getZ());
    2.  
    3. for(int i = 0; i <= 20; i++)
    4. {
    5. e.getPlayer().getWorld().spawnEntity(plLoc, EntityType.ARROW);
    6. }
     
  5. Offline

    jimbo8

    Thanks, now it spawns one arrow, 20 blocks above me :>

    I just have to figure out how to spawn 20 arrows at the same time now.
     
  6. Offline

    NinjaWAffles

    That's what the for loop is for. It'll iterate through that loop 20 times and spawn an arrow each time.
     
  7. Offline

    jimbo8

    NinjaWAffles

    Yeah, but it won't loop it 20 times.
    It only spawns one arrow :p

    Also, i've mostly done stuff with commands and not listeners, so i'm not really experienced with this, i'm still a beginner too. :>
     
  8. Offline

    NinjaWAffles

    Would you like to spawn an updated version of your code? The for loop should work.
     
  9. Offline

    RealDope

    Code:JAVA
    1.  
    2. Location loc = p.getLocation().add(0, 20, 0);
    3. List<Location> locs = new ArrayList<Location>();
    4. for(int x = -2; x <= 2; x++) {
    5. for(int z = -2; z <= 2; z++) {
    6. locs.add(loc.add(x, 0, z);
    7. }
    8. }
    9. for(Location arrowSpot : locs) {
    10. arrowSpot.getWorld().spawnEntity(arrowSpot, EntityType.ARROW);
    11. }
    12.  

    That should work
     
  10. Offline

    jimbo8

    NinjaWAffles

    Here ya go :)

    Code:java
    1. if(e.getAction() == Action.LEFT_CLICK_AIR){
    2. Location plLoc = new Location(e.getPlayer().getWorld(), e.getPlayer().getLocation().getX(), e.getPlayer().getLocation().getY() + 20, e.getPlayer().getLocation().getZ());
    3.  
    4. for(int i = 0; i <= 20; i++)
    5. {
    6. e.getPlayer().getWorld().spawnEntity(plLoc, EntityType.ARROW);
    7. }
    8. }


    Thanks for helping me out with the problem :D

    [EDIT]

    RealDope

    That didn't work :p
     
  11. Offline

    RealDope

    What?
    That code barely makes sense.. Why are you making a new Location that long way instead of just using what I put? Also that loop will just spawn 20 arrows inside eachother.. You said you wanted 25 and spread out 1 block each?
     
  12. Offline

    jimbo8

    RealDope

    Yeah, i wanted 25 to spread out :p

    Sorry, i wrote my post while you posted yours, so i didn't show my code with your part in it.

    I tried your version, but it still wouldn't work.
     
  13. Offline

    RealDope

    What doesn't work? That loop should make a list of 25 locations in a 5x5 grid 20 blocks above the player, then the loop below it spawns arrows at each of them.
     
  14. Offline

    jimbo8

    RealDope

    Well, it basically won't work.

    It only spawns one arrow, when it should spawn 25 of them. I've tried to modify the code, but i can't figure out how i should do it.

    This is what the code is like right now;

    Code:java
    1. package me.adrian.plugin.Listeners;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import me.adrian.plugin.Testplugin1.Main;
    7.  
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Location;
    10. import org.bukkit.Material;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.Action;
    16. import org.bukkit.event.player.PlayerInteractEvent;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.potion.PotionEffect;
    19. import org.bukkit.potion.PotionEffectType;
    20.  
    21. public class BlockFood implements Listener {
    22. public static Main plugin;
    23.  
    24. public BlockFood(Main instance) {
    25. plugin = instance;
    26. }
    27.  
    28. @EventHandler
    29. public void onEat(PlayerInteractEvent e) {
    30. Player player = e.getPlayer();
    31. ItemStack m = new ItemStack(Material.DRAGON_EGG, 1);
    32. if (player.getItemInHand().getType() == Material.DRAGON_EGG) {
    33. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    34.  
    35. player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL,
    36. 1200, 96));
    37. player.addPotionEffect(new PotionEffect(
    38. PotionEffectType.HEALTH_BOOST, 1200, 104));
    39. player.setFoodLevel(20);
    40. player.setSaturation(1200);
    41. player.sendMessage(ChatColor.GREEN + "You ate a " + ChatColor.YELLOW
    42. + player.getItemInHand().getType() + ".");
    43. player.getInventory().removeItem(m);
    44.  
    45. }
    46. if(e.getAction() == Action.LEFT_CLICK_AIR){
    47. Location loc = player.getLocation().add(0, 20, 0);
    48. List<Location> locs = new ArrayList<Location>();
    49. for(int x = -2; x <= 2; x++) {
    50. for(int z = -2; z <= 2; z++) {
    51. locs.add(loc.add(x, 0, z));
    52. }
    53. }
    54. for(Location arrowSpot : locs) {
    55. arrowSpot.getWorld().spawnEntity(arrowSpot, EntityType.ARROW);
    56. }
    57. }
    58.  
    59. }
    60. }
    61. }
    62.  
     
  15. Offline

    RealDope

    Change the second loop to this:
    Code:JAVA
    1.  
    2. for(Location arrowSpot : locs) {
    3. System.out.println(arrowSpot);
    4. arrowSpot.getWorld().spawnEntity(arrowSpot, EntityType.ARROW);
    5. }
    6.  

    Show me what console prints
     
  16. Offline

    jimbo8

    RealDope

    The console prints the following:

    Code:
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
    19:38:37 [INFO] Location{world=CraftWorld{name=world},x=33.8168459246107,y=97.0,
    z=209.64276952779366,pitch=4.4999995,yaw=-235.20145}
     
  17. Offline

    RealDope

    But it only spawns one arrow?..
    Change to this:
    Code:JAVA
    1.  
    2. for(Location arrowSpot : locs){
    3. System.out.println(arrowSpot);
    4. Entity e = arrowSpot.getWorld().spawnEntity(arrowSpot, EntityType.ARROW);
    5. System.out.println(e);
    6. }
    7.  

    Show me console.
     
  18. Offline

    chasechocolate

    The location object is not immutable, so using loc.add(0, 1, 0) and loc.add(0, 1, 0) will cause the location object to now have a Y two higher, if that makes sense. Use loc.clone().add(x, y, z).
     
  19. Offline

    jimbo8

    RealDope

    Code:
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    21:11:16 [INFO] Location{world=CraftWorld{name=world},x=26.6417893868915,y=108.6
    6767378356163,z=263.79332082185056,pitch=-9.6000185,yaw=204.7489}
    21:11:16 [INFO] org.bukkit.event.player.PlayerInteractEvent@33b3bed9
    There ya go.

    chasechocolate

    I didn't really understand what you meant, i tried what you said, sorry :p
     
  20. Offline

    RealDope

    Show your code now, I didn't really look at the locations before, but now I notice every location in that array is the same, probably something to do with what chasechocolate said. Did you add the .clone()?
     
  21. Offline

    jimbo8

    RealDope

    Code:java
    1. package me.adrian.plugin.Listeners;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import me.adrian.plugin.Testplugin1.Main;
    7.  
    8. import org.bukkit.Location;
    9. import org.bukkit.Material;
    10. import org.bukkit.entity.Entity;
    11. import org.bukkit.entity.EntityType;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.Action;
    16. import org.bukkit.event.player.PlayerInteractEvent;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.potion.PotionEffect;
    19. import org.bukkit.potion.PotionEffectType;
    20.  
    21. public class BlockFood implements Listener {
    22. public static Main pl;
    23.  
    24. public BlockFood(Main instance) {
    25. pl = instance;
    26. }
    27.  
    28. @EventHandler
    29. public void onEat(PlayerInteractEvent e) {
    30. Player player = e.getPlayer();
    31. ItemStack m = new ItemStack(Material.DRAGON_EGG, 1);
    32. if (player.getItemInHand().getType() == Material.DRAGON_EGG) {
    33. if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    34.  
    35. player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL,
    36. 1200, 96));
    37. player.addPotionEffect(new PotionEffect(
    38. PotionEffectType.HEALTH_BOOST, 1200, 104));
    39. player.setFoodLevel(20);
    40. player.setSaturation(1200);
    41. player.sendMessage(pl.blue + "Du spiste et " + pl.green
    42. + player.getItemInHand().getType() + pl.blue +" og fikk livboost og instant liv, maten din ble også satt på maks, "+ pl.green + "gratulerer!");
    43. player.getInventory().removeItem(m);
    44.  
    45. }
    46. if(e.getAction() == Action.LEFT_CLICK_AIR){
    47. Location loc = player.getLocation().add(0, 20, 0);
    48. List<Location> locs = new ArrayList<Location>();
    49. for(int x = -2; x <= 2; x++) {
    50. for(int z = -2; z <= 2; z++) {
    51. locs.add(loc.add(x, 0, z).clone().add(x,y,z));
    52. }
    53. }
    54. for(Location arrowSpot : locs) {
    55. System.out.println(arrowSpot);
    56. @SuppressWarnings("unused")
    57. Entity en = arrowSpot.getWorld().spawnEntity(arrowSpot, EntityType.ARROW);
    58. System.out.println(e);
    59. }
    60. }
    61.  
    62. }
    63. }
    64. }
    65.  


    Yeah.. the Y isn't registered, i don't know how we should register it in this case, as a Y loop would be wrong(i think?).
     
  22. Offline

    RealDope

    Yeah there's a few things wrong there..

    Change this:
    Code:JAVA
    1.  
    2. locs.add(loc.add(x, 0, z).clone().add(x,y,z));
    3.  

    To this:
    Code:JAVA
    1.  
    2. locs.add(loc.clone().add(x, 0, z));
    3.  

    And change this:
    Code:JAVA
    1.  
    2. System.out.println(e);
    3.  

    To this:
    Code:JAVA
    1.  
    2. System.out.println(en);
    3.  

    Show console.
     
    jimbo8 likes this.
  23. Offline

    jimbo8

    RealDope

    It actually works now!

    Thanks a lot for your help, i really appreciate that.
     
    RealDope likes this.
Thread Status:
Not open for further replies.

Share This Page