[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

    OK, title may not be of use, but here it is: I am thinking about (depending on difficulty and time) that when someone asks "Can I be OP?" The server says Nope! then kicks the player. Possible hard?
     
  2. Offline

    turqmelon

    Code:
    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
        
        String m = event.getMessage();
        String mlow = m.toLowerCase();
     
        if (mlow.contains("Can I be OP?")){
            // Do Stuff
        }
    }
    
    Simple enough :p
     
  3. Offline

    travja

    Code:java
    1. @EventHandler
    2. public void onPlayerChat(PlayerChatEvent event){
    3. String msg = event.getMessage().toLowerCase();
    4. if(msg.contains("Can I be OP"){
    5. event.getPlayer().kick("No!");
    6. }
    7. }


    I think that's how you would do it.
     
  4. Offline

    calebbfmv

    just a little fix:
    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    String msg = event.getMessage().toLowerCase();
    if(msg.contains("Can I be OP")}{
    event.getPlayer().kick("No!");
    }
    }
    :)
    That works now I need to define .kick hmmm this is new to me

    Who just said "yes" on the poll?

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

    np98765

    What? I can't help with this.... At all. -_- Sorry.

    Although I can say that NoobResponse does this. :p But I have no idea how to code this, sorry.
     
  7. Next time think bevore you vote if you see "Your vote will be publicly visible." :p
     
  8. Offline

    calebbfmv

    It was meant as a joke :p

    Lol, could you help out with the topic though?

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

    np98765

    Oh, the poll! Yeah.. Google chrome isn't the easiest to use on iPhone. I've accidently voted wrong on another poll a few days ago, too, I think -_-

    But no, please -- ask questions. I reference here to answer my own questions. :p

    EDIT: Editing on iOS devices is so much harder... I despise using Bukkit on here. -_-
     
  10. Offline

    calebbfmv

    Sureeeeee :p! Anyway, I need to kick someone when they ask for OP, now I think NoobRepsonse does it, but, I like making my own plugins :), So what should I do?
    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    String msg = event.getMessage().toLowerCase();
    if(msg.contains("Can I be OP")){
    event.getPlayer().kick("No!");
    }

    }
    }

    (Besides all the onEnable/Disable things and the imports)
    but event is screwy and when I change it to Event getMessgae is screwy, am I being a total blonde right now?
     
  11. Sure: change kick to kickPlayer ;)
     
  12. Offline

    Snipes01

    Tapatalk is great for viewing forums on iOS. http://tapatalk.com/
     
  13. Offline

    calebbfmv

    It doesn't work! Nothing happens when the player type Can I be OP
     
  14. Cause you're converting the message to lowercase and then compare it to a sentence with uppercase characters... ;)
     
  15. Offline

    calebbfmv

    Nope that doesn't work.....
     
  16. What doesn't work? What I meand was:
    String msg = event.getMessage().toLowerCase();
    this converts the message the player wrote to lowercase...
    if(msg.contains("Can I be OP"){
    these characters aren't lowercase, so the if will always return false as "can i be op" != "Can I be OP"...
     
  17. Offline

    calebbfmv

    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    String msg = event.getMessage();
    if(msg.contains("Can I be OP")){
    event.getPlayer().kickPlayer("No! We are not run by total noobs:)");
    }
    }

    }
     
  18. calebbfmv Did you registerthe event? And why did you remove the toLowerCase() instead of checking against a lowercase sentence? Now I can write "can I be op" for example...
     
  19. Offline

    calebbfmv

    Misunderstood :D. Changed it! Now registering events? how would I do that? Sorry if I seem like a noob.
     
  20. Offline

    calebbfmv

    public class myPlyaerlistener extends JavaPlugin implements Listener {
    public void onEnable() {
    getServer().getPluginManager().registerEvents(new myPlyaerlistener(), this);
    }
    @EventHandler
    public void onPlayerChat(PlayerChatEvent event){
    String msg = event.getMessage().toLowerCase();
    if(msg.contains("can i be op")){
    event.getPlayer().kickPlayer("No! We are not run by total noobs:)");
    }
    }

    }
    ?
     
  21. Almost:
    Code:java
    1. public class myPlugin extends JavaPlugin implements Listener
    2. {
    3. public void onEnable()
    4. {
    5. getServer().getPluginManager().registerEvents(this, this);
    6. }
    7.  
    8. @EventHandler
    9. public void onPlayerChat(PlayerChatEvent event)
    10. {
    11. String msg = event.getMessage().toLowerCase();
    12. if(msg.contains("can i be op"))
    13. event.getPlayer().kickPlayer("No! We are not run by total noobs:)");
    14. }
    15. }
     
  22. Offline

    calebbfmv

    Sweet I was close!!! Level Up!

    Now for config changing the message it says when it kicks you, and what words are said to be kicked

    And exemptioning

    Still nothing happens... do I have to do something else?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  23. If this is the only class you have (which is what main in your plugin.yml points to): No.
     
  24. Offline

    calebbfmv

    YES IT WORKS!!! :D :D :D :D!!! Now to add config support for groups and what the message is!
    EDIT :O This seems hard
     
  25. Offline

    travja

    Right click your project and click new > file and name it config.yml. Then when you are editing it make the first line
    Code:
    # default config.yml
    Then add whatever config options you want. In your onEnable you need to save it so, it should look something like this:
    Code:java
    1. public class myPlugin extends JavaPlugin implements Listener{
    2. public FileConfiguration config;
    3. public void onEnable(){
    4. config = this.getConfig();
    5. config.options().copyDefaults();
    6. this.saveDefaultConfig();
    7. this.getServer().registerEvents(this, this);
    8. }
    9. //All your event stuff


    When you're done with that, I'll help you further....
     
  26. Offline

    calebbfmv

    That's done, what next? Thanks by the way, this is helpful beyond measure
     
  27. Offline

    travja

    K, so now that you have your config set up, you are going to need to make your text changeable. So, your listener should look something like this:
    Code:java
    1. @EventHandler
    2. public void onPlayerChat(PlayerChatEvent event){
    3. String msg = event.getMessage().toLowerCase();
    4. String kickmsg = config.getString("path_in_config");
    5. String kickreason = config.getString("path_in_config");
    6. if(msg.contains(kickreason){
    7. p.kickPlayer(kickmsg);
    8. }
    9. }
     
  28. Offline

    calebbfmv

    Ok I dont get ^^
     
  29. Offline

    travja

    oh, sorry, I use p for my player object. So you would do Player p = event.getPlayer(); do that up by the Strings
     
Thread Status:
Not open for further replies.

Share This Page