mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 01:00:18 +01:00
#421 Create PluginHooks
- PluginHooks manages third-party plugins and allows to perform actions and queries on them, instead of public fields on the AuthMe main class
This commit is contained in:
parent
45fd241517
commit
8b27444a49
@ -1,9 +1,8 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
import fr.xephi.authme.cache.IpAddressManager;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.backup.JsonCache;
|
||||
@ -23,6 +22,7 @@ import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.hooks.BungeeCordMessage;
|
||||
import fr.xephi.authme.hooks.EssSpawn;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.listener.AuthMeBlockListener;
|
||||
import fr.xephi.authme.listener.AuthMeEntityListener;
|
||||
import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter;
|
||||
@ -33,7 +33,6 @@ import fr.xephi.authme.listener.AuthMeServerListener;
|
||||
import fr.xephi.authme.listener.AuthMeTabCompletePacketAdapter;
|
||||
import fr.xephi.authme.listener.AuthMeTablistPacketAdapter;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.cache.IpAddressManager;
|
||||
import fr.xephi.authme.output.ConsoleFilter;
|
||||
import fr.xephi.authme.output.Log4JFilter;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
@ -60,7 +59,6 @@ import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.MigrationService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -123,21 +121,19 @@ public class AuthMe extends JavaPlugin {
|
||||
* Plugin Hooks
|
||||
* TODO: Move into modules
|
||||
*/
|
||||
public Essentials ess;
|
||||
public MultiverseCore multiverse;
|
||||
public CombatTagPlus combatTagPlus;
|
||||
public AuthMeInventoryPacketAdapter inventoryProtector;
|
||||
public AuthMeTabCompletePacketAdapter tabComplete;
|
||||
public AuthMeTablistPacketAdapter tablistHider;
|
||||
private Management management;
|
||||
private CommandHandler commandHandler = null;
|
||||
private PermissionsManager permsMan = null;
|
||||
private CommandHandler commandHandler;
|
||||
private PermissionsManager permsMan;
|
||||
private NewSetting newSettings;
|
||||
private Messages messages;
|
||||
private JsonCache playerBackup;
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private DataSource database;
|
||||
private IpAddressManager ipAddressManager;
|
||||
private PluginHooks pluginHooks;
|
||||
|
||||
/**
|
||||
* Get the plugin's instance.
|
||||
@ -247,13 +243,16 @@ public class AuthMe extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
pluginHooks = new PluginHooks(server.getPluginManager());
|
||||
|
||||
MigrationService.changePlainTextToSha256(newSettings, database, new SHA256());
|
||||
passwordSecurity = new PasswordSecurity(getDataSource(), newSettings, Bukkit.getPluginManager());
|
||||
ipAddressManager = new IpAddressManager(newSettings);
|
||||
|
||||
// Set up the permissions manager and command handler
|
||||
permsMan = initializePermissionsManager();
|
||||
commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings, ipAddressManager);
|
||||
commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings, ipAddressManager,
|
||||
pluginHooks);
|
||||
|
||||
// Set up Metrics
|
||||
MetricsStarter.setupMetrics(plugin, newSettings);
|
||||
@ -271,14 +270,8 @@ public class AuthMe extends JavaPlugin {
|
||||
setupMailApi();
|
||||
|
||||
// Hooks
|
||||
// Check Combat Tag Plus Version
|
||||
checkCombatTagPlus();
|
||||
|
||||
// Check Multiverse
|
||||
checkMultiverse();
|
||||
|
||||
// Check Essentials
|
||||
checkEssentials();
|
||||
checkEssentialsSpawn();
|
||||
|
||||
// Check if the ProtocolLib is available. If so we could listen for
|
||||
// inventory protection
|
||||
@ -293,14 +286,14 @@ public class AuthMe extends JavaPlugin {
|
||||
playerBackup = new JsonCache();
|
||||
|
||||
// Set the DataManager
|
||||
dataManager = new DataManager(this);
|
||||
dataManager = new DataManager(this, pluginHooks);
|
||||
|
||||
// Set up the new API
|
||||
setupApi();
|
||||
|
||||
// Set up the management
|
||||
ProcessService processService = new ProcessService(newSettings, messages, this, ipAddressManager,
|
||||
passwordSecurity);
|
||||
passwordSecurity, pluginHooks);
|
||||
management = new Management(this, processService, database, PlayerCache.getInstance());
|
||||
|
||||
// Set up the BungeeCord hook
|
||||
@ -384,7 +377,7 @@ public class AuthMe extends JavaPlugin {
|
||||
pluginManager.registerEvents(new AuthMePlayerListener(this), this);
|
||||
pluginManager.registerEvents(new AuthMeBlockListener(), this);
|
||||
pluginManager.registerEvents(new AuthMeEntityListener(), this);
|
||||
pluginManager.registerEvents(new AuthMeServerListener(this), this);
|
||||
pluginManager.registerEvents(new AuthMeServerListener(this, messages, pluginHooks), this);
|
||||
|
||||
// Try to register 1.6 player listeners
|
||||
try {
|
||||
@ -432,12 +425,12 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
private CommandHandler initializeCommandHandler(PermissionsManager permissionsManager, Messages messages,
|
||||
PasswordSecurity passwordSecurity, NewSetting settings,
|
||||
IpAddressManager ipAddressManager) {
|
||||
IpAddressManager ipAddressManager, PluginHooks pluginHooks) {
|
||||
HelpProvider helpProvider = new HelpProvider(permissionsManager, settings.getProperty(HELP_HEADER));
|
||||
Set<CommandDescription> baseCommands = CommandInitializer.buildCommands();
|
||||
CommandMapper mapper = new CommandMapper(baseCommands, permissionsManager);
|
||||
CommandService commandService = new CommandService(
|
||||
this, mapper, helpProvider, messages, passwordSecurity, permissionsManager, settings, ipAddressManager);
|
||||
CommandService commandService = new CommandService(this, mapper, helpProvider, messages, passwordSecurity,
|
||||
permissionsManager, settings, ipAddressManager, pluginHooks);
|
||||
return new CommandHandler(commandService);
|
||||
}
|
||||
|
||||
@ -640,32 +633,8 @@ public class AuthMe extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
// Get the Multiverse plugin
|
||||
public void checkMultiverse() {
|
||||
if (Settings.multiverse && server.getPluginManager().isPluginEnabled("Multiverse-Core")) {
|
||||
try {
|
||||
multiverse = (MultiverseCore) server.getPluginManager().getPlugin("Multiverse-Core");
|
||||
ConsoleLogger.info("Hooked correctly with Multiverse-Core");
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
multiverse = null;
|
||||
}
|
||||
} else {
|
||||
multiverse = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the Essentials plugin
|
||||
public void checkEssentials() {
|
||||
if (server.getPluginManager().isPluginEnabled("Essentials")) {
|
||||
try {
|
||||
ess = (Essentials) server.getPluginManager().getPlugin("Essentials");
|
||||
ConsoleLogger.info("Hooked correctly with Essentials");
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
ess = null;
|
||||
}
|
||||
} else {
|
||||
ess = null;
|
||||
}
|
||||
public void checkEssentialsSpawn() {
|
||||
if (server.getPluginManager().isPluginEnabled("EssentialsSpawn")) {
|
||||
try {
|
||||
essentialsSpawn = new EssSpawn().getLocation();
|
||||
@ -679,20 +648,6 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// Check the presence of CombatTag
|
||||
public void checkCombatTagPlus() {
|
||||
if (server.getPluginManager().isPluginEnabled("CombatTagPlus")) {
|
||||
try {
|
||||
combatTagPlus = (CombatTagPlus) server.getPluginManager().getPlugin("CombatTagPlus");
|
||||
ConsoleLogger.info("Hooked correctly with CombatTagPlus");
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
combatTagPlus = null;
|
||||
}
|
||||
} else {
|
||||
combatTagPlus = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the presence of the ProtocolLib plugin
|
||||
public void checkProtocolLib() {
|
||||
if (!server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
@ -778,7 +733,7 @@ public class AuthMe extends JavaPlugin {
|
||||
return;
|
||||
}
|
||||
ConsoleLogger.info("AutoPurging the Database: " + cleared.size() + " accounts removed!");
|
||||
if (newSettings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && this.ess != null)
|
||||
if (newSettings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && pluginHooks.isEssentialsAvailable())
|
||||
dataManager.purgeEssentials(cleared);
|
||||
if (newSettings.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
||||
dataManager.purgeDat(cleared);
|
||||
@ -884,4 +839,8 @@ public class AuthMe extends JavaPlugin {
|
||||
return passwordSecurity;
|
||||
}
|
||||
|
||||
public PluginHooks getPluginHooks() {
|
||||
return pluginHooks;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
@ -7,27 +15,21 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class DataManager {
|
||||
|
||||
public final AuthMe plugin;
|
||||
private final AuthMe plugin;
|
||||
private final PluginHooks pluginHooks;
|
||||
|
||||
/**
|
||||
* Constructor for DataManager.
|
||||
*
|
||||
* @param plugin AuthMe
|
||||
*/
|
||||
public DataManager(AuthMe plugin) {
|
||||
public DataManager(AuthMe plugin, PluginHooks pluginHooks) {
|
||||
this.plugin = plugin;
|
||||
this.pluginHooks = pluginHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,7 +39,7 @@ public class DataManager {
|
||||
*
|
||||
* @return OfflinePlayer
|
||||
*/
|
||||
public synchronized OfflinePlayer getOfflinePlayer(final String name) {
|
||||
private synchronized OfflinePlayer getOfflinePlayer(final String name) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
|
||||
|
||||
@ -57,7 +59,7 @@ public class DataManager {
|
||||
try {
|
||||
return result.get();
|
||||
} catch (Exception e) {
|
||||
return (null);
|
||||
return null;
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
}
|
||||
@ -78,14 +80,13 @@ public class DataManager {
|
||||
String playerName = player.getName();
|
||||
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
|
||||
if (playerFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
|
||||
ConsoleLogger.info("AutoPurgeDatabase: Removed " + i + " AntiXRayData Files");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,26 +104,23 @@ public class DataManager {
|
||||
String playerName = player.getName();
|
||||
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
|
||||
if (playerFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
|
||||
if (playerFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
|
||||
if (playerFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
|
||||
ConsoleLogger.info("AutoPurgeDatabase: Removed " + i + " LimitedCreative Survival, Creative and Adventure files");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,13 +139,11 @@ public class DataManager {
|
||||
|
||||
try {
|
||||
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
} catch (Exception ignore) {
|
||||
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat");
|
||||
if (playerFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
@ -155,7 +151,7 @@ public class DataManager {
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
|
||||
ConsoleLogger.info("AutoPurgeDatabase: Removed " + i + " .dat Files");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,25 +159,24 @@ public class DataManager {
|
||||
*
|
||||
* @param cleared List of String
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void purgeEssentials(List<String> cleared) {
|
||||
int i = 0;
|
||||
// FIXME: essentials data folder may be null
|
||||
final File userDataFolder = new File(pluginHooks.getEssentialsDataFolder(), "userdata");
|
||||
for (String name : cleared) {
|
||||
try {
|
||||
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
File playerFile = new File(userDataFolder, plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml");
|
||||
playerFile.delete();
|
||||
i++;
|
||||
} catch (Exception e) {
|
||||
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
||||
File playerFile = new File(userDataFolder, name + ".yml");
|
||||
if (playerFile.exists()) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
playerFile.delete();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
|
||||
ConsoleLogger.info("AutoPurgeDatabase: Removed " + i + " EssentialsFiles");
|
||||
}
|
||||
|
||||
// TODO: What is this method for? Is it correct?
|
||||
@ -192,9 +187,10 @@ public class DataManager {
|
||||
public synchronized void purgePermissions(List<String> cleared) {
|
||||
// Get the permissions manager, and make sure it's valid
|
||||
PermissionsManager permsMan = this.plugin.getPermissionsManager();
|
||||
if (permsMan == null)
|
||||
if (permsMan == null) {
|
||||
ConsoleLogger.showError("Unable to access permissions manager instance!");
|
||||
assert permsMan != null;
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (String name : cleared) {
|
||||
@ -204,7 +200,7 @@ public class DataManager {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Removed " + i + "permissions");
|
||||
ConsoleLogger.info("AutoPurgeDatabase: Removed " + i + "permissions");
|
||||
|
||||
/*int i = 0;
|
||||
for (String name : cleared) {
|
||||
@ -220,38 +216,6 @@ public class DataManager {
|
||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Method isOnline.
|
||||
*
|
||||
* @param player Player
|
||||
* @param name String
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isOnline(Player player, final String name) {
|
||||
if (player.isOnline())
|
||||
return true;
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
@Override
|
||||
public synchronized Boolean call() throws Exception {
|
||||
for (OfflinePlayer op : Utils.getOnlinePlayers())
|
||||
if (op.getName().equalsIgnoreCase(name)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getOnlinePlayerLower.
|
||||
*
|
||||
@ -259,12 +223,13 @@ public class DataManager {
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getOnlinePlayerLower(String name) {
|
||||
private Player getOnlinePlayerLower(String name) {
|
||||
name = name.toLowerCase();
|
||||
for (Player player : Utils.getOnlinePlayers()) {
|
||||
if (player.getName().equalsIgnoreCase(name))
|
||||
if (player.getName().equalsIgnoreCase(name)) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.cache.IpAddressManager;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
@ -30,6 +31,7 @@ public class CommandService {
|
||||
private final PermissionsManager permissionsManager;
|
||||
private final NewSetting settings;
|
||||
private final IpAddressManager ipAddressManager;
|
||||
private final PluginHooks pluginHooks;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -45,7 +47,7 @@ public class CommandService {
|
||||
*/
|
||||
public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
|
||||
PasswordSecurity passwordSecurity, PermissionsManager permissionsManager, NewSetting settings,
|
||||
IpAddressManager ipAddressManager) {
|
||||
IpAddressManager ipAddressManager, PluginHooks pluginHooks) {
|
||||
this.authMe = authMe;
|
||||
this.messages = messages;
|
||||
this.helpProvider = helpProvider;
|
||||
@ -54,6 +56,7 @@ public class CommandService {
|
||||
this.permissionsManager = permissionsManager;
|
||||
this.settings = settings;
|
||||
this.ipAddressManager = ipAddressManager;
|
||||
this.pluginHooks = pluginHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,4 +198,8 @@ public class CommandService {
|
||||
return PlayerCache.getInstance();
|
||||
}
|
||||
|
||||
public PluginHooks getPluginHooks() {
|
||||
return pluginHooks;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
|
||||
// Purge the banned players
|
||||
plugin.getDataSource().purgeBanned(bannedPlayers);
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && plugin.ess != null)
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES)
|
||||
&& commandService.getPluginHooks().isEssentialsAvailable())
|
||||
plugin.dataManager.purgeEssentials(bannedPlayers);
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
||||
plugin.dataManager.purgeDat(bannedPlayers);
|
||||
|
@ -47,7 +47,8 @@ public class PurgeCommand implements ExecutableCommand {
|
||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||
|
||||
// Purge other data
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && plugin.ess != null)
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) &&
|
||||
commandService.getPluginHooks().isEssentialsAvailable())
|
||||
plugin.dataManager.purgeEssentials(purged);
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
||||
plugin.dataManager.purgeDat(purged);
|
||||
|
158
src/main/java/fr/xephi/authme/hooks/PluginHooks.java
Normal file
158
src/main/java/fr/xephi/authme/hooks/PluginHooks.java
Normal file
@ -0,0 +1,158 @@
|
||||
package fr.xephi.authme.hooks;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Hooks into third-party plugins and allows to perform actions on them.
|
||||
*/
|
||||
public class PluginHooks {
|
||||
|
||||
private final PluginManager pluginManager;
|
||||
private Essentials essentials;
|
||||
private MultiverseCore multiverse;
|
||||
private CombatTagPlus combatTagPlus;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pluginManager The server's plugin manager
|
||||
*/
|
||||
public PluginHooks(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
tryHookToCombatPlus();
|
||||
tryHookToEssentials();
|
||||
tryHookToMultiverse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the social spy status of the given user if Essentials is available.
|
||||
*
|
||||
* @param player The player to modify
|
||||
* @param socialSpyStatus The social spy status (enabled/disabled) to set
|
||||
*/
|
||||
public void setEssentialsSocialSpyStatus(Player player, boolean socialSpyStatus) {
|
||||
if (essentials != null) {
|
||||
essentials.getUser(player).setSocialSpyEnabled(socialSpyStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If Essentials is hooked into, return Essentials' data folder.
|
||||
*
|
||||
* @return The Essentials data folder, or null if unavailable
|
||||
*/
|
||||
public File getEssentialsDataFolder() {
|
||||
if (essentials != null) {
|
||||
return essentials.getDataFolder();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the spawn of the given world as defined by Multiverse (if available).
|
||||
*
|
||||
* @param world The world to get the Multiverse spawn for
|
||||
* @return The spawn location from Multiverse, or null if unavailable
|
||||
*/
|
||||
public Location getMultiverseSpawn(World world) {
|
||||
if (multiverse != null) {
|
||||
MVWorldManager manager = multiverse.getMVWorldManager();
|
||||
if (manager.isMVWorld(world)) {
|
||||
return manager.getMVWorld(world).getSpawnLocation();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the CombatTagPlus plugin whether the given player is an NPC.
|
||||
*
|
||||
* @param player The player to verify
|
||||
* @return True if the player is an NPC according to CombatTagPlus, false if not or if the plugin is unavailable
|
||||
*/
|
||||
public boolean isNpcInCombatTagPlus(Player player) {
|
||||
return combatTagPlus != null && combatTagPlus.getNpcPlayerHelper().isNpc(player);
|
||||
}
|
||||
|
||||
|
||||
// ------
|
||||
// "Is plugin available" methods
|
||||
// ------
|
||||
public boolean isEssentialsAvailable() {
|
||||
return essentials != null;
|
||||
}
|
||||
|
||||
public boolean isMultiverseAvailable() {
|
||||
return multiverse != null;
|
||||
}
|
||||
|
||||
public boolean isCombatTagPlusAvailable() {
|
||||
return combatTagPlus != null;
|
||||
}
|
||||
|
||||
// ------
|
||||
// Hook methods
|
||||
// ------
|
||||
public void tryHookToEssentials() {
|
||||
try {
|
||||
essentials = getPlugin(pluginManager, "Essentials", Essentials.class);
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
essentials = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void tryHookToCombatPlus() {
|
||||
try {
|
||||
combatTagPlus = getPlugin(pluginManager, "CombatTagPlus", CombatTagPlus.class);
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
combatTagPlus = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void tryHookToMultiverse() {
|
||||
try {
|
||||
multiverse = getPlugin(pluginManager, "Multiverse-Core", MultiverseCore.class);
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
multiverse = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ------
|
||||
// Unhook methods
|
||||
// ------
|
||||
public void unhookEssentials() {
|
||||
essentials = null;
|
||||
}
|
||||
public void unhookCombatPlus() {
|
||||
combatTagPlus = null;
|
||||
}
|
||||
public void unhookMultiverse() {
|
||||
multiverse = null;
|
||||
}
|
||||
|
||||
// ------
|
||||
// Helpers
|
||||
// ------
|
||||
private static <T extends Plugin> T getPlugin(PluginManager pluginManager, String name, Class<T> clazz)
|
||||
throws Exception, NoClassDefFoundError {
|
||||
if (pluginManager.isPluginEnabled(name)) {
|
||||
T plugin = clazz.cast(pluginManager.getPlugin(name));
|
||||
ConsoleLogger.info("Hooked successfully into " + name);
|
||||
return plugin;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@ -12,18 +13,19 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AuthMeServerListener implements Listener {
|
||||
|
||||
private final AuthMe plugin;
|
||||
private final Messages m;
|
||||
private final Messages messages;
|
||||
private final PluginHooks pluginHooks;
|
||||
|
||||
public AuthMeServerListener(AuthMe plugin) {
|
||||
this.m = plugin.getMessages();
|
||||
public AuthMeServerListener(AuthMe plugin, Messages messages, PluginHooks pluginHooks) {
|
||||
this.plugin = plugin;
|
||||
this.messages = messages;
|
||||
this.pluginHooks = pluginHooks;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@ -31,11 +33,11 @@ public class AuthMeServerListener implements Listener {
|
||||
if (!Settings.countriesBlacklist.isEmpty() || !Settings.countries.isEmpty()){
|
||||
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if( Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
event.setMotd(messages.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
if (Settings.enableProtection && !Settings.countries.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
event.setMotd(messages.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,35 +49,21 @@ public class AuthMeServerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the plugin instance
|
||||
Plugin pluginInstance = event.getPlugin();
|
||||
|
||||
// Make sure it's not this plugin itself
|
||||
if (pluginInstance.equals(this.plugin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String pluginName = pluginInstance.getName();
|
||||
if (pluginName.equalsIgnoreCase("Essentials")) {
|
||||
plugin.ess = null;
|
||||
ConsoleLogger.info("Essentials has been disabled, unhook!");
|
||||
return;
|
||||
}
|
||||
if (pluginName.equalsIgnoreCase("EssentialsSpawn")) {
|
||||
final String pluginName = event.getPlugin().getName();
|
||||
if ("Essentials".equalsIgnoreCase(pluginName)) {
|
||||
pluginHooks.unhookEssentials();
|
||||
ConsoleLogger.info("Essentials has been disabled: unhooking");
|
||||
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
|
||||
pluginHooks.unhookMultiverse();
|
||||
ConsoleLogger.info("Multiverse-Core has been disabled: unhooking");
|
||||
} else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) {
|
||||
pluginHooks.unhookCombatPlus();
|
||||
ConsoleLogger.info("CombatTagPlus has been disabled: unhooking");
|
||||
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
|
||||
plugin.essentialsSpawn = null;
|
||||
ConsoleLogger.info("EssentialsSpawn has been disabled, unhook!");
|
||||
return;
|
||||
}
|
||||
if (pluginName.equalsIgnoreCase("Multiverse-Core")) {
|
||||
plugin.multiverse = null;
|
||||
ConsoleLogger.info("Multiverse-Core has been disabled, unhook!");
|
||||
return;
|
||||
}
|
||||
if (pluginName.equalsIgnoreCase("CombatTagPlus")) {
|
||||
plugin.combatTagPlus = null;
|
||||
ConsoleLogger.info("CombatTagPlus has been disabled, unhook!");
|
||||
return;
|
||||
ConsoleLogger.info("EssentialsSpawn has been disabled: unhooking");
|
||||
}
|
||||
|
||||
if (pluginName.equalsIgnoreCase("ProtocolLib")) {
|
||||
plugin.inventoryProtector = null;
|
||||
plugin.tablistHider = null;
|
||||
@ -86,19 +74,22 @@ public class AuthMeServerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
String pluginName = event.getPlugin().getName();
|
||||
if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) {
|
||||
plugin.checkEssentials();
|
||||
// Make sure the plugin instance isn't null
|
||||
if (event.getPlugin() == null) {
|
||||
return;
|
||||
}
|
||||
if (pluginName.equalsIgnoreCase("Multiverse-Core")) {
|
||||
plugin.checkMultiverse();
|
||||
return;
|
||||
}
|
||||
if (pluginName.equalsIgnoreCase("CombatTagPlus")) {
|
||||
plugin.checkCombatTagPlus();
|
||||
return;
|
||||
|
||||
final String pluginName = event.getPlugin().getName();
|
||||
if ("Essentials".equalsIgnoreCase(pluginName)) {
|
||||
pluginHooks.tryHookToEssentials();
|
||||
} else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) {
|
||||
pluginHooks.tryHookToMultiverse();
|
||||
} else if ("CombatTagPlus".equalsIgnoreCase(pluginName)) {
|
||||
pluginHooks.tryHookToCombatPlus();
|
||||
} else if ("EssentialsSpawn".equalsIgnoreCase(pluginName)) {
|
||||
plugin.checkEssentialsSpawn();
|
||||
}
|
||||
|
||||
if (pluginName.equalsIgnoreCase("ProtocolLib")) {
|
||||
plugin.checkProtocolLib();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.IpAddressManager;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
@ -22,14 +23,16 @@ public class ProcessService {
|
||||
private final AuthMe authMe;
|
||||
private final IpAddressManager ipAddressManager;
|
||||
private final PasswordSecurity passwordSecurity;
|
||||
private final PluginHooks pluginHooks;
|
||||
|
||||
public ProcessService(NewSetting settings, Messages messages, AuthMe authMe, IpAddressManager ipAddressManager,
|
||||
PasswordSecurity passwordSecurity) {
|
||||
PasswordSecurity passwordSecurity, PluginHooks pluginHooks) {
|
||||
this.settings = settings;
|
||||
this.messages = messages;
|
||||
this.authMe = authMe;
|
||||
this.ipAddressManager = ipAddressManager;
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
this.pluginHooks = pluginHooks;
|
||||
}
|
||||
|
||||
public <T> T getProperty(Property<T> property) {
|
||||
@ -84,4 +87,8 @@ public class ProcessService {
|
||||
return passwordSecurity.computeHash(password, username);
|
||||
}
|
||||
|
||||
public PluginHooks getPluginHooks() {
|
||||
return pluginHooks;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,8 +59,8 @@ public class AsynchronousJoin implements Process {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.ess != null && service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) {
|
||||
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
||||
if (service.getProperty(HooksSettings.DISABLE_SOCIAL_SPY)) {
|
||||
service.getPluginHooks().setEssentialsSocialSpyStatus(player, false);
|
||||
}
|
||||
|
||||
final String ip = service.getIpAddressManager().getPlayerIp(player);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
@ -117,11 +116,8 @@ public class Spawn extends CustomConfiguration {
|
||||
}
|
||||
break;
|
||||
case "multiverse":
|
||||
if (Settings.multiverse && plugin.multiverse != null) {
|
||||
MVWorldManager manager = plugin.multiverse.getMVWorldManager();
|
||||
if (manager.isMVWorld(world)) {
|
||||
spawnLoc = manager.getMVWorld(world).getSpawnLocation();
|
||||
}
|
||||
if (Settings.multiverse) {
|
||||
spawnLoc = plugin.getPluginHooks().getMultiverseSpawn(world);
|
||||
}
|
||||
break;
|
||||
case "essentials":
|
||||
|
@ -240,8 +240,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static boolean isNPC(Player player) {
|
||||
return player.hasMetadata("NPC") || plugin.combatTagPlus != null
|
||||
&& plugin.combatTagPlus.getNpcPlayerHelper().isNpc(player);
|
||||
return player.hasMetadata("NPC") || plugin.getPluginHooks().isNpcInCombatTagPlus(player);
|
||||
}
|
||||
|
||||
public static void teleportToSpawn(Player player) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.IpAddressManager;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.cache.IpAddressManager;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
@ -42,6 +43,7 @@ public class CommandServiceTest {
|
||||
private PermissionsManager permissionsManager;
|
||||
private NewSetting settings;
|
||||
private IpAddressManager ipAddressManager;
|
||||
private PluginHooks pluginHooks;
|
||||
|
||||
@Before
|
||||
public void setUpService() {
|
||||
@ -53,8 +55,9 @@ public class CommandServiceTest {
|
||||
permissionsManager = mock(PermissionsManager.class);
|
||||
settings = mock(NewSetting.class);
|
||||
ipAddressManager = mock(IpAddressManager.class);
|
||||
pluginHooks = mock(PluginHooks.class);
|
||||
commandService = new CommandService(authMe, commandMapper, helpProvider, messages, passwordSecurity,
|
||||
permissionsManager, settings, ipAddressManager);
|
||||
permissionsManager, settings, ipAddressManager, pluginHooks);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user