Fix giveblocks command with negative amounts.

This commit is contained in:
bloodshot 2020-02-16 15:35:30 -05:00
parent 2ccd881bb6
commit c4543827eb
2 changed files with 10 additions and 0 deletions

View File

@ -38,6 +38,11 @@ public class CommandGiveBlocks extends BaseCommand {
@Syntax("<player> <amount>") @Syntax("<player> <amount>")
@Subcommand("giveblocks") @Subcommand("giveblocks")
public void execute(Player src, OfflinePlayer targetPlayer, int amount) { public void execute(Player src, OfflinePlayer targetPlayer, int amount) {
if (amount <= 0) {
TextAdapter.sendComponent(src, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_INVALID_AMOUNT));
return;
}
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(src.getWorld(), src.getUniqueId()); final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(src.getWorld(), src.getUniqueId());
int availableBlocks = playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks(); int availableBlocks = playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks();
if (amount > availableBlocks) { if (amount > availableBlocks) {

View File

@ -37,6 +37,11 @@ public class CommandGiveBlocks extends BaseCommand {
@Syntax("<player> <amount>") @Syntax("<player> <amount>")
@Subcommand("giveblocks") @Subcommand("giveblocks")
public void execute(Player src, User targetPlayer, int amount) { public void execute(Player src, User targetPlayer, int amount) {
if (amount <= 0) {
TextAdapter.sendComponent(src, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_INVALID_AMOUNT));
return;
}
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(src.getWorld(), src.getUniqueId()); final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(src.getWorld(), src.getUniqueId());
int availableBlocks = playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks(); int availableBlocks = playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks();
if (amount > availableBlocks) { if (amount > availableBlocks) {