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