commit 2eea920d65945baef2a4d796d677c822a652e829 Author: Sophia Atkinson Date: Wed May 7 22:46:14 2025 -0700 Initial commit working? diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9484d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +.vscode/settings.json diff --git a/lib/PlaceholderAPI-2.11.7-DEV-207.jar b/lib/PlaceholderAPI-2.11.7-DEV-207.jar new file mode 100644 index 0000000..9922b9c Binary files /dev/null and b/lib/PlaceholderAPI-2.11.7-DEV-207.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3cda17b --- /dev/null +++ b/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + + com.sophiaatkinson + PronounsPlugin + 1.0 + jar + + PronounsPlugin + + + 21 + ${java.version} + ${java.version} + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + central + https://repo.maven.apache.org/maven2 + + + + + + org.spigotmc + spigot-api + 1.16.5-R0.1-SNAPSHOT + provided + + + me.clip + placeholderapi + 2.11.7 + system + + ${project.basedir}/lib/PlaceholderAPI-2.11.7-DEV-207.jar + + + org.jetbrains + annotations + 24.0.1 + + + + + diff --git a/src/main/java/com/sophiaatkinson/pronouns/PronounsCommand.java b/src/main/java/com/sophiaatkinson/pronouns/PronounsCommand.java new file mode 100644 index 0000000..6ae3ebc --- /dev/null +++ b/src/main/java/com/sophiaatkinson/pronouns/PronounsCommand.java @@ -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 " + 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 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 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(); + } +} diff --git a/src/main/java/com/sophiaatkinson/pronouns/PronounsPlaceholder.java b/src/main/java/com/sophiaatkinson/pronouns/PronounsPlaceholder.java new file mode 100644 index 0000000..aaf0f7a --- /dev/null +++ b/src/main/java/com/sophiaatkinson/pronouns/PronounsPlaceholder.java @@ -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; + } +} diff --git a/src/main/java/com/sophiaatkinson/pronouns/PronounsPlugin.java b/src/main/java/com/sophiaatkinson/pronouns/PronounsPlugin.java new file mode 100644 index 0000000..37b6800 --- /dev/null +++ b/src/main/java/com/sophiaatkinson/pronouns/PronounsPlugin.java @@ -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 blockedPronouns; + private List pronounSuggestions; + private final List 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 getPronounSuggestions() { + return pronounSuggestions; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..d0a6f4d --- /dev/null +++ b/src/main/resources/config.yml @@ -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" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..f23a242 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -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: / + 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