SteamWar/FightSystem
Archiviert
13
1

Omni-Replay #280

Manuell gemergt
Lixfel hat 15 Commits von spectate2.0 nach master 2021-08-27 22:12:03 +02:00 zusammengeführt
9 geänderte Dateien mit 177 neuen und 197 gelöschten Zeilen
Nur Änderungen aus Commit 573c518e33 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -27,6 +28,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -38,7 +40,6 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -102,7 +103,7 @@ public class FightTeam_14 {
} }
} }
static void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) throws NoClipboardException { static void pasteSchematic(Clipboard clipboard, Region region, boolean rotate) {
BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ());
World w = new BukkitWorld(Bukkit.getWorlds().get(0)); World w = new BukkitWorld(Bukkit.getWorlds().get(0));
@ -134,6 +135,23 @@ public class FightTeam_14 {
e.flushSession(); e.flushSession();
} }
static 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);
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1);
ClipboardHolder ch = new ClipboardHolder(character);
ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build());
e.flushSession();
}
static Clipboard loadSchem(NBTInputStream stream) throws IOException {
return new SpongeSchematicReader(stream).read();
}
public static boolean checkPistonMoving(Block block){ public static boolean checkPistonMoving(Block block){
return block.getType() == Material.MOVING_PISTON; return block.getType() == Material.MOVING_PISTON;
} }

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
@ -29,6 +30,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.extent.clipboard.io.SchematicReader;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
@ -37,7 +39,6 @@ import com.sk89q.worldedit.session.ClipboardHolder;
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.utils.Region; import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -99,7 +100,7 @@ public class FightTeam_8 {
} }
} }
static void pasteSchematic(Clipboard clipboard, Region paste, boolean rotate) throws NoClipboardException { static void pasteSchematic(Clipboard clipboard, Region paste, boolean rotate) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0)); World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector dimensions = clipboard.getDimensions(); Vector dimensions = clipboard.getDimensions();
Vector v = new Vector(paste.centerX(), paste.getMinY(), paste.centerZ()); Vector v = new Vector(paste.centerX(), paste.getMinY(), paste.centerZ());
@ -129,6 +130,24 @@ public class FightTeam_8 {
e.flushQueue(); e.flushQueue();
} }
static 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);
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ClipboardHolder ch = new ClipboardHolder(character, w.getWorldData());
ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build());
e.flushQueue();
}
static Clipboard loadSchem(NBTInputStream stream) throws IOException {
return new SchematicReader(stream).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData());
}
public static boolean checkPistonMoving(Block block){ public static boolean checkPistonMoving(Block block){
return block.getType() == Material.PISTON_MOVING_PIECE; return block.getType() == Material.PISTON_MOVING_PIECE;
} }

Datei anzeigen

@ -71,6 +71,10 @@ public class Region {
return maxZ; return maxZ;
} }
public int getSizeZ() {
return maxZ - minZ;
}
public double posToChunk(int pos){ public double posToChunk(int pos){
return pos / 16.0; return pos / 16.0;
} }

Datei anzeigen

@ -19,8 +19,11 @@
package de.steamwar.fightsystem.fight; package de.steamwar.fightsystem.fight;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.transform.AffineTransform;
import de.steamwar.core.VersionedCallable;
import de.steamwar.core.VersionedRunnable; import de.steamwar.core.VersionedRunnable;
import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
@ -30,7 +33,6 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.Region;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
@ -39,10 +41,14 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.zip.GZIPInputStream;
public class FightSchematic extends StateDependent { public class FightSchematic extends StateDependent {
@ -75,7 +81,7 @@ public class FightSchematic extends StateDependent {
clipboard = schem.load(); clipboard = schem.load();
} catch (IOException e) { } catch (IOException e) {
team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!"); team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!");
Bukkit.getLogger().log(Level.SEVERE, "Couldn't load Schematic " + schem.getSchemName(), e); Bukkit.getLogger().log(Level.SEVERE, e, () -> "Couldn't load Schematic " + schem.getSchemName());
} }
} }
@ -111,33 +117,38 @@ public class FightSchematic extends StateDependent {
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste);
} }
private void paste(){ private void replaceTeamColor(Clipboard clipboard){
FreezeWorld freezer = new FreezeWorld();
DyeColor c = ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK; DyeColor c = ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK;
try {
VersionedRunnable.call(new VersionedRunnable(() -> { VersionedRunnable.call(new VersionedRunnable(() -> {
try { try {
FightTeam_8.replaceTeamColor(clipboard, c); FightTeam_8.replaceTeamColor(clipboard, c);
FightTeam_8.pasteSchematic(clipboard, region, rotate); } catch (WorldEditException ex) {
} catch (NoClipboardException | WorldEditException ex) { throw new SecurityException("Error recoloring schematic", ex);
throw new SecurityException("Error pasting schematic", ex);
} }
}, 8), new VersionedRunnable(() -> { }, 8),
new VersionedRunnable(() -> {
try { try {
FightTeam_12.replaceTeamColor(clipboard, c); FightTeam_12.replaceTeamColor(clipboard, c);
FightTeam_8.pasteSchematic(clipboard, region, rotate); } catch (WorldEditException ex) {
} catch (NoClipboardException | WorldEditException ex) { throw new SecurityException("Error recoloring schematic", ex);
throw new SecurityException("Error pasting schematic", ex);
} }
}, 12), new VersionedRunnable(() -> { }, 12),
new VersionedRunnable(() -> {
try { try {
FightTeam_14.replaceTeamColor(clipboard, c); FightTeam_14.replaceTeamColor(clipboard, c);
FightTeam_14.pasteSchematic(clipboard, region, rotate); } catch (WorldEditException ex) {
} catch (NoClipboardException | WorldEditException ex) { throw new SecurityException("Error recoloring schematic", ex);
throw new SecurityException("Error pasting schematic", ex);
} }
}, 14)); }, 14));
}
private void paste(){
FreezeWorld freezer = new FreezeWorld();
try {
replaceTeamColor(clipboard);
VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.pasteSchematic(clipboard, region, rotate), 8),
new VersionedRunnable(() -> FightTeam_14.pasteSchematic(clipboard, region, rotate), 14));
} catch (SecurityException securityException) { } catch (SecurityException securityException) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState);
@ -148,6 +159,62 @@ public class FightSchematic extends StateDependent {
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
} }
private Clipboard loadTextSchem(String schemName){
return VersionedCallable.call(new VersionedCallable<>(() -> FightTeam_8.loadSchem(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + schemName + ".schematic"))))), 8),
new VersionedCallable<>(() -> FightTeam_14.loadSchem(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + schemName + ".schem"))))), 14));
}
public void pasteTeamName(){
List<Clipboard> characters = new ArrayList<>();
for(char c : team.getName().toCharArray()){
try {
try {
characters.add(loadTextSchem(c == '/' ? "slash" : String.valueOf(c)));
} catch (RuntimeException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", c);
characters.add(loadTextSchem(""));
}
}catch (RuntimeException e) {
throw new SecurityException("Could not load text", e);
}
}
//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++){
replaceTeamColor(characters.get(i));
pasteChar(characters.get(i), offsets[i], length, team.getSchemRegion().centerX(), team.getExtendRegion().getMaxY(), z, aT);
}
}
private void pasteChar(Clipboard character, int charOffset, int length, int x, int y, int z, AffineTransform aT){
VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.pasteChar(character, charOffset, length, x, y, z, aT), 8),
new VersionedRunnable(() -> FightTeam_14.pasteChar(character, charOffset, length, x, y, z, aT), 14));
}
@Override @Override
public void disable() { public void disable() {
if(!Config.ReplaceObsidianBedrock) if(!Config.ReplaceObsidianBedrock)

Datei anzeigen

@ -54,9 +54,9 @@ public class FightTeam implements IFightTeam{
private final Map<Player, FightPlayer> players = new HashMap<>(); private final Map<Player, FightPlayer> players = new HashMap<>();
private final Set<Player> invited = new HashSet<>(); private final Set<Player> invited = new HashSet<>();
private final String name; private String name;
private final String prefix; private String prefix;
private final ChatColor color; private ChatColor color;
private final FightSchematic schematic; private final FightSchematic schematic;
private final Team team; private final Team team;
private final boolean blue; private final boolean blue;
@ -72,13 +72,11 @@ public class FightTeam implements IFightTeam{
this.spawn = spawn; this.spawn = spawn;
this.schemRegion = schemRegion; this.schemRegion = schemRegion;
this.extendRegion = extendRegion; this.extendRegion = extendRegion;
this.name = name;
this.prefix = prefix;
this.ready = false; this.ready = false;
this.skip = false; this.skip = false;
this.blue = blue; this.blue = blue;
this.designatedLeader = designatedLeader; this.designatedLeader = designatedLeader;
this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); setPrefixAndName(prefix, name);
this.schematic = new FightSchematic(this, rotate); this.schematic = new FightSchematic(this, rotate);
new KitLoader(); new KitLoader();
new SpectateHandler(); new SpectateHandler();
@ -94,6 +92,12 @@ public class FightTeam implements IFightTeam{
team.setAllowFriendlyFire(false); team.setAllowFriendlyFire(false);
} }
public void setPrefixAndName(String prefix, String name){
this.name = name;
this.prefix = prefix;
this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""));
}
public UUID getDesignatedLeader(){ public UUID getDesignatedLeader(){
return designatedLeader; return designatedLeader;
} }
@ -296,13 +300,17 @@ public class FightTeam implements IFightTeam{
public void pasteSchem(Schematic schematic){ public void pasteSchem(Schematic schematic){
setSchem(schematic); setSchem(schematic);
if(Config.test()) if(Config.test() || RecordSystem.isReplaying())
this.schematic.enable(); this.schematic.enable();
else if(Fight.getOpposite(this).hasSchematic()){ else if(Fight.getOpposite(this).hasSchematic()){
FightSystem.setPostSchemState(); FightSystem.setPostSchemState();
} }
} }
public void pasteTeamName(){
schematic.pasteTeamName();
}
public void setSchem(Schematic schematic){ public void setSchem(Schematic schematic){
this.schematic.setSchematic(schematic); this.schematic.setSchematic(schematic);
broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!");

Datei anzeigen

@ -54,7 +54,6 @@ public class FightScoreboard implements Listener, ScoreboardCallback {
return scoreboard; return scoreboard;
} }
private boolean replaying = false;
private int index = 0; private int index = 0;
private String title = ""; private String title = "";
@ -113,7 +112,7 @@ public class FightScoreboard implements Listener, ScoreboardCallback {
} }
private void updateScoreboard() { private void updateScoreboard() {
if(replaying) if(RecordSystem.isReplaying())
return; return;
if ((index++ / 5) % 2 == 0) { if ((index++ / 5) % 2 == 0) {
@ -125,10 +124,6 @@ public class FightScoreboard implements Listener, ScoreboardCallback {
} }
} }
public void setReplaying(boolean replaying) {
this.replaying = replaying;
}
public void setTitle(String t) { public void setTitle(String t) {
scores.clear(); scores.clear();
title = t; title = t;

Datei anzeigen

@ -1,150 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.record;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader;
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.World;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.utils.ColorConverter;
import de.steamwar.sql.Team;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.zip.GZIPInputStream;
public class BlockTextCreator {
private BlockTextCreator(){}
private static final int BETWEEN_CHARACTERS_WIDTH = 1;
private static final World WORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
private static BlockArrayClipboard[] createText(String text){
List<BlockArrayClipboard> result = new ArrayList<>();
for(char c : text.toCharArray()){
try {
try {
result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + nameConversion(c) + ".schem"))))).read());
} catch (FileNotFoundException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character " + c + " due to missing file!");
result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/.schem"))))).read());
}
}catch (IOException e) {
throw new SecurityException("Could not load text", e);
}
}
return result.toArray(new BlockArrayClipboard[0]);
}
private static String nameConversion(char c) {
switch (Character.toUpperCase(c)) {
case '/':
return "slash";
default:
return c + "";
}
}
private static int[] characterSize(BlockArrayClipboard[] characters){
int[] lengthes = new int[characters.length];
for(int i = 0; i < lengthes.length; i++)
lengthes[i] = characters[i].getDimensions().getBlockX();
return lengthes;
}
private static int[] textOffsets(int[] lengthes){
int[] offsets = new int[lengthes.length];
int previousOffset = 0;
for(int i = 0; i < offsets.length; i++){
offsets[i] = previousOffset;
previousOffset += lengthes[i] + BETWEEN_CHARACTERS_WIDTH;
}
return offsets;
}
private static int textLength(int[] lengthes, int[] offsets){
if(lengthes.length == 0)
return 0;
return lengthes[lengthes.length - 1] + offsets[offsets.length - 1];
}
private static void pasteChar(BlockArrayClipboard character, int charOffset, int length, int x, int y, int z, AffineTransform transform, DyeColor c){
BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin());
BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset);
v = transform.apply(v.toVector3()).toBlockPoint();
v = v.add(x, y, z);
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1);
ClipboardHolder ch = new ClipboardHolder(character);
ch.setTransform(transform);
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build());
e.flushSession();
}
private static void pasteText(String text, int x, int y, int z, AffineTransform transform, DyeColor c){
BlockArrayClipboard[] characters = createText(text);
int[] lengthes = characterSize(characters);
int[] offsets = textOffsets(lengthes);
int length = textLength(lengthes, offsets);
for(int i = 0; i < characters.length; i++)
pasteChar(characters[i], offsets[i], length, x, y, z, transform, c);
Paster.replaceTeamColor(
WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1),
c,
x - length / 2, y, z, length, 6, 0);
}
private static void pasteForTeam(int teamId, int x, int z, boolean rotate, String color){
Team team = Team.get(teamId);
AffineTransform aT = new AffineTransform();
if(rotate){
aT = aT.rotateY(180);
z += Config.SchemsizeZ / 2;
}else
z -= Config.SchemsizeZ / 2;
DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(color).replace("§", "")));
pasteText(team.getTeamKuerzel(), x, Config.upperArenaBorder + 10, z, aT, c);
}
public static void pasteTeamNames(int teamBlueId, int teamRedId){
pasteForTeam(teamBlueId, Config.TeamBluePasteX, Config.TeamBluePasteZ, Config.TeamBlueRotate, Config.TeamBluePrefix);
pasteForTeam(teamRedId, Config.TeamRedPasteX, Config.TeamRedPasteZ, Config.TeamRedRotate, Config.TeamRedPrefix);
}
}

Datei anzeigen

@ -28,6 +28,7 @@ import de.steamwar.fightsystem.fight.FreezeWorld;
import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.FightScoreboard;
import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import de.steamwar.sql.Team;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
@ -39,7 +40,6 @@ import org.bukkit.scheduler.BukkitTask;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -57,7 +57,7 @@ class PacketProcessor {
public PacketProcessor(PacketSource source){ public PacketProcessor(PacketSource source){
this.source = source; this.source = source;
FightScoreboard.getScoreboard().setReplaying(true); RecordSystem.setReplaying(true);
if(source.async()) { if(source.async()) {
Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process); Bukkit.getScheduler().runTaskAsynchronously(FightSystem.getPlugin(), this::process);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1); task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::runSync, 1, 1);
@ -253,7 +253,16 @@ class PacketProcessor {
int blueId = source.rInt(); int blueId = source.rInt();
int redId = source.rInt(); int redId = source.rInt();
execSync(() -> BlockTextCreator.pasteTeamNames(blueId, redId)); execSync(() -> {
pasteForTeam(blueId, Fight.getBlueTeam());
pasteForTeam(redId, Fight.getRedTeam());
});
}
private void pasteForTeam(int teamId, FightTeam fightTeam){
Team team = Team.get(teamId);
fightTeam.setPrefixAndName("§" + team.getTeamColor(), team.getTeamKuerzel());
fightTeam.pasteTeamName();
} }
private void scoreboardTitle() throws IOException { private void scoreboardTitle() throws IOException {
@ -271,10 +280,10 @@ class PacketProcessor {
private void endReplay(){ private void endReplay(){
REntity.dieAll(); REntity.dieAll();
FightScoreboard.getScoreboard().setReplaying(false);
freezer.disable(); freezer.disable();
//TODO: Stop server if singular replay //TODO: Stop server if singular replay
FightWorld.resetWorld(); FightWorld.resetWorld();
RecordSystem.setReplaying(false);
} }
private void bow() throws IOException { private void bow() throws IOException {
@ -393,7 +402,7 @@ class PacketProcessor {
tickFinished = true; tickFinished = true;
break; break;
default: default:
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing: " + packetType); Bukkit.getLogger().log(Level.SEVERE, "Unknown packet {} recieved, closing.", packetType);
source.close(); source.close();
} }
} }

Datei anzeigen

@ -40,6 +40,16 @@ import org.bukkit.util.Vector;
public class RecordSystem { public class RecordSystem {
private RecordSystem(){} private RecordSystem(){}
private static boolean replaying = false;
public static boolean isReplaying(){
return replaying;
}
public static void setReplaying(boolean replaying){
RecordSystem.replaying = replaying;
}
private static final World WORLD = Bukkit.getWorlds().get(0); private static final World WORLD = Bukkit.getWorlds().get(0);
public static void init(){ public static void init(){