Magic clock not working?

Discussion in 'Plugin Development' started by Sean0402, Sep 2, 2014.

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

    Sean0402

    Hello my magic clock is not working for some reason. Code:

    Main Class:
    Code:java
    1. package me.Sean0402.MagicClock;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import me.Sean0402.MagicClock.Listener.Clock;
    7.  
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin {
    13.  
    14. public List<Player> playerusedclock = new ArrayList<>();
    15.  
    16. public void onEnable(){
    17. PluginManager pm = this.getServer().getPluginManager();
    18.  
    19. pm.registerEvents(new Clock(this), this);
    20. }
    21.  
    22. }
    23.  


    Listener :
    Code:java
    1. package me.Sean0402.MagicClock.Listener;
    2.  
    3. import me.Sean0402.MagicClock.Main;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13.  
    14. public class Clock implements Listener {
    15.  
    16. private Main plugin;
    17.  
    18. public Clock (Main plugin)
    19. {
    20. this.plugin = plugin;
    21. }
    22.  
    23.  
    24. @EventHandler
    25. public void onIneract(PlayerInteractEvent e)
    26. {
    27. final Player p = e.getPlayer();
    28.  
    29. if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)
    30. {
    31. return;
    32. }
    33.  
    34. if (e.getItem() == null)
    35. {
    36. return;
    37. }
    38.  
    39. if (e.getItem().getType() != Material.WATCH)
    40. {
    41. return;
    42. }
    43.  
    44. if (plugin.playerusedclock.contains(p))
    45. {
    46. p.sendMessage(ChatColor.RED + "Du darfst diese Uhr erst wieder in 5 Sekunden nutzen!");
    47.  
    48. return;
    49. }
    50.  
    51.  
    52.  
    53. for (Player p1 : plugin.getServer().getOnlinePlayers())
    54. {
    55. if (p.canSee(p1))
    56. {
    57. p.hidePlayer(p1);
    58. }
    59.  
    60. else
    61. {
    62. p.showPlayer(p1);
    63. }
    64.  
    65.  
    66. }
    67.  
    68. plugin.playerusedclock.add(p);
    69.  
    70. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    71.  
    72. @Override
    73. public void run() {
    74. plugin.playerusedclock.remove(p);
    75.  
    76. }
    77. }, 100L);
    78.  
    79.  
    80. }
    81.  
    82. }
     
  2. Offline

    DevRosemberg

    hintss likes this.
  3. Offline

    Jimfutsu

    I wouldn't do the ifs this way if I were you, I would check if they were positive, not negative.
     
  4. Offline

    BillyGalbreath

    His conditions are correct for the style of coding he's using.
     
  5. Offline

    Jimfutsu

    I know, but this was, I personally believe it's a lot harder to bug fix.
     
  6. Offline

    Sean0402

    Well there is not errors.. Just nothing happens :/
     
  7. Offline

    Rocoty

    Jimfutsu I like that style to be honest. Makes the code neat and tidy. It's like saying "don't run the following code if these precautions aren't fulfilled." That way you prevent having lines that start 5 indents in.

    Sean0402 If you could tell us what you want to happen, what actually happens and the steps you take to test, that would be nice. These are the things one should share when posting threads like this.
     
  8. Offline

    Sean0402

    Rocoty I want it when you right click the clock it makes players hide. Then a delay of 5 seconds. Then if you right click again it makes them appear again. Example is on hivemc. But they use a dye instead of a clock.
     
  9. Offline

    Rocoty

    Now, I'm gonna ask again the questions you failed to answer:
     
Thread Status:
Not open for further replies.

Share This Page