mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-29 04:18:07 +01:00
refactor(vault): change way to hook providers
Also the Permission provider has been added to get permission of an offline player. This has be done to easily add more providers in the future but also avoid code repetitions (like logging if Vault is enabled).
This commit is contained in:
parent
e364609ec7
commit
96cfcf78e9
@ -1,80 +1,34 @@
|
||||
/**
|
||||
* Jobs Plugin for Bukkit
|
||||
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.gamingmesh.jobs.economy.BlackholeEconomy;
|
||||
import com.gamingmesh.jobs.economy.VaultEconomy;
|
||||
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
public class HookEconomyTask implements Runnable {
|
||||
|
||||
private Jobs plugin;
|
||||
|
||||
public HookEconomyTask(Jobs plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
enum hookResult {
|
||||
novault, noeconomy, pass;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
hookResult result = setVault();
|
||||
|
||||
if (result.equals(hookResult.pass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// no Economy found
|
||||
Jobs.setEconomy(new BlackholeEconomy());
|
||||
Jobs.getPluginLogger().severe("==================== " + plugin.getDescription().getName() + " ====================");
|
||||
if (result.equals(hookResult.novault)) {
|
||||
Jobs.getPluginLogger().severe("Vault is required by this plugin for economy support!");
|
||||
Jobs.getPluginLogger().severe("Please install them first!");
|
||||
Jobs.getPluginLogger().severe("You can find the latest versions here:");
|
||||
Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/34315/");
|
||||
} else {
|
||||
Jobs.getPluginLogger().severe("Vault detected but economy plugin still missing!");
|
||||
Jobs.getPluginLogger().severe("Please install Vault supporting economy plugin!");
|
||||
}
|
||||
Jobs.getPluginLogger().severe("==============================================");
|
||||
}
|
||||
|
||||
private hookResult setVault() {
|
||||
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
return hookResult.novault;
|
||||
|
||||
RegisteredServiceProvider<Economy> provider = plugin.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (provider == null) {
|
||||
return hookResult.noeconomy;
|
||||
}
|
||||
|
||||
Jobs.setEconomy(new VaultEconomy(provider.getProvider()));
|
||||
CMIMessages.consoleMessage("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault. (" + provider.getProvider().getName() + ")");
|
||||
return hookResult.pass;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Jobs Plugin for Bukkit
|
||||
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import com.gamingmesh.jobs.economy.VaultEconomy;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
public class HookEconomyTask extends HookVault<Economy> {
|
||||
|
||||
public HookEconomyTask(Class<Economy> providerClass) {
|
||||
super(providerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
void runIfProviderIsFound() {
|
||||
Jobs.setEconomy(new VaultEconomy(provider.getProvider()));
|
||||
}
|
||||
}
|
||||
|
15
src/main/java/com/gamingmesh/jobs/HookPermissionTask.java
Normal file
15
src/main/java/com/gamingmesh/jobs/HookPermissionTask.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class HookPermissionTask extends HookVault<Permission> {
|
||||
|
||||
public HookPermissionTask(Class<Permission> providerClass) {
|
||||
super(providerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
void runIfProviderIsFound() {
|
||||
Jobs.setVaultPermission(this.provider.getProvider());
|
||||
}
|
||||
}
|
60
src/main/java/com/gamingmesh/jobs/HookVault.java
Normal file
60
src/main/java/com/gamingmesh/jobs/HookVault.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public abstract class HookVault<T> {
|
||||
private static Boolean vaultEnable = null;
|
||||
protected Class<T> providerClass;
|
||||
protected RegisteredServiceProvider<T> provider;
|
||||
|
||||
protected HookVault(Class<T> providerClass) {
|
||||
this.providerClass = providerClass;
|
||||
if (!isVaultEnable())return;
|
||||
this.provider = Jobs.getInstance().getServer().getServicesManager().getRegistration(this.providerClass);
|
||||
if (this.provider != null) {
|
||||
logProviderConnected();
|
||||
runIfProviderIsFound();
|
||||
} else {
|
||||
logProviderNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVaultEnable() {
|
||||
if (vaultEnable == null) {
|
||||
setIsVaultEnable();
|
||||
if (!vaultEnable)
|
||||
logIfVaultIsNotEnable();
|
||||
}
|
||||
return vaultEnable;
|
||||
}
|
||||
|
||||
private static void setIsVaultEnable() {
|
||||
vaultEnable = Jobs.getInstance().getServer().getPluginManager().isPluginEnabled("Vault");
|
||||
}
|
||||
|
||||
public static void logIfVaultIsNotEnable() {
|
||||
if (vaultEnable)return;
|
||||
Jobs.getPluginLogger().severe("==================== " + Jobs.getInstance().getName() + " ====================");
|
||||
Jobs.getPluginLogger().severe("Vault is required by this plugin for economy support!");
|
||||
Jobs.getPluginLogger().severe("Please install them first!");
|
||||
Jobs.getPluginLogger().severe("You can find the latest versions here:");
|
||||
Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/34315/");
|
||||
Jobs.getPluginLogger().severe("==============================================");
|
||||
}
|
||||
|
||||
public void logProviderNotFound() {
|
||||
if (this.provider == null && isVaultEnable()) {
|
||||
Jobs.getPluginLogger().severe("==================== " + Jobs.getInstance().getDescription().getName() + " ====================");
|
||||
Jobs.getPluginLogger().severe("Vault detected but " + this.providerClass.getSimpleName() + " plugin still missing!");
|
||||
Jobs.getPluginLogger().severe("Please install Vault supporting " + this.providerClass.getSimpleName() + " plugin!");
|
||||
Jobs.getPluginLogger().severe("==============================================");
|
||||
}
|
||||
}
|
||||
|
||||
protected void logProviderConnected() {
|
||||
CMIMessages.consoleMessage("&e[" + Jobs.getInstance().getName() + "] Successfully linked with Vault. (" + provider.getPlugin().getName() + ")");
|
||||
}
|
||||
|
||||
abstract void runIfProviderIsFound();
|
||||
}
|
@ -18,28 +18,6 @@
|
||||
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.gamingmesh.jobs.Gui.GuiManager;
|
||||
import com.gamingmesh.jobs.Placeholders.Placeholder;
|
||||
import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook;
|
||||
@ -47,40 +25,8 @@ import com.gamingmesh.jobs.Signs.SignUtil;
|
||||
import com.gamingmesh.jobs.api.JobsExpGainEvent;
|
||||
import com.gamingmesh.jobs.api.JobsPrePaymentEvent;
|
||||
import com.gamingmesh.jobs.commands.JobsCommands;
|
||||
import com.gamingmesh.jobs.config.BlockProtectionManager;
|
||||
import com.gamingmesh.jobs.config.BossBarManager;
|
||||
import com.gamingmesh.jobs.config.ConfigManager;
|
||||
import com.gamingmesh.jobs.config.ExploreManager;
|
||||
import com.gamingmesh.jobs.config.GeneralConfigManager;
|
||||
import com.gamingmesh.jobs.config.LanguageManager;
|
||||
import com.gamingmesh.jobs.config.NameTranslatorManager;
|
||||
import com.gamingmesh.jobs.config.RestrictedAreaManager;
|
||||
import com.gamingmesh.jobs.config.RestrictedBlockManager;
|
||||
import com.gamingmesh.jobs.config.ScheduleManager;
|
||||
import com.gamingmesh.jobs.config.ShopManager;
|
||||
import com.gamingmesh.jobs.config.TitleManager;
|
||||
import com.gamingmesh.jobs.config.YmlMaker;
|
||||
import com.gamingmesh.jobs.container.ActionInfo;
|
||||
import com.gamingmesh.jobs.container.ActionType;
|
||||
import com.gamingmesh.jobs.container.ArchivedJobs;
|
||||
import com.gamingmesh.jobs.container.BlockProtection;
|
||||
import com.gamingmesh.jobs.container.Boost;
|
||||
import com.gamingmesh.jobs.container.Convert;
|
||||
import com.gamingmesh.jobs.container.CurrencyLimit;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.DBAction;
|
||||
import com.gamingmesh.jobs.container.FastPayment;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobInfo;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.container.JobsWorld;
|
||||
import com.gamingmesh.jobs.container.LoadStatus;
|
||||
import com.gamingmesh.jobs.container.Log;
|
||||
import com.gamingmesh.jobs.container.PlayerInfo;
|
||||
import com.gamingmesh.jobs.container.PlayerPoints;
|
||||
import com.gamingmesh.jobs.container.Quest;
|
||||
import com.gamingmesh.jobs.container.QuestProgression;
|
||||
import com.gamingmesh.jobs.config.*;
|
||||
import com.gamingmesh.jobs.container.*;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||
import com.gamingmesh.jobs.dao.JobsClassLoader;
|
||||
@ -93,32 +39,35 @@ import com.gamingmesh.jobs.economy.Economy;
|
||||
import com.gamingmesh.jobs.economy.PaymentData;
|
||||
import com.gamingmesh.jobs.hooks.HookManager;
|
||||
import com.gamingmesh.jobs.i18n.Language;
|
||||
import com.gamingmesh.jobs.listeners.JobsListener;
|
||||
import com.gamingmesh.jobs.listeners.JobsPayment1_14Listener;
|
||||
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
|
||||
import com.gamingmesh.jobs.listeners.PistonProtectionListener;
|
||||
import com.gamingmesh.jobs.listeners.JobsPayment1_16Listener;
|
||||
import com.gamingmesh.jobs.listeners.PlayerSignEdit1_20Listeners;
|
||||
import com.gamingmesh.jobs.listeners.*;
|
||||
import com.gamingmesh.jobs.selection.SelectionManager;
|
||||
import com.gamingmesh.jobs.stuff.Loging;
|
||||
import com.gamingmesh.jobs.stuff.TabComplete;
|
||||
import com.gamingmesh.jobs.stuff.ToggleBarHandling;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
import com.gamingmesh.jobs.stuff.VersionChecker;
|
||||
import com.gamingmesh.jobs.stuff.*;
|
||||
import com.gamingmesh.jobs.stuff.complement.Complement;
|
||||
import com.gamingmesh.jobs.stuff.complement.Complement1;
|
||||
import com.gamingmesh.jobs.stuff.complement.Complement2;
|
||||
import com.gamingmesh.jobs.stuff.complement.JobsChatEvent;
|
||||
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
|
||||
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
||||
|
||||
import net.Zrips.CMILib.ActionBar.CMIActionBar;
|
||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.RawMessages.RawMessage;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class Jobs extends JavaPlugin {
|
||||
|
||||
@ -142,6 +91,8 @@ public final class Jobs extends JavaPlugin {
|
||||
private static GeneralConfigManager gConfigManager;
|
||||
|
||||
private static BufferedEconomy economy;
|
||||
|
||||
private static Permission vaultPermission;
|
||||
private static PermissionHandler permissionHandler;
|
||||
private static PermissionManager permissionManager;
|
||||
|
||||
@ -691,6 +642,10 @@ public final class Jobs extends JavaPlugin {
|
||||
economy = new BufferedEconomy(getInstance(), eco);
|
||||
}
|
||||
|
||||
public static void setVaultPermission(Permission permission) {
|
||||
vaultPermission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the economy handler
|
||||
* @return the economy handler
|
||||
@ -699,6 +654,10 @@ public final class Jobs extends JavaPlugin {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public static Permission getVaultPermission() {
|
||||
return vaultPermission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version check manager
|
||||
* @return the version check manager
|
||||
@ -762,7 +721,10 @@ public final class Jobs extends JavaPlugin {
|
||||
}
|
||||
|
||||
// register economy
|
||||
CMIScheduler.get().runTask(new HookEconomyTask(this));
|
||||
CMIScheduler.get().runTask(() -> new HookEconomyTask(net.milkbowl.vault.economy.Economy.class));
|
||||
|
||||
// register permission from vault
|
||||
CMIScheduler.get().runTask(() -> new HookPermissionTask(Permission.class));
|
||||
|
||||
dao.loadBlockProtection();
|
||||
getExploreManager().load();
|
||||
|
Loading…
Reference in New Issue
Block a user