Minor fix

This commit is contained in:
Carlos
2020-03-14 12:03:36 +01:00
parent 39b4ea5592
commit d1e1909e49
2 changed files with 47 additions and 42 deletions

View File

@ -1,36 +1,41 @@
package com.mesacarlos.webconsole.websocket.command;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import org.bukkit.Bukkit;
import org.java_websocket.WebSocket;
import com.mesacarlos.webconsole.util.Internationalization;
import com.mesacarlos.webconsole.websocket.WSServer;
import com.mesacarlos.webconsole.websocket.response.ConsoleOutput;
public class ReadLogFileCommand implements WSCommand{
@Override
public void execute(WSServer wsServer, WebSocket conn, String params) {
List<String> lines = null;
try {
lines = Files.readAllLines(Paths.get("logs/latest.log"), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
if(lines == null) {
Bukkit.getLogger().info(Internationalization.getPhrase("log-read-error"));
return;
}
for(String line : lines)
wsServer.sendToClient(conn, new ConsoleOutput(line));
}
package com.mesacarlos.webconsole.websocket.command;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import org.bukkit.Bukkit;
import org.java_websocket.WebSocket;
import com.mesacarlos.webconsole.util.Internationalization;
import com.mesacarlos.webconsole.websocket.WSServer;
import com.mesacarlos.webconsole.websocket.response.ConsoleOutput;
public class ReadLogFileCommand implements WSCommand{
@Override
public void execute(WSServer wsServer, WebSocket conn, String params) {
List<String> lines = null;
try {
lines = Files.readAllLines(Paths.get("logs/latest.log"), StandardCharsets.UTF_8);
} catch (IOException e) {
try {
lines = Files.readAllLines(Paths.get("logs/latest.log"), StandardCharsets.ISO_8859_1);
}catch(IOException ex) {
ex.printStackTrace();
}
}
if(lines == null) {
Bukkit.getLogger().info(Internationalization.getPhrase("log-read-error"));
return;
}
for(String line : lines)
wsServer.sendToClient(conn, new ConsoleOutput(line));
}
}