I want to code a plugin for a plugin's bug.(ChestShop). When player right click sign(Sign's line 2 is "B Free" or "Free" and line 3 is "Iron_Ingot") cancel event and send message.
public void onPlayerInteract(PlayerInteractEvent e){
Player player = e.getPlayer();
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.LEFT_CLICK_BLOCK) ){
if(e.getClickedBlock().getState() instanceof Sign){
Sign sign = (Sign) e.getClickedBlock().getState();
if(sign.getLine(2).equals("B Free") || sign.getLine(2).equals("Free")){
if(sign.getLine(3).equals("Iron_Ingot"))
e.setCancelled(true);
e.getPlayer().sendMessage("You can not click this sign");
}
}
}
}
I tried this but it didn't work, which part of the code is wrong? What methods can I use?
The class your method onPlayerInteract is in has to implement te interface Listener. You also have to use the EventHandler annotation and register the event in your plugin.
public class PlayerInteract implements Listener {
// priority is when the listener is called.
// LOWEST is called first, then LOW, NORMAL, HIGH, HIGHEST, MONITOR.
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
// ...
}
}
In your onEnable in the Main class (which extends JavaPlugin):
getServer().getPluginManager().registerEvents(new PlayerInteract(),this);