[Code] java help

Discussion in 'Plugin Development' started by komes, Feb 2, 2011.

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

    komes

    Ok well here is my problem. I have made the basics to this plugin i am fiddling around with, for my first project. And i have ran into this problem. So i have 3 classes BlastPick.java, BlastPickPlayerListener.java, BlastPickBlockListener. and in my PlayeListener i have 2 methods onPlayerCommand and onLength.


    Code:
    public int onLength(PlayerChatEvent event) {
              String s;
              int Length = 0;
              String[] split = event.getMessage().split(" ");
    
                if ((split[0].equalsIgnoreCase("/BlastLength"))) {
                    s = split[1];
                    Length = Integer.parseInt(s.trim());
                }
                return Length;
            }



    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
              //Make the message a string.
                String[] split = event.getMessage().split(" ");
                //Get the player that talked.
                Player player = event.getPlayer();
                //If the first part of the string is /BlastPick or /b then do this.
                if ((split[0].equalsIgnoreCase("/BlastBox"))) {
                    //Run the method toggleVision for player
                    plugin.toggleVision(player);
                    event.setCancelled(true);
                }
    
            }







    How would i get the return value of my onLength method into my blocklistener class.
     
  2. Offline

    Killie01

    what is the problem then
     
  3. Offline

    Archelaus

    You never specified what the problem was
     
  4. Offline

    komes

    sorry for not putting my question i have edited it.
     
  5. Offline

    Lemonstein

    If you need to do such a thing why not have BlastPick supersede the other two classes and define onLength() there?

    The simple solution here is to make onLength() static and call BlastPickPlayerListener.onLength(param);


    Code:
    public static int onLength(PlayerChatEvent event) {
              //do stuff
    
                }
            }
     
  6. Offline

    Lologarithm

    I agree, make it static if its a method that doesn't need an instance of a class to use.

    Even better, separate out 'helper' methods like that into a utilities class that is static and just access the methods from there.
     
  7. Offline

    komes

    yeah i solved my problem by using a hashmap.
     
Thread Status:
Not open for further replies.

Share This Page