Solved Sign Coding > Help Making Buy Signs with vault

Discussion in 'Plugin Development' started by VinexAx789, Jun 20, 2015.

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

    VinexAx789

    My problem is when they click the sign it doesn't do anything.

    Code:

    Code:
          @EventHandler
          public void onSignChange(SignChangeEvent e){
            if (!e.getPlayer().hasPermission("RektSnD.signcreate")) {
              e.getPlayer().sendMessage(
                "§cYou do not have permissions to create this sign");
            }
            if ((e.getLine(0).equalsIgnoreCase("[Enderpearls]")) &&
              (e.getPlayer().hasPermission("RektSnD.signcreate")))
            {
              e.setLine(0, "§4§l[Buy]");
              e.setLine(1, "§9§lEnderpearls");
              e.setLine(2, "§a§l6");
              e.setLine(3, "§c§lCoins: 2");
            }
          }
       
         @EventHandler
          public void onPlayerBuySign(PlayerInteractEvent e){
             if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                  return;
                }
                if ((e.getClickedBlock().getState() instanceof Sign))
                {
                  Sign s = (Sign) e.getClickedBlock().getState();
                  Player p = e.getPlayer();
                  PlayerInventory myInv = p.getInventory();
                  if (s.getLine(1).equalsIgnoreCase("[Enderpearls]")){
                  } else if(e.getClickedBlock().equals(Material.SIGN)) {
                      EconomyResponse r = econ1.withdrawPlayer(
                                p.getName(), 2);
                      if (r.transactionSuccess()) {
                            p.sendMessage(ChatColor.GREEN
                                    + "§a§lHey! Thanks for buying §4§l[- 2 Coins§4§l] ");
                    myInv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 6) });
                     
                  }
                  {
                    p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
                    p.updateInventory();
                  }
                }
              }
            }
    I've registered my events already.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    SuperSniper

    Your problem is Line 27:
    if(s.getLine(1).equalsIgnoreCase("[Enderpearls]")){

    in the sign change, the 2nd line has
    §9§lEnderpearls

    not
    [Enderpearls]


    Change [Enderpearls]
    to §9§lEnderpearls
     
  3. Offline

    VinexAx789

    @SuperSniper Not working:

    Code:

    Code:
         @EventHandler
         public void onSignChange(SignChangeEvent e){
           if (!e.getPlayer().hasPermission("RektSnD.signcreate")) {
             e.getPlayer().sendMessage(
               "§cYou do not have permissions to create this sign");
           }
           if ((e.getLine(0).equalsIgnoreCase("[Enderpearls]")) &&
             (e.getPlayer().hasPermission("RektSnD.signcreate")))
           {
             e.setLine(0, "§9§lEnderpearls");
             e.setLine(1, "§a§l6");
             e.setLine(2, "§c§lCoins: 2");
           }
         }
     
        @EventHandler
         public void onPlayerBuySign(PlayerInteractEvent e){
            if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                 return;
               }
               if ((e.getClickedBlock().getState() instanceof Sign))
               {
                 Sign s = (Sign) e.getClickedBlock().getState();
                 Player p = e.getPlayer();
                 PlayerInventory myInv = p.getInventory();
                 if (ChatColor.stripColor(s.getLine(0)).equalsIgnoreCase("Enderpearls")) {
                 } else if(e.getClickedBlock().equals(Material.SIGN)) {
                     EconomyResponse r = econ1.withdrawPlayer(
                               p.getName(), 2);
                     if (r.transactionSuccess()) {
                           p.sendMessage(ChatColor.GREEN
                                   + "§a§lHey! Thanks for buying §4§l[- 2 Coins§4§l] ");
                   myInv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 6) });
                   
                 }
                 {
                   p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
                   p.updateInventory();
                 }
               }
             }
           }
     
  4. Offline

    SuperSniper

    @VinexAx789
    You only put "EnderPearls" you need to put the whole thing

    §9§lEnderpearls
     
  5. Offline

    VinexAx789

    @SuperSniper

    No I don't this is why I'm using the
    Code:
    if (ChatColor.stripColor(s.getLine(0)).equalsIgnoreCase("Enderpearls")) {
    Method.

    @SuperSniper I'll try it.

    Still doesn't work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  6. Offline

    Reynergodoy

    thats because you did else if '-'
    you need to use || or && to "add more arguments"
    like: if ((player1.contais(p.getName()) || (player2.contains(p.getName()) {
    //do something
    }
    (correct)

    in your code is:
    like: if ((player1.contais(p.getName()) }else if{ (player2.contains(p.getName()) {
    //do something
    }
    }
    (wrong)
     
  7. Offline

    VinexAx789

    @Reynergodoy

    New code:
    Doesn't Work.

    Code:
         @EventHandler
         public void onSignChange(SignChangeEvent e){
           if (!e.getPlayer().hasPermission("RektSnD.signcreate")) {
             e.getPlayer().sendMessage(
               "§cYou do not have permissions to create this sign");
           }
           if ((e.getLine(0).equalsIgnoreCase("[Enderpearls]")) &&
             (e.getPlayer().hasPermission("RektSnD.signcreate")))
           {
             e.setLine(0, "§9§lEnderpearls");
             e.setLine(1, "§a§l6");
             e.setLine(2, "§c§lCoins: 2");
           }
         }
     
        @EventHandler
         public void onPlayerBuySign(PlayerInteractEvent e){
            if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                 return;
               }
               if ((e.getClickedBlock().getState() instanceof Sign))
               {
                 Sign s = (Sign) e.getClickedBlock().getState();
                 Player p = e.getPlayer();
                 PlayerInventory myInv = p.getInventory();
                 if (ChatColor.stripColor(s.getLine(0)).equalsIgnoreCase("§9§lEnderpearls") || e.getClickedBlock().equals(Material.SIGN)) {
                     EconomyResponse r = econ1.withdrawPlayer(
                               p.getName(), 2);
                     if(r.transactionSuccess()) {
                           p.sendMessage(ChatColor.GREEN
                                   + "§a§lHey! Thanks for buying §4§l[- 2 Coins§4§l] ");
                   myInv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 6) });
                   
                 }
                 {
                   p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
                   p.updateInventory();
                 }
               }
             }
           }
        
    Why can't this work lol
     
  8. Offline

    boysnnoco

    Your Sign Code (When you place the sign)
    Code:
    e.setLine(0, "§4§l[Buy]");
    e.setLine(1, "§9§lEnderpearls")  ;
    e.setLine(2, "§a§l6") ;      
    e.setLine(3, "§c§lCoins: 2");
    What your checking for.. Your checking line zero (first line) but you set your first line as [Buy] not Enderpearls. change .getLine(0) to getLine(1).
    Code:
    ChatColor.stripColor(s.getLine(0)).equalsIgnoreCase("§9§lEnderpearls") 
    If that doesn't work tag me with your new code and i'll give it another look.
     
  9. Offline

    VinexAx789

    @boysnnoco

    New Code:

    Doesn't Work

    Code:
    @EventHandler
         public void onSignChange(SignChangeEvent e){
           if (!e.getPlayer().hasPermission("RektSnD.signcreate")) {
             e.getPlayer().sendMessage(
               "§cYou do not have permissions to create this sign");
           }
           if ((e.getLine(0).equalsIgnoreCase("[Enderpearls]")) &&
             (e.getPlayer().hasPermission("RektSnD.signcreate")))
           {
               e.setLine(0, "§4§l[Buy]");
               e.setLine(1, "§9§lEnderpearls")  ;
               e.setLine(2, "§a§l6") ;     
               e.setLine(3, "§c§lCoins: 2");
           }
         }
     
        @EventHandler
         public void onPlayerBuySign(PlayerInteractEvent e){
            if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                 return;
               }
               if ((e.getClickedBlock().getState() instanceof Sign))
               {
                 Sign s = (Sign) e.getClickedBlock().getState();
                 Player p = e.getPlayer();
                 PlayerInventory myInv = p.getInventory();
                 if (ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("§9§lEnderpearls") || e.getClickedBlock().equals(Material.SIGN)) {
                     EconomyResponse r = econ1.withdrawPlayer(
                               p.getName(), 2);
                     if(r.transactionSuccess()) {
                           p.sendMessage(ChatColor.GREEN
                                   + "§a§lHey! Thanks for buying §4§l[- 2 Coins§4§l] ");
                   myInv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 6) });
                   
                 }
                 {
                   p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
                   p.updateInventory();
                 }
               }
             }
           }
        
    @boysnnoco @Reynergodoy @SuperSniper

    New Code Still Not Wanting To Work....

    Code:
        //This Part Works
         @EventHandler
         public void onSignChange(SignChangeEvent e){
           if (!e.getPlayer().hasPermission("RektSnD.signcreate")) {
             e.getPlayer().sendMessage(
               "§cYou do not have permissions to create this sign");
             return;
           }
           if ((e.getLine(0).equalsIgnoreCase("[Enderpearls]")) &&
             (e.getPlayer().hasPermission("RektSnD.signcreate")))
           {
               e.setLine(0, "§4§l[Buy]");
               e.setLine(1, "§9§lEnderpearls");
               e.setLine(2, "§a§lAmount: 6");
               e.setLine(3, "§c§lCoins: 2");
           }
         }
     
        
         //This part isn't doing crap.
        @EventHandler
         public void onPlayerBuySign(PlayerInteractEvent e){
            if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                 return;
               }
               if ((e.getClickedBlock().getState() instanceof Sign))
               {
                 Sign s = (Sign) e.getClickedBlock().getState();
                 Player p = e.getPlayer();
                 PlayerInventory myInv = p.getInventory();
                 if (ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("§9§lEnderpearls") && e.getClickedBlock().equals(Material.SIGN)) {
                     System.out.println("Sign has been clicked");
                     EconomyResponse r = econ1.withdrawPlayer(
                               p.getName(), 2);
                     if(r.transactionSuccess()) {
                           p.sendMessage(ChatColor.GREEN
                                   + "§a§lHey! Thanks for buying §4§l[- 2 Coins§4§l] ");
                   myInv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 6) });
                   
                 }
                 {
                   p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
                   p.updateInventory();
                 }
               }
             }
           }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  10. Offline

    Irantwomiles

    @VinexAx789 What doesn't work? Have you tried setting up debug points? Or just simple messages to see how far the code goes?
     
  11. Offline

    SuperOriginal

    Well you're stripping the colors and then trying to add color codes
     
  12. Offline

    VinexAx789

    @Irantwomiles @SuperOriginal the strip method makes it so I don't need to put colors just the text. And yes I've debug alot and nothing.
     
  13. Offline

    Boomer

    ..wrong post. removed.

    So what is the "Doesn't work" part?|

    Does it print the message about the sign being clicked? does it not reach there?
    Are you only looking at the player money balance to judge success or fail? Are there any big spammy bursts of errors in the log while interacting with the sign, complaining about the vault components, etc...

    A bit of a hint other than "still doesn't work" is required

    Edit: Added
    Actually...
    Code:
    if (ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("§9§lEnderpearls") && e.getClickedBlock().equals(Material.SIGN)
    
    Translates as
    if ( stringstrippedofcolor.equalsignorecase(stringwithcolor) && othercondition )
     
    Last edited: Jun 21, 2015
  14. Offline

    VinexAx789

    @Boomer There are no error, The debug messages aren't printing to the console, I've look at my balance nothing is happening no messages I'm not getting any items at all. It just doesn't work you guys try the code and see if it works.
     
  15. Offline

    Boomer

    so, other than my explanation , throw a debug statement higher up - ie AS SOON as the event is fired , to see if it is entering the event. And then right after that first if -block that returns, before it checks the block type... and just before it checks the strings to match... This is how you solve 'it isn't working, nothing is happening' problems - throw all the assumptions out the window - is the event being triggered yes or no, sometimes, you may surprise yourself. Does this code after this IF test ever get reached yes or no, you may be surprised by a small typo in a check that always terminates, etc..

    Also to follow "You guys use the code and see" means nothing.
    Unless you provide EVERY LINE of your entire program to make sure we have everything the same, its a lot of work to piece together things to demonstrate only a few blocks of code out of context, esp if somewhere else your code had a flaw - but, thats not the case here anyways.
    Its the logic of your string comparison that i outlined above
     
  16. Offline

    JBoss925

    After a bit of testing, your check is wrong. Using ChatColor#stripColor(String s) changes it from something like "§cHello" to "Hello"

    thus, using
    Code:
    if(ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("§9§lEnderpearls"))
    won't work because it can't equal something with color if the color has been stripped. Instead, try changing it to
    Code:
    if(ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("Enderpearls"))
     
  17. Offline

    SuperOriginal

    Exactly, so why were you still trying to check for colors?
     
  18. Offline

    VinexAx789

    This code has been updated:

    Still doing the samethings

    Code:
    //This Part Works
         @EventHandler
         public void onSignChange(SignChangeEvent e){
           if (!e.getPlayer().hasPermission("RektSnD.signcreate")) {
             e.getPlayer().sendMessage(
               "§cYou do not have permissions to create this sign");
             return;
           }
           if ((e.getLine(0).equalsIgnoreCase("[Enderpearls]")) &&
             (e.getPlayer().hasPermission("RektSnD.signcreate")))
           {
               e.setLine(0, "§4§l[Buy]");
               e.setLine(1, "§9§lEnderpearls");
               e.setLine(2, "§a§lAmount: 6");
               e.setLine(3, "§c§lCoins: 2");
           }
         }
    
       
         //This part isn't doing crap.
        @EventHandler
         public void onPlayerBuySign(PlayerInteractEvent e){
            if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
                 return;
               }
               if ((e.getClickedBlock().getState() instanceof Sign))
               {
                 Sign s = (Sign) e.getClickedBlock().getState();
                 Player p = e.getPlayer();
                 PlayerInventory myInv = p.getInventory();
                 if((e.getClickedBlock().getState() instanceof Sign))
    if(ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("Enderpearls")[B]&& [/B]e.getClickedBlock().equals(Material.SIGN)){
                     {
                     EconomyResponse r = econ1.withdrawPlayer(
                             p.getName(), 2);
                   if(r.transactionSuccess()) {
                         p.sendMessage(ChatColor.GREEN
                                 + "§a§lHey! Thanks for buying §4§l[- 2 Coins§4§l] ");
                 myInv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 6) });
                   p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
                   p.updateInventory();
                 }
               }
             }
            }
           }
    @SuperOriginal @JBoss925 @Boomer
     
    Last edited: Jun 21, 2015
  19. Offline

    Boomer

    e.getClickedBlock().equals(Material.SIGN)

    A block will never equal a blocktype material, plus you already know its a sign from the previous line
     
  20. Offline

    VinexAx789

    @Boomer So then remove that and just leave it e.getClickedBlock(); ?
     
  21. Offline

    Boomer

    uh.. what would e.getClickedBlock(); all by itself do? It woudl throw an error in the system, cause thats not a true/false condition.

    Get rid of everything including and after the && - you dont need that cause you already are only executing this test IF the block is a sign, so checking if you can read the second line of the sign AND it is also a sign is just redundant and always true...
     
  22. Offline

    VinexAx789

    Here's my code from another plugin of mine that works 100%

    Code:

    Code:
    @EventHandler
      public void onSignChange(SignChangeEvent e)
      {
        if (!e.getPlayer().hasPermission("ptokens.create")) {
          e.getPlayer().sendMessage(
            "§cYou do not have permissions to create this sign");
        }
        if ((e.getLine(0).equalsIgnoreCase("[PrisonTokens]")) &&
          (e.getLine(1).equalsIgnoreCase("efficiency")) &&
          (e.getLine(2).equalsIgnoreCase("1")) &&
          (e.getPlayer().hasPermission("ptokens.create")))
        {
          e.setLine(0, "§c§lP§4§lTokens");
          e.setLine(1, "§c§lEfficiency");
          e.setLine(2, "§c§lTokens: 1");
        }
      }
     
      @EventHandler
      public void onPlayerInteract(PlayerInteractEvent e)
      {
        if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
          return;
        }
        if ((e.getClickedBlock().getState() instanceof Sign))
        {
          Sign s = (Sign)e.getClickedBlock().getState();
          Player p = e.getPlayer();
          ItemStack myItem = p.getItemInHand();
          int newLevel = myItem.getEnchantmentLevel(Enchantment.DIG_SPEED) + 1;
          if ((myItem.getType().equals(Material.DIAMOND_PICKAXE)) &&
            (p.getInventory().contains(Material.MAGMA_CREAM)) &&
            (s.getLine(1).equalsIgnoreCase("§c§lEfficiency")))
          {
            p.getInventory().removeItem(
              new ItemStack[] { new ItemStack(
              Material.MAGMA_CREAM, 1) });
            p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
            myItem.addUnsafeEnchantment(Enchantment.DIG_SPEED, newLevel);
            e.getPlayer().sendMessage(ChatColor.GREEN + "+1 Efficiency");
            p.updateInventory();
          }
        }
      }
    Now I used it as a frame for the one I'm trying to do now.
     
  23. Offline

    Zombie_Striker

    @VinexAx789
    Why has no one pointed out that he needs to update the block?
    Code:
    [/B]BlockState#update();
     
  24. Offline

    VinexAx789

  25. Offline

    Boomer

    Cause thats so far downstream from his failure to be able to get to the point in code where he wants to get, we didn't notice yet
     
  26. Offline

    xTrollxDudex

    Are you sure you are checking for the right Sign? Like, block.Sign not material.Sign?
     
  27. Offline

    VinexAx789

    @xTrollxDudex I'm doing this:
    Code:
     if((e.getClickedBlock().getState() instanceof Sign))
    if(ChatColor.stripColor(s.getLine(1)).equalsIgnoreCase("Enderpearls") && [/B]e.getClickedBlock().equals(Material.SIGN)){
     
  28. Offline

    xTrollxDudex

    Can I see your imports
     
  29. Offline

    VinexAx789

  30. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page