[Closed] I gotta figure it out on my own now, thanks for your help!

Discussion in 'Plugin Development' started by calebbfmv, Jul 27, 2012.

?

Do I post too much?

  1. Yes. Figure it out on your own loser. -_-

    44.4%
  2. No, we like the question and the more people learning Java, the better.

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

    calebbfmv

    Cool, what next? Or is it all?

    Here is my config.yml if it helps:
    # Deafault config.yml

    #Choose the groups to kick for asking for.
    groups:
    Admin
    OP
    Mod

    #The Message displayed when an user is kicked.
    Message:
    No! We are not total noobs :)

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

    travja

    i
    so basically instead of kicking them for kickreason change your config to:
    groups:
    - admin
    - op
    - mod
    Then in your listener do List reasons = config.getStringList("groups");
    then instead of .contains(kickreason) do .contains("can i be " + reasons)

    I'm off to bed..

    Basically, put a dash in front of them and indent them four spaces (NOT tabs) Then you can change if it contains kickreason and make kickreason a list that you get from the config.

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

    calebbfmv

    XD I am an idiot I still don't get it, I am going to study it then maybe I will.
     
  4. Offline

    travja

    It is just how you format a .yml file, you the groups: is an option containing the things that are 4 spaces in.
     
  5. Offline

    calebbfmv

    I get that, but not the code itself i get errors with it and stuff so I am trying to get it

    EDIT I think I got it...
    Figured it out, was a pretty stupid one as well, thanks for your help.
    But now it loads right, but no config is generated...

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

    travja

    Hmm.... wanna send me your onEnable
     
  7. Offline

    calebbfmv

    Sure,public void onEnable() {
    PluginDescriptionFile pdffile = this.getDescription();
    log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now Enabled.");
    getConfig().options().copyDefaults(true);
    saveConfig();
    This is not in my listener class

    Listener class
    public void onPlayerChat(PlayerChatEvent event){
    List reasons = (List) config.getStringList("groups");
    Player p = event.getPlayer();
    String msg = event.getMessage().toLowerCase();
    String kickmsg = config.getString("path_in_config");
    if(msg.contains("can i be " + reasons)){
    p.kickPlayer(kickmsg);
    }
    }
    }

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

    travja

    Try saveDefaultConfig instead of saveConfig
     
  9. Offline

    calebbfmv

    K

    Nope, still nothing

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

    travja

    Are you sure it exported right? Can you give me your main class?
     
  11. Offline

    calebbfmv

    Here it is:
    package me.calebbfmv.StopAskingOp;

    import java.util.logging.Logger;

    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class StopOP extends JavaPlugin {

    public Logger log = Logger.getLogger("Minecraft");


    public void onDisbale() {
    PluginDescriptionFile pdffile = this.getDescription();
    log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now disabled.");
    }


    public void onEnable() {
    PluginDescriptionFile pdffile = this.getDescription();
    log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now Enabled.");
    this.getConfig().options().copyDefaults(true);
    this.saveDefaultConfig();
    }
    }

    just in case, here is my playerlistener:
    package me.calebbfmv.StopAskingOp;

    import java.awt.List;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class myPlyaerlistener extends JavaPlugin implements Listener
    {
    public FileConfiguration config;
    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    List reasons = (List) config.getStringList("groups");
    Player p = event.getPlayer();
    String msg = event.getMessage().toLowerCase();
    String kickmsg = config.getString("path_in_config");
    if(msg.contains("can i be " + reasons)){
    p.kickPlayer(kickmsg);
    }
    }
    }

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

    Firefly

    List reasons = (List) config.getStringList("groups");

    Might want to be changed to List<String> reasons = config.getStringList("groups");
     
  13. Offline

    calebbfmv

    Nah, that doesn't help any. I still don't get a generated folder. Am I missing something?
     
  14. Offline

    Firefly

    It's still a needed change.
     
  15. Offline

    travja

    Try this for your main class:
    package me.calebbfmv.StopAskingOp;

    import java.util.logging.Logger;

    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class StopOP extends JavaPlugin {

    public Logger log = Logger.getLogger("Minecraft");
    public FileConfiguration config;

    public void onDisbale() {
    PluginDescriptionFile pdffile = this.getDescription();
    log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now disabled.");
    }


    public void onEnable() {
    config = this.getConfig();
    config.options().copyDefaults();
    this.saveDefaultConfig();
    PluginDescriptionFile pdffile = this.getDescription();
    log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now Enabled.");
    }
    }
     
  16. Offline

    calebbfmv

    No, it is not working! Grrrr
     
  17. Offline

    travja

    Are there any errors in the console when you start it up?
     
  18. Offline

    calebbfmv

    No none

    http://pastebin.com/5mU26KEg
    Thats my console

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

    travja

    It isn't even registering your onEnable... try switching the locations of onEnable and onDisable, oh, and your onDisable is spelled wrong you have it onDisbale
     
  20. Offline

    calebbfmv

    OK tried that didn't work
     
  21. Offline

    travja

    I have no clue... it isn't even loading all the way... in your server log there is no Has been enabled message... just "Enabling"
     
  22. Offline

    calebbfmv

    I see that, why would it be...Is there anything wrong with my code?
     
  23. Offline

    travja

    not that I can see.... Try getting rid of all the pdffile things.... instead use the Logger so:
    log.info("whatever");
     
  24. Offline

    calebbfmv

    I have fixed it!

    I just made it all one class, i have it to load a config, but nothing still happens.

    Well, getting there...

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

    chaseoes

    It's only taken 68 replies so far. :)
     
  26. Offline

    calebbfmv

    :) It's a learning experience, but I have a feeling when I get this done, I will be good to go.
     
  27. Offline

    ZeusAllMighty11

    It seems that we basically wrote the whole plugin for you...

    3 voted yes? ;P
     
  28. Offline

    calebbfmv

    No, no, I am adding features outside of this forum, but I am using them I try different things, and if they don't work I come here and try that. I fix some problems but you guys did help me a lot, I won't lie and I think I am going to get it to work 100% on my own, because I think I can now. :)

    Firefly
    Here it is, here is my code, changed some things to it main:
    package me.calebbfmv.StopAskingOp;

    import java.util.List;
    import java.util.logging.Logger;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class MyPlayerlistener extends JavaPlugin implements Listener {
    public FileConfiguration config;
    public Logger log = Logger.getLogger("Minecraft");

    public void onEnable() {
    config = this.getConfig();
    config.options().copyDefaults();
    this.saveDefaultConfig();
    PluginDescriptionFile pdffile = this.getDescription();
    log.info(pdffile.getName() + " " + pdffile.getVersion() + " is now Enabled.");
    }

    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    List<String> reasons = config.getStringList("groups");
    Player p = event.getPlayer();
    String msg = event.getMessage().toLowerCase();
    String kickmsg = config.getString("path_in_config");
    if(msg.contains("can i be " + reasons)){
    p.kickPlayer(kickmsg);
    }
    }
    }

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

    Firefly

    You didn't register your events in onEnable where the first parameter is your listener class, the second is the plugin.

    getServer().getPluginManager().registerEvents(this, this);
     
  30. Offline

    calebbfmv

    onDisable is in another class
    I was testing things I know, I am not the smartest person
     
Thread Status:
Not open for further replies.

Share This Page