mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-31 21:37:57 +01:00
iConomy 6/7 support and moved vault as soft dependent
This commit is contained in:
parent
911907818a
commit
f24811d44a
@ -7,5 +7,6 @@
|
||||
<classpathentry kind="lib" path="C:/Users/Arte/Desktop/Jobs/lib/CoreProtect_2.12.0.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Arte/Desktop/CheckMyInventory/lib/spigot-1.11.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Arte/Desktop/Jobs/lib/MythicMobs-2.1.8.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Arte/Desktop/Residence/lib/iConomy7.0.6.jar"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
||||
|
@ -20,14 +20,13 @@ package com.gamingmesh.jobs;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.gamingmesh.jobs.economy.BlackholeEconomy;
|
||||
import com.gamingmesh.jobs.economy.VaultEconomy;
|
||||
import com.gamingmesh.jobs.economy.IConomy6Adapter;
|
||||
|
||||
public class HookEconomyTask implements Runnable {
|
||||
private Jobs plugin;
|
||||
@ -38,29 +37,57 @@ public class HookEconomyTask implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Plugin eco = Bukkit.getServer().getPluginManager().getPlugin("Vault");
|
||||
if (eco != null) {
|
||||
RegisteredServiceProvider<Economy> provider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (provider != null) {
|
||||
Economy economy = provider.getProvider();
|
||||
if (economy != null) {
|
||||
Jobs.setEconomy(this.plugin, new VaultEconomy(economy));
|
||||
String message = ChatColor.translateAlternateColorCodes('&', "&e[" + this.plugin.getDescription().getName() + "] Successfully linked with Vault.");
|
||||
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||
console.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no Vault found
|
||||
if (setVault())
|
||||
return;
|
||||
|
||||
if (setIConomy())
|
||||
return;
|
||||
|
||||
// no Economy found
|
||||
Jobs.setEconomy(this.plugin, new BlackholeEconomy());
|
||||
Bukkit.getServer().getLogger().severe("==================== " + this.plugin.getDescription().getName() + " ====================");
|
||||
Bukkit.getServer().getLogger().severe("Vault is required by this plugin for economy support!");
|
||||
Bukkit.getServer().getLogger().severe("Please install Vault and economy manager first!");
|
||||
Bukkit.getServer().getLogger().severe("You can find the latest version here:");
|
||||
Bukkit.getServer().getLogger().severe("Vault or Iconomy is required by this plugin for economy support!");
|
||||
Bukkit.getServer().getLogger().severe("Please install them first!");
|
||||
Bukkit.getServer().getLogger().severe("You can find the latest versions here:");
|
||||
Bukkit.getServer().getLogger().severe("http://dev.bukkit.org/bukkit-plugins/vault/");
|
||||
Bukkit.getServer().getLogger().severe("https://dev.bukkit.org/bukkit-plugins/iconomy-7/");
|
||||
Bukkit.getServer().getLogger().severe("==============================================");
|
||||
}
|
||||
|
||||
private boolean setVault() {
|
||||
Plugin eco = Bukkit.getServer().getPluginManager().getPlugin("Vault");
|
||||
if (eco == null)
|
||||
return false;
|
||||
|
||||
RegisteredServiceProvider<Economy> provider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (provider == null)
|
||||
return false;
|
||||
|
||||
Economy economy = provider.getProvider();
|
||||
if (economy == null)
|
||||
return false;
|
||||
|
||||
Jobs.setEconomy(this.plugin, new VaultEconomy(economy));
|
||||
Jobs.consoleMsg("&e[" + this.plugin.getDescription().getName() + "] Successfully linked with Vault.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean setIConomy() {
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("iConomy");
|
||||
if (p == null)
|
||||
return false;
|
||||
|
||||
try {
|
||||
Jobs.setEconomy(this.plugin, new IConomy6Adapter((com.iCo6.iConomy) p));
|
||||
} catch (Exception e) {
|
||||
Jobs.consoleMsg("&e[" + this.plugin.getDescription().getName() + "] UNKNOWN iConomy version.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Jobs.consoleMsg("&e[" + this.plugin.getDescription().getName() + "] Successfully linked with iConomy! Version: " + p.getDescription().getVersion());
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1261,4 +1261,7 @@ public class Jobs extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void consoleMsg(String msg){
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.container.Log;
|
||||
import com.gamingmesh.jobs.container.LogAmounts;
|
||||
import com.gamingmesh.jobs.container.PlayerInfo;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
import com.gamingmesh.jobs.stuff.Sorting;
|
||||
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||
|
||||
|
2
com/gamingmesh/jobs/economy/.gitignore
vendored
2
com/gamingmesh/jobs/economy/.gitignore
vendored
@ -5,3 +5,5 @@
|
||||
/VaultEconomy.class
|
||||
/PaymentData.class
|
||||
/PointsData.class
|
||||
/IConomy6Adapter.class
|
||||
/IConomy7Adapter.class
|
||||
|
75
com/gamingmesh/jobs/economy/IConomy6Adapter.java
Normal file
75
com/gamingmesh/jobs/economy/IConomy6Adapter.java
Normal file
@ -0,0 +1,75 @@
|
||||
package com.gamingmesh.jobs.economy;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.iCo6.iConomy;
|
||||
import com.iCo6.system.Accounts;
|
||||
|
||||
public class IConomy6Adapter implements Economy {
|
||||
|
||||
iConomy icon;
|
||||
|
||||
public IConomy6Adapter(iConomy iconomy) {
|
||||
icon = iconomy;
|
||||
}
|
||||
|
||||
public double getBalance(String playerName) {
|
||||
checkExist(playerName);
|
||||
return new Accounts().get(playerName).getHoldings().getBalance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoney(OfflinePlayer offlinePlayer, double amount) {
|
||||
return hasMoney(offlinePlayer.getName(), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoney(String PlayerName, double amount) {
|
||||
checkExist(PlayerName);
|
||||
double holdings = this.getBalance(PlayerName);
|
||||
if (holdings >= amount) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean depositPlayer(String PlayerName, double amount) {
|
||||
checkExist(PlayerName);
|
||||
new Accounts().get(PlayerName).getHoldings().add(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean depositPlayer(OfflinePlayer offlinePlayer, double amount) {
|
||||
return depositPlayer(offlinePlayer.getName(), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawPlayer(String playerName, double amount) {
|
||||
checkExist(playerName);
|
||||
if (this.hasMoney(playerName, amount)) {
|
||||
new Accounts().get(playerName).getHoldings().subtract(amount);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawPlayer(OfflinePlayer offlinePlayer, double amount) {
|
||||
return withdrawPlayer(offlinePlayer.getName(), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(double money) {
|
||||
return iConomy.format(money);
|
||||
}
|
||||
|
||||
private static void checkExist(String playerName) {
|
||||
Accounts acc = new Accounts();
|
||||
if (!acc.exists(playerName)) {
|
||||
acc.create(playerName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,8 +3,7 @@ description: Jobs Plugin for the BukkitAPI
|
||||
main: com.gamingmesh.jobs.Jobs
|
||||
version: 3.7.0
|
||||
author: phrstbrn
|
||||
depend: [Vault]
|
||||
softdepend: [MythicMobs, McMMO]
|
||||
softdepend: [Vault, iConomy, MythicMobs, McMMO]
|
||||
commands:
|
||||
jobs:
|
||||
description: Jobs
|
||||
|
Loading…
Reference in New Issue
Block a user