Merge pull request 'standalone' (#174) from standalone into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #174
Dieser Commit ist enthalten in:
Commit
da3ae03ecd
@ -44,6 +44,9 @@ sourceSets {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(":SpigotCore_Main")
|
implementation project(":SpigotCore_Main")
|
||||||
|
implementation project(":SpigotCore_14")
|
||||||
|
|
||||||
|
compileOnly files("${project.rootDir}/lib/WorldEdit-1.15.jar")
|
||||||
|
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
|
||||||
compileOnly files("${project.rootDir}/lib/Spigot-1.18.jar")
|
compileOnly files("${project.rootDir}/lib/Spigot-1.18.jar")
|
||||||
|
46
SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java
Normale Datei
46
SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java
Normale Datei
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 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.core;
|
||||||
|
|
||||||
|
import com.sk89q.jnbt.NBTInputStream;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader;
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader;
|
||||||
|
import de.steamwar.sql.NoClipboardException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class WorldEditWrapper18 extends WorldEditWrapper14 {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
|
||||||
|
//Use FAWE reader due to FAWE capability of reading corrupt FAWE schems
|
||||||
|
try {
|
||||||
|
if(schemFormat){
|
||||||
|
return new SpongeSchematicReader(new NBTInputStream(is)).read();
|
||||||
|
}else{
|
||||||
|
return new MCEditSchematicReader(new NBTInputStream(is)).read();
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
throw new NoClipboardException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -38,11 +39,9 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class Core extends JavaPlugin{
|
public class Core extends JavaPlugin{
|
||||||
|
|
||||||
|
public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
||||||
|
|
||||||
private static final int VERSION;
|
private static final int VERSION;
|
||||||
public static final Message MESSAGE;
|
|
||||||
|
|
||||||
private static Core instance;
|
|
||||||
|
|
||||||
static{
|
static{
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
if(packageName.contains("1_18"))
|
if(packageName.contains("1_18"))
|
||||||
@ -61,8 +60,27 @@ public class Core extends JavaPlugin{
|
|||||||
VERSION = 8;
|
VERSION = 8;
|
||||||
else
|
else
|
||||||
VERSION = 18;
|
VERSION = 18;
|
||||||
|
}
|
||||||
|
public static int getVersion(){
|
||||||
|
return VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
private static JavaPlugin instance;
|
||||||
|
public static JavaPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
public static void setInstance(JavaPlugin instance) {
|
||||||
|
Core.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean standalone = true;
|
||||||
|
public static boolean standalone() {
|
||||||
|
return standalone;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File sqlConfig;
|
||||||
|
public static File sqlConfig() {
|
||||||
|
return sqlConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ErrorHandler errorHandler;
|
private ErrorHandler errorHandler;
|
||||||
@ -74,6 +92,7 @@ public class Core extends JavaPlugin{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
setSqlConfig();
|
||||||
errorHandler = new ErrorHandler();
|
errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||||
@ -84,7 +103,7 @@ public class Core extends JavaPlugin{
|
|||||||
AuthlibInjector.inject();
|
AuthlibInjector.inject();
|
||||||
TinyProtocol.init();
|
TinyProtocol.init();
|
||||||
try {
|
try {
|
||||||
Bukkit.getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine());
|
getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException("Could not load Hostname", e);
|
throw new SecurityException("Could not load Hostname", e);
|
||||||
}
|
}
|
||||||
@ -94,18 +113,13 @@ public class Core extends JavaPlugin{
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
TinyProtocol.instance.close();
|
TinyProtocol.instance.close();
|
||||||
errorHandler.unregister();
|
errorHandler.unregister();
|
||||||
|
if(!standalone) {
|
||||||
Statement.close();
|
Statement.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Core getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getVersion(){
|
private static void setSqlConfig() {
|
||||||
return VERSION;
|
sqlConfig = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
||||||
}
|
standalone = !sqlConfig.exists();
|
||||||
|
|
||||||
private static void setInstance(Core instance) {
|
|
||||||
Core.instance = instance;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,9 @@ public class WorldEditWrapper {
|
|||||||
InputStream getPlayerClipboard(Player player, boolean schemFormat);
|
InputStream getPlayerClipboard(Player player, boolean schemFormat);
|
||||||
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
|
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
|
||||||
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
|
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static WorldEditPlugin getWorldEditPlugin() {
|
public static WorldEditPlugin getWorldEditPlugin() {
|
||||||
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,28 +23,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BauweltMember{
|
public class BauweltMember {
|
||||||
|
private static final List<BauweltMember> memberCache = new ArrayList<>();
|
||||||
private static final Statement getMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
|
|
||||||
private static final Statement getMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?");
|
|
||||||
|
|
||||||
private final int bauweltID;
|
|
||||||
private final int memberID;
|
|
||||||
private final boolean worldEdit;
|
|
||||||
private final boolean world;
|
|
||||||
|
|
||||||
private static final List<BauweltMember> members = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
members.clear();
|
memberCache.clear();
|
||||||
}
|
|
||||||
|
|
||||||
private BauweltMember(int ownerID, int memberID, boolean worldEdit, boolean world) {
|
|
||||||
bauweltID = ownerID;
|
|
||||||
this.memberID = memberID;
|
|
||||||
this.worldEdit = worldEdit;
|
|
||||||
this.world = world;
|
|
||||||
members.add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
||||||
@ -52,14 +35,10 @@ public class BauweltMember{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BauweltMember getBauMember(int ownerID, int memberID){
|
public static BauweltMember getBauMember(int ownerID, int memberID){
|
||||||
for(BauweltMember member : members)
|
for(BauweltMember member : memberCache)
|
||||||
if(member.memberID == memberID)
|
if(member.getMemberID() == memberID)
|
||||||
return member;
|
return member;
|
||||||
return getMember.select(rs -> {
|
return Provider.impl.getBauMember(ownerID, memberID);
|
||||||
if(!rs.next())
|
|
||||||
return null;
|
|
||||||
return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World"));
|
|
||||||
}, ownerID, memberID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BauweltMember> getMembers(UUID bauweltID){
|
public static List<BauweltMember> getMembers(UUID bauweltID){
|
||||||
@ -67,12 +46,20 @@ public class BauweltMember{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<BauweltMember> getMembers(int bauweltID){
|
public static List<BauweltMember> getMembers(int bauweltID){
|
||||||
return getMembers.select(rs -> {
|
return Provider.impl.getMembers(bauweltID);
|
||||||
List<BauweltMember> members = new ArrayList<>();
|
}
|
||||||
while(rs.next())
|
|
||||||
members.add(new BauweltMember(bauweltID, rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World")));
|
private final int bauweltID;
|
||||||
return members;
|
private final int memberID;
|
||||||
}, bauweltID);
|
private final boolean worldEdit;
|
||||||
|
private final boolean world;
|
||||||
|
|
||||||
|
public BauweltMember(int bauweltID, int memberID, boolean worldEdit, boolean world) {
|
||||||
|
this.bauweltID = bauweltID;
|
||||||
|
this.memberID = memberID;
|
||||||
|
this.worldEdit = worldEdit;
|
||||||
|
this.world = world;
|
||||||
|
memberCache.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBauweltID() {
|
public int getBauweltID() {
|
||||||
|
@ -20,45 +20,17 @@
|
|||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CheckedSchematic {
|
public class CheckedSchematic {
|
||||||
|
|
||||||
private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC");
|
|
||||||
private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
|
||||||
|
|
||||||
private final Integer node;
|
|
||||||
private final int validator;
|
|
||||||
private final Timestamp startTime;
|
|
||||||
private final Timestamp endTime;
|
|
||||||
private final String declineReason;
|
|
||||||
|
|
||||||
private CheckedSchematic(int node, int validator, Timestamp startTime, Timestamp endTime, String declineReason){
|
|
||||||
this.node = node;
|
|
||||||
this.validator = validator;
|
|
||||||
this.startTime = startTime;
|
|
||||||
this.endTime = endTime;
|
|
||||||
this.declineReason = declineReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
|
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
|
||||||
return getLastDeclinedOfNode(node.getId());
|
return getLastDeclinedOfNode(node.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
|
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
|
||||||
return nodeHistory.select(rs -> {
|
return Provider.impl.getLastDeclinedOfNode(node);
|
||||||
List<CheckedSchematic> lastDeclined = new ArrayList<>();
|
|
||||||
while(rs.next()){
|
|
||||||
int validator = rs.getInt("Validator");
|
|
||||||
Timestamp startTime = rs.getTimestamp("StartTime");
|
|
||||||
Timestamp endTime = rs.getTimestamp("EndTime");
|
|
||||||
String declineReason = rs.getString("DeclineReason");
|
|
||||||
lastDeclined.add(new CheckedSchematic(node, validator, startTime, endTime, declineReason));
|
|
||||||
}
|
|
||||||
return lastDeclined;
|
|
||||||
}, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
|
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
|
||||||
@ -66,12 +38,21 @@ public class CheckedSchematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDelined(int schemOwner){
|
public static List<CheckedSchematic> getLastDelined(int schemOwner){
|
||||||
return checkHistory.select(rs -> {
|
return Provider.impl.getLastDelined(schemOwner);
|
||||||
List<CheckedSchematic> history = new ArrayList<>();
|
}
|
||||||
while(rs.next())
|
|
||||||
history.add(new CheckedSchematic(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason")));
|
private final Integer node;
|
||||||
return history;
|
private final int validator;
|
||||||
}, schemOwner);
|
private final Timestamp startTime;
|
||||||
|
private final Timestamp endTime;
|
||||||
|
private final String declineReason;
|
||||||
|
|
||||||
|
public CheckedSchematic(Integer node, int validator, Timestamp startTime, Timestamp endTime, String declineReason) {
|
||||||
|
this.node = node;
|
||||||
|
this.validator = validator;
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.endTime = endTime;
|
||||||
|
this.declineReason = declineReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValidator() {
|
public int getValidator() {
|
||||||
|
@ -22,18 +22,11 @@ package de.steamwar.sql;
|
|||||||
public class Elo {
|
public class Elo {
|
||||||
private Elo(){}
|
private Elo(){}
|
||||||
|
|
||||||
private static final Statement get = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?");
|
|
||||||
private static final Statement set = new Statement("INSERT INTO Elo (UserID, GameMode, Elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)");
|
|
||||||
|
|
||||||
public static int getElo(int userId, String gameMode){
|
public static int getElo(int userId, String gameMode){
|
||||||
return get.select(rs -> {
|
return Provider.impl.getElo(userId, gameMode);
|
||||||
if(rs.next())
|
|
||||||
return rs.getInt("Elo");
|
|
||||||
return 1000;
|
|
||||||
}, userId, gameMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setElo(int userId, String gameMode, int elo){
|
public static void setElo(int userId, String gameMode, int elo){
|
||||||
set.update(userId, gameMode, elo);
|
Provider.impl.setElo(userId, gameMode, elo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
public class Event {
|
public class Event {
|
||||||
|
|
||||||
private static final Statement get = new Statement("SELECT * FROM Event WHERE EventID = ?");
|
public static Event get(int eventID){
|
||||||
|
return Provider.impl.getEvent(eventID);
|
||||||
|
}
|
||||||
|
|
||||||
private final int eventID;
|
private final int eventID;
|
||||||
private final String eventName;
|
private final String eventName;
|
||||||
@ -35,21 +35,14 @@ public class Event {
|
|||||||
private final boolean publicSchemsOnly;
|
private final boolean publicSchemsOnly;
|
||||||
private final boolean spectateSystem;
|
private final boolean spectateSystem;
|
||||||
|
|
||||||
private Event(ResultSet rs) throws SQLException{
|
public Event(int eventID, String eventName, Timestamp start, Timestamp end, int maximumTeamMembers, boolean publicSchemsOnly, boolean spectateSystem) {
|
||||||
this.eventID = rs.getInt("EventID");
|
this.eventID = eventID;
|
||||||
this.eventName = rs.getString("EventName");
|
this.eventName = eventName;
|
||||||
this.start = rs.getTimestamp("Start");
|
this.start = start;
|
||||||
this.end = rs.getTimestamp("End");
|
this.end = end;
|
||||||
this.maximumTeamMembers = rs.getInt("MaximumTeamMembers");
|
this.maximumTeamMembers = maximumTeamMembers;
|
||||||
this.publicSchemsOnly = rs.getBoolean("PublicSchemsOnly");
|
this.publicSchemsOnly = publicSchemsOnly;
|
||||||
this.spectateSystem = rs.getBoolean("SpectateSystem");
|
this.spectateSystem = spectateSystem;
|
||||||
}
|
|
||||||
|
|
||||||
public static Event get(int eventID){
|
|
||||||
return get.select(rs -> {
|
|
||||||
rs.next();
|
|
||||||
return new Event(rs);
|
|
||||||
}, eventID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEventID() {
|
public int getEventID() {
|
||||||
|
@ -19,14 +19,11 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class EventFight {
|
public class EventFight {
|
||||||
|
|
||||||
private static final Statement get = new Statement("SELECT * FROM EventFight WHERE FightID = ?");
|
public static EventFight get(int fightID) {
|
||||||
private static final Statement setResult = new Statement("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?");
|
return Provider.impl.getEventFight(fightID);
|
||||||
private static final Statement setFight = new Statement("UPDATE EventFight SET Fight = ? WHERE FightID = ?");
|
}
|
||||||
|
|
||||||
private final int eventID;
|
private final int eventID;
|
||||||
private final int fightID;
|
private final int fightID;
|
||||||
@ -35,29 +32,22 @@ public class EventFight {
|
|||||||
private final int kampfleiter;
|
private final int kampfleiter;
|
||||||
private final int ergebnis;
|
private final int ergebnis;
|
||||||
|
|
||||||
private EventFight(ResultSet rs) throws SQLException{
|
public EventFight(int eventID, int fightID, int teamBlue, int teamRed, int kampfleiter, int ergebnis) {
|
||||||
this.eventID = rs.getInt("EventID");
|
this.eventID = eventID;
|
||||||
this.fightID = rs.getInt("FightID");
|
this.fightID = fightID;
|
||||||
this.teamBlue = rs.getInt("TeamBlue");
|
this.teamBlue = teamBlue;
|
||||||
this.teamRed = rs.getInt("TeamRed");
|
this.teamRed = teamRed;
|
||||||
this.kampfleiter = rs.getInt("Kampfleiter");
|
this.kampfleiter = kampfleiter;
|
||||||
this.ergebnis = rs.getInt("Ergebnis");
|
this.ergebnis = ergebnis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EventFight get(int fightID){
|
public void setErgebnis(int winner) {
|
||||||
return get.select(rs -> {
|
Provider.impl.setEventFightResult(this, winner);
|
||||||
rs.next();
|
|
||||||
return new EventFight(rs);
|
|
||||||
}, fightID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setErgebnis(int winner){
|
public void setFight(int fight) {
|
||||||
setResult.update(winner, fightID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFight(int fight){
|
|
||||||
//Fight.FightID, not EventFight.FightID
|
//Fight.FightID, not EventFight.FightID
|
||||||
setFight.update(fight, fightID);
|
Provider.impl.setEventFightFightID(this, fight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTeamBlue() {
|
public int getTeamBlue() {
|
||||||
|
@ -27,32 +27,19 @@ import java.util.function.Consumer;
|
|||||||
public class Fight {
|
public class Fight {
|
||||||
private Fight(){}
|
private Fight(){}
|
||||||
|
|
||||||
private static final Statement create = new Statement("INSERT INTO Fight (GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition, ReplayLock) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
||||||
private static final Statement lastId = new Statement("SELECT LAST_INSERT_ID() AS FightID");
|
|
||||||
private static final Statement getReplay = new Statement("SELECT Replay FROM Fight WHERE FightID = ?");
|
|
||||||
private static final Statement setReplay = new Statement("UPDATE Fight SET Replay = ? WHERE FightID = ?");
|
|
||||||
|
|
||||||
public static int create(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){
|
public static int create(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){
|
||||||
return create(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition, Timestamp.from(Instant.now()));
|
return create(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition, Timestamp.from(Instant.now()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int create(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock){
|
public static int create(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock){
|
||||||
create.update(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition, replayLock);
|
return Provider.impl.createFight(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition, replayLock);
|
||||||
return lastId.select(rs -> {
|
|
||||||
rs.next();
|
|
||||||
return rs.getInt("FightID");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getReplay(int fightID, Consumer<InputStream> reader) {
|
public static void getReplay(int fightID, Consumer<InputStream> reader) {
|
||||||
getReplay.select(rs -> {
|
Provider.impl.getReplay(fightID, reader);
|
||||||
rs.next();
|
|
||||||
reader.accept(rs.getBinaryStream("Replay"));
|
|
||||||
return null;
|
|
||||||
}, fightID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setReplay(int fightID, InputStream data) {
|
public static void setReplay(int fightID, InputStream data) {
|
||||||
setReplay.update(data, fightID);
|
Provider.impl.setReplay(fightID, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,7 @@ package de.steamwar.sql;
|
|||||||
public class FightPlayer {
|
public class FightPlayer {
|
||||||
private FightPlayer(){}
|
private FightPlayer(){}
|
||||||
|
|
||||||
private static final Statement create = new Statement("INSERT INTO FightPlayer (FightID, UserID, Team, Kit, Kills, IsOut) VALUES (?, ?, ?, ?, ?, ?)");
|
|
||||||
|
|
||||||
public static void create(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut){
|
public static void create(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut){
|
||||||
create.update(fightID, userID, blue ? 1 : 2, kit, kills, isOut);
|
Provider.impl.createFightPlayer(fightID, userID, blue, kit, kills, isOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
public class NodeDownload {
|
public class NodeDownload {
|
||||||
|
private NodeDownload() {}
|
||||||
private static final Statement createLink = new Statement("INSERT INTO NodeDownload (NodeId, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)");
|
|
||||||
|
|
||||||
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ public class NodeDownload {
|
|||||||
digest.reset();
|
digest.reset();
|
||||||
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
|
digest.update((Instant.now().toString() + schem.getOwner() + schem.getId()).getBytes());
|
||||||
String hash = BaseEncoding.base16().encode(digest.digest());
|
String hash = BaseEncoding.base16().encode(digest.digest());
|
||||||
createLink.update(schem.getId(), hash);
|
Provider.impl.createDownloadLink(schem.getId(), hash);
|
||||||
return BASE + hash;
|
return BASE + hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,56 +19,36 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class NodeMember {
|
public class NodeMember {
|
||||||
|
|
||||||
private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?");
|
|
||||||
private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?");
|
|
||||||
private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?");
|
|
||||||
private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)");
|
|
||||||
private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?");
|
|
||||||
|
|
||||||
public static NodeMember getNodeMember(int node, int member) {
|
public static NodeMember getNodeMember(int node, int member) {
|
||||||
return getNodeMember.select(rs -> {
|
return Provider.impl.getNodeMember(node, member);
|
||||||
if(!rs.next())
|
|
||||||
return null;
|
|
||||||
return new NodeMember(rs);
|
|
||||||
}, node, member);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<NodeMember> getNodeMembers(int node) {
|
public static Set<NodeMember> getNodeMembers(int node) {
|
||||||
return getNodeMembers.select(rs -> {
|
return Provider.impl.getNodeMembers(node);
|
||||||
Set<NodeMember> members = new HashSet<>();
|
|
||||||
while (rs.next())
|
|
||||||
members.add(new NodeMember(rs));
|
|
||||||
return members;
|
|
||||||
}, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<NodeMember> getSchematics(int member) {
|
public static Set<NodeMember> getSchematics(int member) {
|
||||||
return getSchematics.select(rs -> {
|
return Provider.impl.getMemberSchematics(member);
|
||||||
Set<NodeMember> members = new HashSet<>();
|
|
||||||
while (rs.next())
|
|
||||||
members.add(new NodeMember(rs));
|
|
||||||
return members;
|
|
||||||
}, member);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeMember createNodeMember(int node, int member) {
|
public static NodeMember createNodeMember(int node, int member) {
|
||||||
createNodeMember.update(node, member);
|
Provider.impl.createNodeMember(node, member);
|
||||||
return getNodeMember(node, member);
|
return getNodeMember(node, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int node;
|
private final int node;
|
||||||
final int member;
|
private final int member;
|
||||||
|
private final Consumer<NodeMember> delete;
|
||||||
|
|
||||||
private NodeMember(ResultSet set) throws SQLException {
|
public NodeMember(int node, int member, Consumer<NodeMember> delete) {
|
||||||
node = set.getInt("NodeId");
|
this.node = node;
|
||||||
member = set.getInt("UserId");
|
this.member = member;
|
||||||
|
this.delete = delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNode() {
|
public int getNode() {
|
||||||
@ -80,6 +60,6 @@ public class NodeMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
deleteNodeMember.update(node, member);
|
delete.accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,31 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class PersonalKit {
|
public class PersonalKit {
|
||||||
|
|
||||||
private static final Statement getKits = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?");
|
public static List<PersonalKit> get(int userID, String gamemode){
|
||||||
private static final Statement getKit = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?");
|
return Provider.impl.getKits(userID, gamemode);
|
||||||
private static final Statement getKitInUse = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND InUse = 1");
|
}
|
||||||
private static final Statement delete = new Statement("DELETE FROM `PersonalKit` WHERE UserID = ? AND GameMode = ? AND Name = ?");
|
|
||||||
private static final Statement update = new Statement("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor, InUse) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(Name), InUse = VALUES(InUse)");
|
public static PersonalKit get(int userID, String gamemode, String name) {
|
||||||
|
return Provider.impl.getKit(userID, gamemode, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){
|
||||||
|
if(armor == null) {
|
||||||
|
armor = new ItemStack[]{null, null, null, null};
|
||||||
|
}
|
||||||
|
PersonalKit kit = new PersonalKit(userID, name, gamemode, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor), true);
|
||||||
|
Provider.impl.updateKit(kit);
|
||||||
|
return kit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PersonalKit getKitInUse(int userID, String gamemode) {
|
||||||
|
return Provider.impl.getKitInUse(userID, gamemode);
|
||||||
|
}
|
||||||
|
|
||||||
private final int userID;
|
private final int userID;
|
||||||
private String name;
|
private String name;
|
||||||
@ -44,49 +56,13 @@ public class PersonalKit {
|
|||||||
private String armor;
|
private String armor;
|
||||||
private boolean inUse;
|
private boolean inUse;
|
||||||
|
|
||||||
private PersonalKit(ResultSet rs) throws SQLException {
|
public PersonalKit(int userID, String name, String gamemode, String inventory, String armor, boolean inUse) {
|
||||||
userID = rs.getInt("UserID");
|
this.userID = userID;
|
||||||
gamemode = rs.getString("GameMode");
|
this.name = name;
|
||||||
inventory = rs.getString("Inventory");
|
this.gamemode = gamemode;
|
||||||
armor = rs.getString("Armor");
|
this.inventory = inventory;
|
||||||
name = rs.getString("Name");
|
this.armor = armor;
|
||||||
inUse = rs.getBoolean("InUse");
|
this.inUse = inUse;
|
||||||
}
|
|
||||||
|
|
||||||
public static List<PersonalKit> get(int userID, String gamemode){
|
|
||||||
return getKits.select(rs -> {
|
|
||||||
List<PersonalKit> list = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
list.add(new PersonalKit(rs));
|
|
||||||
return list;
|
|
||||||
}, userID, gamemode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PersonalKit get(int userID, String gamemode, String name) {
|
|
||||||
return getKit.select(rs -> {
|
|
||||||
if(rs.next())
|
|
||||||
return new PersonalKit(rs);
|
|
||||||
return null;
|
|
||||||
}, userID, gamemode, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PersonalKit create(int userID, String gamemode, String name, ItemStack[] inventory, ItemStack[] armor){
|
|
||||||
if(armor == null) {
|
|
||||||
armor = new ItemStack[]{null, null, null, null};
|
|
||||||
}
|
|
||||||
update.update(userID, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor), true);
|
|
||||||
return get(userID, gamemode, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PersonalKit getKitInUse(int userID, String gamemode) {
|
|
||||||
return getKitInUse.select(rs -> {
|
|
||||||
if(!rs.next())
|
|
||||||
return null;
|
|
||||||
PersonalKit kit = new PersonalKit(rs);
|
|
||||||
while (rs.next())
|
|
||||||
new PersonalKit(rs).setUse(false); //TODO: Violation of integrity, should not be necessary?
|
|
||||||
return kit;
|
|
||||||
}, userID, gamemode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getInventory(){
|
public ItemStack[] getInventory(){
|
||||||
@ -107,6 +83,18 @@ public class PersonalKit {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGamemode() {
|
||||||
|
return gamemode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRawInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRawArmor() {
|
||||||
|
return armor;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInUse() {
|
public boolean isInUse() {
|
||||||
return inUse;
|
return inUse;
|
||||||
}
|
}
|
||||||
@ -120,32 +108,32 @@ public class PersonalKit {
|
|||||||
|
|
||||||
private void setUse(boolean inUse) {
|
private void setUse(boolean inUse) {
|
||||||
this.inUse = inUse;
|
this.inUse = inUse;
|
||||||
updateDB();
|
Provider.impl.updateKit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
updateDB();
|
Provider.impl.updateKit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInventory(ItemStack[] inventory) {
|
public void setInventory(ItemStack[] inventory) {
|
||||||
this.inventory = saveInvConfig("Inventory", inventory);
|
this.inventory = saveInvConfig("Inventory", inventory);
|
||||||
updateDB();
|
Provider.impl.updateKit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArmor(ItemStack[] armor) {
|
public void setArmor(ItemStack[] armor) {
|
||||||
this.armor = saveInvConfig("Armor", armor);
|
this.armor = saveInvConfig("Armor", armor);
|
||||||
updateDB();
|
Provider.impl.updateKit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContainer(ItemStack[] inventory, ItemStack[] armor) {
|
public void setContainer(ItemStack[] inventory, ItemStack[] armor) {
|
||||||
this.armor = saveInvConfig("Armor", armor);
|
this.armor = saveInvConfig("Armor", armor);
|
||||||
this.inventory = saveInvConfig("Inventory", inventory);
|
this.inventory = saveInvConfig("Inventory", inventory);
|
||||||
updateDB();
|
Provider.impl.updateKit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
delete.update(userID, gamemode, name);
|
Provider.impl.deleteKit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String saveInvConfig(String name, ItemStack[] inv) {
|
private static String saveInvConfig(String name, ItemStack[] inv) {
|
||||||
@ -154,8 +142,4 @@ public class PersonalKit {
|
|||||||
|
|
||||||
return armorConfig.saveToString();
|
return armorConfig.saveToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB() {
|
|
||||||
update.update(userID, gamemode, name, inventory, armor, inUse);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
104
SpigotCore_Main/src/de/steamwar/sql/Provider.java
Normale Datei
104
SpigotCore_Main/src/de/steamwar/sql/Provider.java
Normale Datei
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 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.sql;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface Provider {
|
||||||
|
Provider impl = Core.standalone() ? new StandaloneProvider() : new SQLProvider();
|
||||||
|
|
||||||
|
BauweltMember getBauMember(int ownerID, int memberID);
|
||||||
|
List<BauweltMember> getMembers(int bauweltID);
|
||||||
|
|
||||||
|
List<CheckedSchematic> getLastDeclinedOfNode(int node);
|
||||||
|
List<CheckedSchematic> getLastDelined(int schemOwner);
|
||||||
|
|
||||||
|
int getElo(int userId, String gameMode);
|
||||||
|
void setElo(int userId, String gameMode, int elo);
|
||||||
|
|
||||||
|
Event getEvent(int eventID);
|
||||||
|
EventFight getEventFight(int fightID);
|
||||||
|
void setEventFightResult(EventFight fight, int winner);
|
||||||
|
void setEventFightFightID(EventFight fight, int fightID);
|
||||||
|
|
||||||
|
int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock);
|
||||||
|
void getReplay(int fightID, Consumer<InputStream> reader);
|
||||||
|
void setReplay(int fightID, InputStream data);
|
||||||
|
|
||||||
|
void createFightPlayer(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut);
|
||||||
|
|
||||||
|
void createDownloadLink(int nodeId, String hash);
|
||||||
|
|
||||||
|
NodeMember getNodeMember(int node, int member);
|
||||||
|
Set<NodeMember> getNodeMembers(int node);
|
||||||
|
Set<NodeMember> getMemberSchematics(int member);
|
||||||
|
void createNodeMember(int node, int member);
|
||||||
|
|
||||||
|
List<PersonalKit> getKits(int userID, String gamemode);
|
||||||
|
PersonalKit getKit(int userID, String gamemode, String name);
|
||||||
|
void updateKit(PersonalKit kit);
|
||||||
|
void deleteKit(PersonalKit kit);
|
||||||
|
PersonalKit getKitInUse(int userID, String gamemode);
|
||||||
|
|
||||||
|
Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type);
|
||||||
|
Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user);
|
||||||
|
|
||||||
|
SteamwarUser getUserByName(String userName);
|
||||||
|
SteamwarUser getUserByUUID(UUID uuid);
|
||||||
|
SteamwarUser getUserByID(int id);
|
||||||
|
|
||||||
|
void logException(String server, String message, String stacktrace);
|
||||||
|
|
||||||
|
Team getTeam(int id);
|
||||||
|
List<Integer> getTeamMembers(Team team);
|
||||||
|
|
||||||
|
String getConfig(int player, String config);
|
||||||
|
void updatePlayerConfig(int id, String config, String value);
|
||||||
|
void removePlayerConfig(int id, String config);
|
||||||
|
|
||||||
|
void createSchematicNode(int owner, String name, Integer parent, String type, String item);
|
||||||
|
SchematicNode getSchematicNode(int owner, String name, Integer parent);
|
||||||
|
List<SchematicNode> getSchematicNodeInNode(Integer parent);
|
||||||
|
List<SchematicNode> getSchematicDirectoryInNode(Integer parent);
|
||||||
|
SchematicNode getSchematicDirectory(String name, Integer parent);
|
||||||
|
SchematicNode getSchematicNode(String name, Integer parent);
|
||||||
|
SchematicNode getSchematicNode(int id);
|
||||||
|
List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent);
|
||||||
|
List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType);
|
||||||
|
List<SchematicNode> getAllSchematicsOfType(int owner, String schemType);
|
||||||
|
List<SchematicNode> getAllSchematicsOfType(String schemType);
|
||||||
|
List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent);
|
||||||
|
List<SchematicNode> getAllSchematicsAccessibleByUser(int user);
|
||||||
|
List<SchematicNode> getAllParentsOfNode(int node);
|
||||||
|
Integer countNodes();
|
||||||
|
void updateSchematicNode(SchematicNode node);
|
||||||
|
void deleteSchematicNode(SchematicNode node);
|
||||||
|
InputStream getSchematicData(SchematicNode node) throws IOException;
|
||||||
|
void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat);
|
||||||
|
}
|
@ -22,33 +22,21 @@ package de.steamwar.sql;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Punishment {
|
public class Punishment {
|
||||||
|
|
||||||
private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
|
||||||
private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
|
|
||||||
|
|
||||||
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
|
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
|
||||||
return getPunishment.select(rs -> {
|
return Provider.impl.getPunishmentOfPlayer(user, type);
|
||||||
if (rs.next())
|
|
||||||
return new Punishment(rs);
|
|
||||||
return null;
|
|
||||||
}, user, type.name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||||
return getPunishments.select(rs -> {
|
return Provider.impl.getPunishmentsOfPlayer(user);
|
||||||
Map<PunishmentType, Punishment> punishments = new HashMap<>();
|
|
||||||
while (rs.next())
|
|
||||||
punishments.put(PunishmentType.valueOf(rs.getString("Type")), new Punishment(rs));
|
|
||||||
return punishments;
|
|
||||||
}, user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPunished(SteamwarUser user, Punishment.PunishmentType type, Consumer<Punishment> callback) {
|
public static boolean isPunished(SteamwarUser user, Punishment.PunishmentType type, Consumer<Punishment> callback) {
|
||||||
@ -61,24 +49,23 @@ public class Punishment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Timestamp startTime;
|
|
||||||
private Timestamp endTime;
|
|
||||||
private final PunishmentType type;
|
|
||||||
private final int user;
|
|
||||||
private final int id;
|
|
||||||
private String reason;
|
|
||||||
private final int punisher;
|
|
||||||
private boolean perma;
|
|
||||||
|
|
||||||
private Punishment(ResultSet set) throws SQLException {
|
private final int user;
|
||||||
user = set.getInt("UserId");
|
private final int punisher;
|
||||||
reason = set.getString("Reason");
|
private final PunishmentType type;
|
||||||
type = PunishmentType.valueOf(set.getString("Type"));
|
private final Timestamp startTime;
|
||||||
startTime = set.getTimestamp("StartTime");
|
private final Timestamp endTime;
|
||||||
endTime = set.getTimestamp("EndTime");
|
private final boolean perma;
|
||||||
punisher = set.getInt("Punisher");
|
private final String reason;
|
||||||
perma = set.getBoolean("Perma");
|
|
||||||
id = set.getInt("PunishmentId");
|
public Punishment(int user, int punisher, PunishmentType type, Timestamp startTime, Timestamp endTime, boolean perma, String reason) {
|
||||||
|
this.user = user;
|
||||||
|
this.punisher = punisher;
|
||||||
|
this.type = type;
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.endTime = endTime;
|
||||||
|
this.perma = perma;
|
||||||
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getStartTime() {
|
public Timestamp getStartTime() {
|
||||||
|
605
SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java
Normale Datei
605
SpigotCore_Main/src/de/steamwar/sql/SQLProvider.java
Normale Datei
@ -0,0 +1,605 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 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.sql;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.sql.Blob;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
public class SQLProvider implements Provider {
|
||||||
|
|
||||||
|
private static final Statement getBauMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
|
||||||
|
@Override
|
||||||
|
public BauweltMember getBauMember(int ownerID, int memberID) {
|
||||||
|
return getBauMember.select(rs -> rs.next() ? newBauweltMember(rs) : null, ownerID, memberID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getBauMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?");
|
||||||
|
@Override
|
||||||
|
public List<BauweltMember> getMembers(int bauweltID) {
|
||||||
|
return getBauMembers.select(rs -> {
|
||||||
|
List<BauweltMember> members = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
members.add(newBauweltMember(rs));
|
||||||
|
return members;
|
||||||
|
}, bauweltID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BauweltMember newBauweltMember(ResultSet rs) throws SQLException {
|
||||||
|
return new BauweltMember(rs.getInt("BauweltID"), rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement nodeHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
||||||
|
@Override
|
||||||
|
public List<CheckedSchematic> getLastDeclinedOfNode(int node) {
|
||||||
|
return nodeHistory.select(rs -> {
|
||||||
|
List<CheckedSchematic> lastDeclined = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
lastDeclined.add(newCheckedSchematic(rs));
|
||||||
|
return lastDeclined;
|
||||||
|
}, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement checkHistory = new Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' AND NodeId is not NULL ORDER BY EndTime DESC");
|
||||||
|
@Override
|
||||||
|
public List<CheckedSchematic> getLastDelined(int schemOwner) {
|
||||||
|
return checkHistory.select(rs -> {
|
||||||
|
List<CheckedSchematic> history = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
history.add(newCheckedSchematic(rs));
|
||||||
|
return history;
|
||||||
|
}, schemOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CheckedSchematic newCheckedSchematic(ResultSet rs) throws SQLException {
|
||||||
|
return new CheckedSchematic(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getElo = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?");
|
||||||
|
@Override
|
||||||
|
public int getElo(int userId, String gameMode) {
|
||||||
|
return getElo.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return rs.getInt("Elo");
|
||||||
|
return 1000;
|
||||||
|
}, userId, gameMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement setElo = new Statement("INSERT INTO Elo (UserID, GameMode, Elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Elo = VALUES(Elo)");
|
||||||
|
@Override
|
||||||
|
public void setElo(int userId, String gameMode, int elo) {
|
||||||
|
setElo.update(userId, gameMode, elo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getEvent = new Statement("SELECT * FROM Event WHERE EventID = ?");
|
||||||
|
@Override
|
||||||
|
public Event getEvent(int eventID) {
|
||||||
|
return getEvent.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return new Event(rs.getInt("EventID"), rs.getString("EventName"), rs.getTimestamp("Start"), rs.getTimestamp("End"), rs.getInt("MaximumTeamMembers"), rs.getBoolean("PublicSchemsOnly"), rs.getBoolean("SpectateSystem"));
|
||||||
|
}, eventID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getEventFight = new Statement("SELECT * FROM EventFight WHERE FightID = ?");
|
||||||
|
@Override
|
||||||
|
public EventFight getEventFight(int fightID) {
|
||||||
|
return getEventFight.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return new EventFight(rs.getInt("EventID"), rs.getInt("FightID"), rs.getInt("TeamBlue"), rs.getInt("TeamRed"), rs.getInt("Kampfleiter"), rs.getInt("Ergebnis"));
|
||||||
|
}, fightID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement setEventFightResult = new Statement("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?");
|
||||||
|
@Override
|
||||||
|
public void setEventFightResult(EventFight fight, int winner) {
|
||||||
|
setEventFightResult.update(winner, fight.getFightID());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement setEventFightFightID = new Statement("UPDATE EventFight SET Fight = ? WHERE FightID = ?");
|
||||||
|
@Override
|
||||||
|
public void setEventFightFightID(EventFight fight, int fightID) {
|
||||||
|
setEventFightFightID.update(fight, fight.getFightID());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement createFight = new Statement("INSERT INTO Fight (GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition, ReplayLock) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
private static final Statement getLastFightID = new Statement("SELECT LAST_INSERT_ID() AS FightID");
|
||||||
|
@Override
|
||||||
|
public int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock) {
|
||||||
|
createFight.update(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition, replayLock);
|
||||||
|
return getLastFightID.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return rs.getInt("FightID");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getReplay = new Statement("SELECT Replay FROM Fight WHERE FightID = ?");
|
||||||
|
@Override
|
||||||
|
public void getReplay(int fightID, Consumer<InputStream> reader) {
|
||||||
|
getReplay.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
reader.accept(rs.getBinaryStream("Replay"));
|
||||||
|
return null;
|
||||||
|
}, fightID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement setReplay = new Statement("UPDATE Fight SET Replay = ? WHERE FightID = ?");
|
||||||
|
@Override
|
||||||
|
public void setReplay(int fightID, InputStream data) {
|
||||||
|
setReplay.update(data, fightID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement create = new Statement("INSERT INTO FightPlayer (FightID, UserID, Team, Kit, Kills, IsOut) VALUES (?, ?, ?, ?, ?, ?)");
|
||||||
|
@Override
|
||||||
|
public void createFightPlayer(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut) {
|
||||||
|
create.update(fightID, userID, blue ? 1 : 2, kit, kills, isOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement createLink = new Statement("INSERT INTO NodeDownload (NodeId, Link) VALUES (?, ?) ON DUPLICATE KEY UPDATE Link = VALUES(Link)");
|
||||||
|
@Override
|
||||||
|
public void createDownloadLink(int nodeId, String hash) {
|
||||||
|
createLink.update(nodeId, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getNodeMember = new Statement("SELECT * FROM NodeMember WHERE NodeId = ? AND UserId = ?");
|
||||||
|
@Override
|
||||||
|
public NodeMember getNodeMember(int node, int member) {
|
||||||
|
return getNodeMember.select(rs -> {
|
||||||
|
if(!rs.next())
|
||||||
|
return null;
|
||||||
|
return newNodeMember(rs);
|
||||||
|
}, node, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getNodeMembers = new Statement("SELECT * FROM NodeMember WHERE NodeId = ?");
|
||||||
|
@Override
|
||||||
|
public Set<NodeMember> getNodeMembers(int node) {
|
||||||
|
return getNodeMembers.select(rs -> {
|
||||||
|
Set<NodeMember> members = new HashSet<>();
|
||||||
|
while (rs.next())
|
||||||
|
members.add(newNodeMember(rs));
|
||||||
|
return members;
|
||||||
|
}, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getSchematics = new Statement("SELECT * FROM NodeMember WHERE UserId = ?");
|
||||||
|
@Override
|
||||||
|
public Set<NodeMember> getMemberSchematics(int member) {
|
||||||
|
return getSchematics.select(rs -> {
|
||||||
|
Set<NodeMember> members = new HashSet<>();
|
||||||
|
while (rs.next())
|
||||||
|
members.add(newNodeMember(rs));
|
||||||
|
return members;
|
||||||
|
}, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement deleteNodeMember = new Statement("DELETE FROM NodeMember WHERE NodeId = ? AND UserId = ?");
|
||||||
|
private NodeMember newNodeMember(ResultSet rs) throws SQLException {
|
||||||
|
return new NodeMember(rs.getInt("NodeId"), rs.getInt("UserId"), member -> deleteNodeMember.update(member.getNode(), member.getMember()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement createNodeMember = new Statement("INSERT INTO NodeMember (NodeId, UserId) VALUES (?, ?)");
|
||||||
|
@Override
|
||||||
|
public void createNodeMember(int node, int member) {
|
||||||
|
createNodeMember.update(node, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getKits = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?");
|
||||||
|
@Override
|
||||||
|
public List<PersonalKit> getKits(int userID, String gamemode) {
|
||||||
|
return getKits.select(rs -> {
|
||||||
|
List<PersonalKit> list = new ArrayList<>();
|
||||||
|
while (rs.next())
|
||||||
|
list.add(newPersonalKit(rs));
|
||||||
|
return list;
|
||||||
|
}, userID, gamemode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getKit = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND Name = ?");
|
||||||
|
@Override
|
||||||
|
public PersonalKit getKit(int userID, String gamemode, String name) {
|
||||||
|
return getKit.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return newPersonalKit(rs);
|
||||||
|
return null;
|
||||||
|
}, userID, gamemode, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PersonalKit newPersonalKit(ResultSet rs) throws SQLException {
|
||||||
|
return new PersonalKit(rs.getInt("UserID"), rs.getString("Name"), rs.getString("GameMode"), rs.getString("Inventory"), rs.getString("Armor"), rs.getBoolean("InUse"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement updateKit = new Statement("INSERT INTO PersonalKit (UserID, GameMode, Name, Inventory, Armor, InUse) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor), Name = VALUES(Name), InUse = VALUES(InUse)");
|
||||||
|
@Override
|
||||||
|
public void updateKit(PersonalKit kit) {
|
||||||
|
updateKit.update(kit.getUserID(), kit.getGamemode(), kit.getName(), kit.getRawInventory(), kit.getRawArmor(), kit.isInUse());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement deleteKit = new Statement("DELETE FROM `PersonalKit` WHERE UserID = ? AND GameMode = ? AND Name = ?");
|
||||||
|
@Override
|
||||||
|
public void deleteKit(PersonalKit kit) {
|
||||||
|
deleteKit.update(kit.getUserID(), kit.getGamemode(), kit.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getKitInUse = new Statement("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ? AND InUse = 1");
|
||||||
|
@Override
|
||||||
|
public PersonalKit getKitInUse(int userID, String gamemode) {
|
||||||
|
return getKitInUse.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return newPersonalKit(rs);
|
||||||
|
return null;
|
||||||
|
}, userID, gamemode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
||||||
|
@Override
|
||||||
|
public Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type) {
|
||||||
|
return getPunishment.select(rs -> {
|
||||||
|
if (rs.next())
|
||||||
|
return newPunishment(rs);
|
||||||
|
return null;
|
||||||
|
}, user, type.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Punishment newPunishment(ResultSet rs) throws SQLException {
|
||||||
|
return new Punishment(rs.getInt("UserId"), rs.getInt("Punisher"), Punishment.PunishmentType.valueOf(rs.getString("Type")), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getBoolean("Perma"), rs.getString("Reason"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
|
||||||
|
@Override
|
||||||
|
public Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||||
|
return getPunishments.select(rs -> {
|
||||||
|
Map<Punishment.PunishmentType, Punishment> punishments = new HashMap<>();
|
||||||
|
while (rs.next())
|
||||||
|
punishments.put(Punishment.PunishmentType.valueOf(rs.getString("Type")), newPunishment(rs));
|
||||||
|
return punishments;
|
||||||
|
}, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getUserName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
|
||||||
|
@Override
|
||||||
|
public SteamwarUser getUserByName(String userName) {
|
||||||
|
return getUserName.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return newSteamwarUser(rs);
|
||||||
|
return null;
|
||||||
|
}, userName.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getUserUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?");
|
||||||
|
@Override
|
||||||
|
public SteamwarUser getUserByUUID(UUID uuid) {
|
||||||
|
return getUserUUID.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return newSteamwarUser(rs);
|
||||||
|
}, uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getUserId = new Statement("SELECT * FROM UserData WHERE id = ?");
|
||||||
|
@Override
|
||||||
|
public SteamwarUser getUserByID(int id) {
|
||||||
|
return getUserId.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return newSteamwarUser(rs);
|
||||||
|
}, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SteamwarUser newSteamwarUser(ResultSet rs) throws SQLException {
|
||||||
|
return new SteamwarUser(rs.getInt("id"), UUID.fromString(rs.getString("UUID")), rs.getString("UserName"), UserGroup.getUsergroup(rs.getString("UserGroup")), rs.getInt("Team"), rs.getBoolean("Bedrock"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
|
||||||
|
@Override
|
||||||
|
public void logException(String server, String message, String stacktrace) {
|
||||||
|
insert.update(server, message, stacktrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getTeam = new Statement("SELECT * FROM Team WHERE TeamID = ?");
|
||||||
|
@Override
|
||||||
|
public Team getTeam(int id) {
|
||||||
|
return getTeam.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return new Team(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
|
||||||
|
}, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getTeamMembers = new Statement("SELECT id FROM UserData WHERE Team = ?");
|
||||||
|
@Override
|
||||||
|
public List<Integer> getTeamMembers(Team team) {
|
||||||
|
return getTeamMembers.select(rs -> {
|
||||||
|
List<Integer> members = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
members.add(rs.getInt("id"));
|
||||||
|
return members;
|
||||||
|
}, team.getTeamId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement getConfig = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
|
||||||
|
@Override
|
||||||
|
public String getConfig(int player, String config) {
|
||||||
|
return getConfig.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return rs.getString("Value");
|
||||||
|
return null;
|
||||||
|
}, player, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement setConfig = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
|
||||||
|
@Override
|
||||||
|
public void updatePlayerConfig(int id, String config, String value) {
|
||||||
|
setConfig.update(id, config, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement deleteConfig = new Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
|
||||||
|
@Override
|
||||||
|
public void removePlayerConfig(int id, String config) {
|
||||||
|
deleteConfig.update(id, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)");
|
||||||
|
private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
|
||||||
|
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
|
||||||
|
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ");
|
||||||
|
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||||
|
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
||||||
|
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||||
|
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||||
|
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
|
||||||
|
private static final Statement.ResultSetUser<List<SchematicNode>> toSchematicList = rs -> {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
nodes.add(nodeFromResultSet(rs));
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
};
|
||||||
|
private static final Statement.ResultSetUser<SchematicNode> toSchematicNode = rs -> {
|
||||||
|
if (rs.next()) {
|
||||||
|
return nodeFromResultSet(rs);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
private static SchematicNode nodeFromResultSet(ResultSet set) throws SQLException {
|
||||||
|
Integer parent = set.getInt("ParentNode");
|
||||||
|
if(set.wasNull()) {
|
||||||
|
parent = null;
|
||||||
|
}
|
||||||
|
String type = set.getString("NodeType");
|
||||||
|
boolean isDir = true;
|
||||||
|
int rank = 0;
|
||||||
|
boolean schemFormat = false;
|
||||||
|
if (type != null) {
|
||||||
|
isDir = false;
|
||||||
|
rank = set.getInt("NodeRank");
|
||||||
|
schemFormat = set.getBoolean("NodeFormat");
|
||||||
|
}
|
||||||
|
return new SchematicNode(
|
||||||
|
set.getInt("NodeId"),
|
||||||
|
set.getInt("NodeOwner"),
|
||||||
|
set.getString("NodeName"),
|
||||||
|
parent,
|
||||||
|
set.getString("NodeItem"),
|
||||||
|
type,
|
||||||
|
isDir,
|
||||||
|
rank,
|
||||||
|
set.getTimestamp("LastUpdate"),
|
||||||
|
schemFormat
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||||
|
createNode.update(name, owner, parent, type, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||||
|
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicNode_Null.select(toSchematicNode, owner, name);
|
||||||
|
} else {
|
||||||
|
return getSchematicNode.select(toSchematicNode, owner, name, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicsInNode_Null.select(toSchematicList);
|
||||||
|
}else {
|
||||||
|
return getSchematicsInNode.select(toSchematicList, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
|
if(parent == null) {
|
||||||
|
return getDirsInNode_Null.select(toSchematicList);
|
||||||
|
}else {
|
||||||
|
return getDirsInNode.select(toSchematicList, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||||
|
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
||||||
|
while (rs.next()) {
|
||||||
|
SchematicNode node = nodeFromResultSet(rs);
|
||||||
|
if(node.isDir())
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicDirectory_Null.select(user, name);
|
||||||
|
}else {
|
||||||
|
return getSchematicDirectory.select(user, name, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(String name, Integer parent) {
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicNodeO_Null.select(toSchematicNode, name);
|
||||||
|
}else {
|
||||||
|
return getSchematicNodeO.select(toSchematicNode, name, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int id) {
|
||||||
|
return getSchematicNodeId.select(rs -> {
|
||||||
|
if (!rs.next())
|
||||||
|
return null;
|
||||||
|
return nodeFromResultSet(rs);
|
||||||
|
}, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||||
|
if(parent == null || parent == 0) {
|
||||||
|
return getAccessibleByUserByTypeInNode_Null.select(toSchematicList, owner, owner, schemType);
|
||||||
|
} else {
|
||||||
|
return getAccessibleByUserByTypeInNode.select(toSchematicList, owner, owner, schemType, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||||
|
return getAccessibleByUserByType.select(toSchematicList, user, user, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
|
return getAllSchemsOfTypeOwner.select(toSchematicList, owner, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
|
return getAllSchemsOfType.select(toSchematicList, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
|
if (parent != null && parent != 0) {
|
||||||
|
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return rs.getInt("Accessible") > 0;
|
||||||
|
}, parent, user, user))) {
|
||||||
|
return getSchematicNodeInNode(parent);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return getAccessibleByUser.select(rs -> {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
nodes.add(nodeFromResultSet(rs));
|
||||||
|
return nodes;
|
||||||
|
}, user, user, user, user);
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
|
return getAllSchematicsAccessibleByUser.select(toSchematicList, user, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
|
return getAllParentsOfNode.select(toSchematicList, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer countNodes() {
|
||||||
|
return countNodes.select(rs -> {
|
||||||
|
if (rs.next()) {
|
||||||
|
return rs.getInt("count");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSchematicNode(SchematicNode node) {
|
||||||
|
updateDB.update(
|
||||||
|
node.getName(),
|
||||||
|
node.getOwner(),
|
||||||
|
node.getParent(),
|
||||||
|
node.getItem(),
|
||||||
|
node.getType(),
|
||||||
|
node.getRank(),
|
||||||
|
node.getId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteSchematicNode(SchematicNode node) {
|
||||||
|
deleteNode.update(node.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getSchematicData(SchematicNode node) throws IOException {
|
||||||
|
try {
|
||||||
|
return selSchemData.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
Blob schemData = rs.getBlob("NodeData");
|
||||||
|
if(schemData == null) {
|
||||||
|
throw new SecurityException("SchemData is null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new GZIPInputStream(schemData.getBinaryStream());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException("SchemData is wrong", e);
|
||||||
|
}
|
||||||
|
}, node.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) {
|
||||||
|
updateDatabase.update(blob, newFormat, node.getId());
|
||||||
|
}
|
||||||
|
}
|
@ -25,8 +25,6 @@ import org.bukkit.entity.Player;
|
|||||||
public class SWException {
|
public class SWException {
|
||||||
private SWException(){}
|
private SWException(){}
|
||||||
|
|
||||||
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
|
|
||||||
|
|
||||||
public static void log(String message, String stacktrace){
|
public static void log(String message, String stacktrace){
|
||||||
message += "\n";
|
message += "\n";
|
||||||
for(Player player : Bukkit.getOnlinePlayers())
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
@ -38,6 +36,6 @@ public class SWException {
|
|||||||
else
|
else
|
||||||
server = Bukkit.getWorlds().get(0).getName();
|
server = Bukkit.getWorlds().get(0).getName();
|
||||||
|
|
||||||
insert.update(server, message, stacktrace);
|
Provider.impl.logException(server, message, stacktrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,33 +39,6 @@ import java.util.zip.GZIPInputStream;
|
|||||||
|
|
||||||
public class SchematicNode {
|
public class SchematicNode {
|
||||||
|
|
||||||
private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)");
|
|
||||||
private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
|
|
||||||
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
|
|
||||||
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ");
|
|
||||||
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName");
|
|
||||||
private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
|
|
||||||
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
|
||||||
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
|
||||||
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
|
||||||
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
|
||||||
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
|
||||||
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
|
||||||
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
|
|
||||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||||
}
|
}
|
||||||
@ -77,7 +50,7 @@ public class SchematicNode {
|
|||||||
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||||
if (parent != null && parent == 0)
|
if (parent != null && parent == 0)
|
||||||
parent = null;
|
parent = null;
|
||||||
createNode.update(name, owner, parent, type, item);
|
Provider.impl.createSchematicNode(owner, name, parent, type, item);
|
||||||
return getSchematicNode(owner, name, parent);
|
return getSchematicNode(owner, name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,23 +58,29 @@ public class SchematicNode {
|
|||||||
return getSchematicNode(owner, name, parent.getId());
|
return getSchematicNode(owner, name, parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SchematicNode(ResultSet set) throws SQLException {
|
public SchematicNode(
|
||||||
id = set.getInt("NodeId");
|
int id,
|
||||||
owner = set.getInt("NodeOwner");
|
int owner,
|
||||||
name = set.getString("NodeName");
|
String name,
|
||||||
parent = set.getInt("ParentNode");
|
Integer parent,
|
||||||
if(set.wasNull()) {
|
String item,
|
||||||
parent = null;
|
String type,
|
||||||
}
|
boolean isDir,
|
||||||
item = set.getString("NodeItem");
|
int rank,
|
||||||
type = set.getString("NodeType");
|
Timestamp lastUpdate,
|
||||||
lastUpdate = set.getTimestamp("LastUpdate");
|
boolean schemFormat
|
||||||
if (type != null) {
|
) {
|
||||||
isDir = false;
|
this.id = id;
|
||||||
rank = set.getInt("NodeRank");
|
this.owner = owner;
|
||||||
schemFormat = set.getBoolean("NodeFormat");
|
this.name = name;
|
||||||
} else {
|
this.parent = parent;
|
||||||
isDir = true;
|
this.item = item;
|
||||||
|
this.type = type;
|
||||||
|
this.lastUpdate = lastUpdate;
|
||||||
|
this.isDir = isDir;
|
||||||
|
if (!isDir) {
|
||||||
|
this.schemFormat = schemFormat;
|
||||||
|
this.rank = rank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,136 +96,60 @@ public class SchematicNode {
|
|||||||
if (parent != null && parent == 0) {
|
if (parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
return Provider.impl.getSchematicNode(owner, name, parent);
|
||||||
if (rs.next()) {
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicNode_Null.select(user, owner, name);
|
|
||||||
} else {
|
|
||||||
return getSchematicNode.select(user, owner, name, parent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicsInNode_Null.select(user);
|
|
||||||
}else {
|
|
||||||
return getSchematicsInNode.select(user, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicNodeInNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getDirsInNode_Null.select(user);
|
|
||||||
}else {
|
|
||||||
return getDirsInNode.select(user, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicDirectoryInNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
SchematicNode node = new SchematicNode(rs);
|
|
||||||
if(node.isDir())
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicDirectory_Null.select(user, name);
|
|
||||||
}else {
|
|
||||||
return getSchematicDirectory.select(user, name, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicDirectory(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicNodeO_Null.select(user, name);
|
|
||||||
}else {
|
|
||||||
return getSchematicNodeO.select(user, name, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicNode(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int id) {
|
public static SchematicNode getSchematicNode(int id) {
|
||||||
return getSchematicNodeId.select(rs -> {
|
return Provider.impl.getSchematicNode(id);
|
||||||
if (!rs.next())
|
|
||||||
return null;
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
return Provider.impl.getAccessibleSchematicsOfTypeInParent(owner, schemType, parent);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null || parent == 0) {
|
|
||||||
return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType);
|
|
||||||
} else {
|
|
||||||
return getAccessibleByUserByTypeInNode.select(user, owner, owner, schemType, parent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||||
return getAccessibleByUserByType.select(rs -> {
|
return Provider.impl.getAllAccessibleSchematicsOfType(user, schemType);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, user, user, schemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
return getAllSchemsOfTypeOwner.select(rs -> {
|
return Provider.impl.getAllSchematicsOfType(owner, schemType);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, owner, schemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
return getAllSchemsOfType.select(rs -> {
|
return Provider.impl.getAllSchematicsOfType(schemType);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
}
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
public static List<SchematicNode> getAllSchematicsOfType(SchematicType schemType) {
|
||||||
return nodes;
|
return Provider.impl.getAllSchematicsOfType(schemType.toDB());
|
||||||
}, schemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
||||||
@ -264,32 +167,11 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
if (parent != null && parent != 0) {
|
return Provider.impl.getSchematicsAccessibleByUser(user, parent);
|
||||||
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
|
|
||||||
rs.next();
|
|
||||||
return rs.getInt("Accessible") > 0;
|
|
||||||
}, parent, user, user))) {
|
|
||||||
return getSchematicNodeInNode(parent);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return getAccessibleByUser.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, user, user, user, user);
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
return getAllSchematicsAccessibleByUser.select(rs -> {
|
return Provider.impl.getAllSchematicsAccessibleByUser(user);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, user, user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
||||||
@ -297,13 +179,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
return getAllParentsOfNode.select(rs -> {
|
return Provider.impl.getAllParentsOfNode(node);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
|
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
|
||||||
@ -367,12 +243,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Integer countNodes() {
|
public static Integer countNodes() {
|
||||||
return countNodes.select(rs -> {
|
return Provider.impl.countNodes();
|
||||||
if (rs.next()) {
|
|
||||||
return rs.getInt("count");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -501,32 +372,17 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB() {
|
private void updateDB() {
|
||||||
updateDB.update(name, owner, parent, item, type, rank, id);
|
Provider.impl.updateSchematicNode(this);
|
||||||
this.lastUpdate = Timestamp.from(Instant.now());
|
this.lastUpdate = Timestamp.from(Instant.now());
|
||||||
this.brCache.clear();
|
this.brCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
deleteNode.update(id);
|
Provider.impl.deleteSchematicNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream schemData() throws IOException {
|
public InputStream schemData() throws IOException {
|
||||||
try {
|
return Provider.impl.getSchematicData(this);
|
||||||
return selSchemData.select(rs -> {
|
|
||||||
rs.next();
|
|
||||||
Blob schemData = rs.getBlob("NodeData");
|
|
||||||
if(schemData == null) {
|
|
||||||
throw new SecurityException("SchemData is null");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return new GZIPInputStream(schemData.getBinaryStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new SecurityException("SchemData is wrong", e);
|
|
||||||
}
|
|
||||||
}, id);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Clipboard load() throws IOException, NoClipboardException {
|
public Clipboard load() throws IOException, NoClipboardException {
|
||||||
@ -560,7 +416,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDatabase(InputStream blob, boolean newFormat) {
|
private void updateDatabase(InputStream blob, boolean newFormat) {
|
||||||
updateDatabase.update(blob, newFormat, id);
|
Provider.impl.saveSchematicNode(this, blob, newFormat);
|
||||||
schemFormat = newFormat;
|
schemFormat = newFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
390
SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java
Normale Datei
390
SpigotCore_Main/src/de/steamwar/sql/StandaloneProvider.java
Normale Datei
@ -0,0 +1,390 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 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.sql;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import de.steamwar.core.WorldEditWrapper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
public class StandaloneProvider implements Provider {
|
||||||
|
public StandaloneProvider() {
|
||||||
|
nodesToPath.put(-1, schematicDir.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BauweltMember getBauMember(int ownerID, int memberID) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(SteamwarUser.get(memberID).getUUID());
|
||||||
|
return new BauweltMember(ownerID, memberID, player.isOp(), player.isOp());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BauweltMember> getMembers(int bauweltID) {
|
||||||
|
return Bukkit.getOnlinePlayers().stream().map(player -> getBauMember(bauweltID, SteamwarUser.get(player.getUniqueId()).getId())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CheckedSchematic> getLastDeclinedOfNode(int node) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CheckedSchematic> getLastDelined(int schemOwner) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getElo(int userId, String gameMode) {
|
||||||
|
return 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setElo(int userId, String gameMode, int elo) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Event getEvent(int eventID) {
|
||||||
|
return new Event(eventID, "DummyEvent", Timestamp.from(Instant.now()), Timestamp.from(Instant.now()), 6, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EventFight getEventFight(int fightID) {
|
||||||
|
return new EventFight(0, fightID, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEventFightResult(EventFight fight, int winner) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEventFightFightID(EventFight fight, int fightID) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition, Timestamp replayLock) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getReplay(int fightID, Consumer<InputStream> reader) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReplay(int fightID, InputStream data) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createFightPlayer(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createDownloadLink(int nodeId, String hash) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMember getNodeMember(int node, int member) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<NodeMember> getNodeMembers(int node) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<NodeMember> getMemberSchematics(int member) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createNodeMember(int node, int member) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PersonalKit> getKits(int userID, String gamemode) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PersonalKit getKit(int userID, String gamemode, String name) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateKit(PersonalKit kit) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteKit(PersonalKit kit) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PersonalKit getKitInUse(int userID, String gamemode) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Punishment getPunishmentOfPlayer(int user, Punishment.PunishmentType type) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Punishment.PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int userId = 1;
|
||||||
|
private final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||||
|
@Override
|
||||||
|
public SteamwarUser getUserByName(String userName) {
|
||||||
|
Player player = Bukkit.getPlayer(userName);
|
||||||
|
if(player == null)
|
||||||
|
return null;
|
||||||
|
return usersByUUID.computeIfAbsent(player.getUniqueId(), uuid -> new SteamwarUser(userId++, uuid, userName, UserGroup.Member, 0, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SteamwarUser getUserByUUID(UUID uuid) {
|
||||||
|
return usersByUUID.computeIfAbsent(uuid, uuid1 -> new SteamwarUser(userId++, uuid1, Objects.requireNonNull(Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid1)).getName()), UserGroup.Member, 0, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SteamwarUser getUserByID(int id) {
|
||||||
|
return usersByUUID.values().stream().filter(user -> user.getId() == id).findAny().get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logException(String server, String message, String stacktrace) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Team getTeam(int id) {
|
||||||
|
return new Team(0, "TEST", "TestAlliancePleaseIgnore", "c");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> getTeamMembers(Team team) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<Integer, Map<String, String>> configs = new HashMap<>();
|
||||||
|
@Override
|
||||||
|
public String getConfig(int player, String config) {
|
||||||
|
return configs.computeIfAbsent(player, player1 -> new HashMap<>()).get(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePlayerConfig(int id, String config, String value) {
|
||||||
|
configs.computeIfAbsent(id, player -> new HashMap<>()).put(config, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removePlayerConfig(int id, String config) {
|
||||||
|
configs.computeIfAbsent(id, player -> new HashMap<>()).remove(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int nodeId = 1;
|
||||||
|
private final File schematicDir = WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getWorkingDirectoryFile(WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getConfiguration().saveDir);
|
||||||
|
private final Map<Integer, SchematicNode> nodeById = new HashMap<>();
|
||||||
|
private final Map<Integer, List<SchematicNode>> nodesByParent = new HashMap<>();
|
||||||
|
private final Map<Integer, Path> nodesToPath = new HashMap<>();
|
||||||
|
|
||||||
|
private List<SchematicNode> mapDir(Integer id) {
|
||||||
|
try (Stream<Path> stream = Files.list(id==null?schematicDir.toPath():nodesToPath.get(id))) {
|
||||||
|
List<SchematicNode> list = stream.map(path -> {
|
||||||
|
File file = path.toFile();
|
||||||
|
SchematicNode node = new SchematicNode(
|
||||||
|
nodeId++,
|
||||||
|
0,
|
||||||
|
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
||||||
|
null,
|
||||||
|
"",
|
||||||
|
"normal",
|
||||||
|
file.isDirectory(),
|
||||||
|
0,
|
||||||
|
Timestamp.from(Instant.now()),
|
||||||
|
file.getName().endsWith(".schem")
|
||||||
|
);
|
||||||
|
nodesToPath.put(node.getId(), path);
|
||||||
|
nodeById.put(node.getId(), node);
|
||||||
|
return node;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
nodesByParent.putIfAbsent(id == null?-1:id, list);
|
||||||
|
return list;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||||
|
boolean isDir = type == null;
|
||||||
|
Path p = null;
|
||||||
|
try {
|
||||||
|
if(isDir) {
|
||||||
|
p = Files.createDirectory(new File(nodesToPath.get(parent == null?-1:parent).toFile(), name).toPath());
|
||||||
|
} else {
|
||||||
|
p = Files.createFile(new File(nodesToPath.get(parent == null?-1:parent).toFile(), name + ".schem").toPath());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = p.toFile();
|
||||||
|
int id = nodeId++;
|
||||||
|
nodesToPath.put(id, p);
|
||||||
|
SchematicNode node = new SchematicNode(
|
||||||
|
nodeId++,
|
||||||
|
0,
|
||||||
|
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
|
||||||
|
null,
|
||||||
|
"",
|
||||||
|
"normal",
|
||||||
|
file.isDirectory(),
|
||||||
|
0,
|
||||||
|
Timestamp.from(Instant.now()),
|
||||||
|
file.getName().endsWith(".schem")
|
||||||
|
);
|
||||||
|
nodeById.put(id, node);
|
||||||
|
nodesByParent.get(parent == null?-1:parent).add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||||
|
return nodesByParent.get(parent).stream().filter(node -> node.getName().equals(name)).findAny().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
|
return nodesByParent.computeIfAbsent(parent==null?-1:parent, integer -> mapDir(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
|
return getSchematicNodeInNode(parent).stream().filter(SchematicNode::isDir).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||||
|
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getName().equals(name)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(String name, Integer parent) {
|
||||||
|
return getSchematicNodeInNode(parent).stream().filter(node -> name.equals(node.getName())).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int id) {
|
||||||
|
return nodeById.getOrDefault(id, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int ignored, String schemType, Integer parent) {
|
||||||
|
return getSchematicDirectoryInNode(parent).stream().filter(node -> node.getType().equals(schemType)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllAccessibleSchematicsOfType(int ignored, String schemType) {
|
||||||
|
return getAllSchematicsAccessibleByUser(ignored).stream().filter(node -> schemType.equals(node.getType())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(int ignored, String schemType) {
|
||||||
|
return getAllAccessibleSchematicsOfType(ignored, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
|
return getAllAccessibleSchematicsOfType(-1, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicsAccessibleByUser(int ignored, Integer parent) {
|
||||||
|
return getSchematicNodeInNode(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
|
return nodesByParent.values().stream().reduce((schematicNodes, schematicNodes2) -> {
|
||||||
|
schematicNodes.addAll(schematicNodes2);
|
||||||
|
return schematicNodes;
|
||||||
|
}).orElse(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
|
List<SchematicNode> allSchematicsAccessibleByUser = getAllSchematicsAccessibleByUser(node);
|
||||||
|
allSchematicsAccessibleByUser.remove(getSchematicNode(node));
|
||||||
|
return allSchematicsAccessibleByUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer countNodes() {
|
||||||
|
return nodesByParent.values().stream().map(List::size).reduce((Integer::sum)).orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSchematicNode(SchematicNode node) {
|
||||||
|
try {
|
||||||
|
Path newPath = new File(nodesToPath.get(node.getParent() == null?-1:node.getParent()).toFile(), node.getName() + (node.getSchemFormat()?".schem":".schematic")).toPath();
|
||||||
|
Files.move(nodesToPath.get(node.getId()), newPath);
|
||||||
|
nodesToPath.put(node.getId(), newPath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteSchematicNode(SchematicNode node) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(nodesToPath.get(node.getId()));
|
||||||
|
nodeById.remove(node.getId());
|
||||||
|
nodesByParent.get(node.getParent() == null?-1:node.getId()).remove(node);
|
||||||
|
nodesToPath.remove(node.getId());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getSchematicData(SchematicNode node) throws IOException {
|
||||||
|
return new GZIPInputStream(Files.newInputStream(nodesToPath.get(node.getId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) {
|
||||||
|
try (FileOutputStream stream = new FileOutputStream(nodesToPath.get(node.getId()).toFile())) {
|
||||||
|
byte[] bucket = new byte[1024];
|
||||||
|
int nReadBytes;
|
||||||
|
|
||||||
|
while((nReadBytes = blob.read(bucket, 0, bucket.length)) !=-1){
|
||||||
|
stream.write(bucket, 0, nReadBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(newFormat != node.getSchemFormat()) {
|
||||||
|
nodesToPath.get(node.getId()).toFile().renameTo(new File(nodesToPath.get(node.getId()).toFile().getParentFile(), node.getName() + "." + (newFormat?".schem":"schematic")));
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -40,7 +40,7 @@ public class Statement {
|
|||||||
private static final List<Statement> statements = new ArrayList<>();
|
private static final List<Statement> statements = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
File file = Core.sqlConfig();
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
|
||||||
if(!file.exists())
|
if(!file.exists())
|
||||||
@ -63,12 +63,14 @@ public class Statement {
|
|||||||
|
|
||||||
public static void close() {
|
public static void close() {
|
||||||
for (Statement statement : statements) {
|
for (Statement statement : statements) {
|
||||||
|
if (statement.st != null) {
|
||||||
try {
|
try {
|
||||||
statement.st.close();
|
statement.st.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Core.getInstance().getLogger().log(Level.INFO, "Could not close statement", e);
|
Core.getInstance().getLogger().log(Level.INFO, "Could not close statement", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
con.close();
|
con.close();
|
||||||
@ -80,14 +82,6 @@ public class Statement {
|
|||||||
private static void reset() {
|
private static void reset() {
|
||||||
close();
|
close();
|
||||||
connect();
|
connect();
|
||||||
|
|
||||||
try {
|
|
||||||
for (Statement statement : statements) {
|
|
||||||
statement.init();
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
throw new SecurityException("Could not reprepare SQL Statements", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean connectionStable() {
|
public static boolean connectionStable() {
|
||||||
@ -101,31 +95,22 @@ public class Statement {
|
|||||||
private final String sql;
|
private final String sql;
|
||||||
private PreparedStatement st;
|
private PreparedStatement st;
|
||||||
|
|
||||||
Statement(String sql) {
|
public Statement(String sql) {
|
||||||
this.sql = sql;
|
this.sql = sql;
|
||||||
try {
|
|
||||||
init();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not init statement", e);
|
|
||||||
}
|
|
||||||
statements.add(this);
|
statements.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void init() throws SQLException {
|
public <T> T select(ResultSetUser<T> user, Object... objects) {
|
||||||
st = con.prepareStatement(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
<T> T select(ResultSetUser<T> user, Object... objects) {
|
|
||||||
return prepare(() -> {
|
return prepare(() -> {
|
||||||
ResultSet rs = st.executeQuery();
|
ResultSet rs = getSt().executeQuery();
|
||||||
T result = user.use(rs);
|
T result = user.use(rs);
|
||||||
rs.close();
|
rs.close();
|
||||||
return result;
|
return result;
|
||||||
}, objects);
|
}, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(Object... objects) {
|
public void update(Object... objects) {
|
||||||
prepare(st::executeUpdate, objects);
|
prepare(getSt()::executeUpdate, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
private synchronized <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
||||||
@ -143,13 +128,24 @@ public class Statement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PreparedStatement getSt() {
|
||||||
|
if(st == null) {
|
||||||
|
try {
|
||||||
|
st = con.prepareStatement(sql);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new SecurityException("Could not prepare statement", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
private void setObjects(Object... objects) throws SQLException {
|
private void setObjects(Object... objects) throws SQLException {
|
||||||
for (int i = 0; i < objects.length; i++) {
|
for (int i = 0; i < objects.length; i++) {
|
||||||
st.setObject(i + 1, objects[i]);
|
getSt().setObject(i + 1, objects[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ResultSetUser<T> {
|
public interface ResultSetUser<T> {
|
||||||
T use(ResultSet rs) throws SQLException;
|
T use(ResultSet rs) throws SQLException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,17 +23,12 @@ import de.steamwar.core.Core;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SteamwarUser {
|
public class SteamwarUser {
|
||||||
|
|
||||||
private static final Statement getId = new Statement("SELECT * FROM UserData WHERE id = ?");
|
|
||||||
private static final Statement getUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?");
|
|
||||||
private static final Statement getName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
|
|
||||||
|
|
||||||
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
|
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
|
||||||
private static final Map<String, SteamwarUser> byName = new HashMap<>();
|
private static final Map<String, SteamwarUser> byName = new HashMap<>();
|
||||||
@ -54,21 +49,17 @@ public class SteamwarUser {
|
|||||||
private final int team;
|
private final int team;
|
||||||
private final boolean bedrock;
|
private final boolean bedrock;
|
||||||
|
|
||||||
private SteamwarUser(ResultSet rs){
|
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean bedrock) {
|
||||||
try {
|
this.id = id;
|
||||||
id = rs.getInt("id");
|
this.uuid = uuid;
|
||||||
uuid = java.util.UUID.fromString(rs.getString("UUID"));
|
this.userName = userName;
|
||||||
userName = rs.getString("UserName");
|
this.userGroup = userGroup;
|
||||||
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
|
this.team = team;
|
||||||
team = rs.getInt("Team");
|
this.bedrock = bedrock;
|
||||||
bedrock = rs.getBoolean("Bedrock");
|
|
||||||
|
|
||||||
byUUID.put(uuid, this);
|
byUUID.put(uuid, this);
|
||||||
byName.put(userName.toLowerCase(), this);
|
byName.put(userName.toLowerCase(), this);
|
||||||
byId.put(id, this);
|
byId.put(id, this);
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not instance User", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -98,31 +89,21 @@ public class SteamwarUser {
|
|||||||
public static SteamwarUser get(String userName){
|
public static SteamwarUser get(String userName){
|
||||||
SteamwarUser user = byName.get(userName.toLowerCase());
|
SteamwarUser user = byName.get(userName.toLowerCase());
|
||||||
if(user == null)
|
if(user == null)
|
||||||
user = getName.select(rs -> {
|
user = Provider.impl.getUserByName(userName);
|
||||||
if(rs.next())
|
|
||||||
return new SteamwarUser(rs);
|
|
||||||
return null;
|
|
||||||
}, userName.toLowerCase());
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(UUID uuid){
|
public static SteamwarUser get(UUID uuid){
|
||||||
SteamwarUser user = byUUID.get(uuid);
|
SteamwarUser user = byUUID.get(uuid);
|
||||||
if(user == null)
|
if(user == null)
|
||||||
user = getUUID.select(rs -> {
|
user = Provider.impl.getUserByUUID(uuid);
|
||||||
rs.next();
|
|
||||||
return new SteamwarUser(rs);
|
|
||||||
}, uuid.toString());
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(int id) {
|
public static SteamwarUser get(int id) {
|
||||||
SteamwarUser user = byId.get(id);
|
SteamwarUser user = byId.get(id);
|
||||||
if(user == null)
|
if(user == null)
|
||||||
user = getId.select(rs -> {
|
user = Provider.impl.getUserByID(id);
|
||||||
rs.next();
|
|
||||||
return new SteamwarUser(rs);
|
|
||||||
}, id);
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,16 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Team {
|
public class Team {
|
||||||
|
|
||||||
private static final Statement get = new Statement("SELECT * FROM Team WHERE TeamID = ?");
|
|
||||||
private static final Statement getMembers = new Statement("SELECT id FROM UserData WHERE Team = ?");
|
|
||||||
|
|
||||||
private final int teamId;
|
private final int teamId;
|
||||||
private final String teamKuerzel;
|
private final String teamKuerzel;
|
||||||
private final String teamName;
|
private final String teamName;
|
||||||
@ -36,24 +30,17 @@ public class Team {
|
|||||||
|
|
||||||
private static final Team pub = new Team(0, "PUB", "Öffentlich", "8");
|
private static final Team pub = new Team(0, "PUB", "Öffentlich", "8");
|
||||||
|
|
||||||
private Team(int teamId, String teamKuerzel, String teamName, String teamColor){
|
public Team(int teamId, String teamKuerzel, String teamName, String teamColor) {
|
||||||
this.teamId = teamId;
|
this.teamId = teamId;
|
||||||
this.teamKuerzel = teamKuerzel;
|
this.teamKuerzel = teamKuerzel;
|
||||||
this.teamName = teamName;
|
this.teamName = teamName;
|
||||||
this.teamColor = teamColor;
|
this.teamColor = teamColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Team(ResultSet rs) throws SQLException {
|
|
||||||
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Team get(int id){
|
public static Team get(int id){
|
||||||
if(id == 0)
|
if(id == 0)
|
||||||
return pub;
|
return pub;
|
||||||
return get.select(rs -> {
|
return Provider.impl.getTeam(id);
|
||||||
rs.next();
|
|
||||||
return new Team(rs);
|
|
||||||
}, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTeamId() {
|
public int getTeamId() {
|
||||||
@ -73,11 +60,6 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getMembers(){
|
public List<Integer> getMembers(){
|
||||||
return getMembers.select(rs -> {
|
return Provider.impl.getTeamMembers(this);
|
||||||
List<Integer> members = new ArrayList<>();
|
|
||||||
while(rs.next())
|
|
||||||
members.add(rs.getInt("id"));
|
|
||||||
return members;
|
|
||||||
}, teamId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,54 +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.sql;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TeamTeilnahme {
|
|
||||||
private TeamTeilnahme(){}
|
|
||||||
|
|
||||||
private static final Statement byEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
|
|
||||||
private static final Statement byEvent = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?");
|
|
||||||
private static final Statement byTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?");
|
|
||||||
|
|
||||||
public static boolean nimmtTeil(int teamID, int eventID){
|
|
||||||
return byEventTeam.select(ResultSet::next, teamID, eventID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<Team> getTeams(int eventID){
|
|
||||||
return byEvent.select(rs -> {
|
|
||||||
Set<Team> teams = new HashSet<>();
|
|
||||||
while(rs.next())
|
|
||||||
teams.add(Team.get(rs.getInt("TeamID")));
|
|
||||||
return teams;
|
|
||||||
}, eventID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<Event> getEvents(int teamID){
|
|
||||||
return byTeam.select(rs -> {
|
|
||||||
Set<Event> events = new HashSet<>();
|
|
||||||
while(rs.next())
|
|
||||||
events.add(Event.get(rs.getInt("EventID")));
|
|
||||||
return events;
|
|
||||||
}, teamID);
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,20 +24,12 @@ import java.util.UUID;
|
|||||||
public class UserConfig {
|
public class UserConfig {
|
||||||
private UserConfig() {}
|
private UserConfig() {}
|
||||||
|
|
||||||
private static final Statement get = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
|
|
||||||
private static final Statement set = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
|
|
||||||
private static final Statement delete = new Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
|
|
||||||
|
|
||||||
public static String getConfig(UUID player, String config) {
|
public static String getConfig(UUID player, String config) {
|
||||||
return getConfig(SteamwarUser.get(player).getId(), config);
|
return getConfig(SteamwarUser.get(player).getId(), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConfig(int player, String config) {
|
public static String getConfig(int player, String config) {
|
||||||
return get.select(rs -> {
|
return Provider.impl.getConfig(player, config);
|
||||||
if(rs.next())
|
|
||||||
return rs.getString("Value");
|
|
||||||
return null;
|
|
||||||
}, player, config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePlayerConfig(UUID uuid, String config, String value) {
|
public static void updatePlayerConfig(UUID uuid, String config, String value) {
|
||||||
@ -49,7 +41,7 @@ public class UserConfig {
|
|||||||
removePlayerConfig(id, config);
|
removePlayerConfig(id, config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
set.update(id, config, value);
|
Provider.impl.updatePlayerConfig(id, config, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removePlayerConfig(UUID uuid, String config) {
|
public static void removePlayerConfig(UUID uuid, String config) {
|
||||||
@ -57,6 +49,6 @@ public class UserConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removePlayerConfig(int id, String config) {
|
public static void removePlayerConfig(int id, String config) {
|
||||||
delete.update(id, config);
|
Provider.impl.removePlayerConfig(id, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren