How to loop through config and find only coordinates?

Discussion in 'Plugin Development' started by IconByte, Feb 21, 2015.

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

    IconByte

    Hello. I am making plugin that teleports you to "linked" position. But I can't figure out how I would loop it through Teleports and positions' coordinates..?
    The configuration looks like this:
    Code:
    Teleporters:
      Teleport1:
        Pos1:
          X: -293
          Y: 64
          Z: 208
        Pos2:
          X: -298
          Y: 63
          Z: 221
      Teleport2:
        Pos1:
          X: -316
          Y: 70
          Z: 233
        Pos2:
          X: -331
          Y: 77
          Z: 238
    And there is something like timer when you are sneaking AND you are on the correct coords, then teleport, but I am stuck here atm, I don't know how I would do this:
    Code:
        public void sneakingTimer() {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                    for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
                        if (onlinePlayer.isSneaking()) {
                            int X = onlinePlayer.getLocation().getBlockX();
                            int Y = onlinePlayer.getLocation().getBlockY();
                            int Z = onlinePlayer.getLocation().getBlockZ();
                            for (String key : plugin.getConfig().getKeys(true)) {
                               
                            }
                        }
                    }
                }
            }, 0L, 20L);
        }
     
  2. I give you an example, but not a fully working code:
    for(String key : getConfig().getConfigurationSection("Teleporters").getKeys(false)) {
    int x1 = getConfig().getInt("Teleporters."+key+".Pos1");
    }
     
    Last edited: Feb 21, 2015
  3. Offline

    IconByte

    @FisheyLP
    Okay, thanks alot for that, but I still didn't figure out how to do it? :D
    Is it even close what I did?
    Code:
                            String world1 = onlinePlayer.getWorld().getName();
                            int X1 = onlinePlayer.getLocation().getBlockX();
                            int Y1 = onlinePlayer.getLocation().getBlockY();
                            int Z1 = onlinePlayer.getLocation().getBlockZ();
                            for (String teleporterName : plugin.getConfig().getConfigurationSection("Teleporters").getKeys(false)) {
                                int x1 = plugin.getConfig().getInt("Teleporters.Pos1." + teleporterName);
                                if (world1 == plugin.getConfig().getString("Teleporters." + teleporterName + ".Pos1.World") && X1 == plugin.getConfig().getInt("Teleporters." + teleporterName + ".Pos1.X") && Y1 == plugin.getConfig().getInt("Teleporters." + teleporterName + ".Pos1.Y") + 1 && Z1 == plugin.getConfig().getInt("Teleporters." + teleporterName + ".Pos1.Z") + 1) {
                                    String world2 = plugin.getConfig().getString("Teleporters." + teleporterName + ".Pos2.World");
                                    int X2 = plugin.getConfig().getInt("Teleporters." + teleporterName + ".Pos2.X");
                                    int Y2 = plugin.getConfig().getInt("Teleporters." + teleporterName + ".Pos2.Y");
                                    int Z2 = plugin.getConfig().getInt("Teleporters." + teleporterName + ".Pos2.Z");
                                    World world = Bukkit.getWorld(world2);
                                    Location loc = new Location(world, X2, Y2, Z2);
                                    onlinePlayer.teleport(loc);
                                }
                            }
    
     
  4. I would define each x,y,z,world and then use it like this:
    if(x == x1 && y == y1 && z == z1)
    . Your code looks right but why do you have +1 after y and z?
     
  5. Offline

    IconByte

    Yeah, after Z was a mistake, but Y is because when I set these coords in game(with PlayerInteractEvent) then it sets these coords like "in block" or something, so I have to check 1 block above Y..? I don't know is this logic right or not.
     
  6. getLocation().getY() or getLocation().getBlockY() returns the y coordinate on the feets position of the player.
    [​IMG]
     
  7. Offline

    IconByte

    Oh, okay. :) But what is then e.getClickedBlock().getLocation().getBlockY() coords...?

    //EDIT: Why the if statement is returning always else? I did some debugging too and it should work....

    http://i.imgur.com/esOTSPO.png
     
    Last edited: Feb 21, 2015
  8. getClickedBlock() returns a block. and block.getLocation() returns the location of the block (Exact spot where the block is).
    Example: block.getBlockY() + 1 would be the y coordinate above the block
     
  9. Offline

    IconByte

    Ah, I see.. I edited my last post just a moment ago, can you take a look at this? Why it is not working?
     
  10. locs are not the same as the others on World2.
    show me the config
     
  11. Offline

    IconByte

    Code:
    Teleporters:
      Teleport1:
        Pos1:
          World: World
          X: -341
          Y: 79
          Z: 244
        Pos2:
          World: World
          X: -339
          Y: 80
          Z: 248
    World is player's world in picture btw
     
Thread Status:
Not open for further replies.

Share This Page