Why doesn't this work!?!

Discussion in 'Plugin Development' started by nrs23, Jan 1, 2014.

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

    nrs23

    Can I get some help with this code I've no idea whats wrong with it or anything, it just won't work.
    Have I forgotten/overlooked something completely obvious or what ?
    Main Class

    Code:java
    1. package nrs.ethereal.freezer;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5. import java.util.logging.Level;
    6. import java.util.logging.Logger;
    7.  
    8.  
    9. import nrs.ethereal.goldrush.Main;
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.Server;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Main extends JavaPlugin
    17. {
    18. public Logger logger = Logger.getLogger("Minecraft");
    19. public Main plugin;
    20. public Server bukkit;
    21. List<String> freeze = new ArrayList<String>();
    22. public void onEnable()
    23. {
    24. PluginDescriptionFile pdfFile = getDescription();
    25. logger.log(Level.INFO, "{0} Version {1} Has Been Enabled!", new Object[] { pdfFile.getName(), pdfFile.getVersion() });
    26. startup();
    27. this.plugin = this;
    28. this.bukkit = this.plugin.getServer();
    29. this.logger = this.plugin.getLogger();
    30.  
    31. }
    32.  
    33. private void startup() {
    34. Bukkit.getServer().getPluginManager().registerEvents(new EventListener(this), this);
    35. }
    36.  
    37. public void onDisable()
    38. {
    39. PluginDescriptionFile pdfFile = getDescription();
    40. logger.log(Level.INFO, "{0} Version {1} Has Been Disabled!", new Object[] { pdfFile.getName(), pdfFile.getVersion() });
    41. }
    42. }
    43.  


    Scheduler
    Code:java
    1. package nrs.ethereal.freezer;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8.  
    9. public class Schedulers
    10. {
    11. public static Main main;
    12. public Schedulers(JavaPlugin plugin)
    13. {
    14. plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    15. public void run(){
    16. Schedulers.DamagePlayer();
    17. }
    18. }
    19. , 20L, 240);
    20. }
    21.  
    22. public static void DamagePlayer()
    23. {
    24. Main m = main;
    25. for(String frozen : m.freeze){
    26. Player player = Bukkit.getPlayerExact(frozen);
    27. player.damage(1.0);
    28. if (player.getHealth() == 1) {
    29. player.sendMessage(ChatColor.BLUE + "So Cold... So Cold... So.. So.. So Very Cold........");
    30. Cold(player);
    31. }
    32. }
    33. }
    34.  
    35. private static void Cold(Player player)
    36. {
    37. if (player.getHealth() == 12D)
    38. player.sendMessage(ChatColor.BLUE + "Bit nippy out here, I hope I've got some spare logs in the ponies pack.");
    39. else if (player.getHealth() == 10D)
    40. player.sendMessage(ChatColor.BLUE + "Wish I had a fire right about now.");
    41. else if (player.getHealth() == 6D)
    42. player.sendMessage(ChatColor.BLUE + "Can't feel my toes... FIRE!!");
    43. else if (player.getHealth() == 2D)
    44. player.sendMessage(ChatColor.BLUE + "Cold... Cold... Fire....");
    45. }
    46. }
    47.  


    Event Listener
    Code:java
    1. package nrs.ethereal.freezer;
    2.  
    3.  
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.World;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.block.BlockFace;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerJoinEvent;
    15. import org.bukkit.event.player.PlayerMoveEvent;
    16. import org.bukkit.scheduler.BukkitRunnable;
    17. import nrs.ethereal.goldrush.Main;
    18.  
    19. public class EventListener implements Listener {
    20.  
    21. Main main;
    22. public Logger logger = Logger.getLogger("Minecraft");
    23. public EventListener(Main passedMain)
    24. {
    25. this.main = passedMain;
    26. }
    27.  
    28. public void PlayerJoin(PlayerJoinEvent event){
    29. Player p = event.getPlayer();
    30. p.setFireTicks(100);
    31. }
    32.  
    33. public void PlayerMove(PlayerMoveEvent event)
    34. {
    35.  
    36. final Player player = event.getPlayer();
    37. Location loc = player.getLocation();
    38. World world = loc.getWorld();
    39. Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    40. long time = Bukkit.getServer().getWorld("world").getTime();
    41. if (time < 13000 || time > 22220) { // night
    42. if (world.getHighestBlockAt(loc).getLocation().getY() <= loc.getY()) { // on surface
    43. if (block.getLightFromBlocks() < 8) { // if fires around the place and the player is within
    44. player.sendMessage(ChatColor.BLUE + "Its pretty cold out here, I should get a fire going ASAP if I want to stay alive much longer.");
    45. new BukkitRunnable() {
    46.  
    47. @Override
    48. public void run() {
    49. main.freeze.add(player.getName());
    50.  
    51. }
    52. }.runTaskLater(this.main, 2400);
    53.  
    54. } else {
    55. main.freeze.contains(player.getName());
    56. main.freeze.remove(player.getName());
    57. player.sendMessage(ChatColor.BLUE + "Phew.. That was cold, I hope the fire lasts till Dawn.");
    58. }
    59. }
    60. }
    61. }
    62. }
    63.  
     
  2. Offline

    BillyGalbreath

    "Just wont work" isnt descriptive enough for us to help you. Please elaborate on the exact problem(s), the expected output, error logs, etc.
     
  3. Offline

    nrs23

    BillyGalbreath there are no errors, nothing in the console, nothing. What's supposed to happen is after about 9pm if the player is on the surface and out side and There's no fire within 5 or so blocks the player will slowly freeze to death over 6 minutes
     
  4. Offline

    xTrollxDudex

    nrs23
    Debug your code and see how far the code gets before not executing what you want
     
  5. Offline

    nrs23

    @xTrollxDudex I have and nothing in the Event Listener is running, that why i posted it it here
     
  6. Offline

    Sour

    You don't have any @EventHandler annotations above your events.
     
  7. Offline

    nrs23

    @Sour Thanks mate, knew id forgotten something totally stupidly obvious
     
Thread Status:
Not open for further replies.

Share This Page