|
| 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 | +} |
0 commit comments