Skip to content

Commit

Permalink
fix lite-version cant link to vault problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Oct 19, 2024
1 parent 1112382 commit 1ff19f5
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 5 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var libraries = listOf<String>()
libraries = libraries + "cn.lunadeer:MinecraftPluginUtils:2.0.7"

group = "cn.lunadeer"
version = "2.14.1-beta"
version = "2.14.2-beta"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down Expand Up @@ -40,6 +40,8 @@ allprojects {
compileOnly("com.github.BlueMap-Minecraft:BlueMapAPI:v2.6.2")
compileOnly("us.dynmap:DynmapCoreAPI:3.4")
compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("net.milkbowl.vault:VaultUnlockedAPI:2.2")

if (!BuildFull) {
libraries.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.Particle;
import cn.lunadeer.dominion.utils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.utils.MessageDisplay;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import cn.lunadeer.dominion.utils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
Expand Down
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);
}
}
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();
}
}
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;
}
}
}
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);

}
Binary file added logos/logo4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.Particle;
import cn.lunadeer.dominion.utils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.Particle;
import cn.lunadeer.dominion.utils.VaultConnect.VaultConnect;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down

0 comments on commit 1ff19f5

Please sign in to comment.