Solved Removing client side vines(Wall Climbing)

Discussion in 'Plugin Development' started by Mr. Sandwich, May 14, 2016.

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

    Mr. Sandwich

    Code:
                  @EventHandler
                    public void onPlayerMove(PlayerMoveEvent ev) {
                    
                    Block b1 = ev.getPlayer().getLocation().getBlock();
                    
                    if (b1.getType() != Material.AIR)
                    return;
                    
                    Block b2 = b1.getRelative(BlockFace.UP);
                    Location l = ev.getPlayer().getLocation();
                    if (b1.getRelative(BlockFace.NORTH).getType().isBlock()
                    || b1.getRelative(BlockFace.EAST).getType().isBlock()
                    || b1.getRelative(BlockFace.SOUTH).getType().isBlock()
                    || b1.getRelative(BlockFace.WEST).getType().isBlock()) {
                    double y = l.getY();
                    ev.getPlayer().sendBlockChange(b1.getLocation(), Material.VINE, (byte) 0);
                    if (y % 1 > .40 && b2.getType() == Material.AIR) {
                    ev.getPlayer().sendBlockChange(b2.getLocation(), Material.VINE, (byte) 0);
                    }
                    }
                    }
    
    So this code basically is for wall climbing and its working and all but the vines stay there, I know only the player that spawns them can see or use them and if he relogs then they will be gone but I dont want them to stay after he finishes wall climbing, ideas or improvements to the code?
     
  2. Offline

    Mr. Sandwich

    I read it and the solution code they found is the one I am having problems with... I need a way to remove the vines not to wall climb

    EDIT: Also to add a way to check if the player is even trying to wall climb I dont want the vines to spawn every time he moves.
     
  3. The 4. post in the thread I linked you.

    And maybe check if they are colliding horizontally everytime they move..
     
  4. Offline

    Mr. Sandwich

    I didnt understand what he meant
     
  5. ..How can you not understand this :D
    You make a list and every time you send a vine block change to a player, you save the player, position of the block and the block which was there before in a list so when you set another block to a vine for the same player, you can revert the last vine block to the block that was there before
    (You need to save the block so things you can go through like torches don't get destroyed)

    And I don't think I can explain this much better than the other guy. Maybe tell me what part it was which you don't understand.
     
  6. Offline

    Mr. Sandwich

    I dont understand how to save this block's location
     
    Last edited: May 14, 2016
  7. Make a list/map and maybe a wrapper class for this stuff
     
  8. Offline

    Mr. Sandwich

    Yeah but how do I get this blocks location?

    EDIT: Nevermind I think I know how

    Well I tried but I dont want how to continue form here, I want it to save for a couple of second and then remove it:
    Code:
        private HashMap<Location, Integer> savedBlocks;
    
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            savedBlocks = new HashMap<Location, Integer>();
              Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable() {
                    public void run() {
                        for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                          if (savedBlocks.containsKey(?) {
                                savedBlocks.put(?, savedBlocks.get(?) - 1);
                                if (savedBlocks.get(?) < 1) {
                                    savedBlocks.remove(?);//Notice the question marks, I dont know what to put there, I want it to be a list of all locations I have been at in the last few seconds but I am stuck
                                }
                            }
                            }
                        }
                    }
                }, 0, 10);
    
        @EventHandler(priority = EventPriority.HIGH)
        public void onPlayerMove(PlayerMoveEvent e) {
            if (e.getPlayer().isSprinting()) {
                savedBlocks.put(e.getPlayer().getLocation(), 5);
            }
        }
    
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 15, 2016
  9. Offline

    Mr. Sandwich

    well its been a day since I posted this ^^^ so bump...
     
  10. Online

    timtower Administrator Administrator Moderator

    @Mr. Sandwich Save the vines in a radius, if the player gets further away: remove vines.
     
  11. Offline

    Mr. Sandwich

    How do I save the vines locations in a radius?
     
  12. Online

    timtower Administrator Administrator Moderator

    Set of locations? Probably in a hashmap so it is per player.
     
  13. Offline

    Mr. Sandwich

    I tried to save locations this is my main problems and I couldnt figure it out here's the code again:
    Code:
                   private HashMap<Location, Integer> savedBlocks;
                   
                   public void onEnable() {
                       Bukkit.getServer().getPluginManager().registerEvents(this, this);
                       savedBlocks = new HashMap<Location, Integer>();
                         Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable() {
                               public void run() {
                                   for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                                     if (savedBlocks.containsKey(?) {
                                           savedBlocks.put(?, savedBlocks.get(?) - 1);
                                           if (savedBlocks.get(?) < 1) {
                                               savedBlocks.remove(?);//Notice the question marks, I dont know what to put there, I want it to be a list of all locations I have been at in the last few seconds but I am stuck
                                           }
                                       }
                                       }
                                   }
                               }
                           }, 0, 10);
               
                   @EventHandler(priority = EventPriority.HIGH)
                   public void onPlayerMove(PlayerMoveEvent e) {
                       if (e.getPlayer().isSprinting()) {
                           savedBlocks.put(e.getPlayer().getLocation(), 5);
                       }
                   }
    
     
  14. Online

    timtower Administrator Administrator Moderator

    @Mr. Sandwich You need to save all blocks in the area, not the player location.
     
  15. Offline

    Mr. Sandwich

    Okay I will try that but can you still tell me how to save the locations the player was at in the last few seconds (or just every single location he was and then I will just remove the old ones)? I need it for another problem I am having
     
  16. Online

    timtower Administrator Administrator Moderator

    Save them with a timestamp, or a timestamp with a location.
     
  17. Offline

    Mr. Sandwich

    Okay also how so I did the radius and all but now how do I search for the vines that exist only in the player's game? because they arent really there
     
  18. Online

    timtower Administrator Administrator Moderator

    @Mr. Sandwich You just use sendBlockChange with the original blocks on the stored blocks.
    And radius = location+range
     
  19. Offline

    Mr. Sandwich

    sendBlockChange wants a location not a list of them so I dont know how to have radius and sendBlockChange together
    Code:
        private static List<Location> getBlocksInRadius(Location l, int radius) {
            World w = l.getWorld();
            int xCoord = (int) l.getX();
            int zCoord = (int) l.getZ();
            int YCoord = (int) l.getY();
      
            List<Location> tempList = new ArrayList<Location>();
            for (int x = -radius; x <= radius; x++)
            {
            for (int z = -radius; z <= radius; z++)
            {
            for (int y = -radius; y <= radius; y++)
            {
            tempList.add(new Location(w, xCoord + x, YCoord + y, zCoord + z));
            }
            }
            }
            return tempList;
        }
    
        @EventHandler(priority = EventPriority.HIGH)
        public void onPlayerMove(PlayerMoveEvent e) {
            e.getPlayer().sendBlockChange(getRadius(e.getPlayer().getLocation(), 3), Material.AIR, (byte) 0);
        }
    
    EDIT: And yes I know this will change every block in the radius to air
     
  20. Online

    timtower Administrator Administrator Moderator

  21. Offline

    Mr. Sandwich

    I will try that

    EDIT: Ok I got it to work but is there a way to speed up the climbing? because climbing on vines takes forever
     
    Last edited: May 16, 2016
  22. Online

    timtower Administrator Administrator Moderator

    @Mr. Sandwich There probably is a way, but I don't know a solid one.
     
Thread Status:
Not open for further replies.

Share This Page