Development Assistance Handling Reloads?

Discussion in 'Plugin Help/Development/Requests' started by AJKproductions, Jan 29, 2015.

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

    AJKproductions

    Hi Guys,
    I have just started working with bukkit, and i have come across this problem:

    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class TestPlugin extends JavaPlugin{
        @Override
        public void onEnable() {  //When the plugin starts these statments will be loaded
           
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                playerList.put(player.getName(), playerData(player));
            }
           
           
            getLogger().info("Test Plugin has started!");
           
        }
    This was taken directly from the bukkit tutorial wiki, yet Eclipse is telling me that
    "playerList cannot be resolved"
    &
    "The method playerData(Player) is undefined for the type TestPlugin"

    Anyone can help me? Sorry if I have been an idiot and the answer is something really simple...
     
  2. Offline

    Experminator

    @AJKproductions You need a hashmap with PlayerData.
    Example:

    Main class (open)

    Code:
    public class Main {
     
         Map<Player, PlayerData> playerData = new HashMap< Player, PlayerData>();
    
         public PlayerData getPlayerData(Player p){
             return playerData.get(p);
         }
    }


    PlayerData (open)

    Code:
    public class PlayerData {
     
        String name;
        Location loc;
        PlayerInventory inv;
    
        public PlayerData(String name, Location loc, PlayerInventory inv){
            this.name = name;
            this.loc = loc;
            this.inv = inv;
        }
    
        public String getName(){
           return name;
        }
    
        public Location getLocation(){
            return loc;
        }
    
        public PlayerInventory getInventory(){
            return inv;
        }
    }
    Code:
    public class PlayerData {
     
        String name;
        Location loc;
        PlayerInventory inv;
    
        public PlayerData(String name, Location loc, PlayerInventory inv){
            this.name = name;
            this.loc = loc;
            this.inv = inv;
        }
    
        public String getName(){
           return name;
        }
    
        public Location getLocation(){
            return loc;
        }
    
        public PlayerInventory getInventory(){
            return inv;
        }
    }


    You can also add more fields in the class: PlayerData.

    Note: My example uses Player, but that's not the best way. It can cause memory leaks.
    But i use that for example, you must use String (For name of player.) or UUID (For uuid of player).
     
    Last edited: Jan 29, 2015
    AJKproductions likes this.
  3. Offline

    AJKproductions

    Thank You! I think I got it working, but i ran into another problem :( so I am going to have to create another thread...
     
  4. Offline

    Experminator

  5. Offline

    AJKproductions

    Okay, so i compiled my plugin then i ran into "Cannot find main class" error when i launched my server...
    Here is my plugin.yml file
    plugin.yml (open)

    Code:
    main: AJKproductions.github.io.TestPlugin
    name: TestPlugin
    version: "0.0.1-SNAPSHOT"
    author: "AJKproductions"
    commands:
        testcommand:
          description: This is a test command
          usage: /<command>
          permission: TestPlugin.testcommand
          permission-message: You don't have <permission>


    Here is my main file(called "TestPlugin")
    TestPlugin.java (open)

    Code:
    package AJKproductions.github.io.TestPlugin;
    
    import java.io.File;
    import java.util.HashMap;
    import java.util.Map;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public final class TestPlugin extends JavaPlugin{
    
       
        @Override
        public void onEnable() { 
    
           
           
            getLogger().info("Test Plugin has started!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("testcommand"))
            {
                sender.sendMessage("Command Executed");
            }
           
            return false;
        }
       
        @Override
        public void onDisable() { //When the plugin is disabled or stopped these statments will be disabled
            getLogger().info("Plugin has been disabled!");
        }
    
    }
    


    This might help:
    [​IMG]
    Again, sorry if the answer is really obvious...
     
  6. Offline

    Experminator

    @AJKproductions The main seems good.
    But multiple notices:
    Why is .. in quotionmarks?:
    - Author? (Use: author: <name>)
    - Version? (Use: version: <1.0> (Only numbers/doubles.)
    - Package? Your package structure is a bit strange. (Use: io.github.AJKproductions.TestPlugin) <- That's the correct way.
     
  7. Offline

    Lolmewn

    @Experminator No it's not, TestPlugin needs to be repeated. Right now it's only the package name, not the class.
     
    Experminator and TGRHavoc like this.
  8. Offline

    AJKproductions

    Thank You all! @Lolmewn was right, I changed it an now it works! And @Experminator I changed my file/package structure to what you said. Thanks Guys :)
     
  9. Offline

    Experminator

    @Lolmewn I see now, Sorry about my mistake!
    - I saw the package and i think... ow... add the class name again to the package...


    @AJKproductions About package names: It's better to use lowercase names instead uppercase names. Only class names must be in uppercase (For suggestion).

    So you cannot be confused (Like me) about the package and the class.
     
Thread Status:
Not open for further replies.

Share This Page