Multiple Arrow Limits

Discussion in 'Plugin Development' started by UberTrigger, Feb 5, 2016.

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

    UberTrigger

    Hey guys,

    I made a plugin where when you shoot a bow with full power, it shoots out multiple arrows, and it only works if you type /barrage.

    Code:
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Barrr extends JavaPlugin implements Listener{
      
        public void onEnable() {
          
        }
      
        public void onDisable() {
          
        }
      
        @EventHandler
        public void barrage(EntityShootBowEvent event) {
            if (event.getEntityType().toString().equals("PLAYER")) {
                if (event.getForce()==1.0) {
                    Entity mainArrow = event.getProjectile();
                  
                    for (int i = 1;i < 4;i++) {
                        mainArrow.getWorld().spawnArrow(mainArrow.getLocation(), mainArrow.getVelocity(), 3, 3).setShooter(event.getEntity());
                    }
                }
            }
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
          
            if (cmd.getName().equalsIgnoreCase("barrage")) {
                if (sender instanceof Player) {
                  
                    getServer().getPluginManager().registerEvents(this, this);
                }
            }
          
            return false;      
        }  
    }
    
    But, when I type /barrage over and over, the arrows I shoot get multiplied, so if I typed /barrage twice, then it would shoot 6 arrows, when I only want it to shoot 3. How do I do this? How would I limit the amount of arrows shot out of the bow to be 3, and not 3 * amount of times /barrage typed?

    EDIT: Eh one of the disadvantages of using forums and being a beginner, it gets you laughed on.

    Thanks!
    ~Uber
     
    Last edited: Feb 5, 2016
  2. God please forgive us.
     
    Evonoucono likes this.
  3. Offline

    teej107

    @UberTrigger Don't register the event multiple times.
    Also is this well.... I don't know exactly what to say. You know you can compare enums right?
     
  4. Offline

    Evonoucono

    Your code made me laugh... :D
     
  5. Offline

    adam753

  6. Offline

    Evonoucono

    Well... You were told about how to register events in your last post... Please listen carefully next time...
    https://bukkit.org/threads/simple-arrow-barrage.405449/

     
  7. Offline

    mcdorli

    Is this in the default package, ir you just remived the package declaration?
     
  8. Offline

    adam753

    @UberTrigger
    Sorry but your code really looks like a joke. What with all the specific and absurd things you've done wrong, it's hard to believe you're not an experienced programmer who made this thread as a joke.
     
  9. Offline

    teej107

    Not all "experienced programmers" know the Bukkit API. Be nice :p
     
  10. Offline

    adam753

    @teej107
    Okay then let me rephrase that to "Experienced Bukkit API user".
     
  11. Offline

    teej107

    Isn't that the reason for these forums? To help the people who don't have as much experience with the Bukkit API?
     
  12. Offline

    Evonoucono

    @teej107
    Yes but he should have read or watched some tutorials that at least cover the basics of the Bukkit API before attempting to make a plugin. Registering events should be one of the first things you learn. It's like learning java for the first time, I don't think someone would just start making programs without any experience. They would most likely watch/reed some tutorials first.
     
  13. Offline

    adam753

    @teej107
    Go re-read my point. I thought he WAS experienced with the Bukkit API and was making this as a joke.
     
  14. Offline

    mcdorli

    Also, there's nothing such as "experienced" programmer. Learning a language 100% would take a lifetime +- 10 years
     
  15. Offline

    adam753

    @mcdorli
    You have a strange definition of experienced.
     
    teej107 and Evonoucono like this.
Thread Status:
Not open for further replies.

Share This Page