Plugin Not Working

Discussion in 'Plugin Development' started by bignose956, Feb 20, 2017.

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

    bignose956

    I am making my own plugin, and can not find what's wrong with the code. All I know is that the PlayerLogonEvent and /titleremove command are not working. This is in CraftBukkit 1.8.8

    Can anybody help with this???

    UPDATE: I changed the main class and copied the new error log. At this point none of the commands are working.

    Here is my main plugin class:
    CustomTitles.java (open)

    Code:
    package me.bukkit.bignose956;
    
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    import java.io.UnsupportedEncodingException;
    
    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.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CustomTitles extends JavaPlugin implements Listener{
      
      
        @Override
        public void onEnable(){
          
            Bukkit.getPluginManager().registerEvents(this, this);
          
            try {
                PrintWriter pw = new PrintWriter(System.getProperty("user.dir") + "/plugins/CustomTitles/Readme.txt","UTF-8");
                pw.println("In the names.txt file, the name on line one will be assigned the title on line 1 in titles.txt.");
                pw.println("=========================================================================================================");
                pw.println("If you want to assign a title to a player, then add his name on a new line at the bottom of names.txt,");
                pw.println("and add his title on a new line at the bottom on titles.txt.");
                pw.println("=========================================================================================================");
                pw.println("If you want to edit a player's title, then find his name in the names.txt file, and memorize what line it's on,");
                pw.println("then go to that same line on titles.txt and edit the title that is already there.");
                pw.println("=========================================================================================================");
                pw.println("If you want to remove a player's title, then use /titleremove <player> in game. You can also open names.txt");
                pw.println("and find the player's name, memorize what is it's on, remove it from names.txt, open titles.txt, go to the same line,");
                pw.println("and remove the title that is already there.");
                pw.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
          
          
            String user = new String(System.getProperty("user.name"));
            getLogger().info("================================================= \n "
                    + "\tbignose956: Custom Titles: \n"
                    + "================================================= \n"
                    + "\tCustom Titles is enabled and has loaded successfully!  \n"
                    + "\tVersion: 1.0 \n"
                    + "================================================= \n"
                    + "\t" + user + " Thank you for using this plugin, \n"
                            + "\tuse '/help CustomTitles' for commands. \n"
                            + "=================================================");
          
        }
      
        @Override
        public void onDisable(){
          
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
      
                if(cmd.getName().equalsIgnoreCase("titleset")){
                if(args.length == 2){
                    Player player = (Player) sender;
                    String playernam = args[0];
    
                    getConfig().createSection(playernam);
                    if(args[2] != null){
                    getConfig().createSection(playernam + "Color");
                    getConfig().set(playernam + "Color", args[2]);
                    }
                  
                    getConfig().set(playernam, args[1]);
                  
                    if(sender instanceof Player){
                  
                    player.sendMessage(ChatColor.DARK_PURPLE + args[0] + ChatColor.RESET + "'s title has been set to " + ChatColor.ITALIC + ChatColor.DARK_RED + args[1]);
                    }else{
                        System.out.println(ChatColor.DARK_PURPLE + args[0] + ChatColor.RESET + "'s title has been set to " + ChatColor.ITALIC + ChatColor.DARK_RED + args[1]);
                    }
                }else if(args.length == 1){
                    Player player = (Player) sender;
                    String playernam = args[0];
    
                    getConfig().createSection(playernam);
                    if(args[2] != null){
                    getConfig().createSection(playernam + "Color");
                    getConfig().set(playernam + "Color", "RESET");
                  
                    }
                  
                    getConfig().set(playernam, args[1]);
                  
                    if(sender instanceof Player){
                  
                    player.sendMessage(ChatColor.DARK_PURPLE + args[0] + ChatColor.RESET + "'s title has been set to " + ChatColor.ITALIC + ChatColor.valueOf(args[2])+ args[1]);
                }else if(sender instanceof Player){
                    player.sendMessage("/titleset <player> <title> <title color>");
                }else{
                    System.out.println("/titleset <player> <title> <title color>");
                }
              
              
              
            }
        }else if(cmd.getName().equalsIgnoreCase("titleremove")){
            if(args.length == 0){
                Player player = (Player) sender;
                String playernam = args[0];
              
                getConfig().set(playernam, "null");
                getConfig().set(playernam + "Color", "RESET");
              
                if(sender instanceof Player)
                player.sendMessage(ChatColor.RED + playernam + "'s title has been removed.");
                else System.out.println(ChatColor.RED + playernam + "'s title has been removed.");
              
            }else if(sender instanceof Player){
                Player player = (Player) sender;
                player.sendMessage("/titleremove <player>");
            }
        }else if(cmd.getName().equalsIgnoreCase("titlevisible")){
            if(args.length == 0){
                if(sender instanceof Player){
                    if(args[0] == "true"){
                    Player player = (Player) sender;
                    if(getConfig().getString(player.toString()) != null){
                    player.setDisplayName("[" + ChatColor.valueOf(getConfig().getString(player.toString() + "Color")) + getConfig().getString(player.toString()) + "] " + player.toString());
                    player.sendMessage(ChatColor.MAGIC + "Your title is now visible!");
                    }else{
                        player.sendMessage(ChatColor.DARK_RED + "-- You don't have a title! --");
                    }
                    }else if(args[0] == "false"){
                        Player player = (Player) sender;
                        player.setDisplayName(player.toString());
                        player.sendMessage(ChatColor.DARK_PURPLE + "Your title is no longer visible.");
                    }else{
                        Player player = (Player) sender;
                        player.sendMessage(ChatColor.DARK_RED + "Sorry, something went wrong while processing your command!");
                        player.sendMessage(ChatColor.DARK_RED + "Please tell an admin or moderator about this error.");
                    }
                  
                }else{
                    System.out.println("Sorry, /titlevisible can not be executed from the console!");
                    System.out.println("Consider using /titleremove <player>");
    
                }
              
            }else if(sender instanceof Player){
                Player player = (Player) sender;
                player.sendMessage("/titlevisible <true/false>");
              
            }else{
                System.out.println("Sorry, /titlevisible can not be executed from the console!");
                System.out.println("Consider using /titleremove <player>");
    
            }
        }else if(cmd.getName().equalsIgnoreCase("locate")){
            if(args.length == 0){
                if(Bukkit.getServer().getOnlinePlayers().contains(args[0])){
                    Player players = Bukkit.getServer().getPlayer(args[0]);
                    Player player = (Player) sender;
                  
                    if(sender instanceof Player)
                    player.sendMessage(ChatColor.DARK_GREEN + players.toString() + "'s location is " + ChatColor.GOLD + ChatColor.ITALIC + players.getLocation().getBlock().getLocation());
                    else System.out.println(ChatColor.DARK_GREEN + players.toString() + "'s location is " + ChatColor.GOLD + ChatColor.ITALIC + players.getLocation().getBlock().getLocation());
                  
                }else{
                    Player player = (Player) sender;
                    player.sendMessage(ChatColor.RED + "That player cannot be found!");
    
                }
              
            }else if(sender instanceof Player){
                Player player = (Player) sender;
                player.sendMessage("/locate <player>");
            }else{
                System.out.println("/locate <player>");
            }
        }
                return false;
                }
    }
    

    And here is my console output:
    Log (open)

    Code:
    [20:16:45] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [20:16:46] [Server thread/INFO]: Loading properties
    [20:16:46] [Server thread/INFO]: Default game type: SURVIVAL
    [20:16:46] [Server thread/INFO]: Generating keypair
    [20:16:47] [Server thread/INFO]: Starting Minecraft server on 192.168.1.6:25565
    [20:16:47] [Server thread/INFO]: Using default channel type
    [20:16:56] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [20:16:56] [Server thread/INFO]: [CustomTitles] Loading CustomTitles v1.0
    [20:16:58] [Server thread/INFO]: Preparing level "world"
    [20:16:59] [Server thread/INFO]: Preparing start region for level 0 (Seed: 7718521308278882592)
    [20:17:00] [Server thread/INFO]: Preparing spawn area: 0%
    [20:17:01] [Server thread/INFO]: Preparing spawn area: 4%
    [20:17:02] [Server thread/INFO]: Preparing spawn area: 23%
    [20:17:03] [Server thread/INFO]: Preparing spawn area: 60%
    [20:17:04] [Server thread/INFO]: Preparing spawn area: 81%
    [20:17:05] [Server thread/INFO]: Preparing start region for level 1 (Seed: 7718521308278882592)
    [20:17:06] [Server thread/INFO]: Preparing spawn area: 26%
    [20:17:07] [Server thread/INFO]: Preparing spawn area: 44%
    [20:17:08] [Server thread/INFO]: Preparing spawn area: 51%
    [20:17:09] [Server thread/INFO]: Preparing spawn area: 86%
    [20:17:09] [Server thread/INFO]: Preparing start region for level 2 (Seed: 7718521308278882592)
    [20:17:10] [Server thread/INFO]: Preparing spawn area: 48%
    [20:17:11] [Server thread/INFO]: [CustomTitles] Enabling CustomTitles v1.0
    [20:17:12] [Server thread/INFO]: [CustomTitles] ================================================= 
        bignose956: Custom Titles: 
    ================================================= 
        Custom Titles is enabled and has loaded successfully!  
        Version: 1.0 
    ================================================= 
        User Thank you for using this plugin, 
        use '/help CustomTitles' for commands. 
    =================================================
    [20:17:12] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:17:12] [Server thread/INFO]: Done (14.418s)! For help, type "help" or "?"
    [20:17:23] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 6069ms behind, skipping 121 tick(s)
    [20:17:52] [User Authenticator #1/INFO]: UUID of player bignose956 is 0cd5d267-fb98-4a3c-a7c3-1c5a9569773d
    [20:17:52] [Server thread/INFO]: bignose956[/192.168.1.6:50247] logged in with entity id 286 at ([world]249.74299364537458, 66.0, 212.2320888734398)
    [20:18:09] [Server thread/INFO]: bignose956 issued server command: /titleset bignose956 Owner RED
    [20:19:09] [Server thread/INFO]: bignose956 issued server command: /titleset bignose956 Owner
    [20:19:09] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'titleset' in plugin CustomTitles v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
        at me.bukkit.bignose956.CustomTitles.onCommand(CustomTitles.java:72) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        ... 15 more
    [20:19:17] [Server thread/INFO]: bignose956 issued server command: /locate bignose956
    [20:19:44] [Server thread/INFO]: bignose956 issued server command: /locate
    [20:19:44] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'locate' in plugin CustomTitles v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at me.bukkit.bignose956.CustomTitles.onCommand(CustomTitles.java:164) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        ... 15 more
    [20:19:53] [Server thread/INFO]: bignose956 issued server command: /titleremove bignose956
    [20:20:06] [Server thread/INFO]: bignose956 issued server command: /titlevisible true
    [20:20:09] [Server thread/INFO]: bignose956 issued server command: /titlevisible false
    [20:20:12] [Server thread/INFO]: bignose956 lost connection: Disconnected
    [20:20:12] [Server thread/INFO]: bignose956 left the game.
    [20:20:17] [Server thread/INFO]: Stopping the server
    [20:20:17] [Server thread/INFO]: Stopping server
    [20:20:17] [Server thread/INFO]: [CustomTitles] Disabling CustomTitles v1.0
    [20:20:17] [Server thread/INFO]: Saving players
    [20:20:17] [Server thread/INFO]: Saving worlds
    [20:20:17] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [20:20:19] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [20:20:19] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
    
    
    
     
    Last edited: Mar 8, 2017
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development
    @bignose956 Please post your code, not your class files.
     
  3. Offline

    bignose956

    Ok I changed it
     
    Last edited: Feb 20, 2017
  4. Offline

    ipodtouch0218

    1. You can use ChatColor.valueOf(String) to return a ChatColor from a string...
    2. DO NOT SLEEP THE MAIN THREAD. Use Schedulers or BukkitRunnables instead.
    3. Your onDisable doesn't do anything, remove it.
    4. Why are you using InputStreams and OutputStreams to write to files? Just use Bukkit's Config.
    5. Don't blindly cast sender to Player. It will return errors if the console runs it. Check if sender instanceof Player first.
    6. Don't have your event handler throw FileNotFoundException.
    7. Don't log your own plugins, Bukkit does that for you.
    8. Check if the command name equalsIgnoreCase() instead of just equals, for CaPs compataibility.

    Can you post exactly line 147 of CustomTitles?
     
    Last edited: Feb 23, 2017
  5. Offline

    bignose956

    Line 147: break;
     
  6. Offline

    ipodtouch0218

    Breaking a loop will never cause the error that you have, an ArrayIndexOutOfBoundsException. Did you edit your code any more?
     
    Last edited: Mar 2, 2017
  7. Offline

    bignose956

    I did change it, but I continue to have errors.
    Could you look at it again please? (I removed ColorCoding.java)
    CustomTitles.java (open)
    Code:
    package me.bukkit.bignose956;
    
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    import java.io.UnsupportedEncodingException;
    
    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.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class CustomTitles extends JavaPlugin implements Listener{
    
    
        @Override
        public void onEnable(){
        
            Bukkit.getPluginManager().registerEvents(this, this);
        
            try {
                PrintWriter pw = new PrintWriter(System.getProperty("user.dir") + "/plugins/CustomTitles/Readme.txt","UTF-8");
                pw.println("In the names.txt file, the name on line one will be assigned the title on line 1 in titles.txt.");
                pw.println("=========================================================================================================");
                pw.println("If you want to assign a title to a player, then add his name on a new line at the bottom of names.txt,");
                pw.println("and add his title on a new line at the bottom on titles.txt.");
                pw.println("=========================================================================================================");
                pw.println("If you want to edit a player's title, then find his name in the names.txt file, and memorize what line it's on,");
                pw.println("then go to that same line on titles.txt and edit the title that is already there.");
                pw.println("=========================================================================================================");
                pw.println("If you want to remove a player's title, then use /titleremove <player> in game. You can also open names.txt");
                pw.println("and find the player's name, memorize what is it's on, remove it from names.txt, open titles.txt, go to the same line,");
                pw.println("and remove the title that is already there.");
                pw.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        
        
            String user = new String(System.getProperty("user.name"));
            getLogger().info("================================================= \n "
                    + "\tbignose956: Custom Titles: \n"
                    + "================================================= \n"
                    + "\tCustom Titles is enabled and has loaded successfully!  \n"
                    + "\tVersion: 1.0 \n"
                    + "================================================= \n"
                    + "\t" + user + " Thank you for using this plugin, \n"
                            + "\tuse '/help CustomTitles' for commands. \n"
                            + "=================================================");
        
        }
    
        @Override
        public void onDisable(){
        
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        
            if(cmd.getName().equalsIgnoreCase("titleset")){
                System.out.println(args [0] + args[1] + args[2] + args[3]);
                if(args.length <= 3 && args.length > 1){
                    Player player = (Player) sender;
                    String playernam = args[1];
    
                    getConfig().createSection(playernam);
                    if(args[3] != null){
                    getConfig().createSection(playernam + "Color");
                    getConfig().set(playernam + "Color", args[3]);
                    }
                
                    getConfig().set(playernam, args[1]);
                
                    if(sender instanceof Player){
                
                    player.sendMessage(ChatColor.DARK_PURPLE + args[0] + ChatColor.RESET + "'s title has been set to " + ChatColor.ITALIC + ChatColor.DARK_RED + args[1]);
                    }else{
                        System.out.println(ChatColor.DARK_PURPLE + args[0] + ChatColor.RESET + "'s title has been set to " + ChatColor.ITALIC + ChatColor.DARK_RED + args[1]);
                    }
                }else if(sender instanceof Player){
                    Player player = (Player) sender;
                    player.sendMessage("/titleset <player> <title> <title color>");
                }else{
                    System.out.println("/titleset <player> <title> <title color>");
                }
            
            
            
            }else{
                if(cmd.getName().equalsIgnoreCase("titleremove")){
                    if(args.length == 1){
                        Player player = (Player) sender;
                        String playernam = args[1];
                    
                            getConfig().set(playernam, "");
                        
                            if(sender instanceof Player){
                                player.sendMessage(ChatColor.ITALIC + playernam + "'s title was removed.");
                            }
                }else if(sender instanceof Player){
                    Player player = (Player) sender;
                    player.sendMessage("/titleremove <player>");
                }else{
                    System.out.println("/titleremove <player>");
                }
                }else if(cmd.getName().equalsIgnoreCase("locate")){
                    if(args.length == 1){
                    
                    }else if(sender instanceof Player){
                        Player player = (Player) sender;
                        player.sendMessage("/locate <player>");              
                    }else{
                    System.out.println("/locate <player>");
                    }
                }else if(sender instanceof Player){
                    Player player = (Player) sender;
                    player.sendMessage("Unknown command! Type /help for help.");
                }else if(cmd.getName().equalsIgnoreCase("titlevisible")){
                    if(sender instanceof Player){
                        Player player = (Player) sender;
                        String playernam = player.toString();
                    if(args.length == 1){
                        if(args[1] == "true"){
                            player.setDisplayName("[" + ChatColor.valueOf(getConfig().getString(playernam + "Color")) + getConfig().getString(playernam) + ChatColor.RESET + "]" + " " + playernam);
                        player.sendMessage(ChatColor.MAGIC + "Your title is now visible.");
                        }else{
                            if(args[1] == "false"){
                                player.setDisplayName(playernam);
                                player.sendMessage(ChatColor.RED + "Your title is no longer visible.");
                            }
                        }
                    }else{
                        player.sendMessage("/titlevisible <true/false>");
                    }
                    }else{
                        System.out.println("/titlevisible can not be executed by the console!");
                    }
                }else{
                        System.out.println("Unknown command! Type /help for help.");
                }
            }
        
            return false;
        }
    }

    Log (open)
    Code:
    [18:14:20] [Server thread/INFO]: Starting minecraft server version 1.8.8
    [18:14:20] [Server thread/INFO]: Loading properties
    [18:14:20] [Server thread/INFO]: Default game type: SURVIVAL
    [18:14:20] [Server thread/INFO]: Generating keypair
    [18:14:20] [Server thread/INFO]: Starting Minecraft server on 192.168.1.6:25565
    [18:14:20] [Server thread/INFO]: Using default channel type
    [18:14:23] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-e1ebe52 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [18:14:23] [Server thread/INFO]: [CustomTitles] Loading CustomTitles v1.0
    [18:14:23] [Server thread/INFO]: Preparing level "world"
    [18:14:24] [Server thread/INFO]: Preparing start region for level 0 (Seed: 7718521308278882592)
    [18:14:25] [Server thread/INFO]: Preparing spawn area: 10%
    [18:14:26] [Server thread/INFO]: Preparing spawn area: 82%
    [18:14:26] [Server thread/INFO]: Preparing start region for level 1 (Seed: 7718521308278882592)
    [18:14:27] [Server thread/INFO]: Preparing spawn area: 19%
    [18:14:28] [Server thread/INFO]: Preparing spawn area: 87%
    [18:14:28] [Server thread/INFO]: Preparing start region for level 2 (Seed: 7718521308278882592)
    [18:14:29] [Server thread/INFO]: [CustomTitles] Enabling CustomTitles v1.0
    [18:14:29] [Server thread/INFO]: [CustomTitles] =================================================
        bignose956: Custom Titles:
    =================================================
        Custom Titles is enabled and has loaded successfully!
        Version: 1.0
    =================================================
        User Thank you for using this plugin,
        use '/help CustomTitles' for commands.
    =================================================
    [18:14:29] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [18:14:29] [Server thread/INFO]: Done (5.568s)! For help, type "help" or "?"
    [18:14:33] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2582ms behind, skipping 51 tick(s)
    [18:14:37] [User Authenticator #1/INFO]: UUID of player bignose956 is 0cd5d267-fb98-4a3c-a7c3-1c5a9569773d
    [18:14:38] [Server thread/INFO]: bignose956[/192.168.1.6:52373] logged in with entity id 299 at ([world]243.28443365076535, 67.0, 210.31344373419367)
    [18:14:52] [Server thread/INFO]: bignose956 issued server command: /titleset bignose956 Owner Red
    [18:14:52] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'titleset' in plugin CustomTitles v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
        at me.bukkit.bignose956.CustomTitles.onCommand(CustomTitles.java:67) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.8.8.jar:git-Bukkit-e1ebe52]
        ... 15 more
    [18:15:18] [Server thread/INFO]: bignose956 lost connection: Disconnected
    [18:15:18] [Server thread/INFO]: bignose956 left the game.
    [18:15:21] [Server thread/INFO]: Stopping the server
    [18:15:21] [Server thread/INFO]: Stopping server
    [18:15:21] [Server thread/INFO]: [CustomTitles] Disabling CustomTitles v1.0
    [18:15:21] [Server thread/INFO]: Saving players
    [18:15:21] [Server thread/INFO]: Saving worlds
    [18:15:21] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [18:15:22] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [18:15:22] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
    

    P.S. I'm going to use onDisable later, so I left it there
     
  8. Offline

    Zombie_Striker

    This is happening because you are printing out the args before you even know if they exist. Remove the sys.out line and everything should work fine.
     
  9. Offline

    MaxFireIce

    @bignose956 also, please name your title something less generic and be more specific next time;) Thanks!
     
  10. Offline

    ipodtouch0218

    One other problem, args[x] starts from zero, whilst args.length starts at one. When you're checking "
    if(args.length <= 3)", You never get a third argument, only args[0,1,2], but never args[3]. Change all the args[x] to one less, then you'll get the arguments you want.
     
  11. Offline

    bignose956

    I tried both of these suggestions, still got errors. I updated the thread, you can read the new error log and main class to further help me.
     
  12. Offline

    Zombie_Striker

    Code:
    if(args.length == 2){
    ...
    if(args[2] != null){
    The problem here is that you are confusing "Human numbers" with "Machine numbers/indexes". When checking the length, it returns human numbers, meaning the first value is "1".// But, Indexes start at 0. So you either meant for args length to be equal to 3 so you can get three args (since args[2] is the third arg), or you meant for args[2] to be the second arg (args[1])
     
    Kermit_23 and ipodtouch0218 like this.
  13. Offline

    bignose956

    Looking at my longest command,
    Code:
    /titleset <player> <title> <title color>
    you can see that it requires 3 arguments, <player>, <title>, and <color>. That would be 2 indexes/args in my understanding.
    Code:
    /locate <player>
    would have 1 arguments, that would be stored in args[0]? And it's the same way with
    Code:
    /titleremove <player>
    and
    Code:
    /titlevisible <true/false>
    ?
     
  14. Offline

    Zombie_Striker

  15. Offline

    bignose956

    So then what's wrong with my code? Why is it crashing?
     
  16. Offline

    Zombie_Striker

    @bignose956
    Can you post the updated code with an updated error log? Most likely, the error message has changed.
     
  17. Offline

    bignose956

    Done
     
  18. Offline

    ipodtouch0218

    You're checking "if (args.length == 1)" then trying to get "args[2]".
     
  19. Offline

    bignose956

    [​IMG]

    Let me fix that...

    Ok, I updated the class file and the new crash log. Still crashing.
     
    Last edited: Mar 8, 2017
    ipodtouch0218 likes this.
  20. Offline

    Gater12

    @bignose956
    It looks like you are trying to grab the third argument when there is only two.
    Index numbers for Arrays start at 0. So the first argument would 0 and the second 1 and so on.
     
  21. Offline

    bignose956

    I know... Where am I screwing up with indexes?
     
  22. Offline

    Gater12

    @bignose956
    Check all your args.length checks because maybe you got confused. Sometimes you check if the args.length is 0 meaning no arguments but you try to use the first argument args[0].
     
  23. Offline

    ipodtouch0218

    Don't null check args[2] if you know they don't exist.
     
  24. Offline

    bignose956

    For /locate, /titleremove, and /titlevisible only one arguments are passed, that's why it checks args.length == 0
     
  25. Offline

    Gater12

    @bignose956
    args.length is 0 when there are no arguments. When there is 1 argument args.length will give you 1.
     
  26. Offline

    bignose956

    OHHHH!!!! I thought that that it was like regular arrays! For example
    Code:
    String cake[] = {"Chocolate", "Vanilla", "Red Velvet", "Strawberry"};
    
    where as cake[0] is chocolate, and it goes on from there. Now I get it XP
     
  27. Offline

    ipodtouch0218

    Edit: Yeah, you got it :p
     
Thread Status:
Not open for further replies.

Share This Page