Skip to content

Commit 5e45a67

Browse files
committed
sender uses audience now
1 parent fa6b827 commit 5e45a67

File tree

1 file changed

+41
-49
lines changed

1 file changed

+41
-49
lines changed

src/main/java/gg/quartzdev/lib/qlibpaper/Sender.java

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,62 @@
1010
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1111
import org.bukkit.Bukkit;
1212
import org.bukkit.command.CommandSender;
13+
import org.bukkit.command.ConsoleCommandSender;
1314
import org.bukkit.entity.Player;
1415

1516
/**
16-
* Easy way to send information to a player or console. All text messages supports MiniMessage format
17+
* Easy way to send information to a player or console. All messages support MiniMessage format
1718
*/
1819
public class Sender {
20+
1921
/**
20-
* Sends a message to the player in chat. If the message is empty, nothing is sent
21-
* @param sender the {@link CommandSender} to send the message to
22-
* @param message the message as a {@link String} to send supporting MiniMessage formatting
22+
* Sends a message to an audience in chat
23+
* @param audience the audience to send the message to
24+
* @param message the message to send
2325
*/
24-
public static void message(CommandSender sender, String message){
25-
if(message.isEmpty())
26-
return;
27-
sender.sendMessage(parse(message, !(sender instanceof Player)));
28-
}
29-
30-
public static void message(Audience audience, QMessage message){
31-
if(message.get().isEmpty())
32-
return;
33-
audience.sendMessage(parse(message.get(), false));
34-
}
3526
public static void message(Audience audience, String message){
3627
if(message.isEmpty())
3728
return;
38-
audience.sendMessage(parse(message, false));
39-
}
40-
41-
/**
42-
* Sends a Message to the player in chat
43-
* @param sender the {@link CommandSender} to send the message to
44-
* @param message the {@link QMessage} to send supporting MiniMessage formatting
45-
*/
46-
public static void message(CommandSender sender, QMessage message){
47-
message(sender, message.get());
29+
audience.sendMessage(parse(message, audience instanceof ConsoleCommandSender));
4830
}
4931

5032
/**
51-
* Sends a message to the player in chat
52-
* @param player the {@link Player} to send the message to
53-
* @param message the message to send
33+
* Sends a {@link QMessage} to an audience in chat. This just calls {@link #message(Audience, String)} by using {@link QMessage#get()}
34+
* @param audience the audience to send the message to
35+
* @param message the {@link QMessage} to send
5436
*/
55-
public static void message(Player player, QMessage message){
56-
message(player, message.get());
37+
public static void message(Audience audience, QMessage message){
38+
message(audience, message.get());
5739
}
5840

5941
/**
60-
* Sends a message to the player in chat
61-
* @param player the {@link Player} to send the message to
62-
* @param message the message to send
42+
* Sends an action bar to an audience
43+
* @param audience the audience to send the actionbar to
44+
* @param message the message to send supporting MiniMessage formatting
6345
*/
64-
public static void message(Player player, String message){
65-
player.sendMessage(parse(message, false));
66-
46+
public static void actionBar(Audience audience, String message){
47+
if(message.isEmpty()){
48+
return;
49+
}
50+
audience.sendActionBar(parse(message, false));
6751
}
6852

6953
/**
70-
* Sends an action bar to a player
71-
* @param player the player to send the actionbar to
72-
* @param message the message to send supporting MiniMessage formatting
54+
* Sends an action bar to an audience. This just calls {@link #actionBar(Audience, String)} by using {@link QMessage#get()}
55+
* @param audience the audience to send the actionbar to
56+
* @param message the {@link QMessage} to send supporting MiniMessage formatting
7357
*/
74-
public static void actionBar(Player player, String message){
75-
player.sendActionBar(parse(message, false));
58+
public static void actionBar(Audience audience, QMessage message){
59+
actionBar(audience, message.get());
7660
}
7761

7862
/**
79-
* Sends an action bar to a player
80-
* @param player the player to send the actionbar to
81-
* @param message the {@link QMessage} to send supporting MiniMessage formatting
63+
* Sends a sound to an audience
64+
* @param audience the audience to send the sound to
65+
* @param sound the adventure {@link Sound} to send
8266
*/
83-
public static void actionBar(Player player, QMessage message){
84-
player.sendActionBar(parse(message.get(), false));
67+
public static void sound(Audience audience, Sound sound){
68+
audience.playSound(sound);
8569
}
8670

8771
/**
@@ -90,22 +74,30 @@ public static void actionBar(Player player, QMessage message){
9074
*/
9175
public static void broadcast(String message){
9276
// Sends a message to all online players
93-
Audience.audience(Bukkit.getOnlinePlayers()).sendMessage(parse(message, false));
77+
message(Audience.audience(Bukkit.getOnlinePlayers()), message);
9478
// Sends a message to the consoles
9579
message(Bukkit.getConsoleSender(), message);
9680
}
9781

82+
/**
83+
* Broadcast a message to all online players including the console. This just calls {@link #broadcast(String)} by using {@link QMessage#get()}
84+
* @param message the {@link QMessage} to send supporting MiniMessage formatting
85+
*/
86+
public static void broadcast(QMessage message){
87+
broadcast(message.get());
88+
}
89+
9890
/**
9991
* Broadcast a sound to all online players, and logs it to the console
100-
* @param sound the {@link Sound} to broadcast. The examinableName is what's logged to the console
92+
* @param sound the adventure {@link Sound} to broadcast. The {@link Sound#examinableName()} is what's logged to the console
10193
*/
10294
public static void broadcast(Sound sound){
10395
Audience.audience(Bukkit.getOnlinePlayers()).playSound(sound);
10496
GenericMessages.LOG_BROADCAST_SOUND.parse(QPlaceholder.SOUND, sound.examinableName());
10597
}
10698

10799
/**
108-
* Deserializes the message into a {@link Component} and parses any MiniMessage placeholders along the plugin <prefix>
100+
* Deserializes the message into an adventure {@link Component} and parses any MiniMessage placeholders including the plugin <prefix>
109101
* @param message the message to parse
110102
* @param isConsole whether the <prefix> is replaced with the console or chat prefix
111103
* @return A MiniMessage deserialized chat {@link Component}

0 commit comments

Comments
 (0)