Initaaaaaa
This commit is contained in:
parent
714fdcc312
commit
f95ccd11c0
5
pom.xml
5
pom.xml
@ -76,5 +76,10 @@
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.17.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -2,6 +2,8 @@ package org.twipnetwork.colorfulwords;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@ -16,10 +18,21 @@ public class ChatListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
String colorHex = plugin.getPlayerColor(event.getPlayer().getUniqueId());
|
||||
if (colorHex != null) {
|
||||
TextColor color = TextColor.fromHexString(colorHex);
|
||||
String coloredMessage = Component.text(event.getMessage()).color(color).toString();
|
||||
event.setFormat("%1$s: " + coloredMessage);
|
||||
if (colorHex == null) {
|
||||
colorHex = "#ffffff";
|
||||
}
|
||||
String playerName = event.getPlayer().getName();
|
||||
String messageContent = event.getMessage();
|
||||
TextColor color = TextColor.fromHexString(colorHex);
|
||||
var mm = MiniMessage.miniMessage();
|
||||
var recipents = event.getRecipients();
|
||||
var newmessage = mm.deserialize(
|
||||
"<white><<" + color + ">" + playerName + "</" + color + ">></white> <" + color + ">" + messageContent + "</" + color + ">"
|
||||
);
|
||||
for (Player recipient :recipents){
|
||||
recipient.sendMessage(newmessage);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,43 @@
|
||||
package org.twipnetwork.colorfulwords;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ColorCommand implements CommandExecutor {
|
||||
private final ColorfulWords plugin;
|
||||
private final MiniMessage mm;
|
||||
|
||||
public ColorCommand(ColorfulWords plugin) {
|
||||
this.mm = MiniMessage.miniMessage();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage("This command can only be used by players.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (args.length != 1) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /color <hex>|reset");
|
||||
player.sendMessage(mm.deserialize("<red>Usage: /color <hex>|reset</red>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
String colorHex = args[0];
|
||||
if (colorHex.equalsIgnoreCase("reset")) {
|
||||
plugin.resetPlayerColor(player.getUniqueId());
|
||||
player.sendMessage(ChatColor.GREEN + "Your chat color has been reset.");
|
||||
player.sendMessage(mm.deserialize("<green>Your chat color has been reset.</green>"));
|
||||
} else if (colorHex.matches("^#[a-fA-F0-9]{6}$")) {
|
||||
plugin.setPlayerColor(player.getUniqueId(), colorHex);
|
||||
player.sendMessage(ChatColor.GREEN + "Your chat color has been set to " + colorHex + ".");
|
||||
player.sendMessage(mm.deserialize("<green>Your chat color has been set to </green><" + colorHex + ">" + colorHex + "<green>."));
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Invalid hex color. Please use a valid hex code.");
|
||||
player.sendMessage(mm.deserialize("<red>Invalid hex color. Please use a valid hex code.</red>"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -3,6 +3,7 @@ package org.twipnetwork.colorfulwords;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ColorfulWords extends JavaPlugin {
|
||||
@ -12,7 +13,7 @@ public final class ColorfulWords extends JavaPlugin {
|
||||
// Plugin startup logic
|
||||
saveDefaultConfig();
|
||||
getServer().getPluginManager().registerEvents(new ChatListener(this), this);
|
||||
getCommand("color").setExecutor(new ColorCommand(this));
|
||||
Objects.requireNonNull(getCommand("color")).setExecutor(new ColorCommand(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user