Getting variable out of getter

Discussion in 'Plugin Development' started by McJoshuaGaming, Feb 12, 2020.

  1. Offline

    McJoshuaGaming

    Hello, I am having trouble getting the "targetplayer" out of the getter.



    Code:
    static String target;
     
        public static void main(String[] args) {
            Grant targetplayer = new Grant();
        }
     
        public static void clicked(Player p, int slot, ItemStack clicked, Inventory inv) {
            if(clicked.getItemMeta().getDisplayName().equalsIgnoreCase(Utils.chat("&3&lFounder"))) {
                p.getServer().dispatchCommand(p.getServer().getConsoleSender(), "lp user "+targetplayer.getTargetPlayer()+" parent remove founder");
                p.closeInventory();
             
            }
        }
     
    Last edited: Feb 12, 2020
  2. Online

    timtower Moderator Moderator

    @McJoshuaGaming You have no getter though.
    Nor will this work due to it having the public static main.
     
  3. Offline

    McJoshuaGaming

    Code:
    public static void main(String[] args) { 
    Grant targetplayer = new Grant(); 
    }
    That is the getter is it not? that's what I have seen on tutorials that I have looked at..
     
  4. Online

    timtower Moderator Moderator

    No, that is a main function, you only need it when you are writing a full application, which you are not.
     
  5. Offline

    Strahan

    I don't think your grasp of Java is where it needs to be. Nothing about that "gets". It just creates a new variable in that method and as timtower said, that's for a regular Java application. For a MC plugin, you'll never have that.

    Also I'd consider leveraging the LuckPerms API rather than issuing commands. Cleaner, IMO.
     

Share This Page