mirror of
https://github.com/kaboomserver/commandspy.git
synced 2025-02-05 06:22:51 +00:00
Update Paper API & use Adventure for chat messages (#9)
This commit is contained in:
parent
5933691f8c
commit
b7f20a595a
2 changed files with 24 additions and 18 deletions
5
pom.xml
5
pom.xml
|
@ -13,9 +13,10 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -17,6 +16,8 @@ import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
public final class Main extends JavaPlugin implements CommandExecutor, Listener {
|
public final class Main extends JavaPlugin implements CommandExecutor, Listener {
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
|
@ -31,27 +32,27 @@ public final class Main extends JavaPlugin implements CommandExecutor, Listener
|
||||||
private void enableCommandSpy(final Player player) {
|
private void enableCommandSpy(final Player player) {
|
||||||
config.set(player.getUniqueId().toString(), true);
|
config.set(player.getUniqueId().toString(), true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
player.sendMessage("Successfully enabled CommandSpy");
|
player.sendMessage(Component.text("Successfully enabled CommandSpy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableCommandSpy(final Player player) {
|
private void disableCommandSpy(final Player player) {
|
||||||
config.set(player.getUniqueId().toString(), null);
|
config.set(player.getUniqueId().toString(), null);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
player.sendMessage("Successfully disabled CommandSpy");
|
player.sendMessage(Component.text("Successfully disabled CommandSpy"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChatColor getChatColor(final Player player) {
|
private NamedTextColor getTextColor(final Player player) {
|
||||||
if (config.contains(player.getUniqueId().toString())) {
|
if (config.contains(player.getUniqueId().toString())) {
|
||||||
return ChatColor.YELLOW;
|
return NamedTextColor.YELLOW;
|
||||||
}
|
}
|
||||||
return ChatColor.AQUA;
|
return NamedTextColor.AQUA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label,
|
public boolean onCommand(final CommandSender sender, final Command cmd, final String label,
|
||||||
final String[] args) {
|
final String[] args) {
|
||||||
if (sender instanceof ConsoleCommandSender) {
|
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"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +78,10 @@ public final class Main extends JavaPlugin implements CommandExecutor, Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final ChatColor color = getChatColor(player);
|
final NamedTextColor color = getTextColor(player);
|
||||||
final String message = color + player.getName() + color + ": " + event.getMessage();
|
final Component message = Component.text(player.getName(), color)
|
||||||
|
.append(Component.text(": "))
|
||||||
|
.append(Component.text(event.getMessage()));
|
||||||
|
|
||||||
for (String uuidString : config.getKeys(false)) {
|
for (String uuidString : config.getKeys(false)) {
|
||||||
final UUID uuid = UUID.fromString(uuidString);
|
final UUID uuid = UUID.fromString(uuidString);
|
||||||
|
@ -94,9 +97,15 @@ public final class Main extends JavaPlugin implements CommandExecutor, Listener
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onSignChange(final SignChangeEvent event) {
|
void onSignChange(final SignChangeEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final ChatColor color = getChatColor(player);
|
final NamedTextColor color = getTextColor(player);
|
||||||
final String message = color + player.getName() + color
|
Component message = Component.text(player.getName(), color)
|
||||||
+ " created a sign with contents:";
|
.append(Component.text(" created a sign with contents:"));
|
||||||
|
|
||||||
|
for (Component line : event.lines()) {
|
||||||
|
message = message
|
||||||
|
.append(Component.text("\n "))
|
||||||
|
.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
for (String uuidString : config.getKeys(false)) {
|
for (String uuidString : config.getKeys(false)) {
|
||||||
final UUID uuid = UUID.fromString(uuidString);
|
final UUID uuid = UUID.fromString(uuidString);
|
||||||
|
@ -106,10 +115,6 @@ public final class Main extends JavaPlugin implements CommandExecutor, Listener
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
recipient.sendMessage(message);
|
recipient.sendMessage(message);
|
||||||
|
|
||||||
for (String line : event.getLines()) {
|
|
||||||
recipient.sendMessage(color + " " + line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue