mirror of
https://github.com/kaboomserver/extras.git
synced 2025-07-22 21:43:48 +00:00
Migrate commands to Adventure, add new commands
New additions are Adventure-centric.
This commit is contained in:
parent
6bb5f374e3
commit
04b8ce1c3c
22 changed files with 337 additions and 138 deletions
|
@ -1,5 +1,8 @@
|
|||
package pw.kaboom.extras.commands;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
|
@ -8,47 +11,56 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class CommandUsername implements CommandExecutor {
|
||||
private long millis;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String label,
|
||||
public boolean onCommand(final @Nonnull CommandSender sender,
|
||||
final @Nonnull Command command,
|
||||
final @Nonnull String label,
|
||||
final String[] args) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage("Command has to be run by a player");
|
||||
sender.sendMessage(Component
|
||||
.text("Command has to be run by a player"));
|
||||
} else {
|
||||
final Player player = (Player) sender;
|
||||
|
||||
final String nameColor = ChatColor.translateAlternateColorCodes(
|
||||
'&', String.join(" ", args));
|
||||
'&', String.join(" ", args));
|
||||
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
|
||||
final long millisDifference = System.currentTimeMillis() - millis;
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
player.sendMessage(Component
|
||||
.text("Usage: /" + label + " <username>",
|
||||
NamedTextColor.RED));
|
||||
} else if (name.equals(player.getName())) {
|
||||
player.sendMessage("You already have the username \"" + name + "\"");
|
||||
player.sendMessage(Component
|
||||
.text("You already have the username \"" + name + "\""));
|
||||
} else if (millisDifference <= 2000) {
|
||||
player.sendMessage("Please wait a few seconds before changing your username");
|
||||
player.sendMessage(Component
|
||||
.text("Please wait a few seconds before changing your username."));
|
||||
} else {
|
||||
if (Bukkit.getPlayer(name) != null
|
||||
&& Bukkit.getPlayer(name).isOnline()) {
|
||||
player.sendMessage("A player with that username is already logged in");
|
||||
if (Bukkit.getPlayer(name) != null) {
|
||||
player.sendMessage(Component
|
||||
.text("A player with that username is already logged in."));
|
||||
return true;
|
||||
}
|
||||
|
||||
final PlayerProfile profile = player.getPlayerProfile();
|
||||
|
||||
//FIXME Marked for removal
|
||||
profile.setName(name);
|
||||
|
||||
player.setPlayerProfile(profile);
|
||||
|
||||
millis = System.currentTimeMillis();
|
||||
|
||||
player.sendMessage("Successfully set your username to \"" + name + "\"");
|
||||
player.sendMessage(Component
|
||||
.text("Successfully set your username to \"" + name + "\""));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue