[Broadcast]Time

Discussion in 'Plugin Development' started by ShredNyx, Sep 16, 2013.

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

    ShredNyx

    Hey I've already implemented a timer but when I right click the sign it doesn't seem to broadcast the seconds/time? Here's the code
    Code:java
    1. if (sign.getLine(0).contains("[teleport]")); {
    2. isCancelled = false;
    3. getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    4. public void run() {
    5. if (isCancelled == false) {
    6. time = time -1;
    7. Bukkit.broadcastMessage("Message prefix"+time);
    8. plugin.getServer().broadcastMessage("Message prefix"+time);
    9. if (time == 0) {
    10. plugin.getServer().getScheduler().cancelTask(taskID);
    11. time=5;
    12. }
    13. }
    14. }
    15. }, 0, 40);
     
  2. ShredNyx
    You have a semicolon before the bracket in line 1.
    Code:
    if (sign.getLine(0).contains("[teleport]")); {
     
  3. Offline

    ShredNyx

    What will that change though? Assist

    Doesn't change anything Assist

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. ShredNyx
    Debug your code. Make sure you have the @EventHandler annotation, and that you have registered your events.
     
  5. Offline

    ShredNyx

    Alrighty I just did but still doesn't work Assist
     
  6. Offline

    chasechocolate

    ShredNyx what do you mean? Does anything get printed out? Post your updated code.
     
  7. Offline

    ShredNyx

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.ChatColor;
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.block.Sign;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.block.SignChangeEvent;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.plugin.Plugin;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15.  
    16. public class Main extends JavaPlugin implements Listener{
    17. public static int time = 5; //time in seconds
    18. public static Boolean isCancelled;
    19. public static int taskID;
    20. Plugin plugin;
    21.  
    22.  
    23. @Override
    24. public void onEnable() {
    25. getServer().getPluginManager().registerEvents(this, this);
    26. //getServer().getPluginManager().registerEvents(new ClickSignListener(), this);
    27. }
    28. @EventHandler
    29. public void signPlace(SignChangeEvent e) {
    30. if(e.getLine(0).contains("[teleport]")) {
    31. e.setLine(0, ChatColor.GREEN +"[teleport]");
    32. }
    33. }
    34.  
    35. @EventHandler
    36. public void signInteract(PlayerInteractEvent e) {
    37. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    38. Block block = e.getClickedBlock();
    39. if(block.getType() == Material.SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
    40. Sign sign = (Sign) e.getClickedBlock().getState();
    41. if(sign.getLine(0).contains("[teleport]")) {
    42. e.getPlayer().teleport(new Location(e.getPlayer().getWorld(), 100, 100, 100));
    43. isCancelled = true;
    44. }
    45. else {
    46. if (sign.getLine(0).contains("[teleport]")) {
    47. isCancelled = false;
    48. getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    49. public void run() {
    50. if (isCancelled == false) {
    51. time = time -1;
    52. Bukkit.broadcastMessage("Message prefix"+time);
    53. plugin.getServer().broadcastMessage("Message prefix"+time);
    54. if (time == 0) {
    55. plugin.getServer().getScheduler().cancelTask(taskID);
    56. time=5;
    57. }
    58. }
    59. }
    60. }, 0, 40);
    61. }
    62. }
    63.  
    64. }
    65. }
    66. }
    67. }
    68.  

    I've tried everything but could find the solution to why it isn't working

    Please advise chasechocolate

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

    EdenCampo

    ShredNyx

    Try changing this line:

    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {


    to this:
    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
     
Thread Status:
Not open for further replies.

Share This Page