-
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
1 parent
273b7c7
commit 474de5c
Showing
8 changed files
with
168 additions
and
1 deletion.
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
29 changes: 29 additions & 0 deletions
29
src/main/java/us/mytheria/bloblib/utilities/CashFormat.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,29 @@ | ||
package us.mytheria.bloblib.utilities; | ||
|
||
import net.md_5.bungee.api.ChatColor; | ||
|
||
import java.text.NumberFormat; | ||
|
||
public class CashFormat { | ||
|
||
static NumberFormat numberFormat; | ||
|
||
static { | ||
numberFormat = NumberFormat.getInstance(); | ||
numberFormat.setGroupingUsed(true); | ||
numberFormat.setMaximumFractionDigits(2); | ||
} | ||
|
||
public static String numberFormat(Double number) { | ||
return numberFormat.format(number).replace("\u00A0", ","); | ||
} | ||
|
||
public static String format(double number) { | ||
if (number >= 0) | ||
return ChatColor.translateAlternateColorCodes('&', | ||
"&a+ $&l" + numberFormat.format(number).replace("\u00A0", ",")); | ||
else | ||
return ChatColor.translateAlternateColorCodes('&', | ||
"&c- $&l" + numberFormat.format(number).replace("\u00A0", ",")); | ||
} | ||
} |
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,24 @@ | ||
package us.mytheria.bloblib.vault; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
public class Absent implements Vault { | ||
|
||
@Override | ||
public void addCash(Player player, double amount) { | ||
} | ||
|
||
@Override | ||
public void setCash(Player player, double amount) { | ||
} | ||
|
||
@Override | ||
public boolean hasCashAmount(Player player, double amount) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public double getCash(Player player) { | ||
return 0; | ||
} | ||
} |
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 us.mytheria.bloblib.vault; | ||
|
||
import net.milkbowl.vault.economy.Economy; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
|
||
public class Found implements Vault { | ||
private Economy economy; | ||
|
||
private boolean setupEconomy() { | ||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); | ||
if (rsp == null) { | ||
return false; | ||
} | ||
economy = rsp.getProvider(); | ||
return economy != null; | ||
} | ||
|
||
public Found() { | ||
setupEconomy(); | ||
} | ||
|
||
@Override | ||
public void addCash(Player player, double amount) { | ||
economy.depositPlayer(player, amount); | ||
} | ||
|
||
@Override | ||
public void setCash(Player player, double amount) { | ||
economy.withdrawPlayer(player, economy.getBalance(player)); | ||
economy.depositPlayer(player, amount); | ||
} | ||
|
||
@Override | ||
public boolean hasCashAmount(Player player, double amount) { | ||
return economy.has(player, amount); | ||
} | ||
|
||
@Override | ||
public double getCash(Player player) { | ||
return economy.getBalance(player); | ||
} | ||
} |
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,14 @@ | ||
package us.mytheria.bloblib.vault; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
public interface Vault { | ||
|
||
void addCash(Player player, double amount); | ||
|
||
void setCash(Player player, double amount); | ||
|
||
boolean hasCashAmount(Player player, double amount); | ||
|
||
double getCash(Player player); | ||
} |
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,38 @@ | ||
package us.mytheria.bloblib.vault; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
public class VaultManager { | ||
private Vault vault; | ||
private boolean vaultInstalled = false; | ||
|
||
public VaultManager() { | ||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) { | ||
vault = new Found(); | ||
vaultInstalled = true; | ||
} else { | ||
vault = new Absent(); | ||
} | ||
} | ||
|
||
public void addCash(Player player, double amount) { | ||
vault.addCash(player, amount); | ||
} | ||
|
||
public void setCash(Player player, double amount) { | ||
vault.setCash(player, amount); | ||
} | ||
|
||
public boolean hasCashAmount(Player player, double amount) { | ||
return vault.hasCashAmount(player, amount); | ||
} | ||
|
||
public double getCash(Player player) { | ||
return vault.getCash(player); | ||
} | ||
|
||
public boolean isVaultInstalled() { | ||
return vaultInstalled; | ||
} | ||
} |
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