Coinflip Command
Coinflip Command
* DeluxeCoinflip Plugin
* Copyright (c) Zithium Studios. All rights reserved.
*/
package net.zithium.deluxecoinflip.command;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import net.zithium.deluxecoinflip.DeluxeCoinflipPlugin;
import net.zithium.deluxecoinflip.api.events.CoinflipCreatedEvent;
import net.zithium.deluxecoinflip.config.ConfigType;
import net.zithium.deluxecoinflip.config.Messages;
import net.zithium.deluxecoinflip.economy.EconomyManager;
import net.zithium.deluxecoinflip.economy.provider.EconomyProvider;
import net.zithium.deluxecoinflip.game.CoinflipGame;
import net.zithium.deluxecoinflip.game.GameManager;
import net.zithium.deluxecoinflip.storage.PlayerData;
import net.zithium.deluxecoinflip.utility.TextUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@CommandAlias("coinflip|cf")
@Description("Main command for using DeluxeCoinflip")
public class CoinflipCommand extends BaseCommand {
@Default
public void defaultCommand(final CommandSender sender) {
if (!(sender instanceof Player)) {
sender.sendMessage("Console cannot open the coinflip GUI, use /coinflip
help");
return;
}
plugin.getInventoryManager().getGamesGUI().openInventory((Player) sender);
}
@Subcommand("reload")
@CommandPermission("coinflip.reload")
public void reloadSubCommand(final CommandSender sender) {
plugin.reload();
Messages.RELOAD.send(sender);
}
@Subcommand("help")
public void helpSubCommand(final CommandSender sender) {
Messages.HELP_DEFAULT.send(sender, "{PROVIDERS}",
economyManager.getEconomyProviders().values().stream().map(p ->
p.getDisplayName().toLowerCase()).collect(Collectors.joining(", ")));
if (sender.hasPermission("coinflip.admin"))
Messages.HELP_ADMIN.send(sender);
}
@Subcommand("about")
public void aboutSubCommand(final CommandSender sender) {
sender.sendMessage("");
sender.sendMessage(TextUtil.color("&e&lDeluxeCoinflip"));
sender.sendMessage(TextUtil.color("&eVersion: &fv" +
plugin.getDescription().getVersion()));
sender.sendMessage(TextUtil.color("&eAuthor: &fItsLewizzz"));
if (!TextUtil.isValidDownload()) {
sender.sendMessage(TextUtil.color("&4Registered to: &cFailed to find
licensed owner to this plugin. Contact developer to report possible leak
(ItsLewizzz#6023)."));
} else if (TextUtil.isMCMarket()) {
sender.sendMessage(TextUtil.color("&4Registered to: &chttps://www.mc-
market.org/members/%%__USER__%%/"));
} else {
sender.sendMessage(TextUtil.color("&4Registered to:
&chttps://www.spigotmc.org/members/%%__USER__%%/"));
}
sender.sendMessage("");
}
@Subcommand("toggle")
public void toggleSubCommand(final CommandSender sender) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can toggle broadcast messages");
return;
}
if(!playerDataOptional.isPresent()) {
sender.sendMessage(TextUtil.color("&cYour player data has not loaded
yet, please wait a few moments or relog."));
return;
}
economyManager.getEconomyProvider(game.getProvider()).deposit(player,
game.getAmount());
gameManager.removeCoinflipGame(uuid);
Messages.DELETED_GAME.send(player);
} else {
Messages.GAME_NOT_FOUND.send(player);
}
}
@Subcommand("create|new")
//@WrongUsage("&c/coinflip create <amount> [economy]")
@CommandCompletion("* @providers")
public void createSubCommand(final Player player, String amountInput, @Optional
String currencyProvider) {
final long amount;
try {
amount = Long.parseLong(amountInput.replace(",", ""));
} catch (Exception ex) {
Messages.INVALID_AMOUNT.send(player, "{INPUT}", amountInput);
return;
}
if (gameManager.getCoinflipGames().containsKey(player.getUniqueId())) {
Messages.GAME_ACTIVE.send(player);
return;
}
if (provider == null) {
Messages.INVALID_CURRENCY.send(player,"{CURRENCY_TYPES}",
economyManager.getEconomyProviders().values().stream().map(p ->
p.getDisplayName().toLowerCase()).collect(Collectors.joining(", ")));
return;
}
provider.withdraw(player, amount);
gameManager.addCoinflipGame(player.getUniqueId(), coinflipGame);
if(config.getBoolean("settings.broadcast-coinflip-creation")) {
Messages.COINFLIP_CREATED_BROADCAST.broadcast("{PLAYER}",
player.getName(), "{CURRENCY}", provider.getDisplayName(), "{AMOUNT}",
TextUtil.numberFormat(amount));
}
Messages.CREATED_GAME.send(player, "{CURRENCY}",
provider.getDisplayName(), "{AMOUNT}", TextUtil.numberFormat(amount));
} else {
Messages.INSUFFICIENT_FUNDS.send(player);
}
}