-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix lite-version cant link to vault problem
- Loading branch information
1 parent
1112382
commit 1ff19f5
Showing
10 changed files
with
227 additions
and
5 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
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
49 changes: 49 additions & 0 deletions
49
core/src/main/java/cn/lunadeer/dominion/utils/VaultConnect/Vault.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,49 @@ | ||
package cn.lunadeer.dominion.utils.VaultConnect; | ||
|
||
import cn.lunadeer.minecraftpluginutils.XLogger; | ||
import cn.lunadeer.minecraftpluginutils.i18n.Localization; | ||
import net.milkbowl.vault.economy.Economy; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class Vault implements VaultInterface { | ||
|
||
private Economy econ = null; | ||
|
||
@Override | ||
public boolean init(JavaPlugin plugin) { | ||
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); | ||
if (rsp != null) { | ||
econ = rsp.getProvider(); | ||
return true; | ||
} | ||
XLogger.err(Localization.Utils_VaultNotAvailable); | ||
return false; | ||
} | ||
|
||
@Override | ||
public String currencyNamePlural() { | ||
return econ.currencyNamePlural(); | ||
} | ||
|
||
@Override | ||
public String currencyNameSingular() { | ||
return econ.currencyNameSingular(); | ||
} | ||
|
||
@Override | ||
public void withdrawPlayer(Player player, double amount) { | ||
econ.withdrawPlayer(player, amount); | ||
} | ||
|
||
@Override | ||
public void depositPlayer(Player player, double amount) { | ||
econ.depositPlayer(player, amount); | ||
} | ||
|
||
@Override | ||
public double getBalance(Player player) { | ||
return econ.getBalance(player); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
core/src/main/java/cn/lunadeer/dominion/utils/VaultConnect/Vault2.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,51 @@ | ||
package cn.lunadeer.dominion.utils.VaultConnect; | ||
|
||
import cn.lunadeer.minecraftpluginutils.XLogger; | ||
import cn.lunadeer.minecraftpluginutils.i18n.Localization; | ||
import net.milkbowl.vault2.economy.Economy; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class Vault2 implements VaultInterface { | ||
|
||
private Economy econ = null; | ||
|
||
@Override | ||
public boolean init(JavaPlugin plugin) { | ||
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); | ||
if (rsp != null) { | ||
econ = rsp.getProvider(); | ||
return true; | ||
} | ||
XLogger.err(Localization.Utils_VaultUnlockedNotAvailable); | ||
return false; | ||
} | ||
|
||
@Override | ||
public String currencyNamePlural() { | ||
return econ.defaultCurrencyNamePlural(); | ||
} | ||
|
||
@Override | ||
public String currencyNameSingular() { | ||
return econ.defaultCurrencyNameSingular(); | ||
} | ||
|
||
@Override | ||
public void withdrawPlayer(Player player, double amount) { | ||
econ.withdraw("MPU", player.getUniqueId(), BigDecimal.valueOf(amount)); | ||
} | ||
|
||
@Override | ||
public void depositPlayer(Player player, double amount) { | ||
econ.deposit("MPU", player.getUniqueId(), BigDecimal.valueOf(amount)); | ||
} | ||
|
||
@Override | ||
public double getBalance(Player player) { | ||
return econ.getBalance("MPU", player.getUniqueId()).doubleValue(); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
core/src/main/java/cn/lunadeer/dominion/utils/VaultConnect/VaultConnect.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,99 @@ | ||
package cn.lunadeer.dominion.utils.VaultConnect; | ||
|
||
import cn.lunadeer.minecraftpluginutils.XLogger; | ||
import cn.lunadeer.minecraftpluginutils.i18n.Localization; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.server.ServiceRegisterEvent; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class VaultConnect implements Listener { | ||
|
||
public static VaultConnect instance; | ||
private VaultInterface vaultInstance = null; | ||
private JavaPlugin plugin; | ||
|
||
public VaultConnect(JavaPlugin plugin) { | ||
this.plugin = plugin; | ||
instance = this; | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST) | ||
public void onEnable(ServiceRegisterEvent event) { | ||
} | ||
|
||
public boolean economyAvailable() { | ||
if (vaultInstance == null) { | ||
Plugin vaultPlugin = this.plugin.getServer().getPluginManager().getPlugin("Vault"); | ||
if (vaultPlugin == null) { | ||
XLogger.err(Localization.Utils_VaultNotAvailable); | ||
return false; | ||
} | ||
if (vaultPlugin.getDescription().getAuthors().contains("creatorfromhell")) { | ||
vaultInstance = new Vault2(); | ||
} else { | ||
vaultInstance = new Vault(); | ||
} | ||
if (!vaultInstance.init(plugin)) { | ||
vaultInstance = null; | ||
XLogger.err(Localization.Utils_NoEconomyPlugin); | ||
return false; | ||
} | ||
} | ||
XLogger.debug("Vault connected."); | ||
return true; | ||
} | ||
|
||
public String currencyNamePlural() { | ||
if (economyAvailable()) { | ||
return vaultInstance.currencyNamePlural(); | ||
} | ||
XLogger.warn(Localization.Utils_NoEconomyPlugin); | ||
return ""; | ||
} | ||
|
||
public String currencyNameSingular() { | ||
if (economyAvailable()) { | ||
return vaultInstance.currencyNameSingular(); | ||
} | ||
XLogger.warn(Localization.Utils_NoEconomyPlugin); | ||
return ""; | ||
} | ||
|
||
public void withdrawPlayer(Player player, double amount) { | ||
if (economyAvailable()) { | ||
vaultInstance.withdrawPlayer(player, amount); | ||
return; | ||
} | ||
XLogger.warn(Localization.Utils_NoEconomyPlugin); | ||
} | ||
|
||
public void depositPlayer(Player player, double amount) { | ||
if (economyAvailable()) { | ||
vaultInstance.depositPlayer(player, amount); | ||
return; | ||
} | ||
XLogger.warn(Localization.Utils_NoEconomyPlugin); | ||
} | ||
|
||
public double getBalance(Player player) { | ||
if (economyAvailable()) { | ||
return vaultInstance.getBalance(player); | ||
} | ||
XLogger.warn(Localization.Utils_NoEconomyPlugin); | ||
return 0; | ||
} | ||
|
||
private static boolean foundClass(String className) { | ||
try { | ||
Class.forName(className); | ||
return true; | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/cn/lunadeer/dominion/utils/VaultConnect/VaultInterface.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 cn.lunadeer.dominion.utils.VaultConnect; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public interface VaultInterface { | ||
|
||
public boolean init(JavaPlugin plugin); | ||
|
||
public String currencyNamePlural(); | ||
|
||
|
||
public String currencyNameSingular(); | ||
|
||
public void withdrawPlayer(Player player, double amount); | ||
|
||
public void depositPlayer(Player player, double amount); | ||
|
||
public double getBalance(Player player); | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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