I want to kill a player if he went higher then 24

2019-08-15 01:49发布

I want to make a Spigot Plugin that kills a Player if he is over 24 Blocks. I already made a code but it doesn't work Here is the full code, I don't need to register a new class because I wrote the event in the main class

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 MainFFA extends JavaPlugin implements Listener{

@Override
public void onEnable() {
    getServer().getConsoleSender().sendMessage("_____________START_____________");
    getServer().getConsoleSender().sendMessage("_____________START_____________");
    getServer().getConsoleSender().sendMessage("_____________START_____________");
    getServer().getConsoleSender().sendMessage("_____________START_____________");
    super.onEnable();
}

@Override
public void onDisable() {
    getServer().getConsoleSender().sendMessage("_________STOP_________-");
    super.onDisable();
}
@EventHandler
public void onPlayerDead(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    if(p.getLocation().getBlockY() > 80) {
        p.setHealth(0);
    }
    else {
        p.sendMessage("Wenn du das siehst dann bist du unter 80 blöcken hoch");
    }

}
}

1条回答
老娘就宠你
2楼-- · 2019-08-15 02:55

To solve this issue, you must remember to register your listeners, or else bukkit will never see them.

public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
}

Add that line to the onEnable method, and you should be fine

查看更多
登录 后发表回答