Skip to content

Commit

Permalink
Merge pull request #4 from jingwenMC/preview
Browse files Browse the repository at this point in the history
3.0.1
  • Loading branch information
jingwenMC authored Feb 13, 2024
2 parents a4b875f + 0c37510 commit 9d813df
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>top.jingwenmc</groupId>
<artifactId>SpigotPie</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<packaging>jar</packaging>

<name>SpigotPie</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package top.jingwenmc.spigotpie;

public class PieDistroConfigurations {
public static final String DISTRO_VERSION = "3.0.0";
public static final String DISTRO_VERSION = "3.0.1";

public static final int API_VERSION = 4;
}
43 changes: 19 additions & 24 deletions src/main/java/top/jingwenmc/spigotpie/common/SpigotPie.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Getter;
import top.jingwenmc.spigotpie.PieDistroConfigurations;
import top.jingwenmc.spigotpie.common.instance.SimpleInstanceManager;
import top.jingwenmc.spigotpie.common.lang.PieLang;

import java.util.logging.Level;

Expand All @@ -12,39 +13,33 @@ public class SpigotPie {

public static void loadPlugin(PieEnvironment environment) {
SpigotPie.environment = environment;
environment.getLogger().info("Starting Library Spigot Pie...");
environment.getLogger().info("正在加载Spigot Pie运行库...");
environment.getLogger().info("Pie language Setting: " + PieLang.LANGUAGE_NAME);
environment.getLogger().info("You can change this in " + environment.getWorkFolder() +"\\SpigotPie\\Lang.yml");
environment.getLogger().info(PieLang.LOADING);
char[] packageName = new char[]{'t','o','p','.','j','i','n','g','w','e','n','m','c','.','s','p','i','g','o','t','p','i','e','.','c','o','m','m','o','n'};
if(!environment.isAsDedicatePlugin() && SpigotPie.class.getName().startsWith(new String(packageName))) {
environment.getLogger().log(Level.SEVERE,"Failed to load Spigot Pie.");
environment.getLogger().log(Level.SEVERE,"Spigot Pie加载失败.");
environment.getLogger().log(Level.SEVERE,"可能的原因: 潜在的包名冲突");
environment.getLogger().log(Level.SEVERE,"Reason: Possible Package Conflict");
environment.getLogger().log(Level.SEVERE,PieLang.FAILED_TO_LOAD);
environment.getLogger().log(Level.SEVERE,"Reason: " + PieLang.PACKAGE_CONFLICT);
throw new IllegalStateException("Exception during PreLoad: Developer notice: ensure to use relocation while not using plugin mode!");
}

//start pie
environment.getLogger().info("Loading managed instances...");
environment.getLogger().info("正在加载受管理的实例...");
environment.getLogger().info(PieLang.LOADING_INSTANCE);
try {
SimpleInstanceManager.init();
environment.getLogger().info("Managed instances load complete!");
environment.getLogger().info("加载受管理的实例完成!");
environment.getLogger().info("========================================\n"+
" _____ _ __ ____ _ \n" +
" / ___/____ (_)___ _____ / /_ / __ \\(_)__ \n" +
" \\__ \\/ __ \\/ / __ `/ __ \\/ __/ / /_/ / / _ \\\n" +
" ___/ / /_/ / / /_/ / /_/ / /_ / ____/ / __/\n" +
"/____/ .___/_/\\__, /\\____/\\__/ /_/ /_/\\___/ \n" +
" /_/ /____/ Version:"+ PieDistroConfigurations.DISTRO_VERSION);
environment.getLogger().info("========================================");
environment.getLogger().info("Spigot Pie运行库加载完成!");
environment.getLogger().info("Library Spigot Pie Load Complete!");
environment.getLogger().info(PieLang.LOADING_INSTANCE_COMPLETE);
environment.getLogger().info(
" \n" +
" _____ _ _ _____ _ \n" +
" | __|___|_|___ ___| |_| _ |_|___ \n" +
" |__ | . | | . | . | _| __| | -_| \n" +
" |_____| _|_|_ |___|_| |__| |_|___| \n" +
" |_| |___| Version:" + PieDistroConfigurations.DISTRO_VERSION + "\n" +
" ");
environment.getLogger().info(PieLang.LOADING_COMPLETE);
} catch (Exception e) {
environment.getLogger().log(Level.SEVERE,"Failed to load Spigot Pie.");
environment.getLogger().log(Level.SEVERE,"Spigot Pie加载失败.");
environment.getLogger().log(Level.SEVERE,"Check 'Caused by:' to learn more");
environment.getLogger().log(Level.SEVERE,"查看'Caused by:'了解更多");
environment.getLogger().log(Level.SEVERE,PieLang.FAILED_TO_LOAD);
environment.getLogger().log(Level.SEVERE,PieLang.CHECK_CAUSE);
throw new RuntimeException("Exception during Load: Unknown Exception",e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down Expand Up @@ -82,6 +83,23 @@ private static List<String> getFilter() {
return filter;
}

private static Object processObject(Class<?> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
if(!SpigotPie.getEnvironment().isBungeeCord() && clazz.getSuperclass().equals(org.bukkit.plugin.java.JavaPlugin.class)) {
Class<? extends org.bukkit.plugin.java.JavaPlugin> clazz2 = (Class<? extends org.bukkit.plugin.java.JavaPlugin>) clazz;
return org.bukkit.plugin.java.JavaPlugin.getPlugin(clazz2);
}
if(SpigotPie.getEnvironment().isBungeeCord() && clazz.getSuperclass().equals(net.md_5.bungee.api.plugin.Plugin.class)) {
Class<? extends net.md_5.bungee.api.plugin.Plugin> clazz2 = (Class<? extends net.md_5.bungee.api.plugin.Plugin>) clazz;
for(net.md_5.bungee.api.plugin.Plugin p : net.md_5.bungee.api.ProxyServer.getInstance().getPluginManager().getPlugins()) {
if(p.getClass().equals(clazz2)) {
return p;
}
}
}
//创建管理实例
return clazz.getConstructor().newInstance();
}

/**
* Call on start
*/
Expand All @@ -98,29 +116,9 @@ public static void init() throws Exception {
if(pieComponent.name() != null && !pieComponent.name().isEmpty()) {
name = pieComponent.name().toLowerCase();
}
if(!SpigotPie.getEnvironment().isBungeeCord() && clazz.getSuperclass().equals(org.bukkit.plugin.java.JavaPlugin.class)) {
Class<? extends org.bukkit.plugin.java.JavaPlugin> clazz2 = (Class<? extends org.bukkit.plugin.java.JavaPlugin>) clazz;
ObjectManager.addObject(clazz,name,org.bukkit.plugin.java.JavaPlugin.getPlugin(clazz2));
preProcess.add(org.bukkit.plugin.java.JavaPlugin.getPlugin(clazz2));
continue;
}
if(SpigotPie.getEnvironment().isBungeeCord() && clazz.getSuperclass().equals(net.md_5.bungee.api.plugin.Plugin.class)) {
Class<? extends net.md_5.bungee.api.plugin.Plugin> clazz2 = (Class<? extends net.md_5.bungee.api.plugin.Plugin>) clazz;
for(net.md_5.bungee.api.plugin.Plugin p : net.md_5.bungee.api.ProxyServer.getInstance().getPluginManager().getPlugins()) {
if(p.getClass().equals(clazz2)) {
ObjectManager.addObject(clazz,name,p);
preProcess.add(p);
break;
}
}
continue;
}
//创建管理实例
Object o = clazz.getConstructor().newInstance();
if(!ObjectManager.contains(clazz)) {
ObjectManager.addObject(clazz,name,o);
preProcess.add(o);
}
Object o = processObject(clazz);
ObjectManager.addObject(clazz,name,o);
preProcess.add(o);
//因逻辑增多,统一延迟注入字段
for(Field f : o.getClass().getDeclaredFields()) {
if(f.isAnnotationPresent(Wire.class)) injectionMap.put(f,o);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/top/jingwenmc/spigotpie/common/lang/PieLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
@PieComponent
@ConfigurationFile("SpigotPie/lang.yml")
public class PieLang extends BaseConfiguration {

@Configuration("language_name")
public static String LANGUAGE_NAME = "zh_CN";

@Configuration("loading")
public static String LOADING = "正在加载 Spigot Pie 运行库...";
@Configuration("load_complete")
public static String LOADING_COMPLETE = "Spigot Pie 加载完毕";
@Configuration("failed_to_load")
public static String FAILED_TO_LOAD = "Spigot Pie 加载失败.";
@Configuration("package_conflict")
public static String PACKAGE_CONFLICT = "可能潜在的包名冲突";
@Configuration("loading_instance")
public static String LOADING_INSTANCE = "正在加载受管理的实例...";
@Configuration("loading_instance_complete")
public static String LOADING_INSTANCE_COMPLETE = "受管理的实例已加载完毕.";
@Configuration("check_cause")
public static String CHECK_CAUSE = "查看'Caused by:'了解更多";

@Configuration("too_few_args")
public static String TOO_FEW_ARGS = ChatColor.RED+"指令的参数不足!至少需要$1个参数!";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void sendMessage(String message) {
sender.sendMessage(message);
}
};

ArrayList<String> arrayList = new ArrayList<>(Collections.singletonList(commandName));
arrayList.addAll(Arrays.asList(args));
CommandTreeNode node = root.getCommandNode(root,arrayList.toArray(new String[0]));
Expand Down

0 comments on commit 9d813df

Please sign in to comment.