Problems with making SwearBot Plugin

Discussion in 'Plugin Development' started by cococow123, Aug 17, 2014.

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

    cococow123

    Hey! I'm having an error that I can't figure out.

    My Code:



    package me.cococow123.Swearbot;

    import java.util.Locale;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {



    if (cmd.getName().equalsIgnoreCase("sbreload")) {
    if (sender.hasPermission("swearbot.reload")) {
    this.reloadConfig();
    sender.sendMessage(ChatColor.GREEN+ "Reload Complete.");

    if (cmd.getName().equalsIgnoreCase("sbreload")) {
    if (!sender.hasPermission("swearbot.reload")) {
    sender.sendMessage(ChatColor.RED + "You do not have permission.");
    }
    }
    return false;
    }
    }
    return false;
    }

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
    for(String word : e.getMessage().split(" ")){
    if(getConfig().getStringList("bannedwords").contains(word.toLowerCase(Locale.ENGLISH))){
    e.setCancelled(true);
    e.getPlayer().sendMessage(ChatColor.BLUE.toString() + ChatColor.BOLD + getConfig().getString("server-name") +ChatColor.BLUE.toString() + ChatColor.BOLD + " Chat> " + ChatColor.DARK_RED + "Please Don't Use That Language!");
    }
    }
    }





    public void onEnable() {
    getConfig().options().copyDefaults(true);
    saveConfig();
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }

    }


    My Plugin.yml

    name: SwearBot
    main: me.cococow123.SwearBot.main
    version: "1.0"
    commands:
    sbreload:
    description: Reloads SwearBot
    usage: /<command>
    permission: swearbot.reload
    permission-message: You do not have permission.


    My Config.yml

    ####################
    # SwearBot #
    # Configuration #
    ###################

    server-name:

    ################

    bannedwords:
    - cheese

    -Cheese was an example.


    When I try to export it, it gives an error in the Plugin.yml

    I just need some help!


    Thanks,
    Coco


     
  2. Offline

    Erigitic

    cococow123 Take a look at this link http://wiki.bukkit.org/Plugin_YAML. There is an example of a plugin.yml file on that page. See if that helps you out with your plugin.yml. Also next time you post code please put it in code tags.
     
    cococow123 likes this.
  3. Offline

    mythbusterma

    cococow123

    1. What's the problem?
    2. Use syntax BB tags
    3. You're violating the thread-safety of the server
    4. This wouldn't be a very effective method of eliminating vulgarities
    5. This algorithm runs in O(n^2*m), making it very slow and inefficient (not to mention reading in from the file)
     
  4. Offline

    cococow123

    I'm still a beginner at coding...

    Sorry if I didn't tell you.

    Thanks

    I'll try it tomorrow!!


    [edit by JaguarJo: merged posts. Please use the edit option instead of double-posting. Thanks.]

    It worked! [diamond]:)

    Thanks!
    Coco

    mythbusterma

    I'm still a beginner... I don't really understand what u mean by all that stuff.

    Though thanks for taking a look at my problems :)

    Thanks,
    Coco

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

    mythbusterma

    cococow123

    You should probably read up on what those mean if you want to start making plugins.
     
  6. Offline

    AronTheGamer

    A SwearBot? What is daaat? A thing that randomly swears every x seconds?
     
    cococow123 and Totom3 like this.
  7. Offline

    Forseth11

    Change your class name from Main to main.
     
  8. Offline

    TGRHavoc

    Why? What will that accomplish apart from going against Java naming conventions?
     
  9. Offline

    Forseth11

    TGRHavoc His plugin.yml has it as a lower case and his class is named "Main":
    Code:
    main: me.cococow123.SwearBot.main
     
  10. Offline

    TGRHavoc

    Ah, I see now. You could of just told him to change the plugin.yml :p
     
  11. Offline

    Forseth11

    TGRHavoc yea but bukkit has an object by the name of Main so he would be better off with lower case main.
     
  12. Offline

    TGRHavoc

    No it doesn't. It has a class by the name of "Main" however, that shouldn't pose a problem unless he calls his package "org.bukkit"..
     
  13. Offline

    Forseth11

    TGRHavoc True. Either way works. I just prefer using main instead of Main.
     
  14. Offline

    fireblast709

    mythbusterma Where did you get your n^2 from?
    Code:
    for(String word : words) // O(n)
    {
        for(String banned : bannedList) // O(m)
        {
            if(word.equals(banned)) // O(1)
            {
                // Do stuff that's O(1)
            }
        }
    }
    Gives me O(n*m) amortized running time. (amortized since the file would only be loaded once)
     
    zackpollard likes this.
  15. Offline

    Lactem

    You might want to do word.contains(banned) and have whitelisted words like assassin.
     
  16. Offline

    zackpollard

    Please don't come here and teach newbies bad ways. Please try to stick to convention wherever you can, classnames should always begin with a capital, there are many reasons for this which i'm not getting into, if you're interested a simple google will explain why.
     
  17. Offline

    mythbusterma

    fireblast709

    String.equals checks by iterating over every character in the word, from the String.java:


    Code:
    public boolean equals(Object anObject) {
    1014          if (this == anObject) {
    1015              return true;
    1016          }
    1017          if (anObject instanceof String) {
    1018              String anotherString = (String)anObject;
    1019              int n = count;
    1020              if (n == anotherString.count) {
    1021                  char v1[] = value;
    1022                  char v2[] = anotherString.value;
    1023                  int i = offset;
    1024                  int j = anotherString.offset;
    1025                  while (n-- != 0) {
    1026                      if (v1[i++] != v2[j++])
    1027                          return false;
    1028                  }
    1029                  return true;
    1030              }
    1031          }
    1032          return false;
    1033      }
     
  18. Offline

    fireblast709

    mythbusterma ah forgot about equals... I'm too used to HashSets. [edit] Still, that would be n*m*o wouldn't it? (since n != 0)
     
  19. Offline

    mythbusterma

    fireblast709

    Tuche, still, that's basically cubic time, which is CERTAINLY not desirable is my point.
     
  20. Offline

    cococow123

    It's all fixed now! I just need to figure out how to have like a bypass permission to let players say words that are in the config!

    Thanks,
    Coco
     
  21. Offline

    fireblast709

    cococow123 Player#hasPermission(String permission)
     
    cococow123 likes this.
  22. Offline

    AronTheGamer

    before you are gonna relpace the bad words just do:
    Code:java
    1. if( !e.getPlayer().hasPermission( "yourplugin.bypass" ) )
     
    cococow123 likes this.
Thread Status:
Not open for further replies.

Share This Page