Implementing custom testblock & reset region capability
Dieser Commit ist enthalten in:
Ursprung
f9d5bc89e8
Commit
19adf2eedb
@ -45,11 +45,5 @@
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>FAWE</artifactId>
|
||||
<version>1.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,13 +1,19 @@
|
||||
package de.steamwar.bausystem.world;
|
||||
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.object.schematic.Schematic;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -15,15 +21,23 @@ public class Region_12 {
|
||||
private Region_12(){}
|
||||
|
||||
static void paste(File file, int x, int y, int z, boolean rotate){
|
||||
Schematic schem;
|
||||
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
schem = FaweAPI.load(file);
|
||||
}catch(IOException e){
|
||||
clipboard = Objects.requireNonNull(ClipboardFormat.findByFile(file)).getReader(new FileInputStream(file)).read(w.getWorldData());
|
||||
} catch (NullPointerException | IOException e) {
|
||||
throw new SecurityException("Bausystem schematic not found", e);
|
||||
}
|
||||
Vector dimensions = Objects.requireNonNull(schem.getClipboard()).getDimensions();
|
||||
|
||||
paste(clipboard, x, y, z, rotate);
|
||||
}
|
||||
|
||||
static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){
|
||||
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
|
||||
Vector dimensions = clipboard.getDimensions();
|
||||
Vector v = new Vector(x, y, z);
|
||||
Vector offset = new Vector(schem.getClipboard().getRegion().getMinimumPoint()).subtract(schem.getClipboard().getOrigin());
|
||||
Vector offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
||||
AffineTransform aT = new AffineTransform();
|
||||
if(rotate){
|
||||
aT = aT.rotateY(180);
|
||||
@ -31,6 +45,11 @@ public class Region_12 {
|
||||
}else{
|
||||
v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset);
|
||||
}
|
||||
schem.paste(new BukkitWorld(Bukkit.getWorlds().get(0)), v, false, true, aT).flushQueue();
|
||||
|
||||
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
|
||||
ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData());
|
||||
ch.setTransform(aT);
|
||||
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build());
|
||||
e.flushQueue();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package de.steamwar.bausystem.world;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
@ -9,7 +10,13 @@ import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -27,6 +34,10 @@ public class Region_15 {
|
||||
throw new SecurityException("Bausystem schematic not found", e);
|
||||
}
|
||||
|
||||
paste(clipboard, x, y, z, rotate);
|
||||
}
|
||||
|
||||
static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){
|
||||
BlockVector3 dimensions = clipboard.getDimensions();
|
||||
BlockVector3 v = BlockVector3.at(x, y, z);
|
||||
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
||||
@ -44,4 +55,42 @@ public class Region_15 {
|
||||
Operations.completeBlindly(ch.createPaste(e).to(v).build());
|
||||
e.flushSession();
|
||||
}
|
||||
|
||||
static void fastpaste(File file, int x, int y, int z, boolean rotate){
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file)).read();
|
||||
} catch (NullPointerException | IOException e) {
|
||||
throw new SecurityException("Bausystem schematic not found", e);
|
||||
}
|
||||
|
||||
BlockVector3 dimensions = clipboard.getDimensions();
|
||||
BlockVector3 v = BlockVector3.at(x, y, z);
|
||||
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
||||
if(rotate){
|
||||
v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1);
|
||||
}else{
|
||||
v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset);
|
||||
}
|
||||
|
||||
WorldServer world = ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle();
|
||||
v = v.add(offset);
|
||||
|
||||
for(int X = v.getBlockX(); X < v.getBlockX() + dimensions.getBlockX(); X++){
|
||||
for(int Y = v.getBlockY(); Y < v.getBlockY() + dimensions.getBlockY(); Y++){
|
||||
for(int Z = v.getBlockZ(); Z < v.getBlockZ() + dimensions.getBlockZ(); Z++){
|
||||
BlockPosition blockPos = new BlockPosition(X, Y, Z);
|
||||
BaseBlock fullBlock = clipboard.getFullBlock(BlockVector3.at(X, Y, Z).subtract(v).add(clipboard.getRegion().getMinimumPoint()));
|
||||
Material replaceTo = BukkitAdapter.adapt(fullBlock.getBlockType());
|
||||
world.removeTileEntity(blockPos);
|
||||
if(replaceTo == null)
|
||||
world.setTypeAndData(blockPos, ((CraftBlockData)Material.AIR.createBlockData()).getState(), 1042);
|
||||
else
|
||||
world.setTypeAndData(new BlockPosition(X, Y, Z), ((CraftBlockData)replaceTo.createBlockData()).getState(), 1042);
|
||||
|
||||
world.getChunkProvider().flagDirty(blockPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,5 +67,11 @@
|
||||
<version>1.15</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>WorldEdit</artifactId>
|
||||
<version>1.15</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -4,6 +4,7 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.world.ArenaSection;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import de.steamwar.sql.Schematic;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -28,7 +29,16 @@ public class CommandReset implements CommandExecutor {
|
||||
for(ArenaSection section : BauSystem.getSections()){
|
||||
if(section.inRegion(player.getLocation())){
|
||||
try {
|
||||
section.reset();
|
||||
if(args.length > 0){
|
||||
Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
|
||||
if(schem == null){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
|
||||
return false;
|
||||
}
|
||||
section.reset(schem);
|
||||
}else{
|
||||
section.fastreset();
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt");
|
||||
}catch(Exception e){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region");
|
||||
|
@ -4,11 +4,15 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.world.ArenaSection;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.Schematic;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CommandTestblock implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
@ -24,7 +28,21 @@ public class CommandTestblock implements CommandExecutor {
|
||||
|
||||
for(ArenaSection section : BauSystem.getSections()){
|
||||
if(section.inRegion(player.getLocation())){
|
||||
section.getTestblock().reset();
|
||||
if(args.length > 0){
|
||||
Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId());
|
||||
if(schem == null){
|
||||
player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
section.getTestblock().reset(schem);
|
||||
} catch (IOException | NoClipboardException e) {
|
||||
player.sendMessage(BauSystem.PREFIX + "§cFehler beim Laden der Schematic");
|
||||
throw new SecurityException("Failed to load Testblock Schematic", e);
|
||||
}
|
||||
}else{
|
||||
section.getTestblock().reset();
|
||||
}
|
||||
player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
|
||||
return false;
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package de.steamwar.bausystem.world;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import de.steamwar.sql.Schematic;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Region {
|
||||
final int sizeX;
|
||||
@ -38,11 +42,20 @@ public class Region {
|
||||
return min <= l && l <= min + size;
|
||||
}
|
||||
|
||||
public void fastreset(){
|
||||
File file = new File(BauSystem.SECTION_PATH + schematic);
|
||||
fastpaste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
File file = new File(BauSystem.SECTION_PATH + schematic);
|
||||
paste(file, minX + sizeX/2, minY, minZ + sizeZ/2, rotate);
|
||||
}
|
||||
|
||||
public void reset(Schematic schem) throws IOException, NoClipboardException {
|
||||
paste(schem.load(), minX + sizeX/2, minY, minZ + sizeZ/2, rotate);
|
||||
}
|
||||
|
||||
static void paste(File file, int x, int y, int z, boolean rotate){
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
@ -52,4 +65,24 @@ public class Region {
|
||||
Region_12.paste(file, x, y, z, rotate);
|
||||
}
|
||||
}
|
||||
|
||||
private static void fastpaste(File file, int x, int y, int z, boolean rotate){
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
Region_15.fastpaste(file, x, y, z, rotate);
|
||||
break;
|
||||
default:
|
||||
Region_12.paste(file, x, y, z, rotate);
|
||||
}
|
||||
}
|
||||
|
||||
private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){
|
||||
switch(Core.getVersion()){
|
||||
case 15:
|
||||
Region_15.paste(clipboard, x, y, z, rotate);
|
||||
break;
|
||||
default:
|
||||
Region_12.paste(clipboard, x, y, z, rotate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren