teleporting help

Discussion in 'Plugin Development' started by DracinisScripting, Feb 15, 2013.

Thread Status:
Not open for further replies.
  1. need some help with teleporting
    the problem is i keep getting teleported and i can't get out of the loop :s
    code:
    Code:
        @EventHandler
        public void OnPlayerMove (PlayerMoveEvent event ) {
            Player player = event.getPlayer();
            Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
     
           
            //int blockid = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "BlockId");
            int x1 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "X");
            int y1 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "Y");
            int z1 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "Z");
           
            Block block1 = new Location(player.getWorld(), x1, y1, z1).getBlock();
            Location loc1 = block1.getLocation();
           
            int x2 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate2" + "." + "X");
            int y2 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate2" + "." + "Y");
            int z2 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate2" + "." + "Z");
           
            Block block2 = new Location(player.getWorld(), x2, y2, z2).getBlock();
            Location loc2 = block2.getLocation();
           
            //teleporting locations
            //location 1
            int xlocation1 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "X");
            int ylocation1 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "Y") + 1;
            int zlocation1 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate1" + "." + "Z");
            Location location1 = new Location(player.getWorld(), xlocation1, ylocation1, zlocation1);
            //location 2
            int xlocation2 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate2" + "." + "X");
            int ylocation2 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate2" + "." + "Y") + 1;
            int zlocation2 = this.GatesConfig.getInt("Gates"+ "." + block.getType() + "." + "Gate2" + "." + "Z");
            Location location2 = new Location(player.getWorld(), xlocation2, ylocation2, zlocation2);
           
            if(block.equals(block1)) {
                player.teleport(location2);
            }
            if(block.equals(block2)) {
                player.teleport(location1);
     
            }
     
  2. Offline

    mb01

    What are you trying to achieve?
     
  3. when people stands on a block like diamond they get teleported to a other block diamond that is set in the config sort of portals but then for my plugin

    but i stay teleporting between the 2 blocks because i can't get of the blocks
     
  4. Offline

    ZeusAllMighty11

    I'd use a scheduler if I were you, this is intensive as heck
     
  5. then it gonna loop trough the scheduler ?
     
  6. Offline

    ZeusAllMighty11

    Every X seconds, check player's locations and get block below. Every 3 seconds works fine for me with 100 players
     
  7. i have now that code i think i'm whrong :(
    can you look at it
    and it is gonna take 3 seconds before the player gets teleported?


    Code:
            if(block.equals(block1)) {
                taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                 
                    int seconds = 0;
                    public void run() {
                        if(seconds == 1) {
                            player.teleport(location2);
                            getServer().getScheduler().cancelTask(taskID);
                        }
                        if(seconds > 1) {
                            getServer().getScheduler().cancelAllTasks();
                            seconds = 0;
                        }
                        seconds ++;
                    }
                }, 0, 20);
            }
            if(block.equals(block2)) {
                taskID2 = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                 
                    int seconds = 0;
                    public void run() {
                        if(seconds == 1) {
                            player.teleport(location2);
                            getServer().getScheduler().cancelTask(taskID2);
                        }
                        if(seconds > 1) {
                            getServer().getScheduler().cancelAllTasks();
                            seconds = 0;
                        }
                        seconds++;
                    }
                }, 0, 20);
    @ZeusAllMighty11
    can you help me,?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page