Adds release plugin to gradle.

This commit is contained in:
Tom Hicks
2025-07-16 02:35:17 -07:00
parent 116ec79bc7
commit 69dddfb6a0
11 changed files with 1279 additions and 485 deletions

View File

@@ -1,107 +1,127 @@
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;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreAddCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreArchiveCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreGetCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreResetCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractCommand;
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
public void onEnable() {
getCommand("score-get").setExecutor(new ScoreGetCommand(this));
getCommand("score-add").setExecutor(new ScoreAddCommand(this));
getCommand("score-subtract").setExecutor(new ScoreSubtractCommand(this));
getCommand("score-reset").setExecutor(new ScoreResetCommand(this));
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.");
logInfo(getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
}
//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);
}
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
}
/*
This file is part of ScoreKeeper.
ScoreKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScoreKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.minecraft.plugins.scorekeeper;
import java.util.HashMap;
import java.util.UUID;
import java.util.logging.Level;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreAddCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreArchiveCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreGetCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreResetCommand;
import com.majinnaibu.minecraft.plugins.scorekeeper.commands.ScoreSubtractCommand;
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.java.JavaPlugin;
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
public void onEnable() {
getCommand("score-get").setExecutor(new ScoreGetCommand(this));
getCommand("score-add").setExecutor(new ScoreAddCommand(this));
getCommand("score-subtract").setExecutor(new ScoreSubtractCommand(this));
getCommand("score-reset").setExecutor(new ScoreResetCommand(this));
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.");
logInfo(
getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
}
// 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);
}
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
}

View File

@@ -1,86 +1,100 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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 ScoreAddCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreAddCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(
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.addScore(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-add ").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-add ").color(NamedTextColor.WHITE))
.append(Component.text("[playerName] ").color(NamedTextColor.YELLOW))
.append(Component.text("<amount>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}
}
}
/*
This file is part of ScoreKeeper.
ScoreKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScoreKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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;
public class ScoreAddCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreAddCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(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.addScore(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-add ").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-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,30 +1,40 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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 ScoreArchiveCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreArchiveCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(
CommandSender sender,
Command command,
String label,
String[] split
) {
_plugin.sendMessage(sender, Component.text("archive command unimplemented"));
return true;
}
}
/*
This file is part of ScoreKeeper.
ScoreKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScoreKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
import net.kyori.adventure.text.Component;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class ScoreArchiveCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreArchiveCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
_plugin.sendMessage(sender, Component.text("archive command unimplemented"));
return true;
}
}

View File

@@ -1,85 +1,107 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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 ScoreGetCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreGetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(
CommandSender sender,
Command command,
String label,
String[] split
) {
boolean rcon = !(sender instanceof Player);
Player targetPlayer = null;
if(split.length == 0){
if(!rcon){
targetPlayer = (Player)sender;
}else{
echoUsage(sender, rcon);
return true; //false;
}
}else if(split.length == 1){
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
}else if(split.length > 1){
echoUsage(sender, rcon);
return true; //false;
}
if(targetPlayer == null){
echoError(sender, rcon, "Can't find a player with that name");
return true;
}
int score = _plugin.getScore(targetPlayer);
if(!rcon){
if(sender == targetPlayer){
_plugin.sendMessage(targetPlayer, Component.text("Your score is ").append(Component.text(score).color(NamedTextColor.GREEN)));
}else{
_plugin.sendMessage(sender, Component.text(targetPlayer.getName() + "'s score is ").append(Component.text(score).color(NamedTextColor.GREEN)));
}
return true;
}else{
_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) {
_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-get ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}else{
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);
}
}
}
/*
This file is part of ScoreKeeper.
ScoreKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScoreKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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;
public class ScoreGetCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreGetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
boolean rcon = !(sender instanceof Player);
Player targetPlayer = null;
if (split.length == 0) {
if (!rcon) {
targetPlayer = (Player) sender;
} else {
echoUsage(sender, rcon);
return true; // false;
}
} else if (split.length == 1) {
targetPlayer = _plugin.getServer().getPlayerExact(split[0]);
} else if (split.length > 1) {
echoUsage(sender, rcon);
return true; // false;
}
if (targetPlayer == null) {
echoError(sender, rcon, "Can't find a player with that name");
return true;
}
int score = _plugin.getScore(targetPlayer);
if (!rcon) {
if (sender == targetPlayer) {
_plugin.sendMessage(
targetPlayer,
Component.text("Your score is ")
.append(Component.text(score).color(NamedTextColor.GREEN)));
} else {
_plugin.sendMessage(
sender,
Component.text(targetPlayer.getName() + "'s score is ")
.append(Component.text(score).color(NamedTextColor.GREEN)));
}
return true;
} else {
_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) {
_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-get ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
} else {
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,71 +1,85 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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 ScoreResetCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreResetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(
CommandSender sender,
Command command,
String label,
String[] split
) {
boolean rcon = !(sender instanceof Player);
Player targetPlayer = null;
if(split.length == 0){
if(rcon){
echoUsage(sender, rcon);
return true;
}else{
targetPlayer = (Player)sender;
}
}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;
}
}else{
echoUsage(sender, rcon);
return true;
}
_plugin.resetScore(targetPlayer);
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-reset ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
}else{
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);
}
}
}
/*
This file is part of ScoreKeeper.
ScoreKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScoreKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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;
public class ScoreResetCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreResetCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
boolean rcon = !(sender instanceof Player);
Player targetPlayer = null;
if (split.length == 0) {
if (rcon) {
echoUsage(sender, rcon);
return true;
} else {
targetPlayer = (Player) sender;
}
} 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;
}
} else {
echoUsage(sender, rcon);
return true;
}
_plugin.resetScore(targetPlayer);
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-reset ").color(NamedTextColor.WHITE))
.append(Component.text("<playerName>").color(NamedTextColor.GREEN));
_plugin.sendMessage(sender, message);
} else {
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,87 +1,100 @@
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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;
public class ScoreSubtractCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(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) {
_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);
}
}
}
/*
This file is part of ScoreKeeper.
ScoreKeeper is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScoreKeeper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.minecraft.plugins.scorekeeper.commands;
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;
public class ScoreSubtractCommand implements CommandExecutor {
private final ScoreKeeperPlugin _plugin;
public ScoreSubtractCommand(ScoreKeeperPlugin scoreKeeperPlugin) {
_plugin = scoreKeeperPlugin;
}
@Override
public boolean onCommand(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) {
_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);
}
}
}