Fixing a shit ton of warning / code style and stuff (code inspector from IDEA)

This commit is contained in:
2022-07-10 00:55:56 +02:00
parent 276b1d323a
commit b6104a76c1
118 changed files with 1116 additions and 1574 deletions

View File

@@ -1,7 +1,6 @@
package fr.pandacube.lib.cli;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -22,16 +21,14 @@ import fr.pandacube.lib.core.util.Log;
import fr.pandacube.lib.core.util.Reflect;
public abstract class BrigadierCommand extends ChatStatic {
private LiteralCommandNode<Object> commandNode;
public BrigadierCommand() {
LiteralArgumentBuilder<Object> builder = buildCommand();
String[] aliases = getAliases();
if (aliases == null)
aliases = new String[0];
commandNode = BrigadierDispatcher.instance.register(builder);
LiteralCommandNode<Object> commandNode = BrigadierDispatcher.instance.register(builder);
for (String alias : aliases) {
@@ -94,16 +91,14 @@ public abstract class BrigadierCommand extends ChatStatic {
String message = builder.getInput();
try {
int tokenStartPos = builder.getStart();
List<String> results = Collections.emptyList();
int firstSpacePos = message.indexOf(" ");
String[] args = (firstSpacePos + 1 > tokenStartPos - 1) ? new String[0]
: message.substring(firstSpacePos + 1, tokenStartPos - 1).split(" ", -1);
args = Arrays.copyOf(args, args.length + 1);
args[args.length - 1] = message.substring(tokenStartPos);
results = suggestions.getSuggestions(sender, args.length - 1, args[args.length - 1], args);
List<String> results = suggestions.getSuggestions(sender, args.length - 1, args[args.length - 1], args);
for (String s : results) {
if (s != null)

View File

@@ -31,9 +31,9 @@ public class BrigadierDispatcher implements Completer {
private CommandDispatcher<Object> dispatcher;
private final CommandDispatcher<Object> dispatcher;
private Object sender = new Object();
private final Object sender = new Object();
public BrigadierDispatcher() {
dispatcher = new CommandDispatcher<>();
@@ -69,7 +69,9 @@ public class BrigadierDispatcher implements Completer {
Suggestions completeResult = getSuggestions(bufferBeforeCursor);
completeResult.getList().stream().map(s -> s.getText()).forEach(candidates::add);
completeResult.getList().stream()
.map(Suggestion::getText)
.forEach(candidates::add);
return completeResult.getRange().getStart();
}

View File

@@ -38,8 +38,8 @@ public class CLI {
private ConsoleReader reader;
private Logger logger;
private final ConsoleReader reader;
private final Logger logger;
public CLI() throws IOException {
@@ -78,9 +78,7 @@ public class CLI {
if (line.trim().equals(""))
continue;
String cmdLine = line;
new Thread(() -> {
BrigadierDispatcher.instance.execute(cmdLine);
}, "CLICmdThread #"+(i++)).start();
new Thread(() -> BrigadierDispatcher.instance.execute(cmdLine), "CLICmdThread #"+(i++)).start();
}
} catch (IOException e) {

View File

@@ -12,9 +12,9 @@ import java.util.logging.Handler;
import java.util.logging.LogRecord;
class DailyLogRotateFileHandler extends Handler {
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private BufferedWriter currentFile = null;
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private String currentFileDate = getCurrentDay();
private boolean closed = false;
@@ -24,7 +24,7 @@ class DailyLogRotateFileHandler extends Handler {
closed = true;
if (currentFile != null) try {
currentFile.close();
} catch (IOException e) {}
} catch (IOException ignored) {}
}
@Override
@@ -33,7 +33,7 @@ class DailyLogRotateFileHandler extends Handler {
if (currentFile == null) return;
try {
currentFile.flush();
} catch (IOException e) {}
} catch (IOException ignored) {}
}
@Override
@@ -68,7 +68,7 @@ class DailyLogRotateFileHandler extends Handler {
try {
currentFile.flush();
currentFile.close();
} catch (IOException e) {}
} catch (IOException ignored) {}
new File("logs/latest.log").renameTo(new File("logs/" + currentFileDate + ".log"));
}
@@ -76,11 +76,10 @@ class DailyLogRotateFileHandler extends Handler {
try {
File logDir = new File("logs");
logDir.mkdir();
currentFile = new BufferedWriter(new FileWriter(new File("logs/latest.log"), true));
currentFile = new BufferedWriter(new FileWriter("logs/latest.log", true));
} catch (SecurityException | IOException e) {
reportError("Erreur lors de l'initialisation d'un fichier log", e, ErrorManager.OPEN_FAILURE);
currentFile = null;
return;
}
}