basic bukkit implementation

This commit is contained in:
dfsek
2021-03-08 01:40:12 -07:00
parent 026a6066d3
commit b1256427a2
19 changed files with 356 additions and 54 deletions

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.entity.Entity;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitEntity implements Entity {
@@ -21,6 +22,11 @@ public class BukkitEntity implements Entity {
return BukkitAdapter.adapt(entity.getLocation());
}
@Override
public World getWorld() {
return BukkitAdapter.adapt(entity.getWorld());
}
@Override
public void sendMessage(String message) {
entity.sendMessage(message);

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.entity.Player;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitPlayer implements Player {
@@ -22,6 +23,11 @@ public class BukkitPlayer implements Player {
return new Location(BukkitAdapter.adapt(bukkit.getWorld()), bukkit.getX(), bukkit.getY(), bukkit.getZ());
}
@Override
public World getWorld() {
return BukkitAdapter.adapt(delegate.getWorld());
}
@Override
public void sendMessage(String message) {
delegate.sendMessage(message);

View File

@@ -6,6 +6,8 @@ import com.dfsek.terra.api.addons.TerraAddon;
import com.dfsek.terra.api.addons.annotations.Addon;
import com.dfsek.terra.api.addons.annotations.Author;
import com.dfsek.terra.api.addons.annotations.Version;
import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.TerraCommandManager;
import com.dfsek.terra.api.event.EventManager;
import com.dfsek.terra.api.event.TerraEventManager;
import com.dfsek.terra.api.platform.block.BlockData;
@@ -19,8 +21,7 @@ import com.dfsek.terra.api.util.logging.DebugLogger;
import com.dfsek.terra.api.util.logging.JavaLogger;
import com.dfsek.terra.api.util.logging.Logger;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.bukkit.command.command.TerraCommand;
import com.dfsek.terra.bukkit.command.command.structure.LocateCommand;
import com.dfsek.terra.bukkit.command.BukkitCommandAdapter;
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
@@ -30,6 +31,7 @@ import com.dfsek.terra.bukkit.listeners.SpigotListener;
import com.dfsek.terra.bukkit.listeners.TerraListener;
import com.dfsek.terra.bukkit.util.PaperUtil;
import com.dfsek.terra.bukkit.world.BukkitBiome;
import com.dfsek.terra.commands.profiler.ProfileCommand;
import com.dfsek.terra.config.GenericLoaders;
import com.dfsek.terra.config.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
@@ -163,14 +165,16 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
registry.loadAll(this); // Load all config packs.
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
TerraCommand command = new TerraCommand(this); // Set up main Terra command.
c.setExecutor(command);
c.setTabCompleter(command);
//TerraCommand command = new TerraCommand(this); // Set up main Terra command.
LocateCommand locate = new LocateCommand(command);
PluginCommand locatePl = Objects.requireNonNull(getCommand("locate"));
locatePl.setExecutor(locate); // Override locate command. Once Paper accepts StructureLocateEvent this will be unneeded on Paper implementations.
locatePl.setTabCompleter(locate);
CommandManager manager = new TerraCommandManager(this);
manager.register("profile", ProfileCommand.class);
BukkitCommandAdapter command = new BukkitCommandAdapter(manager);
c.setExecutor(command);
//c.setTabCompleter(command);
long save = config.getDataSaveInterval();

View File

@@ -0,0 +1,36 @@
package com.dfsek.terra.bukkit.command;
import com.dfsek.terra.api.command.CommandManager;
import com.dfsek.terra.api.command.exception.CommandException;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BukkitCommandAdapter implements CommandExecutor {
private final CommandManager manager;
public BukkitCommandAdapter(CommandManager manager) {
this.manager = manager;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
List<String> argList = new ArrayList<>(Arrays.asList(args));
if(argList.isEmpty()) {
sender.sendMessage("Command requires arguments.");
return true;
}
try {
manager.execute(argList.remove(0), BukkitAdapter.adapt(sender), argList);
} catch(CommandException e) {
sender.sendMessage(e.getMessage());
}
return true;
}
}

View File

@@ -19,6 +19,7 @@ import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.transform.MapTransform;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.BukkitEntity;
import com.dfsek.terra.bukkit.BukkitPlayer;
import com.dfsek.terra.bukkit.world.block.BukkitBlockTypeAndItem;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
@@ -27,6 +28,7 @@ import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@@ -351,6 +353,8 @@ public final class BukkitAdapter {
}
public static CommandSender adapt(org.bukkit.command.CommandSender sender) {
if(sender instanceof Player) return new BukkitPlayer((Player) sender);
if(sender instanceof Entity) return new BukkitEntity((Entity) sender);
return new BukkitCommandSender(sender);
}