Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- option ver:
- get:
- return console.getServer().getClass().getPackage().getName().split("\.")[3] #Get the version of the server (for NMS)
- import:
- java.util.Optional
- net.minecraft.server.{@ver}.BlockPosition #Required for the location of the bed
- net.minecraft.server.{@ver}.EntityPose #The pose (here we'll use Sleeping)
- com.comphenix.protocol.wrappers.WrappedDataWatcher #Required to edit the player's metadata using protocollib (and packets)
- com.comphenix.protocol.wrappers.WrappedDataWatcher$Registry as DataWatcherRegistry
- com.comphenix.protocol.wrappers.WrappedDataWatcher$WrappedDataWatcherObject as DataWatcherObject
- effect (make|force) [the] %players% [to] sleep at %location% for %players% [to not be stuck in bed %-boolean%]:
- trigger:
- set {_stuck} to expression-4 ? false #Set to false if "to not be.." is not set
- set {_PacketMetadata} to new play_server_entity_metadata packet
- set {_OptionalBlockPos} to Optional.of(new BlockPosition(x location of expression-2, (y location of expression-2) - 0.5 and z location of expression-2)) #The location of the ""fake"" bed (where the player will sleep)
- set {_WDW} to new WrappedDataWatcher() #Creating the datawatcher/watchablecollection
- set {_Serializer} to DataWatcherRegistry.getBlockPositionSerializer(true)
- set {_DWO} to new DataWatcherObject(13 and {_Serializer})
- {_WDW}.setObject({_DWO} and {_OptionalBlockPos}) #Object 13 is the location
- {_WDW}.setObject(6, DataWatcherRegistry.get(EntityPose) and EntityPose.SLEEPING) #Object 6 is the EntityPose, here the sleeping one
- set watchable collection field 0 of {_PacketMetadata} to {_WDW}
- loop expressions-1:
- set int pnum 0 of {_PacketMetadata} to (loop-value-1).getEntityId() #Send the packet with the right entity Id
- if {_stuck} is false:
- loop expressions-3:
- send packet {_PacketMetadata} to loop-value-2
- set {IsSleeping::%(loop-value-1).getEntityId()%::%loop-value-2%} to true #Useful to make the player sleep again when he comes in a visible range
- wait 2 ticks #Avoid some bugs you may have if you try to make multiple players sleep at once
- else:
- loop expressions-3:
- loop-value-1 is not loop-value-2 #If the player doesn't receive his packets, he isn't stuck
- send packet {_PacketMetadata} to loop-value-2
- set {IsSleeping::%(loop-value-1).getEntityId()%::%loop-value-2%} to true
- effect wake [the][up] %players% [up] for %players%:
- trigger:
- set {_PacketMetadata} to new play_server_entity_metadata packet
- set {_OptionalBlockPos} to Optional.empty() #The same thing happen when you click "leave bed"
- set {_WDW} to new WrappedDataWatcher()
- set {_Serializer} to DataWatcherRegistry.getBlockPositionSerializer(true)
- set {_DWO} to new DataWatcherObject(13 and {_Serializer})
- {_WDW}.setObject({_DWO} and {_OptionalBlockPos})
- {_WDW}.setObject(6, DataWatcherRegistry.get(EntityPose) and EntityPose.STANDING)
- set watchable collection field 0 of {_PacketMetadata} to {_WDW}
- loop expressions-1:
- set int pnum 0 of {_PacketMetadata} to (loop-value-1).getEntityId()
- loop expressions-2:
- clear {IsSleeping::%(loop-value-1).getEntityId()%::%loop-value-2%}
- send packet {_PacketMetadata} to loop-value-2
- on packet event play_server_entity_metadata: #Prevent the player from changing position (by sneaking for instance)
- {IsSleeping::%int pnum 0 of event-packet%::%player%} is true
- set {_WC} to watchable collection field 0 of event-packet
- "%{_WC}.getObject(6)%" is not "SLEEPING" or "<none>"
- cancel event #I have to cancel here, because setting it can cause weird visual glitches
- on packet event play_server_named_entity_spawn: #Make the player sleep when he comes in a visible range
- {IsSleeping::%int pnum 0 of event-packet%::%player%} is true
- make {Id::%int pnum 0 of event-packet%} sleep at {Id::%int pnum 0 of event-packet%}'s location for player
- on quit: #The player won't be asleep when he'll log back
- clear {IsSleeping::%player.getEntityId()%::*}
- on join: #Must be used in order to convert an entityid into a player without looping all players
- set {Id::%player.getEntityId()%} to player
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement