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?
https://bukkit.org/threads/disable-chest-opening.200593/
What would be the difference to his solution?
For example, this line is not in the form
if (e.getAction () == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock (). GetType () == Material.CHEST)