12
0

WIP current state
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Lixfel 2022-09-08 10:42:57 +02:00
Ursprung 7d74179c26
Commit 9a4e85d749
28 geänderte Dateien mit 249 neuen und 1558 gelöschten Zeilen

@ -1 +1 @@
Subproject commit 211f6258b5bd5a50253a21bd82804edb12f34e3e
Subproject commit c1e175c3e84280c160ae5c7f84e44805f159bbf3

Datei anzeigen

@ -1,32 +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.core;
import org.bukkit.entity.Player;
import java.util.Locale;
public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorWrapper {
@Override
public Locale getLocale(Player player){
return Locale.forLanguageTag(player.getLocale().replace('_', '-'));
}
}

Datei anzeigen

@ -44,6 +44,7 @@ sourceSets {
dependencies {
implementation project(":SpigotCore_Main")
implementation project(':CommonCore')
compileOnly project(":SpigotCore_8")
compileOnly project(":SpigotCore_9")

Datei anzeigen

@ -45,6 +45,7 @@ sourceSets {
dependencies {
implementation project(":SpigotCore_Main")
implementation project(":SpigotCore_14")
implementation project(':CommonCore')
compileOnly swdep("WorldEdit-1.15")

Datei anzeigen

@ -44,6 +44,7 @@ sourceSets {
dependencies {
implementation project(":SpigotCore_Main")
implementation project(':CommonCore')
compileOnly swdep("Spigot-1.8")
compileOnly swdep("WorldEdit-1.12")

Datei anzeigen

@ -1,32 +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.core;
import org.bukkit.entity.Player;
import java.util.Locale;
public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWrapper {
@Override
public Locale getLocale(Player player){
return Locale.forLanguageTag(player.spigot().getLocale().replace('_', '-'));
}
}

Datei anzeigen

@ -31,13 +31,13 @@ import de.steamwar.core.events.PlayerJoinedEvent;
import de.steamwar.core.events.WorldLoadEvent;
import de.steamwar.message.Message;
import de.steamwar.network.NetworkReceiver;
import de.steamwar.sql.Statement;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.internal.Statement;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
@ -82,16 +82,6 @@ public class Core extends JavaPlugin{
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 CrashDetector crashDetector;
@ -102,7 +92,6 @@ public class Core extends JavaPlugin{
@Override
public void onEnable() {
setSqlConfig();
errorHandler = new ErrorHandler();
crashDetector = new CrashDetector();
@ -131,6 +120,8 @@ public class Core extends JavaPlugin{
if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null)
new PartialChunkFixer();
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000);
if(Core.getVersion() >= 19)
//new ServerDataHandler();
@ -146,13 +137,6 @@ public class Core extends JavaPlugin{
TinyProtocol.instance.close();
crashDetector.stop();
errorHandler.unregister();
if(!standalone) {
Statement.close();
}
}
private static void setSqlConfig() {
sqlConfig = new File(System.getProperty("user.home"), "MySQL.yml");
standalone = !sqlConfig.exists();
Statement.closeAll();
}
}

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.sql.SWException;
import de.steamwar.sql.Statement;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
@ -74,10 +73,11 @@ public class ErrorHandler extends Handler {
if(stacktrace.contains("POI data mismatch"))
return;
if(!Statement.connectionStable())
return;
SWException.log(message, stacktrace);
try {
SWException.log(message, stacktrace);
} catch (SecurityException e) {
Core.getInstance().getLogger().log(Level.INFO, "Could not log error in database", e);
}
}
@Override

Datei anzeigen

@ -1,34 +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.core;
import org.bukkit.entity.Player;
import java.util.Locale;
public class WorldOfColorWrapper {
private WorldOfColorWrapper() {}
public static final IWorldOfColorWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
public interface IWorldOfColorWrapper {
Locale getLocale(Player player);
}
}

Datei anzeigen

@ -323,7 +323,7 @@ public class SchematicSelector {
} else {
List<SWListInv.SWListEntry<SchematicType>> types = new ArrayList<>();
SchematicType.values().forEach(schematicType -> {
types.add(new SWListInv.SWListEntry<>(new SWItem(schematicType.getMaterial(), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType));
types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial(schematicType.getMaterial()), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType));
});
SWListInv<SchematicType> listInv = new SWListInv<>(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> {
filter.setType(schematicType);
@ -334,9 +334,9 @@ public class SchematicSelector {
};
if(filter.getType() == null) {
inv.setItem(2, SchematicType.Normal.getMaterial(), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), schemTypeCallback);
inv.setItem(2, SWItem.getMaterial(SchematicType.Normal.getMaterial()), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), schemTypeCallback);
} else {
inv.setItem(2, filter.getType().getMaterial(), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE_SEARCH", player, filter.getType().name())), true, schemTypeCallback);
inv.setItem(2, SWItem.getMaterial(filter.getType().getMaterial()), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE_SEARCH", player, filter.getType().name())), true, schemTypeCallback);
}
}

Datei anzeigen

@ -1,80 +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.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class BauweltMember {
private static final List<BauweltMember> memberCache = new ArrayList<>();
public static void clear() {
memberCache.clear();
}
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId());
}
public static BauweltMember getBauMember(int ownerID, int memberID){
for(BauweltMember member : memberCache)
if(member.getMemberID() == memberID)
return member;
return Provider.impl.getBauMember(ownerID, memberID);
}
public static List<BauweltMember> getMembers(UUID bauweltID){
return getMembers(SteamwarUser.get(bauweltID).getId());
}
public static List<BauweltMember> getMembers(int bauweltID){
return Provider.impl.getMembers(bauweltID);
}
private final int bauweltID;
private final int memberID;
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() {
return bauweltID;
}
public int getMemberID() {
return memberID;
}
public boolean isWorldEdit() {
return worldEdit;
}
public boolean isWorld() {
return world;
}
}

Datei anzeigen

@ -19,67 +19,57 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;
@AllArgsConstructor
public class CheckedSchematic {
private static final Table<CheckedSchematic> table = new Table<>(CheckedSchematic.class);
private static final SelectStatement<CheckedSchematic> statusOfNode = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){
return getLastDeclinedOfNode(node.getId());
}
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
return Provider.impl.getLastDeclinedOfNode(node);
return statusOfNode.listSelect(node);
}
public static List<CheckedSchematic> getLastDeclined(UUID uuid){
return getLastDelined(SteamwarUser.get(uuid).getId());
}
public static List<CheckedSchematic> getLastDelined(int schemOwner){
return Provider.impl.getLastDelined(schemOwner);
}
private final Integer node;
@Field(nullable = true)
private final Integer nodeId;
@Field
private final int nodeOwner;
@Field
private final String nodeName;
@Getter
@Field
private final int validator;
@Getter
@Field
private final Timestamp startTime;
@Getter
@Field
private final Timestamp endTime;
@Getter
@Field
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() {
return validator;
}
public Timestamp getStartTime() {
return startTime;
}
public Timestamp getEndTime() {
return endTime;
}
public String getDeclineReason() {
return declineReason;
}
public int getNode() {
return node;
return nodeId;
}
public String getSchemName() {
return SchematicNode.getSchematicNode(node).getName();
return nodeName;
}
public int getSchemOwner() {
return SchematicNode.getSchematicNode(node).getId();
return nodeOwner;
}
}

Datei anzeigen

@ -1,69 +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.Timestamp;
public class Event {
public static Event get(int eventID){
return Provider.impl.getEvent(eventID);
}
private final int eventID;
private final String eventName;
private final Timestamp start;
private final Timestamp end;
private final int maximumTeamMembers;
private final boolean publicSchemsOnly;
private final boolean spectateSystem;
public Event(int eventID, String eventName, Timestamp start, Timestamp end, int maximumTeamMembers, boolean publicSchemsOnly, boolean spectateSystem) {
this.eventID = eventID;
this.eventName = eventName;
this.start = start;
this.end = end;
this.maximumTeamMembers = maximumTeamMembers;
this.publicSchemsOnly = publicSchemsOnly;
this.spectateSystem = spectateSystem;
}
public int getEventID() {
return eventID;
}
public String getEventName() {
return eventName;
}
public Timestamp getStart() {
return start;
}
public Timestamp getEnd() {
return end;
}
public int getMaximumTeamMembers() {
return maximumTeamMembers;
}
public boolean publicSchemsOnly() {
return publicSchemsOnly;
}
public boolean spectateSystem(){
return spectateSystem;
}
}

Datei anzeigen

@ -1,76 +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;
public class EventFight {
public static EventFight get(int fightID) {
return Provider.impl.getEventFight(fightID);
}
private final int eventID;
private final int fightID;
private final int teamBlue;
private final int teamRed;
private final int kampfleiter;
private final int ergebnis;
public EventFight(int eventID, int fightID, int teamBlue, int teamRed, int kampfleiter, int ergebnis) {
this.eventID = eventID;
this.fightID = fightID;
this.teamBlue = teamBlue;
this.teamRed = teamRed;
this.kampfleiter = kampfleiter;
this.ergebnis = ergebnis;
}
public void setErgebnis(int winner) {
Provider.impl.setEventFightResult(this, winner);
}
public void setFight(int fight) {
//Fight.FightID, not EventFight.FightID
Provider.impl.setEventFightFightID(this, fight);
}
public int getTeamBlue() {
return teamBlue;
}
public int getTeamRed() {
return teamRed;
}
public int getEventID() {
return eventID;
}
public int getFightID() {
return fightID;
}
public int getKampfleiter() {
return kampfleiter;
}
public int getErgebnis() {
return ergebnis;
}
}

Datei anzeigen

@ -1,40 +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.io.InputStream;
import java.sql.Timestamp;
import java.util.function.Consumer;
public class Fight {
private Fight(){}
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 Provider.impl.createFight(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition);
}
public static void getReplay(int fightID, Consumer<InputStream> reader) {
Provider.impl.getReplay(fightID, reader);
}
public static void setReplay(int fightID, InputStream data) {
Provider.impl.setReplay(fightID, data);
}
}

Datei anzeigen

@ -1,28 +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;
public class FightPlayer {
private FightPlayer(){}
public static void create(int fightID, int userID, boolean blue, String kit, int kills, boolean isOut){
Provider.impl.createFightPlayer(fightID, userID, blue, kit, kills, isOut);
}
}

Datei anzeigen

@ -1,23 +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;
public class NoClipboardException extends RuntimeException {
}

Datei anzeigen

@ -1,65 +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.util.Set;
import java.util.function.Consumer;
public class NodeMember {
public static NodeMember getNodeMember(int node, int member) {
return Provider.impl.getNodeMember(node, member);
}
public static Set<NodeMember> getNodeMembers(int node) {
return Provider.impl.getNodeMembers(node);
}
public static Set<NodeMember> getSchematics(int member) {
return Provider.impl.getMemberSchematics(member);
}
public static NodeMember createNodeMember(int node, int member) {
Provider.impl.createNodeMember(node, member);
return getNodeMember(node, member);
}
private final int node;
private final int member;
private final Consumer<NodeMember> delete;
public NodeMember(int node, int member, Consumer<NodeMember> delete) {
this.node = node;
this.member = member;
this.delete = delete;
}
public int getNode() {
return node;
}
public int getMember() {
return member;
}
public void delete() {
delete.accept(this);
}
}

Datei anzeigen

@ -19,6 +19,12 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
@ -26,43 +32,39 @@ import java.io.StringReader;
import java.util.List;
import java.util.Objects;
@AllArgsConstructor
public class PersonalKit {
public static List<PersonalKit> get(int userID, String gamemode){
return Provider.impl.getKits(userID, gamemode);
}
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 static final Table<PersonalKit> table = new Table<>(PersonalKit.class);
private static final SelectStatement<PersonalKit> getKits = table.selectFields("UserID", "GameMode");
private static final SelectStatement<PersonalKit> getKit = table.select(Table.PRIMARY);
private static final SelectStatement<PersonalKit> getKitInUse = table.selectFields("UserID", "GameMode", "InUse");
private static final Statement update = table.insertAll();
private static final Statement delete = table.delete(Table.PRIMARY);
@Getter
@Field(keys = {Table.PRIMARY})
private final int userID;
private String name;
@Getter
@Field(keys = {Table.PRIMARY})
private final String gamemode;
@Getter
@Field(keys = {Table.PRIMARY})
private final String name;
@Field
private String inventory;
@Field
private String armor;
@Getter
@Field(def = "1")
private boolean inUse;
public PersonalKit(int userID, String name, String gamemode, String inventory, String armor, boolean inUse) {
this.userID = userID;
this.name = name;
this.gamemode = gamemode;
this.inventory = inventory;
this.armor = armor;
this.inUse = inUse;
public String getRawInventory() {
return inventory;
}
public String getRawArmor() {
return armor;
}
public ItemStack[] getInventory(){
@ -75,30 +77,6 @@ public class PersonalKit {
return Objects.requireNonNull(config.getList("Armor")).toArray(new ItemStack[0]);
}
public int getUserID() {
return userID;
}
public String getName() {
return name;
}
public String getGamemode() {
return gamemode;
}
public String getRawInventory() {
return inventory;
}
public String getRawArmor() {
return armor;
}
public boolean isInUse() {
return inUse;
}
public void setInUse() {
PersonalKit kit = getKitInUse(userID, gamemode);
if(kit != null)
@ -108,32 +86,52 @@ public class PersonalKit {
private void setUse(boolean inUse) {
this.inUse = inUse;
Provider.impl.updateKit(this);
}
public void setName(String name) {
this.name = name;
Provider.impl.updateKit(this);
update();
}
public void setInventory(ItemStack[] inventory) {
this.inventory = saveInvConfig("Inventory", inventory);
Provider.impl.updateKit(this);
update();
}
public void setArmor(ItemStack[] armor) {
this.armor = saveInvConfig("Armor", armor);
Provider.impl.updateKit(this);
update();
}
public void setContainer(ItemStack[] inventory, ItemStack[] armor) {
this.armor = saveInvConfig("Armor", armor);
this.inventory = saveInvConfig("Inventory", inventory);
Provider.impl.updateKit(this);
update();
}
public void delete() {
Provider.impl.deleteKit(this);
delete.update(userID, gamemode, name);
}
private void update() {
update.update(userID, gamemode, name, inventory, armor, inUse);
}
public static List<PersonalKit> get(int userID, String gamemode){
return getKits.listSelect(userID, gamemode);
}
public static PersonalKit get(int userID, String gamemode, String name) {
return getKit.select(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, gamemode, name, saveInvConfig("Inventory", inventory), saveInvConfig("Armor", armor), true);
kit.update();
return kit;
}
public static PersonalKit getKitInUse(int userID, String gamemode) {
return getKitInUse.select(userID, gamemode);
}
private static String saveInvConfig(String name, ItemStack[] inv) {

Datei anzeigen

@ -19,62 +19,24 @@
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);
Event getEvent(int eventID);
EventFight getEventFight(int fightID);
void setEventFightResult(EventFight fight, int winner);
void setEventFightFightID(EventFight fight, int fightID);
Provider impl = new SQLProvider();
boolean hasEventTeam(int teamID, int eventID);
Set<Team> getEventTeams(int eventID);
Set<Event> getTeamEvents(int teamID);
int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition);
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);
List<SteamwarUser> getServerTeam();
void logException(String server, String message, String stacktrace);
Team getTeam(int id);

Datei anzeigen

@ -0,0 +1,37 @@
/*
* 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 de.steamwar.sql.internal.SQLConfig;
import java.util.logging.Logger;
public class SQLConfigImpl implements SQLConfig {
@Override
public Logger getLogger() {
return Core.getInstance().getLogger();
}
@Override
public int maxConnections() {
return 1;
}
}

Datei anzeigen

@ -19,103 +19,26 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.Statement;
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.stream.Collectors;
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 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(fightID, fight.getFightID());
}
private static final Statement hasEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
private static final de.steamwar.sql.internal.Statement hasEventTeam = new de.steamwar.sql.internal.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
@Override
public boolean hasEventTeam(int teamID, int eventID) {
return hasEventTeam.select(ResultSet::next, teamID, eventID);
}
private static final Statement eventTeams = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?");
private static final de.steamwar.sql.internal.Statement eventTeams = new de.steamwar.sql.internal.Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?");
@Override
public Set<Team> getEventTeams(int eventID) {
return eventTeams.select(rs -> {
@ -126,7 +49,7 @@ public class SQLProvider implements Provider {
}, eventID);
}
private static final Statement eventsTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?");
private static final de.steamwar.sql.internal.Statement eventsTeam = new de.steamwar.sql.internal.Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?");
@Override
public Set<Event> getTeamEvents(int teamID) {
return eventsTeam.select(rs -> {
@ -137,136 +60,13 @@ public class SQLProvider implements Provider {
}, teamID);
}
private static final Statement createFight = new Statement("INSERT INTO Fight (GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) 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) {
createFight.update(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition);
return getLastFightID.select(rs -> {
rs.next();
return rs.getInt("FightID");
});
}
private static final Statement getReplay = new Statement("SELECT Replay FROM Replay 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("INSERT INTO Replay (FightID, Replay) VALUES (?, ?)");
@Override
public void setReplay(int fightID, InputStream data) {
setReplay.update(fightID, data);
}
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)");
private static final de.steamwar.sql.internal.Statement createLink = new de.steamwar.sql.internal.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");
private static final de.steamwar.sql.internal.Statement getPunishment = new de.steamwar.sql.internal.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 -> {
@ -280,7 +80,7 @@ public class SQLProvider implements Provider {
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)");
private static final de.steamwar.sql.internal.Statement getPunishments = new de.steamwar.sql.internal.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 -> {
@ -291,57 +91,13 @@ public class SQLProvider implements Provider {
}, 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 static final Statement getServerTeam = new Statement("SELECT * FROM UserData WHERE UserGroup != 'Member' AND UserGroup != 'YouTuber'");
@Override
public List<SteamwarUser> getServerTeam() {
return getServerTeam.select(rs -> {
List<SteamwarUser> users = new ArrayList<>();
while(rs.next())
users.add(newSteamwarUser(rs));
return users;
});
}
private SteamwarUser newSteamwarUser(ResultSet rs) throws SQLException {
String dbLocale = rs.getString("Locale");
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"), dbLocale != null ? Locale.forLanguageTag(dbLocale) : null);
}
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
private static final de.steamwar.sql.internal.Statement insert = new de.steamwar.sql.internal.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 = ?");
private static final de.steamwar.sql.internal.Statement getTeam = new de.steamwar.sql.internal.Statement("SELECT * FROM Team WHERE TeamID = ?");
@Override
public Team getTeam(int id) {
return getTeam.select(rs -> {
@ -350,7 +106,7 @@ public class SQLProvider implements Provider {
}, id);
}
private static final Statement getTeamMembers = new Statement("SELECT id FROM UserData WHERE Team = ?");
private static final de.steamwar.sql.internal.Statement getTeamMembers = new de.steamwar.sql.internal.Statement("SELECT id FROM UserData WHERE Team = ?");
@Override
public List<Integer> getTeamMembers(Team team) {
return getTeamMembers.select(rs -> {
@ -361,7 +117,7 @@ public class SQLProvider implements Provider {
}, team.getTeamId());
}
private static final Statement getConfig = new Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
private static final de.steamwar.sql.internal.Statement getConfig = new de.steamwar.sql.internal.Statement("SELECT Value FROM UserConfig WHERE User = ? AND Config = ?");
@Override
public String getConfig(int player, String config) {
return getConfig.select(rs -> {
@ -371,13 +127,13 @@ public class SQLProvider implements Provider {
}, player, config);
}
private static final Statement setConfig = new Statement("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)");
private static final de.steamwar.sql.internal.Statement setConfig = new de.steamwar.sql.internal.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 = ?");
private static final de.steamwar.sql.internal.Statement deleteConfig = new de.steamwar.sql.internal.Statement("DELETE FROM UserConfig WHERE User = ? AND Config = ?");
@Override
public void removePlayerConfig(int id, String config) {
deleteConfig.update(id, config);
@ -387,42 +143,42 @@ public class SQLProvider implements Provider {
private static String nodeSelectCreator(String itemPrefix) {
return "SELECT " + Arrays.stream(nodeSelect).map(s -> itemPrefix + s).collect(Collectors.joining(", ")) + " FROM 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(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
private static final Statement getSchematicNode = new Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
private static final Statement getSchematicsInNode_Null = new Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL ORDER BY NodeName");
private static final Statement getSchematicsInNode = new Statement(nodeSelectCreator("") + "WHERE ParentNode = ? ORDER BY NodeName");
private static final Statement getDirsInNode_Null = new Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
private static final Statement getDirsInNode = new Statement(nodeSelectCreator("") + "WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
private static final Statement getSchematicDirectory_Null = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
private static final Statement getSchematicDirectory = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
private static final Statement getSchematicNodeO_Null = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ");
private static final Statement getSchematicNodeO = new Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
private static final Statement getSchematicNodeId = new Statement(nodeSelectCreator("") + "WHERE NodeId = ?");
private static final Statement getAllSchemsOfTypeOwner = new Statement( nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
private static final Statement getAllSchemsOfType = new Statement(nodeSelectCreator("") + "WHERE NodeType = ? ORDER BY NodeName");
private static final Statement getAccessibleByUser = new Statement(nodeSelectCreator("s.") + "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 (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "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 (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "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 (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "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 (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "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 (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "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 (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "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 = ?, ReplaceColor = ?, AllowReplay = ? 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 schemElo = new Statement("SELECT Elo FROM SchemElo WHERE SchemId = ? AND Season = ?");
private static final de.steamwar.sql.internal.Statement createNode = new de.steamwar.sql.internal.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 de.steamwar.sql.internal.Statement getSchematicNode_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
private static final de.steamwar.sql.internal.Statement getSchematicNode = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
private static final de.steamwar.sql.internal.Statement getSchematicsInNode_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getSchematicsInNode = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getDirsInNode_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getDirsInNode = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getSchematicDirectory_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getSchematicDirectory = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getSchematicNodeO_Null = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode is NULL ");
private static final de.steamwar.sql.internal.Statement getSchematicNodeO = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getSchematicNodeId = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeId = ?");
private static final de.steamwar.sql.internal.Statement getAllSchemsOfTypeOwner = new de.steamwar.sql.internal.Statement( nodeSelectCreator("") + "WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getAllSchemsOfType = new de.steamwar.sql.internal.Statement(nodeSelectCreator("") + "WHERE NodeType = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getAccessibleByUser = new de.steamwar.sql.internal.Statement(nodeSelectCreator("s.") + "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 de.steamwar.sql.internal.Statement getAccessibleByUserByTypeInNode = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getAccessibleByUserByTypeInNode_Null = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? UNION " + nodeSelectCreator("SN.") + "AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getAccessibleByUserByType = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement getAllSchematicsAccessibleByUser = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN as (" + nodeSelectCreator("s.") + "s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId UNION " + nodeSelectCreator("SN.") + "AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement isSchematicAccessibleForUser = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "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 de.steamwar.sql.internal.Statement getAllParentsOfNode = new de.steamwar.sql.internal.Statement("WITH RECURSIVE RSN AS (" + nodeSelectCreator("") + "WHERE NodeId = ? UNION " + nodeSelectCreator("SN.") + "SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
private static final de.steamwar.sql.internal.Statement countNodes = new de.steamwar.sql.internal.Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
private static final de.steamwar.sql.internal.Statement updateDB = new de.steamwar.sql.internal.Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ?, ReplaceColor = ?, AllowReplay = ? WHERE NodeId = ?");
private static final de.steamwar.sql.internal.Statement updateDatabase = new de.steamwar.sql.internal.Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
private static final de.steamwar.sql.internal.Statement selSchemData = new de.steamwar.sql.internal.Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
private static final de.steamwar.sql.internal.Statement deleteNode = new de.steamwar.sql.internal.Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
private static final de.steamwar.sql.internal.Statement schemElo = new de.steamwar.sql.internal.Statement("SELECT Elo FROM SchemElo WHERE SchemId = ? AND Season = ?");
private static final Statement.ResultSetUser<List<SchematicNode>> toSchematicList = rs -> {
private static final de.steamwar.sql.internal.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 -> {
private static final de.steamwar.sql.internal.Statement.ResultSetUser<SchematicNode> toSchematicNode = rs -> {
if (rs.next()) {
return nodeFromResultSet(rs);
}

Datei anzeigen

@ -0,0 +1,63 @@
/*
* 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 org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class SQLWrapperImpl implements SQLWrapper {
@Override
public void loadSchemTypes(List<SchematicType> tmpTypes, Map<String, SchematicType> tmpFromDB) {
File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
if(folder.exists()) {
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
if(!config.isConfigurationSection("Schematic"))
continue;
String type = config.getString("Schematic.Type");
assert type != null;
String shortcut = config.getString("Schematic.Shortcut");
if(tmpFromDB.containsKey(type.toLowerCase()))
continue;
SchematicType checktype = null;
String material = config.getString("Schematic.Material", "STONE_BUTTON");
if(!config.getStringList("CheckQuestions").isEmpty()) {
checktype = new SchematicType("C" + type, "C" + shortcut, SchematicType.Type.CHECK_TYPE, null, material);
tmpTypes.add(checktype);
tmpFromDB.put(checktype.toDB(), checktype);
}
SchematicType current = new SchematicType(type, shortcut, config.isConfigurationSection("Server") ? SchematicType.Type.FIGHT_TYPE : SchematicType.Type.NORMAL, checktype, material);
tmpTypes.add(current);
tmpFromDB.put(type.toLowerCase(), current);
}
}
}
}

Datei anzeigen

@ -1,140 +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 de.steamwar.core.Core;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
public class SchematicType {
public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null, SWItem.getMaterial("STONE_BUTTON")); //Has to stay publicly availible
private static final Map<String, SchematicType> fromDB;
private static final List<SchematicType> types;
static {
File folder = new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
List<SchematicType> tmpTypes = new LinkedList<>();
Map<String, SchematicType> tmpFromDB = new HashMap<>();
tmpTypes.add(Normal);
tmpFromDB.put(Normal.name().toLowerCase(), Normal);
if(folder.exists()) {
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
if(!config.isConfigurationSection("Schematic"))
continue;
String type = config.getString("Schematic.Type");
assert type != null;
String shortcut = config.getString("Schematic.Shortcut");
if(tmpFromDB.containsKey(type.toLowerCase()))
continue;
SchematicType checktype = null;
Material material = SWItem.getMaterial(config.getString("Schematic.Material", "STONE_BUTTON"));
if(!config.getStringList("CheckQuestions").isEmpty()) {
checktype = new SchematicType("C" + type, "C" + shortcut, Type.CHECK_TYPE, null, material);
tmpTypes.add(checktype);
tmpFromDB.put(checktype.toDB(), checktype);
}
SchematicType current = new SchematicType(type, shortcut, config.isConfigurationSection("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype, material);
tmpTypes.add(current);
tmpFromDB.put(type.toLowerCase(), current);
}
}
fromDB = Collections.unmodifiableMap(tmpFromDB);
types = Collections.unmodifiableList(tmpTypes);
}
private final String name;
private final String kuerzel;
private final Type type;
private final SchematicType checkType;
private final Material material;
private SchematicType(String name, String kuerzel, Type type, SchematicType checkType, Material material){
this.name = name;
this.kuerzel = kuerzel;
this.type = type;
this.checkType = checkType;
this.material = material;
}
public boolean isAssignable(){
return type == Type.NORMAL || (type == Type.FIGHT_TYPE && checkType != null);
}
public SchematicType checkType(){
return checkType;
}
public boolean check(){
return type == Type.CHECK_TYPE;
}
public boolean fightType(){
return type == Type.FIGHT_TYPE;
}
public boolean writeable(){
return type == Type.NORMAL;
}
public String name(){
return name;
}
public String getKuerzel() {
return kuerzel;
}
public Material getMaterial() {
return material;
}
public String toDB(){
return name.toLowerCase();
}
public static SchematicType fromDB(String input){
return fromDB.getOrDefault(input.toLowerCase(), null);
}
public static List<SchematicType> values(){
return types;
}
enum Type{
NORMAL,
CHECK_TYPE,
FIGHT_TYPE
}
}

Datei anzeigen

@ -20,10 +20,6 @@
package de.steamwar.sql;
import de.steamwar.core.WorldEditWrapper;
import de.steamwar.core.WorldOfColorWrapper;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.FileOutputStream;
@ -34,7 +30,6 @@ 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;
@ -44,43 +39,6 @@ public class StandaloneProvider implements Provider {
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 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 boolean hasEventTeam(int teamID, int eventID) {
return false;
@ -96,62 +54,9 @@ public class StandaloneProvider implements Provider {
return Collections.emptySet();
}
@Override
public int createFight(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition) {
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;
@ -162,31 +67,6 @@ public class StandaloneProvider implements Provider {
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, null));
}
@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, null));
}
@Override
public SteamwarUser getUserByID(int id) {
return usersByUUID.values().stream().filter(user -> user.getId() == id).findAny().get();
}
@Override
public List<SteamwarUser> getServerTeam() {
return Bukkit.getOperators().stream().map(OfflinePlayer::getUniqueId).map(this::getUserByUUID).collect(Collectors.toList());
}
@Override
public void logException(String server, String message, String stacktrace) {}

Datei anzeigen

@ -1,156 +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 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;
import de.steamwar.core.Core;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public class Statement {
private static final String URL;
private static final String USER;
private static final String PASSWORD;
private static Connection con;
private static final List<Statement> statements = new ArrayList<>();
static {
File file = Core.sqlConfig();
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
if(!file.exists())
throw new SecurityException("SQL-ConfigFile not found!");
URL = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
USER = config.getString("USER");
PASSWORD = config.getString("PASSWORD");
Statement.connect();
}
private static void connect() {
try {
con = DriverManager.getConnection(URL + "?useServerPrepStmts=true", USER, PASSWORD);
} catch (SQLException e) {
throw new SecurityException("Could not start SQL connection", e);
}
}
public static void close() {
for (Statement statement : statements) {
if (statement.st != null) {
try {
statement.st.close();
} catch (SQLException e) {
Core.getInstance().getLogger().log(Level.INFO, "Could not close statement", e);
}
statement.st = null;
}
}
try {
con.close();
} catch (SQLException e) {
Core.getInstance().getLogger().log(Level.INFO, "Could not close SQL connection", e);
}
}
private static void reset() {
close();
connect();
}
public static boolean connectionStable() {
try {
return !con.isClosed();
} catch (SQLException e) {
return false;
}
}
private final String sql;
private PreparedStatement st;
public Statement(String sql) {
this.sql = sql;
statements.add(this);
}
public <T> T select(ResultSetUser<T> user, Object... objects) {
return prepare(() -> {
ResultSet rs = getSt().executeQuery();
T result = user.use(rs);
rs.close();
return result;
}, objects);
}
public void update(Object... objects) {
prepare(getSt()::executeUpdate, objects);
}
private synchronized <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
try {
try {
setObjects(objects);
return runnable.run();
} catch (CommunicationsException e) {
reset();
setObjects(objects);
return runnable.run();
}
} catch (SQLException e) {
throw new SecurityException("Could not execute SQL statement", e);
}
}
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 {
for (int i = 0; i < objects.length; i++) {
getSt().setObject(i + 1, objects[i]);
}
}
public interface ResultSetUser<T> {
T use(ResultSet rs) throws SQLException;
}
private interface SQLRunnable<T> {
T run() throws SQLException;
}
}

Datei anzeigen

@ -1,135 +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 de.steamwar.core.Core;
import de.steamwar.core.WorldOfColorWrapper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.*;
public class SteamwarUser {
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
private static final Map<String, SteamwarUser> byName = new HashMap<>();
private static final Map<Integer, SteamwarUser> byId = new HashMap<>();
static{
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
byId.clear();
byName.clear();
byUUID.clear();
}, 72000, 72000);
}
public static void invalidate(int userId) {
SteamwarUser user = byId.remove(userId);
if (user == null)
return;
byName.remove(user.getUserName());
byUUID.remove(user.getUUID());
}
private final int id;
private final UUID uuid;
private final String userName;
private final UserGroup userGroup;
private final int team;
private final boolean bedrock;
private Locale locale;
public SteamwarUser(int id, UUID uuid, String userName, UserGroup userGroup, int team, boolean bedrock, Locale locale) {
this.id = id;
this.uuid = uuid;
this.userName = userName;
this.userGroup = userGroup;
this.team = team;
this.bedrock = bedrock;
this.locale = locale;
byUUID.put(uuid, this);
byName.put(userName.toLowerCase(), this);
byId.put(id, this);
}
public int getId() {
return id;
}
public UUID getUUID() {
return uuid;
}
public String getUserName() {
return userName;
}
public UserGroup getUserGroup() {
return userGroup;
}
public int getTeam(){
return team;
}
public boolean isBedrock(){
return bedrock;
}
public Locale getLocale() {
if(locale != null)
return locale;
Locale locale = WorldOfColorWrapper.impl.getLocale(Bukkit.getPlayer(uuid));
if (locale != null)
return locale;
return Locale.getDefault();
}
public static SteamwarUser get(String userName){
SteamwarUser user = byName.get(userName.toLowerCase());
if(user == null)
user = Provider.impl.getUserByName(userName);
return user;
}
public static SteamwarUser get(UUID uuid){
SteamwarUser user = byUUID.get(uuid);
if(user == null)
user = Provider.impl.getUserByUUID(uuid);
return user;
}
public static SteamwarUser get(int id) {
SteamwarUser user = byId.get(id);
if(user == null)
user = Provider.impl.getUserByID(id);
return user;
}
public static SteamwarUser get(Player player) {
return get(player.getUniqueId());
}
public static List<SteamwarUser> getServerTeam() {
return Provider.impl.getServerTeam();
}
}

Datei anzeigen

@ -1,72 +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.util.Arrays;
import java.util.stream.Collectors;
public enum UserGroup {
Admin("§4", "§e", true, true, true),
Developer("§3", "§f", true, true, true),
Moderator("§c", "§f", true, true, true),
Supporter("§9", "§f", false, true, true),
Builder("§2", "§f", false, true, false),
YouTuber("§5", "§f", false, false, false),
Member("§7", "§7", false, false, false);
private final String colorCode;
private final String chatColorCode;
private final boolean adminGroup;
private final boolean teamGroup;
private final boolean checkSchematics;
UserGroup(String colorCode, String chatColorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) {
this.colorCode = colorCode;
this.chatColorCode = chatColorCode;
this.adminGroup = adminGroup;
this.teamGroup = teamGroup;
this.checkSchematics = checkSchematics;
}
public String getColorCode() {
return colorCode;
}
public boolean isAdminGroup() {
return adminGroup;
}
public boolean isTeamGroup() {
return teamGroup;
}
public boolean isCheckSchematics() {
return checkSchematics;
}
public String getChatColorCode() {
return chatColorCode;
}
public static UserGroup getUsergroup(String name) {
return Arrays.stream(UserGroup.values()).filter(userGroup -> userGroup.name().equalsIgnoreCase(name)).collect(Collectors.toList()).get(0);
}
}