Solved Sign Event? (No more posting on here)

Discussion in 'Plugin Development' started by PolarCraft, Dec 11, 2013.

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

    PolarCraft

    Okay so i am trying to make it so when you type the following:
    First line: KP
    Second Line: S

    It would change to:
    First line: [KitPvp]
    Second Line: Standard

    But it is not doing that.
    Sign Event:
    Code:java
    1. @EventHandler
    2. public void clicksign3(PlayerInteractEvent g) {
    3. Player p = g.getPlayer();
    4. if (g.getAction() == Action.RIGHT_CLICK_BLOCK){
    5. Block d = g.getClickedBlock();
    6. if (d.getType() == Material.SIGN_POST || d.getType() == Material.WALL_SIGN) {
    7. Sign sign = (Sign) d.getState();
    8. if ((sign.getLine(0).equalsIgnoreCase("KP"))) {
    9. sign.setLine(0, ChatColor.BLUE + "[KitPvp]");
    10. if ((sign.getLine(1).equalsIgnoreCase("s"))) {
    11. sign.setLine(1, ChatColor.GREEN+ "Standard");
    12. //CODING HERE
    13. }
    14. }
    15. }
    16. }
    17. }
    18. }
    19.  
     
  2. Offline

    mattrick

  3. Offline

    PolarCraft

    mattrick Then i get this.
    The method getAction() is undefined for the type SignChangeEvent
    The method getClickedBlock() is undefined for the type SignChangeEvent
     
  4. Offline

    mattrick

    PolarCraft
    You don't need to use that. Use event.getLine() and event.setLine(). There is no need for those methods.
     
  5. Offline

    PolarCraft

    mattrick soo?

    Code:java
    1. @EventHandler
    2. public void clicksign3(SignChangeEvent g) {
    3. Block d = g.getBlock();
    4. if (d.getType() == Material.SIGN_POST || d.getType() == Material.WALL_SIGN) {
    5. Sign sign = (Sign) d.getState();
    6. if ((sign.getLine(0).equalsIgnoreCase("KP"))) {
    7. sign.setLine(0, ChatColor.BLUE + "[KitPvp]");
    8. if ((sign.getLine(1).equalsIgnoreCase("s"))) {
    9. sign.setLine(1, ChatColor.GREEN+ "Standard");
    10. //CODING HERE
    11. }
    12. }
    13. }
    14. }
    15. }
     
  6. Offline

    cowteal

    People please reply I need this too XD
     
  7. Offline

    mattrick

    PolarCraft
    No, there is no need to get the sign.
    Code:java
    1. @EventHandler
    2. public void clicksign3(SignChangeEvent g) {
    3. if (event.getLine(0)=="String"){
    4. event.setLine(0,"AnotherString")
    5. }
    6. }
     
  8. Offline

    iiHeroo

  9. Offline

    cowteal

    Thanks

    How do you make it so that the signs actually runs a command? I know the code for run a command but where do I put it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 4, 2018
  10. Offline

    random_username

    Maybe something like this??
    Code:java
    1. @EventHandler
    2. public void onsignchange(SignChangeEvent event){
    3. if(event.getLine(0).equalsIgnoreCase("KP")){
    4. if(event.getLine(1).equalsIgnoreCase("S")){
    5. event.setLine(0, ChatColor.BLUE + "[KitPvp]");
    6. event.setLine(1, ChatColor.GREEN + "Standard");
    7. }
    8. }
    9. }
     
  11. Offline

    iiHeroo


    When you interact do

    p.performCommand("cmd"); It's all in my tutorial :)
     
  12. Offline

    cowteal

    OMG thanks!! Any other tour toutorials you can refer me to?
     
  13. Offline

    iiHeroo


    Depends on what you need, but I'd recommend looking on here for what you need, there's some great resources/tutorials on it http://forums.bukkit.org/forums/resources.60/
     
  14. Offline

    PolarCraft

    cowteal Stop stealing my thread . . .
    iiHeroo Okay how could i do the interact event on the same event? Or should i do that on a separate class?
     
  15. Offline

    iiHeroo


    I always do my events in seperate classes and name them after what they're doing, although, you can put them in the same class, as long as it's not the same event in the same class, because one I don't think it'll work, and it'd be a waste. If you want to see my SignChangeEvent and my PlayerInteractEvent with the sign and all, the GitHub is here.
     
  16. Offline

    random_username

    This is an example of what I would do:
    Code:java
    1. @EventHandler
    2. public void onsignchange(SignChangeEvent event){
    3. if(event.getLine(0).equalsIgnoreCase("KP")){
    4. if(event.getLine(1).equalsIgnoreCase("S")){
    5. event.setLine(0, ChatColor.BLUE + "[KitPvp]");
    6. event.setLine(1, ChatColor.GREEN + "Standard");
    7. }
    8. }
    9. }
    10.  
    11. @EventHandler
    12. public void interact(PlayerInteractEvent event){
    13. Action action = event.getAction();
    14. //check you right click a block
    15. if(action == Action.RIGHT_CLICK_BLOCK){
    16. //check the block is a sign
    17. if(event.getClickedBlock() instanceof Sign){
    18. //get the sign
    19. Sign s = (Sign) event.getClickedBlock().getState();
    20. //checks sign..
    21. if(s.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[KitPvp]")){
    22. //checks the second line...
    23. if(s.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Standard")){
    24.  
    25. //do something...
    26. }
    27. }
    28. }
    29. }
    30. }

    Hope this helps :)
     
  17. Offline

    DrTURTLE2


    He had the same problem that you did? He was thanking a person and asking if he had anymore tuts, excuse me but what is wrong with that?
     
  18. Offline

    PolarCraft

    iiHeroo So this is not giving me the helmet.

    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. Player p = e.getPlayer();
    4. if(e.getLine(0).equalsIgnoreCase("[KitPvp]")) {
    5. if(e.getLine(1).equalsIgnoreCase("s")) {
    6. if(p.hasPermission("kitme.admin.signmake")) {
    7. e.setLine(0, ChatColor.BLACK + "[" + ChatColor.DARK_RED + "KitMe" + ChatColor.BLACK + "]");
    8. e.setLine(1, ChatColor.GREEN + "Standard");
    9. }
    10. }
    11. }
    12. }
    13.  
    14. @SuppressWarnings("deprecation")
    15. @EventHandler
    16. public void SignClick(PlayerInteractEvent e) {
    17. Player p = e.getPlayer();
    18. if (e.getAction() == Action.RIGHT_CLICK_BLOCK){ //Checks if person is right clicking on a block
    19. //This checks if the player is right clicking on the sign and it'll do all the code below if it is a sign.
    20. if (e.getClickedBlock().getState() instanceof Sign) { //This checks if the player is right clicking on the sign and it'll do all the code below if it is a sign.
    21. Sign sign = (Sign) e.getClickedBlock().getState();
    22. if(sign.getLine(0).equalsIgnoreCase(ChatColor.BLACK + "[" + ChatColor.DARK_RED + "KitMe" + ChatColor.BLACK + "]") && p.getGameMode() == GameMode.SURVIVAL) { //Capitalization matters for this too.
    23. if(sign.getLine(1).equalsIgnoreCase("Strandard")) { //Capitalization matters for this too.
    24. p.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
    25. p.updateInventory();
    26. }
    27. }
    28. }
    29. }
    30. }
    31. }
     
  19. Offline

    random_username

    In your player interact event, it says "Strandard" :p Line where it says that:
    Code:java
    1. if(sign.getLine(1).equalsIgnoreCase("Strandard")) {

    Try fixing that? :)
    edit: Also you're not including the ChatColor for the standard line. set it to:
    Code:java
    1. if(sign.getLine(1).equalsIgnoreCase(ChatColor.GREEN + "Standard")){
     
  20. Offline

    hamzaxx

    Just saying it would be easier to register a command to give items get the player to preform when the player clicks the sign.
     
  21. Offline

    PolarCraft

    Okay how would you add enchantments, dyes, etc...
     
  22. Offline

    random_username

    For leather armor dyes, LeatherArmorMeta?
     
  23. Offline

    cowteal

    its not working for me :(
     
  24. Offline

    random_username

    Which part isn't working for you?
     
    cowteal likes this.
  25. Offline

    Developerjohn

    He isn't, and please don't start an argument :cool:
     
    iiHeroo likes this.
  26. Offline

    PolarCraft

    Developerjohn He actually did "How do you make it so that the signs actually runs a command? I know the code for run a command but where do I put it?"
     
  27. Offline

    Developerjohn

    PolarCraft heh don't ask me, I'm learning to code ;):D:p
     
  28. Offline

    PolarCraft

    Didnt ask you posted what he said -_-
     
  29. Offline

    cowteal

    He does have a point, and I'm sorry if you think I'm trying to steal your post it's just that if there's already one it's easier for me

    When I try it on the server it dosnt work.....

    Should I be using 1.7?

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

    Developerjohn

    PolarCraft IDK sometimes it's hard to read posts on Bukkit
     
Thread Status:
Not open for further replies.

Share This Page