Skip to content

Commit

Permalink
Merge pull request #84 from MultiChat/v1-8
Browse files Browse the repository at this point in the history
Version 1.8.1
  • Loading branch information
OllieMartin authored Apr 9, 2020
2 parents 62d7a94 + c75d494 commit 1a5bd63
Show file tree
Hide file tree
Showing 30 changed files with 231 additions and 130 deletions.
2 changes: 1 addition & 1 deletion multichat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>xyz.olivermartin.multichat</groupId>
<artifactId>multichat</artifactId>
<version>1.8</version>
<version>1.8.1</version>

<repositories>

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void sendMessage(ProxiedPlayer sender, String message, String format) {

for (ProxiedPlayer receiver : ProxyServer.getInstance().getPlayers()) {

if (receiver != null) {
if (receiver != null && sender != null) {

synchronized (receiver) {

Expand Down Expand Up @@ -172,6 +172,14 @@ public void sendMessage(ProxiedPlayer sender, String message, String format) {

}

} else {

DebugManager.log("NULL POINTER WAS DETECTED CHECKS!");
DebugManager.log("< START >");
DebugManager.log(sender != null ? sender.getName() : "SENDER NULL");
DebugManager.log(receiver != null ? receiver.getUniqueId().toString() : "RECEIVER NULL");
DebugManager.log("< / END >");

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ public void onChat(ChatEvent event) {
message = ChatControl.replaceLinks(message);
event.setMessage(message);
}

DebugManager.log("NULL POINTER CHECKS!");
DebugManager.log("< START >");
DebugManager.log(player.getName());
DebugManager.log(player.getUniqueId().toString());
DebugManager.log(Channel.getChannel(player.getUniqueId()).getName());
DebugManager.log(player.getServer().getInfo().getName());
DebugManager.log("< / END >");

// Let server know players channel preference
BungeeComm.sendPlayerChannelMessage(player.getName(), Channel.getChannel(player.getUniqueId()).getName(), Channel.getChannel(player.getUniqueId()), player.getServer().getInfo(), (player.hasPermission("multichat.chat.colour")||player.hasPermission("multichat.chat.color")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@
*/
public class MultiChat extends Plugin implements Listener {

public static final String LATEST_VERSION = "1.8";
public static final String LATEST_VERSION = "1.8.1";

public static final String[] ALLOWED_VERSIONS = new String[] {

LATEST_VERSION,
"1.8",
"1.7.5",
"1.7.4",
"1.7.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private DatabaseManager() {
////////////

public static void main(String args[]) throws SQLException {

DatabaseManager.getInstance().setPathSQLite(new File("C:\\multichat\\db\\"));
DatabaseManager.getInstance().createDatabase("multichat.db");

Expand All @@ -52,31 +52,31 @@ public static void main(String args[]) throws SQLException {

try {
db.connectToDatabase();
db.execute("DROP TABLE IF EXISTS name_data;");
db.execute("DROP TABLE IF EXISTS nick_data;");

db.update("CREATE TABLE IF NOT EXISTS name_data(id VARCHAR(128), f_name VARCHAR(255), u_name VARCHAR(255), PRIMARY KEY (id));");
db.update("CREATE TABLE IF NOT EXISTS nick_data(id VARCHAR(128), u_nick VARCHAR(255), f_nick VARCHAR(255), PRIMARY KEY (id));");
db.update("INSERT INTO name_data VALUES ('" + uuid1.toString() + "', 'Revilo410', 'revilo410');");
db.update("INSERT INTO nick_data VALUES ('" + uuid1.toString() + "', '&3Revi', 'revi');");
db.update("INSERT INTO name_data VALUES ('" + uuid2.toString() + "', 'Revilo510', 'revilo510');");
ResultSet results = db.query("SELECT * FROM name_data;");
db.safeExecute("DROP TABLE IF EXISTS name_data;");
db.safeExecute("DROP TABLE IF EXISTS nick_data;");

db.safeUpdate("CREATE TABLE IF NOT EXISTS name_data(id VARCHAR(128), f_name VARCHAR(255), u_name VARCHAR(255), PRIMARY KEY (id));");
db.safeUpdate("CREATE TABLE IF NOT EXISTS nick_data(id VARCHAR(128), u_nick VARCHAR(255), f_nick VARCHAR(255), PRIMARY KEY (id));");

db.safeUpdate("INSERT INTO name_data VALUES (?, 'Revilo410', 'revilo410');", uuid1.toString());
db.safeUpdate("INSERT INTO nick_data VALUES (?, '&3Revi', 'revi');", uuid1.toString());
db.safeUpdate("INSERT INTO name_data VALUES (?, 'Revilo510', 'revilo510');", uuid2.toString());
ResultSet results = db.safeQuery("SELECT * FROM name_data;");
while (results.next()) {
System.out.println(results.getString("id"));
}
results = db.query("SELECT * FROM nick_data;");

results = db.safeQuery("SELECT * FROM nick_data;");
while (results.next()) {
System.out.println(results.getString("id"));
}
results = db.query("SELECT * FROM name_data INNER JOIN nick_data ON name_data.id = nick_data.id;");

results = db.safeQuery("SELECT * FROM name_data INNER JOIN nick_data ON name_data.id = nick_data.id;");
while (results.next()) {
System.out.println(results.getString("id"));
}
results = db.query("SELECT * FROM name_data LEFT JOIN nick_data ON name_data.id = nick_data.id;");

results = db.safeQuery("SELECT * FROM name_data LEFT JOIN nick_data ON name_data.id = nick_data.id;");
while (results.next()) {
System.out.println(results.getString("id"));
if (results.getString("f_nick") == null) {
Expand All @@ -85,21 +85,21 @@ public static void main(String args[]) throws SQLException {
System.out.println(results.getString("f_nick"));
}
}
results = db.query("SELECT f_name, f_nick FROM name_data LEFT JOIN nick_data ON name_data.id = nick_data.id WHERE name_data.id = '" + uuid1.toString() + "';");

results = db.safeQuery("SELECT f_name, f_nick FROM name_data LEFT JOIN nick_data ON name_data.id = nick_data.id WHERE name_data.id = ?;", uuid1.toString());
while (results.next()) {
if (results.getString("f_nick") == null) {
System.out.println(results.getString("f_name"));
} else {
System.out.println(results.getString("f_nick"));
}
}

db.disconnectFromDatabase();
} catch (SQLException e) {
e.printStackTrace();
}

}

/*DatabaseManager.getInstance().setPathSQLite(new File("C:\\multichat\\db\\"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public abstract class GenericDatabase {

protected String url;
private boolean ready;

protected String username;
protected String password;

public GenericDatabase(String url) throws SQLException {
this.url = url;
ready = setupDatabase(url);
}

public GenericDatabase(String url, String user, String pass) throws SQLException {
this.url = url;
this.username = user;
Expand All @@ -37,11 +37,17 @@ public boolean isReady() {

protected abstract boolean connect() throws SQLException;

public abstract ResultSet query(String sql) throws SQLException;
public abstract ResultSet safeQuery(String sqlTemplate, String... stringParameters) throws SQLException;

public abstract void safeUpdate(String sqlTemplate, String... stringParameters) throws SQLException;

public abstract void safeExecute(String sqlTemplate, String... stringParameters) throws SQLException;

//public abstract ResultSet query(String sql) throws SQLException;

//public abstract void update(String sql) throws SQLException;

public abstract void update(String sql) throws SQLException;

public abstract void execute(String sql) throws SQLException;
//public abstract void execute(String sql) throws SQLException;

public void connectToDatabase() throws SQLException {
this.ready = connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

Expand Down Expand Up @@ -70,7 +71,7 @@ protected boolean connect() throws SQLException {
return true;
}

@Override
/*@Override
public ResultSet query(String sql) throws SQLException {
ResultSet results = conn.createStatement().executeQuery(sql);
Expand All @@ -90,8 +91,47 @@ public void execute(String sql) throws SQLException {
conn.createStatement().execute(sql);
}*/

@Override
public ResultSet safeQuery(String sqlTemplate, String... stringParameters) throws SQLException {

PreparedStatement p = conn.prepareStatement(sqlTemplate);

for (int i = 1; i <= stringParameters.length; i++) {
p.setString(i, stringParameters[i-1]);
}

ResultSet results = p.executeQuery();

return results;

}

@Override
public void safeUpdate(String sqlTemplate, String... stringParameters) throws SQLException {

PreparedStatement p = conn.prepareStatement(sqlTemplate);

for (int i = 1; i <= stringParameters.length; i++) {
p.setString(i, stringParameters[i-1]);
}

p.executeUpdate();

}

@Override
public void safeExecute(String sqlTemplate, String... stringParameters) throws SQLException {

PreparedStatement p = conn.prepareStatement(sqlTemplate);

for (int i = 1; i <= stringParameters.length; i++) {
p.setString(i, stringParameters[i-1]);
}

p.execute();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

Expand Down Expand Up @@ -71,7 +72,7 @@ protected boolean connect() throws SQLException {
return true;
}

@Override
/*@Override
public ResultSet query(String sql) throws SQLException {
ResultSet results = conn.createStatement().executeQuery(sql);
Expand All @@ -91,6 +92,47 @@ public void execute(String sql) throws SQLException {
conn.createStatement().execute(sql);
}*/

@Override
public ResultSet safeQuery(String sqlTemplate, String... stringParameters) throws SQLException {

PreparedStatement p = conn.prepareStatement(sqlTemplate);

for (int i = 1; i <= stringParameters.length; i++) {
p.setString(i, stringParameters[i-1]);
}

ResultSet results = p.executeQuery();

return results;

}

@Override
public void safeUpdate(String sqlTemplate, String... stringParameters) throws SQLException {

PreparedStatement p = conn.prepareStatement(sqlTemplate);

for (int i = 1; i <= stringParameters.length; i++) {
p.setString(i, stringParameters[i-1]);
}

p.executeUpdate();

}

@Override
public void safeExecute(String sqlTemplate, String... stringParameters) throws SQLException {

PreparedStatement p = conn.prepareStatement(sqlTemplate);

for (int i = 1; i <= stringParameters.length; i++) {
p.setString(i, stringParameters[i-1]);
}

p.execute();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void onEnable() {
getDataFolder().mkdirs();
configDir = getDataFolder();
}

String translationsDir = configDir.toString() + File.separator + "translations";
if (!new File(translationsDir).exists()) {
getLogger().info(logPrefix + "Creating translations directory!");
Expand All @@ -121,7 +121,7 @@ public void onEnable() {

SpigotConfigManager.getInstance().registerHandler("spigotconfig.yml", configDir);
SpigotConfigManager.getInstance().registerHandler("spigotconfig_fr.yml", new File(translationsDir));

Configuration config = SpigotConfigManager.getInstance().getHandler("spigotconfig.yml").getConfig();

if (config.contains("server_name")) {
Expand Down Expand Up @@ -183,8 +183,8 @@ public void onEnable() {
}

DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().connectToDatabase();
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().update("CREATE TABLE IF NOT EXISTS name_data(id VARCHAR(128), f_name VARCHAR(255), u_name VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().update("CREATE TABLE IF NOT EXISTS nick_data(id VARCHAR(128), u_nick VARCHAR(255), f_nick VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().safeUpdate("CREATE TABLE IF NOT EXISTS name_data(id VARCHAR(128), f_name VARCHAR(255), u_name VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().safeUpdate("CREATE TABLE IF NOT EXISTS nick_data(id VARCHAR(128), u_nick VARCHAR(255), f_nick VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().disconnectFromDatabase();

NameManager.useSQL(nicknameSQL);
Expand All @@ -207,8 +207,8 @@ public void onEnable() {
DatabaseManager.getInstance().createDatabase("multichatspigot.db");

DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().connectToDatabase();
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().update("CREATE TABLE IF NOT EXISTS name_data(id VARCHAR(128), f_name VARCHAR(255), u_name VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().update("CREATE TABLE IF NOT EXISTS nick_data(id VARCHAR(128), u_nick VARCHAR(255), f_nick VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().safeUpdate("CREATE TABLE IF NOT EXISTS name_data(id VARCHAR(128), f_name VARCHAR(255), u_name VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().safeUpdate("CREATE TABLE IF NOT EXISTS nick_data(id VARCHAR(128), u_nick VARCHAR(255), f_nick VARCHAR(255), PRIMARY KEY (id));");
DatabaseManager.getInstance().getDatabase("multichatspigot.db").get().disconnectFromDatabase();

NameManager.useSQL(nicknameSQL);
Expand Down
Loading

0 comments on commit 1a5bd63

Please sign in to comment.