Skip to content

Commit

Permalink
Only show error messages from SocketReader
Browse files Browse the repository at this point in the history
Use query.isConnected()
Fix NullPointer
  • Loading branch information
Kakifrucht committed Apr 18, 2017
1 parent 8574591 commit ea0fd75
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# Halfminer Bot
Teamspeak 3 Bot for Minecraft Server [Two and a half Miner](https://halfminer.de).
Connecting to query via [API](https://github.com/TheHolyWaffle/TeamSpeak-3-Java-API).
Connecting to query via [this API](https://github.com/TheHolyWaffle/TeamSpeak-3-Java-API).

Current features
-------
Expand All @@ -22,7 +22,7 @@ Current features
- Server join message can be disabled
- Command flood protection (optional bypass permission)
- Custom cooldowns available additionally, for example for *!channel update*
- Default command if none supplied is !channel, to make channel creation easier
- Default command if none supplied is *!channel create*, to make channel creation easier
- Permission to use command necessary
- **Commands**
- !admin
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/de/halfminer/hmbot/HalfminerBot.java
Expand Up @@ -122,7 +122,9 @@ public void onConnect(TS3Query ts3Query) {
@Override
public void onDisconnect(TS3Query ts3Query) {
logger.warn("Bot lost connection to server, trying to reconnect...");
scheduler.shutdown();
if(scheduler != null) {
scheduler.shutdown();
}
}
});

Expand Down Expand Up @@ -206,12 +208,8 @@ public void stop(String message, boolean restart) {

if (scheduler != null) scheduler.shutdown();
if (storage != null) storage.doSaveOnDisk();
if (query != null) {
try {
query.exit();
} catch (NullPointerException ignored) {
// if exiting from query without successful connect NullPointerEx is thrown, we cannot check beforehand
}
if (query != null && query.isConnected()) {
query.exit();
}

synchronized (monitor) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/halfminer/hmbot/cmd/CmdRank.java
Expand Up @@ -60,7 +60,7 @@ void run() throws InvalidCommandException {
Gson gson = new Gson();

Type type = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> GETMap = new Gson().fromJson(response.body().string(), type);
Map<String, String> GETMap = gson.fromJson(response.body().string(), type);
String rank = GETMap.get("rank");
String uuid = GETMap.get("uuid");
String ip = GETMap.get("ip");
Expand Down
10 changes: 7 additions & 3 deletions src/main/resources/log4j2.xml
Expand Up @@ -13,9 +13,13 @@
</Async>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="consoleAppender" level="debug"/>
<AppenderRef ref="asyncFileAppender" level="info"/>
<Logger name="com.github.theholywaffle.teamspeak3.SocketReader" level="debug" additivity="false">
<AppenderRef ref="consoleAppender" level="error"/>
<AppenderRef ref="asyncFileAppender" level="error"/>
</Logger>
<Root level="info">
<AppenderRef ref="consoleAppender"/>
<AppenderRef ref="asyncFileAppender"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit ea0fd75

Please sign in to comment.