If player walks over block contains with xyz in configuration.

Discussion in 'Plugin Development' started by Plukkies, Feb 14, 2015.

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

    Plukkies

    Hello Bukkit persons,

    I have now this code but it still not working ;(
    Code:
    package me.Plukkies.Blockset;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            int x1 = p.getLocation().getBlockX();
            int y1 = p.getLocation().getBlockY();
            int z1 = p.getLocation().getBlockZ();
            String x1s = Integer.toString(x1);
            String y1s = Integer.toString(y1);
            String z1s = Integer.toString(z1);
            if (getConfig().getString("block."+x1s+" "+y1s+" "+z1s) == "block."+x1s+" "+y1s+" "+z1s){
                p.sendMessage(ChatColor.RED + "Hello");
               
            }
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("setteleportblock")){
                Player p = (Player)sender;
                int x = p.getLocation().getBlockX();
                int y = p.getLocation().getBlockY();
                int z = p.getLocation().getBlockZ();
                String x1s1 = Integer.toString(x);
                String y1s1 = Integer.toString(y);
                String z1s1 = Integer.toString(z);
                {
                            getConfig().set("block", x1s1 + " " + y1s1 + " " + z1s1);
                            saveConfig();
                            p.sendMessage(ChatColor.RED + "Block set!");
                    }
                }
            return false;
        }
    }
    
    
    Who can fix this?
     
  2. Offline

    Hex_27

    @Plukkies technically, the block the player is at is one block DOWN, not at his legs. The block you're getting isn't the right block. First, get the player's location's block, then get the block below it by block.getRelative(0, -1, 0); This is the block the player is walking on. TAKE NOTE, this may not work on slabs/stairs and so on
     
  3. Offline

    Plukkies

    How find where the player is pointing at?
     
  4. Offline

    Plukkies

    It's fixed
     
  5. Offline

    EnveRuleZZ

Thread Status:
Not open for further replies.

Share This Page