-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...kit/src/main/java/dev/rollczi/example/bukkit/command/currency/CurrencyBalanceCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.rollczi.example.bukkit.command.currency; | ||
|
||
import dev.rollczi.litecommands.annotations.argument.Arg; | ||
import dev.rollczi.litecommands.annotations.command.Command; | ||
import dev.rollczi.litecommands.annotations.context.Context; | ||
import dev.rollczi.litecommands.annotations.execute.Execute; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
@Command(name = "currency balance") | ||
public class CurrencyBalanceCommand { | ||
|
||
private final CurrencyService currencyService; | ||
|
||
public CurrencyBalanceCommand(CurrencyService currencyService) { | ||
this.currencyService = currencyService; | ||
} | ||
|
||
@Execute | ||
void balance(@Context Player sender) { | ||
sender.sendMessage("Your balance is " + currencyService.getCurrency(sender.getUniqueId())); | ||
} | ||
|
||
@Execute | ||
void balance(@Context CommandSender sender, @Arg Player player) { | ||
sender.sendMessage(player.getName() + "'s balance is " + currencyService.getCurrency(player.getUniqueId())); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...les/bukkit/src/main/java/dev/rollczi/example/bukkit/command/currency/CurrencyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package dev.rollczi.example.bukkit.command.currency; | ||
|
||
import dev.rollczi.litecommands.annotations.argument.Arg; | ||
import dev.rollczi.litecommands.annotations.command.Command; | ||
import dev.rollczi.litecommands.annotations.context.Context; | ||
import dev.rollczi.litecommands.annotations.execute.Execute; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
@Command(name = "currency") | ||
public class CurrencyCommand { | ||
|
||
private final CurrencyService currencyService; | ||
|
||
public CurrencyCommand(CurrencyService currencyService) { | ||
this.currencyService = currencyService; | ||
} | ||
|
||
@Execute(name = "give") | ||
void give(@Context CommandSender sender, @Arg Player player, @Arg int amount) { | ||
currencyService.addCurrency(player.getUniqueId(), amount); | ||
|
||
sender.sendMessage("Given " + amount + " to " + player.getName()); | ||
player.sendMessage("You have received " + amount + " from " + sender.getName()); | ||
} | ||
|
||
@Execute(name = "take") | ||
void take(@Context CommandSender sender, @Arg Player player, @Arg int amount) { | ||
currencyService.removeCurrency(player.getUniqueId(), amount); | ||
|
||
sender.sendMessage("Taken " + amount + " from " + player.getName()); | ||
player.sendMessage("Your balance has been reduced by " + amount + " by " + sender.getName()); | ||
} | ||
|
||
@Execute(name = "set") | ||
void set(@Context CommandSender sender, @Arg Player player, @Arg int amount) { | ||
currencyService.setCurrency(player.getUniqueId(), amount); | ||
|
||
sender.sendMessage("Set " + amount + " to " + player.getName()); | ||
player.sendMessage("Your balance has been set to " + amount + " by " + sender.getName()); | ||
} | ||
|
||
@Execute(name = "take") | ||
void reset(@Context CommandSender sender, @Arg Player player) { | ||
currencyService.setCurrency(player.getUniqueId(), 0); | ||
|
||
sender.sendMessage("Reset " + player.getName()); | ||
player.sendMessage("Your balance has been reset by " + sender.getName()); | ||
} | ||
|
||
@Execute(name = "pay") | ||
void pay(@Context Player sender, @Arg Player player, @Arg int amount) { | ||
currencyService.addCurrency(player.getUniqueId(), amount); | ||
currencyService.removeCurrency(sender.getUniqueId(), amount); | ||
|
||
sender.sendMessage("Paid " + amount + " to " + player.getName()); | ||
player.sendMessage("You have received " + amount + " from " + sender.getName()); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...les/bukkit/src/main/java/dev/rollczi/example/bukkit/command/currency/CurrencyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.rollczi.example.bukkit.command.currency; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
/** | ||
* This class is a simple service that stores currency for players. (Used for demonstration /currency command) | ||
* {@link CurrencyCommand} and {@link CurrencyBalanceCommand} are using this service. | ||
*/ | ||
public class CurrencyService { | ||
|
||
private final Map<UUID, Integer> currency = new HashMap<>(); | ||
|
||
public void setCurrency(UUID uuid, int amount) { | ||
currency.put(uuid, amount); | ||
} | ||
|
||
public void addCurrency(UUID uuid, int amount) { | ||
currency.put(uuid, currency.getOrDefault(uuid, 0) + amount); | ||
} | ||
|
||
public void removeCurrency(UUID uuid, int amount) { | ||
currency.put(uuid, currency.getOrDefault(uuid, 0) - amount); | ||
} | ||
|
||
public int getCurrency(UUID uuid) { | ||
return currency.getOrDefault(uuid, 0); | ||
} | ||
|
||
} |