# dBroadcasting system
# Allows for colorized broadcasts
# Users require op or dbroadcast.command permission
# Broadcasts are stored in dBroadcasts_saves.yml and is
# Editable and reloadable.
# Created by Talamar1/Mik/Mikayle1
Broadcast:
type: world
debug: false
events:
on server start:
- if <server.has_file[dbroadcast_saves.yml]> {
- announce "<red><&lb>dBroadcast<&rb> <green>Loading Broadcast Config File"
- yaml load:dbroadcast_saves.yml id:dbroadcast_saves
}
else {
- announce "<red><&lb>dBroadcast<&rb> <green>Creating Broadcast Config File"
- yaml create id:dbroadcast_saves
- yaml savefile:dbroadcast_saves.yml id:dbroadcast_saves
}
- run InitdBroadcast delay:10t
on dbc command:
- determine passively fulfilled
- if !<context.server> && !<player.has_permission[dbroadcast.command]||false> {
- narrate "<&6>You do not have permission to use the dbroadcast command."
- queue clear
}
- if <el@val[add].is[==].to[<context.args.get[1]>]> {
- inject dbroadcast_command_add
}
else if <context.args.get[1].matches[^(rem|remove|del|delete)$]> {
- inject dbroadcast_command_remove
}
else if <el@val[list].is[==].to[<context.args.get[1]>]> {
- inject dbroadcast_command_list
}
else if <el@val[reload].is[==].to[<context.args.get[1]>]> {
- inject dbroadcast_command_reload
}
else {
- narrate "<&6>/dBroadcast add <<>timer<>> <<>message<>>"
- narrate "<&6>/dBroadcast remove <<>dbid<>>"
- narrate "<&6>/dBroadcast list"
- narrate "<&6>/dBroadcast reload"
}
InitdBroadcast:
type: task
debug: false
script:
- if <yaml[dbroadcast_saves].list_keys[bclist].size.is[more].than[0]||null> == true {
- foreach <yaml[dbroadcast_saves].list_keys[bclist]> {
- if <util.date.time.minute.mod[<yaml[dbroadcast_saves].read[bclist.%value%.timer]>].is[==].to[0]> {
- define dBmsg <yaml[dbroadcast_saves].read[bclist.%value%.message]>
- announce "<def[dBmsg]>"
}
}
- run InitdBroadcast delay:60s
dbroadcast_command_add:
type: task
debug: false
script:
- if <context.args.get[3].is[==].to[null]||true> {
- narrate "<&6>/dBroadcast add <<>timer<>> <<>message<>>"
- narrate "<&6>Timer - Amount of time between rebroadcasts"
- narrate "<&6>Message - message you want broadcasts"
- queue clear
}
- if <context.args.get[2].as_int.is[LESS].than[5]||true> {
- narrate "<gold>dBroadcast Invalid time argument"
- narrate "<gold>Value must be greater than 5"
- queue clear
}
- define dBtimer <context.args.get[2].as_int>
- define dBmsg <context.args.get[3].to[<context.args.size>].as_string>
- define dBmsg <def[dBmsg].replace[&0].with[<&0>]>
- define dBmsg <def[dBmsg].replace[&1].with[<&1>]>
- define dBmsg <def[dBmsg].replace[&2].with[<&2>]>
- define dBmsg <def[dBmsg].replace[&3].with[<&3>]>
- define dBmsg <def[dBmsg].replace[&4].with[<&4>]>
- define dBmsg <def[dBmsg].replace[&5].with[<&5>]>
- define dBmsg <def[dBmsg].replace[&6].with[<&6>]>
- define dBmsg <def[dBmsg].replace[&7].with[<&7>]>
- define dBmsg <def[dBmsg].replace[&8].with[<&8>]>
- define dBmsg <def[dBmsg].replace[&9].with[<&9>]>
- define dBmsg <def[dBmsg].replace[&a].with[<&a>]>
- define dBmsg <def[dBmsg].replace[&b].with[<&b>]>
- define dBmsg <def[dBmsg].replace[&c].with[<&c>]>
- define dBmsg <def[dBmsg].replace[&d].with[<&d>]>
- define dBmsg <def[dBmsg].replace[&e].with[<&e>]>
- define dBmsg <def[dBmsg].replace[&f].with[<&f>]>
- define dBmsg <def[dBmsg].replace[&k].with[<&k>]>
- define dBmsg <def[dBmsg].replace[&l].with[<&l>]>
- define dBmsg <def[dBmsg].replace[&m].with[<&m>]>
- define dBmsg <def[dBmsg].replace[&n].with[<&n>]>
- define dBmsg <def[dBmsg].replace[&o].with[<&o>]>
- define dBmsg <def[dBmsg].replace[&r].with[<&r>]>
- narrate "Timer %dBtimer%"
- narrate "Message %dBmsg%"
- define bcount <yaml[dbroadcast_saves].list_keys[bclist].size||0>
- yaml set bclist.<def[bcount].add[1].as_int>.timer:%dBtimer% id:dBroadcast_saves
- yaml set bclist.<def[bcount].add[1].as_int>.message:%dBmsg% id:dBroadcast_saves
- yaml savefile:dbroadcast_saves.yml id:dbroadcast_saves
dbroadcast_command_list:
type: task
debug: false
script:
- foreach <yaml[dbroadcast_saves].list_keys[bclist]> {
- narrate "Key<&co> %value% <&co> <yaml[dbroadcast_saves].read[bclist.%value%.timer]> <&co> <yaml[dbroadcast_saves].read[bclist.%value%.message]> "
}
dbroadcast_command_reload:
type: task
debug: false
script:
- if <server.has_file[dbroadcast_saves.yml]> {
- narrate "<red><&lb>dBroadcast<&rb> <green>Loading Broadcast Config File"
- yaml load:dbroadcast_saves.yml id:dbroadcast_saves
}
else {
- narrate "<red><&lb>dBroadcast<&rb> <green>Creating Broadcast Config File"
- yaml create id:dbroadcast_saves
- yaml savefile:dbroadcast_saves.yml id:dbroadcast_saves
}
dbroadcast_command_remove:
type: task
debug: false
script:
- if <context.args.get[2].as_int.is[LESS].than[1]||false> || <yaml[dBroadcast_saves].read[bclist.<context.args.get[2].as_int>].is[==].to[null]> {
- narrate "<gold>dBroadcast Invalid broadcast id number"
- narrate "<gold>Check IDs with /bc info"
- queue clear
}
- yaml set bclist.<context.args.get[2].as_int>:! id:dBroadcast_saves
- yaml create id:temp_broadcast
- foreach <yaml[dBroadcast_saves].list_keys[bclist]> {
- yaml set bclist.%loop_index%.timer:<yaml[dBroadcast_saves].read[bclist.%value%.timer]> id:temp_broadcast
- yaml set bclist.%loop_index%.message:<yaml[dBroadcast_saves].read[bclist.%value%.message]> id:temp_broadcast
}
- yaml savefile:dbroadcast_saves.yml id:temp_broadcast
- yaml unload id:temp_broadcast
- inject dbroadcast_command_reload