Unhandled exception error

Discussion in 'Plugin Development' started by Fluf3, Jan 10, 2018.

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

    Fluf3

    I havent used Java and Bukkit in a couple years and I now have a bug I cant fix. Any help please
    Here is code and log:
    Code:
    Code:
    package io.eliot.parkourgen;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class Main extends JavaPlugin {
        //Add duo system so when the both people have stepped on them then break the block
        //Generate list of all blocks created and set back to air when /parkour stop is called
        String perms[] = {"pgen.mat1", "pgen.mat2","pgen.mat3","pgen.mat4","pgen.mat5","pgen.mat6"};
        FileConfiguration config = this.getConfig();
        Map<String,String> currentUsers = new HashMap<String,String>();
        Map<String,Boolean> firstBlock = new HashMap<String,Boolean>();
        Map<String,String> newBlockX = new HashMap<String,String>();
        Map<String,String> newBlockY = new HashMap<String,String>();
        Map<String,String> newBlockZ = new HashMap<String,String>();
        Map<String,String> prevBlockX = new HashMap<String,String>();
        Map<String,String> prevBlockY = new HashMap<String,String>();
        Map<String,String> prevBlockZ = new HashMap<String,String>();
        Map<String,Boolean> play = new HashMap<String,Boolean>();
        @Override
        public void onEnable() {
            if(config.getBoolean("firstLaunch")) {
                getLogger().info("Make sure to setup your config file correctly. Follow the guide at the plugin download page on bukkit!");
            }
            PlayerJumpEvent.register(this);
        }
        @Override
        public void onDisable() {
          
        }
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player;
            try {
                player = (Player)sender;
            }catch(Exception e) {
                player = null;
            }
            //Start of command
            if(command.getName().equalsIgnoreCase("parkour")) {
                Location loc = player.getLocation();
                World world = loc.getWorld();
                //Arg one is start
                if(args[0].equalsIgnoreCase("start")) {
                    //Message player saying that the game is starting
                    player.sendMessage(ChatColor.BLUE+"Starting Game! Use '/parkour stop' to end the game!");
                    //teleports player up
                    try {
                      
                  
                    if(args.length==2) {
                        if(Integer.parseInt(args[1])>200) {
                            sender.sendMessage(ChatColor.RED+"Use a hight under 200! (/parkour start 150)");
                            return false;
                        }else if(Integer.parseInt(args[1])>0&&Integer.parseInt(args[1])<200){
                            Location teleport = new Location(player.getWorld(),player.getLocation().getX(), Double.parseDouble(args[1]), player.getLocation().getZ());
                            Location block = new Location(player.getWorld(),player.getLocation().getX(), Double.parseDouble(args[1])-1, player.getLocation().getZ());
                            Block tped = world.getBlockAt(block);
                            tped.setType(Material.EMERALD);
                            player.teleport(teleport);
                        }
                    }else {
                      
                    }
                    }catch(Exception e){player.sendMessage(e.toString());}
                    Material favBlock = Material.getMaterial(config.getString(player.getUniqueId().toString()+" material"));
                    firstBlock.put(player.getUniqueId().toString(),true);
                    play.put(player.getUniqueId().toString(), true);
                    Boolean running = play.get(player.getUniqueId().toString());
                    player.sendMessage("one");
                    while(running) {
                        player.sendMessage("one");
                        //Put player loc into newBlockX/Y/Z
                        int startX = player.getLocation().getBlockX();
                        int startY = player.getLocation().getBlockY();
                        int startZ = player.getLocation().getBlockZ();
                        int currentBlockX = startX;
                        int currentBlockY= startY;
                        int currentBlockZ = startZ;
                        currentUsers.put(player.getUniqueId().toString(),"0");
                        int currentNum = Integer.parseInt(currentUsers.get(player.getUniqueId().toString()));
                        //New block randoms
                        //SORT THESE OUT WITH THE PREVBLOCK ARRAYS CUZ THIS DOESNT WORK
                        currentBlockX = (int) (Math.random() * (Double.parseDouble(prevBlockX.get(player.getUniqueId().toString())+" 1")+5) + (Double.parseDouble(newBlockX.get(player.getUniqueId().toString()))-4));
                        currentBlockY = (int) (Math.random() * (Double.parseDouble(newBlockY.get(player.getUniqueId().toString()))+2) + (Double.parseDouble(newBlockY.get(player.getUniqueId().toString()))-3));
                        currentBlockZ = (int) (Math.random() * (Double.parseDouble(newBlockZ.get(player.getUniqueId().toString()))+5) + (Double.parseDouble(newBlockZ.get(player.getUniqueId().toString()))-4));
                        //Find block at the generated location
                        Block newBlock = world.getBlockAt(currentBlockX, currentBlockY, currentBlockZ);
                        if(!player.isOnGround()) {
                            if(currentUsers.containsKey(player.getUniqueId().toString())) {
                                currentUsers.remove(player.getUniqueId().toString());
                            }
                            currentUsers.put(player.getUniqueId().toString(), "0");
    
                        if(firstBlock.containsKey(player.getUniqueId().toString())){
                            prevBlockX.put(player.getUniqueId().toString()+" 1", Integer.toString(currentBlockX));
                            prevBlockY.put(player.getUniqueId().toString()+" 1", Integer.toString(currentBlockY));
                            prevBlockZ.put(player.getUniqueId().toString()+" 1", Integer.toString(currentBlockZ));
                            prevBlockX.put(player.getUniqueId().toString()+" 2", Integer.toString(currentBlockX));
                            prevBlockY.put(player.getUniqueId().toString()+" 2", Integer.toString(currentBlockY));
                            prevBlockZ.put(player.getUniqueId().toString()+" 2", Integer.toString(currentBlockZ));
                            prevBlockX.put(player.getUniqueId().toString()+" 3", Integer.toString(currentBlockX));
                            prevBlockY.put(player.getUniqueId().toString()+" 3", Integer.toString(currentBlockY));
                            prevBlockZ.put(player.getUniqueId().toString()+" 3", Integer.toString(currentBlockZ));
                            firstBlock.remove(player.getUniqueId().toString());
                        }
                        //Check if the block type is air and the two blocks above it are are
                        if(newBlock.getType() == Material.AIR&&world.getBlockAt(currentBlockX, currentBlockY+1, currentBlockZ).getType()==Material.AIR&&world.getBlockAt(currentBlockX, currentBlockY+2, currentBlockZ).getType()==Material.AIR) {
                            try {
                                if(currentNum==0) {
                                    newBlock.setType(favBlock);
                                    currentUsers.put(player.getUniqueId().toString(), "1");
                                    Location oldLocation = new Location(player.getWorld(),Double.parseDouble(prevBlockX.get( player.getUniqueId().toString())+ " 3"),Double.parseDouble(prevBlockX.get( player.getUniqueId().toString())+ " 3"),Double.parseDouble(prevBlockX.get( player.getUniqueId().toString())+ " 3"));
                                    Block old = world.getBlockAt(oldLocation);
                                    old.setType(Material.AIR);
                                    prevBlockX.put(player.getUniqueId().toString()+ " 3", prevBlockX.get( player.getUniqueId().toString()+ " 2"));
                                    prevBlockY.put(player.getUniqueId().toString()+ " 3",prevBlockY.get( player.getUniqueId().toString()+ " 2"));
                                    prevBlockZ.put(player.getUniqueId().toString()+ " 3", prevBlockZ.get( player.getUniqueId().toString()+ " 2"));
                                    prevBlockX.put(player.getUniqueId().toString()+ " 2", prevBlockX.get( player.getUniqueId().toString()+ " 1"));
                                    prevBlockY.put(player.getUniqueId().toString()+ " 2", prevBlockX.get( player.getUniqueId().toString()+ " 1"));
                                    prevBlockZ.put(player.getUniqueId().toString()+ " 2", prevBlockX.get( player.getUniqueId().toString()+ " 1"));
                                    prevBlockX.put(player.getUniqueId().toString()+ " 1", Integer.toString(currentBlockX));
                                    prevBlockY.put(player.getUniqueId().toString()+ " 1", Integer.toString(currentBlockY));
                                    prevBlockZ.put(player.getUniqueId().toString()+ " 1", Integer.toString(currentBlockZ));
                                }
                              
                            }catch(Exception e){
                                if(currentNum==0) {
                                    sender.sendMessage(ChatColor.AQUA+"Parkour: unlock blocks with /parkour blocks");
                                    newBlock.setType(Material.STONE);
                                    currentUsers.put(player.getUniqueId().toString(), "1");
                                }
                              
                            }
                        }else {
                            //Dont spawn the block because it isnt clear
                        }
                    }
                    }
                    //END OF START
                    //Setting blocks command
                    }else if(args[0]=="blocks") {
                        if(args[1]==null) {
                            sender.sendMessage(ChatColor.RED+"ERROR! You need to state a material. Available materials are:");
                            for(int i=0;i<perms.length;i++)
                            {
                                if(sender.hasPermission(perms[i]))
                                {
                                    sender.sendMessage(ChatColor.GREEN+config.getString(perms[i]));
                                }else {
                                    sender.sendMessage(ChatColor.RED+config.getString(perms[i]));
                                }
                            }
                            sender.sendMessage(ChatColor.RED+"");
                        }else {
                            if(config.getString("mat1").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[1])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat2").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[2])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat3").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[3])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat4").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[4])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat5").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[5])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat6").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[6])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else {
                              
                            }
                        }
                      
                    }else if(args[0]=="stop") {
                        try {
                            play.remove(player.getUniqueId().toString());
                        } catch (Exception e) {
                            player.sendMessage(ChatColor.RED+"You must be playing to stop!");
                        }
                    }
              
            }
        return true;
        }
        @EventHandler
        public void onPlayerJump(PlayerJumpEvent e) {
            if(e.getPlayer().isOnGround()) {
              
            }
        }
      
    }
    
     
    Last edited: Jan 10, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @Fluf3 What is at line 93?
     
  3. Offline

    Fluf3

    @timtower Sorry didnt see that. That didnt fix the problem but I updated the code with what it was meant to be.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Fluf3 You get arguments before you check the length.
     
  5. Offline

    Fluf3

    oof.jpg ill try and fix that now. if that fixes it im so sorry for being that stupid. I thought i could just try and do args[1].isEmpty()

    @timtower It now doesnt give me the error when i call /parkour (which does nothing) but when i do '/parkour start' it says
    new code is
    Code:
    package io.eliot.parkourgen;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class Main extends JavaPlugin {
        //Add duo system so when the both people have stepped on them then break the block
        //Generate list of all blocks created and set back to air when /parkour stop is called
        String perms[] = {"pgen.mat1", "pgen.mat2","pgen.mat3","pgen.mat4","pgen.mat5","pgen.mat6"};
        FileConfiguration config = this.getConfig();
        Map<String,String> currentUsers = new HashMap<String,String>();
        Map<String,Boolean> firstBlock = new HashMap<String,Boolean>();
        Map<String,String> newBlockX = new HashMap<String,String>();
        Map<String,String> newBlockY = new HashMap<String,String>();
        Map<String,String> newBlockZ = new HashMap<String,String>();
        Map<String,String> prevBlockX = new HashMap<String,String>();
        Map<String,String> prevBlockY = new HashMap<String,String>();
        Map<String,String> prevBlockZ = new HashMap<String,String>();
        Map<String,Boolean> play = new HashMap<String,Boolean>();
        @Override
        public void onEnable() {
            if(config.getBoolean("firstLaunch")) {
                getLogger().info("Make sure to setup your config file correctly. Follow the guide at the plugin download page on bukkit!");
            }
            PlayerJumpEvent.register(this);
        }
        @Override
        public void onDisable() {
           
        }
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player;
            try {
                player = (Player)sender;
            }catch(Exception e) {
                player = null;
            }
            //Start of command
            if(command.getName().equalsIgnoreCase("parkour")) {
                if(args.length>0&&args.length<3) {
                Location loc = player.getLocation();
                World world = loc.getWorld();
                //Arg one is start
                if(args[0].equalsIgnoreCase("start")) {
                    //Message player saying that the game is starting
                    player.sendMessage(ChatColor.BLUE+"Starting Game! Use '/parkour stop' to end the game!");
                    //teleports player up
                    try {
                       
                   
                    if(args.length==2) {
                        if(Integer.parseInt(args[1])>200) {
                            sender.sendMessage(ChatColor.RED+"Use a hight under 200! (/parkour start 150)");
                            return false;
                        }else if(Integer.parseInt(args[1])>0&&Integer.parseInt(args[1])<200){
                            Location teleport = new Location(player.getWorld(),player.getLocation().getX(), Double.parseDouble(args[1]), player.getLocation().getZ());
                            Location block = new Location(player.getWorld(),player.getLocation().getX(), Double.parseDouble(args[1])-1, player.getLocation().getZ());
                            Block tped = world.getBlockAt(block);
                            tped.setType(Material.EMERALD);
                            player.teleport(teleport);
                        }
                    }else {
                       
                    }
                    }catch(Exception e){player.sendMessage(e.toString());}
                    Material favBlock = Material.getMaterial(config.getString(player.getUniqueId().toString()+" material"));
                    firstBlock.put(player.getUniqueId().toString(),true);
                    play.put(player.getUniqueId().toString(), true);
                    Boolean running = play.get(player.getUniqueId().toString());
                    player.sendMessage("one");
                    while(running) {
                        player.sendMessage("one");
                        //Put player loc into newBlockX/Y/Z
                        int startX = player.getLocation().getBlockX();
                        int startY = player.getLocation().getBlockY();
                        int startZ = player.getLocation().getBlockZ();
                        int currentBlockX = startX;
                        int currentBlockY= startY;
                        int currentBlockZ = startZ;
                        int currentNum = Integer.parseInt((currentUsers.put(currentUsers.get(player.getUniqueId().toString()),"0")));
                        //New block randoms
                        //SORT THESE OUT WITH THE PREVBLOCK ARRAYS CUZ THIS DOESNT WORK
                        currentBlockX = (int) (Math.random() * (Double.parseDouble(prevBlockX.get(player.getUniqueId().toString())+" 1")+5) + (Double.parseDouble(newBlockX.get(player.getUniqueId().toString()))-4));
                        currentBlockY = (int) (Math.random() * (Double.parseDouble(newBlockY.get(player.getUniqueId().toString()))+2) + (Double.parseDouble(newBlockY.get(player.getUniqueId().toString()))-3));
                        currentBlockZ = (int) (Math.random() * (Double.parseDouble(newBlockZ.get(player.getUniqueId().toString()))+5) + (Double.parseDouble(newBlockZ.get(player.getUniqueId().toString()))-4));
                        //Find block at the generated location
                        Block newBlock = world.getBlockAt(currentBlockX, currentBlockY, currentBlockZ);
                        if(!player.isOnGround()) {
                            if(currentUsers.containsKey(player.getUniqueId().toString())) {
                                currentUsers.remove(player.getUniqueId().toString());
                            }
                            currentUsers.put(player.getUniqueId().toString(), "0");
    
                        if(firstBlock.containsKey(player.getUniqueId().toString())){
                            prevBlockX.put(player.getUniqueId().toString()+" 1", Integer.toString(currentBlockX));
                            prevBlockY.put(player.getUniqueId().toString()+" 1", Integer.toString(currentBlockY));
                            prevBlockZ.put(player.getUniqueId().toString()+" 1", Integer.toString(currentBlockZ));
                            prevBlockX.put(player.getUniqueId().toString()+" 2", Integer.toString(currentBlockX));
                            prevBlockY.put(player.getUniqueId().toString()+" 2", Integer.toString(currentBlockY));
                            prevBlockZ.put(player.getUniqueId().toString()+" 2", Integer.toString(currentBlockZ));
                            prevBlockX.put(player.getUniqueId().toString()+" 3", Integer.toString(currentBlockX));
                            prevBlockY.put(player.getUniqueId().toString()+" 3", Integer.toString(currentBlockY));
                            prevBlockZ.put(player.getUniqueId().toString()+" 3", Integer.toString(currentBlockZ));
                            firstBlock.remove(player.getUniqueId().toString());
                        }
                        //Check if the block type is air and the two blocks above it are are
                        if(newBlock.getType() == Material.AIR&&world.getBlockAt(currentBlockX, currentBlockY+1, currentBlockZ).getType()==Material.AIR&&world.getBlockAt(currentBlockX, currentBlockY+2, currentBlockZ).getType()==Material.AIR) {
                            try {
                                if(currentNum==0) {
                                    newBlock.setType(favBlock);
                                    currentUsers.put(player.getUniqueId().toString(), "1");
                                    Location oldLocation = new Location(player.getWorld(),Double.parseDouble(prevBlockX.get( player.getUniqueId().toString())+ " 3"),Double.parseDouble(prevBlockX.get( player.getUniqueId().toString())+ " 3"),Double.parseDouble(prevBlockX.get( player.getUniqueId().toString())+ " 3"));
                                    Block old = world.getBlockAt(oldLocation);
                                    old.setType(Material.AIR);
                                    prevBlockX.put(player.getUniqueId().toString()+ " 3", prevBlockX.get( player.getUniqueId().toString()+ " 2"));
                                    prevBlockY.put(player.getUniqueId().toString()+ " 3",prevBlockY.get( player.getUniqueId().toString()+ " 2"));
                                    prevBlockZ.put(player.getUniqueId().toString()+ " 3", prevBlockZ.get( player.getUniqueId().toString()+ " 2"));
                                    prevBlockX.put(player.getUniqueId().toString()+ " 2", prevBlockX.get( player.getUniqueId().toString()+ " 1"));
                                    prevBlockY.put(player.getUniqueId().toString()+ " 2", prevBlockX.get( player.getUniqueId().toString()+ " 1"));
                                    prevBlockZ.put(player.getUniqueId().toString()+ " 2", prevBlockX.get( player.getUniqueId().toString()+ " 1"));
                                    prevBlockX.put(player.getUniqueId().toString()+ " 1", Integer.toString(currentBlockX));
                                    prevBlockY.put(player.getUniqueId().toString()+ " 1", Integer.toString(currentBlockY));
                                    prevBlockZ.put(player.getUniqueId().toString()+ " 1", Integer.toString(currentBlockZ));
                                }
                               
                            }catch(Exception e){
                                if(currentNum==0) {
                                    sender.sendMessage(ChatColor.AQUA+"Parkour: unlock blocks with /parkour blocks");
                                    newBlock.setType(Material.STONE);
                                    currentUsers.put(player.getUniqueId().toString(), "1");
                                }
                               
                            }
                        }else {
                            //Dont spawn the block because it isnt clear
                        }
                    }
                    }
                    //END OF START
                    //Setting blocks command
                    }else if(args[0]=="blocks") {
                        if(args[1]==null) {
                            sender.sendMessage(ChatColor.RED+"ERROR! You need to state a material. Available materials are:");
                            for(int i=0;i<perms.length;i++)
                            {
                                if(sender.hasPermission(perms[i]))
                                {
                                    sender.sendMessage(ChatColor.GREEN+config.getString(perms[i]));
                                }else {
                                    sender.sendMessage(ChatColor.RED+config.getString(perms[i]));
                                }
                            }
                            sender.sendMessage(ChatColor.RED+"");
                        }else {
                            if(config.getString("mat1").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[1])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat2").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[2])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat3").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[3])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat4").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[4])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat5").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[5])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else if(config.getString("mat6").equalsIgnoreCase(args[1])&&sender.hasPermission(perms[6])) {
                                config.addDefault(player.getUniqueId().toString()+ " material", args[1]);
                            }else {
                               
                            }
                        }
                       
                    }else if(args[0]=="stop") {
                        try {
                            play.remove(player.getUniqueId().toString());
                        } catch (Exception e) {
                            player.sendMessage(ChatColor.RED+"You must be playing to stop!");
                        }
                    }
               
            }
            }else {
                player.sendMessage(ChatColor.BLUE+"You need to use valid arguments for parkour (/start /block /stop!");
            }
        return true;
        }
        @EventHandler
        public void onPlayerJump(PlayerJumpEvent e) {
            if(e.getPlayer().isOnGround()) {
               
            }
        }
       
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 10, 2018
  6. Offline

    timtower Administrator Administrator Moderator

    @Fluf3 Then again: What is on line 94
     
  7. Offline

    Fluf3

    @timtower sorry i fixed that. it wasnt the problem. it still doesnt work :( sorry for wasting your time. it is getting caught on
    Code:
    try {
    
    
    if(args.length==2) {
    if(Integer.parseInt(args[1])>200) {
    sender.sendMessage(ChatColor.RED+"Use a hight under 200! (/parkour start 150)");
    return false;
    }else if(Integer.parseInt(args[1])>0&&Integer.parseInt(args[1])<200){
    Location teleport = new Location(player.getWorld(),player.getLocation().getX(), Double.parseDouble(args[1]), player.getLocation().getZ());
    Location block = new Location(player.getWorld(),player.getLocation().getX(), Double.parseDouble(args[1])-1, player.getLocation().getZ());
    Block tped = world.getBlockAt(block);
    tped.setType(Material.EMERALD);
    player.teleport(teleport);
    }
    }else {
    
    }
    }catch(Exception e){player.sendMessage(e.toString());}
    and im getting a errror about invalid integers. im going to try again tomorrow
     
  8. Offline

    timtower Administrator Administrator Moderator

    You fixed that twice already...
     
  9. Offline

    Fluf3

    Yeah I don't know what happened. I tried to write two lines of code in one but not purposely
     
Thread Status:
Not open for further replies.

Share This Page