Replaces ChatColor with adventure text.

This commit is contained in:
Tom Hicks
2025-07-14 10:40:59 -07:00
parent eaaafa3fee
commit 116ec79bc7
8 changed files with 216 additions and 134 deletions

View File

@@ -1,3 +1,6 @@
{
"[java]": {
"editor.formatOnSave": true
},
"java.configuration.updateBuildConfiguration": "interactive"
}

View File

@@ -1,10 +1,10 @@
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
}
group = 'com.majinnaibu.minecraft.plugins.'
version = '0.2.0-SNAPSHOT'
group = 'com.majinnaibu.minecraft.plugins'
version = '0.2.1-SNAPSHOT'
description = "ScoreKeeper"
java {
@@ -13,6 +13,14 @@ java {
}
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}
repositories {
mavenCentral()
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
@@ -27,7 +35,12 @@ tasks.withType(JavaCompile).configureEach {
// options.compilerArgs << "-Xlint:deprecation"
}
tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}
processResources {
inputs.property "version", project.version
filesMatching('plugin.yml') {
expand(project.properties)
}

View File

@@ -2,7 +2,12 @@ package com.majinnaibu.minecraft.plugins.scorekeeper;
import java.util.HashMap;
import java.util.UUID;
import java.util.logging.Level;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
@@ -15,10 +20,15 @@ import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractComman
public class ScoreKeeperPlugin extends JavaPlugin {
private final HashMap<UUID, Integer> _playerScores = new HashMap<UUID, Integer>();
public final String _logPrefix = "[ScoreKeeper] ";
public final Component _messagePrefix = Component.text("[")
.append(Component.text("ScoreKeeper").color(NamedTextColor.AQUA))
.append(Component.text("] ").color(NamedTextColor.WHITE));
@Override
public void onDisable() {
//TODO: save score data to file
logWarning("Unable to save scores to file. This feature is not implemented yet.");
}
@Override
@@ -30,34 +40,68 @@ public class ScoreKeeperPlugin extends JavaPlugin {
getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this));
//TODO: load score data from file
logWarning("Unable to load scores from file. This feature is not implemented yet.");
PluginDescriptionFile pdFile = this.getDescription();
getLogger().info(pdFile.getName() + " version " + pdFile.getVersion() + " is enabled!");
logInfo(getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
}
public int getPlayerScore(Player player) {
//region Commands
public void addScore(Player player, int amount) {
int oldScore = getPlayerScore(player);
setPlayerScore(player, oldScore + amount);
}
public void archiveScore(Player player) {
logWarning("Unable to archive score for " + player.getName() + ".");
}
public int getScore(Player player) {
return getPlayerScore(player);
}
public void resetScore(Player player) {
setPlayerScore(player, 0);
}
public void setScore(Player player, int score) {
setPlayerScore(player, score);
}
public void subtractScore(Player player, int amount) {
int oldScore = getPlayerScore(player);
setPlayerScore(player, oldScore - amount);
}
//endregion
//region Utiilty Methods
public void sendMessage(CommandSender reciever, Component message) {
reciever.sendMessage(_messagePrefix.append(message));
}
private int getPlayerScore(Player player) {
UUID uuid = player.getUniqueId();
if(!_playerScores.containsKey(uuid)){
_playerScores.put(uuid, 0);
}
return _playerScores.get(uuid);
}
public void addScore(Player player, int amount) {
UUID uuid = player.getUniqueId();
int score = getPlayerScore(player);
_playerScores.put(uuid, score + amount);
private void setPlayerScore(Player player, int score) {
_playerScores.put(player.getUniqueId(), score);
}
//endregion
//region Logging
public void logError(Exception ex) {
getLogger().log(Level.SEVERE, _logPrefix + ex.toString());
}
public void subtractScore(Player player, int amount) {
UUID uuid = player.getUniqueId();
int score = getPlayerScore(player);
_playerScores.put(uuid, score - amount);
public void logInfo(String message) {
getLogger().info(_logPrefix + message);
}
public void resetPlayerScore(Player targetPlayer) {
// TODO Auto-generated method stub
public void logWarning(String message) {
getLogger().warning(_logPrefix + message);
}
//endregion
}

View File

@@ -1,6 +1,8 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -62,14 +64,23 @@ public class ScoreAddCommand implements CommandExecutor {
}
private void echoError(CommandSender sender, boolean rcon, String string) {
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
_plugin.sendMessage(sender, Component.text(string).color(NamedTextColor.RED));
}
private void echoUsage(CommandSender sender, boolean rcon) {
if(rcon){
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-add " + ChatColor.GREEN + "<playername> <amount>");
Component message =
Component.text("Usage").color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": score-add ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName> <amount>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}else{
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-add " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>");
Component message =
Component.text("Usage").color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": /score-add ").color(NamedTextColor.WHITE))
.append(Component.text("[playerName] ").color(NamedTextColor.YELLOW))
.append(Component.text("<amount>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}
}
}

View File

@@ -1,6 +1,8 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -22,15 +24,7 @@ public class ScoreArchiveCommand implements CommandExecutor {
String label,
String[] split
) {
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented ");
if(sender instanceof Player){
Player player = (Player) sender;
int score = _plugin.getPlayerScore(player);
player.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] Your score is " + ChatColor.GREEN + score);
_plugin.sendMessage(sender, Component.text("archive command unimplemented"));
return true;
}else{
return false;
}
}
}

View File

@@ -1,6 +1,8 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -44,32 +46,40 @@ public class ScoreGetCommand implements CommandExecutor {
return true;
}
int score = _plugin.getPlayerScore(targetPlayer);
int score = _plugin.getScore(targetPlayer);
if(!rcon){
if(sender == targetPlayer){
targetPlayer.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] Your score is " + ChatColor.GREEN + score);
_plugin.sendMessage(targetPlayer, Component.text("Your score is ").append(Component.text(score).color(NamedTextColor.GREEN)));
}else{
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] " + targetPlayer.getName() + "'s score is " + ChatColor.GREEN + score);
_plugin.sendMessage(sender, Component.text(targetPlayer.getName() + "'s score is ").append(Component.text(score).color(NamedTextColor.GREEN)));
}
return true;
}else{
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] " + targetPlayer.getName() + "'s score is " + ChatColor.GREEN + score);
_plugin.sendMessage(sender,
Component.text(targetPlayer.getName() + "'s score is ").append(Component.text(score).color(NamedTextColor.GREEN)));
return true;
}
}
private void echoError(CommandSender sender, boolean rcon, String string) {
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
_plugin.sendMessage(sender, Component.text(string).color(NamedTextColor.RED));
}
private void echoUsage(CommandSender sender, boolean rcon) {
if(rcon){
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-get " + ChatColor.GREEN + "<playername>");
Component message =
Component.text("Usage").color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": score-get ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}else{
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-get " + ChatColor.YELLOW + "[playername]");
}
Component message =
Component.text("Usage").color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": /score-get ").color(NamedTextColor.WHITE))
.append(Component.text("[playerName]").color(NamedTextColor.YELLOW));
_plugin.sendMessage(sender, message);
}
}
}

View File

@@ -1,6 +1,8 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -22,55 +24,48 @@ public class ScoreResetCommand implements CommandExecutor {
String label,
String[] split
) {
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented ");
boolean rcon = !(sender instanceof Player);
Player targetPlayer = null;
if(split.length == 1){
if(split.length == 0){
if(rcon){
echoUsage(sender, rcon);
return true;
}else{
targetPlayer = (Player)sender;
try{
}catch(NumberFormatException ex){
echoError(sender, rcon, "amount must be an integer");
return true;
}
}
}else if(split.length == 2){
}else if(split.length == 1){
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
if(targetPlayer == null){
echoError(sender, rcon, "Can't find a player with that name");
return true;
}
try{
}catch(NumberFormatException ex){
echoError(sender, rcon, "amount must be an integer");
return true;
}
}else{
echoUsage(sender, rcon);
return true;
}
_plugin.resetPlayerScore(targetPlayer);
_plugin.resetScore(targetPlayer);
return true;
}
private void echoError(CommandSender sender, boolean rcon, String string) {
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
_plugin.sendMessage(sender, Component.text(string).color(NamedTextColor.RED));
}
private void echoUsage(CommandSender sender, boolean rcon) {
if(rcon){
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-reset " + ChatColor.GREEN + "<playername>");
Component message =
Component.text("Usage").color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": score-reset ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}else{
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-reset " + ChatColor.YELLOW + "[playername]");
Component message =
Component.text("Usage").color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": /score-reset ").color(NamedTextColor.WHITE))
.append(Component.text("[playerName]").color(NamedTextColor.YELLOW));
_plugin.sendMessage(sender, message);
}
}
}

View File

@@ -1,12 +1,13 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
import org.bukkit.ChatColor;
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
public class ScoreSubtractCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
@@ -16,12 +17,8 @@ public class ScoreSubtractCommand implements CommandExecutor {
}
@Override
public boolean onCommand(
CommandSender sender,
Command command,
String label,
String[] split
) {
public boolean onCommand(CommandSender sender, Command command, String label,
String[] split) {
boolean rcon = !(sender instanceof Player);
int amount = 0;
Player targetPlayer = null;
@@ -62,14 +59,29 @@ public class ScoreSubtractCommand implements CommandExecutor {
}
private void echoError(CommandSender sender, boolean rcon, String string) {
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
_plugin.sendMessage(sender,
Component.text(string).color(NamedTextColor.RED));
}
private void echoUsage(CommandSender sender, boolean rcon) {
if (rcon) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-subtract " + ChatColor.GREEN + "<playername> <amount>");
Component message = Component.text("Usage")
.color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": score-subtract ")
.color(NamedTextColor.WHITE))
.append(Component.text("<playerName> <amount>")
.color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
} else {
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-subtract " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>");
Component message =
Component.text("Usage")
.color(NamedTextColor.DARK_PURPLE)
.append(Component.text(": /score-subtract ")
.color(NamedTextColor.WHITE))
.append(
Component.text("[playerName] ").color(NamedTextColor.YELLOW))
.append(Component.text("<amount>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}
}
}