12
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
4 geänderte Dateien mit 34 neuen und 25 gelöschten Zeilen
Nur Änderungen aus Commit 5826f7e8b1 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -109,6 +109,12 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper {
e.flushSession(); e.flushSession();
} }
@Override
public Vector getDimensions(Clipboard clipboard) {
BlockVector3 dims = clipboard.getDimensions();
return new Vector(dims.getX(), dims.getY(), dims.getZ());
}
@Override @Override
public Clipboard loadChar(String charName) throws IOException { public Clipboard loadChar(String charName) throws IOException {
return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schem"))))).read(); return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schem"))))).read();

Datei anzeigen

@ -109,6 +109,12 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper {
e.flushQueue(); e.flushQueue();
} }
@Override
public org.bukkit.util.Vector getDimensions(Clipboard clipboard) {
Vector dims = clipboard.getDimensions();
return new org.bukkit.util.Vector(dims.getBlockX(), dims.getBlockY(), dims.getBlockZ());
}
@Override @Override
public Clipboard loadChar(String charName) throws IOException { public Clipboard loadChar(String charName) throws IOException {
return new SchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schematic"))))).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData()); return new SchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schematic"))))).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData());

Datei anzeigen

@ -114,30 +114,30 @@ public class FightSchematic extends StateDependent {
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste);
} }
private void replaceTeamColor(Clipboard clipboard) throws WorldEditException { private void replaceTeamColor(Clipboard clipboard) {
WorldeditWrapper.impl.replaceTeamColor(clipboard, ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK); try {
WorldeditWrapper.impl.replaceTeamColor(clipboard, ArenaMode.AntiPrepare.contains(Config.mode) ? ColorConverter.chat2dye(team.getColor()) : DyeColor.PINK);
} catch (WorldEditException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not recolor schematic", e);
}
} }
private void paste(){ private void paste(){
FreezeWorld freezer = new FreezeWorld(); FreezeWorld freezer = new FreezeWorld();
try { replaceTeamColor(clipboard);
replaceTeamColor(clipboard);
WorldeditWrapper.impl.pasteClipboard( Vector dims = WorldeditWrapper.impl.getDimensions(clipboard);
clipboard, WorldeditWrapper.impl.pasteClipboard(
new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()), clipboard,
new Vector( new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()),
-clipboard.getDimensions().getBlockX()/2, new Vector(
Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, -dims.getBlockX()/2,
-clipboard.getDimensions().getBlockZ()/2 Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0,
), -dims.getBlockZ()/2
new AffineTransform().rotateY(rotate ? 180 : 0) ),
); new AffineTransform().rotateY(rotate ? 180 : 0)
} catch (WorldEditException e) { );
FightSystem.broadcast("§cFehler beim Pasten der Schematic");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), FightSystem::setPreSchemState);
throw new SecurityException("Could not paste schematic", e);
}
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), freezer::disable, 3);
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40);
@ -179,15 +179,11 @@ public class FightSchematic extends StateDependent {
} }
} }
try { replaceTeamColor(character);
replaceTeamColor(character);
} catch (WorldEditException e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not recolor team text", e);
}
characters[i] = character; characters[i] = character;
offsets[i] = length; offsets[i] = length;
length += character.getDimensions().getBlockX() + 1; // 1 is the distance between characters length += WorldeditWrapper.impl.getDimensions(character).getBlockX() + 1; // 1 is the distance between characters
} }
length -= 1; length -= 1;

Datei anzeigen

@ -39,6 +39,7 @@ public class WorldeditWrapper {
void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException;
int getWaterDepth(Clipboard clipboard); int getWaterDepth(Clipboard clipboard);
void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT); void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT);
Vector getDimensions(Clipboard clipboard);
Clipboard loadChar(String charName) throws IOException; Clipboard loadChar(String charName) throws IOException;
void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException; void saveSchem(Schematic schem, Region region, int minY) throws WorldEditException;
} }