Skip to content

Commit

Permalink
Merge pull request #106 from UltiKits/alpha
Browse files Browse the repository at this point in the history
2024/07/03 更新 版本6.1.1
  • Loading branch information
wisdommen authored Jul 2, 2024
2 parents 1b42cd5 + 577a792 commit 93f2756
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>UltiTools-API</artifactId>
<groupId>com.ultikits</groupId>
<version>6.1.0</version>
<version>6.1.1</version>
<modelVersion>4.0.0</modelVersion>
<name>UltiTools-API</name>
<description>This project is the base of the Ultitools plugin development.</description>
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/ultikits/ultitools/UltiTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import com.ultikits.ultitools.interfaces.VersionWrapper;
import com.ultikits.ultitools.interfaces.impl.data.mysql.MysqlDataStore;
import com.ultikits.ultitools.interfaces.impl.data.sqlite.SQLiteDataStore;
import com.ultikits.ultitools.interfaces.impl.logger.BukkitLogFactory;
import com.ultikits.ultitools.listeners.PlayerJoinListener;
import com.ultikits.ultitools.manager.*;
import com.ultikits.ultitools.utils.HttpDownloadUtils;
import com.ultikits.ultitools.utils.Metrics;
import com.ultikits.ultitools.utils.PluginInitiationUtils;

import cn.hutool.log.LogFactory;
import lombok.Getter;
import lombok.Setter;
import net.milkbowl.vault.economy.Economy;
Expand Down Expand Up @@ -73,6 +71,8 @@ public final class UltiTools extends JavaPlugin implements Localized {
@Getter
@Setter
private DataStore dataStore;
@Getter
private URLClassLoader ultiToolsClassLoader;

/**
* Returns the instance of the UltiTools.
Expand Down Expand Up @@ -119,7 +119,6 @@ public static YamlConfiguration getEnv() {

@Override
public void onLoad() {
LogFactory.setCurrentLogFactory(new BukkitLogFactory());
saveDefaultConfig();
ultiTools = this;
// Plugin classloader initialization
Expand All @@ -139,10 +138,10 @@ public void onLoad() {
@Override
public void onEnable() {
// Load all lib
URLClassLoader urlClassLoader = new URLClassLoader(getLibs(), getClassLoader());
ultiToolsClassLoader = new URLClassLoader(getLibs(), getClassLoader());
// External bukkit libraries initialization
try {
dependenceManagers = new DependenceManagers(this, urlClassLoader);
dependenceManagers = new DependenceManagers(this, ultiToolsClassLoader);
} catch (Exception | NoClassDefFoundError error) {
needLoadLib = true;
}
Expand Down Expand Up @@ -193,7 +192,7 @@ public void onEnable() {
file.mkdirs();
}
try {
pluginManager.init(urlClassLoader);
pluginManager.init(ultiToolsClassLoader);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private Object[] buildParams(String[] strings, Method method, CommandSender comm
String[] value = params.get(cmdParam.value());
try {
paramList.add(parseType(value, paramType));
} catch (Exception e) {
} catch (Exception | Error e) {
commandSender.sendMessage(ChatColor.RED + e.getMessage());
//noinspection CallToPrintStackTrace
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ public abstract class UltiToolsPlugin implements IPlugin, Localized, Configurabl
* <p>
* UltiToolsPlugin的构造函数。仅用于模块开发。
*/
@SneakyThrows
protected UltiToolsPlugin() {
InputStream inputStream = getInputStream();
InputStream inputStream = null;
try {
inputStream = getInputStream();
}catch (IOException e){
getLogger().error(e);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
YamlConfiguration pluginConfig = YamlConfiguration.loadConfiguration(reader);
version = pluginConfig.getString("version");
Expand All @@ -79,8 +83,12 @@ protected UltiToolsPlugin() {
loadAfter = pluginConfig.getStringList("loadAfter");
minUltiToolsVersion = pluginConfig.getInt("api-version");
mainClass = pluginConfig.getString("main");
inputStream.close();
reader.close();
try{
inputStream.close();
reader.close();
} catch (IOException e) {
getLogger().error(e);
}

resourceFolderPath = UltiTools.getInstance().getDataFolder().getAbsolutePath() + File.separator + "pluginConfig" + File.separator + this.getPluginName();
File file = new File(resourceFolderPath + File.separator + "lang" + File.separator + this.getLanguageCode() + ".json");
Expand All @@ -98,7 +106,11 @@ protected UltiToolsPlugin() {
language = new Language(file);
}
saveResources();
initConfig();
try{
initConfig();
} catch (IOException e) {
getLogger().error(e);
}
}

/**
Expand Down Expand Up @@ -229,7 +241,7 @@ private void initConfig() throws IOException {
if (annotation != null && annotation.config()) {
for (String packageName : DependencyUtils.getPluginPackages(this)) {
UltiTools.getInstance().getConfigManager().registerAll(
this, packageName, this.getClass().getClassLoader()
this, packageName, UltiTools.getInstance().getUltiToolsClassLoader()
);
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void registerAll(UltiToolsPlugin plugin, String packageName) {
Set<Class<?>> classes = PackageScanUtils.scanAnnotatedClasses(
CmdExecutor.class,
packageName,
UltiTools.getInstance().getClass().getClassLoader()
UltiTools.getInstance().getUltiToolsClassLoader()
);
for (Class<?> clazz : classes) {
try {
Expand Down Expand Up @@ -233,7 +233,7 @@ private PluginCommand getCommand(String name, Plugin plugin) {
c.setAccessible(true);

command = c.newInstance(name, plugin);
} catch (Exception e) {
} catch (Exception | Error e) {
e.printStackTrace();
}

Expand All @@ -250,7 +250,7 @@ private CommandMap getCommandMap() {

commandMap = (CommandMap) f.get(Bukkit.getPluginManager());
}
} catch (Exception e) {
} catch (Exception | Error e) {
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.ultikits.ultitools.manager;

import cn.hutool.core.comparator.VersionComparator;
import cn.hutool.log.LogFactory;

import com.ultikits.ultitools.UltiTools;
import com.ultikits.ultitools.context.ContextConfig;
import com.ultikits.ultitools.interfaces.impl.logger.BukkitLogFactory;

import lombok.Getter;
import mc.obliviate.inventory.InventoryAPI;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
Expand All @@ -23,6 +27,7 @@ public class DependenceManagers {

public DependenceManagers(UltiTools plugin, ClassLoader classLoader) {
this.classLoader = classLoader;
LogFactory.setCurrentLogFactory(new BukkitLogFactory());
initAdventure(plugin);
initSpringContext();
initInventoryAPI(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public boolean register(Class<? extends UltiToolsPlugin> pluginClass) {
UltiToolsPlugin plugin;
try {
plugin = initializePlugin(classLoader, pluginClass);
} catch (Exception e) {
} catch (Exception | Error e) {
Bukkit.getLogger().log(
Level.WARNING,
String.format("[UltiTools-API] Cannot initialize plugin for %s", pluginClass.getName())
Expand Down Expand Up @@ -130,7 +130,7 @@ public boolean register(
plugin = initializePlugin(
classLoader, pluginClass, pluginName, version, authors, loadAfter, minUltiToolsVersion, mainClass
);
} catch (Exception e) {
} catch (Exception | Error e) {
Bukkit.getLogger().log(
Level.WARNING,
String.format("[UltiTools-API] Cannot initialize plugin for %s", pluginClass.getName())
Expand Down Expand Up @@ -164,7 +164,7 @@ public boolean register(UltiToolsPlugin plugin) {
pluginContext.refresh();
pluginContext.getAutowireCapableBeanFactory().autowireBean(plugin);
}
} catch (Exception e) {
} catch (Exception | Error e) {
Bukkit.getLogger().log(
Level.WARNING,
String.format("[UltiTools-API] Cannot initialize plugin for %s", plugin.getPluginName())
Expand Down Expand Up @@ -301,7 +301,7 @@ private boolean invokeRegisterSelf(UltiToolsPlugin plugin) {
);
}
return registerSelf;
} catch (Exception e) {
} catch (Exception | Error e) {
Bukkit.getLogger().log(Level.WARNING, e, String::new);
Bukkit.getLogger().log(Level.WARNING, String.format("[UltiTools-API] %s load failed!", plugin.getPluginName()));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Set<Class<?>> scanAnnotatedClasses(
classes.add(c);
}
}
} catch (Exception e) {
} catch (Exception | Error e) {
Bukkit.getLogger().log(Level.SEVERE, "Failed to scan annotated classes", e);
}
return classes;
Expand Down

0 comments on commit 93f2756

Please sign in to comment.