I want to set a sign so that if it is using my plugin it can only be broken by someone with permission. Also I am having a problem with LWC and Essentials showing text when you click a sign. How can I stop this?
To check if they have permission: on the event: Code: if(event.isCancelled(false)) { //checks to see if another plugin did not cancel it, //Do what you want to do }
cman1885 maybe, well change it to: Code: if(event.isCancelled() == false) { //checks to see if another plugin did not cancel it, //Do what you want to do }
uh try this Code: @EventHandler public void onplayerBreakASignYo(BlockBreakEvent event) { if(event.getBlock().getType() == Material.SIGN){ Sign sign = (Sign) event.getBlock(); if(sign.getLine(1).equalsIgnoreCase("Whatever your sign says")) { if(event.getPlayer().hasPermission("permission.node")) { return; } else event.setCancelled(true); event.getPlayer().sendMessage("Yo dude, you don't have permission to mess up this sign."); } }
Code: @EventHandler public void onPlayerInteractWithASignHurrDurr(PlayerInteractEvent event) if(event.isCancelled()) { if(event.getClickedBlock().getType() == Material.SIGN) { //Stuff you want it to do. }
I was trying to think of what to say lol This post has been edited 6 times. It was last edited by SaintMotherfuckingX A moment ago.
No. Why would you check if it's not cancelled. LWC is cancelling the event PlayerInteractEvent due to permissions being on the sign. LWC's mentality: Code: @EventHandler public void onPlayerTouchMyF'inSigns(PlayerInteractEvent event) if(event.getBlockClicked().getType() == Material.SIGN) Sign sign =(Sign) event.getBlockClicked(); if(playerssigns.contains(sign.getLine(1).equalsIgnoreCase(player.getName())) if(playersign.haspermissiontodoanythingwiththesign() == false) event.setCancelled(); You need to say, "Even though this scumbag plugin is cancelling the event, I want you to do it anyways." With his code, basically java is going, I really don't know what is going on, but something is stopping me from doing something. Think of it as an invisible barrier, that the plugin can't get around, and by adding event.isCancelled() it's saying, oh, you're being cancelled, oh well, do it anyways because my plugin is more important than LWC.
Just wondering buy wouldnt event.setcancel also stop my plugin? and would I need to use LWC permissions such as Check for the LWC permissions and if it exists then do Event Cancel.
Because it returns a true or false statement. setCancelled() can only be a true or false statement. Basically, you're seeing if it's cancelled, if another plugin is cancelling it, just do it anyways. Think of the setCancelled() as coming to a fork in the road. And you can go one way, or you can go the other, and by not seeing if the event is cancelled, you basically don't even know if you're at the fork in the road, you're just walking straight into the sign that's telling you to go left or right and you're not going any further. You can also set Priority.HIGHEST on your eventhandlers.