Any Thing Wrong With This Code???

Discussion in 'Plugin Development' started by DexterMorgan451, Mar 14, 2016.

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

    DexterMorgan451

    Code:
    package com.dexter.antispam;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class AntiSpam extends JavaPlugin implements Listener {
    
        public void onEnable() {
            getLogger().info("AntiSpam Is Enabled");
            {
            getServer().getScheduler().runTaskLater(this, new Runnable() {
                @Override
                public void run() {
                    getServer().broadcastMessage(ChatColor.DARK_AQUA + " " + ChatColor.BOLD + "[" + ChatColor.BLUE + " " + ChatColor.BOLD + "AntiSpam" + ChatColor.DARK_AQUA + " " + ChatColor.BOLD + "]" + ChatColor.BLUE + "" + ChatColor.BOLD + "By Dexter_Morgan451 Has Been Loaded!" );
               
                }
            }, 0L);
           
           
            }
           
        }
       
        public void onDisable() {
            getLogger().info("AntiSpam Is Disabled");
           
        }
        @EventHandler
         public void onChat(AsyncPlayerChatEvent e)
         {
           if (e.isCancelled()) {
             return;
           }
           Player p = e.getPlayer();
           
           String m = e.getMessage();
           for (int i = 0; i < this.msg.size(); i++)
           {
             String pm = (String)this.msg.get(i);
             if (m.contains(pm))
             {
               e.setCancelled(true);
               
               p.sendMessage(ChatColor.RED + " " + ChatColor.BOLD + "Spamming Is Not Permitted And Is Anoying");
               p.getServer().dispatchCommand(p.getServer().getConsoleSender(), "mute " + p.getName() + " 60s");
             }
           }
           if (m.length() >= 7)
           {
             this.msg.add(m);
             removeMessage(m, p);
           }
         }
    }
    
     
  2. Offline

    XxTimexX

    What kind of error do you get? And did you test it at all?
     
  3. Offline

    DexterMorgan451

    i put it in the plugin folder and the plugin is not there
     
  4. Offline

    87pen

    Is your plugin.yml set up right? Can you show it to us?
     
  5. Offline

    Ethanol2906

    Original

    Code:
     public void onEnable() {
            getLogger().info("AntiSpam Is Enabled");
            {
            getServer().getScheduler().runTaskLater(this, new Runnable() {
                @Override
                public void run() {
                    getServer().broadcastMessage(ChatColor.DARK_AQUA + " " + ChatColor.BOLD + "[" + ChatColor.BLUE + " " + ChatColor.BOLD + "AntiSpam" + ChatColor.DARK_AQUA + " " + ChatColor.BOLD + "]" + ChatColor.BLUE + "" + ChatColor.BOLD + "By Dexter_Morgan451 Has Been Loaded!" );
              
                }
            }, 0L);
          
          
            }
          
        }
    Slight edit. There was an unneccessary parenthesis "{" below the getLogger line. Might not change anything and I might be wrong but maybe?

    Code:
     public void onEnable() {
            getLogger().info("AntiSpam Is Enabled");
            
            getServer().getScheduler().runTaskLater(this, new Runnable() {
                @Override
                public void run() {
                    getServer().broadcastMessage(ChatColor.DARK_AQUA + " " + ChatColor.BOLD + "[" + ChatColor.BLUE + " " + ChatColor.BOLD + "AntiSpam" + ChatColor.DARK_AQUA + " " + ChatColor.BOLD + "]" + ChatColor.BLUE + "" + ChatColor.BOLD + "By Dexter_Morgan451 Has Been Loaded!" );
                };
            }, 0L);
           
          
        }
     
  6. Offline

    Irantwomiles

    @DexterMorgan451 if the plugin isn't showing up in your plugins list when the server runs and from what I can tell you aren't getting any consol errors, it's most likely your plugin.yml
     
  7. Offline

    87pen

    @Ethanol2906 You do know you don't need the logger right. Bukkit already announces your plugin being enabled automatically.
     
  8. Offline

    mcdorli

    Please, don't spoonfeed, just tell him what's wrong, and if he understands java, he probably can correct it.

    I'm actually not sure, there's a thing in c++, where you can just drop a random bracket around a code block, to make sure, some variables never get used outside of that part of the code. I forgot the name of that technique, so google isn't useful right now.
     
  9. Offline

    I Al Istannen

    @mcdorli
    In german it is "Anweisungsblock". I think it is this in english: link (14.2).
     
  10. Offline

    mythbusterma

  11. Offline

    mcdorli

    Thanks
     
  12. Offline

    MajorSkillage

    Register your listener -.-
     
Thread Status:
Not open for further replies.

Share This Page