BoomStick not working. Help?

Discussion in 'Plugin Development' started by TheLazeboy, Jun 5, 2013.

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

    TheLazeboy

  2. Offline

    TheUpdater

    post code
     
  3. Offline

    TheLazeboy

  4. Offline

    TheUpdater

    if(evt.getAction().equals(evt.getAction.LEFT/RIGHT CLICK);
    just do ctrl + space to get options what to put
     
  5. Offline

    TheLazeboy

    So this is what I added in my code: "if(evt.getAction().equals(evt.getAction.RIGHT_CLICK));", where do I do the CTRL + SPACE? I'm no expert of coding. :p Also the "getAction" behind ".RIGHT_CLICK));" is getting an error.
     
  6. Offline

    SoThatsIt

    Theres no need to do eve.getAction.LEFT/RIGHT Click you can just do if(evt.getAction().equals(Action.LEFT/RIGHT CLICK);
     
  7. Offline

    TheLazeboy

    I want it to be just right click, but the "RIGHT" & "CLICK" have errors.
     
  8. Offline

    TheUpdater

    if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if (e.getAction() == Action.RIGHT_CLICK_AIR) {
    if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
    if (e.getAction() == Action.LEFT_CLICK_AIR) {

    use 1 of em or use both like this
    if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
    if (e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_AIR) {
     
  9. Offline

    TheLazeboy

    This is the part code I have right now: http://pastebin.com/zmEux8v4. And it isn't working in game.
     
  10. Offline

    TheUpdater

    Code:
    @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent evt){
    Player player = evt.getPlayer();
    Location locd = (Location) player.getTargetBlock(null, 10);
            if(evt.getPlayer().getItemInHand().getType() == Material.STICK){
                 if (evt.getAction() == Action.RIGHT_CLICK_BLOCK || evt.getAction() == Action.RIGHT_CLICK_AIR) {
                player.getWorld().strikeLightning(locd);
            }
        }
    }
    }
    try that
     
  11. Offline

    TheLazeboy

    Still not working in-game.
     
  12. Offline

    TheUpdater

    has you registered events?
     
  13. Offline

    TheLazeboy

    I don't think so; although, not entirely sure what events are. :3
     
  14. Offline

    TheUpdater

    post fully code all of it

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

    TheLazeboy

  16. Offline

    TheUpdater

    bukkit.getpluginmanager().registerEvents(MyPlayerListener, this);

    add that in onEnable
     
  17. Offline

    TheLazeboy

    I fixed the minor mistakes, but here is the new code "Bukkit.getPluginManager().registerEvents(MyPlayerListener, this);" the "MyPlayerListener" is an error, though.
     
  18. Offline

    TheUpdater

    what is error saying?
     
  19. Offline

    TheLazeboy

    "MyPlayerListener cannot be resolved to a variable". there are 4 quick fixes; although, they don't seem to be the right fixes.
     
  20. Offline

    TheUpdater

    hm...

    add this to under main class name
    public final MyPlayerListener mp = new MyPlayerListener(this);

    and this is on enable
    Bukkit.getPluginManager().registerEvents((Listener) mp, this);

    then create constructor in My PlayerListener

    add this under constructor

    public static Staves plugin;

    public void mp(Staves instance){
    plugin = instance;
    }
    public void Enable(boolean b) {
    // TODO Auto-generated method stub
    }
     
  21. Offline

    TheLazeboy

    How do I add a constructor?
     
  22. Offline

    TheUpdater

    hold over the red one on this one
    public final MyPlayerListener mp = new MyPlayerListener(this);
     
  23. Offline

    TheLazeboy

    Errors everywhere. Can you please try this in Eclipse as well?

    Not literally errors everywhere. :3 Just exaggerating.

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

    TheUpdater

    tell errors
     
  25. Offline

    TheLazeboy

  26. Offline

    Wingzzz

    TheLazeboy
    Alright a constructor is basically a method with the name of the class. The code inside it will execute code once you've initialized an object of it's type, ex:
    Code:java
    1. public MyPlayerListener myPlayerListener = new MyPlayerListener(this.staves);

    Now the parameters are going off of what you have, assuming this is done with a variable name staves in whatever class you're making the MyPlayerListener object. None the less that's not really important. Constructors also sometimes take parameters to help initialize some objects inside the class.

    So what you have is this:
    Code:java
    1. public MyPlayerListener(Staves staves) {
    2. // TODO Auto-generated constructor stub
    3. }

    Which is pretty much useless since the staves parameter is being unused. Classes by default have an empty constructor, which is why when you initialize an object without an explicitly defined constructor you see something along the lines of:
    Code:java
    1. ExampleObject object = new ExampleObject();

    So, if you're using Staves as a parameter for your MyPlayerListener constructor you should have a reason. So, right here I see you do:
    Code:java
    1. public void mp(Staves instance){
    2. plugin = instance;
    3. }

    Ah there we go... You've been basically doing what constructors are so loved for all along... Except err... Not in a constructor. What you've done here is say okay, once I make my MyPlayerListener object I'll go ahead and call myPlayerListener.mp(this); (if you did it in your Staves class- "this" keyword is a reference to the class it's used in) to ensure the "plugin" variable is instantiated. Okay, works sure... Although let's get this done all in one go shall we?

    Remove the mp(...) method... And transfer it's contents to your constructor like so:
    Code:java
    1. public MyPlayerListener(Staves plugin) {
    2. this.plugin = plugin;
    3. }

    Now when you instantiate a MyPlayerListener object it will have it's "plugin" variable all good to go.

    More information on constructors: http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

    Alright awesome! We understand that, it'll be really helpful in the future. Multiple parameters will help to get our variables rockin' and we'll have some excellent classes to use!

    Although err... You're now having a slight problem with understanding what events are eh? Alright might as well tackle that one as well, right? So an Event is basically something that is fired off when something happens. EX: I join a server, the code the handles that has an event named PlayerJoinEvent that is called as apart of that code so that we may manipulate some things when a player joins. Synopsis: Something happens, we can listen for Events so we can manipulate what happened or is going to happen during the event.

    Specific to your problem is you just simply haven't registered your event. Fix it by- well... registering it like so:
    Code:java
    1. getServer().getPluginManager().registerEvents(new MyPlayerListener(this), this);

    Throw that line of code in the onEnable() or in a method that ends up in the onEnable() eventually...
    Alright excellent! Now the server knows of all the events in the Listener(first param) and the plugin(second param).

    More information on Events: http://wiki.bukkit.org/Event_API_Reference

    Sorry if this is a little long, but hey... Why not right?

    Let me know if you don't understand something or need clarification. I'm not really the greatest at explaining but hey, sometimes people understand me and I'll take that any day ;)
     
Thread Status:
Not open for further replies.

Share This Page