I have no clue what I am doing wrong

Discussion in 'Bukkit Help' started by WonderWaffleYT, Mar 25, 2015.

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

    WonderWaffleYT

    I making a report plugin. The idea of it is someone does /report {player name} {number of reason} This part of the code is made to check if they have a reason, if they don't have a reason it is supposed to tell the player the list of reasons and the usage.
    Code:
    package com.WonderWaffle.bukkit;
    
    import java.util.Arrays;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    
    public class Main extends JavaPlugin {
        public Player staffList[];
       
        public void loadConfiguration(){
           getConfig().options().copyDefaults(true); 
           saveConfig();
           
           getConfig().set("staff", Arrays.asList(staffList));
           saveConfig();
    
        }
        public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("report")){
                Player p = (Player) sender;
                Player target = p.getServer().getPlayer(args[0]);
                String reasons = args[1];
                p.sendMessage("123");
                 
                  if (sender instanceof Player){
                      if (!(reasons.equalsIgnoreCase("1"))){
                        if (!(reasons.equalsIgnoreCase("2"))){
                            if (!(reasons.equalsIgnoreCase("3"))){
                                if (!(reasons.equalsIgnoreCase("4"))){
                                    if (!(reasons.equalsIgnoreCase("5"))){
                                        p.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + "1. Hacking");
                                        p.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + "2. Harassment");
                                        p.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + "3. Innappropriate Language");
                                        p.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + "4. Combat Logging");
                                        p.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + "5. Other");
                                        p.sendMessage(ChatColor.GOLD + "/report {Player} {Number Of The Reason}"); 
                                    }
                                }
                            }
                        }
                     }
                      if(reasons.equalsIgnoreCase("1")){
                          for(int i = 0;i>staffList.length;i++){
                              Player staffMember = staffList[i];
                              staffMember.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + p.getName() + " thinks " + ChatColor.RED + target.getName() + ChatColor.GOLD + " is hacking.");
                          }
                      }
                      if(reasons.equalsIgnoreCase("2")){
                          for(int i = 0;i>staffList.length;i++){
                              Player staffMember = staffList[i];
                              staffMember.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + p.getName() + " thinks " + ChatColor.RED + target.getName() + ChatColor.GOLD + " is harassing people.");
                          }
                          }
                      if(reasons.equalsIgnoreCase("3")){
                          for(int i = 0;i>staffList.length;i++){
                              Player staffMember = staffList[i];
                              staffMember.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + p.getName() + " thinks " + ChatColor.RED + target.getName() + ChatColor.GOLD + " is using innappropriate language");
                          }
                          }
                      if(reasons.equalsIgnoreCase("4")){
                          for(int i = 0;i>staffList.length;i++){
                              Player staffMember = staffList[i];
                              staffMember.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + p.getName() + " thinks " + ChatColor.RED + target.getName() + ChatColor.GOLD + " is combat logging.");
                          }
                          }
                      if(reasons.equalsIgnoreCase("5")){
                          for(int i = 0;i>staffList.length;i++){
                              Player staffMember = staffList[i];
                              staffMember.sendMessage(ChatColor.BLUE + "[Report]: " + ChatColor.GOLD + p.getName() + " thinks " + ChatColor.RED + target.getName() + ChatColor.GOLD + " is doing something wrong.");
                          }
                          }
                  }
        }
                return true;
        }
    }
    
    
    
     
    Last edited: Mar 25, 2015
  2. Offline

    Gamecube762

    Put your code within the [code] [/code] tags so its easier to read. Also, explain your problem and what you are trying to do, to me the code is doing exactly what you told it to do.
     
  3. Offline

    MrBlackIsBack

    It's a little bit hard to read... You should try removing "Player p2" from the top of onCommand.
     
  4. Offline

    WonderWaffleYT

    A lot of people I have talked to say this should work. I have no clue why it doesn't do anything at all when I type /report
     
  5. Offline

    Gamecube762

    @WonderWaffleYT Are your commands registered in your plugin.yml? Also mind posting the whole class?
     
  6. Offline

    WonderWaffleYT

    I posted the whole class. They are registered in the plugin.yml
     
  7. Invisible

    nverdier

    @WonderWaffleYT I'm just going to tell you a few things to make your code better:
    1. Don't steal Minecraft's logger.
    2. You don't need to log enable/disable messages; Bukkit already does this for you.
    3. You never call the "loadConfiguration method...
    4. For the config you can include a "config.yml" when you export, and use #saveDefaultConfig().
    5. When you use "getConfig().getList("staff");", you aren't doing anything with the return value.
    6. You can replace all of your for loops with foreach (e.g. 'for (Player p : stafflist)).
     
  8. Offline

    WonderWaffleYT

    Thanks for the help. Does this look better?
     
  9. Invisible

    nverdier

    @WonderWaffleYT Yeah, but you still aren't calling the 'loadConfiguration' method when the plugin is enabled.
     
Thread Status:
Not open for further replies.

Share This Page