Bukkit command cleanup

This commit is contained in:
dfsek
2021-03-10 02:54:03 -07:00
parent 5a85aced45
commit 513c6a647f
4 changed files with 1 additions and 206 deletions

View File

@@ -1,64 +0,0 @@
package com.dfsek.terra.bukkit.command.command.structure;
import com.dfsek.terra.api.structures.parser.lang.constants.NumericConstant;
import com.dfsek.terra.api.structures.script.TerraImplementationArguments;
import com.dfsek.terra.api.structures.script.functions.CheckFunction;
import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
import com.dfsek.terra.api.structures.tokenizer.Position;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class SpawnCommand extends WorldCommand implements DebugCommand {
public SpawnCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
Location p = sender.getLocation();
int x = p.getBlockX();
int y = p.getBlockY();
int z = p.getBlockZ();
Position dummy = new Position(0, 0);
com.dfsek.terra.api.platform.world.World w = BukkitAdapter.adapt(world);
String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), dummy).apply(new TerraImplementationArguments(new StructureBuffer(
new com.dfsek.terra.api.math.vector.Location(w, x, y, z)
), Rotation.NONE, new FastRandom(), 0), new HashMap<>());
sender.sendMessage("Found: " + check);
return true;
}
@Override
public String getName() {
return "spawn";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@@ -2,7 +2,6 @@ package com.dfsek.terra.bukkit.command.command.structure;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.command.command.structure.load.LoadCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -31,7 +30,7 @@ public class StructureCommand extends PlayerCommand {
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Arrays.asList(new ExportCommand(this), new LoadCommand(this), new LocateCommand(this), new SpawnCommand(this));
return Arrays.asList(new ExportCommand(this), new LocateCommand(this));
}
@Override

View File

@@ -1,55 +0,0 @@
package com.dfsek.terra.bukkit.command.command.structure.load;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class LoadCommand extends PlayerCommand implements DebugCommand {
public LoadCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
public List<String> getStructureNames(World world) {
List<String> names = new ArrayList<>();
TerraWorld terraWorld = getMain().getWorld(world);
terraWorld.getConfig().getScriptRegistry().forEach(script -> names.add(script.getId()));
return names;
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return true;
}
@Override
public String getName() {
return "load";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Arrays.asList(new LoadFullCommand(this, true), new LoadFullCommand(this, false));
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
@Override
public int arguments() {
return 0;
}
}

View File

@@ -1,85 +0,0 @@
package com.dfsek.terra.bukkit.command.command.structure.load;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.world.PopulationUtil;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitChunk;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class LoadFullCommand extends LoadCommand implements DebugCommand {
private final boolean chunk;
public LoadFullCommand(com.dfsek.terra.bukkit.command.Command parent, boolean chunk) {
super(parent);
this.chunk = chunk;
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
TerraWorld terraWorld = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld()));
long t = System.nanoTime();
FastRandom chunk = PopulationUtil.getRandom(new BukkitChunk(sender.getLocation().getChunk()));
Rotation r;
try {
r = Rotation.fromDegrees(Integer.parseInt(args[1]));
} catch(Exception e) {
sender.sendMessage("Invalid rotation: " + args[1]);
return true;
}
StructureScript script = terraWorld.getConfig().getScriptRegistry().get(args[0]);
if(script == null) {
sender.sendMessage("Invalid structure: " + args[0]);
return true;
}
if(this.chunk) {
script.execute(BukkitAdapter.adapt(sender.getLocation()), BukkitAdapter.adapt(sender.getLocation().getChunk()), chunk, r);
} else {
script.execute(BukkitAdapter.adapt(sender.getLocation()), chunk, r);
}
long l = System.nanoTime() - t;
sender.sendMessage("Took " + ((double) l) / 1000000 + "ms");
return true;
}
@Override
public String getName() {
return chunk ? "chunk" : "full";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 2;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) {
World w = BukkitAdapter.adapt(((Player) commandSender).getWorld());
if(!TerraWorld.isTerraWorld(w)) return Collections.emptyList();
switch(args.length) {
case 1:
return getMain().getWorld(w).getConfig().getScriptRegistry().entries().stream().map(StructureScript::getId).filter(id -> id.startsWith(args[0])).sorted().collect(Collectors.toList());
case 2:
return Stream.of("0", "90", "180", "270").filter(string -> string.toUpperCase().startsWith(args[1].toUpperCase())).collect(Collectors.toList());
}
return Collections.emptyList();
}
}