Skip to content

Commit

Permalink
Add wildcard support for /delhome (#5919)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianOliva2 authored Nov 24, 2024
1 parent 2ac37d8 commit a87760d
Showing 1 changed file with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ public Commanddelhome() {
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) {
Expand Down Expand Up @@ -45,21 +63,19 @@ public void run(final Server server, final CommandSource sender, final String co
name = expandedArg[0].toLowerCase(Locale.ENGLISH);
}

if (name.equals("bed")) {
throw new TranslatableException("invalidHomeName");
}

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;
switch (name) {
case "bed":
throw new TranslatableException("invalidHomeName");
case "*":
final List<String> homes = user.getHomes();
for (String home : homes) {
deleteHome(sender, user, home);
}
break;
default:
deleteHome(sender, user, name);
break;
}

user.delHome(name);
sender.sendTl("deleteHome", name);
}

@Override
Expand All @@ -81,6 +97,7 @@ protected List<String> getTabCompleteOptions(final Server server, final CommandS
return homes;
}
otherUser.getHomes().forEach(home -> homes.add(namePart + ":" + home));
homes.add(namePart + ":" + "*");
}
}
return homes;
Expand Down

0 comments on commit a87760d

Please sign in to comment.