Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Rising Darkness

#1
Hallo,

ich bekomme in meinem Sourcecode durch den Bot einen NullPointerException.
Ich weiß nicht mehr weiter, darum dachte ich, ich frag mal hier:
Fehler:
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1535)
at java.lang.ClassLoader.getClassLoadingLock(ClassLoader.java:463)
at java.lang.ClassLoader.loadClass(ClassLoader.java:404)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at de.stefan1200.jts3servermod.JTS3ServerMod.d(Unknown Source)
at de.stefan1200.jts3servermod.JTS3ServerMod.b(Unknown Source)
at de.stefan1200.jts3servermod.JTS3ServerMod.b(Unknown Source)
at de.stefan1200.jts3servermod.h.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)


Das geschriebene Plugin:
package de.mightful_noobs.Voting;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Vector;

import de.stefan1200.jts3servermod.BotConfigurationException;
import de.stefan1200.jts3servermod.FunctionExceptionLog;
import de.stefan1200.jts3servermod.interfaces.HandleBotEvents;
import de.stefan1200.jts3servermod.interfaces.HandleClientList;
import de.stefan1200.jts3servermod.interfaces.JTS3ServerMod_Interface;
import de.stefan1200.jts3servermod.interfaces.LoadConfiguration;
import de.stefan1200.jts3serverquery.JTS3ServerQuery;
import de.stefan1200.jts3serverquery.TS3ServerQueryException;
import de.stefan1200.util.ArrangedPropertiesWriter;

public class Voting implements HandleBotEvents, LoadConfiguration, HandleClientList {

public static void main(String[] args) {
}

private JTS3ServerMod_Interface modClass = null;
private JTS3ServerQuery queryLib = null;
private String configPrefix = "";
private boolean pluginEnabled = false;

private Vector<Integer> clientList = new Vector<Integer>();
private FunctionExceptionLog fel = new FunctionExceptionLog();
private String sgid = "";
private String key = "";
private String message = "";
private boolean firstInit = true;

@Override
public void initClass(JTS3ServerMod_Interface modClass, JTS3ServerQuery queryLib, String prefix) {
this.modClass = modClass;
this.queryLib = queryLib;
configPrefix = prefix.trim();
}

public void initConfig(ArrangedPropertiesWriter config) {
config.addKey(configPrefix + "_sgid", "Servergroup-ID?");
config.addKey(configPrefix + "_key", "API-Key");
config.addKey(configPrefix + "_message", "Voting Message");
}

@Override
public void handleOnBotConnect() {
if (!pluginEnabled) {
return;
}
String msg = "Voting is enabled. Servergroup: " + sgid.toString() + " API-Key: " + key.toString();
modClass.addLogEntry(configPrefix, JTS3ServerMod_Interface.ERROR_LEVEL_INFO, msg, true);
}

@Override
public void handleAfterCacheUpdate() {
if (!pluginEnabled) {
return;
}
}

@Override
public void activate() {
if (!pluginEnabled) {
return;
}
}

@Override
public void disable() {
if (!pluginEnabled) {
return;
}
}

@Override
public void unload() {
message = null;
clientList = null;
}

@Override
public boolean multipleInstances() {
return false;
}

@Override
public int getAPIBuild() {
return 0;
}

@Override
public String getCopyright() {
return "Voting function v1.0 (27.01.2019) created by Sascha Moser (Rising Darkness), [url]http://mightful-noobs.de[/url]";
}

public boolean loadConfig(ArrangedPropertiesWriter config, boolean slowMode)
throws BotConfigurationException, NumberFormatException {
String temp = null;
pluginEnabled = false;
try {
temp = null;
clientList.clear();
temp = config.getValue(configPrefix + "_sgid");
if (temp == null) {
throw new NumberFormatException();
}
sgid = configPrefix + "_time";
temp = config.getValue(configPrefix + "_key");
if (temp == null) {
throw new NullPointerException();
}
key = temp;
temp = config.getValue(configPrefix + "_message");
if (temp == null) {
throw new NullPointerException();
}
message = temp;
pluginEnabled = true;
} catch (NumberFormatException e) {
NumberFormatException nfe = new NumberFormatException("Config value of \"" + temp
+ "\" is not a number! Current value: " + config.getValue(temp, "not set"));
nfe.setStackTrace(e.getStackTrace());
throw nfe;
}
return pluginEnabled;
}

public void handleClientCheck(Vector<HashMap<String, String>> clientList) {
if (!pluginEnabled) {
return;
}
if (firstInit) {
firstInit = false;
}

// Go through the whole client list
for (HashMap<String, String> clientInfo : clientList) {
// Check real Teamspeak 3 clients only, ignore query clients
String clientNickname = clientInfo.get("client_nickname");
String clientDbId = clientInfo.get("client_database_id");
int clientId = Integer.parseInt(clientInfo.get("clid"));
if (clientInfo.get("client_type").equals("0") && clientDbId == "2") {
// Parse the client id as int
int hasVoted = 0;
try {
hasVoted = checkVote(clientNickname, clientDbId, clientId);
switch (hasVoted) {
case 0:
break;
case 1:
try {
int claim = setClaim(clientNickname, clientDbId, clientId);
} catch (Exception e) {
e.printStackTrace();
}
break;
case 2:
break;
default:
break;
}
} catch (Exception e1) {
e1.printStackTrace();
}

fel.clearException(Integer.parseInt(clientInfo.get("client_database_id")));
}
}
}

public int checkVote(String clientNickname, String clientDbId, int clientId) throws Exception {
int check = 0;
try {
String url = "https://teamspeak-servers.org/api/?object=votes&element=claim&key=" + key + "&username="
+ clientNickname.replace(" ", "%20");
check = Integer.valueOf(URLReader(url));
} catch (Exception e) {
Exception nfe = new Exception("Couldn't open URL");
nfe.setStackTrace(e.getStackTrace());
throw nfe;
}
return check;
}

public int setClaim(String clientNickname, String clientDbId, int clientId) throws Exception {
int claim = 0;
try {
String url = "https://teamspeak-servers.org/api/?action=post&element=claim&key=" + key + "&username="
+ clientNickname.replace(" ", "%20");
modClass.addLogEntry(configPrefix, JTS3ServerMod_Interface.ERROR_LEVEL_INFO, url, true);
claim = Integer.valueOf(URLReader(url));
setServerGroup(clientNickname, clientDbId, clientId);
} catch (Exception e) {
Exception nfe = new Exception("Couldn't open URL");
nfe.setStackTrace(e.getStackTrace());
throw nfe;
}
return claim;
}

public void setServerGroup(String clientNickname, String clientDbId, int clientId) {
String msg = "Servergruppe  zu " + clientNickname + " hinzugefügt";
try {
queryLib.doCommand("servergroupaddclient sgid=" + sgid + " cldbid=" + clientId);
queryLib.sendTextMessage(clientId, JTS3ServerQuery.TEXTMESSAGE_TARGET_CLIENT, message);
modClass.addLogEntry(configPrefix, JTS3ServerMod_Interface.ERROR_LEVEL_INFO, msg, true);
fel.clearException(Integer.parseInt(clientDbId));
} catch (TS3ServerQueryException sqe) {
// This prevents flooding the log file with error messages, if a missing
// permission of the bot account on the Teamspeak 3 server is missing.
if (!fel.existsException(sqe, Integer.parseInt(clientDbId))) {
// Since there is no saved TS3ServerQueryException for this client, save it now.
fel.addException(sqe, Integer.parseInt(clientDbId));

// Adding error message to the bot log.
modClass.addLogEntry(configPrefix, JTS3ServerMod_Interface.ERROR_LEVEL_ERROR,
"Cannot send chat command answer to client \"" + clientNickname + "\" (db id: " + clientId
+ "), an error occurred while sending message to client!",
false);
modClass.addLogEntry(configPrefix, sqe, false);
}
}
}

public String URLReader(String strUrl) throws Exception {

URLConnection connection = new URL(strUrl).openConnection();
connection.setRequestProperty("User-Agent", "Java/8+(compatible; Voting-Addon; https://mightful-noobs.de/)");
connection.connect();

BufferedReader r = new BufferedReader(
new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));

StringBuilder sb = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
sb.append(line);
}
// System.out.println(sb.toString());
return sb.toString();
}

@Override
public void setListModes(BitSet listOptions) {
listOptions.set(1);
listOptions.set(4);
}
}


Vielleicht fehlts mir auch an Logik.