Update JDK 11

This commit is contained in:
sky 2020-02-03 18:40:13 +08:00
parent 725d2899b2
commit 82d1a1b826
2 changed files with 26 additions and 16 deletions

View File

@ -18,8 +18,8 @@ import java.util.UUID;
*/ */
public class CommandBuilder { public class CommandBuilder {
public static final CompleterTab EMPTY_COMPLETER_TAB = ((sender, args) -> new ArrayList<>()); public static final CompleterCommand EMPTY_COMPLETER_COMMAND = ((sender, args) -> {
public static final CompleterCommand EMPTY_COMPLETER_COMMAND = ((sender, args) -> {}); });
private String command; private String command;
private Plugin plugin; private Plugin plugin;
@ -28,7 +28,7 @@ public class CommandBuilder {
private List<String> aliases; private List<String> aliases;
private String permission; private String permission;
private String permissionMessage; private String permissionMessage;
private CompleterTab completerTab = EMPTY_COMPLETER_TAB; private CompleterTab completerTab;
private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND; private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND;
private boolean forceRegister; private boolean forceRegister;
private boolean build; private boolean build;
@ -106,7 +106,6 @@ public class CommandBuilder {
Preconditions.checkNotNull(plugin, "缺少 \"plugin\" 部分"); Preconditions.checkNotNull(plugin, "缺少 \"plugin\" 部分");
Preconditions.checkNotNull(command, "缺少 \"command\" 部分"); Preconditions.checkNotNull(command, "缺少 \"command\" 部分");
Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分"); Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分");
Preconditions.checkNotNull(completerTab, "缺少 \"CompleterTab\" 部分");
if (forceRegister) { if (forceRegister) {
TCommandHandler.getKnownCommands().remove(command); TCommandHandler.getKnownCommands().remove(command);
} }
@ -118,18 +117,20 @@ public class CommandBuilder {
aliases, aliases,
permission, permission,
permissionMessage, permissionMessage,
(sender, command, s, args) -> { completerCommand == null ? null :
completerCommand.execute(sender, args); (sender, command, s, args) -> {
return true; completerCommand.execute(sender, args);
}, return true;
(sender, command, s, args) -> { },
try { completerTab == null ? null :
return completerTab.execute(sender, args); (sender, command, s, args) -> {
} catch (Throwable t) { try {
t.printStackTrace(); return completerTab.execute(sender, args);
} } catch (Throwable t) {
return null; t.printStackTrace();
}); }
return null;
});
build = true; build = true;
return this; return this;
} }

View File

@ -319,6 +319,15 @@ public class Files {
} }
} }
public static void write(File file, WriteHandle writeHandle, boolean append) {
try (FileWriter fileWriter = new FileWriter(file, append); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {
writeHandle.write(bufferedWriter);
bufferedWriter.flush();
} catch (Throwable t) {
t.printStackTrace();
}
}
public static void write(OutputStream out, WriteHandle writeHandle) { public static void write(OutputStream out, WriteHandle writeHandle) {
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out); BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) { try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out); BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) {
writeHandle.write(bufferedWriter); writeHandle.write(bufferedWriter);