ericgrandt / TotalEconomy

All in one economy plugin for Minecraft.
https://ericgrandt.github.io/TotalEconomy/
MIT License
32 stars 33 forks source link

Make /pay @a possible for console #136

Closed crymates closed 8 months ago

crymates commented 7 years ago

Could you add the function that /pay in console is able to reduce coins from all online players? It's just like paying fees. Currently /pay -[amount] is supported, that's nice, but, u know, for roleplay servers it would be great to easy setup an fees-system that way.

Greetz, Hannes

crymates commented 7 years ago

The command should be "/pay -100 @a" ;] Also possible just for some players like "/pay -100 @p[name=yololetsplay]". I Hope u know what I mean. It's default supported by minecraft using /execute and some other commands.

MarkL4YG commented 7 years ago

I think adminpay using negative values does just that. I don't know if @a works for that though. I would suggest it's up to sponge to run the command using every player if @a is used 🤔 (Including the developer uses the provided CommandExecutors)

@Erigitic while we're at it: Is there a specific reason for pay being usable for adminpays purpose when used by a command block or console?

ericgrandt commented 7 years ago

@MarkL4YG I have no idea why I made it so the pay command could be used from the console/command blocks. Odd... I will remove that from the next release as it really does not make much sense to have it in there as far as I can tell. Good catch!

@yololetsplay This would most likely have to be a custom implementation on our end to get it to affect all players. You said this can currently be done using the "/execute" command correct? If that's the case, what would be the advantage of having a custom implementation on Total Economy's end?

crymates commented 7 years ago

Ya the problem is with /execute I cannot remove any money, it's just that there the possibility of @a is given, it was just to explain ;]

Btw. u added /pay minus-amount bc of one of my tickets ;] The background behind is that there is no other way to remove money currently. But: The player cannot have an negative amount of money and this is okay.

MarkL4YG commented 7 years ago

If execute works, why not just let them execute a command that pays you? Doesn't /execute @a ~ ~ ~ /pay yololetsplay 50 work as intended?

ericgrandt commented 7 years ago

@yololetsplay The adminpay command can handle negative amounts and can be run from the console and command blocks. /adminpay -100 Erigitic

MarkL4YG commented 7 years ago

@Erigitic but does /adminpay -100 @a work?

ericgrandt commented 7 years ago

@MarkL4YG I have no idea on that one.

MarkL4YG commented 7 years ago

@Erigitic me neither ^^ Maybe @yololetsplay could test if target selectors work on TEs commands.

However, I think, whenever a dev uses the CommandExecutor it should be up to Sponge to parse (and implement) these arguments since they're doing the argument parsing. 🤔

crymates commented 7 years ago

@MarkL4YG U did it!! /adminpay -100 @a works just great! Thx alot! U saved my day ;]

MarkL4YG commented 7 years ago

uhm, well, okay, glad I could help then ^^''

ericgrandt commented 7 years ago

@yololetsplay Glad to hear that worked out!

crymates commented 7 years ago

Well guys, found an bug :D If you are alone on the server and run /adminpay @ -5 it works, but if you are more players online this issue is found in the console:

[13:42:32] [Server thread/INFO] [nucleus/]: Server ran the command: /adminpay @a -5
[13:42:32] [Server thread/ERROR] [Sponge/]: Error occurred while executing command 'adminpay @a -5' for source DedicatedServer: No value present
java.util.NoSuchElementException: No value present
    at java.util.Optional.get(Optional.java:135) ~[?:1.8.0_111]
    at com.erigitic.commands.AdminPayCommand.execute(AdminPayCommand.java:66) ~[AdminPayCommand.class:?]
    at org.spongepowered.api.command.spec.CommandSpec.process(CommandSpec.java:351) ~[CommandSpec.class:1.11-2178-6.0.0-BETA-1999]
    at org.spongepowered.api.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:333) ~[SimpleDispatcher.class:1.11-2178-6.0.0-BETA-1999]
    at org.spongepowered.common.command.SpongeCommandManager.process(SpongeCommandManager.java:291) [SpongeCommandManager.class:1.11-2178-6.0.0-BETA-1999]
    at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:83) [bd.class:?]
    at net.minecraft.server.dedicated.DedicatedServer.func_71333_ah(DedicatedServer.java:420) [lh.class:?]
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:385) [lh.class:?]
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:624) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
[13:42:53] [HikariPool-1 housekeeper/DEBUG] [com.zaxxer.hikari.pool.HikariPool/sponge]: HikariPool-1 - Pool stats (total=9, active=0, idle=9, waiting=0)
[13:42:54] [HikariPool-2 housekeeper/DEBUG] [com.zaxxer.hikari.pool.HikariPool/sponge]: HikariPool-2 - Pool stats (total=9, active=0, idle=9, waiting=0)
[13:42:56] [Server thread/DEBUG] [FML/]: Gathering id map for writing to world save world
[13:43:23] [HikariPool-1 housekeeper/DEBUG] [com.zaxxer.hikari.pool.HikariPool/sponge]: HikariPool-1 - Pool stats (total=9, active=0, idle=9, waiting=0)
[13:43:24] [HikariPool-2 housekeeper/DEBUG] [com.zaxxer.hikari.pool.HikariPool/sponge]: HikariPool-2 - Pool stats (total=9, active=0, idle=9, waiting=0)

Hope this helps you to maybe fix this in the next release ;]

Greetz, Hannes

MarkL4YG commented 7 years ago

Will try to reproduce this this evening and see what I'll come up with (Yep, living in CET). Thanks for providing the stack trace!

crymates commented 7 years ago

Thx alot @MarkL4YG ;]

MarkL4YG commented 7 years ago

So, I'm back with some results, but unfortunately I currently can't provide a fix commit due to lack of time ^^'' However!: @Erigitic I would suggest reconstructing all commandExecutors in TotalEconomy because
CommadContext.<T>getOne becomes an empty optional whenever multiple targets are used. (such cases are e.g. targetSelectors) This is resolved by using

CommandContext.<Collection<?>>getAll(String key)

instead. It returns an Immutable collection of all targets - even one with only one entry if the target is just a player as normal. A fix that would support single and multiple targets would then just be an iteration over this collection for each individual target.

ericgrandt commented 7 years ago

@MarkL4YG Sounds good. Will get this changed over within the week.

MarkL4YG commented 7 years ago

A "little" off topic: Seems like GitHub notifications don't update when texts are edited 🤔 "2 days ago yololetsplay commented on issue Erigitic/TotalEconomy#136 (at)yololetsplay Thx alot @MarkL4YG ;] Well, germany like me? :D"

@yololetsplay Yes, Germany ;)

ericgrandt commented 7 years ago

Going to push this one off till later.

RedstoneGithub commented 6 years ago

Is this fixed yet? /adminpay 100 @a or /adminpay -100 @a still doesn't work for me

MarkL4YG commented 6 years ago

No not yet. TotalEconomy is using Sponges CommandSpec builder and selects Player as the second argument. Since Sponge parses the commands and then calls the executor it theoretically should be up to Sponge to support this.
However there is a new command system WIP and I don't know how that handles vanillas selectors.
Is there a special reason you need the all selector here instead of just using salaries?