Skip to content

Commit

Permalink
Added MessageReceiver#getName
Browse files Browse the repository at this point in the history
  • Loading branch information
xDec0de committed Nov 2, 2024
1 parent 482d7d4 commit bb636b5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.codersky.mcutils.spigot;

import net.codersky.mcutils.crossplatform.MCConsole;
import net.codersky.mcutils.spigot.cmd.SpigotCommandSender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,6 +22,19 @@ public ConsoleCommandSender getHandle() {
return handle;
}

/**
* Gets the name of this {@link SpigotConsole}. This just
* falls back to {@link CommandSender#getName()}.
*
* @return The name of this {@link SpigotConsole}.
*
* @since MCUtils 1.0.0
*/
@Override
public @NotNull String getName() {
return handle.getName();
}

@Override
public boolean sendMessage(@NotNull String message) {
handle.sendMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public SpigotConsole asConsole() {
* Messages
*/

/**
* Gets the name of this {@link SpigotCommandSender}. This just
* falls back to {@link CommandSender#getName()}.
*
* @return The name of this {@link SpigotCommandSender}.
*
* @since MCUtils 1.0.0
*/
@NotNull
@Override
public String getName() {
return sender.getName();
}

@Override
public boolean sendMessage(@NotNull String message) {
sender.sendMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ public ConsoleCommandSource getHandle() {
return handle;
}

/**
* Gets the name of this {@link VelocityConsole}, which just
* returns "Console".
*
* @return The name of this {@link VelocityConsole}.
*
* @since MCUtils 1.0.0
*/
@Override
public @NotNull String getName() {
return "Console";
}

@Override
public boolean sendMessage(@NotNull String message) {
return sendMessage(Component.text(message));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public ConsoleCommandSource asConsoleHandle() {
* Messages
*/

/**
* Gets the name of this {@link VelocityCommandSender}. If
* {@link #isPlayer()} is {@code true}, {@link Player#getUsername()}
* is used, otherwise <i>"Console"</i> is returned.
*
* @return The name of this {@link VelocityCommandSender}.
*
* @since MCUtils 1.0.0
*/
@NotNull
@Override
public String getName() {
final Player player = asPlayerHandle();
return player == null ? "Console" : player.getUsername();
}

@Override
public boolean sendMessage(@NotNull String message) {
source.sendPlainMessage(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.codersky.mcutils.crossplatform;

import net.codersky.mcutils.cmd.MCCommand;
import net.codersky.mcutils.cmd.MCCommandSender;
import net.codersky.mcutils.crossplatform.player.MCPlayer;
import net.codersky.mcutils.java.strings.Replacer;
import net.kyori.adventure.text.Component;
Expand All @@ -22,6 +23,25 @@
*/
public interface MessageReceiver {

/**
* Gets the name of this {@link MessageReceiver}. The way this works
* can vary depending on the platform and implementation, details are
* provided on the documentation of each implementation, but here is
* a not so detailed list of what you can expect, this only includes
* player and console types that implement {@link MCPlayer},
* {@link MCConsole} and {@link MCCommandSender}:
* <ul>
* <li>Spigot: <i>CommandSender#getName</i></li>
* <li>Velocity: <i>Player#getUsername</i> or <i>"Console"</i>.</li>
* </ul>
*
* @return The name of this {@link MessageReceiver}.
*
* @since MCUtils 1.0.0
*/
@NotNull
String getName();

/*
* Legacy messages (String)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.jetbrains.annotations.NotNull;

/**
* Class used to do fast performance as of right now,
* Class used to do fast performance tests. Currently,
* this class uses {@link ThreadMXBean#getCurrentThreadCpuTime()}
* to get the actual execution time of the methods, as well as creating
* a new {@link Thread} every time a test runs, sleeping before every execution
Expand Down

0 comments on commit bb636b5

Please sign in to comment.