-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented LiteCommands and change base version to 1.8.9. (#12)
- Loading branch information
Showing
17 changed files
with
456 additions
and
269 deletions.
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
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
190 changes: 11 additions & 179 deletions
190
src/main/java/pl/minecodes/mineeconomy/command/admin/EconomyCommand.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 |
---|---|---|
@@ -1,193 +1,25 @@ | ||
package pl.minecodes.mineeconomy.command.admin; | ||
|
||
import co.aikar.commands.BaseCommand; | ||
import co.aikar.commands.annotation.*; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.util.concurrent.AtomicDouble; | ||
import dev.rollczi.litecommands.annotations.Execute; | ||
import dev.rollczi.litecommands.annotations.Permission; | ||
import dev.rollczi.litecommands.annotations.Section; | ||
import eu.okaeri.injector.annotation.Inject; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.command.CommandSender; | ||
import pl.minecodes.mineeconomy.EconomyPlugin; | ||
import pl.minecodes.mineeconomy.data.configuration.Configuration; | ||
import pl.minecodes.mineeconomy.data.configuration.Messages; | ||
import pl.minecodes.mineeconomy.profile.Profile; | ||
import pl.minecodes.mineeconomy.profile.ProfileService; | ||
import pl.minecodes.mineeconomy.profile.helper.BalanceOperationCallback; | ||
import pl.minecodes.mineeconomy.util.MessageUtil; | ||
import pl.minecodes.mineeconomy.util.Placeholders; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
@Section(route = "economy", aliases = {"eco", "ecoadmin"}, priority = 0) | ||
@Permission("economy.admin") | ||
public class EconomyCommand { | ||
|
||
@CommandAlias("economy|eco|ecoadmin") | ||
@CommandPermission("economy.admin") | ||
public class EconomyCommand extends BaseCommand { | ||
@Inject private ProfileService profileService; | ||
@Inject private Configuration configuration; | ||
@Inject private Messages messages; | ||
|
||
@Inject | ||
private ProfileService profileService; | ||
@Inject | ||
private Configuration configuration; | ||
@Inject | ||
private Messages messages; | ||
|
||
|
||
@Default | ||
@HelpCommand | ||
public void help(CommandSender sender) { | ||
@Execute | ||
public void executeHelpCommand(CommandSender sender) { | ||
this.messages.getEconomyAdminCommands().forEach(string -> MessageUtil.sendMessage(sender, string)); | ||
} | ||
|
||
|
||
@Syntax("<username> <balance>") | ||
@Subcommand("set") | ||
@Description("Setup player balance.") | ||
@CommandCompletion("@players 10|100|1000|10000") | ||
public void onAdministratorSetBalance(CommandSender sender, String username, double balance) { | ||
AtomicDouble atomicBalance = new AtomicDouble(Double.parseDouble(EconomyPlugin.FORMAT.format(balance))); | ||
|
||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username); | ||
if (offlinePlayer == null) { | ||
MessageUtil.sendMessage(sender, this.messages.getPlayerIsNotExistsInCache()); | ||
return; | ||
} | ||
|
||
Profile profile = this.profileService.getProfile(offlinePlayer.getUniqueId()); | ||
profile.setupBalance(atomicBalance.get(), new BalanceOperationCallback() { | ||
@Override | ||
public void done() { | ||
MessageUtil.sendMessage(sender, Placeholders.replace(messages.getBalanceSuccessfullySet(), | ||
ImmutableMap.of( | ||
"player", Objects.requireNonNull(offlinePlayer.getName(), "OfflinePlayer name is null."), | ||
"balance", atomicBalance.get(), | ||
"currency", configuration.getCurrency(atomicBalance.get())))); | ||
} | ||
|
||
@Override | ||
public void cancel(CancelReason reason) { | ||
MessageUtil.sendMessage(sender, messages.getBalanceOperationParameterIsNegative()); | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Syntax("<username> <value>") | ||
@Subcommand("deposit") | ||
@Description("Deposit money to player balance.") | ||
@CommandCompletion("@players 10|100|1000|10000") | ||
public void onAdministratorDepositMoney(CommandSender sender, String username, double value) { | ||
AtomicDouble atomicValue = new AtomicDouble(Double.parseDouble(EconomyPlugin.FORMAT.format(value))); | ||
|
||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username); | ||
if (offlinePlayer == null) { | ||
MessageUtil.sendMessage(sender, this.messages.getPlayerIsNotExistsInCache()); | ||
return; | ||
} | ||
|
||
Profile profile = this.profileService.getProfile(offlinePlayer.getUniqueId()); | ||
profile.deposit(atomicValue.get(), new BalanceOperationCallback() { | ||
@Override | ||
public void done() { | ||
MessageUtil.sendMessage(sender, Placeholders.replace(messages.getBalanceSuccessfullyDeposit(), | ||
ImmutableMap.of( | ||
"player", Objects.requireNonNull(offlinePlayer.getName(), "OfflinePlayer name is null."), | ||
"value", atomicValue.get(), | ||
"currency", configuration.getCurrency(atomicValue.get())))); | ||
} | ||
|
||
@Override | ||
public void cancel(CancelReason reason) { | ||
MessageUtil.sendMessage(sender, messages.getBalanceOperationParameterIsNegative()); | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Syntax("<username> <value>") | ||
@Subcommand("withdraw") | ||
@Description("Withdraw money from player balance.") | ||
@CommandCompletion("@players 10|100|1000|10000") | ||
public void onAdministratorWithdrawMoney(CommandSender sender, String username, double value) { | ||
AtomicDouble atomicValue = new AtomicDouble(Double.parseDouble(EconomyPlugin.FORMAT.format(value))); | ||
|
||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username); | ||
if (offlinePlayer == null) { | ||
MessageUtil.sendMessage(sender, this.messages.getPlayerIsNotExistsInCache()); | ||
return; | ||
} | ||
|
||
Profile profile = this.profileService.getProfile(offlinePlayer.getUniqueId()); | ||
profile.withdraw(atomicValue.get(), new BalanceOperationCallback() { | ||
@Override | ||
public void done() { | ||
MessageUtil.sendMessage(sender, Placeholders.replace(messages.getBalanceSuccessfullyWithdraw(), | ||
ImmutableMap.of( | ||
"player", Objects.requireNonNull(offlinePlayer.getName(), "OfflinePlayer name is null."), | ||
"value", atomicValue.get(), | ||
"currency", configuration.getCurrency(atomicValue.get())))); | ||
} | ||
|
||
@Override | ||
public void cancel(CancelReason reason) { | ||
switch (reason) { | ||
case NO_FOUNDS: | ||
MessageUtil.sendMessage(sender, messages.getBalanceWithdrawNoFounds()); | ||
break; | ||
case NEGATIVE_BALANCE: | ||
MessageUtil.sendMessage(sender, messages.getBalanceIsNegative()); | ||
break; | ||
case NEGATIVE_PARAMETER: | ||
MessageUtil.sendMessage(sender, messages.getBalanceOperationParameterIsNegative()); | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Syntax("<username>") | ||
@Subcommand("clear") | ||
@Description("Clear player balance.") | ||
@CommandCompletion("@players") | ||
public void onAdministratorClearBalance(CommandSender sender, String username) { | ||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username); | ||
if (offlinePlayer == null) { | ||
MessageUtil.sendMessage(sender, this.messages.getPlayerIsNotExistsInCache()); | ||
return; | ||
} | ||
|
||
Profile profile = this.profileService.getProfile(offlinePlayer.getUniqueId()); | ||
profile.setupBalance(0, new BalanceOperationCallback() { | ||
@Override | ||
public void done() { | ||
MessageUtil.sendMessage(sender, Placeholders.replace(messages.getBalanceSuccessfullyClear(), | ||
Collections.singletonMap("player", Objects.requireNonNull(offlinePlayer.getName(), "OfflinePlayer name is null.")))); | ||
} | ||
|
||
@Override | ||
public void cancel(CancelReason reason) { | ||
MessageUtil.sendMessage(sender, messages.getBalanceOperationParameterIsNegative()); | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Syntax("<username>") | ||
@Subcommand("check") | ||
@Description("Check player balance.") | ||
@CommandCompletion("@players") | ||
public void onAdministratorCheckBalance(CommandSender sender, String username) { | ||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username); | ||
if (offlinePlayer == null) { | ||
MessageUtil.sendMessage(sender, this.messages.getPlayerIsNotExistsInCache()); | ||
return; | ||
} | ||
|
||
Profile profile = this.profileService.getProfile(offlinePlayer.getUniqueId()); | ||
MessageUtil.sendMessage(sender, Placeholders.replace(this.messages.getBalanceAdministratorCheck(), | ||
ImmutableMap.of( | ||
"player", Objects.requireNonNull(offlinePlayer.getName(), "OfflinePlayer name is null."), | ||
"balance", profile.getBalance(), | ||
"currency", this.configuration.getCurrency(profile.getBalance())))); | ||
} | ||
} |
Oops, something went wrong.