-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
569 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ database: | |
user: minecity | ||
pass: password | ||
|
||
economy: vault | ||
|
||
permissions: | ||
default: | ||
nature: | ||
|
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
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
21 changes: 21 additions & 0 deletions
21
Core/src/main/java/br/com/gamemods/minecity/economy/BalanceResult.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package br.com.gamemods.minecity.economy; | ||
|
||
public class BalanceResult | ||
{ | ||
public static final BalanceResult TRUE = new BalanceResult(true); | ||
public static final BalanceResult FALSE = new BalanceResult(false); | ||
public final boolean result; | ||
|
||
public static BalanceResult of(boolean bool) | ||
{ | ||
if(bool) | ||
return TRUE; | ||
else | ||
return FALSE; | ||
} | ||
|
||
public BalanceResult(boolean result) | ||
{ | ||
this.result = result; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Core/src/main/java/br/com/gamemods/minecity/economy/EconomyProxy.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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package br.com.gamemods.minecity.economy; | ||
|
||
import br.com.gamemods.minecity.api.Async; | ||
import br.com.gamemods.minecity.api.PlayerID; | ||
import br.com.gamemods.minecity.api.world.WorldDim; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface EconomyProxy | ||
{ | ||
/** | ||
* Checks if a player has the amount of money in a given world | ||
* @param amount must be positive | ||
* @param world world to be checked | ||
* @return {@code true} if the player has the amount or if the economy does not support world specific balance | ||
* and the player has the amount in global scope. | ||
*/ | ||
@Async | ||
BalanceResult has(@NotNull PlayerID player, double amount, @NotNull WorldDim world); | ||
|
||
/** | ||
* Checks if a player has an amount of money | ||
* @param amount must be positive | ||
*/ | ||
@Async | ||
BalanceResult has(@NotNull PlayerID player, double amount); | ||
|
||
/** | ||
* Removes an amount of money from the player | ||
* @param amount must be positive | ||
* @param simulation if true nothing must be changed, the returned value must be only a simulation | ||
* @return requested amount - taken amount. Negative values = took too much, positive values = took too few, | ||
* if the it returns the same value as "amount" so nothing was taken | ||
* @throws IllegalArgumentException If amount is negative | ||
*/ | ||
@Async | ||
OperationResult take(@NotNull PlayerID player, double amount, @Nullable BalanceResult balance, boolean simulation) throws IllegalArgumentException; | ||
|
||
/** | ||
* Gives money to a player, the money should be added to the player's main account if possible. Item based economies with | ||
* bank support should deposit the value to the player's bank and auto-create it if possible, when it's not possible | ||
* to credit the bank then the implementation is allowed to give the money to the player in any way. | ||
* @param amount must be positive | ||
* @param simulation if true nothing must be changed, the returned value must be only a simulation | ||
* @return requested amount - taken amount. Negative values = gave too much, positive values = gave too few, | ||
* if the it returns the same value as "amount" so nothing was given | ||
* @throws IllegalArgumentException If amount is negative | ||
*/ | ||
@Async | ||
OperationResult credit(@NotNull PlayerID player, double amount, @Nullable BalanceResult balance, boolean simulation) throws IllegalArgumentException; | ||
|
||
/** | ||
* Removes an amount of money from the player | ||
* @param amount must be positive | ||
* @param simulation if true nothing must be changed, the returned value must be only a simulation | ||
* @return requested amount - taken amount. Negative values = took too much, positive values = took too few, | ||
* if the it returns the same value as "amount" so nothing was taken | ||
* @throws IllegalArgumentException If amount is negative | ||
*/ | ||
@Async | ||
OperationResult take(@NotNull PlayerID player, double amount, @Nullable BalanceResult balance, @NotNull WorldDim world, boolean simulation) throws IllegalArgumentException; | ||
|
||
/** | ||
* Gives money to a player, the money should be added to the player's main account if possible. Item based economies with | ||
* bank support should deposit the value to the player's bank and auto-create it if possible, when it's not possible | ||
* to credit the bank then the implementation is allowed to give the money to the player in any way. | ||
* @param amount must be positive | ||
* @param simulation if true nothing must be changed, the returned value must be only a simulation | ||
* @return requested amount - taken amount. Negative values = gave too much, positive values = gave too few, | ||
* if the it returns the same value as "amount" so nothing was given | ||
* @throws IllegalArgumentException If amount is negative | ||
*/ | ||
@Async | ||
OperationResult credit(@NotNull PlayerID player, double amount, @Nullable BalanceResult balance, @NotNull WorldDim world, boolean simulation) throws IllegalArgumentException; | ||
} |
22 changes: 22 additions & 0 deletions
22
Core/src/main/java/br/com/gamemods/minecity/economy/OperationResult.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package br.com.gamemods.minecity.economy; | ||
|
||
public class OperationResult | ||
{ | ||
public final boolean success; | ||
public final double amount; | ||
public final String error; | ||
|
||
public OperationResult(boolean success, double amount, String error) | ||
{ | ||
this.success = success; | ||
this.amount = amount; | ||
this.error = error; | ||
} | ||
|
||
public OperationResult(boolean success, double amount) | ||
{ | ||
this.success = success; | ||
this.amount = amount; | ||
this.error = null; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Core/src/main/java/br/com/gamemods/minecity/economy/VoidEconomy.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package br.com.gamemods.minecity.economy; | ||
|
||
import br.com.gamemods.minecity.api.PlayerID; | ||
import br.com.gamemods.minecity.api.world.WorldDim; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class VoidEconomy implements EconomyProxy | ||
{ | ||
@Override | ||
public BalanceResult has(@NotNull PlayerID player, double amount, @NotNull WorldDim world) | ||
{ | ||
return BalanceResult.FALSE; | ||
} | ||
|
||
@Override | ||
public BalanceResult has(@NotNull PlayerID player, double amount) | ||
{ | ||
return BalanceResult.FALSE; | ||
} | ||
|
||
@Override | ||
public OperationResult take(@NotNull PlayerID player, double amount, BalanceResult balance, boolean simulation) throws IllegalArgumentException | ||
{ | ||
return new OperationResult(false, amount, "Not Supported"); | ||
} | ||
|
||
@Override | ||
public OperationResult credit(@NotNull PlayerID player, double amount, BalanceResult balance, boolean simulation) throws IllegalArgumentException | ||
{ | ||
return new OperationResult(false, amount, "Not Supported"); | ||
} | ||
|
||
@Override | ||
public OperationResult take(@NotNull PlayerID player, double amount, BalanceResult balance, @NotNull WorldDim world, boolean simulation) throws IllegalArgumentException | ||
{ | ||
return take(player, amount, balance, simulation); | ||
} | ||
|
||
@Override | ||
public OperationResult credit(@NotNull PlayerID player, double amount, BalanceResult balance, @NotNull WorldDim world, boolean simulation) throws IllegalArgumentException | ||
{ | ||
return credit(player, amount, balance, simulation); | ||
} | ||
} |
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
Oops, something went wrong.