diff --git a/pom.xml b/pom.xml index 3712b92..383f1b4 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,18 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + enginehub-maven + https://maven.enginehub.org/repo/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + codemc + https://repo.codemc.io/repository/maven-public/ + @@ -36,6 +48,14 @@ annotations 23.0.0 + + + com.sk89q.worldedit + worldedit-bukkit + 7.2.0-SNAPSHOT + provided + + \ No newline at end of file diff --git a/src/main/java/wtf/beatrice/limbomanager/LimboManager.java b/src/main/java/wtf/beatrice/limbomanager/LimboManager.java index 4ce70c6..f982bdc 100644 --- a/src/main/java/wtf/beatrice/limbomanager/LimboManager.java +++ b/src/main/java/wtf/beatrice/limbomanager/LimboManager.java @@ -8,9 +8,12 @@ import wtf.beatrice.limbomanager.listeners.PlayerHider; import wtf.beatrice.limbomanager.listeners.PlayerTeleporter; import wtf.beatrice.limbomanager.listeners.RiskyBlocksHandler; +import java.io.File; + public class LimboManager extends JavaPlugin { private PluginManager pluginManager; + private static String schematicsFolderPath; private static LimboManager instance; @Override @@ -24,6 +27,11 @@ public class LimboManager extends JavaPlugin { pluginManager.registerEvents(new CommandCanceller(), this); pluginManager.registerEvents(new RiskyBlocksHandler(), this); + // no need to check if it exists, it will just skip creation. + getDataFolder().mkdirs(); + schematicsFolderPath = getDataFolder().getAbsolutePath() + File.separator + "schematics"; + getSchematicsFolder().mkdirs(); + } @@ -37,4 +45,8 @@ public class LimboManager extends JavaPlugin { { return instance; } + + public static File getSchematicsFolder() { + return new File(schematicsFolderPath); + } } \ No newline at end of file diff --git a/src/main/java/wtf/beatrice/limbomanager/listeners/PlayerTeleporter.java b/src/main/java/wtf/beatrice/limbomanager/listeners/PlayerTeleporter.java index fd7f377..8f37e13 100644 --- a/src/main/java/wtf/beatrice/limbomanager/listeners/PlayerTeleporter.java +++ b/src/main/java/wtf/beatrice/limbomanager/listeners/PlayerTeleporter.java @@ -1,15 +1,32 @@ package wtf.beatrice.limbomanager.listeners; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; +import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.World; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import wtf.beatrice.limbomanager.Cache; +import wtf.beatrice.limbomanager.LimboManager; import wtf.beatrice.limbomanager.objects.Coordinates; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + public class PlayerTeleporter implements Listener { @@ -23,9 +40,44 @@ public class PlayerTeleporter implements Listener Cache.playerIslands.put(playerName, islandCoords); Location islandLocation = new Location(player.getWorld(), islandCoords.getX(), 64, islandCoords.getZ()); - islandLocation.getBlock().setType(Material.BEDROCK); - islandLocation.setY(islandLocation.getY() + 2); + // load chunk otherwise it will be buggy (no schem load, no tp) + islandLocation.getWorld().loadChunk(islandLocation.getChunk().getX(), islandLocation.getChunk().getZ(), true); + + + String testSchematicPath = LimboManager.getSchematicsFolder().getAbsolutePath() + File.separator + "endcityship.schem"; + File schematicFile = new File(testSchematicPath); + + if(!schematicFile.exists()) + System.out.println("no exist"); + + // todo: check if exists, but this is just a test + + World islandWEWorld = BukkitAdapter.adapt(islandLocation.getWorld()); + Clipboard shematicClipboard; + + ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(schematicFile); + try (ClipboardReader reader = clipboardFormat.getReader(new FileInputStream(schematicFile))) { + shematicClipboard = reader.read(); + + try (EditSession editSession = WorldEdit.getInstance().newEditSession(islandWEWorld)) { + Operation operation = new ClipboardHolder(shematicClipboard) + .createPaste(editSession) + .to(BlockVector3.at(islandLocation.getX(), 64, islandLocation.getZ())) + // configure here + .build(); + Operations.complete(operation); + editSession.flushSession(); + } catch (WorldEditException e) { + throw new RuntimeException(e); + } + + } catch (IOException e) { + throw new RuntimeException(e); + } + + + islandLocation.setY(islandLocation.getY() + 20); player.teleport(islandLocation); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f2d61e0..60cf668 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,8 @@ name: LimboManager main: wtf.beatrice.limbomanager.LimboManager -version: 0.0.1 +version: 0.0.2 description: Mix of tools to run a Limbo server api-version: 1.19 author: astro_bea +depend: + - WorldEdit \ No newline at end of file