SteamWar/FightSystem
Archiviert
13
1

Schematic Rework

Dieser Commit ist enthalten in:
Lixfel 2019-12-09 12:01:33 +01:00
Ursprung 691f3d8cfa
Commit 09f7711fe2
4 geänderte Dateien mit 59 neuen und 93 gelöschten Zeilen

Datei anzeigen

@ -1,25 +1,20 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import org.bukkit.Bukkit; import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
public class FightTeam_12 { public class FightTeam_12 {
private FightTeam_12(){} private FightTeam_12(){}
@ -50,40 +45,7 @@ public class FightTeam_12 {
e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData())); e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData()));
} }
static EditSession pasteSchematic(File file, int pasteX, int pasteY, int pasteZ, boolean rotate){ static EditSession pasteSchematic(Schematic schematic, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
com.boydti.fawe.object.schematic.Schematic schem; return FightTeam_8.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
Vector paste = new Vector(pasteX, pasteY, pasteZ);
try {
schem = FaweAPI.load(file);
if(schem.getClipboard() == null)
throw new IOException();
}catch(IOException e){
Bukkit.getLogger().log(Level.SEVERE, "Failed loading Schematic", e);
return null;
}
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector dimensions = schem.getClipboard().getDimensions();
Vector v;
Vector offset = new Vector(schem.getClipboard().getRegion().getMinimumPoint()).subtract(schem.getClipboard().getOrigin());
AffineTransform aT = new AffineTransform();
if(rotate){
aT = aT.rotateY(180);
v = paste.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 = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset);
}
if(Config.AlignWater){
Vector it = schem.getClipboard().getMinimumPoint();
int depth = 0;
while(!schem.getClipboard().getBlock(it).isAir()){
depth++;
it = it.setY(it.getY()+1);
}
v = v.add(0, Config.WaterDepth - depth, 0);
}
return schem.paste(w, v, false, true, aT);
} }
} }

Datei anzeigen

@ -1,25 +1,28 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
class FightTeam_14 { class FightTeam_14 {
private FightTeam_14(){} private FightTeam_14(){}
@ -48,22 +51,14 @@ class FightTeam_14 {
e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(BlockState.get(c.name() + "_CONCRETE_POWDER"))); e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(BlockState.get(c.name() + "_CONCRETE_POWDER")));
} }
static EditSession pasteSchematic(File file, int pX, int pY, int pZ, boolean rotate){ static EditSession pasteSchematic(Schematic schematic, int pX, int pY, int pZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
BlockVector3 paste = BlockVector3.at(pX, pY, pZ); BlockVector3 paste = BlockVector3.at(pX, pY, pZ);
com.boydti.fawe.object.schematic.Schematic schem; Clipboard clipboard = schematic.load();
try {
schem = FaweAPI.load(file);
if(schem.getClipboard() == null)
throw new IOException();
}catch(IOException e){
Bukkit.getLogger().log(Level.SEVERE, "Failed loading Schematic", e);
return null;
}
World w = new BukkitWorld(Bukkit.getWorlds().get(0)); World w = new BukkitWorld(Bukkit.getWorlds().get(0));
BlockVector3 dimensions = schem.getClipboard().getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
BlockVector3 v; BlockVector3 v;
BlockVector3 offset = schem.getClipboard().getRegion().getMinimumPoint().subtract(schem.getClipboard().getOrigin()); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
AffineTransform aT = new AffineTransform(); AffineTransform aT = new AffineTransform();
if(rotate){ if(rotate){
aT = aT.rotateY(180); aT = aT.rotateY(180);
@ -73,15 +68,24 @@ class FightTeam_14 {
} }
if(Config.AlignWater){ if(Config.AlignWater){
BlockVector3 it = schem.getClipboard().getMinimumPoint(); BlockVector3 it = clipboard.getMinimumPoint();
int depth = 0; int depth = 0;
while(!schem.getClipboard().getBlock(it).getMaterial().isAir()){ while(!clipboard.getBlock(it).getMaterial().isAir()){
depth++; depth++;
it = it.add(0, 1, 0); it = it.add(0, 1, 0);
} }
v = v.add(0, Config.WaterDepth - depth, 0); v = v.add(0, Config.WaterDepth - depth, 0);
} }
return schem.paste(w, v, false, true, aT); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ClipboardHolder ch = new ClipboardHolder(clipboard);
ch.setTransform(aT);
try {
ch.createPaste(e).to(v).build();
} catch (MaxChangedBlocksException ex) {
throw new IOException(ex);
}
e.flushQueue();
return e;
} }
} }

Datei anzeigen

@ -3,12 +3,15 @@ package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.schematic.SchematicFormat; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
@ -20,11 +23,9 @@ import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
class FightTeam_8 { class FightTeam_8 {
private FightTeam_8(){} private FightTeam_8(){}
@ -65,23 +66,17 @@ class FightTeam_8 {
} }
} }
static EditSession pasteSchematic(File file, int pasteX, int pasteY, int pasteZ, boolean rotate){ static EditSession pasteSchematic(Schematic schematic, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException {
Vector paste = new Vector(pasteX, pasteY, pasteZ); Vector paste = new Vector(pasteX, pasteY, pasteZ);
CuboidClipboard clipboard; Clipboard clipboard = schematic.load();
try {
clipboard = SchematicFormat.getFormat(file).load(file);
}catch(IOException | DataException e){
Bukkit.getLogger().log(Level.SEVERE, "Failed loading Schematic", e);
return null;
}
World w = new BukkitWorld(Bukkit.getWorlds().get(0)); World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector dimensions = clipboard.getSize(); Vector dimensions = clipboard.getDimensions();
Vector v; Vector v;
Vector offset = new Vector(clipboard.getOffset()); Vector offset = new Vector(clipboard.getOrigin());
AffineTransform aT = new AffineTransform();
if(rotate){ if(rotate){
clipboard.rotate2D(180); aT.rotateY(180);
v = paste.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); v = paste.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{ }else{
v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); v = paste.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset);
@ -100,11 +95,9 @@ class FightTeam_8 {
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
FreezeWorld freezer = new FreezeWorld(); FreezeWorld freezer = new FreezeWorld();
Bukkit.getPluginManager().registerEvents(freezer, IFightSystem.getPlugin()); Bukkit.getPluginManager().registerEvents(freezer, IFightSystem.getPlugin());
try { ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData());
clipboard.paste(e, v, false, true); ch.setTransform(aT);
} catch (MaxChangedBlocksException ex) { ch.createPaste(e, w.getWorldData()).to(v).build();
//ignore
}
e.flushQueue(); e.flushQueue();
HandlerList.unregisterAll(freezer); HandlerList.unregisterAll(freezer);
return e; return e;

Datei anzeigen

@ -10,8 +10,8 @@ import de.steamwar.fightsystem.utils.FightScoreboard;
import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.ItemBuilder;
import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
import javafx.util.Pair; import javafx.util.Pair;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -19,7 +19,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import java.io.File; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -216,17 +216,24 @@ public class FightTeam implements IFightTeam{
} }
private void pasteSchematic(){ private void pasteSchematic(){
File file = new File(Config.SchematicDirectory + SteamwarUser.get(schematic.getSchemOwner()).getUUID().toString(), schematic.getSchemName() + ".schematic");
EditSession e; EditSession e;
try {
switch(Core.getVersion()){ switch(Core.getVersion()){
case 8: case 8:
e = FightTeam_8.pasteSchematic(file, pasteX, pasteY, pasteZ, rotate); e = FightTeam_8.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
break; break;
case 14: case 14:
e = FightTeam_14.pasteSchematic(file, pasteX, pasteY, pasteZ, rotate); e = FightTeam_14.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
break; break;
default: default:
e = FightTeam_12.pasteSchematic(file, pasteX, pasteY, pasteZ, rotate); e = FightTeam_12.pasteSchematic(schematic, pasteX, pasteY, pasteZ, rotate);
}
} catch (Schematic.WrongVersionException ex) {
broadcast(FightSystem.PREFIX + "§cDie gewählte Schematic kann nicht in dieser Version geladen werden");
return;
} catch (IOException | NoClipboardException ex) {
broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
throw new SecurityException("Error pasting arena in schematic", ex);
} }
replaceTeamColor(e); replaceTeamColor(e);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40);