How to set modifiers in onCommand method?

Discussion in 'Plugin Development' started by heeavy, Sep 12, 2018.

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

    heeavy

    Hey, I want to use the "Player target" in other classes so I tried to set it to "public static" but then I get an error: "Illegal modifier for the variable target". So is there a way to set the target public and use it in other classes?

    player.PNG
     
  2. Offline

    Zombie_Striker

    @heeavy
    Do not use the static modifier. When it comes to making plugins, if you have to use the static modifier, most likely you are not passing objects correctly.

    If you want the target to be accessable by other classes, get the instance of the other class you want (either by passing the instance through this class's constructor, or by passing the Main class instance through this class's contructor, and have it so the other instance is accessible by the main class) Then, have a field in that other class to store the target (either being a single Player field if it has to be only one player for the whole plugin, or a List<Player> if multiple players can be stored) and set/add the player to that field.
     
  3. It’s because you’re trying to make the new reference in the method static- but the reference is created and lost when onCommand starts and ends. You can make variables static in the class itself, and then use a method to change the variable. But a map of players or using methods in other classes to pass the player to them would make more sense in most cases... Could you say a bit more of what you’re trying to do in the plugin, or how the GUI should work?
     
Thread Status:
Not open for further replies.

Share This Page