Player move one red sand

Discussion in 'Plugin Development' started by samsung0104, Nov 4, 2021.

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

    samsung0104

    Hi! Iam try to learn minecraft plugin writing. I need help, becouse i dont find any working code.
    If player walk sand , kill player and write chat, you are death.
    Somebody help me code?
     
  2. Offline

    Kars

    YouTube tutorials are the best place to start.
     
  3. Offline

    pixelrider2000

    Since what you want to do is extremely simple I would advice you to start watching some basic tutorials first (e.g. on YouTube), before you ask on a forum. But regardless, you need to make a PlayerMoveEvent and check if the block below the player is sand. If it is sand, then you kill the player and send a chat message. Like I said it's extremely simple, so please learn the basics.

    It would look like this:

    public void onPlayerMove(PlayerMoveEvent e) {
    Player p = e#getPlayer()
    Block block = p#getLocation()#getBlock()#getRelative(BlockFace#DOWN)

    if(block#getType() == Material#SAND) {
    p#setHealth(0)
    p#sendMessage(ChatColor#RED + "!Please don't just blindly copy and paste this. Make sure you understand the code first!")
    }
    }
     
  4. Offline

    samsung0104

    Thanks, i understand, why you type this code. Iam learning c# and php. i changed "#" to "." , and after the line get ";".
    I try, but nothing happend.
    I post pastebin, and help me please whats worng?
    https://pastebin.com/rC3b1s0r
     
  5. Offline

    pixelrider2000

    The code I sent you was a listener, so you need to put "@EventHandler" above the function like this:

    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e) {...

    And you also need to register the listener by putting this code in "onEnable()":

    PluginManager pM = Bukkit.getPluginManager();
    pM.registerEvents(this, this);

    You can also put "System.out.println("Test")" in your onPlayerMove, that way you can check if the code inside the method is being ran.

    Let me know if that helps :)
     
  6. Offline

    samsung0104

    Tankh you for helping me! Its fine working!
     
Thread Status:
Not open for further replies.

Share This Page