Split location into individual params for better tab complete.

This commit is contained in:
benwoo1110 2020-12-28 10:52:24 +08:00
parent fc6415af8c
commit e9ec1275fe
2 changed files with 65 additions and 42 deletions

View File

@ -9,13 +9,10 @@ package com.onarandombox.MultiverseCore.commandTools;
import buscript.Buscript;
import co.aikar.commands.BukkitCommandCompletionContext;
import co.aikar.commands.BukkitCommandExecutionContext;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.PaperCommandCompletions;
import co.aikar.commands.RegisteredCommand;
import co.aikar.commands.RootCommand;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
@ -27,16 +24,13 @@ import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import sun.rmi.runtime.Log;
import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -170,7 +164,6 @@ public class MVCommandCompletions extends PaperCommandCompletions {
return Collections.emptyList();
}
Logging.info("location");
Player player = context.getPlayer();
if (player == null) {
return Collections.emptyList();
@ -202,7 +195,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
return Collections.emptyList();
}
return Arrays.asList("~", df.format(coordValue));
return Collections.singletonList(df.format(coordValue));
}
@NotNull

View File

@ -8,11 +8,13 @@
package com.onarandombox.MultiverseCore.commands;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.InvalidCommandArgument;
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.Optional;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -24,6 +26,7 @@ import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SetSpawnCommand extends MultiverseCommand {
@ -40,13 +43,18 @@ public class SetSpawnCommand extends MultiverseCommand {
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch")
@Description("Sets the spawn for the current world.")
public void onSetSpawnCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
//TODO ACF: Split parameter into individual attributes.
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself,fallbackself") Location location) {
@NotNull @Flags("other,defaultself") MultiverseWorld world,
@Nullable @Optional Double x,
@Nullable @Optional Double y,
@Nullable @Optional Double z,
@Nullable @Optional Float yaw,
@Nullable @Optional Float pitch) {
doSpawnSet(sender, location);
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
}
@Subcommand("modify set spawn")
@ -55,30 +63,18 @@ public class SetSpawnCommand extends MultiverseCommand {
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch")
@Description("Sets the spawn for the current world.")
public void onModifySetSpawnCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself,fallbackself") Location location) {
@NotNull @Flags("other,defaultself") MultiverseWorld world,
@Nullable @Optional Double x,
@Nullable @Optional Double y,
@Nullable @Optional Double z,
@Nullable @Optional Float yaw,
@Nullable @Optional Float pitch) {
doSpawnSet(sender, location);
}
}
@CommandAlias("mvm")
public class AliasModifySetSpawn extends BaseCommand {
@Subcommand("set spawn")
@CommandPermission("multiverse.core.spawn.set")
@Syntax("[world x y z [yaw pitch]]")
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch")
@Description("Sets the spawn for the current world.")
public void onModifySetSpawnCommand(@NotNull CommandSender sender,
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself,fallbackself") Location location) {
doSpawnSet(sender, location);
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
}
}
@ -88,19 +84,61 @@ public class SetSpawnCommand extends MultiverseCommand {
@CommandAlias("mvsetspawn")
@CommandPermission("multiverse.core.spawn.set")
@Syntax("[world x y z [yaw pitch]]")
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch")
@CommandCompletion("@MVWorlds @location:x @location:y @location:z @location:yaw @location:pitch @empty")
@Description("Sets the spawn for the current world.")
public void onAliasSetSpawnCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself,fallbackself") Location location) {
@NotNull @Flags("other,defaultself") MultiverseWorld world,
@Nullable @Optional Double x,
@Nullable @Optional Double y,
@Nullable @Optional Double z,
@Nullable @Optional Float yaw,
@Nullable @Optional Float pitch) {
doSpawnSet(sender, location);
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
}
}
@NotNull
private Location parseLocation(@Nullable Player player,
@NotNull MultiverseWorld world,
@Nullable Double x,
@Nullable Double y,
@Nullable Double z,
@Nullable Float yaw,
@Nullable Float pitch) {
if (x == null) {
if (player == null) {
throw new InvalidCommandArgument("You need to specify a location from console.");
}
return player.getLocation();
}
if (y == null) {
throw new InvalidCommandArgument("You need to specify y and z axis as well.");
}
if (z == null) {
throw new InvalidCommandArgument("You need to specify z axis as well.");
}
if (yaw == null) {
return new Location(world.getCBWorld(), x, y, z);
}
if (pitch == null) {
throw new InvalidCommandArgument("You need to specify pitch as well.");
}
return new Location(world.getCBWorld(), x, y, z, yaw, pitch);
}
private void doSpawnSet(@NotNull CommandSender sender,
@NotNull MultiverseWorld world,
@NotNull Location location) {
World bukkitWorld = location.getWorld();
@ -109,14 +147,6 @@ public class SetSpawnCommand extends MultiverseCommand {
return;
}
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(bukkitWorld);
if (world == null) {
bukkitWorld.setSpawnLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ());
sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set.");
sender.sendMessage("Please import it (see /mv import) to set the spawn fully with Pitch and Yaw.");
return;
}
world.setSpawnLocation(location);
BlockSafety blockSafety = this.plugin.getBlockSafety();
if (!blockSafety.playerCanSpawnHereSafely(location) && world.getAdjustSpawn()) {