options:
prefix: &7[&cAFK&7] &f
# Name of the afk region
afk-region: afk
# Placeholders for enter/exit message:
# <player>
# Use false to turn off the message
region-enter-message: &eWelcome to the afk region <player>
region-exit-message: false
# How long it takes to get a reward
reward-cooldown: 5 minutes
# Stop afk-banned players from entering the afk zone
block-banned-users: false
# Progress mode defines how the afk progress is displayed
# action bar: show how long the player has until the next reward in their action bar
# boss bar: creates a bossbar which fills up according to how long the player has until the next reward
progress-mode: action bar
boss-bar-message: &fNext AFK Reward
# Placeholders for action bar message:
# <hours>, <minutes>, <seconds>, <clean time>, <player>
action-bar-message: &b<clean time> &euntil next reward
# The line of code that will be run when a player earns their reward
# Examples:
# console command "say hi"
# give player apple named "&cTasty"
# add 100 to player's balance
reward-code: console command "say hi"
on region enter:
if event-region is ("{@afk-region}" parsed as region):
if {afk::bannedUsers::*} contains uuid of event-player:
if {@block-banned-users} is true:
cancel event
send "{@prefix}&cYou are banned from the afk region"
else:
set {_session} to random uuid
set {afk::sessions::%player's uuid%} to {_session}
if "{@progress-mode}" is "boss bar":
set {_bar} to new boss bar with id "afk-%player's uuid%" with title "{@boss-bar-message}" with style solid bar with progress 0
add player to {_bar}
set {_lastReward} to now
if "{@region-enter-message}" is not "false":
set {_msg} to "{@region-enter-message}"
replace all "<player>" with "%player%" in {_msg}
send {_msg}
while {afk::sessions::%player's uuid%} is {_session}:
if "{@progress-mode}" is "boss bar":
set bar progress of {_bar} to (100*((seconds of (time since {_lastReward}))/(seconds of {@reward-cooldown})))
else if "{@progress-mode}" is "action bar":
set {_msg} to "{@action-bar-message}"
set {_diff} to difference between {@reward-cooldown} and (time since {_lastReward})
replace all "<seconds>" in {_msg} with "%mod(seconds of {_diff}, 60)%"
replace all "<minutes>" in {_msg} with "%mod(minutes of {_diff}, 60)%"
replace all "<hours>" in {_msg} with "%hours of {_diff}%"
replace all "<clean time>" in {_msg} with cleanTime({_diff})
replace all "<player>" in {_msg} with "%player%"
send action bar {_msg}
if time since {_lastReward} > {@reward-cooldown}:
# more rewards can be given out here
{@reward-code}
set {_lastReward} to now
wait 1 second
if {_bar} is set:
remove player from {_bar}
local function cleanTime(time: timespan):: text:
set {_t} to "%mod(seconds of {_time}, 60)%s"
if minutes of {_time} > 0:
set {_t} to "%mod(minutes of {_time}, 60)%m, %{_t}%"
if hours of {_time} > 0:
set {_t} to "%hours of {_time}%h, %{_t}%"
replace all ", 0s" with "" in {_t}
replace all ", 0m" with "" in {_t}
return {_t}
on region exit:
if event-region is ("{@afk-region}" parsed as region):
delete {afk::sessions::%player's uuid%}
if "{@region-exit-message}" is not "false":
set {_msg} to "{@region-exit-message}"
replace all "<player>" with "%player%" in {_msg}
send {_msg}
on quit:
delete {afk::sessions::%player's uuid%}
command /afkban <offline player>:
permission: afk.admin
trigger:
if {afk::bannedUsers::*} does not contain arg-1's uuid:
add arg-1's uuid to {afk::bannedUsers::*}
send "{@prefix}%arg-1% will no longer recieve afk rewards"
else:
send "{@prefix}&c%arg-1% is already banned from recieving afk rewards"
command /afkunban <offline player>:
permission: afk.admin
trigger:
if {afk::bannedUsers::*} contains arg-1's uuid:
remove arg-1's uuid from {afk::bannedUsers::*}
send "{@prefix}%arg-1% will now recieve afk rewards"
else:
send "{@prefix}&c%arg-1% is already recieving afk rewards"
# Remove everything below this point if you do not want to use skript-gui
command /afkbanlist:
permission: afk.admin
trigger:
openUnbanMenu(player)
local function openUnbanMenu(p: player, page: integer = 0):
if size of {afk::bannedUsers::*} is 0:
send "{@prefix}&cThere is no one to unban" to {_p}
else if size of {afk::bannedUsers::*} <= 54:
set {_rows} to ceil(size of {afk::bannedUsers::*} / 9)
create a gui with virtual chest inventory with {_rows} rows named "&8AFK Banned Users":
loop {afk::bannedUsers::*}:
set {_player} to offlineplayer(loop-value)
make next gui slot with skull of {_player} named "&c%{_player}%" with lore "&aClick to unban":
remove {_player}'s uuid from {afk::bannedUsers::*}
send "{@prefix}You have unbanned %{_player}%" to {_p}
if size of {afk::bannedUsers::*} is 0:
close {_p}'s inventory
else:
openUnbanMenu({_p})
else:
set {_start} to 1 + 45*{_page}
set {_stop} to {_start} + 45
create a gui with virtual chest inventory with 6 rows named "&8AFK Banned Users (%{_page} + 1%/%ceil(size of {afk::bannedUsers::*} / 45)%)":
loop {afk::bannedUsers::*}:
if loop-iteration = {_stop}:
stop loop
if loop-iteration >= {_start}:
set {_player} to offlineplayer(loop-value)
make next gui slot with skull of {_player} named "&c%{_player}%" with lore "&aClick to unban":
remove {_player}'s uuid from {afk::bannedUsers::*}
send "{@prefix}You have unbanned %{_player}%" to {_p}
if size of {afk::bannedUsers::*} < {_start}:
openUnbanMenu({_p}, {_page}-1)
else:
openUnbanMenu({_p}, {_page})
make gui slot (integers between 45 and 53) with black stained glass pane named ""
make gui slot 46 with arrow named "&cBack":
openUnbanMenu({_p}, {_page}-1)
if (size of {afk::bannedUsers::*} >= {_stop}):
make gui slot 52 with arrow named "&aNext":
openUnbanMenu({_p}, {_page} + 1)
open last gui to {_p}