SteamWar/SpigotCore
Archiviert
13
0

Merge remote-tracking branch 'origin/gradle' into gradle

Dieser Commit ist enthalten in:
yoyosource 2021-08-24 09:25:57 +02:00
Commit 16a587b6ea
10 geänderte Dateien mit 278 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -54,7 +54,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import static com.google.common.base.Preconditions.checkNotNull;
@ -111,9 +110,9 @@ class Schematic_14 {
static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
try {
if(schemFormat){
return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read();
return new SpongeSchematicReader(new NBTInputStream(is)).read();
}else{
return new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read();
return new MCEditSchematicReader(new NBTInputStream(is)).read();
}
} catch (NullPointerException e) {
throw new NoClipboardException();

Datei anzeigen

@ -32,6 +32,7 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.extent.clipboard.io.SchematicReader;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.registry.WorldData;
@ -47,7 +48,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
class Schematic_8 {
private Schematic_8(){}
@ -88,9 +88,9 @@ class Schematic_8 {
static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
if(schemFormat)
return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
else
return ClipboardFormat.SCHEMATIC.getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
}
private static WorldEditPlugin getWorldEditPlugin() {

Datei anzeigen

@ -29,7 +29,8 @@ public interface TypeMapper<T> {
}
// For backwards compatibility, can be removed later on
@Deprecated(since = "Use the other map Function without calling super!")
// SINCE="Use the other map Function without calling super!"
@Deprecated
default T map(String[] previousArguments, String s) {
throw new SecurityException();
}

Datei anzeigen

@ -20,14 +20,18 @@
package de.steamwar.comms;
public class PacketIdManager {
private PacketIdManager(){}
//0x0(X) Standalone Packets
public final static byte PING_PACKET = 0x01;
public final static byte TABLIST_NAME = 0x02;
public static final byte PING_PACKET = 0x01;
public static final byte TABLIST_NAME = 0x02;
public static final byte PREPARE_SCHEM = 0x03;
public final static byte BAUMEMBER_UPDATE = 0x04;
public static final byte BAUMEMBER_UPDATE = 0x04;
//0x1(X) Bungee Inventory
public final static byte INVENTORY_PACKET = 0x10;
public final static byte INVENTORY_CALLBACK_PACKET = 0x11;
public final static byte INVENTORY_CLOSE_PACKET = 0x12;
public static final byte INVENTORY_PACKET = 0x10;
public static final byte INVENTORY_CALLBACK_PACKET = 0x11;
public static final byte INVENTORY_CLOSE_PACKET = 0x12;
//0x2(X) Server Information System
public static final byte I_AM_A_LOBBY = 0x20;
public static final byte FIGHT_INFO = 0x21;
}

Datei anzeigen

@ -0,0 +1,174 @@
/*
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.comms.packets;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import java.util.ArrayList;
import java.util.List;
public class FightInfoPacket extends SpigotPacket {
private final String serverName; // Name of the Server, might be changed by Bungee
private final String gameMode; // GameMode aka Schematictype (if known, else "")
private final String arena; // Name of the arena
private final String blueName; // Name of the blue team, expected to begin with "§a" colorcode
private final String redName; // Name of the red team, expected to begin with "§a" colorcode
private final String fightState; // Fight state (technical term) (if known, else "")
private final int countdown; // Countdown state in seconds (if known, else 0)
private final int blueLeader; // SWUserID of the blue team leader (if known, else 0)
private final int redLeader; // SWUserID of the red team leader (if known, else 0)
private final int blueSchem; // Blue SchemID (if known, else 0)
private final int redSchem; // Red SchemID (if known, else 0)
private final List<Integer> bluePlayers; // List of Blue SWUserIDs
private final List<Integer> redPlayers; // List of Red SWUserIDs
private final List<Integer> spectators; // List of Spectator SWUserIDs
public FightInfoPacket(String serverName, String gameMode, String arena, String blueName, String redName, String fightState, int countdown, int blueLeader, int redLeader, int blueSchem, int redSchem, List<Integer> bluePlayers, List<Integer> redPlayers, List<Integer> spectators) {
this.serverName = serverName;
this.gameMode = gameMode;
this.arena = arena;
this.blueName = blueName;
this.redName = redName;
this.fightState = fightState;
this.countdown = countdown;
this.blueLeader = blueLeader;
this.redLeader = redLeader;
this.blueSchem = blueSchem;
this.redSchem = redSchem;
this.bluePlayers = bluePlayers;
this.redPlayers = redPlayers;
this.spectators = spectators;
}
public FightInfoPacket(ByteArrayDataInput in) {
this.serverName = in.readUTF();
this.gameMode = in.readUTF();
this.arena = in.readUTF();
this.blueName = in.readUTF();
this.redName = in.readUTF();
this.fightState = in.readUTF();
this.countdown = in.readInt();
this.blueLeader = in.readInt();
this.redLeader = in.readInt();
this.blueSchem = in.readInt();
this.redSchem = in.readInt();
this.bluePlayers = readPlayerList(in);
this.redPlayers = readPlayerList(in);
this.spectators = readPlayerList(in);
}
@Override
public int getName() {
return PacketIdManager.FIGHT_INFO;
}
@Override
public void writeVars(ByteArrayDataOutput out) {
out.writeUTF(serverName);
out.writeUTF(gameMode);
out.writeUTF(arena);
out.writeUTF(blueName);
out.writeUTF(redName);
out.writeUTF(fightState);
out.writeInt(countdown);
out.writeInt(blueLeader);
out.writeInt(redLeader);
out.writeInt(blueSchem);
out.writeInt(redSchem);
writePlayerList(out, bluePlayers);
writePlayerList(out, redPlayers);
writePlayerList(out, spectators);
}
public String getServerName() {
return serverName;
}
public String getGameMode() {
return gameMode;
}
public String getArena() {
return arena;
}
public String getBlueName() {
return blueName;
}
public String getRedName() {
return redName;
}
public String getFightState() {
return fightState;
}
public int getCountdown() {
return countdown;
}
public int getBlueLeader() {
return blueLeader;
}
public int getRedLeader() {
return redLeader;
}
public int getBlueSchem() {
return blueSchem;
}
public int getRedSchem() {
return redSchem;
}
public List<Integer> getBluePlayers() {
return bluePlayers;
}
public List<Integer> getRedPlayers() {
return redPlayers;
}
public List<Integer> getSpectators() {
return spectators;
}
private static List<Integer> readPlayerList(ByteArrayDataInput in) {
int length = in.readInt();
List<Integer> players = new ArrayList<>(length);
for(int i = 0; i < length; i++) {
players.add(in.readInt());
}
return players;
}
private void writePlayerList(ByteArrayDataOutput out, List<Integer> players) {
out.writeInt(players.size());
for(Integer player : players) {
out.writeInt(player);
}
}
}

Datei anzeigen

@ -0,0 +1,36 @@
/*
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.comms.packets;
import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
public class ImALobbyPacket extends SpigotPacket {
@Override
public int getName() {
return PacketIdManager.I_AM_A_LOBBY;
}
@Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
//no content
}
}

Datei anzeigen

@ -57,6 +57,11 @@ public class EventFight {
SQL.update("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?", winner, fightID);
}
public void setFight(int fight){
//Fight.FightID, not EventFight.FightID
SQL.update("UPDATE EventFight SET Fight = ? WHERE FightID = ?", fight, fightID);
}
public int getTeamBlue() {
return teamBlue;
}

Datei anzeigen

@ -19,6 +19,8 @@
package de.steamwar.sql;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
@ -27,8 +29,12 @@ public class Fight {
private Fight(){}
public static int create(String gamemode, String arena, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){
SQL.update("INSERT INTO Fight (GameMode, Arena, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
gamemode, arena, starttime, duration, blueleader, redleader,blueschem, redschem, win, wincondition);
return create(gamemode, arena, null, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition);
}
public static int create(String gamemode, String server, String arena, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){
SQL.update("INSERT INTO Fight (GameMode, Server, Arena, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
gamemode, server, arena, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition);
ResultSet rs = SQL.select("SELECT LAST_INSERT_ID() AS FightID");
try{
if(!rs.next())
@ -39,4 +45,27 @@ public class Fight {
throw new SecurityException(e);
}
}
public static InputStream getReplay(int fightID) {
ResultSet rs = SQL.select("SELECT Replay FROM Fight WHERE FightID = ?", fightID);
try {
rs.next();
Blob replay = rs.getBlob("Replay");
if(replay == null)
throw new SecurityException("Replay null");
return replay.getBinaryStream();
} catch (SQLException e) {
throw new SecurityException(e);
}
}
public static void setReplay(int fightID, byte[] data) {
Blob blob = SQL.blob();
try {
blob.setBytes(1, data);
} catch (SQLException e) {
throw new SecurityException(e);
}
SQL.update("UPDATE Fight SET Replay = ? WHERE FightID = ?", blob, fightID);
}
}

Datei anzeigen

@ -32,6 +32,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
public class Schematic {
@ -182,34 +183,32 @@ public class Schematic {
return true;
}
public Clipboard load() throws IOException, NoClipboardException {
public InputStream schemData() throws IOException {
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID);
try {
rs.next();
Blob schemData = rs.getBlob("SchemData");
if(schemData == null)
throw new IOException("SchemData is null");
InputStream is = schemData.getBinaryStream();
return VersionedCallable.call(new VersionedCallable<>(() -> Schematic_8.getClipboard(is, schemFormat), 8),
new VersionedCallable<>(() -> Schematic_14.getClipboard(is, schemFormat), 14));
return new GZIPInputStream(schemData.getBinaryStream());
} catch (SQLException e) {
throw new IOException(e);
}
}
public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) {
return VersionedCallable.call(new VersionedCallable<>(() -> Schematic_8.getClipboard(is, schemFormat), 8),
new VersionedCallable<>(() -> Schematic_14.getClipboard(is, schemFormat), 14));
}
public Clipboard load() throws IOException, NoClipboardException {
return clipboardFromStream(schemData(), schemFormat);
}
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID);
try {
rs.next();
Blob blob = rs.getBlob("SchemData");
if(blob == null)
throw new NoClipboardException();
InputStream is = blob.getBinaryStream();
InputStream is = schemData();
VersionedRunnable.call(new VersionedRunnable(() -> Schematic_8.setPlayerClipboard(player, is, schemFormat), 8),
new VersionedRunnable(() -> Schematic_14.setPlayerClipboard(player, is, schemFormat), 14));
} catch (SQLException e) {
throw new IOException(e);
}
}
public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {

Datei anzeigen

@ -64,5 +64,4 @@ public class UserConfig {
public static void removePlayerConfig(int id, String config) {
SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, config);
}
}