mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
add structure locate command
This commit is contained in:
@@ -72,6 +72,11 @@ public class CheckedRegistry<T> implements Registry<T> {
|
||||
return registry.entries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keys() {
|
||||
return registry.keys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
return registry.load(t, c, loader);
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.api.registry;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.registry.OpenRegistry;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
@@ -46,6 +45,11 @@ public class LockedRegistry<T> implements Registry<T> {
|
||||
return registry.entries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keys() {
|
||||
return registry.keys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
return registry.load(t, c, loader);
|
||||
|
||||
@@ -43,4 +43,11 @@ public interface Registry<T> extends TypeLoader<T> {
|
||||
* @return Set containing all entries.
|
||||
*/
|
||||
Set<T> entries();
|
||||
|
||||
/**
|
||||
* Get all the keys in this registry.
|
||||
*
|
||||
* @return Keys in registry
|
||||
*/
|
||||
Set<String> keys();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ import com.dfsek.terra.config.lang.LangUtil;
|
||||
clazz = SpawnCommand.class,
|
||||
value = "spawn",
|
||||
aliases = "s"
|
||||
),
|
||||
@Subcommand(
|
||||
clazz = StructureLocateCommand.class,
|
||||
value = "locate",
|
||||
aliases = "l"
|
||||
)
|
||||
},
|
||||
usage = "/te structure"
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.dfsek.terra.commands.structure;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Argument;
|
||||
import com.dfsek.terra.api.command.annotation.Command;
|
||||
import com.dfsek.terra.api.command.annotation.Switch;
|
||||
import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget;
|
||||
import com.dfsek.terra.api.command.annotation.inject.SwitchTarget;
|
||||
import com.dfsek.terra.api.command.annotation.type.PlayerCommand;
|
||||
import com.dfsek.terra.api.command.annotation.type.WorldCommand;
|
||||
import com.dfsek.terra.api.command.arg.IntegerArgumentParser;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.commands.structure.argument.StructureArgumentParser;
|
||||
import com.dfsek.terra.commands.structure.completer.StructureCompleter;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@PlayerCommand
|
||||
@WorldCommand
|
||||
@Command(
|
||||
arguments = {
|
||||
@Argument(
|
||||
value = "structure",
|
||||
tabCompleter = StructureCompleter.class,
|
||||
argumentParser = StructureArgumentParser.class
|
||||
),
|
||||
@Argument(
|
||||
value = "radius",
|
||||
required = false,
|
||||
defaultValue = "100",
|
||||
argumentParser = IntegerArgumentParser.class
|
||||
)
|
||||
},
|
||||
switches = {
|
||||
@Switch(
|
||||
value = "teleport",
|
||||
aliases = {"t", "tp"}
|
||||
)
|
||||
}
|
||||
)
|
||||
public class StructureLocateCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@ArgumentTarget("structure")
|
||||
private TerraStructure structure;
|
||||
|
||||
@ArgumentTarget("radius")
|
||||
private Integer radius;
|
||||
|
||||
@SwitchTarget("teleport")
|
||||
private boolean teleport;
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
new Thread(new AsyncStructureFinder(main.getWorld(player.getWorld()).getBiomeProvider(), structure, player.getLocation().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), 0, radius, location -> {
|
||||
if(location != null) {
|
||||
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", structure.getTemplate().getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.getLocation().getY(), 0)).distance(player.getLocation().toVector())));
|
||||
if(teleport) {
|
||||
main.runPossiblyUnsafeTask(() -> player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ())));
|
||||
}
|
||||
} else LangUtil.send("command.biome.unable-to-locate", sender);
|
||||
}, main), "Biome Location Thread").start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.commands.structure.argument;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.arg.ArgumentParser;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
|
||||
public class StructureArgumentParser implements ArgumentParser<TerraStructure> {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public TerraStructure parse(CommandSender sender, String arg) {
|
||||
return main.getWorld(((Player) sender).getWorld()).getConfig().getStructureRegistry().get(arg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.dfsek.terra.commands.structure.completer;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StructureCompleter implements TabCompleter {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
return new ArrayList<>(main.getWorld(player.getWorld()).getConfig().getStructureRegistry().keys());
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,11 @@ public class OpenRegistry<T> implements Registry<T> {
|
||||
return new HashSet<>(objects.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keys() {
|
||||
return objects.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all entries from the registry.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user