-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.lua
More file actions
executable file
·50 lines (40 loc) · 1.2 KB
/
controller.lua
File metadata and controls
executable file
·50 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local PlayerQuitEvent = import("org.bukkit.event.player.PlayerQuitEvent")
---Used for controlling player scoreboard instances.
---```lua
---paman.need("bukkit/scoreboard/controller")
---```
local this = {}
this.mainBoard = bukkit.scoreboard.getMain()
---uuid -> scoreboard
this.cache = makeMap() ---@type java.Map<string, bukkit.scoreboard.Scoreboard>
---@param player java.Object
---@param create? boolean=`true`
function this.get(player, create)
local id = bukkit.uuid(player)
---@type bukkit.scoreboard.Scoreboard?
local board = this.cache.get(id)
if board == nil and create ~= false then
board = bukkit.scoreboard.getNew()
this.cache.put(id, board)
player.setScoreboard(board)
end
return board
end
---@param player java.Object
function this.delete(player)
local id = bukkit.uuid(player)
if this.cache.remove(id) ~= nil then
player.setScoreboard(this.mainBoard)
end
end
function this.deleteAll()
for p in bukkit.playersLoop() do
this.delete(p)
end
this.cache.clear()
end
events.onStopping(this.deleteAll)
events.listen(PlayerQuitEvent, function(event)
this.delete(event.getPlayer())
end)
bukkit.scoreboard.controller = this