Solved How To Updates Signs

Discussion in 'Plugin Development' started by PlazmaStorm, Jul 7, 2014.

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

    PlazmaStorm

    Help I am plugin developer and i am trying to make a plugin that teleports players to a random location, 3 times max, with a 10m cool-down, when they click a sign.
    i want the sign to say:
    [RTP]​
    Uses Left​
    [Uses Left]​
    Click Here​
    I have done everything already except for the [Uses Left] part.
    I am trying to add the amount of uses the player has left,
    this is the exact line:

    [plugin.getConfig().getInt(player.getUniqueId().toString())]
    it works fine except when the number changes from 3 - 2.
    the sign dosent change. If i check the conifg.yml i still works?
    how could i update this sign?
    Ps: I have tried sign.update(true);
    thank you for your help
     
  2. Offline

    micrlink

    tommycake50 likes this.
  3. Offline

    PlazmaStorm

    Code:java
    1. package me.PlazmaStorm.RandomTp;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.block.Sign;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.block.SignChangeEvent;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11.  
    12. public class RandomTpListeners implements Listener {
    13. RandomTp plugin;
    14.  
    15. public RandomTpListeners(RandomTp instance) {
    16. plugin = instance;
    17. }
    18.  
    19. @EventHandler
    20. public void onSignChange(SignChangeEvent e) {
    21. if (e.getLine(0).equalsIgnoreCase("[RTP]")) {
    22. e.setLine(0, "§8[§3RTP§8]");
    23. e.setLine(1, "§8Uses Left");
    24. e.setLine(2, "§8[§4 + plugin.getConfig().getInt(player.getUniqueId().toString()) + §8]");
    25. e.setLine(3, "§7Click Here");
    26. }
    27. }
    28.  
    29. @EventHandler
    30. public void onPlayerInteract(PlayerInteractEvent e) {
    31. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    32. if (e.getClickedBlock().getState() instanceof Sign) {
    33. Sign s = (Sign) e.getClickedBlock().getState();
    34. if (s.getLine(0).equalsIgnoreCase("§8[§3RTp§8]")) {
    35. s.update(true);
    36.  
    37. Player player = e.getPlayer();
    38. String uuid = player.getUniqueId().toString();
    39.  
    40. if (!plugin.getConfig().contains(uuid)) {
    41. player.performCommand("rtp");
    42. player.sendMessage(ChatColor.GREEN + "You Have Been Teleported");
    43. plugin.getConfig().set(uuid, 3);
    44. plugin.saveConfig();
    45. return;
    46. }
    47.  
    48. int l = this.plugin.getConfig().getInt(uuid);
    49.  
    50. if (l == 3) {
    51. player.performCommand("rtp");
    52. player.sendMessage(ChatColor.GREEN + "You Have Been Teleported");
    53. plugin.getConfig().set(uuid, 2);
    54. plugin.saveConfig();
    55. return;
    56. }
    57.  
    58. if (l == 2) {
    59. player.performCommand("rtp");
    60. player.sendMessage(ChatColor.GREEN + "You Have Been Teleported");
    61. plugin.getConfig().set(uuid, 1);
    62. plugin.saveConfig();
    63. return;
    64. }
    65.  
    66. if (l == 1) {
    67. player.sendMessage(ChatColor.DARK_RED + "Do Not Use More Then 3 Times");
    68. plugin.saveConfig();
    69. return;
    70. }
    71. return;
    72. }
    73. }
    74. }
    75. }
    76.  


    hope this helps
    that is my RandomTpListener
    Main class shouldn't be needed as it has nothing to do with this (ask if you need it)
    all it does is it creates the command rtp
    thank you
     
  4. Offline

    ElliottOlson

    You have to create a method to update the sign by getting the location of the sign and then updating it. A SignChangeEvent only works when you place the sign, so it will not update it by itself. During the SignChangeEvent save the location of the sign and then create a method where it grabs the block at that location and set the sign with the new information. Then on the interact method call the method you should have created which will update the sign.
     
  5. Offline

    PlazmaStorm

    ElliottOlson Thanks a lot ill try that Later
    Everyone: still open for other suggestions just in case that one dosen't work as i cant test it right now

    ElliottOlson what way should i find the location of the sign?

    e.getBlock().getLocation().getX();

    e.getBlock().getLocation().getY();

    e.getBlock().getLocation().getZ();
    ??
    Sorry if I am not doing right i am not very good at this yet :)
    Dont give me a full code i want to do most of it myself though

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

    PlazmaStorm

  7. Offline

    AoH_Ruthless

    PlazmaStorm
    SignChangeEvent#getBlock()#getLocation() should work fine to retrieve location.
     
  8. Offline

    micrlink

    SignChangeEvent e.getBlock().getState().update();
     
  9. Offline

    PlazmaStorm

    micrlink That will just update it once and never again
    as SignChangeEvent is only a once use only and only updates when you place the sign
    adding that shouldn't do anything

    @AoH_Ruthless ill try that thank you

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

Share This Page