Initial commit working?

This commit is contained in:
2025-05-07 22:46:14 -07:00
commit 2eea920d65
8 changed files with 426 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
.vscode/settings.json

Binary file not shown.

53
pom.xml Normal file
View File

@ -0,0 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sophiaatkinson</groupId>
<artifactId>PronounsPlugin</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>PronounsPlugin</name>
<properties>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.7</version>
<scope>system</scope>
<!-- Make sure this path is correct -->
<systemPath>${project.basedir}/lib/PlaceholderAPI-2.11.7-DEV-207.jar</systemPath>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,131 @@
package com.sophiaatkinson.pronouns;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
public class PronounsCommand implements CommandExecutor, TabCompleter {
private final PronounsPlugin plugin;
public PronounsCommand(PronounsPlugin plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
return true;
}
if (args.length == 0) {
player.sendMessage(ChatColor.YELLOW + "Usage: /pronouns help");
return true;
}
String subcommand = args[0].toLowerCase();
switch (subcommand) {
case "set" -> {
if (args.length < 2) {
player.sendMessage(ChatColor.RED + "Please provide your pronouns. Example: /pronouns set she/her");
return true;
}
String pronouns = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
for (String blocked : plugin.getConfig().getStringList("blocked-pronouns")) {
if (pronouns.contains(blocked)) {
player.sendMessage(ChatColor.RED + "Your pronouns contain inappropriate language and cannot be set.");
return true;
}
}
plugin.setPronouns(player.getUniqueId(), pronouns);
player.sendMessage(ChatColor.GREEN + "Your pronouns have been set to: " + ChatColor.AQUA + pronouns);
}
case "view" -> {
if (args.length == 1) {
String pronouns = plugin.getPronouns(player.getUniqueId());
if (pronouns != null) {
player.sendMessage(ChatColor.GREEN + "Your pronouns are: " + ChatColor.AQUA + pronouns);
} else {
player.sendMessage(ChatColor.YELLOW + "You haven't set your pronouns yet.");
}
} else {
Player target = Bukkit.getPlayerExact(args[1]);
if (target != null) {
String pronouns = plugin.getPronouns(target.getUniqueId());
if (pronouns != null) {
player.sendMessage(ChatColor.GREEN + target.getName() + "'s pronouns are: " + ChatColor.AQUA + pronouns);
} else {
player.sendMessage(ChatColor.YELLOW + target.getName() + " hasn't set pronouns.");
}
} else {
player.sendMessage(ChatColor.RED + "Player not found.");
}
}
}
case "reset" -> {
plugin.setPronouns(player.getUniqueId(), null); // Reset the player's pronouns
player.sendMessage(ChatColor.GREEN + "Your pronouns have been reset.");
}
case "help" -> {
player.sendMessage(ChatColor.AQUA + "=== Pronouns Plugin Help ===");
player.sendMessage(ChatColor.YELLOW + "/pronouns set <pronouns> " + ChatColor.WHITE + "- Set your pronouns");
player.sendMessage(ChatColor.YELLOW + "/pronouns view [player] " + ChatColor.WHITE + "- View your or another player's pronouns");
player.sendMessage(ChatColor.YELLOW + "/pronouns reset " + ChatColor.WHITE + "- Reset your pronouns");
player.sendMessage(ChatColor.YELLOW + "/pronouns version " + ChatColor.WHITE + "- Show plugin and server version info");
player.sendMessage(ChatColor.YELLOW + "/pronouns debug " + ChatColor.WHITE + "- Generate a debug file");
}
case "version" -> {
player.sendMessage(ChatColor.AQUA + "=== Version Info ===");
player.sendMessage(ChatColor.YELLOW + "PronounsPlugin: " + ChatColor.WHITE + plugin.getDescription().getVersion());
player.sendMessage(ChatColor.YELLOW + "Server Version: " + ChatColor.WHITE + Bukkit.getVersion());
}
case "debug" -> {
plugin.generateDebugFile();
player.sendMessage(ChatColor.GREEN + "Debug file written to plugin folder as debug.txt");
}
default -> player.sendMessage(ChatColor.RED + "Unknown subcommand. Use /pronouns help for options.");
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
return Arrays.asList("set", "view", "reset", "help", "version", "debug");
}
if (args.length == 2 && args[0].equalsIgnoreCase("view")) {
List<String> names = new ArrayList<>();
for (Player p : Bukkit.getOnlinePlayers()) {
names.add(p.getName());
}
return names;
}
if (args.length == 2 && args[0].equalsIgnoreCase("set")) {
return Arrays.asList("she/her", "he/him", "they/them", "xe/xem", "it/its");
}
return Collections.emptyList();
}
}

View File

@ -0,0 +1,40 @@
package com.sophiaatkinson.pronouns;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
public class PronounsPlaceholder extends PlaceholderExpansion {
private final PronounsPlugin plugin;
public PronounsPlaceholder(PronounsPlugin plugin) {
this.plugin = plugin;
}
@Override
public @NotNull String getIdentifier() {
return "pronounsplugin";
}
@Override
public @NotNull String getAuthor() {
return "Sophia";
}
@Override
public @NotNull String getVersion() {
return "1.0";
}
@Override
public @Nullable String onPlaceholderRequest(Player player, @NotNull String identifier) {
if (identifier.equalsIgnoreCase("pronouns")) {
String pronouns = plugin.getPronouns(player.getUniqueId());
return pronouns != null ? pronouns : "not set";
}
return null;
}
}

View File

@ -0,0 +1,133 @@
package com.sophiaatkinson.pronouns;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
public class PronounsPlugin extends JavaPlugin {
private Connection connection;
private List<String> blockedPronouns;
private List<String> pronounSuggestions;
private final List<String> errorLog = new ArrayList<>();
@Override
public void onEnable() {
getLogger().info("PronounsPlugin enabled!");
// Load blocked pronouns and pronoun suggestions from config
saveDefaultConfig();
blockedPronouns = getConfig().getStringList("blocked-pronouns");
pronounSuggestions = getConfig().getStringList("pronoun-suggestions");
// Load database
initDatabase();
// Register commands and placeholders
PronounsCommand command = new PronounsCommand(this);
getCommand("pronouns").setExecutor(command);
getCommand("pronouns").setTabCompleter(command);
new PronounsPlaceholder(this).register();
}
@Override
public void onDisable() {
try {
if (connection != null) connection.close();
} catch (SQLException e) {
errorLog.add("Database close error: " + e.getMessage());
e.printStackTrace();
}
}
private void initDatabase() {
try {
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();
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS pronouns (uuid TEXT PRIMARY KEY, pronouns TEXT);");
} catch (SQLException e) {
errorLog.add("Database initialization error: " + e.getMessage());
e.printStackTrace();
}
}
public void setPronouns(UUID uuid, String pronouns) {
for (String blocked : blockedPronouns) {
if (pronouns.contains(blocked)) {
return;
}
}
try (PreparedStatement ps = connection.prepareStatement("REPLACE INTO pronouns (uuid, pronouns) VALUES (?, ?)")) {
ps.setString(1, uuid.toString());
ps.setString(2, pronouns);
ps.executeUpdate();
} catch (SQLException e) {
errorLog.add("Database update error: " + e.getMessage());
e.printStackTrace();
}
}
public String getPronouns(UUID uuid) {
try (PreparedStatement ps = connection.prepareStatement("SELECT pronouns FROM pronouns WHERE uuid = ?")) {
ps.setString(1, uuid.toString());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return rs.getString("pronouns");
}
} catch (SQLException e) {
errorLog.add("Database fetch error: " + e.getMessage());
e.printStackTrace();
}
return null;
}
public void generateDebugFile() {
File debugFile = new File(getDataFolder(), "debug.txt");
try {
if (!getDataFolder().exists()) getDataFolder().mkdirs();
if (!debugFile.exists()) debugFile.createNewFile();
FileWriter writer = new FileWriter(debugFile);
writer.write("=== PronounsPlugin Debug Report ===\n");
writer.write("Plugin Enabled: " + isEnabled() + "\n");
writer.write("Database Connected: " + (connection != null) + "\n");
writer.write("Blocked Pronouns: " + blockedPronouns + "\n");
writer.write("Pronoun Suggestions: " + pronounSuggestions + "\n");
writer.write("Error Log:\n");
if (errorLog.isEmpty()) {
writer.write(" No errors logged.\n");
} else {
for (String error : errorLog) {
writer.write(" - " + error + "\n");
}
}
writer.write("Generated at: " + new java.util.Date() + "\n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public List<String> getPronounSuggestions() {
return pronounSuggestions;
}
}

View File

@ -0,0 +1,39 @@
# PronounsPlugin Configuration
blocked-pronouns:
- "faggot"
- "bitch"
- "slut"
- "cunt"
- "dickhead"
- "bastard"
- "asshole"
- "idiot"
- "retard"
- "freak"
- "whore"
- "nigger"
- "chink"
- "spic"
pronoun-suggestions:
- "she/her"
- "he/him"
- "they/them"
- "xe/xem"
- "it/its"
debug: true
generate-debug-file: true
database:
use-sqlite: true
admin-permissions:
- "pronouns.admin"
- "pronouns.override"
player-permissions:
- "pronouns.set"
- "pronouns.view"

View File

@ -0,0 +1,28 @@
name: PronounsPlugin
version: 1.0
main: com.sophiaatkinson.pronouns.PronounsPlugin
api-version: 1.16
commands:
pronouns:
description: Manage pronouns for players
usage: /<command> <set/view> <pronouns/player>
permissions:
pronouns.set:
description: Allows a player to set their pronouns
default: true
pronouns.view:
description: Allows a player to view their own or others' pronouns
default: true
pronouns.debug:
description: Allows players to use the debug command
default: op
pronouns.admin:
description: Allows admin to view all pronouns
default: op
aliases:
- mypronouns
- setpronouns
depend:
- PlaceholderAPI
softdepend:
- InteractiveChat