generated from Rosewood-Development/RoseTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
504 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,91 @@ | ||
package xyz.oribuin.fishing.api.economy; | ||
|
||
/** | ||
* Represents a cost for an item | ||
* | ||
* @param currency The currency type | ||
* @param amount The amount of currency | ||
* @param symbol The symbol of the currency | ||
*/ | ||
public record Cost(Currency currency, int amount, String symbol) { | ||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class Cost implements Currency { | ||
|
||
private final Currency currency; | ||
private Number price; | ||
|
||
/** | ||
* Create a new cost object | ||
* Create a new cost object with a currency and amount | ||
* | ||
* @param currency The currency type | ||
* @param amount The amount of currency | ||
* @param currency The currency to use | ||
* @param price The amount of currency to use | ||
*/ | ||
public Cost(@NotNull Currency currency, @NotNull Number price) { | ||
this.currency = currency; | ||
this.price = price; | ||
} | ||
|
||
/** | ||
* @return The name of the currency | ||
*/ | ||
public Cost(Currency currency, int amount) { | ||
this(currency, amount, ""); | ||
@Override | ||
public String name() { | ||
return this.currency.name(); | ||
} | ||
|
||
/** | ||
* Check if the player has enough currency | ||
* Get the amount of currency the player has | ||
* | ||
* @param player The player to check | ||
*/ | ||
@Override | ||
public @NotNull Number amount(@NotNull OfflinePlayer player) { | ||
return this.currency.amount(player); | ||
} | ||
|
||
/** | ||
* Check if the player has enough currency to purchase an item | ||
* | ||
* @param player The player who is purchasing the item | ||
* @param amount The amount to check | ||
* | ||
* @return If the player has enough currency | ||
*/ | ||
public boolean has(int amount) { | ||
return this.amount >= amount; | ||
@Override | ||
public boolean has(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
return this.currency.has(player, amount); | ||
} | ||
|
||
/** | ||
* Give the player an amount of currency | ||
* | ||
* @param player The player to give the currency to | ||
* @param amount The amount to give | ||
*/ | ||
@Override | ||
public void give(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
this.currency.give(player, amount); | ||
} | ||
|
||
/** | ||
* Take an amount of currency from the player | ||
* | ||
* @param player The player to take the currency from | ||
* @param amount The amount to take | ||
*/ | ||
@Override | ||
public void take(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
this.currency.take(player, amount); | ||
} | ||
|
||
/** | ||
* @return The price of the item | ||
*/ | ||
public Number price() { | ||
return this.price; | ||
} | ||
|
||
/** | ||
* Add a price to the item cost | ||
* | ||
* @param price The price to add | ||
*/ | ||
public void price(Number price) { | ||
this.price = price; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/xyz/oribuin/fishing/api/economy/Currencies.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,28 @@ | ||
package xyz.oribuin.fishing.api.economy; | ||
|
||
import xyz.oribuin.fishing.api.economy.impl.EntropyCurrency; | ||
import xyz.oribuin.fishing.api.economy.impl.FishExpCurrency; | ||
import xyz.oribuin.fishing.api.economy.impl.PlayerExpCurrency; | ||
import xyz.oribuin.fishing.api.economy.impl.SkillpointCurrency; | ||
import xyz.oribuin.fishing.api.economy.impl.VaultCurrency; | ||
|
||
import java.util.PrimitiveIterator; | ||
|
||
public enum Currencies { | ||
ENTROPY(new EntropyCurrency()), | ||
FISH_EXP(new FishExpCurrency()), | ||
PLAYER_XP(new PlayerExpCurrency()), | ||
SKILL_POINTS(new SkillpointCurrency()), | ||
VAULT(new VaultCurrency()); | ||
|
||
private final Currency currency; | ||
|
||
Currencies(Currency currency) { | ||
this.currency = currency; | ||
} | ||
|
||
public Currency get() { | ||
return this.currency; | ||
} | ||
|
||
} |
64 changes: 57 additions & 7 deletions
64
src/main/java/xyz/oribuin/fishing/api/economy/Currency.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 |
---|---|---|
@@ -1,9 +1,59 @@ | ||
package xyz.oribuin.fishing.api.economy; | ||
|
||
public enum Currency { | ||
VAULT, // Vault economy plugin | ||
ENTROPY, // Entropy | ||
FISH_EXP, // Fish experience | ||
PLAYER_XP, // Player experience | ||
SKILL_POINTS, // Skill points | ||
} | ||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
import xyz.oribuin.fishing.FishingPlugin; | ||
import xyz.oribuin.fishing.manager.base.DataManager; | ||
import xyz.oribuin.fishing.storage.Fisher; | ||
|
||
public interface Currency { | ||
|
||
/** | ||
* @return The name of the currency | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* Get the amount of currency the player has | ||
* | ||
* @param player The player to check | ||
*/ | ||
@NotNull | ||
Number amount(@NotNull OfflinePlayer player); | ||
|
||
/** | ||
* Check if the player has enough currency to purchase an item | ||
* | ||
* @param player The player who is purchasing the item | ||
* @param amount The amount to check | ||
* | ||
* @return If the player has enough currency | ||
*/ | ||
boolean has(@NotNull OfflinePlayer player, @NotNull Number amount); | ||
|
||
/** | ||
* Give the player an amount of currency | ||
* | ||
* @param player The player to give the currency to | ||
* @param amount The amount to give | ||
*/ | ||
void give(@NotNull OfflinePlayer player, @NotNull Number amount); | ||
|
||
/** | ||
* Take an amount of currency from the player | ||
* | ||
* @param player The player to take the currency from | ||
* @param amount The amount to take | ||
*/ | ||
void take(@NotNull OfflinePlayer player, @NotNull Number amount); | ||
|
||
/** | ||
* Get the Fisher object for the player | ||
* | ||
* @param player The player to get the Fisher object for | ||
*/ | ||
default Fisher fisher(@NotNull OfflinePlayer player) { | ||
return FishingPlugin.get().getManager(DataManager.class).get(player.getUniqueId()); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/xyz/oribuin/fishing/api/economy/impl/EntropyCurrency.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,65 @@ | ||
package xyz.oribuin.fishing.api.economy.impl; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
import xyz.oribuin.fishing.api.economy.Currency; | ||
import xyz.oribuin.fishing.storage.Fisher; | ||
|
||
public class EntropyCurrency implements Currency { | ||
|
||
/** | ||
* @return The name of the currency | ||
*/ | ||
@Override | ||
public String name() { | ||
return "entropy"; | ||
} | ||
|
||
/** | ||
* Get the amount of currency the player has | ||
* | ||
* @param player The player to check | ||
*/ | ||
@Override | ||
public @NotNull Number amount(@NotNull OfflinePlayer player) { | ||
return this.fisher(player).entropy(); | ||
} | ||
|
||
/** | ||
* Check if the player has enough currency to purchase an item | ||
* | ||
* @param player The player who is purchasing the item | ||
* @param amount The amount to check | ||
* | ||
* @return If the player has enough currency | ||
*/ | ||
@Override | ||
public boolean has(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
return this.amount(player).intValue() >= amount.intValue(); | ||
} | ||
|
||
/** | ||
* Give the player an amount of currency | ||
* | ||
* @param player The player to give the currency to | ||
* @param amount The amount to give | ||
*/ | ||
@Override | ||
public void give(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
Fisher fisher = this.fisher(player); | ||
fisher.entropy(fisher.entropy() + amount.intValue()); | ||
} | ||
|
||
/** | ||
* Take an amount of currency from the player | ||
* | ||
* @param player The player to take the currency from | ||
* @param amount The amount to take | ||
*/ | ||
@Override | ||
public void take(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
Fisher fisher = this.fisher(player); | ||
fisher.entropy(fisher.entropy() - amount.intValue()); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/xyz/oribuin/fishing/api/economy/impl/FishExpCurrency.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,65 @@ | ||
package xyz.oribuin.fishing.api.economy.impl; | ||
|
||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
import xyz.oribuin.fishing.api.economy.Currency; | ||
import xyz.oribuin.fishing.storage.Fisher; | ||
|
||
public class FishExpCurrency implements Currency { | ||
|
||
/** | ||
* @return The name of the currency | ||
*/ | ||
@Override | ||
public String name() { | ||
return "fish_exp"; | ||
} | ||
|
||
/** | ||
* Get the amount of currency the player has | ||
* | ||
* @param player The player to check | ||
*/ | ||
@Override | ||
public @NotNull Number amount(@NotNull OfflinePlayer player) { | ||
return this.fisher(player).experience(); | ||
} | ||
|
||
/** | ||
* Check if the player has enough currency to purchase an item | ||
* | ||
* @param player The player who is purchasing the item | ||
* @param amount The amount to check | ||
* | ||
* @return If the player has enough currency | ||
*/ | ||
@Override | ||
public boolean has(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
return this.amount(player).intValue() >= amount.intValue(); | ||
} | ||
|
||
/** | ||
* Give the player an amount of currency | ||
* | ||
* @param player The player to give the currency to | ||
* @param amount The amount to give | ||
*/ | ||
@Override | ||
public void give(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
Fisher fisher = this.fisher(player); | ||
fisher.experience(fisher.experience() + amount.intValue()); | ||
} | ||
|
||
/** | ||
* Take an amount of currency from the player | ||
* | ||
* @param player The player to take the currency from | ||
* @param amount The amount to take | ||
*/ | ||
@Override | ||
public void take(@NotNull OfflinePlayer player, @NotNull Number amount) { | ||
Fisher fisher = this.fisher(player); | ||
fisher.experience(fisher.experience() - amount.intValue()); | ||
} | ||
|
||
} |
Oops, something went wrong.