Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
660c3c3098
|
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.sophiaatkinson</groupId>
|
<groupId>com.sophiaatkinson</groupId>
|
||||||
<artifactId>PronounsPlaceholder</artifactId>
|
<artifactId>PronounsPlaceholder</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>PronounsPlaceholder</name>
|
<name>PronounsPlaceholder</name>
|
||||||
|
@ -10,6 +10,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -18,6 +19,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public class PronounsPlugin extends JavaPlugin {
|
public class PronounsPlugin extends JavaPlugin {
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
private boolean usingMySQL;
|
||||||
private List<String> blockedPronouns;
|
private List<String> blockedPronouns;
|
||||||
private List<String> pronounSuggestions;
|
private List<String> pronounSuggestions;
|
||||||
private final List<String> errorLog = new ArrayList<>();
|
private final List<String> errorLog = new ArrayList<>();
|
||||||
@ -53,15 +55,27 @@ public class PronounsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initDatabase() {
|
private void initDatabase() {
|
||||||
try {
|
usingMySQL = getConfig().getBoolean("mysql.enabled", false);
|
||||||
File dbFile = new File(getDataFolder(), "pronouns.db");
|
|
||||||
if (!getDataFolder().exists()) getDataFolder().mkdirs();
|
|
||||||
|
|
||||||
String url = "jdbc:sqlite:" + dbFile.getAbsolutePath();
|
try {
|
||||||
connection = DriverManager.getConnection(url);
|
if (usingMySQL) {
|
||||||
|
String host = getConfig().getString("mysql.host");
|
||||||
|
int port = getConfig().getInt("mysql.port");
|
||||||
|
String database = getConfig().getString("mysql.database");
|
||||||
|
String user = getConfig().getString("mysql.user");
|
||||||
|
String password = getConfig().getString("mysql.password");
|
||||||
|
|
||||||
|
String url = "jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false&autoReconnect=true";
|
||||||
|
connection = DriverManager.getConnection(url, user, password);
|
||||||
|
} else {
|
||||||
|
File dbFile = new File(getDataFolder(), "pronouns.db");
|
||||||
|
if (!getDataFolder().exists()) getDataFolder().mkdirs();
|
||||||
|
String url = "jdbc:sqlite:" + dbFile.getAbsolutePath();
|
||||||
|
connection = DriverManager.getConnection(url);
|
||||||
|
}
|
||||||
|
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS pronouns (uuid TEXT PRIMARY KEY, pronouns TEXT);");
|
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS pronouns (uuid VARCHAR(36) PRIMARY KEY, pronouns TEXT);");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
errorLog.add("Database initialization error: " + e.getMessage());
|
errorLog.add("Database initialization error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -81,9 +95,7 @@ public class PronounsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (String blocked : blockedPronouns) {
|
for (String blocked : blockedPronouns) {
|
||||||
if (pronouns.contains(blocked)) {
|
if (pronouns.contains(blocked)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try (PreparedStatement ps = connection.prepareStatement("REPLACE INTO pronouns (uuid, pronouns) VALUES (?, ?)")) {
|
try (PreparedStatement ps = connection.prepareStatement("REPLACE INTO pronouns (uuid, pronouns) VALUES (?, ?)")) {
|
||||||
@ -91,6 +103,18 @@ public class PronounsPlugin extends JavaPlugin {
|
|||||||
ps.setString(2, pronouns);
|
ps.setString(2, pronouns);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// Fallback for MySQL since REPLACE INTO isn't ideal for all cases
|
||||||
|
if (usingMySQL) {
|
||||||
|
try (PreparedStatement ps = connection.prepareStatement("INSERT INTO pronouns (uuid, pronouns) VALUES (?, ?) ON DUPLICATE KEY UPDATE pronouns = VALUES(pronouns)")) {
|
||||||
|
ps.setString(1, uuid.toString());
|
||||||
|
ps.setString(2, pronouns);
|
||||||
|
ps.executeUpdate();
|
||||||
|
return;
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
errorLog.add("MySQL upsert error: " + ex.getMessage());
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
errorLog.add("Database update error: " + e.getMessage());
|
errorLog.add("Database update error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -109,18 +133,18 @@ public class PronounsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public Map<UUID, String> getAllPronouns() {
|
public Map<UUID, String> getAllPronouns() {
|
||||||
Map<UUID, String> result = new java.util.HashMap<>();
|
Map<UUID, String> result = new HashMap<>();
|
||||||
try (Statement stmt = connection.createStatement()) {
|
try (Statement stmt = connection.createStatement()) {
|
||||||
ResultSet rs = stmt.executeQuery("SELECT uuid, pronouns FROM pronouns");
|
ResultSet rs = stmt.executeQuery("SELECT uuid, pronouns FROM pronouns");
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
result.put(UUID.fromString(rs.getString("uuid")), rs.getString("pronouns"));
|
result.put(UUID.fromString(rs.getString("uuid")), rs.getString("pronouns"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
errorLog.add("Database fetch all error: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
return result;
|
||||||
errorLog.add("Database fetch all error: " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateDebugFile() {
|
public void generateDebugFile() {
|
||||||
@ -133,6 +157,7 @@ public Map<UUID, String> getAllPronouns() {
|
|||||||
writer.write("=== PronounsPlugin Debug Report ===\n");
|
writer.write("=== PronounsPlugin Debug Report ===\n");
|
||||||
writer.write("Plugin Enabled: " + isEnabled() + "\n");
|
writer.write("Plugin Enabled: " + isEnabled() + "\n");
|
||||||
writer.write("Database Connected: " + (connection != null) + "\n");
|
writer.write("Database Connected: " + (connection != null) + "\n");
|
||||||
|
writer.write("Using MySQL: " + usingMySQL + "\n");
|
||||||
writer.write("Blocked Pronouns: " + blockedPronouns + "\n");
|
writer.write("Blocked Pronouns: " + blockedPronouns + "\n");
|
||||||
writer.write("Pronoun Suggestions: " + pronounSuggestions + "\n");
|
writer.write("Pronoun Suggestions: " + pronounSuggestions + "\n");
|
||||||
writer.write("Error Log:\n");
|
writer.write("Error Log:\n");
|
||||||
|
@ -27,12 +27,18 @@ debug: true
|
|||||||
|
|
||||||
generate-debug-file: true
|
generate-debug-file: true
|
||||||
|
|
||||||
database:
|
mysql:
|
||||||
use-sqlite: true
|
enabled: false # Setting to false uses SQLite
|
||||||
|
host: localhost
|
||||||
|
port: 3306
|
||||||
|
database: example
|
||||||
|
user: example
|
||||||
|
password: example
|
||||||
|
|
||||||
admin-permissions:
|
admin-permissions:
|
||||||
- "pronouns.admin"
|
- "pronouns.admin"
|
||||||
- "pronouns.override"
|
- "pronouns.override"
|
||||||
|
- "pronouns.reload"
|
||||||
|
|
||||||
player-permissions:
|
player-permissions:
|
||||||
- "pronouns.set"
|
- "pronouns.set"
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
name: PronounsPlaceholder
|
name: PronounsPlaceholder
|
||||||
version: 1.0.2
|
version: 1.0.3
|
||||||
main: com.sophiaatkinson.pronouns.PronounsPlugin
|
main: com.sophiaatkinson.pronouns.PronounsPlugin
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
|
authors: [Sophia Atkinson]
|
||||||
|
website: https://sophia.wtf
|
||||||
commands:
|
commands:
|
||||||
pronouns:
|
pronouns:
|
||||||
description: Manage pronouns for players
|
description: Manage pronouns for players
|
||||||
@ -19,6 +21,9 @@ commands:
|
|||||||
pronouns.admin:
|
pronouns.admin:
|
||||||
description: Allows admin to list, set, remove pronouns
|
description: Allows admin to list, set, remove pronouns
|
||||||
default: op
|
default: op
|
||||||
|
pronouns.reload:
|
||||||
|
description: Reloads plugin configuration
|
||||||
|
default: op
|
||||||
aliases:
|
aliases:
|
||||||
- mypronouns
|
- mypronouns
|
||||||
- setpronouns
|
- setpronouns
|
||||||
|
Reference in New Issue
Block a user