mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Add purge command.
This commit is contained in:
parent
bb92aa57a8
commit
da6d6d64c2
@ -0,0 +1,65 @@
|
||||
package com.onarandombox.MultiverseCore.commands_acf;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Split;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandAlias("mv")
|
||||
public class PurgeCommand extends MultiverseCommand {
|
||||
|
||||
public PurgeCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand("purgeall")
|
||||
@CommandPermission("multiverse.core.purge")
|
||||
@Syntax("<all|animals|monsters|mobname>")
|
||||
@CommandCompletion("all|animals|monsters|@livingEntities")
|
||||
@Description("Removed the specified type of mob from all worlds.")
|
||||
public void onPurgeAllCommand(@NotNull CommandSender sender,
|
||||
@NotNull @Split(",") String[] targetEntities) {
|
||||
|
||||
doPurge(sender, this.plugin.getMVWorldManager().getMVWorlds(), targetEntities);
|
||||
}
|
||||
|
||||
@Subcommand("purge")
|
||||
@CommandPermission("multiverse.core.purge")
|
||||
@Syntax("<all|animals|monsters|mobname>")
|
||||
@CommandCompletion("@MVWorlds|all|animals|monsters|@livingEntities all|animals|monsters|@livingEntities")
|
||||
@Description("Removed the specified type of mob from the specified world.")
|
||||
public void onPurgeCommand(@NotNull CommandSender sender,
|
||||
@NotNull @Flags("other,defaultself,fallbackself") MultiverseWorld world,
|
||||
@NotNull @Split(",") String[] targetEntities) {
|
||||
|
||||
doPurge(sender, Collections.singleton(world), targetEntities);
|
||||
}
|
||||
|
||||
private void doPurge(@NotNull CommandSender sender,
|
||||
@NotNull Collection<MultiverseWorld> targetWorlds,
|
||||
@NotNull String[] targetEntities) {
|
||||
|
||||
List<String> thingsToKill = Arrays.stream(targetEntities)
|
||||
.map(String::toUpperCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
targetWorlds.forEach(w -> this.plugin.getMVWorldManager()
|
||||
.getTheWorldPurger()
|
||||
.purgeWorld(w, thingsToKill, false, false, sender));
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.enums.AddProperties;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@ -33,8 +34,9 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
registerStaticCompletion("gameRules", suggestGameRules());
|
||||
registerStaticCompletion("environments", suggestEnvironments());
|
||||
registerStaticCompletion("addProperties", suggestAddProperties());
|
||||
registerStaticCompletion("livingEntities", suggestEntities());
|
||||
|
||||
//TODO: Change to destinations
|
||||
//TODO: Destinations
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -105,4 +107,12 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
.map(p -> p.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> suggestEntities() {
|
||||
return Arrays.stream(EntityType.values())
|
||||
.filter(e -> e.isAlive() && e.isSpawnable())
|
||||
.map(e -> e.toString().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.onarandombox.MultiverseCore.commands_acf.ImportCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.InfoCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.ListCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.LoadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.PurgeCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.RegenCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.ReloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commands_acf.RemoveCommand;
|
||||
@ -90,6 +91,7 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
registerCommand(new RegenCommand(plugin));
|
||||
registerCommand(new TeleportCommand(plugin));
|
||||
registerCommand(new SilentCommand(plugin));
|
||||
registerCommand(new PurgeCommand(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user