local function t(t)return tostring(t.UserId)end local function o(t)return t==1 and""or"\115"end local function n(t)local n=math.floor(t/60)t=t%60 local P=math.floor(n/60)n=n%60 local b=math.floor(P/24)P=P%24 local d if b>0 then d=b..(" \100\097\121"..o(b))if P>0 then d=d..("\044 "..(P..(" \104\111\117\114"..o(P))))end elseif P>0 then d=P..(" \104\111\117\114"..o(P))if n>0 then d=d..("\044 "..(n..(" \109\105\110\117\116\101"..o(n))))end elseif n>0 then d=n..(" \109\105\110\117\116\101"..o(n))if t>0 then d=d..("\044 "..(t..(" \115\101\099\111\110\100"..o(t))))end else d=t..(" \115\101\099\111\110\100"..o(t))end return d end local function P(o,P)local b=os.time()if P.status=="\098\097\110\110\101\100"then local d=""if type(P.expires)=="\110\117\109\098\101\114"then if b>=P.expires then return end local t=math.max(0,P.expires-b)if t<=0 then return end d=MESSAGE_BAN:gsub("\037\037\084\073\077\069\037\037",n(t))else d=MESSAGE_BAN_NO_EXPIRE end if type(P.reason)=="\115\116\114\105\110\103"then d=d..REASON:gsub("\037\037\082\069\065\083\079\078\037\037",P.reason)end script.KickingBannedPlayer:Fire(o,P)spawn(function()pcall(function()dsPlayerBans:UpdateAsync(t(o),function(t)if not t then return nil end local o={}for t,n in pairs(t)do o[t]=n end o.kicks=(o.kicks or 0)+1 o.lastKick=b return o end)end)end)wait(3)o.PlayerGui.MainUI.Banished.LocalScript.Disabled=false o.PlayerGui.MainUI.Banished.Banned.Visible=true end end local function b(o)local n pcall(function()n=dsPlayerBans:GetAsync(t(o))end)if type(n)=="\116\097\098\108\101"then P(o,n)else end end Players.PlayerAdded:connect(b)for t,o in pairs(Players:GetPlayers())do b(o)end
-- Returns a string key to use in order to access a player's data store
local function getKey(player)
	return tostring(player.UserId)
end

local function plural(n)
	return n == 1 and "" or "s"
end

local function getTimeString(seconds)
	local minutes = math.floor(seconds / 60)
	seconds = seconds % 60
	local hours = math.floor(minutes / 60)
	minutes = minutes % 60
	local days = math.floor(hours / 24)
	hours = hours % 24
	local s
	if days > 0 then
		s = days .. " day" .. plural(days)
		if hours > 0 then
			s = s .. ", " .. hours .. " hour" .. plural(hours)
		end
	elseif hours > 0 then
		s = hours .. " hour" .. plural(hours)
		if minutes > 0 then
			s = s .. ", " .. minutes .. " minute" .. plural(minutes)
		end
	elseif minutes > 0 then
		s = minutes .. " minute" .. plural(minutes)
		if seconds > 0 then
			s = s .. ", " .. seconds .. " second" .. plural(seconds)
		end
	else
		s = seconds .. " second" .. plural(seconds)
	end
	return s
end

local function processPayload(player, payload)
	local now = os.time()
	if payload["status"] == "banned" then
		local kickMessage = ""
		if type(payload["expires"]) == "number" then
			if now >= payload["expires"] then
				-- Ban expired
				return
			end
			local seconds = math.max(0, payload["expires"] - now)
			-- Double check
			if seconds <= 0 then
				return
			end
			kickMessage = MESSAGE_BAN:gsub("%%TIME%%", getTimeString(seconds))
		else
			kickMessage = MESSAGE_BAN_NO_EXPIRE
		end
		if type(payload["reason"]) == "string" then
			kickMessage = kickMessage .. REASON:gsub("%%REASON%%", payload["reason"])
		end
		script.KickingBannedPlayer:Fire(player, payload)
		-- Attempt to increment the number of "kicks"
		spawn(function()
			pcall(function()
				dsPlayerBans:UpdateAsync(getKey(player), function(oldPayload)
					if not oldPayload then
						return nil
					end
					-- Shallow copy
					local newPayload = {}
					for k, v in pairs(oldPayload) do
						newPayload[k] = v
					end
					-- Increment # of kicsk
					newPayload["kicks"] = (newPayload["kicks"] or 0) + 1
					newPayload["lastKick"] = now
					return newPayload
				end)
			end)
		end)
		--local Controls = require(player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()---GetControls

		--Controls:Disable()
		wait(3)
		player.PlayerGui.MainUI.Banished.LocalScript.Disabled = false
		player.PlayerGui.MainUI.Banished.Banned.Visible = true
	end
end

local function onPlayerAdded(player)
	local payload
	pcall(function()
		payload = dsPlayerBans:GetAsync(getKey(player))
	end)
	if type(payload) == "table" then
		processPayload(player, payload)
	else
		-- No bans
	end
end

Players.PlayerAdded:connect(onPlayerAdded)
for _, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end
