Solved Simple Plugin Won't Work -_-

Discussion in 'Plugin Development' started by xELI7E_SNIPEZx, Mar 7, 2014.

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

    xELI7E_SNIPEZx

    Okay, so i was making a simple block notify plugin when it just wouldn't work. It enables but.. when i come to use the command it doesn't do anything - no errors or nothing. After checking if any events worked it turns out none of them did. WHY? Please help?
    Code:
    package blocknotify.george.me;
     
    import java.util.ArrayList;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
       
        ArrayList<Player> BN = new ArrayList<Player>();
     
        @Override
        public void onDisable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info(pdfFile.getName() + " Disabled.");
        }
       
        @Override
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
                pm.registerEvents(this, this);
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Enabled.");
        }
       
       
        ChatColor Red = ChatColor.RED;
        ChatColor Gray = ChatColor.GRAY;
        ChatColor Gold = ChatColor.GOLD;
        ChatColor Aqua = ChatColor.AQUA;
        ChatColor White = ChatColor.WHITE;
        ChatColor Dark_Red = ChatColor.DARK_RED;
        ChatColor Dark_Green = ChatColor.DARK_GREEN;
       
       
        @EventHandler(priority = EventPriority.NORMAL)
        public void onJoin(PlayerJoinEvent e) {
            getLogger().info("JOIN");
            Player player = e.getPlayer();
            if(player.hasPermission("bn.force")) {
                if(!(BN.contains(player))) {
                    BN.add(player);
                }
            }
        }
       
       
        String prefix = ChatColor.GRAY + "[" + ChatColor.AQUA + "Notify" + ChatColor.GRAY + "] ";
       
        public boolean onCommand(Player sender, Command cmd, String label, String[] args) {
          if (cmd.getName().equalsIgnoreCase("bn")) {
              getLogger().info("COMMAND");
            if (!(sender instanceof Player)) {
              sender.sendMessage("-_-");
              return true;
            }
            if (sender.hasPermission("bn.toggle")) {
              if (BN.contains(sender.getName())) {
                  BN.remove(sender);
                  sender.sendMessage(prefix + "Block Notify Is Now " + Dark_Red + "Disabled");
              } else {
                  BN.add(sender);
                  sender.sendMessage(prefix + "Block Notify Is Now " + Dark_Green + "Enabled");
              }
            }
            else sender.sendMessage(prefix + ChatColor.RED + "You Don't Have Permission For That Command!");
          }
     
          return true;
        }
       
       
        @EventHandler(priority = EventPriority.NORMAL)
        public void OnBlockBreak(BlockBreakEvent event) {
          if (event.getBlock().getType() == Material.COAL_ORE) {
            for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
              if(BN.contains(onlinePlayer.getName())) {
                  if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                      onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Coal Block.");
                  }
              }
            }
          } else if (event.getBlock().getType() == Material.IRON_ORE) {
              for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                  if(BN.contains(onlinePlayer.getName())) {
                      if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                          onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Iron Block.");
                      }
                  }
                }
          } else if (event.getBlock().getType() == Material.GOLD_ORE) {
              for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                  if(BN.contains(onlinePlayer.getName())) {
                      if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                          onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Gold Block.");
                      }
                  }
              }
          } else if (event.getBlock().getType() == Material.DIAMOND_ORE) {
              for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                  if(BN.contains(onlinePlayer.getName())) {
                      if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                          onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Diamond Block.");
                      }
                  }
              }
          } else if (event.getBlock().getType() == Material.EMERALD_ORE) {
              for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                  if(BN.contains(onlinePlayer.getName())) {
                      if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                          onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Emerald Block.");
                      }
                  }
              }
             
             
          } else if (event.getBlock().getType() == Material.COAL_BLOCK) {
              for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                  if(BN.contains(onlinePlayer.getName())) {
                      if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                          onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Coal Block.");
                      }
                  }
                }
              } else if (event.getBlock().getType() == Material.IRON_BLOCK) {
                  for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                      if(BN.contains(onlinePlayer.getName())) {
                          if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                              onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Iron Block.");
                          }
                      }
                    }
              } else if (event.getBlock().getType() == Material.GOLD_BLOCK) {
                  for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                      if(BN.contains(onlinePlayer.getName())) {
                          if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                              onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Gold Block.");
                          }
                      }
                  }
              } else if (event.getBlock().getType() == Material.DIAMOND_BLOCK) {
                  for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                      if(BN.contains(onlinePlayer.getName())) {
                          if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                              onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Diamond Block.");
                          }
                      }
                  }
              } else if (event.getBlock().getType() == Material.EMERALD_BLOCK) {
                  for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
                      if(BN.contains(onlinePlayer.getName())) {
                          if(!(event.getPlayer().hasPermission("bn.ignore"))) {
                              onlinePlayer.sendMessage(prefix + ChatColor.GOLD + event.getPlayer().getName() + ChatColor.GRAY + " Broke A " + ChatColor.AQUA + "Emerald Block.");
                          }
                      }
                  }
              }
        }
       
    }
    
     
  2. Offline

    Buizelfan2

    @xELI7E_SNIPEZx
    So /bn doesn't work? if that's it

    i think its because your using the cmd.getName

    Use something more like
    Code:java
    1. public boolean onCommand(Player sender, Command cmd, String label, String[] args) {
    2. if (label.equalsIgnoreCase("bn")) {
    3. // code here
    4. }

    you want to use the String label not the Command cmd

    Oh and ya what BeefyPlays said whats your plugin.yml look like
     
  3. Offline

    BeefyPlays

    Can we please see your plugin.yml and/or the error you get in console?
     
  4. Offline

    Axe2760


    cmd.getName() is actually more correct to use than label, label is the exact command typed in, but cmd.getName() also accounts for aliases... if you're only doing the one /command command, then either one will do, however.
     
  5. Offline

    xELI7E_SNIPEZx

    BeefyPlays There is nothing wrong with my plugin.yml lol... but there is no error. it doesn't say anything. Not even invalid command.
     
  6. Offline

    BrushPainter

  7. Offline

    xELI7E_SNIPEZx

    Code:
    name: BlockNotify
    main: blocknotify.george.me.Main
    version: 1.0
    description: >
                xTHE_ELI7Ex's Block Break Notify
    commands:
      BN:
        description: Toggle Block Notify
        
     
  8. Offline

    The Fancy Whale

    Why did you capitalize BN? I would suggest that you add in some messages to be sent to the player at different places around the process and figure out where the plugin stops working
     
  9. Offline

    Wizehh

    xELI7E_SNIPEZx
    PHP:
    if (BN.contains(sender.getName())) {
    You told your ArrayList to only hold players, so why are you trying to add the sender's name?
    PHP:
    ArrayList<PlayerBN = new ArrayList<Player>();
    // Change to:
    ArrayList<Stringbn = new ArrayList<Player>();
    On a sidenote, you should really adhere to the Java naming conventions; all your variables should be lowercase.
     
  10. Offline

    xELI7E_SNIPEZx

    Fixed it by playing around. Thanks guys.
     
  11. Offline

    Wizardo367

    Don't forget to mark it as solved! :p
     
Thread Status:
Not open for further replies.

Share This Page