io.github.dailystruggle.rtp.bukkit.tools.softdepends.VaultChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of RTP Show documentation
Show all versions of RTP Show documentation
a random teleport plugin
The newest version!
package io.github.dailystruggle.rtp.bukkit.tools.softdepends;
import io.github.dailystruggle.commandsapi.common.CommandsAPI;
import io.github.dailystruggle.rtp.common.RTP;
import io.github.dailystruggle.rtp.common.serverSide.substitutions.RTPEconomy;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.UUID;
public class VaultChecker implements RTPEconomy {
private static Economy econ = null;
private static Permission perms = null;
public static void setupEconomy() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return;
}
RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) return;
econ = rsp.getProvider();
}
public static void setupPermissions() {
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
return;
}
RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
if (rsp == null) return;
perms = rsp.getProvider();
}
public static Economy getEconomy() {
return econ;
}
public static Permission getPermissions() {
return perms;
}
@Override
public boolean give(UUID playerId, double money) {
if (playerId.equals(CommandsAPI.serverId)) return true;
if (econ == null) {
RTP.economy = null;
return true;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(playerId);
if (!player.isOnline()) return false;
EconomyResponse economyResponse = econ.depositPlayer(player, money);
return economyResponse.transactionSuccess();
}
@Override
public boolean take(UUID playerId, double money) {
if (playerId.equals(CommandsAPI.serverId)) return true;
if (econ == null) {
RTP.economy = null;
return true;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(playerId);
if (!player.isOnline()) return false;
EconomyResponse economyResponse = econ.withdrawPlayer(player, money);
return economyResponse.transactionSuccess();
}
@Override
public double bal(UUID playerId) {
if (playerId.equals(CommandsAPI.serverId)) return Double.MAX_VALUE;
if (econ == null) {
RTP.economy = null;
return 0;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(playerId);
if (!player.isOnline()) return 0;
return econ.getBalance(player);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy