Help with signs

Discussion in 'Plugin Development' started by Axanite, Jan 18, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Axanite

    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.");
                }
            }
        }
     
  2. Offline

    Avery246813579

    rf2minecraft
    Do you not want to be able to place a sign? I am confused on what you are asking for.
     
  3. Offline

    Axanite


    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.
     
  4. Offline

    Avery246813579

    Alright try using this:

    Code:java
    1. @EventHandler
    2. public void onPlayerIntedract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. Block b = event.getClickedBlock();
    6. if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    7. Sign sign = (Sign) b.getState();
    8.  
    9. if(sign.getLine(0).equalsIgnoreCase("[Shop]")){
    10. int amount = Integer.parseInt(sign.getLine(1));
    11. int itemid = Integer.parseInt(sign.getLine(2));
    12. int cost = Integer.parseInt(sign.getLine(3));
    13. if(cost > SettingsManager.getInstance().getPoints(player)) {
    14. event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints}" + ChatColor.RED + " You do not have enough points to buy this item.");
    15. } else {
    16. event.getPlayer().getInventory().addItem(new ItemStack(itemid, amount));
    17. SettingsManager.getInstance().removePoints(player, cost);
    18. event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints} " + ChatColor.RED + cost + " points taken from your balance.");
    19. }
    20. }
    21. }
    22. }
    23. }


    You were making it so that every time someone clicks on a sign, they trigger the event. Try this.
     
  5. Offline

    Axanite


    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. ;/
     
  6. Offline

    Avery246813579

    rf2minecraft
    Did you enable the listener?
    Also did you check over it to see that all the lines are good?
     
  7. Offline

    Axanite

    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. ;/
     
  8. Offline

    Avery246813579

    Try this:

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. player.sendMessage("Works")
    5. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block b = event.getClickedBlock();
    7. if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    8. Sign sign = (Sign) b.getState();
    9.  
    10. if(sign.getLine(0).equalsIgnoreCase("[Shop]")){
    11. int amount = Integer.parseInt(sign.getLine(1));
    12. int itemid = Integer.parseInt(sign.getLine(2));
    13. int cost = Integer.parseInt(sign.getLine(3));
    14. if(cost > SettingsManager.getInstance().getPoints(player)) {
    15. event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints}" + ChatColor.RED + " You do not have enough points to buy this item.");
    16. } else {
    17. event.getPlayer().getInventory().addItem(new ItemStack(itemid, amount));
    18. SettingsManager.getInstance().removePoints(player, cost);
    19. event.getPlayer().sendMessage(ChatColor.DARK_RED + "{KillsPoints} " + ChatColor.RED + cost + " points taken from your balance.");
    20. }
    21. }
    22. }
    23. }
    24. }


    Also have you deleted your other interact event. That could be a problem.
     
  9. Offline

    Axanite


    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.
     
    Last edited by a moderator: Jun 6, 2016
  10. Offline

    Avery246813579

  11. Offline

    Axanite

    Yup, I have over 6000. I try to set the price to a really low price too.
     
  12. Offline

    Avery246813579

Thread Status:
Not open for further replies.

Share This Page