-
-
Save lucko/cbef3c9e383201163371f68d6f4ea244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.donotspampls.velocityutils.commands; | |
import com.velocitypowered.api.command.Command; | |
import com.velocitypowered.api.command.CommandSource; | |
import com.velocitypowered.api.proxy.Player; | |
import com.velocitypowered.api.proxy.ProxyServer; | |
import net.kyori.text.TextComponent; | |
import net.kyori.text.format.TextColor; | |
import net.kyori.text.serializer.ComponentSerializers; | |
import javax.annotation.Nonnull; | |
import java.util.Arrays; | |
import java.util.Collection; | |
import java.util.stream.Collectors; | |
public class AlertCommand implements Command { | |
private final ProxyServer server; | |
public AlertCommand(ProxyServer server) { | |
this.server = server; | |
} | |
public void execute(@Nonnull CommandSource source, @Nonnull String[] args) { | |
if (source.hasPermission("velocityutils.alert")) { | |
if (args.length == 0) { | |
source.sendMessage(TextComponent.builder("You must supply a message.").color(TextColor.RED).build()); | |
} else { | |
String message = "&8[&4Alert&8] &r" + Arrays.stream(args).collect(Collectors.joining(" ")); | |
TextComponent component = ComponentSerializers.LEGACY.deserialize(message, '&'); | |
Collection<Player> players = server.getAllPlayers(); | |
for (Player p : players) { | |
p.sendMessage(component); | |
} | |
} | |
} else { | |
source.sendMessage(TextComponent.builder("You do not have permission to execute this command!").color(TextColor.RED).build()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment