SteamWar/FightSystem
Archiviert
13
1

Schematic pasting refactoring #286

Manuell gemergt
Lixfel hat 5 Commits von weRefactoring nach master 2021-09-11 17:57:23 +02:00 zusammengeführt
9 geänderte Dateien mit 151 neuen und 239 gelöschten Zeilen
Nur Änderungen aus Commit eae23123c8 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,44 +19,14 @@
package de.steamwar.fightsystem.utils;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import org.bukkit.DyeColor;
import org.bukkit.Material;
@SuppressWarnings("deprecation")
public class WorldeditWrapper12 extends WorldeditWrapper8 {
@SuppressWarnings("deprecation")
private static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData();
@SuppressWarnings("deprecation")
private static final BaseBlock CONCRETE = new BaseBlock(Material.CONCRETE.getId(), COLOR_TO_REPLACE);
@SuppressWarnings("deprecation")
private static final BaseBlock CONCRETE_POWDER = new BaseBlock(Material.CONCRETE_POWDER.getId(), COLOR_TO_REPLACE);
@SuppressWarnings("deprecation")
@Override
public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException {
super.replaceTeamColor(clipboard, c);
Vector minimum = clipboard.getRegion().getMinimumPoint();
BaseBlock concrete = new BaseBlock(CONCRETE.getId(), c.getWoolData());
BaseBlock concretePowder = new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData());
for(int x = 0; x < clipboard.getDimensions().getX(); x++){
for(int y = 0; y < clipboard.getDimensions().getY(); y++){
for(int z = 0; z < clipboard.getDimensions().getZ(); z++){
Vector pos = minimum.add(x, y, z);
BaseBlock block = clipboard.getBlock(pos);
if(block.equals(CONCRETE)){
clipboard.setBlock(pos, concrete);
}else if(block.equals(CONCRETE_POWDER)){
clipboard.setBlock(pos, concretePowder);
}
}
}
}
static {
colorBlocks.add(new BaseBlock(Material.CONCRETE.getId(), COLOR_TO_REPLACE));
colorBlocks.add(new BaseBlock(Material.CONCRETE_POWDER.getId(), COLOR_TO_REPLACE));
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.sk89q.jnbt.NBTInputStream;
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.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -43,55 +44,44 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.zip.GZIPInputStream;
public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper {
private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock();
private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock();
private static final BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock();
private static final BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock();
private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock();
private static final BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock();
private static final BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock();
private static final Map<BaseBlock, String> colorBlocks = new HashMap<>();
static {
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(), "_wool");
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(), "_terracotta");
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(), "_stained_glass");
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(), "_stained_glass_pane");
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(), "_concrete");
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(), "_concrete_powder");
colorBlocks.put(Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(), "_carpet");
}
@Override
public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException {
BlockVector3 minimum = clipboard.getRegion().getMinimumPoint();
BaseBlock wool = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock();
BaseBlock clay = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock();
BaseBlock glass = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock();
BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock();
BaseBlock carpet = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock();
BaseBlock concrete = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_concrete")).getDefaultState().toBaseBlock();
BaseBlock concretePowder = Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_concrete_powder")).getDefaultState().toBaseBlock();
Map<BaseBlock, BaseBlock> replaceMap = new HashMap<>();
colorBlocks.forEach((base, postfix) -> replaceMap.put(base, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + postfix)).getDefaultState().toBaseBlock()));
for(int x = 0; x < clipboard.getDimensions().getX(); x++){
for(int y = 0; y < clipboard.getDimensions().getY(); y++){
for(int z = 0; z < clipboard.getDimensions().getZ(); z++){
BlockVector3 pos = minimum.add(x, y, z);
BaseBlock block = clipboard.getFullBlock(pos);
if(block.equals(WOOL)){
clipboard.setBlock(pos, wool);
}else if(block.equals(CLAY)){
clipboard.setBlock(pos, clay);
}else if(block.equals(GLASS)){
clipboard.setBlock(pos, glass);
}else if(block.equals(GLASS_PANE)){
clipboard.setBlock(pos, glassPane);
}else if(block.equals(CARPET)){
clipboard.setBlock(pos, carpet);
}else if(block.equals(CONCRETE)){
clipboard.setBlock(pos, concrete);
}else if(block.equals(CONCRETE_POWDER)){
clipboard.setBlock(pos, concretePowder);
}
BaseBlock replacement = replaceMap.get(clipboard.getFullBlock(pos));
if(replacement != null)
clipboard.setBlock(pos, replacement);
}
}
}
@ -99,22 +89,18 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper {
@Override
public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) {
BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ());
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0);
BlockVector3 dimensions = clipboard.getDimensions();
BlockVector3 v;
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
AffineTransform aT = new AffineTransform();
BlockVector3 v = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ());
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);
v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(1, 0, 1);
}else{
v = paste.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset);
v = v.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2);
}
v = v.subtract(aT.apply(clipboardOffset(clipboard).toVector3()).toBlockPoint());
if(Config.WaterDepth != 0){
BlockVector3 it = clipboard.getMinimumPoint();
BlockVector3 it = clipboard.getMinimumPoint().add(0, 0, 1);
int depth = 0;
while(!clipboard.getBlock(it).getBlockType().getMaterial().isAir()){
depth++;
@ -123,24 +109,24 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper {
v = v.add(0, Config.WaterDepth - depth, 0);
}
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ClipboardHolder ch = new ClipboardHolder(clipboard);
ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e).to(v).build());
e.flushSession();
pasteClipboard(Bukkit.getWorlds().get(0), clipboard, aT, v, false);
}
@Override
public void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT) {
BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin());
BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset);
v = aT.apply(v.toVector3()).toBlockPoint();
v = v.add(x, y, z);
public void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT) {
BlockVector3 v = aT.apply(BlockVector3.at(xOffset, 0, 0).subtract(clipboardOffset(character)).toVector3()).toBlockPoint();
pasteClipboard(pos.getWorld(), character, aT, v.add(BukkitAdapter.asBlockVector(pos)), true);
}
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1);
ClipboardHolder ch = new ClipboardHolder(character);
private BlockVector3 clipboardOffset(Clipboard clipboard) {
return clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
}
private void pasteClipboard(org.bukkit.World world, Clipboard clipboard, AffineTransform aT, BlockVector3 pos, boolean ignoreAir) {
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(world), -1);
ClipboardHolder ch = new ClipboardHolder(clipboard);
ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build());
Operations.completeBlindly(ch.createPaste(e).to(pos).ignoreAirBlocks(ignoreAir).build());
e.flushSession();
}
@ -150,21 +136,17 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper {
}
@Override
public void saveSchem(Schematic schem, Region region, int minY) {
public void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
BlockVector3 min = BlockVector3.at(region.getMinX(), minY, region.getMinZ());
CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ()));
BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min);
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(
WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1), cuboidRegion, clipboard, min
);
forwardExtentCopy.setCopyingEntities(false);
try{
Operations.complete(forwardExtentCopy);
}catch(WorldEditException e){
throw new IllegalStateException(e);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
@ -172,7 +154,7 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper {
writer.write(clipboard);
writer.close();
} catch (IOException e) {
throw new IllegalStateException(e);
throw new SecurityException(e);
}
schem.saveFromBytes(outputStream.toByteArray(), true);

Datei anzeigen

@ -42,56 +42,46 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
@SuppressWarnings("deprecation")
public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper {
@SuppressWarnings("deprecation")
private static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData();
protected static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData();
protected static final Set<BaseBlock> colorBlocks = new HashSet<>();
@SuppressWarnings("deprecation")
private static final BaseBlock WOOL = new BaseBlock(Material.WOOL.getId(), COLOR_TO_REPLACE);
@SuppressWarnings("deprecation")
private static final BaseBlock GLASS = new BaseBlock(Material.STAINED_GLASS.getId(), COLOR_TO_REPLACE);
@SuppressWarnings("deprecation")
private static final BaseBlock CLAY = new BaseBlock(Material.CLAY.getId(), COLOR_TO_REPLACE);
@SuppressWarnings("deprecation")
private static final BaseBlock GLASS_PANE = new BaseBlock(Material.STAINED_GLASS_PANE.getId(), COLOR_TO_REPLACE);
@SuppressWarnings("deprecation")
private static final BaseBlock CARPET = new BaseBlock(Material.CARPET.getId(), COLOR_TO_REPLACE);
static {
colorBlocks.add(new BaseBlock(Material.WOOL.getId(), COLOR_TO_REPLACE));
colorBlocks.add(new BaseBlock(Material.STAINED_GLASS.getId(), COLOR_TO_REPLACE));
colorBlocks.add(new BaseBlock(Material.CLAY.getId(), COLOR_TO_REPLACE));
colorBlocks.add(new BaseBlock(Material.STAINED_GLASS_PANE.getId(), COLOR_TO_REPLACE));
colorBlocks.add(new BaseBlock(Material.CARPET.getId(), COLOR_TO_REPLACE));
}
@SuppressWarnings("deprecation")
@Override
public void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException {
Vector minimum = clipboard.getRegion().getMinimumPoint();
BaseBlock wool = new BaseBlock(WOOL.getId(), c.getWoolData());
BaseBlock clay = new BaseBlock(CLAY.getId(), c.getWoolData());
BaseBlock glass = new BaseBlock(GLASS.getId(), c.getWoolData());
BaseBlock glassPane = new BaseBlock(GLASS_PANE.getId(), c.getWoolData());
BaseBlock carpet = new BaseBlock(CARPET.getId(), c.getWoolData());
Map<BaseBlock, BaseBlock> replaceMap = new HashMap<>();
colorBlocks.forEach(base -> replaceMap.put(base, new BaseBlock(base.getId(), c.getWoolData())));
for(int x = 0; x < clipboard.getDimensions().getX(); x++){
for(int y = 0; y < clipboard.getDimensions().getY(); y++){
for(int z = 0; z < clipboard.getDimensions().getZ(); z++){
Vector pos = minimum.add(x, y, z);
BaseBlock block = clipboard.getBlock(pos);
if(block.equals(WOOL)){
clipboard.setBlock(pos, wool);
}else if(block.equals(CLAY)){
clipboard.setBlock(pos, clay);
}else if(block.equals(GLASS)){
clipboard.setBlock(pos, glass);
}else if(block.equals(GLASS_PANE)){
clipboard.setBlock(pos, glassPane);
}else if(block.equals(CARPET)){
clipboard.setBlock(pos, carpet);
}
BaseBlock replacement = replaceMap.get(clipboard.getBlock(pos));
if(replacement != null)
clipboard.setBlock(pos, replacement);
}
}
}
@ -99,47 +89,45 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper {
@Override
public void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0);
Vector dimensions = clipboard.getDimensions();
Vector v = new Vector(region.centerX(), region.getMinY(), region.centerZ());
Vector offset = clipboard.getMinimumPoint().subtract(clipboard.getOrigin());
AffineTransform aT = new AffineTransform();
if(rotate){
aT = aT.rotateY(180);
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);
v = v.add(dimensions.getX()/2 + dimensions.getX()%2, 0, dimensions.getZ()/2 + dimensions.getZ()%2).subtract(1, 0, 1);
}else{
v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset);
v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2);
}
v = v.subtract(aT.apply(clipboardOffset(clipboard)).toBlockPoint());
if(Config.WaterDepth != 0){
Vector it = clipboard.getMinimumPoint();
Vector it = clipboard.getMinimumPoint().add(0, 0, 1);
int depth = 0;
while(!clipboard.getBlock(it).isAir()) {
depth++;
it = it.setY(it.getY()+1);
it = it.add(0, 1, 0);
}
v = v.add(0, Config.WaterDepth - depth, 0);
}
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();
pasteClipboard(Bukkit.getWorlds().get(0), clipboard, aT, v, false);
}
@Override
public void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin());
Vector v = Vector.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset);
v = aT.apply(v).toBlockPoint();
v = v.add(x, y, z);
public void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT) {
Vector v = aT.apply(new Vector(xOffset, 0, 0).subtract(clipboardOffset(character))).toBlockPoint();
pasteClipboard(pos.getWorld(), character, aT, v.add(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), true);
}
private Vector clipboardOffset(Clipboard clipboard) {
return clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
}
private void pasteClipboard(org.bukkit.World world, Clipboard clipboard, AffineTransform aT, Vector pos, boolean ignoreAir) {
World w = new BukkitWorld(world);
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ClipboardHolder ch = new ClipboardHolder(character, w.getWorldData());
ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData());
ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build());
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(pos).ignoreAirBlocks(ignoreAir).build());
e.flushQueue();
}
@ -149,19 +137,16 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper {
}
@Override
public void saveSchem(Schematic schem, Region region, int minY) {
public void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector min = new Vector(region.getMinX(), minY, region.getMinZ());
CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ()));
BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min);
try{
ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(
WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1), cuboidRegion, clipboard, min
);
Operations.complete(forwardExtentCopy);
}catch(WorldEditException e){
throw new IllegalStateException(e);
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
@ -169,7 +154,7 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper {
writer.write(clipboard, w.getWorldData());
writer.close();
} catch (IOException e) {
throw new IllegalStateException(e);
throw new SecurityException(e);
}
schem.saveFromBytes(outputStream.toByteArray(), false);

Datei anzeigen

@ -145,11 +145,7 @@ public class FightSystem extends JavaPlugin {
}else if(Config.mode == ArenaMode.CHECK){
Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.CheckSchemID));
}else if(Config.mode == ArenaMode.PREPARE) {
if(Config.BlueRotate){
Fight.getRedTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID));
}else{
Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID));
}
Fight.getUnrotated().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID));
}else if(Config.mode == ArenaMode.REPLAY) {
FightWorld.forceLoad();
FileSource.startReplay();

Datei anzeigen

@ -88,6 +88,10 @@ public class Fight {
return blueTeam;
}
public static FightTeam getUnrotated() {
return Config.BlueRotate ? Fight.getRedTeam() : Fight.getBlueTeam();
}
public static void playSound(Sound sound, float volume, float pitch) {
GlobalRecorder.getInstance().soundAtPlayer(sound.name(), volume, pitch);
//volume: max. 100, pitch: max. 2

Datei anzeigen

@ -32,15 +32,11 @@ import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.Region;
import de.steamwar.fightsystem.utils.WorldeditWrapper;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.event.HandlerList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
@ -75,7 +71,7 @@ public class FightSchematic extends StateDependent {
try {
clipboard = schem.load();
} catch (IOException e) {
team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!");
team.broadcast(FightSystem.PREFIX + "§cSchematic konnte nicht geladen werden!");
Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getSchemName());
}
}
@ -137,60 +133,6 @@ public class FightSchematic extends StateDependent {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
}
private Clipboard loadTextSchem(String schemName) throws IOException {
return WorldeditWrapper.impl.loadChar(schemName);
}
public void pasteTeamName(){
List<Clipboard> characters = new ArrayList<>();
for(char c : team.getName().toCharArray()){
try {
characters.add(loadTextSchem(c == '/' ? "slash" : String.valueOf(c)));
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", c);
try {
characters.add(loadTextSchem(""));
}catch (IOException ex) {
throw new SecurityException("Could not load text", ex);
}
}
}
//Calc character sizes
int[] lengthes = new int[characters.size()];
for(int i = 0; i < lengthes.length; i++)
lengthes[i] = characters.get(i).getDimensions().getBlockX();
//Calc character offsets
int[] offsets = new int[lengthes.length];
int previousOffset = 0;
for(int i = 0; i < offsets.length; i++){
offsets[i] = previousOffset;
previousOffset += lengthes[i] + 1; // 1 is the distance between characters
}
int length = lengthes.length == 0 ? 0 : lengthes[lengthes.length - 1] + offsets[offsets.length - 1];
int z = team.getSchemRegion().centerZ();
AffineTransform aT = new AffineTransform();
if(rotate){
aT = aT.rotateY(180);
z += team.getSchemRegion().getSizeZ() / 2;
}else{
z -= team.getSchemRegion().getSizeZ() / 2;
}
for(int i = 0; i < characters.size(); i++){
try {
replaceTeamColor(characters.get(i));
} catch (WorldEditException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e);
}
WorldeditWrapper.impl.pasteChar(characters.get(i), offsets[i], length, team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), z, aT);
}
}
@Override
public void disable() {
if(!Config.ReplaceObsidianBedrock)
@ -207,6 +149,45 @@ public class FightSchematic extends StateDependent {
HandlerList.unregisterAll(freezer);
}
public void pasteTeamName(){
char[] chars = team.getName().toCharArray();
Clipboard[] characters = new Clipboard[chars.length];
int length = 0;
int[] offsets = new int[chars.length];
for(int i = 0; i < chars.length; i++){
Clipboard character;
try {
character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i]));
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", chars[i]);
try {
character = WorldeditWrapper.impl.loadChar("");
}catch (IOException ex) {
throw new SecurityException("Could not load text", ex);
}
}
try {
replaceTeamColor(character);
} catch (WorldEditException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e);
}
characters[i] = character;
offsets[i] = length;
length += character.getDimensions().getBlockX() + 1; // 1 is the distance between characters
}
length -= 1;
AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0);
Location base = new Location(Bukkit.getWorlds().get(0), team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), team.getSchemRegion().centerZ() + (rotate ? 1 : -1) * team.getSchemRegion().getSizeZ() / 2);
for(int i = 0; i < characters.length; i++){
WorldeditWrapper.impl.pasteChar(characters[i], base, offsets[i] - length/2, aT);
}
}
private void replaceSync(Material target, Material replacement){
World world = Bukkit.getWorlds().get(0);

Datei anzeigen

@ -305,7 +305,7 @@ public class FightTeam {
private void testPasteAction(){
if(Config.test())
this.schematic.enable();
else if(Fight.getOpposite(this).hasSchematic()){
else if(Fight.getOpposite(this).schematic.hasSchematic()){
FightSystem.setPostSchemState();
}
}
@ -319,10 +319,6 @@ public class FightTeam {
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");
}
public boolean hasSchematic(){
return schematic.hasSchematic();
}
public void setReady(boolean ready) {
Player l = leader.getPlayer();

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.fightsystem.listener;
import com.sk89q.worldedit.WorldEditException;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
@ -45,8 +46,8 @@ public class PrepareSchem implements Listener {
public void disable() {
super.disable();
World world = Bukkit.getWorlds().get(0);
Region region = Config.BlueRotate ? Fight.getRedTeam().getExtendRegion() : Fight.getBlueTeam().getExtendRegion();
int minY = Config.BlueRotate ? Fight.getRedTeam().getSchemRegion().getMinY() : Fight.getBlueTeam().getSchemRegion().getMinY();
Region region = Fight.getUnrotated().getExtendRegion();
int minY = Fight.getUnrotated().getSchemRegion().getMinY();
Schematic schem;
try{
@ -69,7 +70,7 @@ public class PrepareSchem implements Listener {
try{
WorldeditWrapper.impl.saveSchem(schem, region, minY);
}catch(IllegalStateException e){
}catch(WorldEditException e){
FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen.");
throw new SecurityException("Could not save schem", e);
}
@ -86,11 +87,7 @@ public class PrepareSchem implements Listener {
FightTeam team = Fight.getPlayerTeam(player);
if (team == null) {
if(Config.BlueRotate){
Fight.getRedTeam().addMember(player);
}else{
Fight.getBlueTeam().addMember(player);
}
Fight.getUnrotated().addMember(player);
}
if(FightState.getFightState() == FightState.PRE_LEADER_SETUP) {

Datei anzeigen

@ -25,6 +25,7 @@ import com.sk89q.worldedit.math.transform.AffineTransform;
import de.steamwar.fightsystem.VersionDependent;
import de.steamwar.sql.Schematic;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import java.io.IOException;
@ -36,8 +37,8 @@ public class WorldeditWrapper {
public interface IWorldeditWrapper {
void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException;
void pasteSchematic(Clipboard clipboard, Region region, boolean rotate);
void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT);
void pasteChar(Clipboard character, Location pos, int xOffset, AffineTransform aT);
Clipboard loadChar(String charName) throws IOException;
void saveSchem(Schematic schem, Region region, int minY);
void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException;
}
}