GithubHelp home page GithubHelp logo

emibergo02 / rediseconomy Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 5.0 477 KB

Economy plugin made with redis

Home Page: https://www.spigotmc.org/resources/rediseconomy%E2%9A%A1-unlimited-currencies-cross-server-open-source.105965/

Java 100.00%
economy-plugin minecraft redis spigot

rediseconomy's Introduction

Stats Metrics

rediseconomy's People

Contributors

emibergo02 avatar

Stargazers

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

Watchers

 avatar  avatar

rediseconomy's Issues

RedisEco data storage

Hi. How safe is Redis Eco? Will the balance of the players remain after the restart of the dedicated server, I still have a bad understanding of how the Redis-server works.

Plugin messaging channel

[09:47:02 WARN]: [RedisEconomy] Async task for RedisEconomy v4.3.9-SNAPSHOT generated an exception
org.bukkit.plugin.messaging.ChannelNotRegisteredException: Attempted to send a plugin message through the unregistered channel `BungeeCord'.
        at org.bukkit.plugin.messaging.StandardMessenger.validatePluginMessage(StandardMessenger.java:544) ~[purpur-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer.sendPluginMessage(CraftPlayer.java:2346) ~[purpur-1.20.4.jar:git-Purpur-2153]
        at dev.unnm3d.rediseconomy.config.ConfigManager.sendServerIdRequest(ConfigManager.java:122) ~[RedisEconomy-4.3.9-SNAPSHOT.jar:?]
        at dev.unnm3d.rediseconomy.config.ConfigManager$1.lambda$onJoin$0(ConfigManager.java:98) ~[RedisEconomy-4.3.9-SNAPSHOT.jar:?]
        at dev.unnm3d.shaded.universalScheduler.foliaScheduler.FoliaScheduler.lambda$runTaskLaterAsynchronously$13(FoliaScheduler.java:140) ~[RedisEconomy-4.3.9-SNAPSHOT.jar:?]
        at io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler$AsyncScheduledTask.run(FoliaAsyncScheduler.java:217) ~[purpur-1.20.4.jar:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
        ```

Feature requests: Internal currency name and default currency

Heya!
We're currently switching from CMI's currency system to yours and noticed a few QoL things that'd make the integration into other plugins and the general usability a bit easier.

First

Internal Vault currency name
Have an internal currency name that supports legacy color codes.
Why? It seems like a handful of plugins doesn't support MiniMessage yet and therefore, currency names look completely off.


Edit:
If it is not possible to get such an internal value due to vault we would like to ask if it would be possible to add minedown support (minedown supports colour leagecy code) and make it adjustable in the config file whether you want to use this or minimessage.
https://github.com/Phoenix616/MineDown

Example with QuickShop-Hikari (QS dev is aware):
image

Possible config option:

currencies:
- currencyName: vault
  currencySingle: <i><b><green>I</green></b></i>
  currencyPlural: <i><b><green>I</green></b></i>
  currencyNameInternal: §2§lI
  decimalFormat: '#.##'
  languageTag: en-US
  startingBalance: 100.0
  payTax: 0.0

Second

Set default Vault currency when none is specified

When using a command like balance/money <player> <currency> give <amount> [reason...], make <currency> optional by falling back to a specified default currency set in the config (Vault, QuestPoints etc).

How To Install Redis in MC Server?

I have followeds your steps on how to create a redis.uri but what now? what do I have to do to activate it on my server?

I am renting a server from sparked host.

Common problems

The cause of this problem:

java.lang.NullPointerException: Cannot invoke 
"org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" 
because the return value of "org.bukkit.Server.getPluginCommand(String)" is null
at dev.unnm3d.rediseconomy.RedisEconomyPlugin.onEnable(RedisEconomyPlugin.java:75) ~[RedisEconomy-3.2.1-SNAPSHOT.jar:?]
. . .

is probably caused by CMI overriding /pay and other commands (check #10)

RedisEconomy Unable to load

Hello, I get this error when trying to load RedisEconomy

[18:24:46] [Server thread/ERROR]: Error occurred while enabling RedisEconomy v3.2.1-SNAPSHOT (Is it up to date?)
java.lang.NullPointerException: Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "org.bukkit.Server.getPluginCommand(String)" is null
	at dev.unnm3d.rediseconomy.RedisEconomyPlugin.onEnable(RedisEconomyPlugin.java:75) ~[RedisEconomy-3.2.1-SNAPSHOT.jar:?]
	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:542) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?]
	at org.bukkit.craftbukkit.v1_19_R1.CraftServer.enablePlugin(CraftServer.java:567) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at org.bukkit.craftbukkit.v1_19_R1.CraftServer.enablePlugins(CraftServer.java:481) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:640) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:426) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:309) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1105) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:308) ~[paper-1.19.2.jar:git-light-"aaf5e39"]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]

plugin stopped working

After restarting the server, the following error occurs: [00:35:10 INFO]: [RedisEconomy] Enabling RedisEconomy v4.2.3-SNAPSHOT*
[00:35:10 ERROR]: Error occurred while enabling RedisEconomy v4.2.3-SNAPSHOT (Is it up to date?)
java.lang.IllegalArgumentException: Listener can not be null
at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[patched_1.17.1.jar:git-Purpur-1428]
at org.bukkit.plugin.java.JavaPluginLoader.createRegisteredListeners(JavaPluginLoader.java:273) ~[patched_1.17.1.jar:git-Purpur-1428]
at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginManager.java:660) ~[patched_1.17.1.jar:git-Purpur-1428]
at dev.unnm3d.rediseconomy.RedisEconomyPlugin.onEnable(RedisEconomyPlugin.java:88) ~[RedisEconomy-4.2.3-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[patched_1.17.1.jar:git-Purpur-1428]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[patched_1.17.1.jar:git-Purpur-1428]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500) ~[patched_1.17.1.jar:git-Purpur-1428]
at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:561) ~[patched_1.17.1.jar:git-Purpur-1428]
at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:475) ~[patched_1.17.1.jar:git-Purpur-1428]
at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:323) ~[patched_1.17.1.jar:git-Purpur-1428]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1233) ~[patched_1.17.1.jar:git-Purpur-1428]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:322) ~[patched_1.17.1.jar:git-Purpur-1428]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
[00:35:10 INFO]: [RedisEconomy] Disabling RedisEconomy v4.2.3-SNAPSHOT

Better api for currency

I am making a baltop command which combines Vault balance and Bank plugin's balances. You use Lettuce as a dependency and method Currency#getOrderedAccounts returns Lettuce's ScoredValue. And due to how Papaer loads lettuce dependency I can't use this ScoredValue. So I have to use reflections to do this:

        return currency.getOrderedAccounts(n)
                .thenApply(balances -> {
                    List<Account> accounts = new ArrayList<>();
                    for (Object tuple : balances) {
                        try {
                            Method getValueMethod = tuple.getClass().getMethod("getValue");
                            Object valueResult = getValueMethod.invoke(tuple);
                            Method getScoreMethod = tuple.getClass().getMethod("getScore");
                            Object scoreResult = getScoreMethod.invoke(tuple);

                            String valueAsString = String.valueOf(valueResult);
                            UUID uuid = UUID.fromString(valueAsString);
                            String username = RedisEconomyAPI.getAPI().getUsernameFromUUIDCache(uuid);
                            double amount = (Double) scoreResult;

                            // Add the new Account object to the list
                            accounts.add(new Account(username == null ? valueAsString + "-Unknown" : username, uuid, amount));
                            //System.out.println("Added account: " + username + " with balance: " + amount);
                        } catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                    return accounts;
                }).toCompletableFuture();

Paper loads libraries listed in plugin.yml with URLClassLoader. If i add Lettuce as a library it will be loaded with a different class loader than yours Lettuce thus I can't cast your ScoredValue to mine. Please make some DTO for this class to return instead of raw Lettuce object.

add database

hello so i have question can you add mysql database? Cause if i want to change my redis server or reset all of my player balance etc.. it would be easier to do that maybe redis server shutdown or something happen might get so much data loss

Vault Problem

I use the plugin without any problems with other plugins, but I have problems when I want to use it with the Townyadvanced plugin. There is no error in the console and logs. When I asked the developer of the Towny plugin, he replied, "There are lots of economy plugins that dont properly implement vault." I don't know what to do in this case.

minimum payment amount

add minimum payment amount, so that players do not spam /pay player 0.0001, and maybe it's worth adding cooldown.

Balance resets

Moving the private chat with Unmn3d on Discord here.

We've experienced balance resets when using RedisEconomy due to a race condition caused by EssentialsX economy forwarding vault transactions for some plugins, notably (but probably not limited to) quickshop.

Debug trace follows:

[02:09:32 INFO]: 01 Sent update account <account> to 0.0 [A]
[02:09:32 INFO]: 01 Sent update account <account> to 98668.0 [B]

Essentials, instead of doing a balance update based on addition and substraction, will reset the entire balance to 0, then set the new balance with the precomputed value. Since these two actions are triggered pretty much at the same time (not concurrently, but one right after the other), depending on the database and server load, the instructions might not be stored in the database in strict chronological order - needless to say this could be an issue, allowing some exploits in terms of balance amounts.

TLDR; classic race condition issue, [A] [B] should be executed in that order, but [B] ends up being stored before [A].

Proposed solutions (as someone who has never used redis):

  • adding a timestamp to balance updates, so values are only applied if they are newer than the last stored balance update (using millis [probably enough] or nanos as a timestamp value, ofc)
  • postfix solution in which the plugin backtracks local transaction history to apply the last correct expected value
  • (easiest fix but worst for performance for servers with a very large transaction volume or slow databases) adding locks to balance updates in order to limit concurrency.

Extra resources

  • Plugin I coded to test transaction burst with a similar behavior: link (can be used with /testbalance <cycle count> <player>
  • Test enviroment that will automatically spin up two papermc instances + redis with the provided plugin: link (docker compose up, ports 50001, 50002)

Note

  • /browse-transaction seems to always return the correct order, didn't test it in depth tho

Add MoneyFormat

Add an option to change money format (including for bal and top placeholders):
For example:

  • MoneyFormat: '###,###' // 1796943.53 --> 1,796,943
private static final DecimalFormat df = new DecimalFormat("###,###", new DecimalFormatSymbols(Locale.US));

public static String format(int input) {
        return df.format(input);
    }

(you forgot remove println() in 4.2.6 and update`s description on spigotmc has invalid placeholders, should be %rediseco_top_1_playerprefix_%)

Transactions disable feature

It would be nice if the plugin will leave an option for server owners to disable transaction history.
We have 500 MB data on our Redis server. That's not really much, but we don't have a lot of players,
so it would grow upon the players count.

Another idea is purging transactions data after some period of time, let's say a month.
Also could be configurable in the config file.

image
image

Currency symbol is duplicated

1. &7%rediseco_top_1_playerprefix_vault%%rediseco_top_1_name_vault% &f- {#78d264}%rediseco_top_1_bal_formatted_vault%
image

currencies:
- currencyName: vault
  currencySingle: ' &f1'
  currencyPlural: ' &f2'
  decimalFormat: '###,###'
  languageTag: en-US
  startingBalance: 0.0
  payTax: 0.0
  bankEnabled: false

Suggestion

When sending large amounts of money sometimes the player gets confused and puts an extra 0

format can be added to throw money.
example;
/pay {player} 400k (=/pay {player} 400000)
/pay {player} 2m (=/pay {player} 2000000)

Add Treasury Implementation

Two of the planned features can be accomplished directly through Treasury! Treasury allows for as many currencies to be registered as desired, and is based upon transactions, so transaction history can be fetched easily.

I'm the author of the library – we're currently working on an API revamp (version 2), so we recommend plugins to delay in writing an implementation for Treasury until we can release a beta version of v2.

Add shorthand placeholder

Create a placeholder that displays a shorthand of the balance; for example rather than 10000.00, display 10k (this helps with higher account balances)

Placeholder problem when used %rediseco_bal_short_<curency>%

Hi, i have a problem with the placeholder %rediseco_bal_short_%
When i use it, i wanna have for example 15.6 k but i have written 15.6$k
I may thinks it will be cool to get an other placeholder without "currency name" include when we use the placeholder

Thanks for looking my message
Have a nice day

New placeholders for top

Please add new placeholders:

  1. %rediseco_top_1_prefix_<currency>%
  2. %rediseco_top_1_suffix_<currency>%
  3. %rediseco_top_1_displayname_<currency>%
  4. %rediseco_top_position_<short/formatted>_<currency>% - Shows what position the player is at in the leaderboard
  • add MoneyFormat for formatted option

DisplayName must be stored in the database, since it cannot be obtained for an offline player. Prefix and Suffix can be taken from the Vault (or stored in the database as well)

general question

In general, people do not recommend keeping data in redis. As far as I can see you keep your data in redis, how healthy do you think that is? I want to use this plugin but I don't want my data to be lost (in case of power failure etc.).

Im sorry for my bad english

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.