简体   繁体   中英

Is there something wrong in my Minecraft plugin?

This code doesn't work. Wonder, where I went wrong.

public class Basic extends JavaPlugin {

    @EventHandler
    public void onPlayerJoin (PlayerJoinEvent evt) {
        Player player = evt.getPlayer();
        PlayerInventory inventory = player.getInventory();
        ItemStack itemstack = new ItemStack(Material.STICK,1);

        if (player.hasPermission("lobby.lobby")) {
            player.setHealth(0.5);
            inventory.setItem(1,itemstack);
            inventory.addItem(itemstack);
            player.setWalkSpeed(3);
            player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,9999, 1));
            player.hidePlayer(player);
        }
    }
}

When I start my server, there are no errors in console. Everything is fine, but I don't get any items, no speed, no effects.

This could be any number of issues, and this is a poor question, but I would recommend adding a couple lines that print debug messages to the console, that way you know what parts of your code have run if any.

Most likely you do not have the permission node lobby.lobby , being an OP does not actually give you permission nodes. Get a permissions plugin such as Luck Perms and add the permission node to the default group or to yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM