Skip to content

Commit 1d0237d

Browse files
committed
Added StaffAfkCommand and edited config to add placeholders to AFK messages.
1 parent e353973 commit 1d0237d

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* UltraStaffChat BungeeCord - A 100% Customizable StaffChat Plugin for BungeeCord!
3+
* Copyright (C) 2021 SLLCoding
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package dev.hypera.ultrastaffchat.commands.impl;
20+
21+
import dev.hypera.ultrastaffchat.UltraStaffChat;
22+
import dev.hypera.ultrastaffchat.commands.Command;
23+
import dev.hypera.ultrastaffchat.utils.Common;
24+
import net.kyori.adventure.audience.Audience;
25+
import net.md_5.bungee.api.CommandSender;
26+
import net.md_5.bungee.api.connection.ProxiedPlayer;
27+
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
import java.util.UUID;
31+
32+
public class StaffAfkCommand extends Command {
33+
34+
public StaffAfkCommand() {
35+
super("staffchatafk", null, "scafk");
36+
}
37+
38+
@Override
39+
public void execute(CommandSender sender, String[] args) {
40+
Audience audience = UltraStaffChat.getInstance().getAdventure().sender(sender);
41+
42+
if(!sender.hasPermission(UltraStaffChat.getConfig().getString("permission-afk"))) {
43+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("no-permission")));
44+
return;
45+
}
46+
47+
if(!(sender instanceof ProxiedPlayer)) {
48+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("ingame-only")));
49+
return;
50+
}
51+
52+
ProxiedPlayer p = (ProxiedPlayer) sender;
53+
boolean toggled = toggleAfk(p);
54+
Audience all = UltraStaffChat.getInstance().getAdventure().permission(UltraStaffChat.getConfig().getString("permission-read"));
55+
if(toggled) {
56+
all.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("afk-broadcast").replaceAll("\\{player}", p.getName())));
57+
} else
58+
all.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("no-afk-broadcast").replaceAll("\\{player}", p.getName())));
59+
}
60+
61+
@Override
62+
public boolean isDisabled() {
63+
return !UltraStaffChat.getConfig().getBoolean("afk-enabled");
64+
}
65+
66+
private final Map<UUID, Boolean> afkStatus = new HashMap<>();
67+
68+
private boolean toggleAfk(ProxiedPlayer player) {
69+
if (!afkStatus.containsKey(player.getUniqueId())) {
70+
afkStatus.put(player.getUniqueId(), true);
71+
return true;
72+
} else {
73+
boolean oldAfk = afkStatus.get(player.getUniqueId());
74+
afkStatus.replace(player.getUniqueId(), !oldAfk);
75+
return !oldAfk;
76+
}
77+
}
78+
79+
}

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ mute-staffchat-usage: "&cUsage: /mutesc <state>"
282282
afk-enabled: true
283283

284284
# AFK | Message
285+
# - Placeholders: Player - {player}
285286
afk-broadcast: "&7{player} is now &c&lAFK&7."
286287

287288
# AFK | No longer AFK Message
289+
# - Placeholders: Player - {player}
288290
no-afk-broadcast: "&7{player} is no longer &c&lAFK&7."
289291

290292

0 commit comments

Comments
 (0)