[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

    Firefly

    Why..? onEnable/onDisable always go together in your main class.

    Anyways, I said to put that code in onEnable()
     
  2. Offline

    calebbfmv

    *facepalm* :oops:

    Firefly
    Am I an idiot or something? Because It still wont work.

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

    Firefly

    Repost your main class.
     
  4. Offline

    calebbfmv

    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 StopOP extends JavaPlugin implements Listener {
    public Logger log = Logger.getLogger("Minecraft");
    public FileConfiguration config;

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


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

    }
    @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);
    }
    }
    }
     
  5. Offline

    Firefly

    if(msg.contains("can i be " + reasons)){

    Your message can't contain a list. Iterate every element of the list and see if the message contains that certain element.
     
  6. Offline

    calebbfmv

    Iterate, I've heard of that, never thought I needed it, but every one?
     
  7. Offline

    Firefly

    for (String rank : reasons) {
    if (msg.contains("can I be " + rank)) {
    //Do stuff
    }
    }
     
  8. Offline

    calebbfmv

    tried it. didn't work, am I missing something here?
     
  9. Offline

    Firefly

    No. (String rank : reasons) is how you iterate every string in the reasons list.
     
  10. Offline

    calebbfmv

    I did that, but nothing still works...... I fail

    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    List<String> reasons = config.getStringList("groups");
    for (String rank : reasons) {
    Player p = event.getPlayer();
    String msg = event.getMessage().toLowerCase();
    String kickmsg = config.getString("path_in_config");
    if (msg.contains("can I be " + rank)) {
    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
  11. Offline

    Firefly

    What do your config.yml look like?
     
  12. Offline

    calebbfmv

    # Deafault config.yml

    #Choose the groups to kick for asking for.
    groups:
    - admin
    - op
    - mod

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

    Firefly

    Add a debug to your onPlayerChat

    if (config.getPath"groups" != null) {
    player.sendMessage("Hey, the groups path exists!");
    }
     
  14. Offline

    calebbfmv

    getPath it error, where should I put it?
     
  15. Offline

    Firefly

    My bad, it's just config.get("groups");
     
  16. Offline

    calebbfmv

    lol I should use my brain.

    Firefly
    Still nothing.....

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

    Firefly

    You didn't get the debug message? Which probably means your config is set up wrong. I suggest setting up the default config using code, not actually typing it out.
     
  18. Offline

    calebbfmv

    How?
     
Thread Status:
Not open for further replies.

Share This Page