#Run code after skiping the night
81 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
are you looking to do something do something to the sleeping players? or just want to trigger something on a forced new day?
I have a thirst mod installed and i want to set the thirst level when players wake up
??kjsaddons
KubeJS Additions adds more events and methods to make it easier for pack creators to do things such as toggling force-loaded chunks or getting ticking chunks, add additional checks for blocks and entities, add player stats, toggle a player's elytra, mess with JEI and more!
yeah uh lio..... there's nothing there for sleep on forge
there is a forge event you want.... probably SleepFinishedTimeEvent
in startup:
ForgeEvents.onEvent("net.minecraftforge.event.level.SleepFinishedTimeEvent", event=>{
// the rest of the owl
})
this triggers right before the time change
ForgeEvents.onEvent('net.minecraftforge.event.entity.player.PlayerSleepInBedEvent', event => {
global.onSleep(event)
})
global.onSleep = event => {
const { entity } = event
}
ForgeEvents.onEvent('net.minecraftforge.event.entity.player.PlayerWakeUpEvent', event => {
global.onWakeUp(event)
})
global.onWakeUp = event => {
const {entity} = event
}```
you'll wanna use global events so you can run /kubejs reload startup_scripts without having to reload the entire game every time you want to change something
are you sure sleep in bed isn't triggered just when they right click on the bed, whether the time changes or not?
which is not what they want
preferably after the skiping the night
there is no problem, if i want the code to be executed after the skip, i just need to put it on the global.onWakeUp right?
well playersleepinbed wouldn't trigger the new day until enough players are sleeping
I'm not
I'm saying the event you gave is not what they were asking for, how am I the one confused?
??closeticket
Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.
Do you have any other questions regarding your issue? Feel free to ask!
Note: You should generally create a new post for unrelated issues.
does it matter at this point? 
ahh just one last check
sure
wakeup event fires whenever they wake up and get kicked from the bed
not when they leave the bed
yup 
Ticket closed!
sure about that?
public void stopSleepInBed(boolean p_36226_, boolean p_36227_) {
net.minecraftforge.event.ForgeEventFactory.onPlayerWakeup(this, p_36226_, p_36227_);
super.stopSleeping();
if (this.level() instanceof ServerLevel && p_36227_) {
((ServerLevel)this.level()).updateSleepingPlayerList();

ForgeEvents.onEvent('net.minecraftforge.event.entity.player.PlayerWakeUpEvent', event => {
if (event.wakeImmediately()) return;
// got out of bed, not slept through night
global.onWakeUp(event)
})
global.onWakeUp = event => {
const {entity} = event
}
yeah you're right, do this one "net.minecraftforge.event.level.SleepFinishedTimeEvent"
mb
either way works though sleepfinishedtimeevent would be cleaner
if you did the sleepfinishedtimeevent, you get the level instead of a player who slept, so you'd want to get the player list to iterate through by doing event.level.players
this is also true
otherwise the wakeupevent will trigger for each player individually
I wonder if that triggers for players who didn't sleep
when you have the gamerule at less than 100%
but yeah use this one
depends on if all players need to have their thirst updated or only the sleepy ones 😉
np 👍
Ticket re-opened!
hello guys, i reopened the ticket because this is crashing on waking up
i put it on startup scripts
ForgeEvents.onEvent('net.minecraftforge.event.entity.player.PlayerWakeUpEvent', event => {
if (event.wakeImmediately()) return;
// got out of bed, not slept through night
global.onWakeUp(event)
})
global.onWakeUp = event => {
event.server.runCommandSilent('thirst set ' + event.player.username + ' 8 2')
}
forgeevents don't have player, use event.entity.username there and those events don't expose server so you need to do event.entity.server.runCommandSilent
thank you, will test it rn
also, is there a place besides the wiki were i can learn more about developing with kubejs?
worked flawlessly
my documentation is the code itself lol..... just kinda learned how to read java and generally understand it.... can't write it for shit 😉
theres a couple youtube tutorials out there
??tutorial
📼Youtube Tutorials📼
also as i always say the best wiki is right here 😉
thank you again 😁



