Merge branch 'master' into schemType
# Conflicts: # SpigotCore_Main/src/de/steamwar/sql/Schematic.java
Dieser Commit ist enthalten in:
Commit
4a9a678a63
@ -45,11 +45,5 @@
|
||||
<version>2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>SpigotCore_12</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -4,8 +4,9 @@ import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,8 +18,8 @@ import java.io.InputStream;
|
||||
class Schematic_14 {
|
||||
private Schematic_14(){}
|
||||
|
||||
private static final ClipboardFormat SCHEMATIC = ClipboardFormats.findByAlias("schematic");
|
||||
private static final ClipboardFormat SCHEM = ClipboardFormats.findByAlias("schem");
|
||||
private static final ClipboardFormat SCHEMATIC = BuiltInClipboardFormat.MCEDIT_SCHEMATIC;
|
||||
private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
|
||||
|
||||
static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException {
|
||||
ClipboardHolder clipboardHolder;
|
||||
@ -35,10 +36,10 @@ class Schematic_14 {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try{
|
||||
if(schemFormat){
|
||||
assert SCHEM != null;
|
||||
SCHEM.getWriter(outputStream).write(clipboard);
|
||||
ClipboardWriter writer = SCHEM.getWriter(outputStream);
|
||||
writer.write(clipboard);
|
||||
writer.close();
|
||||
}else{
|
||||
assert SCHEMATIC != null;
|
||||
SCHEMATIC.getWriter(outputStream).write(clipboard);
|
||||
}
|
||||
}catch(NullPointerException e){
|
||||
@ -60,10 +61,8 @@ class Schematic_14 {
|
||||
static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
|
||||
try {
|
||||
if(schemFormat){
|
||||
assert SCHEM != null;
|
||||
return SCHEM.getReader(is).read();
|
||||
}else{
|
||||
assert SCHEMATIC != null;
|
||||
return SCHEMATIC.getReader(is).read();
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
|
@ -36,6 +36,8 @@ public class Core extends JavaPlugin{
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||
if(version >= 12)
|
||||
ErrorLogger.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,6 +52,7 @@ public class Core extends JavaPlugin{
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
private static void setInstance(Core instance) {
|
||||
Core.instance = instance;
|
||||
}
|
||||
|
42
SpigotCore_Main/src/de/steamwar/core/ErrorLogger.java
Normale Datei
42
SpigotCore_Main/src/de/steamwar/core/ErrorLogger.java
Normale Datei
@ -0,0 +1,42 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.steamwar.sql.SWException;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.Core;
|
||||
import org.apache.logging.log4j.core.*;
|
||||
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
||||
import org.apache.logging.log4j.core.config.plugins.Plugin;
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
|
||||
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
|
||||
|
||||
@Plugin(name = "ErrorLogger", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
|
||||
public class ErrorLogger extends AbstractAppender {
|
||||
|
||||
public static void init(){
|
||||
final LoggerContext lc = (LoggerContext) LogManager.getContext(false);
|
||||
ErrorLogger el = ErrorLogger.createAppender("SWErrorLogger");
|
||||
el.start();
|
||||
lc.getConfiguration().addAppender(el);
|
||||
lc.getRootLogger().addAppender(lc.getConfiguration().getAppender(el.getName()));
|
||||
lc.updateLoggers();
|
||||
}
|
||||
|
||||
private ErrorLogger(String name) {
|
||||
super(name, null, null);
|
||||
}
|
||||
|
||||
@PluginFactory
|
||||
public static ErrorLogger createAppender(
|
||||
@PluginAttribute("name") String name) {
|
||||
return new ErrorLogger(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append(LogEvent logEvent) {
|
||||
if(logEvent.getLevel().isLessSpecificThan(Level.WARN))
|
||||
return;
|
||||
|
||||
SWException.log(logEvent);
|
||||
}
|
||||
}
|
@ -92,7 +92,7 @@ public class SWInventory implements Listener {
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
if(callbacks.containsKey(e.getRawSlot()))
|
||||
if(callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null)
|
||||
callbacks.get(e.getRawSlot()).clicked(e.getClick());
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package de.steamwar.inventory;
|
||||
|
||||
import de.steamwar.sql.Schematic;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import javafx.util.Pair;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,17 +15,6 @@ public class SWListInv<T> extends SWInventory {
|
||||
private List<SWListEntry<T>> elements;
|
||||
private int page;
|
||||
|
||||
@Deprecated
|
||||
public SWListInv(Player p, String t, ListCallback<T> c, List<Pair<SWItem, T>> l) {
|
||||
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
|
||||
callback = c;
|
||||
//Only here for backwards compatibility
|
||||
elements = new LinkedList<>();
|
||||
for(Pair<SWItem, T> pair : l)
|
||||
elements.add(new SWListEntry<>(pair.getKey(), pair.getValue()));
|
||||
page = 0;
|
||||
}
|
||||
|
||||
public SWListInv(Player p, String t, List<SWListEntry<T>> l, ListCallback<T> c){
|
||||
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
|
||||
callback = c;
|
||||
@ -79,18 +67,6 @@ public class SWListInv<T> extends SWInventory {
|
||||
void clicked(ClickType click, T element);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<Pair<SWItem, UUID>> createPlayerList(Player without){
|
||||
List<Pair<SWItem, UUID>> onlinePlayers = new ArrayList<>();
|
||||
for(Player player : Bukkit.getOnlinePlayers()){
|
||||
if(without != null && player.getUniqueId().equals(without.getUniqueId()))
|
||||
continue;
|
||||
|
||||
onlinePlayers.add(new Pair<>(SWItem.getPlayerSkull(player), player.getUniqueId()));
|
||||
}
|
||||
return onlinePlayers;
|
||||
}
|
||||
|
||||
public static List<SWListEntry<UUID>> createPlayerList(UUID without){
|
||||
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
|
||||
for(Player player : Bukkit.getOnlinePlayers()){
|
||||
@ -102,28 +78,6 @@ public class SWListInv<T> extends SWInventory {
|
||||
return onlinePlayers;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<Pair<SWItem, Schematic>> getSchemList(int warkingUserId, SchematicType type){
|
||||
List<Pair<SWItem, Schematic>> schemList = new ArrayList<>();
|
||||
|
||||
List<Schematic> schems;
|
||||
if(type == null)
|
||||
schems = Schematic.getSchemsAccessibleByUser(warkingUserId);
|
||||
else
|
||||
schems = Schematic.getSchemsOfType(warkingUserId, type);
|
||||
|
||||
for(Schematic s : schems){
|
||||
Material m;
|
||||
if(s.getItem().isEmpty())
|
||||
m = SWItem.getMaterial("CAULDRON_ITEM");
|
||||
else
|
||||
m = SWItem.getMaterial(s.getItem());
|
||||
SWItem item = new SWItem(m,"§e" + s.getSchemName());
|
||||
schemList.add(new Pair<>(item, s));
|
||||
}
|
||||
return schemList;
|
||||
}
|
||||
|
||||
public static List<SWListEntry<Schematic>> getSchemList(SchematicType type, int steamwarUserId){
|
||||
List<SWListEntry<Schematic>> schemList = new ArrayList<>();
|
||||
|
||||
|
@ -41,14 +41,11 @@ public class SWScoreboard {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean removeScoreboard(Player player) {
|
||||
public static void removeScoreboard(Player player) {
|
||||
if(!playerBoards.containsKey(player))
|
||||
return false;
|
||||
|
||||
playerBoards.remove(player);
|
||||
if(player == null)
|
||||
return true;
|
||||
return;
|
||||
|
||||
try{
|
||||
switch (Core.getVersion()) {
|
||||
case 8:
|
||||
((SWScoreboard_8) playerBoards.get(player)).deleteScoreboard(player);
|
||||
@ -68,10 +65,11 @@ public class SWScoreboard {
|
||||
case 15:
|
||||
((SWScoreboard_15) playerBoards.get(player)).deleteScoreboard(player);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}catch(NullPointerException e){
|
||||
//ignored
|
||||
}
|
||||
playerBoards.remove(player);
|
||||
}
|
||||
|
||||
//Scoreboard Updater
|
||||
|
@ -36,17 +36,13 @@ public class BauweltMember{
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
SQL.update("DELETE FROM BauweltMember WHERE BauweltID = " + bauweltID + " AND MemberID = " + memberID);
|
||||
SQL.update("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?", bauweltID, memberID);
|
||||
members.remove(this);
|
||||
}
|
||||
|
||||
private void updateDB(){
|
||||
SQL.update("INSERT INTO BauweltMember" +
|
||||
" (BauweltID, MemberID, Build, WorldEdit, World)" +
|
||||
" VALUES" +
|
||||
" ('" + bauweltID + "', '" + memberID + "', '" + SQL.booleanToInt(build) + "', '" + SQL.booleanToInt(worldEdit) + "', '" + SQL.booleanToInt(world) + "')" +
|
||||
" ON DUPLICATE KEY UPDATE" +
|
||||
" Build = VALUES(Build), WorldEdit = VALUES(WorldEdit), World = VALUES(World)");
|
||||
SQL.update("INSERT INTO BauweltMember (BauweltID, MemberID, Build, WorldEdit, World) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Build = VALUES(Build), WorldEdit = VALUES(WorldEdit), World = VALUES(World)",
|
||||
bauweltID, memberID, build, worldEdit, world);
|
||||
}
|
||||
|
||||
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
||||
@ -57,7 +53,7 @@ public class BauweltMember{
|
||||
for(BauweltMember member : members)
|
||||
if(member.memberID == memberID)
|
||||
return member;
|
||||
ResultSet member = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + ownerID + "' AND MemberID = '" + memberID + "'");
|
||||
ResultSet member = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?", ownerID, memberID);
|
||||
try {
|
||||
if(member == null || !member.next()){
|
||||
return null;
|
||||
@ -77,7 +73,7 @@ public class BauweltMember{
|
||||
|
||||
public static List<BauweltMember> getMembers(int bauweltID){
|
||||
try{
|
||||
ResultSet memberlist = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'");
|
||||
ResultSet memberlist = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = ?", bauweltID);
|
||||
List<BauweltMember> members = new LinkedList<>();
|
||||
while(memberlist.next()){
|
||||
int memberID = memberlist.getInt("MemberID");
|
||||
|
@ -21,12 +21,12 @@ public class CheckedSchematic {
|
||||
private final String declineReason;
|
||||
|
||||
private CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason, boolean insertDB){
|
||||
this.schemName = SQL.disarmString(schemName);
|
||||
this.schemName = schemName;
|
||||
this.schemOwner = schemOwner;
|
||||
this.validator = validator;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.declineReason = SQL.disarmString(declineReason);
|
||||
this.declineReason = declineReason;
|
||||
if(insertDB)
|
||||
insertDB();
|
||||
}
|
||||
@ -41,9 +41,8 @@ public class CheckedSchematic {
|
||||
|
||||
private void insertDB(){
|
||||
SQL.update("INSERT INTO CheckedSchematic" +
|
||||
" (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason)" +
|
||||
" VALUES" +
|
||||
" ('"+ schemName + "', '" + schemOwner + "', '" + validator + "', '" + startTime.toString() + "', '" + endTime.toString() + "', '" + declineReason + "')");
|
||||
" (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
schemName, schemOwner, validator, startTime, endTime, declineReason);
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclined(UUID schemOwner){
|
||||
@ -53,7 +52,7 @@ public class CheckedSchematic {
|
||||
public static List<CheckedSchematic> getLastDelined(int schemOwner){
|
||||
List<CheckedSchematic> lastDeclined = new LinkedList<>();
|
||||
try{
|
||||
ResultSet lastRS = SQL.select("SELECT * FROM CheckedSchematic WHERE SchemOwner = '" + schemOwner + "' AND DeclineReason != '' ORDER BY EndTime DESC");
|
||||
ResultSet lastRS = SQL.select("SELECT * FROM CheckedSchematic WHERE SchemOwner = ? AND DeclineReason != '' ORDER BY EndTime DESC", schemOwner);
|
||||
while(lastRS.next()){
|
||||
String schemName = lastRS.getString("SchemName");
|
||||
int validator = lastRS.getInt("Validator");
|
||||
@ -69,7 +68,7 @@ public class CheckedSchematic {
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
SQL.update("DELETE FROM CheckedSchematic WHERE SchemOwner = " + this.schemOwner + " AND SchemName = '" + this.schemName + "'");
|
||||
SQL.update("DELETE FROM CheckedSchematic WHERE SchemOwner = ? AND SchemName = ?", schemOwner, schemName);
|
||||
}
|
||||
|
||||
public String getSchemName() {
|
||||
|
@ -13,7 +13,7 @@ public class DownloadSchematic {
|
||||
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
||||
|
||||
public static String getLink(Schematic schem){
|
||||
ResultSet rs = SQL.select("SELECT * FROM SchemDownload WHERE SchemID = " + schem.getSchemID());
|
||||
ResultSet rs = SQL.select("SELECT * FROM SchemDownload WHERE SchemID = ?", schem.getSchemID());
|
||||
try {
|
||||
if(rs.next())
|
||||
return BASE + rs.getString("Link");
|
||||
@ -30,7 +30,7 @@ public class DownloadSchematic {
|
||||
cript.reset();
|
||||
cript.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes());
|
||||
String hash = DatatypeConverter.printHexBinary(cript.digest());
|
||||
SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (" + schem.getSchemID() + ", '" + hash + "')");
|
||||
SQL.update("INSERT INTO SchemDownload (SchemID, Link) VALUES (?, ?)", schem.getSchemID(), hash);
|
||||
return BASE + hash;
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,22 @@ public class Event {
|
||||
private final int maximumTeamMembers;
|
||||
private final boolean publicSchemsOnly;
|
||||
|
||||
private Event(int eventID, String eventName, Timestamp start, Timestamp end, int maximumTeamMembers, boolean publicSchemsOnly){
|
||||
this.eventID = eventID;
|
||||
this.eventName = eventName;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.maximumTeamMembers = maximumTeamMembers;
|
||||
this.publicSchemsOnly = publicSchemsOnly;
|
||||
private Event(ResultSet rs) throws SQLException{
|
||||
this.eventID = rs.getInt("EventID");
|
||||
this.eventName = rs.getString("EventName");
|
||||
this.start = rs.getTimestamp("Start");
|
||||
this.end = rs.getTimestamp("End");
|
||||
this.maximumTeamMembers = rs.getInt("MaximumTeamMembers");
|
||||
this.publicSchemsOnly = rs.getBoolean("PublicSchemsOnly");
|
||||
}
|
||||
|
||||
public static Event get(int eventID){
|
||||
ResultSet rs = SQL.select("SELECT * FROM Event WHERE EventID = " + eventID);
|
||||
ResultSet rs = SQL.select("SELECT * FROM Event WHERE EventID = ?", eventID);
|
||||
try{
|
||||
if(!rs.next())
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
return new Event(eventID, rs.getString("EventName"), rs.getTimestamp("Start"), rs.getTimestamp("End"), rs.getInt("MaximumTeamMembers"), rs.getBoolean("PublicSchemsOnly"));
|
||||
return new Event(rs);
|
||||
}catch (SQLException e){
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Event", e);
|
||||
throw new SecurityException();
|
||||
|
@ -14,26 +14,20 @@ public class EventFight {
|
||||
private int kampfleiter;
|
||||
private int ergebnis;
|
||||
|
||||
private 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;
|
||||
private EventFight(ResultSet rs) throws SQLException{
|
||||
this.eventID = rs.getInt("EventID");
|
||||
this.fightID = rs.getInt("FightID");
|
||||
this.teamBlue = rs.getInt("TeamBlue");
|
||||
this.teamRed = rs.getInt("TeamRed");
|
||||
this.kampfleiter = rs.getInt("Kampfleiter");
|
||||
this.ergebnis = rs.getInt("Ergebnis");
|
||||
}
|
||||
|
||||
public static EventFight get(int fightID){
|
||||
ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE FightID = " + fightID);
|
||||
try{
|
||||
rs.next();
|
||||
return new EventFight(
|
||||
rs.getInt("EventID"),
|
||||
fightID,
|
||||
rs.getInt("TeamBlue"),
|
||||
rs.getInt("TeamRed"),
|
||||
rs.getInt("Kampfleiter"),
|
||||
rs.getInt("Ergebnis"));
|
||||
return new EventFight(rs);
|
||||
}catch (SQLException e){
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight", e);
|
||||
}
|
||||
@ -41,7 +35,7 @@ public class EventFight {
|
||||
}
|
||||
|
||||
public void setErgebnis(int winner){
|
||||
SQL.update("UPDATE EventFight SET Ergebnis = " + winner + " WHERE FightID = " + fightID);
|
||||
SQL.update("UPDATE EventFight SET Ergebnis = ? WHERE FightID = ?", winner, fightID);
|
||||
}
|
||||
|
||||
public int getTeamBlue() {
|
||||
|
23
SpigotCore_Main/src/de/steamwar/sql/Fight.java
Normale Datei
23
SpigotCore_Main/src/de/steamwar/sql/Fight.java
Normale Datei
@ -0,0 +1,23 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class Fight {
|
||||
private Fight(){}
|
||||
|
||||
public static int create(String gamemode, String arena, Timestamp starttime, int duration, int blueleader, int redleader, int blueschem, int redschem, int win, String wincondition){
|
||||
SQL.update("INSERT INTO Fight (GameMode, Arena, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
gamemode, arena, starttime, duration, blueleader, redleader,blueschem, redschem, win, wincondition);
|
||||
ResultSet rs = SQL.select("SELECT LAST_INSERT_ID() AS FightID");
|
||||
try{
|
||||
if(!rs.next())
|
||||
throw new SecurityException("No last insert id");
|
||||
|
||||
return rs.getInt("FightID");
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
}
|
10
SpigotCore_Main/src/de/steamwar/sql/FightPlayer.java
Normale Datei
10
SpigotCore_Main/src/de/steamwar/sql/FightPlayer.java
Normale Datei
@ -0,0 +1,10 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
public class FightPlayer {
|
||||
private FightPlayer(){}
|
||||
|
||||
public static void create(int fightID, int userID, String kit, int kills, boolean isOut){
|
||||
SQL.update("INSERT INTO FightPlayer (FightID, UserID, Kit, Kills, IsOut) VALUES (?, ?, ?, ?, ?)",
|
||||
fightID, userID, kit, kills, isOut);
|
||||
}
|
||||
}
|
58
SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java
Normale Datei
58
SpigotCore_Main/src/de/steamwar/sql/PersonalKit.java
Normale Datei
@ -0,0 +1,58 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PersonalKit {
|
||||
|
||||
private final int userID;
|
||||
private final String gamemode;
|
||||
private String inventory;
|
||||
private String armor;
|
||||
|
||||
private PersonalKit(ResultSet rs) throws SQLException {
|
||||
userID = rs.getInt("UserID");
|
||||
gamemode = rs.getString("GameMode");
|
||||
inventory = rs.getString("Inventory");
|
||||
armor = rs.getString("Armor");
|
||||
}
|
||||
|
||||
public static PersonalKit get(int userID, String gamemode){
|
||||
ResultSet rs = SQL.select("SELECT * FROM PersonalKit WHERE UserID = ? AND GameMode = ?", userID, gamemode);
|
||||
try {
|
||||
if(!rs.next())
|
||||
return null;
|
||||
|
||||
return new PersonalKit(rs);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Failed loading personal kit", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PersonalKit save(int userID, String gamemode, ItemStack[] inventory, ItemStack[] armor){
|
||||
YamlConfiguration inventoryConfig = new YamlConfiguration();
|
||||
inventoryConfig.set("Inventory", inventory);
|
||||
|
||||
YamlConfiguration armorConfig = new YamlConfiguration();
|
||||
armorConfig.set("Armor", armor);
|
||||
|
||||
SQL.update("INSERT INTO PersonalKit (UserID, GameMode, Inventory, Armor) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Inventory = VALUES(Inventory), Armor = VALUES(Armor)",
|
||||
userID, gamemode, inventoryConfig.saveToString(), armorConfig.saveToString());
|
||||
return get(userID, gamemode);
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory(){
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(inventory));
|
||||
return Objects.requireNonNull(config.getList("Inventory")).toArray(new ItemStack[0]);
|
||||
}
|
||||
|
||||
public ItemStack[] getArmor(){
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(armor));
|
||||
return Objects.requireNonNull(config.getList("Armor")).toArray(new ItemStack[0]);
|
||||
}
|
||||
}
|
@ -34,13 +34,6 @@ public class SQL {
|
||||
connect();
|
||||
}
|
||||
|
||||
static Integer booleanToInt(boolean b){
|
||||
if(b)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void closeConnection() {
|
||||
try {
|
||||
con.close();
|
||||
@ -49,44 +42,52 @@ public class SQL {
|
||||
}
|
||||
}
|
||||
|
||||
static Connection getCon(){
|
||||
return con;
|
||||
}
|
||||
|
||||
static void update(String qry) {
|
||||
static void update(String qry, Object... objects) {
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
prepare(qry, objects).executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
prepare(qry, objects).executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
throw new SecurityException("Could not perform update", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ResultSet select(String qry) {
|
||||
static ResultSet select(String qry, Object... objects){
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
return prepare(qry, objects).executeQuery();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
return prepare(qry, objects).executeQuery();
|
||||
} catch (SQLException ex) {
|
||||
throw new SecurityException("Could not perform select", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String disarmString(String s){
|
||||
return s.replace("'", "");
|
||||
static Blob blob(){
|
||||
try {
|
||||
return con.createBlob();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
return con.createBlob();
|
||||
} catch (SQLException ex) {
|
||||
throw new SecurityException("Could not create blob", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement prepare(String qry, Object... objects) throws SQLException{
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
for(int i = 0; i < objects.length; i++){
|
||||
st.setObject(i+1, objects[i]);
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
private static void connect() {
|
||||
try {
|
||||
|
46
SpigotCore_Main/src/de/steamwar/sql/SWException.java
Normale Datei
46
SpigotCore_Main/src/de/steamwar/sql/SWException.java
Normale Datei
@ -0,0 +1,46 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SWException {
|
||||
private SWException(){}
|
||||
|
||||
private static boolean logDisabled = false;
|
||||
|
||||
public static void log(LogEvent logEvent){
|
||||
if(logDisabled)
|
||||
return;
|
||||
|
||||
String server = Bukkit.getWorlds().get(0).getName();
|
||||
StringBuilder stacktrace = new StringBuilder(logEvent.getSource().toString());
|
||||
|
||||
Throwable throwable = logEvent.getThrown();
|
||||
while(throwable != null){
|
||||
stacktrace.append("\nCaused by ").append(throwable.getMessage());
|
||||
|
||||
for(StackTraceElement ste : throwable.getStackTrace())
|
||||
stacktrace.append("\n").append(ste.toString());
|
||||
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
|
||||
String message = logEvent.getMessage().getFormattedMessage();
|
||||
if(message.startsWith("Block at") || message.startsWith("POI data mismatch"))
|
||||
return;
|
||||
|
||||
if(message.equals("------------------------------")){
|
||||
message = "Server stopped responding";
|
||||
logDisabled = true;
|
||||
}
|
||||
|
||||
message += "\n\n";
|
||||
|
||||
for(Player player : Bukkit.getOnlinePlayers())
|
||||
message += player.getName() + " ";
|
||||
|
||||
SQL.update("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)",
|
||||
server, message, stacktrace.toString());
|
||||
}
|
||||
}
|
@ -4,11 +4,9 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Blob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@ -42,12 +40,8 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public static void createSchem(String schemName, int schemOwner, String item, SchematicType schemType){
|
||||
SQL.update("INSERT INTO Schematic" +
|
||||
" (SchemName, SchemOwner, Item, SchemType)" +
|
||||
" VALUES" +
|
||||
" ('" + schemName + "', '" + schemOwner + "', '" + item + "', '" + schemType.toDB() + "')" +
|
||||
" ON DUPLICATE KEY UPDATE" +
|
||||
" Item = VALUES(Item), SchemType = VALUES(SchemType)");
|
||||
SQL.update("INSERT INTO Schematic (SchemName, SchemOwner, Item, SchemType) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), SchemType = VALUES(SchemType)",
|
||||
schemName, schemOwner, item, schemType.toDB());
|
||||
}
|
||||
|
||||
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){
|
||||
@ -55,8 +49,7 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public static Schematic getSchemFromDB(String schemName, int schemOwner){
|
||||
schemName = SQL.disarmString(schemName);
|
||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
|
||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
|
||||
try {
|
||||
if(schematic == null || !schematic.next()){
|
||||
SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner);
|
||||
@ -77,7 +70,7 @@ public class Schematic {
|
||||
|
||||
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
||||
try{
|
||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemOwner = '" + schemOwner + "' ORDER BY SchemName");
|
||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemOwner = ? ORDER BY SchemName", schemOwner);
|
||||
List<Schematic> schematics = new ArrayList<>();
|
||||
while(schematic.next()){
|
||||
schematics.add(new Schematic(schematic));
|
||||
@ -107,7 +100,7 @@ public class Schematic {
|
||||
|
||||
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
||||
try{
|
||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'");
|
||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemType = ?", schemType.toDB());
|
||||
List<Schematic> schematics = new ArrayList<>();
|
||||
while(schematic.next()){
|
||||
schematics.add(new Schematic(schematic));
|
||||
@ -153,7 +146,7 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public Clipboard load() throws IOException, NoClipboardException {
|
||||
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID);
|
||||
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID);
|
||||
try {
|
||||
rs.next();
|
||||
Blob schemData = rs.getBlob("SchemData");
|
||||
@ -181,10 +174,13 @@ public class Schematic {
|
||||
|
||||
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
|
||||
|
||||
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID);
|
||||
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = ?", schemID);
|
||||
try {
|
||||
rs.next();
|
||||
InputStream is = rs.getBlob("SchemData").getBinaryStream();
|
||||
Blob blob = rs.getBlob("SchemData");
|
||||
if(blob == null)
|
||||
throw new NoClipboardException();
|
||||
InputStream is = blob.getBinaryStream();
|
||||
switch(Core.getVersion()){
|
||||
case 8:
|
||||
Schematic_8.setPlayerClipboard(player, is, schemFormat);
|
||||
@ -219,34 +215,31 @@ public class Schematic {
|
||||
|
||||
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
|
||||
try{
|
||||
PreparedStatement st = SQL.getCon().prepareStatement("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = " + schemID);
|
||||
byte[] data;
|
||||
Blob blob = SQL.blob();
|
||||
switch(Core.getVersion()){
|
||||
case 8:
|
||||
newFormat = false;
|
||||
data = Schematic_8.getPlayerClipboard(player);
|
||||
blob.setBytes(1, Schematic_8.getPlayerClipboard(player));
|
||||
break;
|
||||
case 9:
|
||||
newFormat = false;
|
||||
data = Schematic_9.getPlayerClipboard(player);
|
||||
blob.setBytes(1, Schematic_9.getPlayerClipboard(player));
|
||||
break;
|
||||
case 10:
|
||||
newFormat = false;
|
||||
data = Schematic_10.getPlayerClipboard(player);
|
||||
blob.setBytes(1, Schematic_10.getPlayerClipboard(player));
|
||||
break;
|
||||
case 14:
|
||||
data = Schematic_14.getPlayerClipboard(player, newFormat);
|
||||
blob.setBytes(1, Schematic_14.getPlayerClipboard(player, newFormat));
|
||||
break;
|
||||
case 15:
|
||||
data = Schematic_15.getPlayerClipboard(player, newFormat);
|
||||
blob.setBytes(1, Schematic_15.getPlayerClipboard(player, newFormat));
|
||||
break;
|
||||
default:
|
||||
newFormat = false;
|
||||
data = Schematic_12.getPlayerClipboard(player);
|
||||
blob.setBytes(1, Schematic_12.getPlayerClipboard(player));
|
||||
}
|
||||
st.setBlob(1, new ByteArrayInputStream(data));
|
||||
st.setBoolean(2, newFormat);
|
||||
st.executeUpdate();
|
||||
SQL.update("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = ?", blob, newFormat, schemID);
|
||||
schemFormat = newFormat;
|
||||
}catch(SQLException e){
|
||||
throw new IOException(e);
|
||||
@ -254,8 +247,8 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
|
||||
SQL.update("DELETE FROM Schematic WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
|
||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ?", schemOwner, schemName);
|
||||
SQL.update("DELETE FROM Schematic WHERE SchemOwner = ? AND SchemName = ?", schemOwner, schemName);
|
||||
}
|
||||
|
||||
public static class WrongVersionException extends Exception{}
|
||||
|
@ -28,10 +28,7 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
private void updateDB(){
|
||||
SQL.update("INSERT INTO SchemMember" +
|
||||
" (SchemName, SchemOwner, Member)" +
|
||||
" VALUES" +
|
||||
" ('" + schemName + "', '" + schemOwner + "', '" + member + "')");
|
||||
SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member);
|
||||
}
|
||||
|
||||
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
|
||||
@ -39,7 +36,7 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember){
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "' AND Member = '" + schemMember + "'");
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ? AND Member = ?", schemName, schemOwner, schemMember);
|
||||
try {
|
||||
if(schematicMember == null || !schematicMember.next()){
|
||||
return null;
|
||||
@ -51,7 +48,7 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = '" + schemName + "' AND Member = '" + schemMember + "'");
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND Member = ?", schemName, schemMember);
|
||||
try {
|
||||
if(schematicMember == null || !schematicMember.next()){
|
||||
return null;
|
||||
@ -68,7 +65,7 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
|
||||
try {
|
||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
||||
while(schematicMember.next()){
|
||||
@ -86,7 +83,7 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
public static List<SchematicMember> getAccessibleSchems(int schemMember){
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = '" + schemMember + "'");
|
||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = ?", schemMember);
|
||||
try {
|
||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
||||
while(schematicMember.next()){
|
||||
@ -113,6 +110,6 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "' AND Member = '" + member + "'");
|
||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?", schemOwner, schemName, member);
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,52 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public enum SchematicType {
|
||||
Normal("", Type.NORMAL),
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
CAirShip("CAS", Type.CHECK_TYPE),
|
||||
CWarGear("CWG", Type.CHECK_TYPE),
|
||||
CWarShip("CWS", Type.CHECK_TYPE),
|
||||
CMiniWarGear("CMWG", Type.CHECK_TYPE),
|
||||
AirShip("AS", Type.FIGHT_TYPE, CAirShip),
|
||||
WarGear("WG", Type.FIGHT_TYPE, CWarGear),
|
||||
WarShip("WS", Type.FIGHT_TYPE, CWarShip),
|
||||
MiniWarGear("MWG", Type.FIGHT_TYPE, CMiniWarGear),
|
||||
public class SchematicType {
|
||||
public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null); //Has to stay publicly availible
|
||||
|
||||
CMPPWarGear1_12("CMPPWG", Type.CHECK_TYPE),
|
||||
CSGWarShip("CSGWS", Type.CHECK_TYPE),
|
||||
CWarGear1_10("CWG1.10", Type.CHECK_TYPE),
|
||||
CWarShip1_9("CWS1.9", Type.CHECK_TYPE),
|
||||
CWarShip1_8("CWS1.8", Type.CHECK_TYPE),
|
||||
CWarGear1_7("CWG1.7", Type.CHECK_TYPE),
|
||||
WarGear1_14("WG1.14", Type.FIGHT_TYPE, null),
|
||||
MPPWarGear1_12("MPPWG", Type.FIGHT_TYPE, CMPPWarGear1_12),
|
||||
SGWarShip("SGWS", Type.FIGHT_TYPE, CSGWarShip),
|
||||
WarGear1_12("WG1.12", Type.FIGHT_TYPE, null),
|
||||
WarShip1_12("WS1.12", Type.FIGHT_TYPE, null),
|
||||
MiniWarGear1_12("MWG1.12", Type.FIGHT_TYPE, null),
|
||||
WarGear1_10("WG1.10", Type.FIGHT_TYPE, CWarGear1_10),
|
||||
WarShip1_9("WS1.9", Type.FIGHT_TYPE, CWarShip1_9),
|
||||
WarShip1_8("WS1.8", Type.FIGHT_TYPE, CWarShip1_8),
|
||||
WarGear1_7("WG1.7", Type.FIGHT_TYPE, CWarGear1_7)
|
||||
|
||||
;
|
||||
|
||||
private static Map<String, SchematicType> fromDB = new HashMap<>();
|
||||
private static final Map<String, SchematicType> fromDB;
|
||||
private static final List<SchematicType> types;
|
||||
|
||||
static{
|
||||
for(SchematicType type : values()){
|
||||
fromDB.put(type.toDB(), type);
|
||||
}
|
||||
File file = new File(Core.getInstance().getDataFolder(), "SchematicTypes.yml");
|
||||
|
||||
if(!file.exists())
|
||||
throw new SecurityException("SchematicType-ConfigFile not found!");
|
||||
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
List<SchematicType> tmpTypes = new LinkedList<>();
|
||||
Map<String, SchematicType> tmpFromDB = new HashMap<>();
|
||||
|
||||
tmpTypes.add(Normal);
|
||||
tmpFromDB.put(Normal.name().toLowerCase(), Normal);
|
||||
|
||||
for(String type : config.getKeys(false)){
|
||||
ConfigurationSection section = config.getConfigurationSection(type);
|
||||
assert section != null;
|
||||
String checktype = section.getString("checktype");
|
||||
SchematicType current = new SchematicType(type, section.getString("kuerzel"), Type.valueOf(section.getString("type")), checktype != null ? tmpFromDB.get(checktype.toLowerCase()) : null);
|
||||
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 SchematicType checkType;
|
||||
|
||||
SchematicType(String kuerzel, Type type){
|
||||
this(kuerzel, type, null);
|
||||
}
|
||||
|
||||
SchematicType(String kuerzel, Type type, SchematicType checkType){
|
||||
private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){
|
||||
this.name = name;
|
||||
this.kuerzel = kuerzel;
|
||||
this.type = type;
|
||||
this.checkType = checkType;
|
||||
@ -76,16 +72,24 @@ public enum SchematicType {
|
||||
return type == Type.NORMAL;
|
||||
}
|
||||
|
||||
public String name(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getKuerzel() {
|
||||
return kuerzel;
|
||||
}
|
||||
|
||||
public String toDB(){
|
||||
return name().toLowerCase();
|
||||
return name.toLowerCase();
|
||||
}
|
||||
|
||||
public static SchematicType fromDB(String input){
|
||||
return fromDB.get(input.toLowerCase());
|
||||
return fromDB.getOrDefault(input.toLowerCase(), null);
|
||||
}
|
||||
|
||||
public static List<SchematicType> values(){
|
||||
return types;
|
||||
}
|
||||
|
||||
enum Type{
|
||||
|
@ -63,8 +63,8 @@ public class SteamwarUser {
|
||||
return team;
|
||||
}
|
||||
|
||||
private static SteamwarUser fromDB(String statement){
|
||||
ResultSet rs = SQL.select(statement);
|
||||
private static SteamwarUser fromDB(String statement, Object identifier){
|
||||
ResultSet rs = SQL.select(statement, identifier);
|
||||
try {
|
||||
if(rs.next())
|
||||
return new SteamwarUser(rs);
|
||||
@ -75,24 +75,23 @@ public class SteamwarUser {
|
||||
}
|
||||
|
||||
public static SteamwarUser get(String userName){
|
||||
userName = SQL.disarmString(userName);
|
||||
SteamwarUser user = byName.get(userName.toLowerCase());
|
||||
if(user == null)
|
||||
user = fromDB("SELECT * FROM UserData WHERE lower(UserName) = '" + userName.toLowerCase() + "'");
|
||||
user = fromDB("SELECT * FROM UserData WHERE lower(UserName) = ?", userName.toLowerCase());
|
||||
return user;
|
||||
}
|
||||
|
||||
public static SteamwarUser get(UUID uuid){
|
||||
SteamwarUser user = byUUID.get(uuid);
|
||||
if(user == null)
|
||||
user = fromDB("SELECT * FROM UserData WHERE UUID = '" + uuid.toString() + "'");
|
||||
user = fromDB("SELECT * FROM UserData WHERE UUID = ?", uuid.toString());
|
||||
return user;
|
||||
}
|
||||
|
||||
public static SteamwarUser get(int id) {
|
||||
SteamwarUser user = byId.get(id);
|
||||
if(user == null)
|
||||
user = fromDB("SELECT * FROM UserData WHERE id = '" + id + "'");
|
||||
user = fromDB("SELECT * FROM UserData WHERE id = ?", id);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class Team {
|
||||
public static Team get(int id){
|
||||
if(id == 0)
|
||||
return pub;
|
||||
ResultSet rs = SQL.select("SELECT * FROM Team WHERE TeamID = " + id);
|
||||
ResultSet rs = SQL.select("SELECT * FROM Team WHERE TeamID = ?", id);
|
||||
try {
|
||||
if(!rs.next())
|
||||
return null;
|
||||
@ -55,7 +55,7 @@ public class Team {
|
||||
|
||||
public List<Integer> getMembers(){
|
||||
try{
|
||||
ResultSet memberlist = SQL.select("SELECT id FROM UserData WHERE Team = '" + teamId + "'");
|
||||
ResultSet memberlist = SQL.select("SELECT id FROM UserData WHERE Team = ?", teamId);
|
||||
List<Integer> members = new LinkedList<>();
|
||||
while(memberlist.next())
|
||||
members.add(memberlist.getInt("id"));
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren