Solved Shooting effect trail?

Discussion in 'Plugin Development' started by GreatMinerZ, Nov 23, 2013.

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

    GreatMinerZ

    Hey,

    i just started coding again and need help with creating a plugin that 'shoots' effects trough the air. (fired by an stick)
    I need to loop the effects like a trail and then create a explosion where the player is looking.
    Anyone wanting to help me?

    Thanks!
     
  2. Offline

    Windy Day

    Get the block the player is looking at. Get their line of sight, use a block iterator to play an effect at every location. Create the explosion where they are looking.
     
  3. Offline

    GreatMinerZ

    Can you give me an example on how to do the important parts? Like the trail
     
  4. Offline

    Windy Day

    Well, if you are shooting a projectile, you could add it to an arraylist of entities. Then schedule a task that plays an effect at that location every so often, effectively making a trail. But the way i would do it is use something like this:
    Code:
                    Location location = player.getEyeLocation();
                      BlockIterator blocksToAdd = new BlockIterator(location, Y-offset Double, Distance);
                      Location blockToAdd;
                      while(blocksToAdd.hasNext()) {
                          blockToAdd = blocksToAdd.next().getLocation();
                          player.getWorld().playEffect(blockToAdd, Effect.EFFECT, integer);
                      }
     
  5. Offline

    GreatMinerZ

    Thanks, i'll try it now.
     
  6. Offline

    Zarko

  7. Offline

    GreatMinerZ

    Can somebody give me an example of how to do it so i can learn from it and expand it?
     
  8. Offline

    DarkBladee12

  9. Offline

    GreatMinerZ

    Last edited by a moderator: Jun 5, 2016
  10. Offline

    chasechocolate

  11. Offline

    GreatMinerZ

  12. Offline

    chasechocolate

    I don't think so, AFAIK it's been around ever since entity.getLineOfSight() has. Maybe > 6 months?
     
  13. Offline

    xTrollxDudex

  14. Offline

    GreatMinerZ

    So.. this code won't give any errors in eclipse but when i start the server it won't work?

    Error: [SEVERE] Could not load 'plugins\Railgun.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassCastException

    Code:
    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2.  
    3. @Override
    4. public void onEnable(){
    5. getLogger().info("Plugin started!");
    6. getServer().getPluginManager().registerEvents(this, this);
    7. }
    8.  
    9. @Override
    10. public void onDisable() {
    11. getLogger().info("Plugin stopped!");
    12. }
    13.  
    14. public void onPlayerUse(PlayerInteractEvent e) {
    15. Player p = e.getPlayer();
    16.  
    17. if(p.getItemInHand().getType() == Material.BLAZE_ROD) {
    18.  
    19. Location pl = p.getEyeLocation();
    20.  
    21. double px = pl.getX();
    22. double py = pl.getY();
    23. double pz = pl.getZ();
    24.  
    25. double yaw = Math.toRadians(pl.getYaw() + 90);
    26. double pitch = Math.toRadians(pl.getPitch() + 90);
    27.  
    28. double x = Math.sin(pitch) * Math.cos(yaw);
    29. double y = Math.sin(pitch) * Math.sin(yaw);
    30. double z = Math.cos(pitch);
    31.  
    32. for(int i = 1 ; i <= 70 ; i++) {
    33. Location loc = new Location(p.getWorld(), px + i*x, py + i*z, pz + i*y);
    34. if(loc.getBlock().getType() == Material.AIR)
    35. p.getWorld().createExplosion(loc, 1f);
    36. else break;
    37. }
    38. }
    39.  
    40. }
    41.  
    42. }
     
  15. Offline

    xTrollxDudex

    GreatMinerZ
    What the heck... What are you trying to do?
     
    AoH_Ruthless likes this.
  16. Offline

    GreatMinerZ

    xTrollxDudex nvm collected code from other threads..

    xTrollxDudex the problem with the other code is that getLineOfSight is deprecated

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

    AoH_Ruthless

    GreatMinerZ
    Deprecated methods function normally. They are just unsupported and may not work at any given update. But, you can use them for the time being. Just suppress any warnings you get.
     
  18. Offline

    mattrick

    You should definitely not do this.....
     
  19. Offline

    GreatMinerZ

    AoH_Ruthless Thanks for the info =)

    mattrick16 removed it now.

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

    AoH_Ruthless

    GreatMinerZ
    Now that all of that is settled; there may be an error with your plugin.yml file. Please post that.
     
  21. Offline

    GreatMinerZ

    Eclipse won't give any errors but the server does (ClassCastExeption)

    Code:

    Code:java
    1. import java.lang.reflect.Method;
    2. import java.util.Random;
    3. import org.bukkit.Location;
    4. import org.bukkit.block.Block;
    5. import org.bukkit.entity.Firework;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin implements Listener {
    12.  
    13. int timer,id = 0;
    14. Random gen = new Random();
    15.  
    16. public void onEnable(){
    17. this.getServer().getPluginManager().registerEvents(this, this);
    18. }
    19.  
    20.  
    21. @EventHandler
    22. public void onS(PlayerInteractEvent event){
    23. try {
    24. for(Block loc:event.getPlayer().getLineOfSight(null, 100)){
    25. playFirework(loc.getLocation());
    26. }
    27. } catch (Exception e) {
    28. // TODO Auto-generated catch block
    29. e.printStackTrace();
    30. }
    31. }
    32. private Object[] dataStore = new Object[5];
    33. public void playFirework(Location loc) throws Exception {
    34. Firework fw = (Firework) loc.getWorld().spawn(loc, Firework.class);
    35. if(dataStore[0] == null) dataStore[0] = getMethod(loc.getWorld().getClass(), "getHandle");
    36. if(dataStore[2] == null) dataStore[2] = getMethod(fw.getClass(), "getHandle");
    37. dataStore[3] = ((Method) dataStore[0]).invoke(loc.getWorld(), (Object[]) null);
    38. dataStore[4] = ((Method) dataStore[2]).invoke(fw, (Object[]) null);
    39. if(dataStore[1] == null) dataStore[1] = getMethod(dataStore[3].getClass(), "addParticle");
    40. ((Method) dataStore[1]).invoke(dataStore[3], new Object[] {"fireworksSpark", loc.getX(),loc.getY(),loc.getZ(),gen.nextGaussian() * 0.05D, -(loc.getZ()* 1.15D) * 0.5D, gen.nextGaussian() * 0.05D});
    41. fw.remove();
    42. }
    43. private Method getMethod(Class<?> cl, String method) {
    44. for(Method m : cl.getMethods()) if(m.getName().equals(method)) return m;
    45. return null;
    46. }
    47. }


    and my plugin.yml:

    Code:
    name: RailGun
    main: nl.dutchlands.railgun.Main
    version: 1.0
     
  22. Offline

    xTrollxDudex

    GreatMinerZ
    Use a block iterator like chasechocolate said:
    PHP:
    BlockIterator it = new BlockIterator(player0);
    while(
    it.hasNext()) {
        
    playFirework(it.next().getLocation());
    }
    Otherwise, post the stacktrace
     
  23. Offline

    AoH_Ruthless

    GreatMinerZ
    And you are positive your package is called nl.dutchlands.railgun (case-sensitive). I'm asking because you didn't post it in the code.
     
  24. Offline

    GreatMinerZ

    xTrollxDudex where should i place the block iterator? Sorry for the noob questions..

    AoH_Ruthless above the imports:
    Code:java
    1. package nl.dutchlands.railgun;


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

    AoH_Ruthless

  26. Offline

    GreatMinerZ

    AoH_Ruthless i understand. Really want to get this working :D

    Still can't get it to work :'(

    Anyone?

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

    fromgate

  28. Offline

    GreatMinerZ

  29. Offline

    GreatMinerZ

    Fixed. Thanks for help ;)
     
  30. Offline

    militiaspack


    Your profile pic scares the shit outta me
     
Thread Status:
Not open for further replies.

Share This Page