add admin command
This commit is contained in:
6
pom.xml
6
pom.xml
@ -4,11 +4,11 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.sophiaatkinson</groupId>
|
||||
<artifactId>PronounsPlugin</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<artifactId>PronounsPlaceholder</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PronounsPlugin</name>
|
||||
<name>PronounsPlaceholder</name>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
|
@ -4,9 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -78,22 +81,23 @@ public class PronounsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
case "reset" -> {
|
||||
plugin.setPronouns(player.getUniqueId(), null); // Reset the player's pronouns
|
||||
plugin.setPronouns(player.getUniqueId(), null);
|
||||
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 view <player> " + ChatColor.WHITE + "- View your own 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");
|
||||
player.sendMessage(ChatColor.YELLOW + "/pronouns version " + ChatColor.WHITE + "- Show plugin version info");
|
||||
player.sendMessage(ChatColor.YELLOW + "/pronouns debug " + ChatColor.WHITE + "- Generate debug file");
|
||||
player.sendMessage(ChatColor.YELLOW + "/pronouns admin " + ChatColor.WHITE + "- Admin tools (list, set, remove)");
|
||||
}
|
||||
|
||||
case "version" -> {
|
||||
player.sendMessage(ChatColor.AQUA + "=== Version Info ===");
|
||||
player.sendMessage(ChatColor.YELLOW + "PronounsPlugin: " + ChatColor.WHITE + plugin.getDescription().getVersion());
|
||||
player.sendMessage(ChatColor.YELLOW + "PronounsPlaceholder: " + ChatColor.WHITE + plugin.getDescription().getVersion());
|
||||
player.sendMessage(ChatColor.YELLOW + "Server Version: " + ChatColor.WHITE + Bukkit.getVersion());
|
||||
}
|
||||
|
||||
@ -102,6 +106,56 @@ public class PronounsCommand implements CommandExecutor, TabCompleter {
|
||||
player.sendMessage(ChatColor.GREEN + "Debug file written to plugin folder as debug.txt");
|
||||
}
|
||||
|
||||
case "admin" -> {
|
||||
if (!player.hasPermission("pronouns.admin")) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to use admin commands.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /pronouns admin <list|remove|set>");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "list" -> {
|
||||
Map<UUID, String> all = plugin.getAllPronouns();
|
||||
if (all.isEmpty()) {
|
||||
player.sendMessage(ChatColor.YELLOW + "No pronouns have been set.");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.AQUA + "=== All Player Pronouns ===");
|
||||
for (Map.Entry<UUID, String> entry : all.entrySet()) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(entry.getKey());
|
||||
player.sendMessage(ChatColor.YELLOW + p.getName() + ": " + ChatColor.AQUA + entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "remove" -> {
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /pronouns admin remove <player>");
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[2]);
|
||||
plugin.setPronouns(target.getUniqueId(), null);
|
||||
player.sendMessage(ChatColor.GREEN + "Removed pronouns for " + target.getName());
|
||||
}
|
||||
|
||||
case "set" -> {
|
||||
if (args.length < 4) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /pronouns admin set <player> <pronouns>");
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[2]);
|
||||
String pronouns = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
|
||||
plugin.setPronouns(target.getUniqueId(), pronouns);
|
||||
player.sendMessage(ChatColor.GREEN + "Set " + target.getName() + "'s pronouns to: " + ChatColor.AQUA + pronouns);
|
||||
}
|
||||
|
||||
default -> player.sendMessage(ChatColor.RED + "Unknown admin subcommand.");
|
||||
}
|
||||
}
|
||||
|
||||
default -> player.sendMessage(ChatColor.RED + "Unknown subcommand. Use /pronouns help for options.");
|
||||
}
|
||||
|
||||
@ -111,7 +165,7 @@ public class PronounsCommand implements CommandExecutor, TabCompleter {
|
||||
@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");
|
||||
return Arrays.asList("set", "view", "reset", "help", "version", "debug", "admin");
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("view")) {
|
||||
@ -123,9 +177,27 @@ public class PronounsCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("set")) {
|
||||
return Arrays.asList("she/her", "he/him", "they/them", "xe/xem", "it/its");
|
||||
return plugin.getPronounSuggestions();
|
||||
}
|
||||
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("admin")) {
|
||||
return Arrays.asList("list", "remove", "set");
|
||||
}
|
||||
|
||||
if (args.length == 3 && args[0].equalsIgnoreCase("admin")) {
|
||||
if (args[1].equalsIgnoreCase("remove") || args[1].equalsIgnoreCase("set")) {
|
||||
List<String> names = new ArrayList<>();
|
||||
for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
|
||||
names.add(p.getName());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 4 && args[0].equalsIgnoreCase("admin") && args[1].equalsIgnoreCase("set")) {
|
||||
return plugin.getPronounSuggestions();
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class PronounsPlaceholder extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "pronounsplugin";
|
||||
return "PronounsPlaceholder";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -108,6 +109,19 @@ public class PronounsPlugin extends JavaPlugin {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Map<UUID, String> getAllPronouns() {
|
||||
Map<UUID, String> result = new java.util.HashMap<>();
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("SELECT uuid, pronouns FROM pronouns");
|
||||
while (rs.next()) {
|
||||
result.put(UUID.fromString(rs.getString("uuid")), rs.getString("pronouns"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
errorLog.add("Database fetch all error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void generateDebugFile() {
|
||||
File debugFile = new File(getDataFolder(), "debug.txt");
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: PronounsPlugin
|
||||
version: 1.0.1
|
||||
name: PronounsPlaceholder
|
||||
version: 1.0.2
|
||||
main: com.sophiaatkinson.pronouns.PronounsPlugin
|
||||
api-version: 1.16
|
||||
commands:
|
||||
@ -17,7 +17,7 @@ commands:
|
||||
description: Allows players to use the debug command
|
||||
default: op
|
||||
pronouns.admin:
|
||||
description: Allows admin to view all pronouns
|
||||
description: Allows admin to list, set, remove pronouns
|
||||
default: op
|
||||
aliases:
|
||||
- mypronouns
|
||||
|
Reference in New Issue
Block a user