added AdminChat
This commit is contained in:
parent
b1427ac90e
commit
bc84b06f0d
@ -0,0 +1,37 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.adminChat;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AdminChat extends Appliance {
|
||||||
|
public void sendMessage(Player sender, String message) {
|
||||||
|
Component privatePrefix = Component
|
||||||
|
.text("[Admin] ", NamedTextColor.LIGHT_PURPLE)
|
||||||
|
.clickEvent(ClickEvent.suggestCommand(AdminChatCommand.commandName));
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> player.hasPermission("admin"))
|
||||||
|
.forEach(player -> {
|
||||||
|
Component formattedMessage = Component.text()
|
||||||
|
.append(privatePrefix)
|
||||||
|
.append(sender.displayName())
|
||||||
|
.append(Component.text(" > ", NamedTextColor.DARK_GRAY))
|
||||||
|
.append(Component.text(message))
|
||||||
|
.build();
|
||||||
|
player.sendMessage(formattedMessage);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
|
return List.of(new AdminChatCommand());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.adminChat;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class AdminChatCommand extends ApplianceCommand.PlayerChecked<AdminChat> {
|
||||||
|
public static final String commandName = "adminchat";
|
||||||
|
|
||||||
|
public AdminChatCommand() {
|
||||||
|
super(commandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||||
|
if(!sender.hasPermission("admin")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = String.join(" ", args);
|
||||||
|
getAppliance().sendMessage(getPlayer(), message);
|
||||||
|
}
|
||||||
|
}
|
@ -43,3 +43,5 @@ commands:
|
|||||||
msg:
|
msg:
|
||||||
r:
|
r:
|
||||||
playtime:
|
playtime:
|
||||||
|
adminchat:
|
||||||
|
aliases: [ "sc" ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user