I really need some help with this plugin I'm developing

Discussion in 'Plugin Development' started by OhYes, Feb 25, 2016.

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

    OhYes

    So the plugin EVENTUALLY will be something along the lines of, you can fight people in 1v1, or perhaps 2v2 duels, and if you win, you will gain mmr, and lose mmr if you lose. I'm not amazing with configs, and I'm really sorry if the code is like spaghetti, but I need some help. Not just with this one error, but with all of it. I will be deeply appriciative of you if you can put some time aside to assist me. Anyway. At the moment when I type the command /echo mmr It comes up in chat in red, saying: an internal error occured while attempting to perform this command. Idk why either. I'm sort of an ametuer when it comes to coding.
    Code:
    package me.OhYes.echocraft;
    
    
    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.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
    
        @Override
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            this.getConfig().options().copyDefaults(true);
        }
    
        @Override
        public void onDisable(){
            saveConfig();
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(!(sender instanceof Player)){
                sender.sendMessage("You cannot use Echocraft commands as a Console!");
                return false;
            }else{
                Player p = (Player) sender;
                if(commandLabel.equalsIgnoreCase("echo")){
                    if(args.length == 0){
                        p.sendMessage(ChatColor.BLUE + "-----[ " + ChatColor.GOLD + "EchoCraft" + ChatColor.BLUE + " ]-----");
                        p.sendMessage(ChatColor.AQUA + "/Echo MMR <Name>| Check you, or a player's Match Made Rating.");
                        p.sendMessage(ChatColor.AQUA + "/Echo MMRUP <Name> <Amount>| Increase a player's MMR by an amount (Admin Only)");
                        p.sendMessage(ChatColor.AQUA + "/Echo MMRDOWN <Name> <Amount>| Decrease a player's MMR by an amount (Admin Only)");
                        p.sendMessage(ChatColor.AQUA + "/Echo Reset | Mass reset all Player's MMR (Owner Only)");
                        p.sendMessage(ChatColor.BLUE + "-----------------------");
                    }else if(args.length == 1 || args.length == 2){
                        if(args[0].equalsIgnoreCase("mmr")){
                            if(args[1] == ""){
                                p.sendMessage(ChatColor.BLUE + "Showing MMR Rating for: " + ChatColor.AQUA + p.getDisplayName());
                                p.sendMessage(ChatColor.BLUE + "Match Made Rating: " + ChatColor.GOLD + getConfig().getInt(p.getName()));
                                if(getConfig().getInt(p.getName()) <= 100){
                                    p.sendMessage(ChatColor.BLUE + "Match Made Tier: " + ChatColor.DARK_GRAY + "COAL");
                                }else if(getConfig().getInt(p.getName()) > 100 && getConfig().getInt(p.getName()) <= 200){
                                    p.sendMessage(ChatColor.BLUE + "Match Made Tier: " + ChatColor.WHITE + "IRON");
                                }else if(getConfig().getInt(p.getName()) > 200 && getConfig().getInt(p.getName()) <= 500){
                                    p.sendMessage(ChatColor.BLUE + "Match Made Tier: " + ChatColor.GOLD + "GOLD");
                                }else if(getConfig().getInt(p.getName()) > 500 && getConfig().getInt(p.getName()) <= 1000){
                                    p.sendMessage(ChatColor.BLUE + "Match Made Tier: " + ChatColor.AQUA + "DIAMOND");
                                }else if(getConfig().getInt(p.getName()) > 1000){
                                    p.sendMessage(ChatColor.BLUE + "Match Made Tier: " + ChatColor.GREEN + "ELITE");
                                }else{
                                    p.sendMessage(ChatColor.RED + "AN ERROR OCCURED. PLEASE RE-LOG.");
                                }
                            }//For more players
                        }
                    //}else if(args.length == 3){
                        //if(args[0].equalsIgnoreCase("mmrup")){
                            //@SuppressWarnings("deprecation")
                            //Player target = Bukkit.getServer().getPlayer(args[1]);
                            //int amount = Integer.parseInt(args[2]);
                           
                            //getConfig().getInt(target.getName()) + amount;
                            //saveConfig();
                        //}
                    }
                   
                }
            }
            return false;
        }
       
    }
    
    Eventually it'll have 1v1 duel systems etc. and when players join it will add them to the config and give them default mmr.

    *gasp*

    Thanks,
    Oh_Yes.
     
  2. Offline

    mythbusterma

    @OhYes

    If it says "an internal error occurred," there will be a stack trace in your console, we need to see that.
     
  3. Offline

    OhYes

    @mythbusterma
     
  4. Offline

    Zombie_Striker

  5. Offline

    OhYes

    Uhm.. So.. in a language I can understand? xD
     
  6. Offline

    Zombie_Striker

    @OhYes
    If you cannot understand what I said, then you may need to re-learn Java. All the things mentioned above is basic Java knowledge. Fully understanding Java is a requirement to working with bukkit. I suggest you take another look at one of the following tutorials (it should take less than a week):
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/

    Google "== vs .equals" and "ArrayListOutOfBounds" if you want a quick answer.
     
    GamerzKing and Lordloss like this.
  7. Offline

    Lordloss

    The link in my signature could also be of help. (not the Tetris one ;-) )
     
Thread Status:
Not open for further replies.

Share This Page