Code Monkey home page Code Monkey logo

bedrockeconomy's Introduction

BedrockEconomy

BedrockEconomy is an economy plugin made for PocketMine-MP focused on stability and simplicity.

Table of Contents

Commands

Name Description Usage Permission
balance Show your and others balance balance [player: string] bedrockeconomy.command.balance
pay Pay others with your balance pay <player: string> <amount: number> bedrockeconomy.command.pay
rich View the top balances rich [page: number] bedrockeconomy.command.rich
addbalance Add points to others balance addbalance <player: string> <amount: number> bedrockeconomy.command.addbalance
removebalance Remove points from others balance removebalance <player: string> <amount: number> bedrockeconomy.command.removebalance
setbalance Set others balance setbalance <player: string> <balance: number> bedrockeconomy.command.setbalance

Features

  • MySQL Database
  • SQLite Database
  • Async API
  • Closure API
  • Customizable
  • Easy to use
  • Lightweight
  • Fast and efficient
  • Cache system

Examples

Retrieving a Player's Balance

You can retrieve a player's balance using the get method. Here's an example:

BedrockEconomyAPI::CLOSURE()->get(
    xuid: "123456789",
    username: "Doge",
    onSuccess: static function (array $result): void {
        echo "Balance: " . $result["amount"] . " Decimals: " . $result["decimals"] . " Position: " . $result["position"];
    },
    onError: static function (SQLException $exception): void {
        if ($exception instanceof RecordNotFoundException) {
            echo "Record not found";
            return;
        }

        echo $exception->getMessage();
    }
);

// Using async-await
Await::f2c(
    function (): Generator {
        try {
            $result = yield from BedrockEconomyAPI::ASYNC()->get(
                xuid: "123456789",
                username: "Doge",
            );
        } catch (RecordNotFoundException) {
            echo "Account not found";
            return;
        } catch (SQLException) {
            echo "Database error";
            return;
        }
        
        echo "Balance: " . $result["amount"] . " Decimals: " . $result["decimals"] . " Position: " . $result["position"];
    }
);

Retrieving Multiple Player Balances

You can retrieve multiple player balances using the bulk method. Here's an example:

BedrockEconomyAPI::CLOSURE()->bulk(
    list: ["Doge", "123456789"], // You can use both username and xuid
    onSuccess: static function (array $result): void {
        foreach ($result as $data) {
            echo "Player: " . $data["username"] . " Balance: " . $data["amount"] . " Decimals: " . $data["decimals"] . " Position: " . $data["position"];
        }
    },
    onError: static function (SQLException $exception): void {
        if ($exception instanceof RecordNotFoundException) {
            echo "No records found";
            return;
        }

        echo $exception->getMessage();
    }
);

// Using async-await
Await::f2c(
    function (): Generator {
        try {
            $result = yield from BedrockEconomyAPI::ASYNC()->bulk(
                list: ["Doge", "123456789"], // You can use both username and xuid
            );
        } catch (RecordNotFoundException) {
            echo "No records found";
            return;
        } catch (SQLException) {
            echo "Database error";
            return;
        }
        
        foreach ($result as $data) {
            echo "Player: " . $data["username"] . " Balance: " . $data["amount"] . " Decimals: " . $data["decimals"] . " Position: " . $data["position"];
        }
    }
);

Adding Funds to a Player's Balance

You can add funds to a player's balance using the add method. Here's an example:

BedrockEconomyAPI::CLOSURE()->add(
    xuid: "123456789",
    username: "Doge",
    amount: 55,
    decimals: 25,
    onSuccess: static function (): void {
        echo 'Balance updated successfully.';
    },
    onError: static function (SQLException $exception): void {
        if ($exception instanceof RecordNotFoundException) {
            echo 'Account not found';
            return;
        }

        echo 'An error occurred while updating the balance.';
    }
);

// Using async-await
Await::f2c(
    function () use ($player): Generator {
        try {
            yield from BedrockEconomyAPI::ASYNC()->add(
                xuid: "123456789",
                username: "Doge",
                amount: 55,
                decimals: 25,
            );
            echo 'Balance updated successfully.';
        } catch (RecordNotFoundException) {
            echo 'Account not found';
        } catch (SQLException) {
            echo 'An error occurred while updating the balance.';
        }
    }
);

Subtracting Funds from a Player's Balance

You can subtract funds from a player's balance using the subtract method. Here's an example:

BedrockEconomyAPI::CLOSURE()->subtract(
    xuid: "123456789",
    username: "Doge",
    amount: 55,
    decimals: 25,
    onSuccess: static function (): void {
        echo 'Balance updated successfully.';
    },
    onError: static function (SQLException $exception): void {
        if ($exception instanceof RecordNotFoundException) {
            echo 'Account not found';
            return;
        }

        if ($exception instanceof InsufficientFundsException) {
            echo 'Insufficient funds';
            return;
        }

        echo 'An error occurred while updating the balance.';
    }
);

// Using async-await
Await::f2c(
    function () use ($player): Generator {
        try {
            yield from BedrockEconomyAPI::ASYNC()->subtract(
                xuid: "123456789",
                username: "Doge",
                amount: 55,
                decimals: 25,
            );
            echo 'Balance updated successfully.';
        } catch (RecordNotFoundException) {
            echo 'Account not found';
        } catch (InsufficientFundsException) {
            echo 'Insufficient funds';
        } catch (SQLException) {
            echo 'An error occurred while updating the balance.';
        }
    }
);

Transferring Funds Between Players

You can transfer funds from one player to another using the transfer method. Here's an example:

$sourcePlayer = ['xuid' => 'source_xuid', 'username' => 'source_username'];
$targetPlayer = ['xuid' => 'target_xuid', 'username' => 'target_username'];

BedrockEconomyAPI::CLOSURE()->transfer(
    source: $sourcePlayer,
    target: $targetPlayer,
    amount: 55,
    decimals: 25,
    onSuccess: static function (): void {
        echo 'Balance transfer successful.';
    },
    onError: static function (SQLException $exception): void {
        if ($exception instanceof RecordNotFoundException) {
            echo 'Account not found';
            return;
        }
        
        if ($exception instanceof InsufficientFundsException) {
            echo 'Insufficient funds';
            return;
        }

        echo 'An error occurred during the balance transfer.';
    }
);

// Using async-await
Await::f2c(
    function () use ($sourcePlayer, $targetPlayer): Generator {
        try {
            yield from BedrockEconomyAPI::ASYNC()->transfer(
                source: $sourcePlayer,
                target: $targetPlayer,
                amount: 55,
                decimals: 25,
            );
            echo 'Balance transfer successful.';
        } catch (RecordNotFoundException) {
            echo 'Account not found';
        } catch (InsufficientFundsException) {
            echo 'Insufficient funds';
        } catch (SQLException) {
            echo 'An error occurred during the balance transfer.';
        }
    }
);

These examples demonstrate how to perform common operations using the BedrockEconomy API, such as retrieving player balances, adding and subtracting funds, and transferring funds between players.

Tools

License

This project is released under the MIT License. For more information, please refer to the LICENSE file.

bedrockeconomy's People

Contributors

aiptu avatar betsthebest avatar borvn avatar brokiem avatar cooldogedev avatar endermanbugzjfc avatar fadheldev avatar kygekdev avatar mrblasymsk avatar nakidori avatar nhanaz avatar poggit-bot avatar sof3 avatar therealdeveloper avatar udachin26 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bedrockeconomy's Issues

Menu form

Add support menu forms to make it easier for users

Scorehud bug

Scorehud does not have to new formatting feature

/setlang

Allows players to set their own language

Scorehud

can you add score support to scorehud plugin?

Add all error phrases to translation

Is your feature request related to a problem? Please describe.

I don't know if it is possible, but it would be great if you could add the error phrases, for example when using /pay or /pay Steve, you get those 2 phrases in English. I don't know if there are more and if it is possible to add them.

Describe the solution you'd like

image

Describe alternatives you've considered

Additional context

changing command names causes a failure when loading

[16:57:48.900] [Server thread/CRITICAL]: UnhandledMatchError: "Unhandled match value of type string" (EXCEPTION) in "plugins/BedrockEconomy.phar/src/cooldogedev/BedrockEconomy/BedrockEconomy" at line 123

--- Stack trace ---

#0 (): cooldogedev\BedrockEconomy\BedrockEconomy->cooldogedev\BedrockEconomy{closure}(array[4])

#1 plugins/BedrockEconomy.phar/src/cooldogedev/BedrockEconomy/BedrockEconomy(122): array_map(object Closure#100285, array[7])

#2 plugins/BedrockEconomy.phar/src/cooldogedev/BedrockEconomy/BedrockEconomy(99): cooldogedev\BedrockEconomy\BedrockEconomy->initializeCommands()

#3 pmsrc/src/plugin/PluginBase(137): cooldogedev\BedrockEconomy\BedrockEconomy->onEnable()

#4 pmsrc/src/plugin/PluginManager(437): pocketmine\plugin\PluginBase->onEnableStateChange(true)

#5 pmsrc/src/Server(1385): pocketmine\plugin\PluginManager->enablePlugin(object cooldogedev\BedrockEconomy\BedrockEconomy#101592)

#6 pmsrc/src/Server(1011): pocketmine\Server->enablePlugins(object pocketmine\plugin\PluginEnableOrder#24932)

#7 pmsrc/src/PocketMine(304): pocketmine\Server->__construct(object BaseClassLoader#2, object pocketmine\utils\MainLogger#3, string[16] /home/minecraft/, string[24] /home/minecraft/plugins/)

#8 pmsrc/src/PocketMine(327): pocketmine\server()

#9 pmsrc(11): require(string[57] phar:///home/minecraft/pocketmine.phar/src/PocketMine.php)

--- End of exception information ---

ScoreHud does not update money

Describe the bug
When you add money to a player, the scorehud is updated for 1 millisecond to the money you have added, but after a second it disappears and returns to the money you had before.

To Reproduce
Steps to reproduce the behavior:
https://streamable.com/43poru

Expected behavior
ScoreHud will be updated correctly when adding or removing money.

Screenshots
Video up

OS and version (please complete the following information):

  • Server OS: linux
  • PocketMine-MP version: 4.2.4
  • Version: 2.0.7
  • Plugins (2): BedrockEconomy v2.0.7, ScoreHud v7.0.0

Additional context
X

using mysql or sqlite is not recommended

using sql to make an economy plugin is very unsuitable and will really lag your server a lot for nothing so I advise you to put the db in json or yml (preferably json) if people want to make a system of economy inter server why not make a plugin that will take care of it and suddenly will be able to attract more people because people who want to do just a server can do it without having to make db and those who want can do it just by installing a " extension" which will do it automatically

API failure reasons

Is your feature request related to a problem? Please describe.
Currently, I am working on supporting some economy plugins in my plugin. After implementing Capital, I noticed something BedrockEconomy's API lacks: There are multiple reasons why a transaction gets cancelled, e.g. the player didn't have enough money or the TransactionEvent was simply cancelled. What BedrockEconomy lacks is a way to get the reason why a transaction failed.

Describe the solution you'd like
I personally like Capital's approach to that problem: When the transaction failed, an exception is thrown where the error code is specifically set to a reason.
But I know that there isn't a simple solution since BedrockEconomy uses PMMP's promise system which doesn't support parameters in their failure callbacks.

Describe alternatives you've considered

Additional context

API proposal

implement a more simplified API for plugin developers or maybe just use singleton for the main class

no work

Console error, but the virions are in the folder, why the error ?

Abbreviation

Allow to abbreviate the recipient's name when payment

It's really annoying and time consuming when I have to write down someone's full name
Instead of a long line of statements like this:
/pay BoxierChimera37 <amount>
Just:
/pay Bo <amount>

Implement more events

currently there's no good way to get all information of a transfer transaction, e.g. sender, receiver

Introduce labels

Is your feature request related to a problem? Please describe.
Rather than storing the balance in a column we store it in a label-based json format, doing so will add more flexibility to implement new features such as the following #73, #69, #46

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Need Help

Hello, I'm trying to get player money by using your API and it's very confusing. I have $100 (balance), but in my GUI it shows that I have $0.

         BedrockEconomyAPI::getInstance()->getPlayerBalance(
            "$username",
            ClosureContext::create(
                function (?int $balance): void {
                    22 => VanillaItems::WRITABLE_BOOK()->setCustomName("§r§7My Info§f\nBalance§7: §2$ §f" . $balance),
                },
            )
        );

implement a temporary cache

currently the plugin has a permanent cache and it might slow down the server startup, and also waste memory (not that much because the data is lightweight).

Events for commands (balance, top balance)

I am very sorry to see that there are no events for the commands(balance, top balance).

I would like to see events for commands as for transactions. Perhaps you need to add a get transaction type

As an alternative at the moment I use "crutches". I catch commands through the processing of kernel events.

Please remove getPlayerBalance API

Is your feature request related to a problem? Please describe.
getPlayerBalance is constantly abused for incorrect code where they check for whether the player has enough balance through getPlayerBalance and call subtractFromPlayerBalance without actually checking whether the latter is successful.

Describe the solution you'd like
Remove the method. It is good for nothing other than abuse.

People who want to display the balance should use an API dedicated for displaying, such as InfoAPI. getPlayerBalance is good for nothing.

help

Error:

[Server thread/CRITICAL]: Error: "Class "cooldogedev\libSQL\context\ClosureContext" not found" (EXCEPTION) in "plugins/Perks-main/src/flxiboy/Perks/provider/BedrockEconomyProvider" at line 44

Code:

use cooldogedev\BedrockEconomy\api\BedrockEconomyAPI;
use cooldogedev\libSQL\context\ClosureContext;

        BedrockEconomyAPI::getInstance()->getPlayerBalance(
            strtolower($player->getName()),
            ClosureContext::create(
                function (?int $balance): void {
                    var_dump($balance);
                },
            )
        );

Upgrade /balance

  • Show more pages currently viewed by the user and the server's maximum number of pages.
  • Show top of users who used /topbalance

Like this:

TOP BALANCES [Current page/Max page]
1. UserName : 100
2. UserName : 100
3. UserName : 100
4. UserName : 100
5. UserName : 100
6. UserName : 100
7. UserName : 100
8. UserName : 100
9. UserName : 100
10. UserName : 100
» Your top: $senderTop

Balances

If the user has money, when the server restarts the money will reset to 0 according to the default config
/addbalance to player and restart server, and also some translation message like /pay is missing

Some ideas for cooldogedev

Hey, i can add theese languages, ( Italy, Spain, Russian, Hungary, France, Austria)
are this a good idea??

questen

Hey,
Ehm one last question, when I do this, it always comes out as 0, is there another possibility? Have already tried with $end = 0, $end = $balance, return $end doesn't work either.

        BedrockEconomyAPI::getInstance()->getPlayerBalance(
            strtolower($player->getName()),
            ClosureContext::create(
                function (?int $balance) {
                    return $balance;
                },
            )
        );
        return 0;

languages

Currently the only available language is English, it needs to be translated to other languages if it gets released on poggit. Google translate is an option but it's obvious that it's not reliable enough for this use case

[Suggests] Balance Arrangements

add some arrangements in the amount of money, for example:

  • "1000 = 1K" -> for making shorter and more efficient.
  • "1000 = 1,000" -> Add commas in each number of thousands and others.

so in config there are several settings for the amount of balance option, for example we can choose one of the money arrangements

  • "shortcut" -> making balance shortener.
  • "commas" -> add every commas in each number of thousands and others.
  • "none" -> no one choose option, default settings

ConfigManager

Comments are not generated in new config when config version is outdated
Below is the config I get when the config is outdated

---
config-version: 2.0.5
language: en-US
utility:
  top-balance-accounts-limit: 10
currency:
  name: USD
  symbol: $
  balance:
    default-balance: 100
    balance-cap: 100000
    enable-balance-cap: false
  payment:
    minimum-payment: 100
    maximum-payment: 1000
database:
  provider: sqlite
  threads: 2
  mysql:
    host: 127.0.0.1
    username: your_username
    password: password
    schema: db_name
    port: 3306
  sqlite:
    file: players.db
...

Force update "resources" folder when updating the plugin

Is your feature request related to a problem? Please describe.
I just updated the version (to Dev #24) and the language section has not been updated.
I don't know if that happens with the config.yml (since in this update there have been no changes in that).
There are other plugins that do update the plugins_data when you add a new version and it contains changes in resources, although I don't know how it works since I'm not a dev.

Describe the solution you'd like
X

Describe alternatives you've considered
X

Additional context
X

MultiWorld support like ng cubecraft rtc

Pls add multiworld support to the plugin it would be a pleasure to all pocketmine community i understand bc i am also a server owner/developer i know it will be hard but it would surpass economy a lot bc it didnt have multiworld but u can do it
Thank You-

ScoreHud bug

when money added to balance scorehud removes the formatting.

So everything looks fine up untill i add balance than the formatting dissapears.

Better arrangement

Could you possibly add better arrangements.

for instance change 1000 = 1.000 or 1k

Would be very helpfull to have this both in the scorehud and the actual plugin

Question

Can you make the command for the ui.
idk how to do this on your way.
But the menu i can do!!!
i send in requests and you make the command.
Output:
$this->EcoUI($sender);

it is okay if i use Form api?
or have i to do it self?

Support Decimals

Add support for decimals so for example you can have $0.1 in your balance

missing behavior

currently the plugin doesn't use the minimum and maximum payment requirements and the balance limits.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.