2020-10-27 18:14:34 +00:00
|
|
|
package me.totalfreedom.plex.util;
|
|
|
|
|
2020-10-28 03:49:56 +00:00
|
|
|
import java.sql.SQLException;
|
2020-10-28 20:47:00 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2020-10-27 18:14:34 +00:00
|
|
|
import me.totalfreedom.plex.Plex;
|
|
|
|
import me.totalfreedom.plex.storage.StorageType;
|
2020-10-28 20:47:00 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.PluginCommandYamlParser;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
2020-10-27 18:14:34 +00:00
|
|
|
|
|
|
|
public class PlexUtils
|
|
|
|
{
|
|
|
|
public static void testConnections()
|
|
|
|
{
|
|
|
|
if (Plex.get().getSqlConnection().getCon() != null)
|
|
|
|
{
|
|
|
|
if (Plex.get().getStorageType() == StorageType.SQL)
|
|
|
|
{
|
|
|
|
PlexLog.log("Successfully enabled MySQL!");
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
2020-10-27 18:14:34 +00:00
|
|
|
{
|
|
|
|
PlexLog.log("Successfully enabled SQLite!");
|
|
|
|
}
|
2020-10-28 03:49:56 +00:00
|
|
|
try
|
|
|
|
{
|
2020-10-27 18:14:34 +00:00
|
|
|
Plex.get().getSqlConnection().getCon().close();
|
|
|
|
}
|
2020-10-28 03:49:56 +00:00
|
|
|
catch (SQLException ignored)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Plex.get().getMongoConnection().getDatastore() != null)
|
2020-10-27 18:14:34 +00:00
|
|
|
{
|
|
|
|
PlexLog.log("Successfully enabled MongoDB!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 20:47:00 +00:00
|
|
|
public static boolean isPluginCMD(String cmd, String pluginName)
|
|
|
|
{
|
|
|
|
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName);
|
|
|
|
if (plugin == null)
|
|
|
|
{
|
|
|
|
PlexLog.error(pluginName + " can not be found on the server! Make sure it is spelt correctly!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
List<Command> cmds = PluginCommandYamlParser.parse(plugin);
|
|
|
|
for (Command pluginCmd : cmds)
|
|
|
|
{
|
|
|
|
List<String> cmdAliases = pluginCmd.getAliases().size() > 0 ? pluginCmd.getAliases().stream().map(String::toLowerCase).collect(Collectors.toList()) : null;
|
|
|
|
if (pluginCmd.getName().equalsIgnoreCase(cmd) || (cmdAliases != null && cmdAliases.contains(cmd.toLowerCase())))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:14:34 +00:00
|
|
|
}
|