SteamWar/SpigotCore
Archiviert
13
0

Full Core MySQL API

Dieser Commit ist enthalten in:
Lixfel 2019-03-19 19:48:39 +01:00
Ursprung 95ebca1681
Commit 52f56e55dc
7 geänderte Dateien mit 397 neuen und 41 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,84 @@
package de.warking.hunjy.MySQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import static de.warking.hunjy.Core.sql;
public class Bauwelt {
private final int UserID;
private boolean TNTDmg;
private boolean FireDmg;
private Bauwelt(int userID, boolean tntDmg, boolean fireDmg, boolean updateDB){
UserID = userID;
TNTDmg = tntDmg;
FireDmg = fireDmg;
if(updateDB)
updateDB();
}
public Bauwelt(int userID, boolean tntDmg, boolean fireDmg){
this(userID, tntDmg, fireDmg, true);
}
public Bauwelt(UUID userID, boolean tntDmg, boolean fireDmg){
this(WarkingUser.get(userID).getId(), tntDmg, fireDmg, true);
}
private void updateDB(){
sql.update("INSERT INTO Bauwelt" +
" (UserID, TNTDmg, FireDmg)" +
" VALUES" +
" ('" + UserID + "', '" + TNTDmg + "', '" + FireDmg + "')" +
" ON DUPLICATE KEY UPDATE" +
" TNTDmg = VALUES(TNTDmg), FireDmg = VALUES(FireDmg)");
}
public static Bauwelt getBauwelt(UUID user){
return getBauwelt(WarkingUser.get(user).getId());
}
public static Bauwelt getBauwelt(int userId){
ResultSet bauwelt = sql.select("SELECT * FROM Schematic WHERE UserID = '" + userId + "'");
try {
if(bauwelt == null || !bauwelt.next()){
return null;
}
boolean tntDmg = bauwelt.getBoolean("TNTDmg");
boolean fireDmg = bauwelt.getBoolean("FireDmg");
return new Bauwelt(userId, tntDmg, fireDmg, false);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public int getUserID() {
return UserID;
}
public UUID getUUID(){
return WarkingUser.get(UserID).getUUID();
}
public boolean isTNTDmg() {
return TNTDmg;
}
public void setTNTDmg(boolean TNTDmg) {
this.TNTDmg = TNTDmg;
updateDB();
}
public boolean isFireDmg() {
return FireDmg;
}
public void setFireDmg(boolean fireDmg) {
FireDmg = fireDmg;
updateDB();
}
}

Datei anzeigen

@ -0,0 +1,147 @@
package de.warking.hunjy.MySQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static de.warking.hunjy.Core.sql;
public class BauweltMember{
private final int BauweltID;
private final int MemberID;
private boolean Build;
private boolean ChangeGM;
private boolean Teleport;
private boolean WorldEdit;
private boolean Testblock;
private BauweltMember(int bauweltID, int memberID, boolean build, boolean changeGM, boolean teleport, boolean worldEdit, boolean testblock, boolean updateDB){
BauweltID = bauweltID;
MemberID = memberID;
Build = build;
ChangeGM = changeGM;
Teleport = teleport;
WorldEdit = worldEdit;
Testblock = testblock;
if(updateDB)
updateDB();
}
public BauweltMember(int bauweltID, int memberID, boolean build, boolean changeGM, boolean teleport, boolean worldEdit, boolean testblock){
this(bauweltID, memberID, build, changeGM, teleport, worldEdit, testblock, true);
}
public void remove(){
sql.update("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
}
private void updateDB(){
sql.update("INSERT INTO BauweltMember" +
" (BauweltID, MemberID, Build, ChangeGM, Teleport, WorldEdit, Testblock)" +
" VALUES" +
" ('" + BauweltID + "', '" + MemberID + "', '" + Build + "', '" + ChangeGM + "', '" + Teleport + "', '" + WorldEdit + "', '" + Testblock + "')" +
" ON DUPLICATE KEY UPDATE" +
" Build = VALUES(Build), ChangeGM = VALUES(ChangeGM), Teleport = VALUES(Teleport), WorldEdit = VALUES(WorldEdit), Testblock = VALUES(Testblock)");
}
public static BauweltMember getBauMember(UUID bauweltID, UUID memberID){
return getBauMember(WarkingUser.get(bauweltID).getId(), WarkingUser.get(memberID).getId());
}
public static BauweltMember getBauMember(int bauweltID, int memberID){
ResultSet member = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "' AND MemberID = '" + memberID + "'");
try {
if(member == null || !member.next()){
return null;
}
boolean build = member.getBoolean("Build");
boolean changeGM = member.getBoolean("ChangeGM");
boolean teleport = member.getBoolean("Teleport");
boolean worldEdit = member.getBoolean("WorldEdit");
boolean testblock = member.getBoolean("Testblock");
return new BauweltMember(bauweltID, memberID, build, changeGM, teleport, worldEdit, testblock, false);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static List<BauweltMember> getMembers(UUID bauweltID){
return getMembers(WarkingUser.get(bauweltID).getId());
}
public static List<BauweltMember> getMembers(int bauweltID){
try{
ResultSet memberlist = sql.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + bauweltID + "'");
List<BauweltMember> members = new ArrayList<>();
while(memberlist.next()){
int memberID = memberlist.getInt("MemberID");
boolean build = memberlist.getBoolean("Build");
boolean changeGM = memberlist.getBoolean("ChangeGM");
boolean teleport = memberlist.getBoolean("Teleport");
boolean worldEdit = memberlist.getBoolean("WorldEdit");
boolean testblock = memberlist.getBoolean("Testblock");
members.add(new BauweltMember(bauweltID, memberID, build, changeGM, teleport, worldEdit, testblock, false));
}
return members;
}catch(SQLException e){
e.printStackTrace();
}
return null;
}
public int getBauweltID() {
return BauweltID;
}
public int getMemberID() {
return MemberID;
}
public boolean isBuild() {
return Build;
}
public void setBuild(boolean build) {
Build = build;
updateDB();
}
public boolean isChangeGM() {
return ChangeGM;
}
public void setChangeGM(boolean changeGM) {
ChangeGM = changeGM;
updateDB();
}
public boolean isTeleport() {
return Teleport;
}
public void setTeleport(boolean teleport) {
Teleport = teleport;
updateDB();
}
public boolean isWorldEdit() {
return WorldEdit;
}
public void setWorldEdit(boolean worldEdit) {
WorldEdit = worldEdit;
updateDB();
}
public boolean isTestblock() {
return Testblock;
}
public void setTestblock(boolean testblock) {
Testblock = testblock;
updateDB();
}
}

Datei anzeigen

@ -10,8 +10,8 @@ import static de.warking.hunjy.Core.sql;
public class Schematic { public class Schematic {
private String SchemName; private final String SchemName;
private int SchemOwner; private final int SchemOwner;
private String Item; private String Item;
private SchematicType SchemType; private SchematicType SchemType;
@ -46,13 +46,12 @@ public class Schematic {
} }
public static Schematic getSchemFromDB(String schemName, int schemOwner){ public static Schematic getSchemFromDB(String schemName, int schemOwner){
ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemName = '" + schemName + "', SchemOwner = '" + schemOwner + "'"); ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
try { try {
if(schematic == null || !schematic.next()){ if(schematic == null || !schematic.next()){
System.err.println("Fatal ERROR: Could not load schematic!");
return null; return null;
} }
String item = schematic.getString("Item");; String item = schematic.getString("Item");
SchematicType schemType = SchematicType.valueOf(schematic.getString("SchemType")); SchematicType schemType = SchematicType.valueOf(schematic.getString("SchemType"));
return new Schematic(schemName, schemOwner, item, schemType, false); return new Schematic(schemName, schemOwner, item, schemType, false);
} catch (SQLException e) { } catch (SQLException e) {
@ -75,6 +74,10 @@ public class Schematic {
SchematicType schemType = SchematicType.valueOf(schematic.getString("SchemType")); SchematicType schemType = SchematicType.valueOf(schematic.getString("SchemType"));
schematics.add(new Schematic(schemName, schemOwner, item, schemType, false)); schematics.add(new Schematic(schemName, schemOwner, item, schemType, false));
} }
List<SchematicMember> addedSchems = SchematicMember.getAccessibleSchems(schemOwner);
for(SchematicMember schem : addedSchems){
schematics.add(getSchemFromDB(schem.getSchemName(), schem.getSchemOwner()));
}
return schematics; return schematics;
}catch(SQLException e){ }catch(SQLException e){
e.printStackTrace(); e.printStackTrace();
@ -106,20 +109,10 @@ public class Schematic {
return SchemName; return SchemName;
} }
public void setSchemName(String schemName) {
SchemName = schemName;
updateDB();
}
public int getSchemOwner() { public int getSchemOwner() {
return SchemOwner; return SchemOwner;
} }
public void setSchemOwner(int schemOwner) {
SchemOwner = schemOwner;
updateDB();
}
public String getItem() { public String getItem() {
return Item; return Item;
} }

Datei anzeigen

@ -1,7 +1,106 @@
package de.warking.hunjy.MySQL; package de.warking.hunjy.MySQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static de.warking.hunjy.Core.sql;
public class SchematicMember { public class SchematicMember {
private int SchemOwner; private final int SchemOwner;
private String SchemName; private final String SchemName;
private int Member; private final int Member;
private SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDB){
SchemOwner = schemOwner;
Member = schemMember;
SchemName = schemName;
if(updateDB)
updateDB();
}
public SchematicMember(String schemName, int schemOwner, int schemMember){
this(schemName, schemOwner, schemMember, true);
}
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){
this(schemName, WarkingUser.get(schemOwner).getId(), WarkingUser.get(schemMember).getId(), true);
}
private void updateDB(){
sql.update("INSERT INTO SchemMember" +
" (SchemName, SchemOwner, Member)" +
" VALUES" +
" ('" + SchemName + "', '" + SchemOwner + "', '" + Member + "')");
}
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
return getSchemMemberFromDB(schemName, WarkingUser.get(schemOwner).getId(), WarkingUser.get(schemMember).getId());
}
public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember){
ResultSet schematicMember = sql.select("SELECT * FROM SchematicMember WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "' AND Member = '" + schemMember + "'");
try {
if(schematicMember == null || !schematicMember.next()){
return null;
}
return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){
return getSchemMembers(schemName, WarkingUser.get(schemOwner).getId());
}
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
ResultSet schematicMember = sql.select("SELECT * FROM SchematicMember WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
try {
List<SchematicMember> schematicMembers = new ArrayList<>();
while(schematicMember.next()){
int schemMember = schematicMember.getInt("Member");
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
}
return schematicMembers;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
return getAccessibleSchems(WarkingUser.get(schemMember).getId());
}
public static List<SchematicMember> getAccessibleSchems(int schemMember){
ResultSet schematicMember = sql.select("SELECT * FROM SchematicMember WHERE Member = '" + schemMember + "'");
try {
List<SchematicMember> schematicMembers = new ArrayList<>();
while(schematicMember.next()){
String schemName = schematicMember.getString("SchemName");
int schemOwner = schematicMember.getInt("SchemOwner");
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
}
return schematicMembers;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public int getSchemOwner() {
return SchemOwner;
}
public String getSchemName() {
return SchemName;
}
public int getMember() {
return Member;
}
} }

Datei anzeigen

@ -0,0 +1,12 @@
package de.warking.hunjy.MySQL;
public enum UserGroup {
Admin,
Developer,
Moderator,
Supporter,
Builder,
Youtuber,
Premium,
Member
}

Datei anzeigen

@ -17,23 +17,30 @@ public class WarkingUser {
private int id; private int id;
private UUID UUID; private UUID UUID;
private String UserName; private String UserName;
private String UserGroup; private UserGroup UserGroup;
public WarkingUser(Player player){ public WarkingUser(UUID uuid){
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + player.getUniqueId().toString() + "'"); ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + uuid.toString() + "'");
init(dbplayer);
}
public WarkingUser(int id){
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE id = '" + id + "'");
init(dbplayer);
}
public WarkingUser(String name){
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UserName = '" + name + "'");
init(dbplayer); init(dbplayer);
} }
private void init(ResultSet dbplayer){ private void init(ResultSet dbplayer){
try { try {
if(dbplayer == null || !dbplayer.next()){ dbplayer.next();
System.err.println("Fatal ERROR: Could not load player!");
return;
}
id = dbplayer.getInt("id"); id = dbplayer.getInt("id");
this.UUID = java.util.UUID.fromString(dbplayer.getString("UUID")); this.UUID = java.util.UUID.fromString(dbplayer.getString("UUID"));
UserName = dbplayer.getString("UserName"); UserName = dbplayer.getString("UserName");
UserGroup = dbplayer.getString("UserGroup"); UserGroup = de.warking.hunjy.MySQL.UserGroup.valueOf(dbplayer.getString("UserGroup"));
allUsers.add(this); allUsers.add(this);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -52,27 +59,40 @@ public class WarkingUser {
return UserName; return UserName;
} }
public String getUserGroup() { public UserGroup getUserGroup() {
return UserGroup; return UserGroup;
} }
public static WarkingUser get(String userName){ public static WarkingUser get(String userName){
for(WarkingUser user : allUsers) for(WarkingUser user : allUsers)
if(user.getUserName().equals(userName)) if(user.UserName.equals(userName))
return user; return user;
return null; WarkingUser offline = new WarkingUser(userName);
allUsers.remove(offline);
return offline;
} }
public static WarkingUser get(UUID uuid){ public static WarkingUser get(UUID uuid){
for(WarkingUser user : allUsers) for(WarkingUser user : allUsers)
if(user.getUserName().equals(uuid)) if(user.UserName.equals(uuid))
return user; return user;
return null; WarkingUser offline = new WarkingUser(uuid);
allUsers.remove(offline);
return offline;
}
public static WarkingUser get(int id){
for(WarkingUser user : allUsers)
if(user.id == id)
return user;
WarkingUser offline = new WarkingUser(id);
allUsers.remove(offline);
return offline;
} }
public static void remove(Player player){ public static void remove(Player player){
for(int i = 0; i < allUsers.size(); i++) for(int i = 0; i < allUsers.size(); i++)
if(allUsers.get(i).getUUID().equals(player.getUniqueId())){ if(allUsers.get(i).UUID.equals(player.getUniqueId())){
allUsers.remove(i); allUsers.remove(i);
return; return;
} }

Datei anzeigen

@ -1,5 +1,6 @@
package de.warking.hunjy.PlayerManager.events; package de.warking.hunjy.PlayerManager.events;
import de.warking.hunjy.MySQL.UserGroup;
import de.warking.hunjy.MySQL.WarkingUser; import de.warking.hunjy.MySQL.WarkingUser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -13,31 +14,31 @@ public class PlayerJoin implements Listener{
@EventHandler @EventHandler
private void onJoin(PlayerJoinEvent event) { private void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
WarkingUser user = new WarkingUser(player); WarkingUser user = new WarkingUser(player.getUniqueId());
switch(user.getUserGroup()){ switch(user.getUserGroup()){
case "Admin": case Admin:
player.setDisplayName("§4Admin " + player.getName() + "§r"); player.setDisplayName("§4Admin " + player.getName() + "§r");
break; break;
case "Developer": case Developer:
player.setDisplayName("§3Developer " + player.getName() + "§r"); player.setDisplayName("§3Developer " + player.getName() + "§r");
break; break;
case "Moderator": case Moderator:
player.setDisplayName("§bModerator " + player.getName() + "§r"); player.setDisplayName("§bModerator " + player.getName() + "§r");
break; break;
case "Supporter": case Supporter:
player.setDisplayName("§1Supporter " + player.getName() + "§r"); player.setDisplayName("§1Supporter " + player.getName() + "§r");
break; break;
case "Builder": case Builder:
player.setDisplayName("§2Architekt " + player.getName() + "§r"); player.setDisplayName("§2Architekt " + player.getName() + "§r");
break; break;
case "Youtuber": case Youtuber:
player.setDisplayName("§5Youtuber " + player.getName() + "§r"); player.setDisplayName("§5Youtuber " + player.getName() + "§r");
break; break;
case "Premium": case Premium:
player.setDisplayName("§6Premium " + player.getName() + "§r"); player.setDisplayName("§6Premium " + player.getName() + "§r");
break; break;
case "Member": case Member:
default: default:
player.setDisplayName("§7" + player.getName() + "§r"); player.setDisplayName("§7" + player.getName() + "§r");
break; break;