2012-02-19 09:22:02 +01:00
/ * This file is part of Vault .
Vault is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
2011-06-29 02:18:20 +02:00
2012-02-19 09:22:02 +01:00
Vault is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with Vault . If not , see < http : //www.gnu.org/licenses/>.
* /
2011-06-29 02:18:20 +02:00
package net.milkbowl.vault ;
2013-12-24 20:02:05 +01:00
import java.io.BufferedReader ;
2012-01-31 23:11:48 +01:00
import java.io.IOException ;
2013-12-24 20:02:05 +01:00
import java.io.InputStreamReader ;
2012-01-16 02:10:53 +01:00
import java.lang.reflect.InvocationTargetException ;
import java.lang.reflect.Method ;
2011-12-03 10:30:44 +01:00
import java.net.URL ;
2013-12-24 20:02:05 +01:00
import java.net.URLConnection ;
2011-07-19 16:33:01 +02:00
import java.util.Collection ;
2011-06-29 02:18:20 +02:00
import java.util.logging.Logger ;
2011-10-23 22:18:23 +02:00
import net.milkbowl.vault.chat.Chat ;
2012-06-10 18:44:59 +02:00
import net.milkbowl.vault.chat.plugins.Chat_DroxPerms ;
2011-10-23 22:18:23 +02:00
import net.milkbowl.vault.chat.plugins.Chat_GroupManager ;
2014-02-21 19:03:30 +01:00
import net.milkbowl.vault.chat.plugins.Chat_OverPermissions ;
2011-10-23 22:18:23 +02:00
import net.milkbowl.vault.chat.plugins.Chat_Permissions3 ;
import net.milkbowl.vault.chat.plugins.Chat_PermissionsEx ;
2013-06-14 20:07:19 +02:00
import net.milkbowl.vault.chat.plugins.Chat_Privileges ;
2011-10-29 01:12:49 +02:00
import net.milkbowl.vault.chat.plugins.Chat_bPermissions ;
2012-02-01 16:20:39 +01:00
import net.milkbowl.vault.chat.plugins.Chat_bPermissions2 ;
2011-11-19 19:13:12 +01:00
import net.milkbowl.vault.chat.plugins.Chat_iChat ;
2011-10-23 22:18:23 +02:00
import net.milkbowl.vault.chat.plugins.Chat_mChat ;
2012-02-21 10:22:16 +01:00
import net.milkbowl.vault.chat.plugins.Chat_mChatSuite ;
2013-04-02 19:27:49 +02:00
import net.milkbowl.vault.chat.plugins.Chat_zPermissions ;
2013-09-04 07:02:56 +02:00
import net.milkbowl.vault.chat.plugins.Chat_rscPermissions ;
2011-06-30 17:14:09 +02:00
import net.milkbowl.vault.economy.Economy ;
import net.milkbowl.vault.economy.plugins.Economy_3co ;
2012-03-12 07:33:33 +01:00
import net.milkbowl.vault.economy.plugins.Economy_AEco ;
2011-10-10 08:02:05 +02:00
import net.milkbowl.vault.economy.plugins.Economy_BOSE6 ;
import net.milkbowl.vault.economy.plugins.Economy_BOSE7 ;
2012-10-16 22:02:16 +02:00
import net.milkbowl.vault.economy.plugins.Economy_CommandsEX ;
2012-01-16 17:01:30 +01:00
import net.milkbowl.vault.economy.plugins.Economy_Craftconomy ;
2012-08-11 21:20:18 +02:00
import net.milkbowl.vault.economy.plugins.Economy_Craftconomy3 ;
2011-12-30 18:03:21 +01:00
import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore ;
2014-01-10 02:31:13 +01:00
import net.milkbowl.vault.economy.plugins.Economy_DigiCoin ;
2012-09-23 22:47:07 +02:00
import net.milkbowl.vault.economy.plugins.Economy_Dosh ;
2011-12-03 19:35:49 +01:00
import net.milkbowl.vault.economy.plugins.Economy_EconXP ;
2011-06-30 17:14:09 +02:00
import net.milkbowl.vault.economy.plugins.Economy_Essentials ;
2012-07-01 19:18:48 +02:00
import net.milkbowl.vault.economy.plugins.Economy_GoldIsMoney ;
2012-09-03 03:10:42 +02:00
import net.milkbowl.vault.economy.plugins.Economy_GoldIsMoney2 ;
2013-12-30 03:11:34 +01:00
import net.milkbowl.vault.economy.plugins.Economy_GoldenChestEconomy ;
2012-08-03 04:32:27 +02:00
import net.milkbowl.vault.economy.plugins.Economy_Gringotts ;
2012-02-19 09:22:02 +01:00
import net.milkbowl.vault.economy.plugins.Economy_McMoney ;
2011-11-27 20:14:28 +01:00
import net.milkbowl.vault.economy.plugins.Economy_MineConomy ;
2011-09-23 08:43:48 +02:00
import net.milkbowl.vault.economy.plugins.Economy_MultiCurrency ;
2013-11-28 01:46:49 +01:00
import net.milkbowl.vault.economy.plugins.Economy_TAEcon ;
2012-12-17 17:02:29 +01:00
import net.milkbowl.vault.economy.plugins.Economy_XPBank ;
2011-11-27 20:28:23 +01:00
import net.milkbowl.vault.economy.plugins.Economy_eWallet ;
2011-06-30 17:14:09 +02:00
import net.milkbowl.vault.economy.plugins.Economy_iConomy4 ;
import net.milkbowl.vault.economy.plugins.Economy_iConomy5 ;
2011-08-11 23:18:25 +02:00
import net.milkbowl.vault.economy.plugins.Economy_iConomy6 ;
2012-12-22 23:40:59 +01:00
import net.milkbowl.vault.economy.plugins.Economy_SDFEconomy ;
2013-08-04 17:33:17 +02:00
import net.milkbowl.vault.economy.plugins.Economy_Minefaconomy ;
2011-06-30 17:14:09 +02:00
import net.milkbowl.vault.permission.Permission ;
2012-06-10 18:44:59 +02:00
import net.milkbowl.vault.permission.plugins.Permission_DroxPerms ;
2011-08-08 09:05:32 +02:00
import net.milkbowl.vault.permission.plugins.Permission_GroupManager ;
2014-02-21 19:03:30 +01:00
import net.milkbowl.vault.permission.plugins.Permission_OverPermissions ;
2011-08-09 17:43:15 +02:00
import net.milkbowl.vault.permission.plugins.Permission_Permissions3 ;
2011-09-18 10:19:35 +02:00
import net.milkbowl.vault.permission.plugins.Permission_PermissionsBukkit ;
2011-06-30 17:14:09 +02:00
import net.milkbowl.vault.permission.plugins.Permission_PermissionsEx ;
2012-06-06 06:08:01 +02:00
import net.milkbowl.vault.permission.plugins.Permission_Privileges ;
2012-04-30 16:18:06 +02:00
import net.milkbowl.vault.permission.plugins.Permission_SimplyPerms ;
2012-01-13 02:24:07 +01:00
import net.milkbowl.vault.permission.plugins.Permission_Starburst ;
2011-09-18 10:19:35 +02:00
import net.milkbowl.vault.permission.plugins.Permission_SuperPerms ;
2013-02-08 08:48:05 +01:00
import net.milkbowl.vault.permission.plugins.Permission_Xperms ;
2011-10-28 22:41:02 +02:00
import net.milkbowl.vault.permission.plugins.Permission_bPermissions ;
2012-02-01 16:20:39 +01:00
import net.milkbowl.vault.permission.plugins.Permission_bPermissions2 ;
2012-01-01 01:35:31 +01:00
import net.milkbowl.vault.permission.plugins.Permission_zPermissions ;
2013-06-27 21:32:35 +02:00
import net.milkbowl.vault.permission.plugins.Permission_TotalPermissions ;
2013-09-04 07:02:56 +02:00
import net.milkbowl.vault.permission.plugins.Permission_rscPermissions ;
2014-01-05 08:27:43 +01:00
import net.milkbowl.vault.permission.plugins.Permission_KPerms ;
2011-06-29 02:18:20 +02:00
2012-02-20 18:54:20 +01:00
import org.bukkit.Bukkit ;
import org.bukkit.OfflinePlayer ;
2011-06-30 15:49:26 +02:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
2011-06-30 17:14:09 +02:00
import org.bukkit.entity.Player ;
2012-01-25 23:31:13 +01:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
2011-12-10 05:14:28 +01:00
import org.bukkit.event.player.PlayerJoinEvent ;
2012-01-16 02:10:53 +01:00
import org.bukkit.event.server.PluginEnableEvent ;
2013-12-24 23:01:04 +01:00
import org.bukkit.permissions.PermissionDefault ;
2012-06-30 18:57:54 +02:00
import org.bukkit.plugin.Plugin ;
2011-07-19 16:33:01 +02:00
import org.bukkit.plugin.RegisteredServiceProvider ;
2011-07-19 15:25:12 +02:00
import org.bukkit.plugin.ServicePriority ;
2012-01-06 09:19:43 +01:00
import org.bukkit.plugin.ServicesManager ;
2011-06-29 02:18:20 +02:00
import org.bukkit.plugin.java.JavaPlugin ;
2013-12-24 20:02:05 +01:00
import org.json.simple.JSONArray ;
import org.json.simple.JSONObject ;
import org.json.simple.JSONValue ;
2011-06-29 02:18:20 +02:00
2012-01-16 02:10:53 +01:00
import com.nijikokun.register.payment.Methods ;
2014-01-10 02:31:13 +01:00
2013-10-03 02:15:35 +02:00
import net.milkbowl.vault.chat.plugins.Chat_TotalPermissions ;
2013-07-17 02:16:42 +02:00
import net.milkbowl.vault.economy.plugins.Economy_MiConomy ;
2012-01-16 02:10:53 +01:00
2011-06-29 02:18:20 +02:00
public class Vault extends JavaPlugin {
2011-08-12 19:11:25 +02:00
2014-01-28 21:06:24 +01:00
private static Logger log ;
2011-12-10 05:14:28 +01:00
private Permission perms ;
2013-12-24 22:27:46 +01:00
private String newVersionTitle = " " ;
private double newVersion = 0 ;
private double currentVersion = 0 ;
private String currentVersionTitle = " " ;
2012-01-06 09:19:43 +01:00
private ServicesManager sm ;
2012-01-31 23:11:48 +01:00
private Metrics metrics ;
2013-12-24 23:01:04 +01:00
private Vault plugin ;
2012-01-16 02:15:05 +01:00
2011-12-10 05:14:28 +01:00
@Override
public void onDisable ( ) {
// Remove all Service Registrations
getServer ( ) . getServicesManager ( ) . unregisterAll ( this ) ;
2012-12-27 01:22:32 +01:00
Bukkit . getScheduler ( ) . cancelTasks ( this ) ;
2011-12-10 05:14:28 +01:00
}
@Override
public void onEnable ( ) {
2013-12-24 23:01:04 +01:00
plugin = this ;
2014-01-28 21:06:24 +01:00
log = this . getLogger ( ) ;
2013-12-24 23:09:22 +01:00
currentVersionTitle = getDescription ( ) . getVersion ( ) . split ( " - " ) [ 0 ] ;
2013-12-24 22:27:46 +01:00
currentVersion = Double . valueOf ( currentVersionTitle . replaceFirst ( " \\ . " , " " ) ) ;
2012-01-06 09:19:43 +01:00
sm = getServer ( ) . getServicesManager ( ) ;
2014-01-28 21:20:52 +01:00
// set defaults
getConfig ( ) . addDefault ( " update-check " , true ) ;
getConfig ( ) . options ( ) . copyDefaults ( true ) ;
saveConfig ( ) ;
2014-02-21 19:03:30 +01:00
2011-12-10 05:14:28 +01:00
// Load Vault Addons
loadEconomy ( ) ;
loadPermission ( ) ;
loadChat ( ) ;
getCommand ( " vault-info " ) . setExecutor ( this ) ;
2012-02-20 18:54:20 +01:00
getCommand ( " vault-convert " ) . setExecutor ( this ) ;
2012-01-25 23:31:13 +01:00
getServer ( ) . getPluginManager ( ) . registerEvents ( new VaultListener ( ) , this ) ;
2013-12-24 22:19:03 +01:00
// Schedule to check the version every 30 minutes for an update. This is to update the most recent
// version so if an admin reconnects they will be warned about newer versions.
2013-12-24 23:01:04 +01:00
this . getServer ( ) . getScheduler ( ) . runTask ( this , new Runnable ( ) {
2012-01-16 02:15:05 +01:00
2013-12-24 22:19:03 +01:00
@Override
public void run ( ) {
2013-12-24 23:01:04 +01:00
// Programmatically set the default permission value cause Bukkit doesn't handle plugin.yml properly for Load order STARTUP plugins
org . bukkit . permissions . Permission perm = getServer ( ) . getPluginManager ( ) . getPermission ( " vault.update " ) ;
if ( perm = = null )
{
perm = new org . bukkit . permissions . Permission ( " vault.update " ) ;
perm . setDefault ( PermissionDefault . OP ) ;
plugin . getServer ( ) . getPluginManager ( ) . addPermission ( perm ) ;
}
perm . setDescription ( " Allows a user or the console to check for vault updates " ) ;
getServer ( ) . getScheduler ( ) . runTaskTimerAsynchronously ( plugin , new Runnable ( ) {
@Override
public void run ( ) {
2014-01-28 21:20:52 +01:00
if ( getServer ( ) . getConsoleSender ( ) . hasPermission ( " vault.update " ) & & getConfig ( ) . getBoolean ( " update-check " , true ) ) {
2013-12-24 23:01:04 +01:00
try {
newVersion = updateCheck ( currentVersion ) ;
2014-01-28 21:06:24 +01:00
log . info ( " Checking for Updates: " ) ;
2013-12-24 23:01:04 +01:00
if ( newVersion > currentVersion ) {
2014-01-28 21:06:24 +01:00
log . warning ( " Stable Version: " + newVersionTitle + " is out! " + " You are still running version: " + currentVersionTitle ) ;
log . warning ( " Update at: http://dev.bukkit.org/server-mods/vault " ) ;
2013-12-24 23:01:04 +01:00
} else if ( currentVersion > newVersion ) {
2014-01-29 02:26:13 +01:00
log . info ( " Stable Version: " + newVersionTitle + " | Current Version: " + currentVersionTitle ) ;
2013-12-24 23:01:04 +01:00
} else {
log . info ( " No new version available " ) ;
}
} catch ( Exception e ) {
// ignore exceptions
}
2013-12-24 21:36:51 +01:00
}
2011-12-12 08:46:43 +01:00
}
2013-12-24 23:01:04 +01:00
} , 0 , 432000 ) ;
2013-12-24 22:19:03 +01:00
2013-12-24 23:01:04 +01:00
}
2014-02-21 19:03:30 +01:00
2013-12-24 23:01:04 +01:00
} ) ;
2012-01-16 02:15:05 +01:00
2012-02-01 01:11:03 +01:00
// Load up the Plugin metrics
2012-01-31 23:11:48 +01:00
try {
2013-06-29 15:41:59 +02:00
metrics = new Metrics ( this ) ;
metrics . findCustomData ( ) ;
metrics . start ( ) ;
2012-01-31 23:11:48 +01:00
} catch ( IOException e ) {
// ignore exception
}
2011-12-10 05:14:28 +01:00
log . info ( String . format ( " [%s] Enabled Version %s " , getDescription ( ) . getName ( ) , getDescription ( ) . getVersion ( ) ) ) ;
}
/ * *
* Attempts to load Chat Addons
* /
private void loadChat ( ) {
2012-06-30 09:11:51 +02:00
// Try to load PermissionsEx
hookChat ( " PermissionsEx " , Chat_PermissionsEx . class , ServicePriority . Highest , " ru.tehkode.permissions.bukkit.PermissionsEx " ) ;
2012-06-10 18:44:59 +02:00
2012-06-30 09:11:51 +02:00
// Try to load mChatSuite
hookChat ( " mChatSuite " , Chat_mChatSuite . class , ServicePriority . Highest , " in.mDev.MiracleM4n.mChatSuite.mChatSuite " ) ;
2012-02-21 10:22:16 +01:00
2012-06-30 09:11:51 +02:00
// Try to load mChat
hookChat ( " mChat " , Chat_mChat . class , ServicePriority . Highest , " net.D3GN.MiracleM4n.mChat " ) ;
2012-01-16 02:15:05 +01:00
2014-02-21 19:03:30 +01:00
// Try to load OverPermissions
hookChat ( " OverPermissions " , Chat_OverPermissions . class , ServicePriority . Highest , " com.overmc.overpermissions.OverPermissions " ) ;
2012-06-30 09:11:51 +02:00
// Try to load DroxPerms Chat
hookChat ( " DroxPerms " , Chat_DroxPerms . class , ServicePriority . Lowest , " de.hydrox.bukkit.DroxPerms.DroxPerms " ) ;
2012-06-10 18:44:59 +02:00
2012-06-30 09:11:51 +02:00
// Try to load bPermssions 2
hookChat ( " bPermssions2 " , Chat_bPermissions2 . class , ServicePriority . Highest , " de.bananaco.bpermissions.api.ApiLayer " ) ;
2012-02-19 02:04:43 +01:00
2012-06-30 09:11:51 +02:00
// Try to load bPermissions 1
hookChat ( " bPermissions " , Chat_bPermissions . class , ServicePriority . Normal , " de.bananaco.permissions.info.InfoReader " ) ;
2012-01-16 02:15:05 +01:00
2012-06-30 09:11:51 +02:00
// Try to load GroupManager
hookChat ( " GroupManager " , Chat_GroupManager . class , ServicePriority . Normal , " org.anjocaido.groupmanager.GroupManager " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load Permissions 3 (Yeti)
hookChat ( " Permissions3 " , Chat_Permissions3 . class , ServicePriority . Normal , " com.nijiko.permissions.ModularControl " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load iChat
hookChat ( " iChat " , Chat_iChat . class , ServicePriority . Low , " net.TheDgtl.iChat.iChat " ) ;
2013-04-02 19:27:49 +02:00
// Try to load zPermissions
hookChat ( " zPermissions " , Chat_zPermissions . class , ServicePriority . Normal , " org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata " ) ;
2013-06-14 20:07:19 +02:00
// Try to load Privileges
hookChat ( " Privileges " , Chat_Privileges . class , ServicePriority . Normal , " net.krinsoft.privileges.Privileges " ) ;
2013-12-24 21:36:51 +01:00
2013-09-04 07:02:56 +02:00
// Try to load rscPermissions
hookChat ( " rscPermissions " , Chat_rscPermissions . class , ServicePriority . Normal , " ru.simsonic.rscPermissions.MainPluginClass " ) ;
2013-10-03 02:15:35 +02:00
//Try to load TotalPermissions
hookChat ( " TotalPermissions " , Chat_TotalPermissions . class , ServicePriority . Normal , " net.ar97.totalpermissions.TotalPermissions " ) ;
2011-12-10 05:14:28 +01:00
}
/ * *
* Attempts to load Economy Addons
* /
private void loadEconomy ( ) {
2013-07-17 02:16:42 +02:00
// Try to load MiConomy
hookEconomy ( " MiConomy " , Economy_MiConomy . class , ServicePriority . Normal , " com.gmail.bleedobsidian.miconomy.Main " ) ;
2013-12-24 21:36:51 +01:00
2013-08-04 17:33:17 +02:00
// Try to load MiFaConomy
2014-01-17 16:37:26 +01:00
hookEconomy ( " MineFaConomy " , Economy_Minefaconomy . class , ServicePriority . Normal , " me.coniin.plugins.minefaconomy.Minefaconomy " ) ;
2012-06-30 09:11:51 +02:00
// Try to load MultiCurrency
hookEconomy ( " MultiCurrency " , Economy_MultiCurrency . class , ServicePriority . Normal , " me.ashtheking.currency.Currency " , " me.ashtheking.currency.CurrencyList " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load MineConomy
hookEconomy ( " MineConomy " , Economy_MineConomy . class , ServicePriority . Normal , " me.mjolnir.mineconomy.MineConomy " ) ;
2012-04-10 02:28:18 +02:00
2012-06-30 09:11:51 +02:00
// Try to load AEco
hookEconomy ( " AEco " , Economy_AEco . class , ServicePriority . Normal , " org.neocraft.AEco.AEco " ) ;
2012-05-10 00:06:02 +02:00
2012-06-30 09:11:51 +02:00
// Try to load McMoney
hookEconomy ( " McMoney " , Economy_McMoney . class , ServicePriority . Normal , " boardinggamer.mcmoney.McMoneyAPI " ) ;
2012-02-19 09:22:02 +01:00
2012-06-30 09:11:51 +02:00
// Try to load Craftconomy
hookEconomy ( " CraftConomy " , Economy_Craftconomy . class , ServicePriority . Normal , " me.greatman.Craftconomy.Craftconomy " ) ;
2012-12-27 01:22:32 +01:00
2012-08-11 21:20:18 +02:00
// Try to load Craftconomy3
2013-06-15 07:20:19 +02:00
hookEconomy ( " CraftConomy3 " , Economy_Craftconomy3 . class , ServicePriority . Normal , " com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader " ) ;
2012-01-30 01:15:15 +01:00
2012-06-30 09:11:51 +02:00
// Try to load eWallet
hookEconomy ( " eWallet " , Economy_eWallet . class , ServicePriority . Normal , " me.ethan.eWallet.ECO " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load 3co
hookEconomy ( " 3co " , Economy_3co . class , ServicePriority . Normal , " me.ic3d.eco.ECO " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load BOSEconomy 6
hookEconomy ( " BOSEconomy6 " , Economy_BOSE6 . class , ServicePriority . Normal , " cosine.boseconomy.BOSEconomy " , " cosine.boseconomy.CommandManager " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load BOSEconomy 7
hookEconomy ( " BOSEconomy7 " , Economy_BOSE7 . class , ServicePriority . Normal , " cosine.boseconomy.BOSEconomy " , " cosine.boseconomy.CommandHandler " ) ;
2012-01-16 02:15:05 +01:00
2012-06-30 09:11:51 +02:00
// Try to load CurrencyCore
hookEconomy ( " CurrencyCore " , Economy_CurrencyCore . class , ServicePriority . Normal , " is.currency.Currency " ) ;
2012-01-16 02:15:05 +01:00
2012-08-08 23:45:38 +02:00
// Try to load Gringotts
hookEconomy ( " Gringotts " , Economy_Gringotts . class , ServicePriority . Normal , " org.gestern.gringotts.Gringotts " ) ;
2012-12-27 01:22:32 +01:00
2012-06-30 09:11:51 +02:00
// Try to load Essentials Economy
hookEconomy ( " Essentials Economy " , Economy_Essentials . class , ServicePriority . Low , " com.earth2me.essentials.api.Economy " , " com.earth2me.essentials.api.NoLoanPermittedException " , " com.earth2me.essentials.api.UserDoesNotExistException " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load iConomy 4
hookEconomy ( " iConomy 4 " , Economy_iConomy4 . class , ServicePriority . High , " com.nijiko.coelho.iConomy.iConomy " , " com.nijiko.coelho.iConomy.system.Account " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load iConomy 5
hookEconomy ( " iConomy 5 " , Economy_iConomy5 . class , ServicePriority . High , " com.iConomy.iConomy " , " com.iConomy.system.Account " , " com.iConomy.system.Holdings " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load iConomy 6
hookEconomy ( " iConomy 6 " , Economy_iConomy6 . class , ServicePriority . High , " com.iCo6.iConomy " ) ;
2011-12-10 05:14:28 +01:00
2012-06-30 09:11:51 +02:00
// Try to load EconXP
hookEconomy ( " EconXP " , Economy_EconXP . class , ServicePriority . Normal , " ca.agnate.EconXP.EconXP " ) ;
2012-07-01 19:18:48 +02:00
// Try to load GoldIsMoney
hookEconomy ( " GoldIsMoney " , Economy_GoldIsMoney . class , ServicePriority . Normal , " com.flobi.GoldIsMoney.GoldIsMoney " ) ;
2012-09-03 03:10:42 +02:00
// Try to load GoldIsMoney2
hookEconomy ( " GoldIsMoney2 " , Economy_GoldIsMoney2 . class , ServicePriority . Normal , " com.flobi.GoldIsMoney2.GoldIsMoney " ) ;
2012-12-27 01:22:32 +01:00
2013-12-30 03:11:34 +01:00
// Try to load GoldenChestEconomy
hookEconomy ( " GoldenChestEconomy " , Economy_GoldenChestEconomy . class , ServicePriority . Normal , " me.igwb.GoldenChest.GoldenChestEconomy " ) ;
2014-02-21 19:03:30 +01:00
2012-09-23 22:47:07 +02:00
// Try to load Dosh
hookEconomy ( " Dosh " , Economy_Dosh . class , ServicePriority . Normal , " com.gravypod.Dosh.Dosh " ) ;
2012-12-27 01:22:32 +01:00
2012-10-16 22:02:16 +02:00
// Try to load CommandsEX Economy
hookEconomy ( " CommandsEX " , Economy_CommandsEX . class , ServicePriority . Normal , " com.github.zathrus_writer.commandsex.api.EconomyAPI " ) ;
2013-12-24 21:36:51 +01:00
2012-12-22 23:40:59 +01:00
// Try to load SDFEconomy Economy
hookEconomy ( " SDFEconomy " , Economy_SDFEconomy . class , ServicePriority . Normal , " com.github.omwah.SDFEconomy.SDFEconomy " ) ;
2013-12-24 21:36:51 +01:00
2012-12-17 17:02:29 +01:00
// Try to load XPBank
hookEconomy ( " XPBank " , Economy_XPBank . class , ServicePriority . Normal , " com.gmail.mirelatrue.xpbank.XPBank " ) ;
2013-12-24 21:36:51 +01:00
2013-11-28 01:46:49 +01:00
// Try to load TAEcon
hookEconomy ( " TAEcon " , Economy_TAEcon . class , ServicePriority . Normal , " net.teamalpha.taecon.TAEcon " ) ;
2014-02-21 19:03:30 +01:00
2014-01-10 02:31:13 +01:00
// Try to load DigiCoin
hookEconomy ( " DigiCoin " , Economy_DigiCoin . class , ServicePriority . Normal , " co.uk.silvania.cities.digicoin.DigiCoin " ) ;
2011-12-10 05:14:28 +01:00
}
/ * *
* Attempts to load Permission Addons
* /
private void loadPermission ( ) {
2012-06-30 09:11:51 +02:00
// Try to load Starburst
hookPermission ( " Starburst " , Permission_Starburst . class , ServicePriority . Highest , " com.dthielke.starburst.StarburstPlugin " ) ;
2012-01-16 02:15:05 +01:00
2012-06-30 09:11:51 +02:00
// Try to load PermissionsEx
hookPermission ( " PermissionsEx " , Permission_PermissionsEx . class , ServicePriority . Highest , " ru.tehkode.permissions.bukkit.PermissionsEx " ) ;
2011-12-10 05:14:28 +01:00
2014-02-21 19:03:30 +01:00
// Try to load OverPermissions
hookPermission ( " OverPermissions " , Permission_OverPermissions . class , ServicePriority . Highest , " com.overmc.overpermissions.OverPermissions " ) ;
2012-06-30 09:11:51 +02:00
// Try to load PermissionsBukkit
2012-08-14 22:22:05 +02:00
hookPermission ( " PermissionsBukkit " , Permission_PermissionsBukkit . class , ServicePriority . Normal , " com.platymuus.bukkit.permissions.PermissionsPlugin " ) ;
2012-02-19 02:04:43 +01:00
2012-06-30 09:11:51 +02:00
// Try to load DroxPerms
hookPermission ( " DroxPerms " , Permission_DroxPerms . class , ServicePriority . High , " de.hydrox.bukkit.DroxPerms.DroxPerms " ) ;
2012-06-10 18:44:59 +02:00
2012-06-30 09:11:51 +02:00
// Try to load SimplyPerms
hookPermission ( " SimplyPerms " , Permission_SimplyPerms . class , ServicePriority . Highest , " net.crystalyx.bukkit.simplyperms.SimplyPlugin " ) ;
2012-02-19 02:04:43 +01:00
2012-06-30 09:11:51 +02:00
// Try to load bPermissions2
hookPermission ( " bPermissions 2 " , Permission_bPermissions2 . class , ServicePriority . Highest , " de.bananaco.bpermissions.api.WorldManager " ) ;
2012-02-19 02:04:43 +01:00
2012-06-30 09:11:51 +02:00
// Try to load zPermission
2013-04-21 09:14:14 +02:00
hookPermission ( " zPermissions " , Permission_zPermissions . class , ServicePriority . High , " org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsPlugin " ) ;
2012-01-16 02:15:05 +01:00
2012-06-30 09:11:51 +02:00
// Try to load Privileges
hookPermission ( " Privileges " , Permission_Privileges . class , ServicePriority . Highest , " net.krinsoft.privileges.Privileges " ) ;
2012-06-30 01:23:18 +02:00
2012-06-30 09:11:51 +02:00
// Try to load bPermissions
hookPermission ( " bPermissions " , Permission_bPermissions . class , ServicePriority . High , " de.bananaco.permissions.SuperPermissionHandler " ) ;
2012-06-10 18:44:59 +02:00
2012-06-30 09:11:51 +02:00
// Try to load GroupManager
hookPermission ( " GroupManager " , Permission_GroupManager . class , ServicePriority . High , " org.anjocaido.groupmanager.GroupManager " ) ;
2012-06-30 01:23:18 +02:00
2012-06-30 09:11:51 +02:00
// Try to load Permissions 3 (Yeti)
2012-08-14 22:22:05 +02:00
hookPermission ( " Permissions 3 (Yeti) " , Permission_Permissions3 . class , ServicePriority . Normal , " com.nijiko.permissions.ModularControl " ) ;
2013-12-24 21:36:51 +01:00
2013-02-08 08:48:05 +01:00
// Try to load Xperms
hookPermission ( " Xperms " , Permission_Xperms . class , ServicePriority . Low , " com.github.sebc722.Xperms " ) ;
2012-06-30 01:23:18 +02:00
2013-06-27 21:32:35 +02:00
//Try to load TotalPermissions
hookPermission ( " TotalPermissions " , Permission_TotalPermissions . class , ServicePriority . Normal , " net.ae97.totalpermissions.TotalPermissions " ) ;
2013-12-24 21:36:51 +01:00
2013-09-04 07:02:56 +02:00
// Try to load rscPermissions
hookPermission ( " rscPermissions " , Permission_rscPermissions . class , ServicePriority . Normal , " ru.simsonic.rscPermissions.MainPluginClass " ) ;
2013-06-27 21:32:35 +02:00
2014-02-21 19:03:30 +01:00
// Try to load KPerms
2014-01-05 08:27:43 +01:00
hookPermission ( " KPerms " , Permission_KPerms . class , ServicePriority . Normal , " com.lightniinja.kperms.KPermsPlugin " ) ;
2014-02-21 19:03:30 +01:00
2012-06-30 01:23:18 +02:00
Permission perms = new Permission_SuperPerms ( this ) ;
sm . register ( Permission . class , perms , this , ServicePriority . Lowest ) ;
log . info ( String . format ( " [%s][Permission] SuperPermissions loaded as backup permission system. " , getDescription ( ) . getName ( ) ) ) ;
this . perms = sm . getRegistration ( Permission . class ) . getProvider ( ) ;
}
2012-06-30 09:11:51 +02:00
2012-06-30 03:47:04 +02:00
private void hookChat ( String name , Class < ? extends Chat > hookClass , ServicePriority priority , String . . . packages ) {
2012-05-10 00:06:02 +02:00
try {
2012-06-30 03:47:04 +02:00
if ( packagesExists ( packages ) ) {
2012-06-30 18:57:54 +02:00
Chat chat = hookClass . getConstructor ( Plugin . class , Permission . class ) . newInstance ( this , perms ) ;
2012-06-30 01:23:18 +02:00
sm . register ( Chat . class , chat , this , priority ) ;
log . info ( String . format ( " [%s][Chat] %s found: %s " , getDescription ( ) . getName ( ) , name , chat . isEnabled ( ) ? " Loaded " : " Waiting " ) ) ;
2012-05-10 00:06:02 +02:00
}
} catch ( Exception e ) {
2012-06-30 03:47:04 +02:00
log . severe ( String . format ( " [%s][Chat] There was an error hooking %s - check to make sure you're using a compatible version! " , getDescription ( ) . getName ( ) , name ) ) ;
2012-01-30 01:15:15 +01:00
}
2012-06-30 01:23:18 +02:00
}
2012-06-30 09:11:51 +02:00
2012-06-30 03:47:04 +02:00
private void hookEconomy ( String name , Class < ? extends Economy > hookClass , ServicePriority priority , String . . . packages ) {
2012-05-10 00:06:02 +02:00
try {
2012-06-30 03:47:04 +02:00
if ( packagesExists ( packages ) ) {
2012-06-30 18:57:54 +02:00
Economy econ = hookClass . getConstructor ( Plugin . class ) . newInstance ( this ) ;
2012-06-30 01:23:18 +02:00
sm . register ( Economy . class , econ , this , priority ) ;
log . info ( String . format ( " [%s][Economy] %s found: %s " , getDescription ( ) . getName ( ) , name , econ . isEnabled ( ) ? " Loaded " : " Waiting " ) ) ;
2012-05-10 00:06:02 +02:00
}
} catch ( Exception e ) {
2012-06-30 03:47:04 +02:00
log . severe ( String . format ( " [%s][Economy] There was an error hooking %s - check to make sure you're using a compatible version! " , getDescription ( ) . getName ( ) , name ) ) ;
2011-12-10 05:14:28 +01:00
}
2012-06-30 01:23:18 +02:00
}
2012-06-30 09:11:51 +02:00
2012-06-30 03:47:04 +02:00
private void hookPermission ( String name , Class < ? extends Permission > hookClass , ServicePriority priority , String . . . packages ) {
2012-05-10 00:06:02 +02:00
try {
2012-06-30 03:47:04 +02:00
if ( packagesExists ( packages ) ) {
2012-06-30 18:57:54 +02:00
Permission perms = hookClass . getConstructor ( Plugin . class ) . newInstance ( this ) ;
2012-06-30 01:23:18 +02:00
sm . register ( Permission . class , perms , this , priority ) ;
log . info ( String . format ( " [%s][Permission] %s found: %s " , getDescription ( ) . getName ( ) , name , perms . isEnabled ( ) ? " Loaded " : " Waiting " ) ) ;
2012-05-10 00:06:02 +02:00
}
} catch ( Exception e ) {
2012-06-30 03:47:04 +02:00
log . severe ( String . format ( " [%s][Permission] There was an error hooking %s - check to make sure you're using a compatible version! " , getDescription ( ) . getName ( ) , name ) ) ;
2011-12-10 05:14:28 +01:00
}
}
@Override
public boolean onCommand ( CommandSender sender , Command command , String commandLabel , String [ ] args ) {
2013-12-24 21:36:51 +01:00
if ( ! sender . hasPermission ( " vault.admin " ) ) {
sender . sendMessage ( " You do not have permission to use that command! " ) ;
2011-12-10 05:14:28 +01:00
}
2012-02-20 18:54:20 +01:00
if ( command . getName ( ) . equalsIgnoreCase ( " vault-info " ) ) {
infoCommand ( sender ) ;
return true ;
} else if ( command . getName ( ) . equalsIgnoreCase ( " vault-convert " ) ) {
convertCommand ( sender , args ) ;
return true ;
2012-04-06 20:10:22 +02:00
} else {
2012-02-20 18:54:20 +01:00
// Show help
sender . sendMessage ( " Vault Commands: " ) ;
sender . sendMessage ( " /vault-info - Displays information about Vault " ) ;
2012-02-21 10:22:16 +01:00
sender . sendMessage ( " /vault-convert [economy1] [economy2] - Converts from one Economy to another " ) ;
2012-02-20 18:54:20 +01:00
return true ;
}
}
2011-12-10 05:14:28 +01:00
2012-02-20 18:54:20 +01:00
private void convertCommand ( CommandSender sender , String [ ] args ) {
Collection < RegisteredServiceProvider < Economy > > econs = this . getServer ( ) . getServicesManager ( ) . getRegistrations ( Economy . class ) ;
if ( econs = = null | | econs . size ( ) < 2 ) {
sender . sendMessage ( " You must have at least 2 economies loaded to convert. " ) ;
return ;
} else if ( args . length ! = 2 ) {
2012-07-31 15:45:00 +02:00
sender . sendMessage ( " You must specify only the economy to convert from and the economy to convert to. (names should not contain spaces) " ) ;
2012-02-20 18:54:20 +01:00
return ;
}
Economy econ1 = null ;
Economy econ2 = null ;
for ( RegisteredServiceProvider < Economy > econ : econs ) {
String econName = econ . getProvider ( ) . getName ( ) . replace ( " " , " " ) ;
if ( econName . equalsIgnoreCase ( args [ 0 ] ) ) {
econ1 = econ . getProvider ( ) ;
} else if ( econName . equalsIgnoreCase ( args [ 1 ] ) ) {
econ2 = econ . getProvider ( ) ;
2011-12-10 05:14:28 +01:00
}
2012-02-20 18:54:20 +01:00
}
2012-02-21 10:22:16 +01:00
2012-02-20 18:54:20 +01:00
if ( econ1 = = null ) {
sender . sendMessage ( " Could not find " + args [ 0 ] + " loaded on the server, check your spelling " ) ;
return ;
} else if ( econ2 = = null ) {
sender . sendMessage ( " Could not find " + args [ 1 ] + " loaded on the server, check your spelling " ) ;
return ;
}
2012-02-21 10:22:16 +01:00
2012-02-20 18:54:20 +01:00
sender . sendMessage ( " This may take some time to convert, expect server lag. " ) ;
for ( OfflinePlayer op : Bukkit . getServer ( ) . getOfflinePlayers ( ) ) {
2014-05-09 04:13:05 +02:00
if ( econ1 . hasAccount ( op ) ) {
if ( econ2 . hasAccount ( op ) ) {
2012-02-20 18:54:20 +01:00
continue ;
2011-12-10 05:14:28 +01:00
}
2014-05-09 04:13:05 +02:00
econ2 . createPlayerAccount ( op ) ;
econ2 . depositPlayer ( op , econ1 . getBalance ( op ) ) ;
2011-12-10 05:14:28 +01:00
}
2012-02-20 18:54:20 +01:00
}
2012-08-08 21:45:30 +02:00
sender . sendMessage ( " Converson complete, please verify the data before using it. " ) ;
2012-02-20 18:54:20 +01:00
}
2011-12-10 05:14:28 +01:00
2012-02-20 18:54:20 +01:00
private void infoCommand ( CommandSender sender ) {
// Get String of Registered Economy Services
String registeredEcons = null ;
Collection < RegisteredServiceProvider < Economy > > econs = this . getServer ( ) . getServicesManager ( ) . getRegistrations ( Economy . class ) ;
for ( RegisteredServiceProvider < Economy > econ : econs ) {
Economy e = econ . getProvider ( ) ;
if ( registeredEcons = = null ) {
registeredEcons = e . getName ( ) ;
} else {
registeredEcons + = " , " + e . getName ( ) ;
}
}
2011-12-10 05:14:28 +01:00
2012-02-20 18:54:20 +01:00
// Get String of Registered Permission Services
String registeredPerms = null ;
Collection < RegisteredServiceProvider < Permission > > perms = this . getServer ( ) . getServicesManager ( ) . getRegistrations ( Permission . class ) ;
for ( RegisteredServiceProvider < Permission > perm : perms ) {
Permission p = perm . getProvider ( ) ;
if ( registeredPerms = = null ) {
registeredPerms = p . getName ( ) ;
} else {
registeredPerms + = " , " + p . getName ( ) ;
}
2011-12-10 05:14:28 +01:00
}
2012-02-20 18:54:20 +01:00
2012-04-25 16:21:24 +02:00
String registeredChats = null ;
Collection < RegisteredServiceProvider < Chat > > chats = this . getServer ( ) . getServicesManager ( ) . getRegistrations ( Chat . class ) ;
for ( RegisteredServiceProvider < Chat > chat : chats ) {
Chat c = chat . getProvider ( ) ;
if ( registeredChats = = null ) {
registeredChats = c . getName ( ) ;
} else {
registeredChats + = " , " + c . getName ( ) ;
}
}
2012-05-10 00:06:02 +02:00
2012-02-20 18:54:20 +01:00
// Get Economy & Permission primary Services
2012-04-25 16:16:44 +02:00
RegisteredServiceProvider < Economy > rsp = getServer ( ) . getServicesManager ( ) . getRegistration ( Economy . class ) ;
Economy econ = null ;
if ( rsp ! = null ) {
econ = rsp . getProvider ( ) ;
}
Permission perm = null ;
RegisteredServiceProvider < Permission > rspp = getServer ( ) . getServicesManager ( ) . getRegistration ( Permission . class ) ;
if ( rspp ! = null ) {
perm = rspp . getProvider ( ) ;
}
2012-04-25 16:21:24 +02:00
Chat chat = null ;
RegisteredServiceProvider < Chat > rspc = getServer ( ) . getServicesManager ( ) . getRegistration ( Chat . class ) ;
if ( rspc ! = null ) {
chat = rspc . getProvider ( ) ;
}
2012-02-20 18:54:20 +01:00
// Send user some info!
sender . sendMessage ( String . format ( " [%s] Vault v%s Information " , getDescription ( ) . getName ( ) , getDescription ( ) . getVersion ( ) ) ) ;
2012-04-25 16:16:44 +02:00
sender . sendMessage ( String . format ( " [%s] Economy: %s [%s] " , getDescription ( ) . getName ( ) , econ = = null ? " None " : econ . getName ( ) , registeredEcons ) ) ;
sender . sendMessage ( String . format ( " [%s] Permission: %s [%s] " , getDescription ( ) . getName ( ) , perm = = null ? " None " : perm . getName ( ) , registeredPerms ) ) ;
2012-04-25 16:21:24 +02:00
sender . sendMessage ( String . format ( " [%s] Chat: %s [%s] " , getDescription ( ) . getName ( ) , chat = = null ? " None " : chat . getName ( ) , registeredChats ) ) ;
2011-12-10 05:14:28 +01:00
}
2012-01-16 02:15:05 +01:00
2011-12-10 05:14:28 +01:00
/ * *
* Determines if all packages in a String array are within the Classpath
* This is the best way to determine if a specific plugin exists and will be
* loaded . If the plugin package isn ' t loaded , we shouldn ' t bother waiting
* for it !
* @param packages String Array of package names to check
* @return Success or Failure
* /
2012-06-30 03:47:04 +02:00
private static boolean packagesExists ( String . . . packages ) {
2011-12-10 05:14:28 +01:00
try {
for ( String pkg : packages ) {
Class . forName ( pkg ) ;
}
return true ;
} catch ( Exception e ) {
return false ;
}
}
2012-01-16 02:15:05 +01:00
2013-12-24 22:23:35 +01:00
public double updateCheck ( double currentVersion ) {
2011-12-10 05:14:28 +01:00
try {
2013-12-24 22:23:35 +01:00
URL url = new URL ( " https://api.curseforge.com/servermods/files?projectids=33184 " ) ;
2013-12-24 20:02:05 +01:00
URLConnection conn = url . openConnection ( ) ;
conn . setReadTimeout ( 5000 ) ;
conn . addRequestProperty ( " User-Agent " , " Vault Update Checker " ) ;
conn . setDoOutput ( true ) ;
final BufferedReader reader = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) ) ) ;
final String response = reader . readLine ( ) ;
final JSONArray array = ( JSONArray ) JSONValue . parse ( response ) ;
2013-12-24 21:36:51 +01:00
2013-12-24 20:02:05 +01:00
if ( array . size ( ) = = 0 ) {
this . getLogger ( ) . warning ( " No files found, or Feed URL is bad. " ) ;
return currentVersion ;
2011-12-10 05:14:28 +01:00
}
2013-12-24 20:02:05 +01:00
// Pull the last version from the JSON
2013-12-24 23:09:22 +01:00
newVersionTitle = ( ( String ) ( ( JSONObject ) array . get ( array . size ( ) - 1 ) ) . get ( " name " ) ) . replace ( " Vault " , " " ) . trim ( ) ;
return Double . valueOf ( newVersionTitle . replaceFirst ( " \\ . " , " " ) . trim ( ) ) ;
2014-02-02 05:54:28 +01:00
} catch ( Exception e ) {
log . info ( " There was an issue attempting to check for the latest version. " ) ;
2011-12-10 05:14:28 +01:00
}
2011-12-18 19:38:09 +01:00
return currentVersion ;
2011-12-10 05:14:28 +01:00
}
2012-01-16 02:15:05 +01:00
2012-01-25 23:31:13 +01:00
public class VaultListener implements Listener {
2012-01-16 02:15:05 +01:00
2012-01-25 23:31:13 +01:00
@EventHandler ( priority = EventPriority . MONITOR )
2011-12-10 05:14:28 +01:00
public void onPlayerJoin ( PlayerJoinEvent event ) {
Player player = event . getPlayer ( ) ;
2013-12-24 21:36:51 +01:00
if ( perms . has ( player , " vault.update " ) ) {
2011-12-10 05:14:28 +01:00
try {
2012-02-18 20:16:13 +01:00
if ( newVersion > currentVersion ) {
2014-01-29 02:34:04 +01:00
player . sendMessage ( " Vault " + newVersion + " is out! You are running " + currentVersion ) ;
2011-12-10 05:14:28 +01:00
player . sendMessage ( " Update Vault at: http://dev.bukkit.org/server-mods/vault " ) ;
}
} catch ( Exception e ) {
// Ignore exceptions
}
}
}
2012-01-30 01:15:15 +01:00
2012-01-25 23:31:13 +01:00
@EventHandler ( priority = EventPriority . MONITOR )
2012-01-16 02:10:53 +01:00
public void onPluginEnable ( PluginEnableEvent event ) {
2012-06-30 03:47:04 +02:00
if ( event . getPlugin ( ) . getDescription ( ) . getName ( ) . equals ( " Register " ) & & packagesExists ( " com.nijikokun.register.payment.Methods " ) ) {
2012-01-16 02:15:05 +01:00
if ( ! Methods . hasMethod ( ) ) {
try {
Method m = Methods . class . getMethod ( " addMethod " , Methods . class ) ;
m . setAccessible ( true ) ;
m . invoke ( null , " Vault " , new net . milkbowl . vault . VaultEco ( ) ) ;
if ( ! Methods . setPreferred ( " Vault " ) ) {
log . info ( " Unable to hook register " ) ;
} else {
log . info ( " [Vault] - Successfully injected Vault methods into Register. " ) ;
}
} catch ( SecurityException e ) {
log . info ( " Unable to hook register " ) ;
} catch ( NoSuchMethodException e ) {
log . info ( " Unable to hook register " ) ;
} catch ( IllegalArgumentException e ) {
log . info ( " Unable to hook register " ) ;
} catch ( IllegalAccessException e ) {
log . info ( " Unable to hook register " ) ;
} catch ( InvocationTargetException e ) {
2012-01-16 02:10:53 +01:00
log . info ( " Unable to hook register " ) ;
}
}
}
}
}
2012-12-22 23:40:59 +01:00
}