1.16.5 [1.16.5] How to create an event everytime the day/night cycles

Discussion in 'Spigot Plugin Development' started by QuackingCoder, Jun 21, 2021.

  1. So I've been coding a plugin for a manhunt challenge that I'm gonna do.
    Its my first plugin ever, so I have no experience at all.

    The challenge is that, every time that the day/night cycles I get op loot, but I don't know how to make an event when the day/night cycles.

    Please give me the code, information about it and how it works.

    Note: I have looked in the spigot docs, but I couldn't find anything that could help, or am I stupid?

    Thanks a lot!
  2. run a bukkit runnable that checks the current world time, if it is greater than 13000 then it's night time, if it's less than 13000 it's day time, if it reaches 24000 then a whole day has past in minecraft and it will reset to 0 since getTime is from 0 - 24000 which is 20 minutes.
  3. Eh, can jou maybe show a command or something?

    I kinda know what you mean but I don't know stuff about a runnable or how to execute it.
  4. on your DayCycle Class extend the bukkit runnable and add an unimplemented method, or create your own.
    inside the unimplemented method, do the things I said above, then on your main class, just do a run task timer.

    Code (Text):
    public void run() {
    int time = getTheTimeUsingTheCorrectMethod

    if (time > 23900 && time < 100) {
    // This means there's only 5 seconds left before the day ends,
    // Do you code

    Code (Text):
    private DayCycle cycle = new DayCycle();

    cycle.runTaskTimer(this, 0, 100);

    you can then change the value of runTaskTimer depending on what you need. On my example it just means that every 5 second the plugin will check if game time is greater than 23900 or less than 100.

    Other thing you can do is, instead of running it every 5 seconds, just run it every 24000 ticks, but inside the run method, set the game time to zero. But be ware because that I think this won't let your server progress, it will always stay on day 1.
  5. So eh can I just copy this code lmao.

    yeah sorry i suck at coding wheeze
  6. It's not advisable to copy paste code, in this case, you can but you need to make sure you are pasting them on their correct location, it's much better to learn how they work it will help you greatly in the future and you will be able to fix errors if it have.
  7. This is my code atm

    package me.ducc.timeisop.commands;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import me.ducc.timeisop.Main;

    public class TimeCommands implements CommandExecutor{
    private Main plugin;

    public TimeCommands(Main plugin) {
    this.plugin = plugin;
    plugin.getCommand("timeisop").setExecutor (this);

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)){
    sender.sendMessage("Only players can use this command!");
    return true;

    return false;


    do you know where i should place it?

    and do you have any good courses or something like that for coding in minecraft?
    Also thanks for all this help man.
  8. Make runnable
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  9. Here's a link to a tutorial about scheduling repeating and and non-repeating tasks. Please read through it, it will help you.