|
2 | 2 |
|
3 | 3 | import com.mojang.brigadier.arguments.IntegerArgumentType; |
4 | 4 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 5 | +import dev.plex.api.message.ActionBroadcast; |
5 | 6 | import dev.plex.command.SimplePlexCommand; |
6 | 7 | import dev.plex.extras.fun.Disco; |
7 | 8 | import io.papermc.paper.command.brigadier.CommandSourceStack; |
8 | 9 | import io.papermc.paper.command.brigadier.Commands; |
| 10 | +import java.util.concurrent.atomic.AtomicBoolean; |
9 | 11 | import net.kyori.adventure.text.Component; |
10 | 12 | import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
11 | 13 | import org.bukkit.Bukkit; |
@@ -62,10 +64,28 @@ private Component execute(CommandSender sender, @Nullable Player player, boolean |
62 | 64 | return null; |
63 | 65 | } |
64 | 66 |
|
| 67 | + ActionBroadcast announcement = api().messages().captureActionBroadcast(sender); |
| 68 | + AtomicBoolean announced = new AtomicBoolean(); |
| 69 | + Component message = messageComponent(seconds == null ? "discoEveryoneStopped" : "discoEveryoneStarted", |
| 70 | + Placeholder.unparsed("sender", sender.getName()), |
| 71 | + Placeholder.unparsed("seconds", String.valueOf(seconds))); |
| 72 | + Runnable done = () -> |
| 73 | + { |
| 74 | + if (announced.compareAndSet(false, true)) announcement.send(message); |
| 75 | + }; |
65 | 76 | for (String name : onlinePlayerNames()) |
66 | 77 | { |
67 | 78 | Player target = Bukkit.getPlayerExact(name); |
68 | | - if (target != null) apply(sender, target, seconds); |
| 79 | + if (target == null) continue; |
| 80 | + if (seconds == null) |
| 81 | + { |
| 82 | + if (disco.stop(target.getUniqueId())) done.run(); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + disco.start(target, seconds, done, () -> sender.sendMessage(messageComponent("funPlayerUnavailable", |
| 87 | + Placeholder.unparsed("player", target.getName())))); |
| 88 | + } |
69 | 89 | } |
70 | 90 | return null; |
71 | 91 | } |
|
0 commit comments