How can if a block under a player is water change it to ice?

Discussion in 'Plugin Development' started by AshleyBae, Jul 26, 2015.

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

    AshleyBae

    I want to make a custom plugin for a friend, the idea is when a player walks over water, the water freezes but I get an error, please read and help me!
    I seem to get an error using this code:

    Code:
        public void changeBlocks() {
              for ( Player player : Bukkit.getOnlinePlayers()) {
                  String playerName = player.getName();
                  if (WaterFreezeUsers.contains(playerName)) {
                    boolean isActive = WaterFreezeUsers.getPlayer(playerName);
                    if (isActive) {
                        Location loc = player.getLocation();
                        loc.add(0, -1, 0);
                        Block block = loc.getBlock();
                        block.setType(Material.ICE);
                    }
                  }
              }
            }
    As seen here the getPlayer(playerName) has an error and I do not know how to solve it, please help :p
    Also if you could tell me how to change the block to ice IF the block beneath is water please say so too!

    PD: Me nub at making plugins XD
     
  2. Offline

    Monollyth

    You can use a PlayerMoveEvent to check the block that the player is currently on.


    Code:
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
      
            Player p = e.getPlayer();
      
            if(p.getLocation().getBlock().getRelative(BlockFace.DOWN, 1).getType().equals(Material.WATER) || 
            p.getLocation().getBlock().getRelative(BlockFace.DOWN, 1).getType().equals(Material.STATIONARY_WATER)){
          
                p.getLocation().getBlock().setType(Material.PACKED_ICE);
          
            }
        }
     
    Last edited: Jul 26, 2015
  3. Offline

    SuperSniper

    @EventHandler
    public void walkWater(final PlayerMoveEvent e) {
    Player p = e.getPlayer();
    final Location loc = p.getLocation();
    loc.setY(loc.getY() - 1);
    loc.setX(loc.getX());
    loc.setZ(loc.getZ());
    final Material b = loc.getBlock().getType();
    if (b == Material.WATER || b == Material.STATIONARY_WATER) {
    loc.getBlock().setType(Material.PACKED_ICE);
    }
     
Thread Status:
Not open for further replies.

Share This Page