From a87760d3ce6f17d36ad8d069369d84bd50ed2b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva=20Del=20R=C3=ADo?= <105056947+AdrianOliva2@users.noreply.github.com> Date: Sun, 24 Nov 2024 02:47:36 +0100 Subject: [PATCH] Add wildcard support for /delhome (#5919) --- .../essentials/commands/Commanddelhome.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanddelhome.java index 7446bf978..95ce61152 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanddelhome.java @@ -18,6 +18,24 @@ public class Commanddelhome extends EssentialsCommand { super("delhome"); } + private void deleteHome(CommandSource sender, User user, String home) { + final HomeModifyEvent event = new HomeModifyEvent(sender.getUser(), user, home, user.getHome(home), false); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + if (ess.getSettings().isDebug()) { + ess.getLogger().info("HomeModifyEvent canceled for /delhome execution by " + sender.getDisplayName()); + } + return; + } + + try { + user.delHome(home); + } catch (Exception e) { + sender.sendTl("invalidHome", home); + } + sender.sendTl("deleteHome", home); + } + @Override public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -45,21 +63,19 @@ public class Commanddelhome extends EssentialsCommand { name = expandedArg[0].toLowerCase(Locale.ENGLISH); } - if (name.equals("bed")) { - throw new TranslatableException("invalidHomeName"); + switch (name) { + case "bed": + throw new TranslatableException("invalidHomeName"); + case "*": + final List homes = user.getHomes(); + for (String home : homes) { + deleteHome(sender, user, home); + } + break; + default: + deleteHome(sender, user, name); + break; } - - final HomeModifyEvent event = new HomeModifyEvent(sender.getUser(), user, name, user.getHome(name), false); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - if (ess.getSettings().isDebug()) { - ess.getLogger().info("HomeModifyEvent canceled for /delhome execution by " + sender.getDisplayName()); - } - return; - } - - user.delHome(name); - sender.sendTl("deleteHome", name); } @Override @@ -81,6 +97,7 @@ public class Commanddelhome extends EssentialsCommand { return homes; } otherUser.getHomes().forEach(home -> homes.add(namePart + ":" + home)); + homes.add(namePart + ":" + "*"); } } return homes;