Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: bound must be positive

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default bound must be positive

    Hello,

    I'm tyring to code a minecraft server plugin and want to spawn a player randomly on pre defined locations writen in a config file. So far so good, because it works when a player wants to join the mini game I made by simply right clicking on a special sign. When there is no spawn defined in the config file yet, the console shows the error: bound must be positive. Which is right because there is no number (spawn) saved in the config. But when a players dies I use the same method but the console says: bound must be postive. Which it is! There is a spawn defined in the config and it says 1, counting up.

    Now to the code:

    public Location getRandomSpawn() {
      		if (!arenas.contains("Arenas." + getName() + ".Spawns.Counter")) {
      			return null;
      		}
      		else {
      			Random rand = new Random();
      			int other = this.arenas.getInt("Arenas." + getName() + ".Spawns.Counter") - 1;
      			int num = rand.nextInt(other) + 1;
      			Location loc = getSpawn(num);
      			return loc;
     
      		}
      	}

    I use this to get the x,y,z and direktion of looking with this:

    public Location getSpawn(int id) {
      		if (!arenas.contains("Arenas." + getName() + ".Spawns.Counter")) {
      			return null;
      		}
      		else {
     
      			Location loc = new Location(Bukkit.getWorld(this.arenas.getString("Arenas." + getName() + ".Spawns." + id + ".World")), this.arenas.getDouble("Arenas." + getName() + ".Spawns." + id + ".X"), 
                            this.arenas.getDouble("Arenas." + getName() + ".Spawns." + id + ".Y"), this.arenas.getDouble("Arenas." + getName() + ".Spawns." + id + ".Z"));
      			loc.setPitch((float)this.arenas.getDouble("Arenas." + getName() + ".Spawns." + id + ".Pitch"));
      			loc.setYaw((float)this.arenas.getDouble("Arenas." + getName() + ".Spawns." + id + ".Yaw"));
      			return loc;
     
      		}
     
      	}

    I call getRandomSpawn() in all cases. And yes I know that if there is no spawn wrtitten in the config it just returns null, i have to change that in the future but for now I want to know what's going on....

    Now the code where I use getRandomSpawn().

    SIGN:

    @EventHandler
    	public void onSignInteract(PlayerInteractEvent e) {
        Player player = e.getPlayer();
        	if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && e.hasBlock() && e.getClickedBlock().getState() instanceof Sign) {
        		Sign sign = (Sign)e.getClickedBlock().getState();
        		if (sign.getLine(0).equalsIgnoreCase("[" + ChatColor.GOLD + "CrackShot" + ChatColor.BLACK + "]")) {
     
        			sign.update();
        			for (Iterator<?> iterator = Arenas.getArenas().iterator(); iterator.hasNext(); ) {
     
        				Arena arena = (Arena)iterator.next();
        				if (sign.getLine(1).equalsIgnoreCase(ChatColor.BOLD + arena.getName())) {
        					if (!arena.hasPlayer(player)) {
     
        						if (Methods.getLobby() != null) {
     
        							if (arena.getPlayers().size() < arena.getMaxPlayers()) {
     
        								if (!arena.isOn()) {
     
        									arena.addPlayer(player);
        									Arenas.addArena(player, arena);
        									player.teleport(arena.getRandomSpawn());
        									Main.sendMessage(player, "You joined the Arena: " + ChatColor.GOLD + arena.getName());
        									arena.sendAll(ChatColor.GRAY + "[" + ChatColor.GOLD + "CrackShot" + ChatColor.GRAY + "] " + ChatColor.GOLD + player.getName().toString() + ChatColor.GRAY + " has joined the Arena!");
        									arena.updateSigns();
        									Main.setScoreboard(player);
        									player.setGameMode(GameMode.SURVIVAL);
        									continue;
        								} 
        								Main.sendMessage(player, "Arena is disabled!");
     
        								continue;
        							} 
        							Main.sendMessage(player, "Arena is full!");
     
        							continue;
        						} 
        						Main.sendMessage(player, "No spawn set!");
     
        						continue;
        					} 
        					Main.sendMessage(player, "You are already in the Arena!");
        				} 
        			} 
        		} 
        	} 
    	}

    Please ignore all the rest because important is only "player.teleport(arena.getRandomSpawn());"

    DEATH:

    @EventHandler
      	public void playerRespawnTeleport(PlayerRespawnEvent e) {
      		Player player = e.getPlayer();
      		if(Arenas.isInArena(player)){
      	  		e.setRespawnLocation(getRandomSpawn());
      		}
      	}

    My impression of the situation is that "teleport()" and "setRespawnLoaction()" maybe work differently? But I just can be stupid and don't see the mistake.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: bound must be positive

    the console says: bound must be postive.
    Have you printed out all the values of the bounds to see where the problem is?
    Are there any values that are not positive? Is 0 considered not positive?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. String out of bound exception
    By dextrod in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 2nd, 2018, 05:31 AM
  2. Bound Buffer Problem
    By hockeyplayer in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 21st, 2012, 04:01 PM
  3. It is possible that not using array to list the positive integer <100??
    By lim131 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 15th, 2012, 10:52 AM
  4. Replies: 8
    Last Post: April 14th, 2012, 12:24 PM
  5. [SOLVED] bound mismatcherror?
    By zytm in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 9th, 2011, 07:52 AM

Tags for this Thread