Need help with few things.

Discussion in 'Plugin Development' started by omnee, Sep 9, 2011.

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

    omnee

    I started developing plugins today... Well made a plugin called LoginLogout that when you loggin it shows "name" has joined/left the game and I want to make a config file so people can make costume messages, I want some help with this, I am not asking to be spoonfeeded, I am just asking for a few tips/tutorials/help. :D
    Thanks -Omnee-
     
  2. Offline

    DrAgonmoray

  3. Offline

    stelar7

  4. Offline

    omnee

  5. Offline

    DrAgonmoray

    PHP:
    public class Config {
        private static 
    uCreate plugin;
        public 
    Config(uCreate instance) {
            
    plugin instance;
        }

        public 
    String directory "plugins" File.separator "uCreate";
        
    File file = new File(directory File.separator "config.yml");
        
    File file2 = new File(directory File.separator "homes.yml");
        
    File file3 = new File(directory File.separator "SpoutInventory.yml");

        public 
    Configuration config;
        public 
    Configuration homes;
        public 
    Configuration spout;


        public 
    void configCheck() {
            try {
                new 
    File(directory).mkdir();
                if (!
    file.exists()) {
                    
    file.createNewFile();
                    
    config = new Configuration(file);
                    
    //example
                    
    config.setProperty("settings.worlds""world1, world3, etc");

                }
                if (!
    file2.exists()) {
                    
    file2.createNewFile();
                    
    homes = new Configuration(file2);
                    
    homes.save();
                }
                if (!
    file3.exists()) {
                    
    file3.createNewFile();
                    
    spout = new Configuration(file3);
                    
    ArrayList<Stringls = new ArrayList<String>();
                    
    ls.add("1");
                    
    ls.add("2");
                    
    ls.add("35:6");
                    
    spout.setProperty("Inventory 1"ls);
                    
    spout.save();
                }
                
    config = new Configuration(file);
                
    homes = new Configuration(file2);
                
    spout = new Configuration(file3);
                
    loadconfig();
            } catch (
    Exception e) {
                
    e.printStackTrace();
            }
        }
     
        public 
    boolean readBoolean(String node) {
            
    Object v config.getProperty(node);
            if (
    != null) {
                return 
    config.getBoolean(nodefalse);
            } else {
                
    config.setProperty(nodefalse);
                
    config.save();
                return 
    false;
            }
        }

        public 
    int readInt(String nodeint def) {
            
    Object v config.getProperty(node);
            if (
    != null) {
                return 
    config.getInt(node0);
            } else {
                
    config.setProperty(nodedef);
                
    config.save();
                return 
    def;
            }
        }

        public 
    String readString(String nodeString def) {
            
    Object v config.getProperty(node);
            if (
    != null) {
                return 
    config.getString(node);
            } else {
                
    config.setProperty(nodedef);
                
    config.save();
                return 
    def;
            }
        }

        public 
    void loadconfig() {
            
    config.load();
            
    //Example
            
    plugin.worlds readString("settings.worlds""").replace(" """).split(",");
        }
    }
    That is the code for my uCreate config file, with a few things snipped. It illustrates having multiple configs, and stuff.

    In my main class, I do this:
    PHP:
    private Config config = new Config(this);
    public 
    String worlds;

    public 
    void onEnable() {
        
    //This will create the config files if they don't exist, and load the values
        
    config.configCheck();
    }
     
  6. Offline

    omnee

    I done this but im confused
    Code:
    public void onEnable() {
        CONFIG.setProperty("Op Login Prefix", "Op ");
        CONFIG.setProperty("Op Logout Prefix", " has joined the game");
        CONFIG.setProperty("Op Login Prefix", "Op ");
        CONFIG.setProperty("Op Logout Prefix", " has left the game");
        CONFIG.setProperty("Player Login Prefix", "");
        CONFIG.setProperty("Player Logout Prefix", " has joined the game");
        CONFIG.setProperty("Player Login Prefix", "");
        CONFIG.setProperty("Player Logout Prefix", " has left the game");
    
    but now how do I make so when someone joins it shows what its saying in the config.yml?
    what do I need to add on PlayerLoginEvent and etc ?
    if anyone wants my playerloginevent or playerquitevent tell me and i will pm with it so you can help me :D
     
  7. Offline

    stelar7

    You cant have variables with the same name!
    Code:java
    1. public void onEnable() {
    2. CONFIG.setProperty("Op Login Prefix", "Op ");
    3. CONFIG.setProperty("Op Join Prefix", " has joined the game");
    4. CONFIG.setProperty("Op Quit Prefix", " has left the game");
    5. CONFIG.setProperty("Player Login Prefix", "");
    6. CONFIG.setProperty("Player Join Prefix", " has joined the game");
    7. CONFIG.setProperty("Player Quit Prefix", " has left the game");
    8. }
    Code:java
    1. onPlayerQuit(PlayerQuitEvent event) {
    2. if (!event.getPlayer().isOp()) {
    3. event.setQuitMessage(plugin.config.getString("Player Login Prefix") + event.getPlayer() + plugin.config.getString("Player Quit Prefix"));
    4. } else {
    5. event.setQuitMessage(plugin.config.getString("Op Login Prefix") + event.getPlayer() + plugin.config.getString("Op Quit Prefix"));
    6. }
    7. }
     
  8. Offline

    omnee

    thank you :D your help is much apreciated ill add credits to you in my plugin page :D

    I have 2 more questions :confused:
    i setted the onenable like this:
    Code:
        public void onEnable() {
            CONFIG.setProperty("Op Login Sufix", "Op ");
            CONFIG.setProperty("Op Logout Prefix", " has joined the game");
            CONFIG.setProperty("Op Login Sufix", "Op ");
            CONFIG.setProperty("Op Logout Prefix", " has left the game");
            CONFIG.setProperty("Player Login Sufix", "");
            CONFIG.setProperty("Player Logout Prefix", " has joined the game");
            CONFIG.setProperty("Player Login Sufix", "");
            CONFIG.setProperty("Player Logout Prefix", " has left the game");
    and when I run the server with the jar file in it it doesnt create a file called config.yml(and if it creates then i dont know where :confused:)
    what is the problem?

    Also i want to make so the basic bukkit Login+Logout Alerts don't show, so only mines does
    what do I add to onEnable?
    your help will be apreciated and I will give credits in my plugin page

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  9. Offline

    stelar7

    It needs to look like this:
    Code:java
    1. public void onEnable() {
    2. config = getConfiguration();
    3. config.load();
    4. //set properties here
    5. config.save();
    6. }
    Code:java
    1. public void onPlayerQuit(PlayerQuitEvent event) {
    2. //remove the current message
    3. event.setQuitMessage(null);
    4. //make our own message
    5. if (!event.getPlayer().isOp()) {
    6. event.setQuitMessage(plugin.config.getString("Player Login Prefix") + event.getPlayer() + plugin.config.getString("Player Quit Prefix"));
    7. } else {
    8. event.setQuitMessage(plugin.config.getString("Op Login Prefix") + event.getPlayer() + plugin.config.getString("Op Quit Prefix"));
    9. }
    10. }
     
  10. Offline

    omnee

    wow man I can consider you an ''EPIC EXPERT'' and just btw thank you I will try this out, i will notice you if it works/doesnt work :D

    edit: I get an error and when i click the light bulb it asks me to create the variable config o.o?
    isnt config already declared -.-'?

    edit2: declared it and now it looks like this
    Code:
        protected static Configuration config;
        public void onEnable() {
            config = getConfiguration();
            config.load();
            config.save();
    ill test it :D

    edit3:
    Code:
    public void onPlayerQuit(PlayerQuitEvent event) {
    //remove the current message
        event.setQuitMessage(null);
    //make our own message
        if (!event.getPlayer().isOp()) {
            event.setQuitMessage(plugin.config.getString("Player Login Prefix") + event.getPlayer() + plugin.config.getString("Player Quit Prefix"));
        } else {
            event.setQuitMessage(plugin.config.getString("Op Login Prefix") + event.getPlayer() + plugin.config.getString("Op Quit Prefix"));
        }
    }
    plugin.config.getString(the word plugin gets error "plugin cannot be resolved"
    why do I get that error? do I need to declare it? if yes how do I do it?
     
  11. Offline

    stelar7

    You probably declared CONFIG instead, Java is case sensitive...

    change:
    Code:
    protected static Configuration config;
    to:
    Code:
    public static Configuration config;
    so you can access it from other classes
     
  12. Offline

    omnee

    your giving me a nice tips man you srsly need loads of credits in my plugin page
    read the edit 3:
    i think i need to declare it, i dont know how :/
     
  13. Offline

    stelar7

    how many classes do you have?
    if only 1 remove "plugin"

    if more add this
    Code:java
    1. public CLASSNAMEHERE(MAINCLASSHERE instance) {
    2. plugin = instance;
    3. }
     
  14. Offline

    omnee

    thank you I think it is all for now
    edit: i still get the error
    edit2: woops soz i didnt wait for u to finish the code :D

    and i have 2 classes, LoginLogoutMain and LoginLogoutPlayerListener
    wich class do I add it to?
     
  15. Offline

    stelar7

    the playerlistener like this:

    Code:java
    1. public LoginLogoutPlayerListener(LoginLogoutMain instance) {
    2. plugin = instance;
    3. }
     
  16. Offline

    omnee

    it isnt working... i already tried adding it before
    public class LoginLogoutPlayerListener extends PlayerListener{

    and before

    }
    public void onPlayerQuit(PlayerQuitEvent event) {

    but it simply get an X in the place of the lightbulb and it doesnt say any error down there

    im sorry for beeing so noob xD im failing kind of hard because its my 1st time working with configs :(
     
  17. Offline

    stelar7

    could you paste your playerlistener?
     
  18. Offline

    omnee

    Code:
    package me.omnee.LoginLogout;
    
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class LoginLogoutPlayerListener extends PlayerListener{
        public void onPlayerLogin(PlayerLoginEvent event) {
            //remove the current message
                event.setQuitMessage(null);
            //make our own message
            if (!event.getPlayer().isOp()) {
                event.setQuitMessage(plugin.config.getString("Player Login Sufix") + event.getPlayer() + plugin.config.getString("Player Login Prefix"));
            } else {
                event.setQuitMessage(plugin.config.getString("Op Login Sufix") + event.getPlayer() + plugin.config.getString("Op Login Prefix"));
    
            }
        }
    
        public void onPlayerQuit(PlayerQuitEvent event) {
            //remove the current message
                event.setQuitMessage(null);
            //make our own message
                if (!event.getPlayer().isOp()) {
                    event.setQuitMessage(plugin.config.getString("Player Logout Sufix") + event.getPlayer() + plugin.config.getString("Player Login Prefix"));
                } else {
                    event.setQuitMessage(plugin.config.getString("Op Logout Sufix") + event.getPlayer() + plugin.config.getString("Op Logout Prefix"));
                }
            }
    }
    
    there you go
    the player/op login/logout sufix/prefix need to be changed their wrong :D
    there are missing many things

    also about the event.setQuitMessage(null); what about the login one?
    event.setJoinMessage(null); ??
    or anything else?
     
  19. Offline

    stelar7

    if you type "event." it should give you some options, there should be an setJoinMessage() there...


    add this before the PlayerLoginEvent:
    Code:java
    1. public static LoginLogoutMain plugin;
    2.  
    3. public LoginLogoutPlayerListener(LoginLogoutMain instance) {
    4. plugin = instance;
    5. }
     
  20. Offline

    omnee

    Code:
    package me.omnee.LoginLogout;
    
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class LoginLogoutPlayerListener extends PlayerListener{
        public static LoginLogoutMain plugin;
    
        public LoginLogoutPlayerListener(LoginLogoutMain instance) {
            plugin = instance;
        }
        public void onPlayerLogin(PlayerLoginEvent event) {
            //remove the current message
                event.setQuitMessage(null);
            //make our own message
            if (!event.getPlayer().isOp()) {
                event.setQuitMessage(plugin.config.getString("Player Login Sufix") + event.getPlayer() + plugin.config.getString("Player Login Prefix"));
            } else {
                event.setQuitMessage(plugin.config.getString("Op Login Sufix") + event.getPlayer() + plugin.config.getString("Op Login Prefix"));
    
            }
        }
    
        public void onPlayerQuit(PlayerQuitEvent event) {
            //remove the current message
                event.setQuitMessage(null);
            //make our own message
                if (!event.getPlayer().isOp()) {
                    event.setQuitMessage(plugin.config.getString("Player Logout Sufix") + event.getPlayer() + plugin.config.getString("Player Login Prefix"));
                } else {
                    event.setQuitMessage(plugin.config.getString("Op Logout Sufix") + event.getPlayer() + plugin.config.getString("Op Logout Prefix"));
                }
            }
    }
    
    now i have red line under setQuitMessage of playerLoginEvent only
    and yellow line under config of both :(
    man I am getting confused now :S idk what to do!
     
  21. Offline

    stelar7

    this should not give any errors :
    Code:java
    1.  
    2. public class LoginLogoutMain extends JavaPlugin {
    3.  
    4. public Configuration config;
    5.  
    Code:java
    1. package me.omnee.LoginLogout;
    2.  
    3. import org.bukkit.event.player.PlayerJoinEvent;
    4. import org.bukkit.event.player.PlayerListener;
    5. import org.bukkit.event.player.PlayerQuitEvent;
    6.  
    7. public class LoginLogoutPlayerListener extends PlayerListener {
    8. public static LoginLogoutMain plugin;
    9.  
    10. public LoginLogoutPlayerListener(LoginLogoutMain instance) {
    11. plugin = instance;
    12. }
    13.  
    14. public void onPlayerJoin(PlayerJoinEvent event) {
    15. // remove the current message
    16. event.setJoinMessage(null);
    17. // make our own message
    18. if (!event.getPlayer().isOp()) {
    19. event.setJoinMessage(plugin.config.getString("Player Login Sufix") + event.getPlayer() + plugin.config.getString("Player Login Prefix"));
    20. } else {
    21. event.setJoinMessage(plugin.config.getString("Op Login Sufix") + event.getPlayer() + plugin.config.getString("Op Login Prefix"));
    22. }
    23. }
    24.  
    25. public void onPlayerQuit(PlayerQuitEvent event) {
    26. // remove the current message
    27. event.setQuitMessage(null);
    28. // make our own message
    29. if (!event.getPlayer().isOp()) {
    30. event.setQuitMessage(plugin.config.getString("Player Logout Sufix") + event.getPlayer() + plugin.config.getString("Player Login Prefix"));
    31. } else { event.setQuitMessage(plugin.config.getString("Op Logout Sufix") + event.getPlayer() + plugin.config.getString("Op Logout Prefix"));
    32. }
    33. }
    34. }
     
  22. Offline

    omnee

    Wow man, finaly no errors gonna try it out

    Edit:
    Code:
        private final LoginLogoutPlayerListener pListener = new LoginLogoutPlayerListener(LoginLogoutMain);
    Description Resource Path Location Type
    The constructor LoginLogoutPlayerListener() is undefined LoginLogoutMain.java /Login&Logout/src/me/omnee/LoginLogout line 12 Java Problem

    Eclipse doesnt want me to get my plugin working xD (this error is in the main class)
     
  23. change

    Code:
     public LoginLogoutPlayerListener(LoginLogoutMain instance) {
           plugin = instance;
      }
    
    
    to

    Code:
      public LoginLogoutPlayerListener(LoginLogoutPlayerListener instance) {
        plugin = instance;
    
       }
    

    Thats what i would try anyway, I dont know if its right, im new to coding also :p
     
Thread Status:
Not open for further replies.

Share This Page