Need a tester/fixer

Discussion in 'Plugin Development' started by theearlypc423, Jan 3, 2013.

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

    Jogy34

    No I'm good. I didn't really do anything directly with your plugin so it wouldn't really make sense for me. Did you get it working correctly?
     
  2. Offline

    theearlypc423

    No i'm having a pretty hard time with it.
    Code:
    package me.andrew.MasterChat;
     
     
     
     
    import info.bytecraft.sabersamus.MasterChat.ChannelChat;
    import info.bytecraft.sabersamus.MasterChat.ChannelConfig;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class MasterChat extends JavaPlugin {
        private static MasterChat plugin;
       
        public void onEnable(){
            plugin = this; // Creates a static instance of this plugin, so you don't need to make a constructor (Masterchat plugin)
            ChannelConfig.load(); //Loads channels.yml
            getLogger().info("Masterchat is now enabled!");
            getServer().getPluginManager().registerEvents(new ChannelChat(), this); // Registers PlayerChatEvent for channels.
        }
     
        public void onDisable(){
            getLogger().info("Disabling Masterchat...");
            //onEnable and onDisable methods created above ^^
        }
       
        public static MasterChat getInstance(){
            return plugin;
        }
    // WOW DUDE REALLY
    }
    Code:
    package info.bytecraft.sabersamus.MasterChat;
     
    import java.io.File;
    import java.io.InputStream;
     
     
     
     
    import me.andrew.MasterChat.MasterChat;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
     
    public class ChannelConfig{
       
        private static File file = null;
        private static FileConfiguration fileConfig = null;
       
        public static void load(){
           
        }
       
        public static FileConfiguration getConfig(){
            if(fileConfig == null){
                reloadConfig();
            }
            return fileConfig;
        }
       
        public static void reloadConfig(){
            if(file == null){
                file = new File(MasterChat.getInstance().getDataFolder(), "Channels.yml");
            }
            fileConfig = YamlConfiguration.loadConfiguration(file);
           
            InputStream defConfigStream = MasterChat.getInstance().getResource("Channels.yml");
            if(defConfigStream != null){
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                fileConfig.setDefaults(defConfig);
            }
        }
    }
    
    I just have no clue what I should replace without damaging all other three classes, I didn't make most of this.

    Yeah it really does but I have no clue how to replace. What this code I have is probaly outdated because it's from august

    Dude could you maybe edit the file for me? I currently have no clue how to do this and I mess up on the spacing and everything! Could you maybe edit that messed up code and post it as a reply?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  3. Offline

    Jogy34

    Can you even code in java?
     
    suckycomedian likes this.
  4. Offline

    theearlypc423

    Yes actually i'm licenced in java dude. I'm new to bukkit api though.
     
  5. Offline

    gomeow

    Licensed?
     
  6. Offline

    suckycomedian

    gomeow He's licensed. Don't mess.
     
  7. Offline

    theearlypc423

    Lol yeah I mainly use JFrame and awt i'm new to bukkit!
     
  8. Offline

    fireblast709

    JFrame and awt... have nothing to do with Bukkit... (and you call yourself licensed without using openGL :p, nah joking)
     
    bobacadodl and ThunderWaffeMC like this.
  9. Offline

    ThunderWaffeMC

  10. Offline

    theearlypc423

    If you have nothing nice to say don't say it dude the reason why u say that is cuz you need somthing to do. Aparently you wan't to waste your life so you can piss people off. Well have fun with that I will come back to this thread if I need further help.
     
  11. Offline

    Jogy34

    If you are licensed in java then you shouldn't really have a problem with adding methods, I remain skeptical.

    Anyways the tutorial I linked you to had three methods that you need to get custom config files to work. You have the getConfig() method and the reloadConfig() method. You are missing probably the most important one which is the saveConfig() method. You have to add that in. You can do this basically word for word from what they give you in the tutorial except you will have to change a few variable names to match what you have and also make it a static method as your other three methods are. Once you do this you can then call upon your class to get your config, through the getConfig() method, to be able to edit what is in your config and then when you are done with that you would call the saveConfig() method and the first time you do that your .yml file will be generated. If you have any questions on that feel free to ask and I will answer them to the best of my knowledge.
     
  12. Offline

    theearlypc423

    Ok well I got everything close to working. Well now that I only need to add a saveConfig() method I will try that... Earlier I tryed replacing all of the methods on the class but then two other classes wanted me to use all static methods which will probaly mess everything up. So I will tell you in a minute if this worked.

    Code:
    package info.bytecraft.sabersamus.MasterChat;
     
    import java.io.File;
    import java.io.InputStream;
     
    import me.andrew.MasterChat.Masterchat;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
     
    public class ChannelConfig{
     
        private static File file = null;
        private static FileConfiguration fileConfig = null;
     
        public static void load(){
         
        }
     
        public static FileConfiguration getConfig(){
            if(fileConfig == null){
                reloadConfig();
            }
            return fileConfig;
        }
     
        public static void reloadConfig(){
            if(file == null){
                file = new File(Masterchat.getInstance().getDataFolder(), "Channels.yml");
            }
            fileConfig = YamlConfiguration.loadConfiguration(file);
         
            InputStream defConfigStream = Masterchat.getInstance().getResource("Channels.yml");
            if(defConfigStream != null){
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                fileConfig.setDefaults(defConfig);
            }
        }
        public void saveCustomConfig() {
            if (customConfig == null || customConfigFile == null) {
            return;
            }
            try {
                getCustomConfig().save(customConfigFile);
            } catch (IOException ex) {
                this.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
            }
        }
    }
    Well if you're telling me that the file should look like this, thats not true because everything gets red underlines and other files error out. Jogy34 I think you shoud have a look at this plugin on your IDE and see what you think because I can't show you where the lines are and everything like that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  13. Offline

    Jogy34


    I told you that you would have to change a few variable names and make the saveConfig() static.
     
  14. Offline

    theearlypc423

    Ok so I will make everything in red go to static.
     
  15. Offline

    Jogy34

    You need to make your saveConfig() method static
     
  16. Offline

    theearlypc423

    [quote uid=90565555 name="Jogy34" post=1488382]I told you that you would have to change a few variable names and make the saveConfig() static.[/quote]
    Ok and that didn't really work here take this from mediafire and put t in your IDE the java project has to be named MasterChat exactly so use this link <Edit by Moderator: Redacted mediafire url>
     
    Last edited by a moderator: Nov 8, 2016
  17. Offline

    Jogy34

    Just post your current channel config class. It will be just as easy for me to help you that way and probably faster.
     
  18. Offline

    theearlypc423

    Code:
    public static void saveCustomConfig() {
        if (customConfig == null || customConfigFile == null) {
        return;
        }
        try {
            getCustomConfig().save(customConfigFile);
        } catch (IOException ex) {
            this.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
        }
    }
     
    
    So instead of this
    Code:
    public void saveCustomConfig() {
        if (customConfig == null || customConfigFile == null) {
        return;
        }
        try {
            getCustomConfig().save(customConfigFile);
        } catch (IOException ex) {
            this.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
        }
    }
    Like this one below?
     
  19. Offline

    Jogy34

    The first one is correct as for it being static but, again, you have to change the variable names to suit the ones that you are using.
     
  20. Offline

    theearlypc423

    What about the masterchat.java, MCPlayerLIstener.java, channel.java and channelchat.java? Those are all effected by the change to static.
     
  21. Offline

    Jogy34

    How so?
     
  22. Offline

    theearlypc423

    Um... actually I have no clue why. Here check out the files in the mediafire pack. They are too long to post here.

    oh like change it from getCustomConfig to getCnfig like those variable names???

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  23. Offline

    Jogy34

    Ya at this point I don't believe that you are licensed in java. You should probably go learn the basics of java before trying to code a plugin. I already know that you are probably going to say I'm being mean but my reasoning is that you don't even know what a variable is or what a method is and I doesn't even seam as if you wrote any of this and that you got someone else to write it as it said in a comment at the bottom of you file that someone gave the code to you.

    Anyways you are trying to use 'customConfigFile' when you don't have any variable called 'customConfigFile' instead you have to replace it with 'file' and you are also trying to use 'customConfig' when you don't have a variable called 'customConfig' instead you have to replace it with 'fileConfig'
     
  24. Offline

    theearlypc423

    I wrote half of this plugin

    Oh well i'll just go get some help from elgarL like usual

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  25. Offline

    Jogy34

    I gave you my opinion and you aren't going to be able to change my mind easily. I will still continue to help you however I am not going to write your plugin for you and I'm not going to put your plugin into my IDE to look through the entire thing to find out what is wrong for you. If you don't want my help just because I expressed my opinion towards you then I don't really care and I will just stop helping you then. Your choice.
     
  26. Offline

    theearlypc423

    Ok well I guess I will do it your way cuz you probaly know way more about this than me. So this is what I currently have in my file. Well this is what I was able to come up with so far just by looking at it what needs to be changed??
    Code:
    package info.bytecraft.sabersamus.MasterChat;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
     
    import me.andrew.MasterChat.Masterchat;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
     
    public class ChannelConfig{
       
        private static File file = null;
        private static FileConfiguration fileConfig = null;
       
        public static void load(){
           
        }
       
        public static FileConfiguration getConfig(){
            if(fileConfig == null){
                reloadConfig();
            }
            return fileConfig;
        }
       
        public static void reloadConfig(){
            if(file == null){
                file = new File(Masterchat.getInstance().getDataFolder(), "Channels.yml");
            }
            fileConfig = YamlConfiguration.loadConfiguration(file);
           
            InputStream defConfigStream = Masterchat.getInstance().getResource("Channels.yml");
            if(defConfigStream != null){
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                fileConfig.setDefaults(defConfig);
            }
        }
        public static void saveCustomConfig() {
            if (customConfig == null || customConfigFile == null) {
            return;
            }
            try {
                getCustomConfig().save(customConfigFile);
            } catch (IOException ex) {
                this.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
            }
        }
    }
     
  27. Offline

    Jogy34

    again, 'customConfig' needs to be changed to 'fileConfig' and 'customConfigFile' needs to be changed to 'file'.
     
  28. Offline

    theearlypc423

    Ohhhh thanks thanks thanks!!!!!!! I'll tell you if I have anymore issues! Again thanks!

    Code:
    package info.bytecraft.sabersamus.MasterChat;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
     
    import me.andrew.MasterChat.Masterchat;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
     
    public class ChannelConfig{
       
        private static File file = null;
        private static FileConfiguration fileConfig = null;
       
        public static void load(){
           
        }
       
        public static FileConfiguration getConfig(){
            if(fileConfig == null){
                reloadConfig();
            }
            return fileConfig;
        }
       
        public static void reloadConfig(){
            if(file == null){
                file = new File(Masterchat.getInstance().getDataFolder(), "Channels.yml");
            }
            fileConfig = YamlConfiguration.loadConfiguration(file);
           
            InputStream defConfigStream = Masterchat.getInstance().getResource("Channels.yml");
            if(defConfigStream != null){
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                fileConfig.setDefaults(defConfig);
            }
        }
        public static void saveCustomConfig() {
            if (fileConfig == null || file == null) {
            return;
            }
            try {
                getConfig().save(file);
            } catch (IOException ex) {
                this.getLogger().log(Level.SEVERE, "Could not save config to " + file, ex);
            }
        }
    }
    ok so this is the new code I have but this is underlined in red and says can't use in static context and level wants me to import but i'm not sure which to use. Any suggestions?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  29. Offline

    Jogy34

    Replace the 'this' with your plugin's instance.
     
  30. Offline

    theearlypc423

    Ok stupid question where do you find the instance again?
     
Thread Status:
Not open for further replies.

Share This Page