-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cross-platform console interfaces
Similar to MCPlayer, MCConsole has been added, along with its respecting SpigotConsole and VelocityConsole variants.
- Loading branch information
Showing
4 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
platforms/spigot/src/main/java/net/codersky/mcutils/spigot/SpigotConsole.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.codersky.mcutils.spigot; | ||
|
||
import net.codersky.mcutils.crossplatform.MCConsole; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class SpigotConsole implements MCConsole<ConsoleCommandSender> { | ||
|
||
private final ConsoleCommandSender handle; | ||
|
||
SpigotConsole(@NotNull ConsoleCommandSender handle) { | ||
this.handle = handle; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ConsoleCommandSender getHandle() { | ||
return handle; | ||
} | ||
|
||
@Override | ||
public boolean sendMessage(@Nullable String message) { | ||
if (message != null) | ||
handle.sendMessage(message); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean sendMessage(@Nullable Component message) { | ||
if (message != null) | ||
handle.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)); | ||
return true; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
platforms/velocity/src/main/java/net/codersky/mcutils/velocity/VelocityConsole.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.codersky.mcutils.velocity; | ||
|
||
import com.velocitypowered.api.proxy.ConsoleCommandSource; | ||
import net.codersky.mcutils.crossplatform.MCConsole; | ||
import net.kyori.adventure.text.Component; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class VelocityConsole implements MCConsole<ConsoleCommandSource> { | ||
|
||
private final ConsoleCommandSource handle; | ||
|
||
VelocityConsole(@NotNull ConsoleCommandSource handle) { | ||
this.handle = handle; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ConsoleCommandSource getHandle() { | ||
return handle; | ||
} | ||
|
||
@Override | ||
public boolean sendMessage(@Nullable String message) { | ||
if (message != null) | ||
handle.sendMessage(Component.text(message)); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean sendMessage(@Nullable Component message) { | ||
if (message != null) | ||
handle.sendMessage(message); | ||
return true; | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
shared/src/main/java/net/codersky/mcutils/crossplatform/MCConsole.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.codersky.mcutils.crossplatform; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Interface used to represent a server or proxy console. | ||
* | ||
* @param <T> The platform-specific console object | ||
* | ||
* @since MCUtils 1.0.0 | ||
* | ||
* @author xDec0de_ | ||
*/ | ||
public interface MCConsole<T> extends MessageReceiver { | ||
|
||
/** | ||
* Gets the platform-specific object that is being wrapped by | ||
* this {@link MCConsole} instance. This can be, for example, a | ||
* Bukkit ConsoleCommandSender instance. | ||
* | ||
* @return The platform-specific object that is being wrapped by | ||
* this {@link MCConsole} instance. | ||
* | ||
* @since MCUtils 1.0.0 | ||
*/ | ||
@NotNull | ||
T getHandle(); | ||
} |