Solved Help with laser.

Discussion in 'Plugin Development' started by stickman561, Jun 23, 2015.

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

    stickman561

    Hi, I'm trying to add a laser rifle to my plugin with vectors, using the code
    Code:
    public static void shootlaser(Player player, boolean breaksblocks, boolean deadly, ParticleEffect effect, int distance) {
        Vector vector = player.getEyeLocation().getDirection();
        Location location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
        distance = distance * 10;
       
        while(location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS) && distance > 0) {
        effect.display(location, 0, 0, 0, 0, 1);
        distance = distance - 1;
            if(breaksblocks) {
                if(location.getBlock().getType().isBlock() && !location.getBlock().getType().equals(Material.BEDROCK)) {
                    location.getBlock().breakNaturally();
            }
          }
           
            if(deadly) {
                List<Entity> entitylist = location.getWorld().getEntities();
                    for(Entity entity : entitylist) {
                        if(entity.getLocation().getBlock() == location) {
                            if(entity instanceof LivingEntity) {
                                LivingEntity liveone = (LivingEntity)entity;
                                liveone.setHealth(0);
                }
              }
            }
          }
            vector = vector.multiply(0.1);
            location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
        }
      }
    called with
    Code:
    if((player.getItemInHand().hasItemMeta()) && (getConfig().getBoolean("laser-rifle")) && (player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Laser Rifle")) && (player.getItemInHand().getType().equals(Material.DIAMOND_HOE))) {
    
    shootlaser(player, false, true, ParticleEffect.RED_DUST, 30);
    
    event.setCancelled(true);
    
    }
    
    
    When I use the item in game, however, nothing happens! Please help!
     
  2. using the player.getEyeLocation().getDirection() gives you a normalized (this means all the values are between -1 and 1) and you can't use this to get the location that you do right after you get the direction. So to get the block you use player.getEyeLocation().add(directionVector.multiply(distance)). It could be that with the add it doesn't take in the vector, so you need to pass the x y and z seperately.
     
  3. Offline

    stickman561

    Thanks! Testing now...

    I'm now using
    Code:
    public static void shootlaser(Player player, boolean breaksblocks, boolean deadly, ParticleEffect effect, int distance) {
        Vector vector = player.getEyeLocation().getDirection();
        Location location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
        distance = distance * 10;
       
        while(location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS) && distance > 0) {
        effect.display(location, 0, 0, 0, 0, 5);
        distance = distance - 1;
            if(breaksblocks) {
                if(location.getBlock().getType().isBlock() && !location.getBlock().getType().equals(Material.BEDROCK)) {
                    location.getBlock().breakNaturally();
            }
          }
           
            if(deadly) {
                List<Entity> entitylist = location.getWorld().getEntities();
                    for(Entity entity : entitylist) {
                        if(entity.getLocation().getBlock() == location) {
                            if(entity instanceof LivingEntity) {
                                LivingEntity liveone = (LivingEntity)entity;
                                liveone.setHealth(0);
                }
              }
            }
          }
            vector = vector.add(vector.multiply(0.1));
            location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
        }
      }
    and getting a PlayerInteractEvent nullpointerexception. Can you please be more specific, like with a code example?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. I don't quite see the nullpointer, so could you give me the stacktrace? and the line it's on? Also with
    Code:
    Location location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
    you need to add the x y and z to the x y and z of the location (else it will happen around 0,0,0). And it could be that the nullpointer happens from the y being below 0, so please add the eyelocation to the location first and then check if it works.
     
  5. Offline

    stickman561

    Ok.

    Now using
    Code:
    public static void shootlaser(Player player, boolean breaksblocks, boolean deadly, ParticleEffect effect, int distance) {
        Vector vector = player.getEyeLocation().getDirection();
        Location location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
        distance = distance * 10;
       
        while(location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS) && distance > 0) {
        effect.display(location, 0, 0, 0, 0, 5);
        distance = distance - 1;
            if(breaksblocks) {
                if(location.getBlock().getType().isBlock() && !location.getBlock().getType().equals(Material.BEDROCK)) {
                    location.getBlock().breakNaturally();
            }
          }
           
            if(deadly) {
                List<Entity> entitylist = location.getWorld().getEntities();
                    for(Entity entity : entitylist) {
                        if(entity.getLocation().getBlock() == location) {
                            if(entity instanceof LivingEntity) {
                                LivingEntity liveone = (LivingEntity)entity;
                                liveone.setHealth(0);
                }
              }
            }
          }
            location = location.add(vector.multiply(0.1));
        }
      }
    and getting THIS insane error:
    Code:
    [14:27:40] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Stickmans_items v5.6.4
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:209) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:176) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:172) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:653) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-262c777]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_25]
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [?:1.7.0_25]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_25]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:643) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:598) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:506) [craftbukkit.jar:git-Bukkit-262c777]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_25]
    Caused by: com.snakec0de.stickmansitems.ParticleEffect$PacketInstantiationException: java.lang.NullPointerException
        at com.snakec0de.stickmansitems.ParticleEffect.instantiatePacket(ParticleEffect.java:233) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:281) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:286) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.shootlaser(StickmansItemsCore.java:1652) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.interact(StickmansItemsCore.java:1085) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit.jar:git-Bukkit-262c777]
        ... 18 more
    Caused by: java.lang.NullPointerException
        at com.snakec0de.stickmansitems.ParticleEffect.instantiatePacket(ParticleEffect.java:229) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:281) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:286) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.shootlaser(StickmansItemsCore.java:1652) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.interact(StickmansItemsCore.java:1085) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit.jar:git-Bukkit-262c777]
        ... 18 more
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:12] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:13] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    [14:28:33] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Stickmans_items v5.6.4
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:209) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:176) [craftbukkit.jar:git-Bukkit-262c777]
        at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:172) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:653) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-262c777]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_25]
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [?:1.7.0_25]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_25]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:643) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:598) [craftbukkit.jar:git-Bukkit-262c777]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:506) [craftbukkit.jar:git-Bukkit-262c777]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_25]
    Caused by: com.snakec0de.stickmansitems.ParticleEffect$PacketInstantiationException: java.lang.NullPointerException
        at com.snakec0de.stickmansitems.ParticleEffect.instantiatePacket(ParticleEffect.java:233) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:281) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:286) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.shootlaser(StickmansItemsCore.java:1652) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.interact(StickmansItemsCore.java:1085) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit.jar:git-Bukkit-262c777]
        ... 18 more
    Caused by: java.lang.NullPointerException
        at com.snakec0de.stickmansitems.ParticleEffect.instantiatePacket(ParticleEffect.java:229) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:281) ~[?:?]
        at com.snakec0de.stickmansitems.ParticleEffect.display(ParticleEffect.java:286) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.shootlaser(StickmansItemsCore.java:1652) ~[?:?]
        at com.snakec0de.stickmansitems.StickmansItemsCore.interact(StickmansItemsCore.java:1085) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit.jar:git-Bukkit-262c777]
        ... 18 more
    [14:28:59] [Server thread/INFO]: Unknown command. Type "help" for help.[m
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  6. one thing, on the first time you initialize the location variable, you still forgot to add the eye location of the player.
     
  7. Offline

    stickman561

    I made location = player.getEyeLocation(), but now I think the problem is with the way I call the particleeffect. I will attempt to troubleshoot that.

    I commented out the effect.display, and the error disappeared! Sadly, now the entire server crashes when one of the laser rifles is used.

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

    mkezar

    Are you seeing ANYTHING when you fire the laser? Or is it just giving you the error?

    *Semi-Offtopic*
    Are you using the ParticleEffect library? Because I've always tried to find one that worked :)
     
  9. Offline

    stickman561

    No error or particles after commenting out effect.display. Now the server just plain crashes. This is my code:
    Code:
    public static void shootlaser(Player player, boolean breaksblocks, boolean deadly, ParticleEffect effect, int distance) {
        Vector vector = player.getEyeLocation().getDirection();
        Location location = player.getEyeLocation();
        distance = distance * 10;
      
        while(location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS) && distance > 0) {
        //effect.display(location, 0, 0, 0, 0, 5);
        distance = distance - 1;
            if(breaksblocks) {
                if(location.getBlock().getType().isBlock() && !location.getBlock().getType().equals(Material.BEDROCK)) {
                    location.getBlock().breakNaturally();
            }
          }
          
            if(deadly) {
                List<Entity> entitylist = location.getWorld().getEntities();
                    for(Entity entity : entitylist) {
                        if(entity.getLocation().getBlock() == location) {
                            if(entity instanceof LivingEntity) {
                                LivingEntity liveone = (LivingEntity)entity;
                                liveone.setHealth(0);
                }
              }
            }
          }
            location = location.add(vector.multiply(0.1));
        }
      }
    Also, yes, I am using the ParticleEffect Library.
     
  10. Offline

    MCMatters

  11. Offline

    stickman561

    There is none! The console stops working, commands, interaction with mobs, blocks don't drop, then, 30 seconds later, everyone gets kicked and can't reconnect, but the server says that everyone is still on. /stop doesn't work, and the server needs to be force shut down with a "Vulcan nerve pinch". (Ctrl+Alt+Delete) -> Task Manager -> Java -> End Process -> End Now.
     
  12. This is probably a timed out, and I think it has to do with the while loop you have.
    Code:
    while(location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS) && distance > 0) {
    You check if the block is liquid OR air OR glass AND distance is higher than zero, it could be that you need to add a '(' and a ')' before and after when you check what block it is.
    Code:
    while((location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS)) && distance > 0) {
    You can also try to add the "break" keyword in the while loop to stop it from running. Maybe this will help.
     
    NathanWolf likes this.
  13. Offline

    stickman561

    Thanks! I'll try it now.

    It works now, but when I uncomment the particleeffect, I get an error. I will try to troubleshoot that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  14. try using world.playEffect() for now, just to see if it would work then. You can then always change it.
     
  15. Offline

    stickman561

    Ok.

    The effect works, but apparently location is staying constant at the player's head!

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

    MCMatters

  17. Offline

    stickman561

    It's supposed to travel along a vector.
     
  18. maybe make the amount that you add to the location a bit higher
     
  19. Offline

    stickman561

    Did nothing.
     
  20. If you can please give the code again, unless it hasn't changed since the last time you gave it. Then I can mess around for myself and see if I can get it to work, because I have no clue what to do right now. I hope I have the answer tomorrow.
     
  21. Offline

    stickman561

    Ok, here.
    Code:
    public static void shootlaser(Player player, boolean breaksblocks, boolean deadly, LaserType type, int distance) {
        Vector vector = player.getEyeLocation().getDirection();
        Location location = player.getEyeLocation();
        distance = distance * 10;
       
        while((location.getBlock().isLiquid() || location.getBlock().getType().equals(Material.AIR) || location.getBlock().getType().equals(Material.GLASS)) && distance > 0) {
            if(type.equals(LaserType.LASER_RIFLE)) {
                player.getWorld().playEffect(location, Effect.MOBSPAWNER_FLAMES, 1);
            }
        distance = distance - 1;
            if(breaksblocks) {
                if(location.getBlock().getType().isBlock() && !location.getBlock().getType().equals(Material.BEDROCK)) {
                    location.getBlock().breakNaturally();
            }
          }
           
            if(deadly) {
                List<Entity> entitylist = location.getWorld().getEntities();
                    for(Entity entity : entitylist) {
                        if(entity.getLocation().getBlock() == location) {
                            if(entity instanceof LivingEntity) {
                                LivingEntity liveone = (LivingEntity)entity;
                                liveone.setHealth(0);
                }
              }
            }
          }
            vector = vector.add(vector.multiply(0.1));
            location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
        }
      }
    
    public enum LaserType {
       
        LASER_RIFLE
       
      }
     
  22. This is quickly from my mobile, but
    1. vector = vector.add(vector.multiply(0.1));
    2. location = new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
    Should be
    1. location.add(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
    And if you still want that vector.multiply(0.1), you do it when initializing the vector

    Sorry for the weird markup
     
  23. Offline

    stickman561

    Ok. Testing...

    YES! THANK YOU!

    Umm, it only shoots along the four cardinal directions...?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  24. What do you mean with that? Some particle effects always display at the center of a block, just so you know.
     
  25. Offline

    stickman561

    I mean, the laser always goes North, South, East, West, Northeast, Southeast, Northwest, Southwest, Up, or Down. Nothing in between those.
     
  26. I think that it has to do something with the particles itself, because some particles are in fixed positions relative to the block they're in. Try increasing the distance and see if it then starts to look a bit like it, or try a different particle maybe use SMOKE. Just try that.
     
  27. Offline

    stickman561

    I know that it's the entire beam because the mobs only die along the particle trail.
     
  28. could you give the code again?
     
  29. Offline

    Zombie_Striker

    From what your code was before, you are not changing the actual 'location' variable. Increment the values of XYZ by the pitch and yaw of the player. There should also be a cut of range for how far the beam could go (E.G. 100 blocks away or if a chunk is not loaded.)
     
  30. Offline

    MnMaxon

    @stickman561
    I think this:
    Code:
     new Location(player.getWorld(), vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
    Should look like:
    Code:
     new Location(player.getWorld(), vector.getX(), vector.getY(), vector.getZ());
    getBlockX returns an int, so adding decimals won't really affect it.
    Also, you have this:
    Code:
    vector = vector.multiply(0.1);
    This code wouldn't be a problem, but you have it in your loop, so the values of vector cut into a 10th each time the loop goes around.
     
Thread Status:
Not open for further replies.

Share This Page