How can you prevent interacting with chests with Minecraft plugins?

gl
- in Plugins
3

This is my code:

package net. **********. Lobby.listeners;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.material.Bed;
import org.bukkit.material.Chest;
import org.bukkit.material.Door;
import org.bukkit.material.Furnace;

public class InteractListeners implements Listener {

@EventHandler
public void onBlockInteract (PlayerInteractEvent event) {

Player player = event.getPlayer ();

if (! Player.hasPermission ("lobby.interact")) {

if (event.getClickedBlock () instanceof Chest) {

player.sendMessage ("§cYou are not allowed to open chests here!");

event.setCancelled (true);

} else if (event.getClickedBlock () instanceof Bed) {

player.sendMessage ("§cYou are not allowed to sleep here!");

event.setCancelled (true);

} else if (event.getClickedBlock () instanceof Furnace) {

player.sendMessage ("§cYou are not allowed to interact with furnaces here!");

event.setCancelled (true);

} else if (event.getClickedBlock () instanceof Door) {

player.sendMessage ("§cYou are not allowed to open / close doors here!");

event.setCancelled (true);

}

}

}

}

What am I doing wrong?

I have the event with me

PluginManager pluginManager = Bukkit.getPluginManager ();
pluginManager.registerEvents (new InteractListeners (), this);

already registered.

Do I have to import anything else? Or do I have to change something on setCancelled?

za

https://bukkit.org/threads/disable-chest-opening.200593/

an

What would be the difference to his solution?

za

For example, this line is not in the form

if (e.getAction () == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock (). GetType () == Material.CHEST)