+ fixed TInject

+ fixed SimpleCommandBuilder
This commit is contained in:
坏黑 2018-11-25 18:16:21 +08:00
parent b37ec49a80
commit 24a9b586c4
3 changed files with 91 additions and 13 deletions

View File

@ -209,7 +209,9 @@ public class TabooLibLoader implements Listener {
loaders.forEach(loader -> {
try {
loader.preLoad(plugin, loadClass);
} catch (Throwable ignored) {
} catch (NoClassDefFoundError ignore) {
} catch (Throwable e) {
e.printStackTrace();
}
});
}
@ -218,7 +220,9 @@ public class TabooLibLoader implements Listener {
loaders.forEach(loader -> {
try {
loader.postLoad(plugin, loadClass);
} catch (Throwable ignored) {
} catch (NoClassDefFoundError ignore) {
} catch (Throwable e) {
e.printStackTrace();
}
});
}
@ -227,7 +231,9 @@ public class TabooLibLoader implements Listener {
loaders.forEach(loader -> {
try {
loader.unload(plugin, loadClass);
} catch (Throwable ignored) {
} catch (NoClassDefFoundError ignore) {
} catch (Throwable e) {
e.printStackTrace();
}
});
}

View File

@ -20,8 +20,8 @@ public class SimpleCommandBuilder {
public static final CompleterTab EMPTY_COMPLETER_TAB = ((sender, args) -> new ArrayList<>());
public static final CompleterCommand EMPTY_COMPLETER_COMMAND = ((sender, args) -> false);
private final String command;
private final Plugin plugin;
private String command;
private Plugin plugin;
private String description;
private String usage;
private List<String> aliases;
@ -34,8 +34,6 @@ public class SimpleCommandBuilder {
private boolean build;
SimpleCommandBuilder(String command, Plugin plugin) {
Preconditions.checkNotNull(command, "command cannot not be null");
Preconditions.checkNotNull(plugin, "plugin cannot not be null");
this.command = command;
this.plugin = plugin;
this.description = "";
@ -49,6 +47,16 @@ public class SimpleCommandBuilder {
return new SimpleCommandBuilder(command.toLowerCase(), plugin);
}
public SimpleCommandBuilder command(String command) {
this.command = command;
return this;
}
public SimpleCommandBuilder plugin(Plugin plugin) {
this.plugin = plugin;
return this;
}
public SimpleCommandBuilder description(String description) {
this.description = description;
return this;
@ -94,11 +102,9 @@ public class SimpleCommandBuilder {
return this;
}
public boolean isBuild() {
return build;
}
public SimpleCommandBuilder build() {
Preconditions.checkNotNull(plugin, "缺少 \"plugin\" 部分");
Preconditions.checkNotNull(command, "缺少 \"command\" 部分");
Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分");
Preconditions.checkNotNull(completerTab, "缺少 \"CompleterTab\" 部分");
if (forceRegister) {
@ -118,4 +124,58 @@ public class SimpleCommandBuilder {
build = true;
return this;
}
// *********************************
//
// Getter and Setter
//
// *********************************
public String getCommand() {
return command;
}
public Plugin getPlugin() {
return plugin;
}
public String getDescription() {
return description;
}
public String getUsage() {
return usage;
}
public List<String> getAliases() {
return aliases;
}
public String getPermission() {
return permission;
}
public String getPermissionMessage() {
return permissionMessage;
}
public CompleterTab getCompleterTab() {
return completerTab;
}
public CompleterCommand getCompleterCommand() {
return completerCommand;
}
public boolean isSilence() {
return silence;
}
public boolean isForceRegister() {
return forceRegister;
}
public boolean isBuild() {
return build;
}
}

View File

@ -2,6 +2,7 @@ package me.skymc.taboolib.common.inject;
import com.google.common.collect.Maps;
import com.ilummc.tlib.logger.TLogger;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.TabooLibLoader;
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
import me.skymc.taboolib.common.configuration.TConfiguration;
@ -65,6 +66,9 @@ public class TInjectLoader implements TabooLibLoader.Loader {
if (builder.isBuild()) {
TLogger.getGlobalLogger().error("Command was registered. (" + field.getType().getName() + ")");
} else {
if (builder.getPlugin() == null) {
builder.plugin(plugin);
}
builder.build();
}
} catch (Exception e) {
@ -88,8 +92,12 @@ public class TInjectLoader implements TabooLibLoader.Loader {
try {
declaredField.setAccessible(true);
injectTypes.get(Plugin.class).run(plugin, declaredField, annotation.value());
} catch (Exception e) {
TabooLib.debug(declaredField.getName() + " injected. (" + declaredField.getType().getName() + ")");
} catch (Throwable e) {
TLogger.getGlobalLogger().error(declaredField.getName() + " inject failed: " + e.getMessage() + " (" + declaredField.getType().getName() + ")");
if (e.getMessage() == null) {
e.printStackTrace();
}
}
}
}
@ -114,8 +122,12 @@ public class TInjectLoader implements TabooLibLoader.Loader {
try {
declaredField.setAccessible(true);
tInjectTask.run(plugin, declaredField, annotation.value());
} catch (Exception e) {
TabooLib.debug(declaredField.getName() + " injected. (" + declaredField.getType().getName() + ")");
} catch (Throwable e) {
TLogger.getGlobalLogger().error(declaredField.getName() + " inject failed: " + e.getMessage() + " (" + declaredField.getType().getName() + ")");
if (e.getMessage() == null) {
e.printStackTrace();
}
}
}
}