mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-27 01:40:48 +08:00
Implement home cleanup utility (#4244)
This commit is contained in:
parent
f08c176b68
commit
1da3b3f08e
@ -13,8 +13,10 @@ import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@ -29,6 +31,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -38,6 +41,8 @@ public class Commandessentials extends EssentialsCommand {
|
||||
private static final Sound NOTE_HARP = EnumUtil.valueOf(Sound.class, "BLOCK_NOTE_BLOCK_HARP", "BLOCK_NOTE_HARP", "NOTE_PIANO");
|
||||
private static final Sound MOO_SOUND = EnumUtil.valueOf(Sound.class, "COW_IDLE", "ENTITY_COW_MILK");
|
||||
|
||||
private static final String HOMES_USAGE = "/<command> homes (fix | delete [world])";
|
||||
|
||||
private static final String NYAN_TUNE = "1D#,1E,2F#,,2A#,1E,1D#,1E,2F#,2B,2D#,2E,2D#,2A#,2B,,2F#,,1D#,1E,2F#,2B,2C#,2A#,2B,2C#,2E,2D#,2E,2C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1C#,,2F#,,2G#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#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1B,,";
|
||||
private static final String[] CONSOLE_MOO = new String[] {" (__)", " (oo)", " /------\\/", " / | ||", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..."};
|
||||
private static final String[] PLAYER_MOO = new String[] {" (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..."};
|
||||
@ -86,12 +91,10 @@ public class Commandessentials extends EssentialsCommand {
|
||||
case "verbose":
|
||||
runDebug(server, sender, commandLabel, args);
|
||||
break;
|
||||
|
||||
case "ver":
|
||||
case "version":
|
||||
runVersion(server, sender, commandLabel, args);
|
||||
break;
|
||||
|
||||
case "cmd":
|
||||
case "commands":
|
||||
runCommands(server, sender, commandLabel, args);
|
||||
@ -107,6 +110,9 @@ public class Commandessentials extends EssentialsCommand {
|
||||
case "cleanup":
|
||||
runCleanup(server, sender, commandLabel, args);
|
||||
break;
|
||||
case "homes":
|
||||
runHomes(server, sender, commandLabel, args);
|
||||
break;
|
||||
case "uuidconvert":
|
||||
runUUIDConvert(server, sender, commandLabel, args);
|
||||
break;
|
||||
@ -130,7 +136,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
// Displays the command's usage.
|
||||
private void showUsage(final CommandSource sender) throws Exception {
|
||||
throw new NotEnoughArgumentsException("/<command> <reload/debug/commands>");
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
// Lists commands that are being handed over to other plugins.
|
||||
@ -253,7 +259,69 @@ public class Commandessentials extends EssentialsCommand {
|
||||
}
|
||||
sender.sendMessage(tl("cleaned"));
|
||||
});
|
||||
}
|
||||
|
||||
private void runHomes(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("This sub-command provides a utility to mass-delete homes based on user options:");
|
||||
sender.sendMessage("Use \"fix\" to delete all homes inside non-existent or unloaded worlds.");
|
||||
sender.sendMessage("Use \"delete\" to delete all existing homes.");
|
||||
sender.sendMessage("Use \"delete <worldname>\" to delete all homes inside a specific world.");
|
||||
throw new Exception(HOMES_USAGE);
|
||||
}
|
||||
|
||||
final UserMap userMap = ess.getUserMap();
|
||||
switch (args[1]) {
|
||||
case "fix":
|
||||
sender.sendMessage(tl("fixingHomes"));
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
for (final UUID u : userMap.getAllUniqueUsers()) {
|
||||
final User user = ess.getUserMap().getUser(u);
|
||||
if (user == null) {
|
||||
continue;
|
||||
}
|
||||
for (String homeName : user.getHomes()) {
|
||||
try {
|
||||
if (user.getHome(homeName) == null) {
|
||||
user.delHome(homeName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ess.getLogger().info("Unable to delete home " + homeName + " for " + user.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(tl("fixedHomes"));
|
||||
});
|
||||
break;
|
||||
case "delete":
|
||||
final boolean filterByWorld = args.length >= 3;
|
||||
if (filterByWorld && server.getWorld(args[2]) == null) {
|
||||
throw new Exception(tl("invalidWorld"));
|
||||
}
|
||||
sender.sendMessage(filterByWorld ? tl("deletingHomesWorld", args[2]) : tl("deletingHomes"));
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
for (final UUID u : userMap.getAllUniqueUsers()) {
|
||||
final User user = ess.getUserMap().getUser(u);
|
||||
if (user == null) {
|
||||
continue;
|
||||
}
|
||||
for (String homeName : user.getHomes()) {
|
||||
try {
|
||||
final Location home = user.getHome(homeName);
|
||||
if (!filterByWorld || (home != null && home.getWorld() != null && home.getWorld().getName().equals(args[2]))) {
|
||||
user.delHome(homeName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ess.getLogger().info("Unable to delete home " + homeName + " for " + user.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(filterByWorld ? tl("deletedHomesWorld", args[2]) : tl("deletedHomes"));
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Exception(HOMES_USAGE);
|
||||
}
|
||||
}
|
||||
|
||||
// Forces a rerun of userdata UUID conversion.
|
||||
@ -406,12 +474,13 @@ public class Commandessentials extends EssentialsCommand {
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
final List<String> options = Lists.newArrayList();
|
||||
options.add("debug");
|
||||
options.add("commands");
|
||||
options.add("version");
|
||||
options.add("reload");
|
||||
options.add("version");
|
||||
options.add("commands");
|
||||
options.add("debug");
|
||||
options.add("reset");
|
||||
options.add("cleanup");
|
||||
options.add("homes");
|
||||
//options.add("uuidconvert");
|
||||
//options.add("uuidtest");
|
||||
//options.add("nya");
|
||||
@ -438,6 +507,13 @@ public class Commandessentials extends EssentialsCommand {
|
||||
return Lists.newArrayList("-1", "0");
|
||||
}
|
||||
break;
|
||||
case "homes":
|
||||
if (args.length == 2) {
|
||||
return Lists.newArrayList("fix", "delete");
|
||||
} else if (args.length == 3 && args[1].equalsIgnoreCase("delete")) {
|
||||
return server.getWorlds().stream().map(World::getName).collect(Collectors.toList());
|
||||
}
|
||||
break;
|
||||
case "uuidconvert":
|
||||
if (args.length == 2) {
|
||||
return Lists.newArrayList("ignoreUFCache");
|
||||
|
@ -191,11 +191,15 @@ customtextCommandUsage=/<alias> - Define in bukkit.yml
|
||||
day=day
|
||||
days=days
|
||||
defaultBanReason=The Ban Hammer has spoken\!
|
||||
deletedHomes=All homes deleted.
|
||||
deletedHomesWorld=All homes in {0} deleted.
|
||||
deleteFileError=Could not delete file\: {0}
|
||||
deleteHome=\u00a76Home\u00a7c {0} \u00a76has been removed.
|
||||
deleteJail=\u00a76Jail\u00a7c {0} \u00a76has been removed.
|
||||
deleteKit=\u00a76Kit\u00a7c {0} \u00a76has been removed.
|
||||
deleteWarp=\u00a76Warp\u00a7c {0} \u00a76has been removed.
|
||||
deletingHomes=Deleting all homes...
|
||||
deletingHomesWorld=Deleting all homes in {0}...
|
||||
delhomeCommandDescription=Removes a home.
|
||||
delhomeCommandUsage=/<command> [player:]<name>
|
||||
delhomeCommandUsage1=/<command> <name>
|
||||
@ -278,6 +282,10 @@ essentialsCommandUsage4=/<command> debug
|
||||
essentialsCommandUsage4Description=Toggles Essentials' "debug mode"
|
||||
essentialsCommandUsage5=/<command> reset <player>
|
||||
essentialsCommandUsage5Description=Resets the given player's userdata
|
||||
essentialsCommandUsage6=/<command> cleanup
|
||||
essentialsCommandUsage6Description=Cleans up old userdata
|
||||
essentialsCommandUsage7=/<command> homes
|
||||
essentialsCommandUsage7Description=Manages user homes
|
||||
essentialsHelp1=The file is broken and Essentials can''t open it. Essentials is now disabled. If you can''t fix the file yourself, go to http\://tiny.cc/EssentialsChat
|
||||
essentialsHelp2=The file is broken and Essentials can''t open it. Essentials is now disabled. If you can''t fix the file yourself, either type /essentialshelp in game or go to http\://tiny.cc/EssentialsChat
|
||||
essentialsReload=\u00a76Essentials reloaded\u00a7c {0}.
|
||||
@ -329,6 +337,8 @@ fireworkCommandUsage4=/<command> <meta>
|
||||
fireworkCommandUsage4Description=Adds the given effect to the held firework
|
||||
fireworkEffectsCleared=\u00a76Removed all effects from held stack.
|
||||
fireworkSyntax=\u00a76Firework parameters\:\u00a7c color\:<color> [fade\:<color>] [shape\:<shape>] [effect\:<effect>]\n\u00a76To use multiple colors/effects, separate values with commas\: \u00a7cred,blue,pink\n\u00a76Shapes\:\u00a7c star, ball, large, creeper, burst \u00a76Effects\:\u00a7c trail, twinkle.
|
||||
fixedHomes=Invalid homes deleted.
|
||||
fixingHomes=Deleting invalid homes...
|
||||
flyCommandDescription=Take off, and soar!
|
||||
flyCommandUsage=/<command> [player] [on|off]
|
||||
flyCommandUsage1=/<command> [player]
|
||||
|
Loading…
Reference in New Issue
Block a user