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>
|
<version>2.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>steamwar</groupId>
|
|
||||||
<artifactId>SpigotCore_12</artifactId>
|
|
||||||
<version>2.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -4,8 +4,9 @@ import com.sk89q.worldedit.EmptyClipboardException;
|
|||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
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.ClipboardFormat;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -17,8 +18,8 @@ import java.io.InputStream;
|
|||||||
class Schematic_14 {
|
class Schematic_14 {
|
||||||
private Schematic_14(){}
|
private Schematic_14(){}
|
||||||
|
|
||||||
private static final ClipboardFormat SCHEMATIC = ClipboardFormats.findByAlias("schematic");
|
private static final ClipboardFormat SCHEMATIC = BuiltInClipboardFormat.MCEDIT_SCHEMATIC;
|
||||||
private static final ClipboardFormat SCHEM = ClipboardFormats.findByAlias("schem");
|
private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
|
||||||
|
|
||||||
static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException {
|
static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException {
|
||||||
ClipboardHolder clipboardHolder;
|
ClipboardHolder clipboardHolder;
|
||||||
@ -35,10 +36,10 @@ class Schematic_14 {
|
|||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
try{
|
try{
|
||||||
if(schemFormat){
|
if(schemFormat){
|
||||||
assert SCHEM != null;
|
ClipboardWriter writer = SCHEM.getWriter(outputStream);
|
||||||
SCHEM.getWriter(outputStream).write(clipboard);
|
writer.write(clipboard);
|
||||||
|
writer.close();
|
||||||
}else{
|
}else{
|
||||||
assert SCHEMATIC != null;
|
|
||||||
SCHEMATIC.getWriter(outputStream).write(clipboard);
|
SCHEMATIC.getWriter(outputStream).write(clipboard);
|
||||||
}
|
}
|
||||||
}catch(NullPointerException e){
|
}catch(NullPointerException e){
|
||||||
@ -60,10 +61,8 @@ class Schematic_14 {
|
|||||||
static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
|
static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
|
||||||
try {
|
try {
|
||||||
if(schemFormat){
|
if(schemFormat){
|
||||||
assert SCHEM != null;
|
|
||||||
return SCHEM.getReader(is).read();
|
return SCHEM.getReader(is).read();
|
||||||
}else{
|
}else{
|
||||||
assert SCHEMATIC != null;
|
|
||||||
return SCHEMATIC.getReader(is).read();
|
return SCHEMATIC.getReader(is).read();
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
|
@ -36,6 +36,8 @@ public class Core extends JavaPlugin{
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||||
|
if(version >= 12)
|
||||||
|
ErrorLogger.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,6 +52,7 @@ public class Core extends JavaPlugin{
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void setInstance(Core instance) {
|
private static void setInstance(Core instance) {
|
||||||
Core.instance = 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;
|
return;
|
||||||
|
|
||||||
e.setCancelled(true);
|
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());
|
callbacks.get(e.getRawSlot()).clicked(e.getClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package de.steamwar.inventory;
|
|||||||
|
|
||||||
import de.steamwar.sql.Schematic;
|
import de.steamwar.sql.Schematic;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import javafx.util.Pair;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -16,17 +15,6 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
private List<SWListEntry<T>> elements;
|
private List<SWListEntry<T>> elements;
|
||||||
private int page;
|
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){
|
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);
|
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
|
||||||
callback = c;
|
callback = c;
|
||||||
@ -79,18 +67,6 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
void clicked(ClickType click, T element);
|
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){
|
public static List<SWListEntry<UUID>> createPlayerList(UUID without){
|
||||||
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
|
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
|
||||||
for(Player player : Bukkit.getOnlinePlayers()){
|
for(Player player : Bukkit.getOnlinePlayers()){
|
||||||
@ -102,28 +78,6 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
return onlinePlayers;
|
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){
|
public static List<SWListEntry<Schematic>> getSchemList(SchematicType type, int steamwarUserId){
|
||||||
List<SWListEntry<Schematic>> schemList = new ArrayList<>();
|
List<SWListEntry<Schematic>> schemList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -41,37 +41,35 @@ public class SWScoreboard {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean removeScoreboard(Player player) {
|
public static void removeScoreboard(Player player) {
|
||||||
if(!playerBoards.containsKey(player))
|
if(!playerBoards.containsKey(player))
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
playerBoards.remove(player);
|
try{
|
||||||
if(player == null)
|
switch (Core.getVersion()) {
|
||||||
return true;
|
case 8:
|
||||||
|
((SWScoreboard_8) playerBoards.get(player)).deleteScoreboard(player);
|
||||||
switch (Core.getVersion()) {
|
break;
|
||||||
case 8:
|
case 9:
|
||||||
((SWScoreboard_8) playerBoards.get(player)).deleteScoreboard(player);
|
((SWScoreboard_9) playerBoards.get(player)).deleteScoreboard(player);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 10:
|
||||||
((SWScoreboard_9) playerBoards.get(player)).deleteScoreboard(player);
|
((SWScoreboard_10) playerBoards.get(player)).deleteScoreboard(player);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 12:
|
||||||
((SWScoreboard_10) playerBoards.get(player)).deleteScoreboard(player);
|
((SWScoreboard_12) playerBoards.get(player)).deleteScoreboard(player);
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 14:
|
||||||
((SWScoreboard_12) playerBoards.get(player)).deleteScoreboard(player);
|
((SWScoreboard_14) playerBoards.get(player)).deleteScoreboard(player);
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 15:
|
||||||
((SWScoreboard_14) playerBoards.get(player)).deleteScoreboard(player);
|
((SWScoreboard_15) playerBoards.get(player)).deleteScoreboard(player);
|
||||||
break;
|
break;
|
||||||
case 15:
|
}
|
||||||
((SWScoreboard_15) playerBoards.get(player)).deleteScoreboard(player);
|
}catch(NullPointerException e){
|
||||||
break;
|
//ignored
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
playerBoards.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Scoreboard Updater
|
//Scoreboard Updater
|
||||||
|
@ -36,17 +36,13 @@ public class BauweltMember{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(){
|
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);
|
members.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB(){
|
private void updateDB(){
|
||||||
SQL.update("INSERT INTO BauweltMember" +
|
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)" +
|
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)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
||||||
@ -57,7 +53,7 @@ public class BauweltMember{
|
|||||||
for(BauweltMember member : members)
|
for(BauweltMember member : members)
|
||||||
if(member.memberID == memberID)
|
if(member.memberID == memberID)
|
||||||
return member;
|
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 {
|
try {
|
||||||
if(member == null || !member.next()){
|
if(member == null || !member.next()){
|
||||||
return null;
|
return null;
|
||||||
@ -77,7 +73,7 @@ public class BauweltMember{
|
|||||||
|
|
||||||
public static List<BauweltMember> getMembers(int bauweltID){
|
public static List<BauweltMember> getMembers(int bauweltID){
|
||||||
try{
|
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<>();
|
List<BauweltMember> members = new LinkedList<>();
|
||||||
while(memberlist.next()){
|
while(memberlist.next()){
|
||||||
int memberID = memberlist.getInt("MemberID");
|
int memberID = memberlist.getInt("MemberID");
|
||||||
|
@ -21,12 +21,12 @@ public class CheckedSchematic {
|
|||||||
private final String declineReason;
|
private final String declineReason;
|
||||||
|
|
||||||
private CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason, boolean insertDB){
|
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.schemOwner = schemOwner;
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
this.declineReason = SQL.disarmString(declineReason);
|
this.declineReason = declineReason;
|
||||||
if(insertDB)
|
if(insertDB)
|
||||||
insertDB();
|
insertDB();
|
||||||
}
|
}
|
||||||
@ -41,9 +41,8 @@ public class CheckedSchematic {
|
|||||||
|
|
||||||
private void insertDB(){
|
private void insertDB(){
|
||||||
SQL.update("INSERT INTO CheckedSchematic" +
|
SQL.update("INSERT INTO CheckedSchematic" +
|
||||||
" (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason)" +
|
" (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
" VALUES" +
|
schemName, schemOwner, validator, startTime, endTime, declineReason);
|
||||||
" ('"+ schemName + "', '" + schemOwner + "', '" + validator + "', '" + startTime.toString() + "', '" + endTime.toString() + "', '" + declineReason + "')");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CheckedSchematic> getLastDeclined(UUID schemOwner){
|
public static List<CheckedSchematic> getLastDeclined(UUID schemOwner){
|
||||||
@ -53,7 +52,7 @@ public class CheckedSchematic {
|
|||||||
public static List<CheckedSchematic> getLastDelined(int schemOwner){
|
public static List<CheckedSchematic> getLastDelined(int schemOwner){
|
||||||
List<CheckedSchematic> lastDeclined = new LinkedList<>();
|
List<CheckedSchematic> lastDeclined = new LinkedList<>();
|
||||||
try{
|
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()){
|
while(lastRS.next()){
|
||||||
String schemName = lastRS.getString("SchemName");
|
String schemName = lastRS.getString("SchemName");
|
||||||
int validator = lastRS.getInt("Validator");
|
int validator = lastRS.getInt("Validator");
|
||||||
@ -69,7 +68,7 @@ public class CheckedSchematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
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() {
|
public String getSchemName() {
|
||||||
|
@ -13,7 +13,7 @@ public class DownloadSchematic {
|
|||||||
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
private static final String BASE = "https://steamwar.de/download.php?schem=";
|
||||||
|
|
||||||
public static String getLink(Schematic 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 {
|
try {
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
return BASE + rs.getString("Link");
|
return BASE + rs.getString("Link");
|
||||||
@ -30,7 +30,7 @@ public class DownloadSchematic {
|
|||||||
cript.reset();
|
cript.reset();
|
||||||
cript.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes());
|
cript.update((Instant.now().toString() + schem.getSchemOwner() + schem.getSchemID()).getBytes());
|
||||||
String hash = DatatypeConverter.printHexBinary(cript.digest());
|
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;
|
return BASE + hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,22 +16,22 @@ public class Event {
|
|||||||
private final int maximumTeamMembers;
|
private final int maximumTeamMembers;
|
||||||
private final boolean publicSchemsOnly;
|
private final boolean publicSchemsOnly;
|
||||||
|
|
||||||
private Event(int eventID, String eventName, Timestamp start, Timestamp end, int maximumTeamMembers, boolean publicSchemsOnly){
|
private Event(ResultSet rs) throws SQLException{
|
||||||
this.eventID = eventID;
|
this.eventID = rs.getInt("EventID");
|
||||||
this.eventName = eventName;
|
this.eventName = rs.getString("EventName");
|
||||||
this.start = start;
|
this.start = rs.getTimestamp("Start");
|
||||||
this.end = end;
|
this.end = rs.getTimestamp("End");
|
||||||
this.maximumTeamMembers = maximumTeamMembers;
|
this.maximumTeamMembers = rs.getInt("MaximumTeamMembers");
|
||||||
this.publicSchemsOnly = publicSchemsOnly;
|
this.publicSchemsOnly = rs.getBoolean("PublicSchemsOnly");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event get(int eventID){
|
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{
|
try{
|
||||||
if(!rs.next())
|
if(!rs.next())
|
||||||
throw new IllegalArgumentException();
|
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){
|
}catch (SQLException e){
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Event", e);
|
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Event", e);
|
||||||
throw new SecurityException();
|
throw new SecurityException();
|
||||||
|
@ -14,26 +14,20 @@ public class EventFight {
|
|||||||
private int kampfleiter;
|
private int kampfleiter;
|
||||||
private int ergebnis;
|
private int ergebnis;
|
||||||
|
|
||||||
private EventFight(int eventID, int fightID, int teamBlue, int teamRed, int kampfleiter, int ergebnis){
|
private EventFight(ResultSet rs) throws SQLException{
|
||||||
this.eventID = eventID;
|
this.eventID = rs.getInt("EventID");
|
||||||
this.fightID = fightID;
|
this.fightID = rs.getInt("FightID");
|
||||||
this.teamBlue = teamBlue;
|
this.teamBlue = rs.getInt("TeamBlue");
|
||||||
this.teamRed = teamRed;
|
this.teamRed = rs.getInt("TeamRed");
|
||||||
this.kampfleiter = kampfleiter;
|
this.kampfleiter = rs.getInt("Kampfleiter");
|
||||||
this.ergebnis = ergebnis;
|
this.ergebnis = rs.getInt("Ergebnis");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EventFight get(int fightID){
|
public static EventFight get(int fightID){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE FightID = " + fightID);
|
ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE FightID = " + fightID);
|
||||||
try{
|
try{
|
||||||
rs.next();
|
rs.next();
|
||||||
return new EventFight(
|
return new EventFight(rs);
|
||||||
rs.getInt("EventID"),
|
|
||||||
fightID,
|
|
||||||
rs.getInt("TeamBlue"),
|
|
||||||
rs.getInt("TeamRed"),
|
|
||||||
rs.getInt("Kampfleiter"),
|
|
||||||
rs.getInt("Ergebnis"));
|
|
||||||
}catch (SQLException e){
|
}catch (SQLException e){
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight", e);
|
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight", e);
|
||||||
}
|
}
|
||||||
@ -41,7 +35,7 @@ public class EventFight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setErgebnis(int winner){
|
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() {
|
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();
|
connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Integer booleanToInt(boolean b){
|
|
||||||
if(b)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeConnection() {
|
public static void closeConnection() {
|
||||||
try {
|
try {
|
||||||
con.close();
|
con.close();
|
||||||
@ -49,44 +42,52 @@ public class SQL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Connection getCon(){
|
static void update(String qry, Object... objects) {
|
||||||
return con;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update(String qry) {
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement st = con.prepareStatement(qry);
|
prepare(qry, objects).executeUpdate();
|
||||||
st.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
reconnect();
|
reconnect();
|
||||||
try {
|
try {
|
||||||
PreparedStatement st = con.prepareStatement(qry);
|
prepare(qry, objects).executeUpdate();
|
||||||
st.executeUpdate();
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new SecurityException("Could not perform update", ex);
|
throw new SecurityException("Could not perform update", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ResultSet select(String qry) {
|
static ResultSet select(String qry, Object... objects){
|
||||||
try {
|
try {
|
||||||
PreparedStatement st = con.prepareStatement(qry);
|
return prepare(qry, objects).executeQuery();
|
||||||
return st.executeQuery();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
reconnect();
|
reconnect();
|
||||||
try {
|
try {
|
||||||
PreparedStatement st = con.prepareStatement(qry);
|
return prepare(qry, objects).executeQuery();
|
||||||
return st.executeQuery();
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new SecurityException("Could not perform select", ex);
|
throw new SecurityException("Could not perform select", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String disarmString(String s){
|
static Blob blob(){
|
||||||
return s.replace("'", "");
|
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() {
|
private static void connect() {
|
||||||
try {
|
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 de.steamwar.core.Core;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Blob;
|
import java.sql.Blob;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -42,12 +40,8 @@ public class Schematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void createSchem(String schemName, int schemOwner, String item, SchematicType schemType){
|
public static void createSchem(String schemName, int schemOwner, String item, SchematicType schemType){
|
||||||
SQL.update("INSERT INTO Schematic" +
|
SQL.update("INSERT INTO Schematic (SchemName, SchemOwner, Item, SchemType) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), SchemType = VALUES(SchemType)",
|
||||||
" (SchemName, SchemOwner, Item, SchemType)" +
|
schemName, schemOwner, item, schemType.toDB());
|
||||||
" VALUES" +
|
|
||||||
" ('" + schemName + "', '" + schemOwner + "', '" + item + "', '" + schemType.toDB() + "')" +
|
|
||||||
" ON DUPLICATE KEY UPDATE" +
|
|
||||||
" Item = VALUES(Item), SchemType = VALUES(SchemType)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){
|
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){
|
||||||
@ -55,8 +49,7 @@ public class Schematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Schematic getSchemFromDB(String schemName, int schemOwner){
|
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 = ? AND SchemOwner = ?", schemName, schemOwner);
|
||||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, SchemFormat FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
|
|
||||||
try {
|
try {
|
||||||
if(schematic == null || !schematic.next()){
|
if(schematic == null || !schematic.next()){
|
||||||
SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner);
|
SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner);
|
||||||
@ -77,7 +70,7 @@ public class Schematic {
|
|||||||
|
|
||||||
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
||||||
try{
|
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<>();
|
List<Schematic> schematics = new ArrayList<>();
|
||||||
while(schematic.next()){
|
while(schematic.next()){
|
||||||
schematics.add(new Schematic(schematic));
|
schematics.add(new Schematic(schematic));
|
||||||
@ -107,7 +100,7 @@ public class Schematic {
|
|||||||
|
|
||||||
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
||||||
try{
|
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<>();
|
List<Schematic> schematics = new ArrayList<>();
|
||||||
while(schematic.next()){
|
while(schematic.next()){
|
||||||
schematics.add(new Schematic(schematic));
|
schematics.add(new Schematic(schematic));
|
||||||
@ -153,7 +146,7 @@ public class Schematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Clipboard load() throws IOException, NoClipboardException {
|
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 {
|
try {
|
||||||
rs.next();
|
rs.next();
|
||||||
Blob schemData = rs.getBlob("SchemData");
|
Blob schemData = rs.getBlob("SchemData");
|
||||||
@ -181,10 +174,13 @@ public class Schematic {
|
|||||||
|
|
||||||
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
|
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 {
|
try {
|
||||||
rs.next();
|
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()){
|
switch(Core.getVersion()){
|
||||||
case 8:
|
case 8:
|
||||||
Schematic_8.setPlayerClipboard(player, is, schemFormat);
|
Schematic_8.setPlayerClipboard(player, is, schemFormat);
|
||||||
@ -219,34 +215,31 @@ public class Schematic {
|
|||||||
|
|
||||||
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
|
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
|
||||||
try{
|
try{
|
||||||
PreparedStatement st = SQL.getCon().prepareStatement("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = " + schemID);
|
Blob blob = SQL.blob();
|
||||||
byte[] data;
|
|
||||||
switch(Core.getVersion()){
|
switch(Core.getVersion()){
|
||||||
case 8:
|
case 8:
|
||||||
newFormat = false;
|
newFormat = false;
|
||||||
data = Schematic_8.getPlayerClipboard(player);
|
blob.setBytes(1, Schematic_8.getPlayerClipboard(player));
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
newFormat = false;
|
newFormat = false;
|
||||||
data = Schematic_9.getPlayerClipboard(player);
|
blob.setBytes(1, Schematic_9.getPlayerClipboard(player));
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
newFormat = false;
|
newFormat = false;
|
||||||
data = Schematic_10.getPlayerClipboard(player);
|
blob.setBytes(1, Schematic_10.getPlayerClipboard(player));
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
data = Schematic_14.getPlayerClipboard(player, newFormat);
|
blob.setBytes(1, Schematic_14.getPlayerClipboard(player, newFormat));
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
data = Schematic_15.getPlayerClipboard(player, newFormat);
|
blob.setBytes(1, Schematic_15.getPlayerClipboard(player, newFormat));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
newFormat = false;
|
newFormat = false;
|
||||||
data = Schematic_12.getPlayerClipboard(player);
|
blob.setBytes(1, Schematic_12.getPlayerClipboard(player));
|
||||||
}
|
}
|
||||||
st.setBlob(1, new ByteArrayInputStream(data));
|
SQL.update("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = ?", blob, newFormat, schemID);
|
||||||
st.setBoolean(2, newFormat);
|
|
||||||
st.executeUpdate();
|
|
||||||
schemFormat = newFormat;
|
schemFormat = newFormat;
|
||||||
}catch(SQLException e){
|
}catch(SQLException e){
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
@ -254,8 +247,8 @@ public class Schematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(){
|
public void remove(){
|
||||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
|
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ?", schemOwner, schemName);
|
||||||
SQL.update("DELETE FROM Schematic WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
|
SQL.update("DELETE FROM Schematic WHERE SchemOwner = ? AND SchemName = ?", schemOwner, schemName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class WrongVersionException extends Exception{}
|
public static class WrongVersionException extends Exception{}
|
||||||
|
@ -28,10 +28,7 @@ public class SchematicMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB(){
|
private void updateDB(){
|
||||||
SQL.update("INSERT INTO SchemMember" +
|
SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member);
|
||||||
" (SchemName, SchemOwner, Member)" +
|
|
||||||
" VALUES" +
|
|
||||||
" ('" + schemName + "', '" + schemOwner + "', '" + member + "')");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
|
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){
|
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 {
|
try {
|
||||||
if(schematicMember == null || !schematicMember.next()){
|
if(schematicMember == null || !schematicMember.next()){
|
||||||
return null;
|
return null;
|
||||||
@ -51,7 +48,7 @@ public class SchematicMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
|
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 {
|
try {
|
||||||
if(schematicMember == null || !schematicMember.next()){
|
if(schematicMember == null || !schematicMember.next()){
|
||||||
return null;
|
return null;
|
||||||
@ -68,7 +65,7 @@ public class SchematicMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
|
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 {
|
try {
|
||||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
List<SchematicMember> schematicMembers = new ArrayList<>();
|
||||||
while(schematicMember.next()){
|
while(schematicMember.next()){
|
||||||
@ -86,7 +83,7 @@ public class SchematicMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicMember> getAccessibleSchems(int schemMember){
|
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 {
|
try {
|
||||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
List<SchematicMember> schematicMembers = new ArrayList<>();
|
||||||
while(schematicMember.next()){
|
while(schematicMember.next()){
|
||||||
@ -113,6 +110,6 @@ public class SchematicMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(){
|
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;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import de.steamwar.core.Core;
|
||||||
import java.util.Map;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
public enum SchematicType {
|
import java.io.File;
|
||||||
Normal("", Type.NORMAL),
|
import java.util.*;
|
||||||
|
|
||||||
CAirShip("CAS", Type.CHECK_TYPE),
|
public class SchematicType {
|
||||||
CWarGear("CWG", Type.CHECK_TYPE),
|
public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null); //Has to stay publicly availible
|
||||||
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),
|
|
||||||
|
|
||||||
CMPPWarGear1_12("CMPPWG", Type.CHECK_TYPE),
|
private static final Map<String, SchematicType> fromDB;
|
||||||
CSGWarShip("CSGWS", Type.CHECK_TYPE),
|
private static final List<SchematicType> types;
|
||||||
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<>();
|
|
||||||
|
|
||||||
static{
|
static{
|
||||||
for(SchematicType type : values()){
|
File file = new File(Core.getInstance().getDataFolder(), "SchematicTypes.yml");
|
||||||
fromDB.put(type.toDB(), type);
|
|
||||||
|
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 String kuerzel;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
private SchematicType checkType;
|
private SchematicType checkType;
|
||||||
|
|
||||||
SchematicType(String kuerzel, Type type){
|
private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){
|
||||||
this(kuerzel, type, null);
|
this.name = name;
|
||||||
}
|
|
||||||
|
|
||||||
SchematicType(String kuerzel, Type type, SchematicType checkType){
|
|
||||||
this.kuerzel = kuerzel;
|
this.kuerzel = kuerzel;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.checkType = checkType;
|
this.checkType = checkType;
|
||||||
@ -76,16 +72,24 @@ public enum SchematicType {
|
|||||||
return type == Type.NORMAL;
|
return type == Type.NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String name(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public String getKuerzel() {
|
public String getKuerzel() {
|
||||||
return kuerzel;
|
return kuerzel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toDB(){
|
public String toDB(){
|
||||||
return name().toLowerCase();
|
return name.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicType fromDB(String input){
|
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{
|
enum Type{
|
||||||
|
@ -63,8 +63,8 @@ public class SteamwarUser {
|
|||||||
return team;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SteamwarUser fromDB(String statement){
|
private static SteamwarUser fromDB(String statement, Object identifier){
|
||||||
ResultSet rs = SQL.select(statement);
|
ResultSet rs = SQL.select(statement, identifier);
|
||||||
try {
|
try {
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
return new SteamwarUser(rs);
|
return new SteamwarUser(rs);
|
||||||
@ -75,24 +75,23 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(String userName){
|
public static SteamwarUser get(String userName){
|
||||||
userName = SQL.disarmString(userName);
|
|
||||||
SteamwarUser user = byName.get(userName.toLowerCase());
|
SteamwarUser user = byName.get(userName.toLowerCase());
|
||||||
if(user == null)
|
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;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(UUID uuid){
|
public static SteamwarUser get(UUID uuid){
|
||||||
SteamwarUser user = byUUID.get(uuid);
|
SteamwarUser user = byUUID.get(uuid);
|
||||||
if(user == null)
|
if(user == null)
|
||||||
user = fromDB("SELECT * FROM UserData WHERE UUID = '" + uuid.toString() + "'");
|
user = fromDB("SELECT * FROM UserData WHERE UUID = ?", uuid.toString());
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(int id) {
|
public static SteamwarUser get(int id) {
|
||||||
SteamwarUser user = byId.get(id);
|
SteamwarUser user = byId.get(id);
|
||||||
if(user == null)
|
if(user == null)
|
||||||
user = fromDB("SELECT * FROM UserData WHERE id = '" + id + "'");
|
user = fromDB("SELECT * FROM UserData WHERE id = ?", id);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class Team {
|
|||||||
public static Team get(int id){
|
public static Team get(int id){
|
||||||
if(id == 0)
|
if(id == 0)
|
||||||
return pub;
|
return pub;
|
||||||
ResultSet rs = SQL.select("SELECT * FROM Team WHERE TeamID = " + id);
|
ResultSet rs = SQL.select("SELECT * FROM Team WHERE TeamID = ?", id);
|
||||||
try {
|
try {
|
||||||
if(!rs.next())
|
if(!rs.next())
|
||||||
return null;
|
return null;
|
||||||
@ -55,7 +55,7 @@ public class Team {
|
|||||||
|
|
||||||
public List<Integer> getMembers(){
|
public List<Integer> getMembers(){
|
||||||
try{
|
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<>();
|
List<Integer> members = new LinkedList<>();
|
||||||
while(memberlist.next())
|
while(memberlist.next())
|
||||||
members.add(memberlist.getInt("id"));
|
members.add(memberlist.getInt("id"));
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren