Replaces ChatColor with adventure text.
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"[java]": {
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
"java.configuration.updateBuildConfiguration": "interactive"
|
"java.configuration.updateBuildConfiguration": "interactive"
|
||||||
}
|
}
|
||||||
21
build.gradle
21
build.gradle
@@ -1,10 +1,10 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.majinnaibu.minecraft.plugins.'
|
group = 'com.majinnaibu.minecraft.plugins'
|
||||||
version = '0.2.0-SNAPSHOT'
|
version = '0.2.1-SNAPSHOT'
|
||||||
|
|
||||||
description = "ScoreKeeper"
|
description = "ScoreKeeper"
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@@ -13,6 +13,14 @@ java {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
maven(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
|
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
|
||||||
@@ -27,7 +35,12 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
// options.compilerArgs << "-Xlint:deprecation"
|
// options.compilerArgs << "-Xlint:deprecation"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType(Javadoc).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
inputs.property "version", project.version
|
||||||
filesMatching('plugin.yml') {
|
filesMatching('plugin.yml') {
|
||||||
expand(project.properties)
|
expand(project.properties)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ package com.majinnaibu.minecraft.plugins.scorekeeper;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
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.entity.Player;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -15,10 +20,15 @@ import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractComman
|
|||||||
|
|
||||||
public class ScoreKeeperPlugin extends JavaPlugin {
|
public class ScoreKeeperPlugin extends JavaPlugin {
|
||||||
private final HashMap<UUID, Integer> _playerScores = new HashMap<UUID, Integer>();
|
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
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
//TODO: save score data to file
|
//TODO: save score data to file
|
||||||
|
logWarning("Unable to save scores to file. This feature is not implemented yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,34 +40,68 @@ public class ScoreKeeperPlugin extends JavaPlugin {
|
|||||||
getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this));
|
getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this));
|
||||||
|
|
||||||
//TODO: load score data from file
|
//TODO: load score data from file
|
||||||
|
logWarning("Unable to load scores from file. This feature is not implemented yet.");
|
||||||
|
|
||||||
PluginDescriptionFile pdFile = this.getDescription();
|
logInfo(getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
|
||||||
getLogger().info(pdFile.getName() + " version " + pdFile.getVersion() + " is enabled!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlayerScore(Player player) {
|
|
||||||
UUID uuid = player.getUniqueId();
|
|
||||||
if(!_playerScores.containsKey(uuid)){
|
|
||||||
_playerScores.put(uuid, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _playerScores.get(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//region Commands
|
||||||
public void addScore(Player player, int amount) {
|
public void addScore(Player player, int amount) {
|
||||||
UUID uuid = player.getUniqueId();
|
int oldScore = getPlayerScore(player);
|
||||||
int score = getPlayerScore(player);
|
setPlayerScore(player, oldScore + amount);
|
||||||
_playerScores.put(uuid, score + 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) {
|
public void subtractScore(Player player, int amount) {
|
||||||
UUID uuid = player.getUniqueId();
|
int oldScore = getPlayerScore(player);
|
||||||
int score = getPlayerScore(player);
|
setPlayerScore(player, oldScore - amount);
|
||||||
_playerScores.put(uuid, score - amount);
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region Utiilty Methods
|
||||||
|
public void sendMessage(CommandSender reciever, Component message) {
|
||||||
|
reciever.sendMessage(_messagePrefix.append(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetPlayerScore(Player targetPlayer) {
|
private int getPlayerScore(Player player) {
|
||||||
// TODO Auto-generated method stub
|
UUID uuid = player.getUniqueId();
|
||||||
|
if(!_playerScores.containsKey(uuid)){
|
||||||
|
_playerScores.put(uuid, 0);
|
||||||
|
}
|
||||||
|
return _playerScores.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 logInfo(String message) {
|
||||||
|
getLogger().info(_logPrefix + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logWarning(String message) {
|
||||||
|
getLogger().warning(_logPrefix + message);
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
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.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -62,14 +64,23 @@ public class ScoreAddCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
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) {
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
if(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{
|
}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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
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.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -22,15 +24,7 @@ public class ScoreArchiveCommand implements CommandExecutor {
|
|||||||
String label,
|
String label,
|
||||||
String[] split
|
String[] split
|
||||||
) {
|
) {
|
||||||
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented ");
|
_plugin.sendMessage(sender, Component.text("archive command unimplemented"));
|
||||||
|
return true;
|
||||||
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);
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
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.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -44,32 +46,40 @@ public class ScoreGetCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int score = _plugin.getPlayerScore(targetPlayer);
|
int score = _plugin.getScore(targetPlayer);
|
||||||
|
|
||||||
if(!rcon){
|
if(!rcon){
|
||||||
if(sender == targetPlayer){
|
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{
|
}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;
|
return true;
|
||||||
}else{
|
}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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
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) {
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
if(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{
|
}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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
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.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -22,55 +24,48 @@ public class ScoreResetCommand implements CommandExecutor {
|
|||||||
String label,
|
String label,
|
||||||
String[] split
|
String[] split
|
||||||
) {
|
) {
|
||||||
sender.sendMessage("[" + ChatColor.AQUA + "ScoreKeeper" + ChatColor.WHITE + "] archive command unimplemented ");
|
|
||||||
|
|
||||||
boolean rcon = !(sender instanceof Player);
|
boolean rcon = !(sender instanceof Player);
|
||||||
Player targetPlayer = null;
|
Player targetPlayer = null;
|
||||||
|
|
||||||
if(split.length == 1){
|
if(split.length == 0){
|
||||||
if(rcon){
|
if(rcon){
|
||||||
echoUsage(sender, rcon);
|
echoUsage(sender, rcon);
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
targetPlayer = (Player)sender;
|
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]);
|
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
if(targetPlayer == null){
|
if(targetPlayer == null){
|
||||||
echoError(sender, rcon, "Can't find a player with that name");
|
echoError(sender, rcon, "Can't find a player with that name");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
}catch(NumberFormatException ex){
|
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
echoUsage(sender, rcon);
|
echoUsage(sender, rcon);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_plugin.resetPlayerScore(targetPlayer);
|
_plugin.resetScore(targetPlayer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
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) {
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
if(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{
|
}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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,75 +1,87 @@
|
|||||||
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
|
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.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
|
|
||||||
|
|
||||||
public class ScoreSubtractCommand implements CommandExecutor {
|
public class ScoreSubtractCommand implements CommandExecutor {
|
||||||
private final ScoreKeeperPlugin _plugin;
|
private final ScoreKeeperPlugin _plugin;
|
||||||
|
|
||||||
public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
|
||||||
_plugin = scoreKeeperPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
|
||||||
public boolean onCommand(
|
_plugin = scoreKeeperPlugin;
|
||||||
CommandSender sender,
|
}
|
||||||
Command command,
|
|
||||||
String label,
|
|
||||||
String[] split
|
|
||||||
) {
|
|
||||||
boolean rcon = !(sender instanceof Player);
|
|
||||||
int amount = 0;
|
|
||||||
Player targetPlayer = null;
|
|
||||||
|
|
||||||
if(split.length == 1){
|
|
||||||
if(rcon){
|
|
||||||
echoUsage(sender, rcon);
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
targetPlayer = (Player)sender;
|
|
||||||
try{
|
|
||||||
amount=Integer.parseInt(split[0]);
|
|
||||||
}catch(NumberFormatException ex){
|
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if(split.length == 2){
|
|
||||||
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
|
||||||
if(targetPlayer == null){
|
|
||||||
echoError(sender, rcon, "Can't find a player with that name");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
|
||||||
amount = Integer.parseInt(split[1]);
|
|
||||||
}catch(NumberFormatException ex){
|
|
||||||
echoError(sender, rcon, "amount must be an integer");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
echoUsage(sender, rcon);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_plugin.subtractScore(targetPlayer, amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void echoError(CommandSender sender, boolean rcon, String string) {
|
|
||||||
sender.sendMessage("[" + ChatColor.RED + "ScoreKeeper" + ChatColor.WHITE + "] " + string);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void echoUsage(CommandSender sender, boolean rcon) {
|
@Override
|
||||||
if(rcon){
|
public boolean onCommand(CommandSender sender, Command command, String label,
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": score-subtract " + ChatColor.GREEN + "<playername> <amount>");
|
String[] split) {
|
||||||
}else{
|
boolean rcon = !(sender instanceof Player);
|
||||||
sender.sendMessage(ChatColor.DARK_PURPLE + "Usage" + ChatColor.WHITE + ": /score-subtract " + ChatColor.YELLOW + "[playername] " + ChatColor.GREEN + "<amount>");
|
int amount = 0;
|
||||||
}
|
Player targetPlayer = null;
|
||||||
}
|
|
||||||
|
if (split.length == 1) {
|
||||||
|
if (rcon) {
|
||||||
|
echoUsage(sender, rcon);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
targetPlayer = (Player)sender;
|
||||||
|
try {
|
||||||
|
amount = Integer.parseInt(split[0]);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
echoError(sender, rcon, "amount must be an integer");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (split.length == 2) {
|
||||||
|
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
|
||||||
|
if (targetPlayer == null) {
|
||||||
|
echoError(sender, rcon, "Can't find a player with that name");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
amount = Integer.parseInt(split[1]);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
echoError(sender, rcon, "amount must be an integer");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echoUsage(sender, rcon);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_plugin.subtractScore(targetPlayer, amount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoError(CommandSender sender, boolean rcon, String string) {
|
||||||
|
_plugin.sendMessage(sender,
|
||||||
|
Component.text(string).color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void echoUsage(CommandSender sender, boolean rcon) {
|
||||||
|
if (rcon) {
|
||||||
|
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 {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user