Please Help - Sign Interacting

Discussion in 'Plugin Development' started by amazed2025, Oct 27, 2013.

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

    amazed2025

    So,
    I've got a very basic code for signs.
    If a sign were to say [aurakits] and under it [tank] (Caps doesn't matter) I'm trying to make it so it'd give the player a specific set of items.
    Code:
    package net.theaura.AuraKits.Events;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.SignChangeEvent;
     
    public class SignChange {
       
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
            if(e.getLine(0).equalsIgnoreCase("[aurakit]")) {
                if(e.getLine(1).equalsIgnoreCase("tank")) {
                   
                }
            }
        }
       
    }
    
     
  2. Offline

    Jake6177

    Use ItemStacks to give them items?...
     
    JPG2000 likes this.
  3. Offline

    JPG2000

    amazed2025 Check if line1 is tank (like you did) then give player items.

    If by "specific" you mean "custom" then your on your own.
     
  4. Offline

    Jordymt

    Why SignChangeEvent? You want to check if the player interacts with the sign right? Then you should use PlayerInteractEvent. Need more help? Send me a PM!
     
  5. Offline

    TheUpdater

    this is how to set sign lines =)
    PHP:
        @EventHandler
        
    public void GAME1(SignChangeEvent sign){
            
    Player p sign.getPlayer();
            if(
    sign.getLine(0).equalsIgnoreCase("gm1")){
                
    sign.setLine(0ChatColor.GOLD+"");
                
    sign.setLine(1ChatColor.BOLD+"");
                
    p.sendMessage("");
     
            }
        }
    when click it
    PHP:
        @EventHandler
        
    public void clicksign(PlayerInteractEvent e) {
            
    Player p e.getPlayer();
            if (
    e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    
    Block b e.getClickedBlock();
                    if (
    b.getType() == Material.SIGN_POST|| b.getType() == Material.WALL_SIGN) {
                        
    Sign sign = (Signb.getState();
                        if (
    sign.getLine(0).equalsIgnoreCase(ChatColor.BOLD "")) {
                            if (
    sign.getLine(1).equalsIgnoreCase(ChatColor.BOLD+"")) {
                                
    p.sendMessage(ChatColor.GREEN "");
                                
    //code here
                            
    }
                        }
                    }   
            }
        }
     
  6. Offline

    Jordymt

    So you wanted to give them items on the interact with a particular sign, this works for me:

    Code:java
    1. @EventHandler
    2. public void clicksign(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. Block b = e.getClickedBlock();
    6. if (b.getType() == Material.SIGN_POST|| b.getType() == Material.WALL_SIGN) {
    7. Sign sign = (Sign) b.getState();
    8. if (sign.getLine(0).equalsIgnoreCase("[aurakits]")) {
    9. if (sign.getLine(1).equalsIgnoreCase("tank")) {
    10. p.getInventory().addItem(new ItemStack(Material.APPLE, 1));
    11. p.getInventory().addItem(new ItemStack(Material.RAW_CHICKEN, 1));
    12. p.sendMessage(ChatColor.GREEN + "You have been given the tank kit!");
    13. }
    14. }
    15. }
    16. }
    17. }


    [​IMG]
     
  7. Offline

    amazed2025

    Thanks for your help!

    didn't work for me, no clue why, I try right-clicking the sign but nothing happens. No errors or anything

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

    PatrickH123

    Did you register the event in your onEnable() method?
     
  9. Offline

    TheUpdater

    post the code here and lets see what you got
     
  10. Offline

    amazed2025

    No worries. That's exactly what I forgot to add. Works now. Thanks for the help<3

    Jordymt TheUpdater only one problem. When I right-click the sign, it glitches. Sometimes only one of the items are given, sometimes all of them. How would I fix that?

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

    TheUpdater

    use p.updateinventory();

    =) hope it helps
     
  12. Offline

    amazed2025

    Okay, before or after the code? Since I put it after/before but this is what eclipse gives me; http://prntscr.com/20lfrh
     
  13. Offline

    SacredWaste

    amazed2025 Deprecate means to "strongly disapprove" or so dictionaries say. Its not used anymore, but may still work with out a issue and solve your problem. Click the suppress deprecation errors, and you should be okay if it still works.
     
  14. Offline

    amazed2025

    I tried, it had a problem with exporting the plugin.

    Made a new thread (http://forums.bukkit.org/threads/coordinate-teleportation-inventory-updating.188819/) So it's easier to understand and clean.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page