Supported TabooLib 4.x & Delete internal commands
This commit is contained in:
@@ -47,13 +47,13 @@ public class TabooLib {
|
||||
config = TConfig.create(getPlugin(), "settings.yml");
|
||||
// 加载版本号
|
||||
try {
|
||||
version = NumberConversions.toDouble(IO.readFully(Files.getResource("version"), Charset.forName("utf-8")));
|
||||
version = NumberConversions.toDouble(IO.readFully(Files.getResource("__resources__/version"), Charset.forName("utf-8")));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
// 加载内部语言文件
|
||||
try {
|
||||
internal.loadFromString(IO.readFully(Files.getResource("lang/internal.yml"), Charset.forName("utf-8")));
|
||||
internal.loadFromString(IO.readFully(Files.getResource("__resources__/lang/internal.yml"), Charset.forName("utf-8")));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TabooLibSettings {
|
||||
|
||||
public static InputStream getSettingsInputStream() {
|
||||
try {
|
||||
URL url = TabooLibServer.class.getClassLoader().getResource("settings.properties");
|
||||
URL url = TabooLibServer.class.getClassLoader().getResource("__resources__/settings.properties");
|
||||
if (url == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
package io.izzel.taboolib.common.command;
|
||||
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.module.command.base.BaseMainCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseSubCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseCommand;
|
||||
import io.izzel.taboolib.module.command.base.Argument;
|
||||
import io.izzel.taboolib.module.command.base.SubCommand;
|
||||
import io.izzel.taboolib.util.ArrayUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-07-04 21:32
|
||||
*/
|
||||
@BaseCommand(
|
||||
name = "tExecute",
|
||||
permission = "taboolib.admin"
|
||||
)
|
||||
public class TabooLibExecuteCommand extends BaseMainCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandTitle() {
|
||||
return TLocale.asString("COMMANDS.TEXECUTE.COMMAND-TITLE");
|
||||
}
|
||||
|
||||
@SubCommand(priority = 1)
|
||||
BaseSubCommand chat = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "chat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TEXECUTE.CHAT.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TEXECUTE.CHAT.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TEXECUTE.CHAT.ARGUMENTS.1"))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Player player = Bukkit.getPlayerExact(args[0]);
|
||||
if (player == null) {
|
||||
TLocale.sendTo(sender, "INVALID-PLAYER-OFFLINE", args[0]);
|
||||
return;
|
||||
}
|
||||
player.chat(ArrayUtil.arrayJoin(args, 1));
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 1)
|
||||
BaseSubCommand command = new BaseSubCommand() {
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "command";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[] {"cmd"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TEXECUTE.COMMAND.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TEXECUTE.COMMAND.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TEXECUTE.COMMAND.ARGUMENTS.1"))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args[0].equalsIgnoreCase("console")) {
|
||||
TabooLibAPI.dispatchCommand(Bukkit.getConsoleSender(), ArrayUtil.arrayJoin(args, 1));
|
||||
return;
|
||||
}
|
||||
Player player = Bukkit.getPlayerExact(args[0]);
|
||||
if (player == null) {
|
||||
TLocale.sendTo(sender, "INVALID-TARGET-NOT-FOUND", args[0]);
|
||||
return;
|
||||
}
|
||||
TabooLibAPI.dispatchCommand(player, ArrayUtil.arrayJoin(args, 1));
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 2)
|
||||
BaseSubCommand commandAsOp = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "commandAsOp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[] {"op"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TEXECUTE.COMMAND-AS-OP.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TEXECUTE.COMMAND-AS-OP.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TEXECUTE.COMMAND-AS-OP.ARGUMENTS.1"))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args[0].equalsIgnoreCase("console")) {
|
||||
TabooLibAPI.dispatchCommand(Bukkit.getConsoleSender(), ArrayUtil.arrayJoin(args, 1));
|
||||
return;
|
||||
}
|
||||
Player player = Bukkit.getPlayerExact(args[0]);
|
||||
if (player == null) {
|
||||
TLocale.sendTo(sender, "INVALID-TARGET-NOT-FOUND", args[0]);
|
||||
return;
|
||||
}
|
||||
boolean isOp = player.isOp();
|
||||
player.setOp(true);
|
||||
try {
|
||||
TabooLibAPI.dispatchCommand(player, ArrayUtil.arrayJoin(args, 1));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
player.setOp(isOp);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package io.izzel.taboolib.common.command;
|
||||
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.module.locale.TLocaleLoader;
|
||||
import io.izzel.taboolib.module.command.base.BaseMainCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseSubCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseCommand;
|
||||
import io.izzel.taboolib.module.command.base.Argument;
|
||||
import io.izzel.taboolib.module.command.base.SubCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018-04-22 14:36:28
|
||||
*/
|
||||
@BaseCommand(
|
||||
name = "tLocale",
|
||||
permission = "taboolib.admin"
|
||||
)
|
||||
public class TabooLibLocaleCommand extends BaseMainCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandTitle() {
|
||||
return TLocale.asString("COMMANDS.TLOCALE.COMMAND-TITLE");
|
||||
}
|
||||
|
||||
@SubCommand
|
||||
BaseSubCommand send = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "send";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TLOCALE.SEND.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TLOCALE.SEND.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TLOCALE.SEND.ARGUMENTS.1")),
|
||||
new Argument(TLocale.asString("COMMANDS.TLOCALE.SEND.ARGUMENTS.2"), false)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
List<CommandSender> target = new ArrayList<>();
|
||||
if (args[0].equalsIgnoreCase("all")) {
|
||||
target.add(Bukkit.getConsoleSender());
|
||||
target.addAll(Bukkit.getOnlinePlayers());
|
||||
} else if (args[0].equalsIgnoreCase("players")) {
|
||||
target.addAll(Bukkit.getOnlinePlayers());
|
||||
} else if (args[0].equalsIgnoreCase("console")) {
|
||||
target.add(Bukkit.getConsoleSender());
|
||||
} else {
|
||||
Player player = Bukkit.getPlayerExact(args[0]);
|
||||
if (player == null) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOCALE.SEND.INVALID-PLAYER", args[0]);
|
||||
return;
|
||||
}
|
||||
target.add(player);
|
||||
}
|
||||
|
||||
String[] arguments;
|
||||
if (args.length > 2) {
|
||||
arguments = new String[args.length - 2];
|
||||
IntStream.range(2, args.length).forEach(i -> arguments[i - 2] = args[i]);
|
||||
} else {
|
||||
arguments = new String[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* 使用命令发送其他插件文本
|
||||
* /tlocale send BlackSKY testPlugin:message
|
||||
*/
|
||||
if (args[1].contains(":")) {
|
||||
String[] path = args[1].split(":");
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(path[0]);
|
||||
if (plugin == null || !TLocaleLoader.isLocaleLoaded(plugin)) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOCALE.SEND.INVALID-PLUGIN", path[0]);
|
||||
return;
|
||||
}
|
||||
if (path.length == 1) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOCALE.SEND.INVALID-PATH", args[1]);
|
||||
return;
|
||||
}
|
||||
target.forEach(x -> TLocaleLoader.sendTo(plugin, path[1], x, arguments));
|
||||
} else {
|
||||
target.forEach(x -> TLocale.sendTo(x, args[1], arguments));
|
||||
}
|
||||
|
||||
if (sender instanceof Player && ((Player) sender).getItemInHand().getType().name().contains("COMMAND")) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOCALE.SEND.SUCCESS-SEND", String.valueOf(System.currentTimeMillis() - time));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
package io.izzel.taboolib.common.command;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.module.command.base.BaseCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseMainCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseSubCommand;
|
||||
import io.izzel.taboolib.module.command.base.Argument;
|
||||
import io.izzel.taboolib.module.command.base.SubCommand;
|
||||
import io.izzel.taboolib.util.plugin.PluginLoadState;
|
||||
import io.izzel.taboolib.util.plugin.PluginLoadStateType;
|
||||
import io.izzel.taboolib.util.plugin.PluginUnloadState;
|
||||
import io.izzel.taboolib.util.plugin.PluginUtils;
|
||||
import io.izzel.taboolib.util.ArrayUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-05-07 20:14
|
||||
*/
|
||||
@BaseCommand(
|
||||
name = "tPlugin",
|
||||
permission = "taboolib.admin"
|
||||
)
|
||||
public class TabooLibPluginCommand extends BaseMainCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandTitle() {
|
||||
return TLocale.asString("COMMANDS.TPLUGIN.COMMAND-TITLE");
|
||||
}
|
||||
|
||||
@SubCommand(priority = 1)
|
||||
BaseSubCommand load = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "load";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TPLUGIN.LOAD.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {new Argument(TLocale.asString("COMMANDS.TPLUGIN.LOAD.ARGUMENTS.0"), true)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String name = ArrayUtil.arrayJoin(args, 0);
|
||||
if (PluginUtils.getPluginByName(name) != null) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-PLUGIN", name, name + " already loaded!");
|
||||
} else {
|
||||
PluginLoadState loadState;
|
||||
try {
|
||||
loadState = PluginUtils.load(name);
|
||||
} catch (Exception e) {
|
||||
loadState = new PluginLoadState(PluginLoadStateType.INVALID_PLUGIN, e.toString());
|
||||
}
|
||||
switch (loadState.getStateType()) {
|
||||
case INVALID_DESCRIPTION: {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-DESCRIPTION");
|
||||
break;
|
||||
}
|
||||
case INVALID_PLUGIN: {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-PLUGIN", name, loadState.getMessage());
|
||||
break;
|
||||
}
|
||||
case FILE_NOT_FOUND: {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.FILE-NOT-FOUND", name);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.LOAD-SUCCESS", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 2)
|
||||
BaseSubCommand unload = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "unload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TPLUGIN.UNLOAD.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {new Argument(TLocale.asString("COMMANDS.TPLUGIN.UNLOAD.ARGUMENTS.0"), true, () -> {
|
||||
return java.util.Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList());
|
||||
})};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String name = ArrayUtil.arrayJoin(args, 0);
|
||||
Plugin plugin = PluginUtils.getPluginByName(name);
|
||||
if (plugin == null) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.INVALID-PLUGIN", name);
|
||||
} else if (PluginUtils.isIgnored(plugin)) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.INVALID-PLUGIN-IGNORED", name);
|
||||
} else {
|
||||
PluginUnloadState unloadState;
|
||||
try {
|
||||
unloadState = PluginUtils.unload(plugin);
|
||||
} catch (Exception e) {
|
||||
unloadState = new PluginUnloadState(true, e.toString());
|
||||
}
|
||||
if (unloadState.isFailed()) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-FAIL", name, unloadState.getMessage());
|
||||
} else {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-SUCCESS", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 3)
|
||||
BaseSubCommand reload = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TPLUGIN.RELOAD.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {new Argument(TLocale.asString("COMMANDS.TPLUGIN.RELOAD.ARGUMENTS.0"), true, () -> {
|
||||
return Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList());
|
||||
})};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String name = ArrayUtil.arrayJoin(args, 0);
|
||||
Plugin plugin = PluginUtils.getPluginByName(name);
|
||||
if (plugin == null) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.RELOAD.INVALID-PLUGIN", name);
|
||||
} else if (PluginUtils.isIgnored(plugin)) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.RELOAD.INVALID-PLUGIN-IGNORED", name);
|
||||
} else {
|
||||
TabooLibAPI.dispatchCommand(sender, "tPlugin unload " + plugin.getName());
|
||||
TabooLibAPI.dispatchCommand(sender, "tPlugin load " + plugin.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 4)
|
||||
BaseSubCommand info = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TPLUGIN.INFO.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {new Argument(TLocale.asString("COMMANDS.TPLUGIN.INFO.ARGUMENTS.0"), true, () -> {
|
||||
return Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList());
|
||||
})};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
String name = ArrayUtil.arrayJoin(args, 0);
|
||||
Plugin plugin = PluginUtils.getPluginByName(name);
|
||||
if (plugin == null) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INVALID-PLUGIN", name);
|
||||
} else {
|
||||
try {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INFO-PLUGIN",
|
||||
plugin.getName(),
|
||||
String.valueOf(plugin.getDescription().getDescription()),
|
||||
String.valueOf(plugin.getDescription().getAuthors()),
|
||||
String.valueOf(plugin.getDescription().getDepend()),
|
||||
String.valueOf(plugin.getDescription().getSoftDepend()),
|
||||
String.valueOf(plugin.getDescription().getMain()),
|
||||
String.valueOf(plugin.getDescription().getVersion()),
|
||||
String.valueOf(plugin.getDescription().getWebsite()),
|
||||
String.valueOf(plugin.getDescription().getCommands() == null ? "" : plugin.getDescription().getCommands().keySet()));
|
||||
} catch (Exception e) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INVALID-DESCRIPTION", name, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 5)
|
||||
BaseSubCommand list = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TPLUGIN.LIST.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
List<String> pluginList = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(PluginUtils::getFormattedName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList());
|
||||
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LIST.LIST-PLUGIN", String.valueOf(Bukkit.getPluginManager().getPlugins().length), Joiner.on(", ").join(pluginList));
|
||||
}
|
||||
};
|
||||
|
||||
// *********************************
|
||||
//
|
||||
// Private Methods
|
||||
//
|
||||
// *********************************
|
||||
|
||||
private boolean isPluginCommand(String label) {
|
||||
return "info".equalsIgnoreCase(label) || "load".equalsIgnoreCase(label) || "unload".equalsIgnoreCase(label) || "reload".equalsIgnoreCase(label);
|
||||
}
|
||||
}
|
||||
@@ -86,12 +86,8 @@ public class SimpleI18n {
|
||||
return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", ""));
|
||||
}
|
||||
|
||||
private static void releaseLocales(Plugin plugin) {
|
||||
TLocaleLoader.getLocalePriority().stream().filter(localeName -> !new File("plugins/TabooLib/simpleI18n/" + getVersion() + "/" + localeName + ".yml").exists() && plugin.getResource("simpleI18n/" + getVersion() + "/" + localeName + ".yml") != null).forEach(localeName -> plugin.saveResource("simpleI18n/" + getVersion() + "/" + localeName + ".yml", true));
|
||||
}
|
||||
|
||||
private static File getLocaleFile(Plugin plugin) {
|
||||
releaseLocales(plugin);
|
||||
TLocaleLoader.getLocalePriority().forEach(localeName -> Files.releaseResource(plugin, "simpleI18n/" + getVersion() + "/" + localeName + ".yml", false));
|
||||
return TLocaleLoader.getLocalePriority().stream().map(localeName -> new File("plugins/TabooLib/simpleI18n/" + getVersion() + "/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class Files {
|
||||
public static void releaseResource(Plugin plugin, String path, boolean replace) {
|
||||
File file = new File(plugin.getDataFolder(), path);
|
||||
if (!file.exists() || replace) {
|
||||
try (InputStream inputStream = getCanonicalResource(plugin, path)) {
|
||||
try (InputStream inputStream = getCanonicalResource(plugin, (plugin instanceof InternalPlugin ? "__resources__/" : "") + path)) {
|
||||
if (inputStream != null) {
|
||||
toFile(inputStream, Files.file(file));
|
||||
}
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
package io.izzel.taboolib.util.lite;
|
||||
|
||||
import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.module.command.base.BaseCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseMainCommand;
|
||||
import io.izzel.taboolib.module.command.base.BaseSubCommand;
|
||||
import io.izzel.taboolib.module.command.base.Argument;
|
||||
import io.izzel.taboolib.module.command.base.SubCommand;
|
||||
import io.izzel.taboolib.util.Files;
|
||||
import io.izzel.taboolib.util.Strings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
*/
|
||||
@BaseCommand(
|
||||
name = "tLogs",
|
||||
permission = "taboolib.admin"
|
||||
)
|
||||
public class Logs extends BaseMainCommand {
|
||||
|
||||
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public String getCommandTitle() {
|
||||
return TLocale.asString("COMMANDS.TLOGS.COMMAND-TITLE");
|
||||
}
|
||||
|
||||
@SubCommand(priority = 0)
|
||||
BaseSubCommand info = new BaseSubCommand() {
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TLOGS.INFO.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TLOGS.INFO.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TLOGS.INFO.ARGUMENTS.1"))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
info(args[0], args[1]);
|
||||
if (sender instanceof Player) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOGS.INFO.SUCCESS");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 1)
|
||||
BaseSubCommand error = new BaseSubCommand() {
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "error";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TLOGS.ERROR.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TLOGS.ERROR.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TLOGS.ERROR.ARGUMENTS.1"))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
info(args[0], args[1]);
|
||||
if (sender instanceof Player) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOGS.ERROR.SUCCESS");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@SubCommand(priority = 2)
|
||||
BaseSubCommand warning = new BaseSubCommand() {
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "warning";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TLOGS.WARNING.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[] {
|
||||
new Argument(TLocale.asString("COMMANDS.TLOGS.WARNING.ARGUMENTS.0")),
|
||||
new Argument(TLocale.asString("COMMANDS.TLOGS.WARNING.ARGUMENTS.1"))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
info(args[0], args[1]);
|
||||
if (sender instanceof Player) {
|
||||
TLocale.sendTo(sender, "COMMANDS.TLOGS.WARNING.SUCCESS");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void info(String filePath, String text) {
|
||||
info(new File(!filePath.contains(".") ? filePath + ".txt" : filePath), text);
|
||||
}
|
||||
|
||||
public static void info(File file, String text) {
|
||||
write(file, "[{0} INFO]: {1}\n", text);
|
||||
}
|
||||
|
||||
public static void error(String filePath, String text) {
|
||||
info(new File(!filePath.contains(".") ? filePath + ".txt" : filePath), text);
|
||||
}
|
||||
|
||||
public static void error(File file, String text) {
|
||||
write(file, "[{0} ERROR]: {1}\n", text);
|
||||
}
|
||||
|
||||
public static void warning(String filePath, String text) {
|
||||
info(new File(!filePath.contains(".") ? filePath + ".txt" : filePath), text);
|
||||
}
|
||||
|
||||
public static void warning(File file, String text) {
|
||||
write(file, "[{0} WARNING]: {1}\n", text);
|
||||
}
|
||||
|
||||
public static void write(File file, String format, String text) {
|
||||
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> {
|
||||
try (FileWriter writer = new FileWriter(Files.file(file), true)) {
|
||||
writer.write(Strings.replaceWithOrder(format, dateFormat.format(System.currentTimeMillis()), text));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user