mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
v4.5: Bulk delete, regex customization, QoL & API work (#486)
* Improve validator error specificity, fix #481 * Add more sanity-checking to cluster IDs, close #482 * Add bulk/player-delete command, close #484, close #257 * Fix checkstyle formatting in tests * Add missing strings to other locale files * Use morepaperlib for runtime command registration on spigot * api: make creation methods return a future, close #473 * Add name/description restriction regex customization * docs: Update config file with new regex options * bump version number to 4.5 * fix typo, correct command confirmation logic * Make confirmation locales more clear * Fix confirmation checking logic
This commit is contained in:
1 parent
e2c9a52911
commit
6bfd69f232
38 files changed
+1161
-692
No files matched your search
@@ -65,6 +65,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
import space.arim.morepaperlib.commands.CommandRegistration;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
|
||||
import java.io.File;
|
||||
@@ -177,11 +178,11 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
}
|
||||
});
|
||||
|
||||
// Register events
|
||||
initialize("events", (plugin) -> this.eventListener = new BukkitEventListener(this));
|
||||
// Register event listener
|
||||
initialize("events", (plugin) -> this.eventListener = registerListener());
|
||||
|
||||
// Register commands
|
||||
initialize("commands", (plugin) -> this.commands = registerCommands());
|
||||
initialize("commands", (plugin) -> this.commands = BukkitCommand.Type.getCommands(this));
|
||||
|
||||
// Initialize the API
|
||||
initialize("API", (plugin) -> HuskHomesAPI.register(this));
|
||||
@@ -191,9 +192,10 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
this.checkForUpdates();
|
||||
}
|
||||
|
||||
// Register the event listener
|
||||
@NotNull
|
||||
public List<Command> registerCommands() {
|
||||
return BukkitCommand.Type.getCommands(this);
|
||||
protected EventListener registerListener() {
|
||||
return new BukkitEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -242,15 +244,6 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
cancelTasks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adventure Bukkit audiences.
|
||||
*
|
||||
* @return The adventure Bukkit audiences
|
||||
*/
|
||||
public BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConsoleUser getConsole() {
|
||||
@@ -482,11 +475,21 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitAudiences getAudiences() {
|
||||
return audiences;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GracefulScheduling getScheduler() {
|
||||
return paperLib.scheduling();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CommandRegistration getCommandRegistrar() {
|
||||
return paperLib.commandRegistration();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HuskHomes getPlugin() {
|
||||
|
||||
@@ -25,10 +25,7 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@@ -39,27 +36,27 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
public class BukkitCommand extends org.bukkit.command.Command {
|
||||
|
||||
private final BukkitHuskHomes plugin;
|
||||
private final Command command;
|
||||
|
||||
public BukkitCommand(@NotNull Command command, @NotNull BukkitHuskHomes plugin) {
|
||||
super(command.getName(), command.getDescription(), command.getUsage(), command.getAliases());
|
||||
this.command = command;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command,
|
||||
@NotNull String label, @NotNull String[] args) {
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
this.command.onExecuted(sender instanceof Player p ? BukkitUser.adapt(p, plugin) : plugin.getConsole(), args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command,
|
||||
@NotNull String alias, @NotNull String[] args) {
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
|
||||
@NotNull String[] args) throws IllegalArgumentException {
|
||||
if (!(this.command instanceof TabProvider provider)) {
|
||||
return List.of();
|
||||
}
|
||||
@@ -69,37 +66,38 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
public void register() {
|
||||
// Register with bukkit
|
||||
final PluginCommand pluginCommand = plugin.getCommand(command.getName());
|
||||
if (pluginCommand == null) {
|
||||
throw new IllegalStateException("Command " + command.getName() + " not found in plugin.yml");
|
||||
}
|
||||
plugin.getCommandRegistrar().getServerCommandMap().register("huskhomes", this);
|
||||
|
||||
// Register permissions
|
||||
addPermission(
|
||||
BukkitCommand.addPermission(
|
||||
plugin,
|
||||
command.getPermission(),
|
||||
command.getUsage(),
|
||||
getPermissionDefault(command.isOperatorCommand())
|
||||
BukkitCommand.getPermissionDefault(command.isOperatorCommand())
|
||||
);
|
||||
final List<Permission> childNodes = command.getAdditionalPermissions()
|
||||
.entrySet().stream()
|
||||
.map((entry) -> addPermission(plugin, entry.getKey(), "", getPermissionDefault(entry.getValue())))
|
||||
.map((entry) -> BukkitCommand.addPermission(
|
||||
plugin,
|
||||
entry.getKey(),
|
||||
"",
|
||||
BukkitCommand.getPermissionDefault(entry.getValue()))
|
||||
)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
if (!childNodes.isEmpty()) {
|
||||
addPermission(plugin, command.getPermission("*"), command.getUsage(), PermissionDefault.FALSE,
|
||||
childNodes.toArray((plugin) -> new Permission[0]));
|
||||
BukkitCommand.addPermission(
|
||||
plugin,
|
||||
command.getPermission("*"),
|
||||
command.getUsage(),
|
||||
PermissionDefault.FALSE,
|
||||
childNodes.toArray(new Permission[0])
|
||||
);
|
||||
}
|
||||
|
||||
// Set command parameters
|
||||
pluginCommand.setExecutor(this);
|
||||
pluginCommand.setTabCompleter(this);
|
||||
pluginCommand.setDescription(command.getDescription());
|
||||
pluginCommand.setPermission(command.getPermission());
|
||||
|
||||
// Register commodore TAB completion
|
||||
if (CommodoreProvider.isSupported() && plugin.getSettings().doBrigadierTabCompletion()) {
|
||||
BrigadierUtil.registerCommodore(plugin, pluginCommand, command);
|
||||
BrigadierUtil.registerCommodore(plugin, this, command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,17 +176,12 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
@NotNull
|
||||
public static List<Command> getCommands(@NotNull BukkitHuskHomes plugin) {
|
||||
return Arrays.stream(values())
|
||||
.map((type) -> {
|
||||
Command command = type.createCommand(plugin);
|
||||
if (plugin.getSettings().isCommandDisabled(command)) {
|
||||
command = new DisabledCommand(command.getName(), plugin);
|
||||
}
|
||||
new BukkitCommand(command, plugin).register();
|
||||
return command;
|
||||
})
|
||||
.filter((command) -> !(command instanceof DisabledCommand))
|
||||
.map((type) -> type.createCommand(plugin))
|
||||
.filter((command) -> !plugin.getSettings().isCommandDisabled(command))
|
||||
.peek((command) -> new BukkitCommand(command, plugin).register())
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.util.BukkitAdapter;
|
||||
import net.william278.huskhomes.util.ValidationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -98,28 +99,29 @@ public class EssentialsXImporter extends Importer {
|
||||
|
||||
@NotNull
|
||||
private String normalizeName(@NotNull String name) {
|
||||
if (plugin.getValidator().isValidName(name)) {
|
||||
try {
|
||||
plugin.getValidator().validateName(name);
|
||||
return name;
|
||||
} catch (ValidationException e) {
|
||||
// Remove spaces
|
||||
name = name.replaceAll(" ", "_");
|
||||
|
||||
// Remove unicode characters
|
||||
if (plugin.getSettings().doRestrictNames()) {
|
||||
name = name.replaceAll("[^A-Za-z0-9_-]", "");
|
||||
}
|
||||
|
||||
// Ensure the name is not blank
|
||||
if (name.isBlank()) {
|
||||
name = "imported-" + UUID.randomUUID().toString().substring(0, 5);
|
||||
}
|
||||
|
||||
// Ensure name is not too long
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
// Remove spaces
|
||||
name = name.replaceAll(" ", "_");
|
||||
|
||||
// Remove unicode characters
|
||||
if (!plugin.getSettings().doAllowUnicodeNames()) {
|
||||
name = name.replaceAll("[^A-Za-z0-9_-]", "");
|
||||
}
|
||||
|
||||
// Ensure the name is not blank
|
||||
if (name.isBlank()) {
|
||||
name = "imported-" + UUID.randomUUID().toString().substring(0, 5);
|
||||
}
|
||||
|
||||
// Ensure name is not too long
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user