So I'm creating a plugin for somebody who requested one on the forums and basically what I'm stumped on is how to fix this one small problem. When I go to place a sign which involves right-clicking, it makes my playerinteractevent trigger and make it so it doesn't work because its not an instance of sign when I place the sign (obviously). If somebody can help me sort this, it will be helpful! Code: public class PlayerListener implements Listener { @SuppressWarnings("deprecation") @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { Sign s = (Sign) e.getClickedBlock().getState(); if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; if(!(e.getClickedBlock() instanceof Sign)) return; if(!(s.getLine(0).equalsIgnoreCase("[Shop]"))) return; int amount = Integer.parseInt(s.getLine(1)); int itemid = Integer.parseInt(s.getLine(2)); int cost = Integer.parseInt(s.getLine(3)); if(cost > SettingsManager.getInstance().getPoints(e.getPlayer())) { e.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints}" + ChatColor.RED + " You do not have enough points to buy this item."); } else { e.getPlayer().getInventory().addItem(new ItemStack(itemid, amount)); SettingsManager.getInstance().removePoints(e.getPlayer(), cost); e.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints} " + ChatColor.RED + cost + " points taken from your balance."); } } }
Basically I want them to place the sign anywhere without triggering the interact event. This is the part where I am stuck on. I only want it to trigger when they right-click a sign.
Alright try using this: Code:java @EventHandler public void onPlayerIntedract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) { Sign sign = (Sign) b.getState(); if(sign.getLine(0).equalsIgnoreCase("[Shop]")){ int amount = Integer.parseInt(sign.getLine(1)); int itemid = Integer.parseInt(sign.getLine(2)); int cost = Integer.parseInt(sign.getLine(3)); if(cost > SettingsManager.getInstance().getPoints(player)) { event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints}" + ChatColor.RED + " You do not have enough points to buy this item."); } else { event.getPlayer().getInventory().addItem(new ItemStack(itemid, amount)); SettingsManager.getInstance().removePoints(player, cost); event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints} " + ChatColor.RED + cost + " points taken from your balance."); } } } } } You were making it so that every time someone clicks on a sign, they trigger the event. Try this.
Although it has stopped triggering when I right-click anything OTHER THAN a sign, it doesn't do anything when I DO click a sign. ;/
rf2minecraft Did you enable the listener? Also did you check over it to see that all the lines are good?
Yea. I enabled the listener and checked that the lines are good. I even added debug and it seems its not even detecting that I've right-clicked which is very strange. ;/
Try this: Code:java @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); player.sendMessage("Works") if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = event.getClickedBlock(); if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) { Sign sign = (Sign) b.getState(); if(sign.getLine(0).equalsIgnoreCase("[Shop]")){ int amount = Integer.parseInt(sign.getLine(1)); int itemid = Integer.parseInt(sign.getLine(2)); int cost = Integer.parseInt(sign.getLine(3)); if(cost > SettingsManager.getInstance().getPoints(player)) { event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints}" + ChatColor.RED + " You do not have enough points to buy this item."); } else { event.getPlayer().getInventory().addItem(new ItemStack(itemid, amount)); SettingsManager.getInstance().removePoints(player, cost); event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints} " + ChatColor.RED + cost + " points taken from your balance."); } } } } } Also have you deleted your other interact event. That could be a problem.
Yeah I replaced the one in the original post with your one. Seems minecraft is messing up, can't test right now So, it works but it doesnt want to add anything to my inventory nor take points. EDIT by Moderator: merged posts, please use the edit button instead of double posting.