Implement demo schematic loader
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9005db7872
commit
ea09d351bf
20
pom.xml
20
pom.xml
@ -20,6 +20,18 @@
|
|||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>enginehub-maven</id>
|
||||||
|
<url>https://maven.enginehub.org/repo/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>codemc</id>
|
||||||
|
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -36,6 +48,14 @@
|
|||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>23.0.0</version>
|
<version>23.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldedit</groupId>
|
||||||
|
<artifactId>worldedit-bukkit</artifactId>
|
||||||
|
<version>7.2.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -8,9 +8,12 @@ import wtf.beatrice.limbomanager.listeners.PlayerHider;
|
|||||||
import wtf.beatrice.limbomanager.listeners.PlayerTeleporter;
|
import wtf.beatrice.limbomanager.listeners.PlayerTeleporter;
|
||||||
import wtf.beatrice.limbomanager.listeners.RiskyBlocksHandler;
|
import wtf.beatrice.limbomanager.listeners.RiskyBlocksHandler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class LimboManager extends JavaPlugin {
|
public class LimboManager extends JavaPlugin {
|
||||||
|
|
||||||
private PluginManager pluginManager;
|
private PluginManager pluginManager;
|
||||||
|
private static String schematicsFolderPath;
|
||||||
private static LimboManager instance;
|
private static LimboManager instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -24,6 +27,11 @@ public class LimboManager extends JavaPlugin {
|
|||||||
pluginManager.registerEvents(new CommandCanceller(), this);
|
pluginManager.registerEvents(new CommandCanceller(), this);
|
||||||
pluginManager.registerEvents(new RiskyBlocksHandler(), 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;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File getSchematicsFolder() {
|
||||||
|
return new File(schematicsFolderPath);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,15 +1,32 @@
|
|||||||
package wtf.beatrice.limbomanager.listeners;
|
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.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import wtf.beatrice.limbomanager.Cache;
|
import wtf.beatrice.limbomanager.Cache;
|
||||||
|
import wtf.beatrice.limbomanager.LimboManager;
|
||||||
import wtf.beatrice.limbomanager.objects.Coordinates;
|
import wtf.beatrice.limbomanager.objects.Coordinates;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PlayerTeleporter implements Listener
|
public class PlayerTeleporter implements Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -23,9 +40,44 @@ public class PlayerTeleporter implements Listener
|
|||||||
Cache.playerIslands.put(playerName, islandCoords);
|
Cache.playerIslands.put(playerName, islandCoords);
|
||||||
|
|
||||||
Location islandLocation = new Location(player.getWorld(), islandCoords.getX(), 64, islandCoords.getZ());
|
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);
|
player.teleport(islandLocation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
name: LimboManager
|
name: LimboManager
|
||||||
main: wtf.beatrice.limbomanager.LimboManager
|
main: wtf.beatrice.limbomanager.LimboManager
|
||||||
version: 0.0.1
|
version: 0.0.2
|
||||||
description: Mix of tools to run a Limbo server
|
description: Mix of tools to run a Limbo server
|
||||||
api-version: 1.19
|
api-version: 1.19
|
||||||
author: astro_bea
|
author: astro_bea
|
||||||
|
depend:
|
||||||
|
- WorldEdit
|
Loading…
Reference in New Issue
Block a user