船新两个 Sendable Json 和 ActionBar
This commit is contained in:
		@@ -17,7 +17,6 @@ public abstract class ActionBar {
 | 
				
			|||||||
            instance = (ActionBar) AsmClassTransformer.builder().from(Impl_1_8.class).fromVersion("v1_8_R3")
 | 
					            instance = (ActionBar) AsmClassTransformer.builder().from(Impl_1_8.class).fromVersion("v1_8_R3")
 | 
				
			||||||
                    .toVersion(Bukkit.getServer().getClass().getName().split("\\.")[3]).build().transform();
 | 
					                    .toVersion(Bukkit.getServer().getClass().getName().split("\\.")[3]).build().transform();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        System.out.println(instance.getClass());
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void sendActionBar(Player player, String text) {
 | 
					    public static void sendActionBar(Player player, String text) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,9 +37,10 @@ class TLocaleInstance {
 | 
				
			|||||||
                    Bukkit.getScheduler().runTask(plugin, () -> sendable.sendTo(sender, args));
 | 
					                    Bukkit.getScheduler().runTask(plugin, () -> sendable.sendTo(sender, args));
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        } catch (Exception e) {
 | 
					        } catch (Exception | Error e) {
 | 
				
			||||||
            TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("SEND-LOCALE-ERROR"), path));
 | 
					            TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("SEND-LOCALE-ERROR"), path));
 | 
				
			||||||
            TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("LOCALE-ERROR-REASON"), e.getMessage()));
 | 
					            TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("LOCALE-ERROR-REASON"), e.toString()));
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
package com.ilummc.tlib.resources;
 | 
					package com.ilummc.tlib.resources;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.ilummc.tlib.TLib;
 | 
					import com.ilummc.tlib.TLib;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.resources.type.TLocaleActionBar;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.resources.type.TLocaleJson;
 | 
				
			||||||
import com.ilummc.tlib.resources.type.TLocaleText;
 | 
					import com.ilummc.tlib.resources.type.TLocaleText;
 | 
				
			||||||
import com.ilummc.tlib.resources.type.TLocaleTitle;
 | 
					import com.ilummc.tlib.resources.type.TLocaleTitle;
 | 
				
			||||||
import com.ilummc.tlib.util.Strings;
 | 
					import com.ilummc.tlib.util.Strings;
 | 
				
			||||||
@@ -39,6 +41,8 @@ public class TLocaleLoader {
 | 
				
			|||||||
    public static void init() {
 | 
					    public static void init() {
 | 
				
			||||||
        ConfigurationSerialization.registerClass(TLocaleText.class, "TEXT");
 | 
					        ConfigurationSerialization.registerClass(TLocaleText.class, "TEXT");
 | 
				
			||||||
        ConfigurationSerialization.registerClass(TLocaleTitle.class, "TITLE");
 | 
					        ConfigurationSerialization.registerClass(TLocaleTitle.class, "TITLE");
 | 
				
			||||||
 | 
					        ConfigurationSerialization.registerClass(TLocaleJson.class, "JSON");
 | 
				
			||||||
 | 
					        ConfigurationSerialization.registerClass(TLocaleActionBar.class, "ACTION");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void load(Plugin plugin, boolean ignoreLoaded) {
 | 
					    public static void load(Plugin plugin, boolean ignoreLoaded) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,61 @@
 | 
				
			|||||||
 | 
					package com.ilummc.tlib.resources.type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.Maps;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.compat.PlaceholderHook;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.nms.ActionBar;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.resources.TLocaleSendable;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.util.Strings;
 | 
				
			||||||
 | 
					import me.skymc.taboolib.Main;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					import org.bukkit.configuration.serialization.ConfigurationSerializable;
 | 
				
			||||||
 | 
					import org.bukkit.configuration.serialization.SerializableAs;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.concurrent.Immutable;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Immutable
 | 
				
			||||||
 | 
					@SerializableAs("ACTION")
 | 
				
			||||||
 | 
					public class TLocaleActionBar implements TLocaleSendable, ConfigurationSerializable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final String text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final boolean papi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public TLocaleActionBar(String text, boolean papi) {
 | 
				
			||||||
 | 
					        this.text = text;
 | 
				
			||||||
 | 
					        this.papi = papi;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static TLocaleActionBar valueOf(Map<String, Object> map) {
 | 
				
			||||||
 | 
					        String text = String.valueOf(map.getOrDefault("text", "Empty Action bar message."));
 | 
				
			||||||
 | 
					        boolean papi = (boolean) map.getOrDefault("papi", Main.getInst().getConfig().getBoolean("LOCALE.USE_PAPI", false));
 | 
				
			||||||
 | 
					        return new TLocaleActionBar(text, papi);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void sendTo(CommandSender sender, String... args) {
 | 
				
			||||||
 | 
					        if (sender instanceof Player)
 | 
				
			||||||
 | 
					            ActionBar.sendActionBar(((Player) sender), replace(sender, text, args));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String replace(CommandSender sender, String text, String[] args) {
 | 
				
			||||||
 | 
					        String s = Strings.replaceWithOrder(text, args);
 | 
				
			||||||
 | 
					        return papi ? PlaceholderHook.replace(sender, s) : s;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String asString(String... args) {
 | 
				
			||||||
 | 
					        return "ActionBar: [" + text + "]";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Map<String, Object> serialize() {
 | 
				
			||||||
 | 
					        Map<String, Object> map = Maps.newHashMap();
 | 
				
			||||||
 | 
					        map.put("text", text);
 | 
				
			||||||
 | 
					        if (papi)
 | 
				
			||||||
 | 
					            map.put("papi", true);
 | 
				
			||||||
 | 
					        return map;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										153
									
								
								src/main/java/com/ilummc/tlib/resources/type/TLocaleJson.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								src/main/java/com/ilummc/tlib/resources/type/TLocaleJson.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,153 @@
 | 
				
			|||||||
 | 
					package com.ilummc.tlib.resources.type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.ImmutableList;
 | 
				
			||||||
 | 
					import com.google.common.collect.Lists;
 | 
				
			||||||
 | 
					import com.google.common.collect.Maps;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.TLib;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.compat.PlaceholderHook;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.resources.TLocaleSendable;
 | 
				
			||||||
 | 
					import com.ilummc.tlib.util.Strings;
 | 
				
			||||||
 | 
					import me.skymc.taboolib.Main;
 | 
				
			||||||
 | 
					import net.md_5.bungee.api.chat.*;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					import org.bukkit.configuration.serialization.ConfigurationSerializable;
 | 
				
			||||||
 | 
					import org.bukkit.configuration.serialization.SerializableAs;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.concurrent.ThreadSafe;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.Arrays;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.regex.Matcher;
 | 
				
			||||||
 | 
					import java.util.regex.Pattern;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@ThreadSafe
 | 
				
			||||||
 | 
					@SerializableAs("JSON")
 | 
				
			||||||
 | 
					public class TLocaleJson implements TLocaleSendable, ConfigurationSerializable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final Pattern pattern = Pattern.compile("<([^<>]*)?@([^<>]*)>");
 | 
				
			||||||
 | 
					    private final List<BaseComponent[]> components;
 | 
				
			||||||
 | 
					    private final boolean papi;
 | 
				
			||||||
 | 
					    private final Map<String, Object> map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private TLocaleJson(List<BaseComponent[]> components, boolean papi, Map<String, Object> map) {
 | 
				
			||||||
 | 
					        this.components = ImmutableList.copyOf(components);
 | 
				
			||||||
 | 
					        this.papi = papi;
 | 
				
			||||||
 | 
					        this.map = map;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static TLocaleJson valueOf(Map<String, Object> map) {
 | 
				
			||||||
 | 
					        Object textObj = map.getOrDefault("text", "Empty Node");
 | 
				
			||||||
 | 
					        List<String> textList = textObj instanceof String ? Lists.newArrayList(((String) textObj)) :
 | 
				
			||||||
 | 
					                (textObj instanceof List && !((List) textObj).isEmpty()) ?
 | 
				
			||||||
 | 
					                        ((List<?>) textObj).stream().map(Object::toString).collect(Collectors.toList()) : Lists.newArrayList(String.valueOf(textObj));
 | 
				
			||||||
 | 
					        boolean papi = (boolean) map.getOrDefault("papi", Main.getInst().getConfig().getBoolean("LOCALE.USE_PAPI", false));
 | 
				
			||||||
 | 
					        Object argsObj = map.get("args");
 | 
				
			||||||
 | 
					        if (argsObj instanceof Map) {
 | 
				
			||||||
 | 
					            Map<?, ?> section = ((Map<?, ?>) argsObj);
 | 
				
			||||||
 | 
					            List<BaseComponent[]> collect = textList.stream().map(s -> {
 | 
				
			||||||
 | 
					                String[] template = pattern.split(s);
 | 
				
			||||||
 | 
					                int index = 0;
 | 
				
			||||||
 | 
					                Matcher matcher = pattern.matcher(s);
 | 
				
			||||||
 | 
					                List<BaseComponent> builder;
 | 
				
			||||||
 | 
					                if (template.length > index) {
 | 
				
			||||||
 | 
					                    builder = new ArrayList<>(Arrays.asList(TextComponent.fromLegacyText(template[index++])));
 | 
				
			||||||
 | 
					                } else builder = new ArrayList<>();
 | 
				
			||||||
 | 
					                while (matcher.find()) {
 | 
				
			||||||
 | 
					                    String replace = matcher.group();
 | 
				
			||||||
 | 
					                    if (replace.length() <= 2) continue;
 | 
				
			||||||
 | 
					                    replace = replace.substring(1, replace.length() - 1);
 | 
				
			||||||
 | 
					                    String[] split = replace.split("@");
 | 
				
			||||||
 | 
					                    String text = split.length > 1 ? split[0] : "";
 | 
				
			||||||
 | 
					                    String node = split.length > 1 ? split[1] : split[0];
 | 
				
			||||||
 | 
					                    if (section.containsKey(node)) {
 | 
				
			||||||
 | 
					                        Map<String, Object> arg = (Map<String, Object>) section.get(node);
 | 
				
			||||||
 | 
					                        text = (String) arg.getOrDefault("text", text);
 | 
				
			||||||
 | 
					                        BaseComponent[] component = TextComponent.fromLegacyText(text);
 | 
				
			||||||
 | 
					                        arg.forEach((key, value) -> {
 | 
				
			||||||
 | 
					                            switch (key) {
 | 
				
			||||||
 | 
					                                case "suggest":
 | 
				
			||||||
 | 
					                                    for (BaseComponent baseComponent : component) {
 | 
				
			||||||
 | 
					                                        baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.valueOf(value)));
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
 | 
					                                case "command":
 | 
				
			||||||
 | 
					                                    for (BaseComponent baseComponent : component) {
 | 
				
			||||||
 | 
					                                        baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.valueOf(value)));
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
 | 
					                                case "hover":
 | 
				
			||||||
 | 
					                                    for (BaseComponent baseComponent : component) {
 | 
				
			||||||
 | 
					                                        baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(String.valueOf(value)).create()));
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					                        builder.addAll(Arrays.asList(component));
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        builder.addAll(Arrays.asList(TextComponent.fromLegacyText(text)));
 | 
				
			||||||
 | 
					                        TLib.getTLib().getLogger().warn(Strings.replaceWithOrder(TLib.getTLib().getInternalLang().getString("MISSING-ARGUMENT"), node));
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    if (index < template.length) {
 | 
				
			||||||
 | 
					                        builder.addAll(Arrays.asList(TextComponent.fromLegacyText(template[index++])));
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return builder.toArray(new BaseComponent[0]);
 | 
				
			||||||
 | 
					            }).collect(Collectors.toList());
 | 
				
			||||||
 | 
					            return new TLocaleJson(collect, papi, map);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return new TLocaleJson(textList.stream().map(TextComponent::fromLegacyText).collect(Collectors.toList()), papi, map);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void sendTo(CommandSender sender, String... args) {
 | 
				
			||||||
 | 
					        if (sender instanceof Player)
 | 
				
			||||||
 | 
					            components.forEach(comp -> ((Player) sender).spigot().sendMessage(replace(comp, sender, args)));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String asString(String... args) {
 | 
				
			||||||
 | 
					        return components.toString();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Map<String, Object> serialize() {
 | 
				
			||||||
 | 
					        return Maps.newHashMap(map);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private BaseComponent[] replace(BaseComponent[] component, CommandSender sender, String... args) {
 | 
				
			||||||
 | 
					        BaseComponent[] components = new BaseComponent[component.length];
 | 
				
			||||||
 | 
					        for (int i = 0; i < components.length; i++) {
 | 
				
			||||||
 | 
					            components[i] = replace(component[i].duplicate(), sender, args);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return components;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private List<BaseComponent> replace(List<BaseComponent> component, CommandSender sender, String... args) {
 | 
				
			||||||
 | 
					        return component.stream().map(c -> replace(c, sender, args)).collect(Collectors.toList());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private BaseComponent replace(BaseComponent component, CommandSender sender, String... args) {
 | 
				
			||||||
 | 
					        if (component.getClickEvent() != null) {
 | 
				
			||||||
 | 
					            ClickEvent clickEvent = new ClickEvent(component.getClickEvent().getAction(), replace(sender, component.getClickEvent().getValue(), args));
 | 
				
			||||||
 | 
					            component.setClickEvent(clickEvent);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (component.getHoverEvent() != null) {
 | 
				
			||||||
 | 
					            HoverEvent hoverEvent = new HoverEvent(component.getHoverEvent().getAction(), replace(component.getHoverEvent().getValue(), sender, args));
 | 
				
			||||||
 | 
					            component.setHoverEvent(hoverEvent);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (component.getExtra() != null)
 | 
				
			||||||
 | 
					            component.setExtra(replace(component.getExtra(), sender, args));
 | 
				
			||||||
 | 
					        if (component instanceof TextComponent) {
 | 
				
			||||||
 | 
					            ((TextComponent) component).setText(replace(sender, ((TextComponent) component).getText(), args));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return component;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String replace(CommandSender sender, String text, String[] args) {
 | 
				
			||||||
 | 
					        String s = Strings.replaceWithOrder(text, args);
 | 
				
			||||||
 | 
					        return papi ? PlaceholderHook.replace(sender, s) : s;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,11 +1,11 @@
 | 
				
			|||||||
package com.ilummc.tlib.resources.type;
 | 
					package com.ilummc.tlib.resources.type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.collect.Maps;
 | 
					import com.google.common.collect.Maps;
 | 
				
			||||||
import com.ilummc.tlib.TLib;
 | 
					 | 
				
			||||||
import com.ilummc.tlib.compat.PlaceholderHook;
 | 
					import com.ilummc.tlib.compat.PlaceholderHook;
 | 
				
			||||||
import com.ilummc.tlib.resources.TLocale;
 | 
					import com.ilummc.tlib.resources.TLocale;
 | 
				
			||||||
import com.ilummc.tlib.resources.TLocaleSendable;
 | 
					import com.ilummc.tlib.resources.TLocaleSendable;
 | 
				
			||||||
import com.ilummc.tlib.util.Strings;
 | 
					import com.ilummc.tlib.util.Strings;
 | 
				
			||||||
 | 
					import me.skymc.taboolib.Main;
 | 
				
			||||||
import me.skymc.taboolib.display.TitleUtils;
 | 
					import me.skymc.taboolib.display.TitleUtils;
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
@@ -52,7 +52,7 @@ public class TLocaleTitle implements TLocaleSendable, ConfigurationSerializable
 | 
				
			|||||||
                    (int) map.getOrDefault("fadein", 10),
 | 
					                    (int) map.getOrDefault("fadein", 10),
 | 
				
			||||||
                    (int) map.getOrDefault("fadeout", 10),
 | 
					                    (int) map.getOrDefault("fadeout", 10),
 | 
				
			||||||
                    (int) map.getOrDefault("stay", 20),
 | 
					                    (int) map.getOrDefault("stay", 20),
 | 
				
			||||||
                    (boolean) map.getOrDefault("papi", TLib.getTLib().getConfig().isEnablePlaceholderHookByDefault()));
 | 
					                    (boolean) map.getOrDefault("papi", Main.getInst().getConfig().getBoolean("LOCALE.USE_PAPI", false)));
 | 
				
			||||||
        } catch (Exception e) {
 | 
					        } catch (Exception e) {
 | 
				
			||||||
            title = new TLocaleTitle("§4Load failed!", "§c" + e.getMessage(), 10, 20, 10, false);
 | 
					            title = new TLocaleTitle("§4Load failed!", "§c" + e.getMessage(), 10, 20, 10, false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,10 +28,6 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
 | 
				
			|||||||
        this.toVer = toVer;
 | 
					        this.toVer = toVer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static Builder builder() {
 | 
					 | 
				
			||||||
        return new Builder().toVersion(Bukkit.getServer().getClass().getName().split("\\.")[3]);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Object transform() {
 | 
					    public Object transform() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            ClassReader classReader = new ClassReader(from.getResourceAsStream("/" + from.getName().replace('.', '/') + ".class"));
 | 
					            ClassReader classReader = new ClassReader(from.getResourceAsStream("/" + from.getName().replace('.', '/') + ".class"));
 | 
				
			||||||
@@ -51,10 +47,8 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    public static Builder builder() {
 | 
				
			||||||
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
 | 
					        return new Builder().toVersion(Bukkit.getServer().getClass().getName().split("\\.")[3]);
 | 
				
			||||||
        super.visit(version, access, newClassName.replace('.', '/'), replace(signature),
 | 
					 | 
				
			||||||
                prevName, replace(interfaces));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -90,31 +84,10 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
 | 
				
			|||||||
        } else return null;
 | 
					        } else return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static class Builder {
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
 | 
				
			||||||
        private Class<?> from;
 | 
					        super.visit(version, access, newClassName.replace('.', '/'), replace(signature),
 | 
				
			||||||
 | 
					                replace(superName), replace(interfaces));
 | 
				
			||||||
        private String fromVersion, toVersion;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Builder from(Class<?> clazz) {
 | 
					 | 
				
			||||||
            this.from = clazz;
 | 
					 | 
				
			||||||
            return this;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Builder fromVersion(String ver) {
 | 
					 | 
				
			||||||
            fromVersion = ver;
 | 
					 | 
				
			||||||
            return this;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Builder toVersion(String ver) {
 | 
					 | 
				
			||||||
            toVersion = ver;
 | 
					 | 
				
			||||||
            return this;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public AsmClassTransformer build() {
 | 
					 | 
				
			||||||
            return new AsmClassTransformer(from, fromVersion, toVersion, new ClassWriter(ClassWriter.COMPUTE_MAXS));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private class AsmMethodTransformer extends MethodVisitor {
 | 
					    private class AsmMethodTransformer extends MethodVisitor {
 | 
				
			||||||
@@ -150,4 +123,31 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
 | 
				
			|||||||
            super.visitLocalVariable(name, replace(descriptor), replace(signature), start, end, index);
 | 
					            super.visitLocalVariable(name, replace(descriptor), replace(signature), start, end, index);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static class Builder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private Class<?> from;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private String fromVersion, toVersion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Builder from(Class<?> clazz) {
 | 
				
			||||||
 | 
					            this.from = clazz;
 | 
				
			||||||
 | 
					            return this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Builder fromVersion(String ver) {
 | 
				
			||||||
 | 
					            fromVersion = ver;
 | 
				
			||||||
 | 
					            return this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Builder toVersion(String ver) {
 | 
				
			||||||
 | 
					            toVersion = ver;
 | 
				
			||||||
 | 
					            return this;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public AsmClassTransformer build() {
 | 
				
			||||||
 | 
					            return new AsmClassTransformer(from, fromVersion, toVersion, new ClassWriter(ClassWriter.COMPUTE_MAXS));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,10 @@
 | 
				
			|||||||
package me.skymc.taboolib.javashell;
 | 
					package me.skymc.taboolib.javashell;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import com.ilummc.tlib.dependency.TDependencyLoader;
 | 
				
			||||||
import java.lang.reflect.Method;
 | 
					import lombok.Getter;
 | 
				
			||||||
import java.net.URL;
 | 
					import lombok.Setter;
 | 
				
			||||||
import java.net.URLClassLoader;
 | 
					import me.skymc.taboolib.Main;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import me.skymc.taboolib.message.MsgUtils;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.apache.commons.lang.ArrayUtils;
 | 
					import org.apache.commons.lang.ArrayUtils;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.event.HandlerList;
 | 
					import org.bukkit.event.HandlerList;
 | 
				
			||||||
@@ -13,195 +12,190 @@ import org.bukkit.event.Listener;
 | 
				
			|||||||
import org.bukkit.plugin.RegisteredListener;
 | 
					import org.bukkit.plugin.RegisteredListener;
 | 
				
			||||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
					import org.bukkit.scheduler.BukkitRunnable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import lombok.Getter;
 | 
					import java.io.File;
 | 
				
			||||||
import lombok.Setter;
 | 
					import java.lang.reflect.Method;
 | 
				
			||||||
import me.skymc.taboolib.Main;
 | 
					import java.net.URL;
 | 
				
			||||||
import me.skymc.taboolib.javashell.utils.JarUtils;
 | 
					import java.net.URLClassLoader;
 | 
				
			||||||
import me.skymc.taboolib.message.MsgUtils;
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class JavaShell {
 | 
					public class JavaShell {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Getter
 | 
					    @Getter
 | 
				
			||||||
	@Setter
 | 
					    @Setter
 | 
				
			||||||
	private static String paths = "";
 | 
					    private static String paths = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Getter
 | 
					    @Getter
 | 
				
			||||||
	@Setter
 | 
					    @Setter
 | 
				
			||||||
	private static File javaShellFolder;
 | 
					    private static File javaShellFolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Getter
 | 
					    @Getter
 | 
				
			||||||
	@Setter
 | 
					    @Setter
 | 
				
			||||||
	private static File scriptFolder;
 | 
					    private static File scriptFolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Getter
 | 
					    @Getter
 | 
				
			||||||
	@Setter
 | 
					    @Setter
 | 
				
			||||||
	private static File cacheFolder;
 | 
					    private static File cacheFolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Getter
 | 
					    @Getter
 | 
				
			||||||
	@Setter
 | 
					    @Setter
 | 
				
			||||||
	private static File libFolder;
 | 
					    private static File libFolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Getter
 | 
					    @Getter
 | 
				
			||||||
	@Setter
 | 
					    @Setter
 | 
				
			||||||
	private static HashMap<String, Class<?>> shells = new HashMap<>();
 | 
					    private static HashMap<String, Class<?>> shells = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void javaShellSetup() {
 | 
					    public static void javaShellSetup() {
 | 
				
			||||||
		File dataFolder = Main.getInst().getDataFolder();
 | 
					        File dataFolder = Main.getInst().getDataFolder();
 | 
				
			||||||
		File pluginsFolder = dataFolder.getParentFile();
 | 
					        File pluginsFolder = dataFolder.getParentFile();
 | 
				
			||||||
		File serverRoot = Bukkit.getWorldContainer();
 | 
					        File serverRoot = Bukkit.getWorldContainer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		File[] rootJars = serverRoot.listFiles((dir, name) -> name.toLowerCase().endsWith("jar"));
 | 
					        File[] rootJars = serverRoot.listFiles((dir, name) -> name.toLowerCase().endsWith("jar"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		File[] pluginJars = pluginsFolder.listFiles((dir, name) -> name.toLowerCase().endsWith("jar"));
 | 
					        File[] pluginJars = pluginsFolder.listFiles((dir, name) -> name.toLowerCase().endsWith("jar"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (File file : (File[]) ArrayUtils.addAll(rootJars, pluginJars)) {
 | 
					        for (File file : (File[]) ArrayUtils.addAll(rootJars, pluginJars)) {
 | 
				
			||||||
			String path = file.getAbsolutePath();
 | 
					            String path = file.getAbsolutePath();
 | 
				
			||||||
			paths += File.pathSeparator + path;
 | 
					            paths += File.pathSeparator + path;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		javaShellFolder = new File(Main.getInst().getDataFolder(), "JavaShells");
 | 
					        javaShellFolder = new File(Main.getInst().getDataFolder(), "JavaShells");
 | 
				
			||||||
		if (!javaShellFolder.exists()) {
 | 
					        if (!javaShellFolder.exists()) {
 | 
				
			||||||
			Main.getInst().saveResource("JavaShells/scripts/-testshell.java", true);
 | 
					            Main.getInst().saveResource("JavaShells/scripts/-testshell.java", true);
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		scriptFolder = new File(javaShellFolder, "scripts");
 | 
					        scriptFolder = new File(javaShellFolder, "scripts");
 | 
				
			||||||
		if (!scriptFolder.exists()) {
 | 
					        if (!scriptFolder.exists()) {
 | 
				
			||||||
			scriptFolder.mkdir();
 | 
					            scriptFolder.mkdir();
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cacheFolder = new File(javaShellFolder, "cache");
 | 
					        cacheFolder = new File(javaShellFolder, "cache");
 | 
				
			||||||
		if (!cacheFolder.exists()) {
 | 
					        if (!cacheFolder.exists()) {
 | 
				
			||||||
			cacheFolder.mkdir();
 | 
					            cacheFolder.mkdir();
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		libFolder = new File(javaShellFolder, "lib");
 | 
					        libFolder = new File(javaShellFolder, "lib");
 | 
				
			||||||
		if (!libFolder.exists()) {
 | 
					        if (!libFolder.exists()) {
 | 
				
			||||||
			libFolder.mkdir();
 | 
					            libFolder.mkdir();
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		File tools = new File(Main.getInst().getDataFolder(), "JavaShells/lib/com.sun.tools.jar");
 | 
					        File tools = new File(Main.getInst().getDataFolder(), "JavaShells/lib/com.sun.tools.jar");
 | 
				
			||||||
		if (!tools.exists()) {
 | 
					        if (!tools.exists()) {
 | 
				
			||||||
			MsgUtils.warn("&4JavaShell &c工具的必要依赖 &4com.sun.tools.jar &c不存在, 功能关闭!");
 | 
					            MsgUtils.warn("&4JavaShell &c工具的必要依赖 &4com.sun.tools.jar &c不存在, 功能关闭!");
 | 
				
			||||||
			return;
 | 
					            return;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		loadLibrary();
 | 
					        loadLibrary();
 | 
				
			||||||
		new BukkitRunnable() {
 | 
					        new BukkitRunnable() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			@Override
 | 
					            @Override
 | 
				
			||||||
			public void run() {
 | 
					            public void run() {
 | 
				
			||||||
				long time = System.currentTimeMillis();
 | 
					                long time = System.currentTimeMillis();
 | 
				
			||||||
				for (File file : scriptFolder.listFiles()) {
 | 
					                for (File file : scriptFolder.listFiles()) {
 | 
				
			||||||
					if (!file.getName().startsWith("-")) {
 | 
					                    if (!file.getName().startsWith("-")) {
 | 
				
			||||||
						reloadShell(file.getName());
 | 
					                        reloadShell(file.getName());
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
				}
 | 
					                }
 | 
				
			||||||
				MsgUtils.send("载入 " + shells.size() + " 个脚本, 耗时 &f" + (System.currentTimeMillis() - time) + "ms");
 | 
					                MsgUtils.send("载入 " + shells.size() + " 个脚本, 耗时 &f" + (System.currentTimeMillis() - time) + "ms");
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
		}.runTask(Main.getInst());
 | 
					        }.runTask(Main.getInst());
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void javaShellCancel() {
 | 
					    public static void javaShellCancel() {
 | 
				
			||||||
		for (File cacheFile : cacheFolder.listFiles()) {
 | 
					        for (File cacheFile : cacheFolder.listFiles()) {
 | 
				
			||||||
			cacheFile.delete();
 | 
					            cacheFile.delete();
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
		for (String name : shells.keySet()) {
 | 
					        for (String name : shells.keySet()) {
 | 
				
			||||||
			invokeMethod(name, "onDisable");
 | 
					            invokeMethod(name, "onDisable");
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void invokeMethod(String name, String method) {
 | 
					    public static void invokeMethod(String name, String method) {
 | 
				
			||||||
		if (shells.containsKey(name)) {
 | 
					        if (shells.containsKey(name)) {
 | 
				
			||||||
			Class<?> clazz = shells.get(name);
 | 
					            Class<?> clazz = shells.get(name);
 | 
				
			||||||
			try {
 | 
					            try {
 | 
				
			||||||
				Method disableMethod = clazz.getMethod(method);
 | 
					                Method disableMethod = clazz.getMethod(method);
 | 
				
			||||||
				if (disableMethod != null) {
 | 
					                if (disableMethod != null) {
 | 
				
			||||||
					disableMethod.invoke(clazz.newInstance());
 | 
					                    disableMethod.invoke(clazz.newInstance());
 | 
				
			||||||
				}
 | 
					                }
 | 
				
			||||||
			}
 | 
					            } catch (Exception e) {
 | 
				
			||||||
			catch (Exception e) {
 | 
					                //
 | 
				
			||||||
				//
 | 
					            }
 | 
				
			||||||
			}
 | 
					        }
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void unloadShell(String shell) {
 | 
					    public static void unloadShell(String shell) {
 | 
				
			||||||
		invokeMethod(shell, "onDisable");
 | 
					        invokeMethod(shell, "onDisable");
 | 
				
			||||||
		Class<?> clazz = shells.remove(shell);
 | 
					        Class<?> clazz = shells.remove(shell);
 | 
				
			||||||
		try {
 | 
					        try {
 | 
				
			||||||
			if (clazz.newInstance() instanceof Listener) {
 | 
					            if (clazz.newInstance() instanceof Listener) {
 | 
				
			||||||
				for (RegisteredListener listener : HandlerList.getRegisteredListeners(Main.getInst())) {
 | 
					                for (RegisteredListener listener : HandlerList.getRegisteredListeners(Main.getInst())) {
 | 
				
			||||||
					if (listener.getListener().getClass().getName().equals(clazz.getName())) {
 | 
					                    if (listener.getListener().getClass().getName().equals(clazz.getName())) {
 | 
				
			||||||
						HandlerList.unregisterAll(listener.getListener());
 | 
					                        HandlerList.unregisterAll(listener.getListener());
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
				}
 | 
					                }
 | 
				
			||||||
				MsgUtils.send("已为脚本 &f" + shell + " &7注销监听器");
 | 
					                MsgUtils.send("已为脚本 &f" + shell + " &7注销监听器");
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
		}
 | 
					        } catch (Exception e) {
 | 
				
			||||||
		catch (Exception e) {
 | 
					            //
 | 
				
			||||||
			//
 | 
					        }
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static boolean reloadShell(String shell) {
 | 
					    public static boolean reloadShell(String shell) {
 | 
				
			||||||
		unloadShell(shell = shell.replace(".java", ""));
 | 
					        unloadShell(shell = shell.replace(".java", ""));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		try {
 | 
					        try {
 | 
				
			||||||
			Class.forName("com.sun.tools.javac.main.Main");
 | 
					            Class.forName("com.sun.tools.javac.main.Main");
 | 
				
			||||||
		}
 | 
					        } catch (Exception e) {
 | 
				
			||||||
		catch (Exception e) {
 | 
					            MsgUtils.warn("&4JavaShell &c工具的必要依赖 &4com.sun.tools.jar &c丢失, 无法载入!");
 | 
				
			||||||
			MsgUtils.warn("&4JavaShell &c工具的必要依赖 &4com.sun.tools.jar &c丢失, 无法载入!");
 | 
					            return false;
 | 
				
			||||||
			return false;
 | 
					        }
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    File javaFile = new File(scriptFolder, shell + ".java");
 | 
					        File javaFile = new File(scriptFolder, shell + ".java");
 | 
				
			||||||
	    if (!javaFile.exists()) {
 | 
					        if (!javaFile.exists()) {
 | 
				
			||||||
	    	MsgUtils.send("&c脚本 &4" + shell + "&c 不存在");
 | 
					            MsgUtils.send("&c脚本 &4" + shell + "&c 不存在");
 | 
				
			||||||
	    	return false; 
 | 
					            return false;
 | 
				
			||||||
	    }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    String[] args = {
 | 
					        String[] args = {
 | 
				
			||||||
	    		  "-nowarn",
 | 
					                "-nowarn",
 | 
				
			||||||
	    	      "-classpath", "." + File.pathSeparator + JavaShell.getPaths(), 
 | 
					                "-classpath", "." + File.pathSeparator + JavaShell.getPaths(),
 | 
				
			||||||
	    	      "-d", cacheFolder.getAbsolutePath() + File.separator, 
 | 
					                "-d", cacheFolder.getAbsolutePath() + File.separator,
 | 
				
			||||||
	    	      javaFile.getAbsolutePath() 
 | 
					                javaFile.getAbsolutePath()
 | 
				
			||||||
	    };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    int code = new com.sun.tools.javac.main.Main("javac").compile(args).exitCode;
 | 
					        int code = new com.sun.tools.javac.main.Main("javac").compile(args).exitCode;
 | 
				
			||||||
	    if (code == 0) {
 | 
					        if (code == 0) {
 | 
				
			||||||
	    	MsgUtils.send("&f" + shell + "&7 载入成功");
 | 
					            MsgUtils.send("&f" + shell + "&7 载入成功");
 | 
				
			||||||
	    	 try {
 | 
					            try {
 | 
				
			||||||
	    		 URL[] urls = { cacheFolder.toURI().toURL() };
 | 
					                URL[] urls = {cacheFolder.toURI().toURL()};
 | 
				
			||||||
	    		 URLClassLoader sysloader = new URLClassLoader(urls, Main.class.getClassLoader());
 | 
					                URLClassLoader sysloader = new URLClassLoader(urls, Main.class.getClassLoader());
 | 
				
			||||||
	    		 Class<?> clazz = sysloader.loadClass(shell);
 | 
					                Class<?> clazz = sysloader.loadClass(shell);
 | 
				
			||||||
	    		 shells.put(shell, clazz);
 | 
					                shells.put(shell, clazz);
 | 
				
			||||||
	    		 sysloader.close();
 | 
					                sysloader.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    		 invokeMethod(shell, "onEnable");
 | 
					                invokeMethod(shell, "onEnable");
 | 
				
			||||||
	    		 if (clazz.newInstance() instanceof Listener) {
 | 
					                if (clazz.newInstance() instanceof Listener) {
 | 
				
			||||||
	    			 Bukkit.getPluginManager().registerEvents((Listener) clazz.newInstance(), Main.getInst());
 | 
					                    Bukkit.getPluginManager().registerEvents((Listener) clazz.newInstance(), Main.getInst());
 | 
				
			||||||
	    			 MsgUtils.send("已为脚本 &f" + shell + " &7注册监听器");
 | 
					                    MsgUtils.send("已为脚本 &f" + shell + " &7注册监听器");
 | 
				
			||||||
	    		 }
 | 
					                }
 | 
				
			||||||
	    	 }
 | 
					            } catch (Exception e) {
 | 
				
			||||||
	    	 catch (Exception e) {
 | 
					                //
 | 
				
			||||||
	    		 //
 | 
					            }
 | 
				
			||||||
	    	 }
 | 
					            return true;
 | 
				
			||||||
	    	 return true;
 | 
					        } else {
 | 
				
			||||||
	    }
 | 
					            MsgUtils.send("&4" + shell + "&c 载入失败");
 | 
				
			||||||
	    else {
 | 
					            return false;
 | 
				
			||||||
	    	MsgUtils.send("&4" + shell + "&c 载入失败");
 | 
					        }
 | 
				
			||||||
	    	return false;
 | 
					    }
 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static void loadLibrary() {
 | 
					    private static void loadLibrary() {
 | 
				
			||||||
		for (File jar : libFolder.listFiles()) {
 | 
					        for (File jar : libFolder.listFiles()) {
 | 
				
			||||||
			try {
 | 
					            try {
 | 
				
			||||||
				JarUtils.addClassPath(JarUtils.getJarUrl(jar));
 | 
					                TDependencyLoader.addToPath(Main.getInst(), jar);
 | 
				
			||||||
				MsgUtils.send("成功载入 &f" + jar.getName() + " &7到运行库");
 | 
					                MsgUtils.send("成功载入 &f" + jar.getName() + " &7到运行库");
 | 
				
			||||||
			} catch (Exception e) {
 | 
					            } catch (Exception e) {
 | 
				
			||||||
				//
 | 
					                //
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,9 @@
 | 
				
			|||||||
package me.skymc.taboolib.javashell.utils;
 | 
					package me.skymc.taboolib.javashell.utils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.BufferedInputStream;
 | 
					import me.skymc.taboolib.message.MsgUtils;
 | 
				
			||||||
import java.io.BufferedOutputStream;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import java.io.File;
 | 
					
 | 
				
			||||||
import java.io.FileOutputStream;
 | 
					import java.io.*;
 | 
				
			||||||
import java.io.IOException;
 | 
					 | 
				
			||||||
import java.io.InputStream;
 | 
					 | 
				
			||||||
import java.io.OutputStream;
 | 
					 | 
				
			||||||
import java.lang.reflect.Method;
 | 
					import java.lang.reflect.Method;
 | 
				
			||||||
import java.net.URL;
 | 
					import java.net.URL;
 | 
				
			||||||
import java.net.URLClassLoader;
 | 
					import java.net.URLClassLoader;
 | 
				
			||||||
@@ -15,10 +12,6 @@ import java.util.Enumeration;
 | 
				
			|||||||
import java.util.jar.JarEntry;
 | 
					import java.util.jar.JarEntry;
 | 
				
			||||||
import java.util.jar.JarFile;
 | 
					import java.util.jar.JarFile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import me.skymc.taboolib.message.MsgUtils;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class JarUtils {
 | 
					public class JarUtils {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static boolean extractFromJar(final String fileName, final String dest) throws IOException {
 | 
						public static boolean extractFromJar(final String fileName, final String dest) throws IOException {
 | 
				
			||||||
@@ -65,6 +58,7 @@ public class JarUtils {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Deprecated
 | 
				
			||||||
	public static URL getJarUrl(final File file) throws IOException {
 | 
						public static URL getJarUrl(final File file) throws IOException {
 | 
				
			||||||
		return new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/");
 | 
							return new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -88,13 +82,14 @@ public class JarUtils {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void addClassPath(final URL url) {
 | 
						@Deprecated
 | 
				
			||||||
 | 
						public static void addClassPath(final URL url) {
 | 
				
			||||||
		final URLClassLoader sysloader = (URLClassLoader) Bukkit.class.getClassLoader();
 | 
							final URLClassLoader sysloader = (URLClassLoader) Bukkit.class.getClassLoader();
 | 
				
			||||||
		final Class<URLClassLoader> sysclass = URLClassLoader.class;
 | 
							final Class<URLClassLoader> sysclass = URLClassLoader.class;
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
            final Method method = sysclass.getDeclaredMethod("addURL", URL.class);
 | 
								final Method method = sysclass.getDeclaredMethod("addURL", URL.class);
 | 
				
			||||||
			method.setAccessible(true);
 | 
								method.setAccessible(true);
 | 
				
			||||||
            method.invoke(sysloader, url);
 | 
								method.invoke(sysloader, url);
 | 
				
			||||||
		} catch (Throwable t) {
 | 
							} catch (Throwable t) {
 | 
				
			||||||
			MsgUtils.warn("无法添加添加 &4" + url + "&c 到运行库");
 | 
								MsgUtils.warn("无法添加添加 &4" + url + "&c 到运行库");
 | 
				
			||||||
			MsgUtils.warn(t.getMessage());
 | 
								MsgUtils.warn(t.getMessage());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,3 +6,4 @@ RELOADING-LANG: '正在重新载入 {0} 插件的语言文件'
 | 
				
			|||||||
FETCH-LOCALE-ERROR: '语言文件获取失败:{0}'
 | 
					FETCH-LOCALE-ERROR: '语言文件获取失败:{0}'
 | 
				
			||||||
SEND-LOCALE-ERROR: '语言文件发送失败:{0}'
 | 
					SEND-LOCALE-ERROR: '语言文件发送失败:{0}'
 | 
				
			||||||
LOCALE-ERROR-REASON: '原因:{0}'
 | 
					LOCALE-ERROR-REASON: '原因:{0}'
 | 
				
			||||||
 | 
					MISSING-ARGUMENT: '语言文本含有没有找到的参数 {0}'
 | 
				
			||||||
		Reference in New Issue
	
	Block a user