First step towards multiversion-support + refactor
Dieser Commit ist enthalten in:
Ursprung
4c56ed3da8
Commit
3e31762fe6
14
pom.xml
14
pom.xml
@ -4,7 +4,7 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.warking</groupId>
|
||||
<groupId>de.steamwar</groupId>
|
||||
<artifactId>SpigotCore</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
@ -17,7 +17,7 @@
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>steamwar</id>
|
||||
<url>https://steamwar.de/maven/</url>
|
||||
<url>https://steamwar.de:81/maven/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@ -48,9 +48,17 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>Spigot</artifactId>
|
||||
<artifactId>Spigot-1.12</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>Spigot-1.14</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
40
src/de/steamwar/core/CommandRemover.java
Normale Datei
40
src/de/steamwar/core/CommandRemover.java
Normale Datei
@ -0,0 +1,40 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CommandRemover {
|
||||
private CommandRemover(){}
|
||||
|
||||
private static String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private static String version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
|
||||
public static void removeAll(String... cmds){
|
||||
for (String cmd : cmds) removeCommand(cmd);
|
||||
}
|
||||
|
||||
|
||||
private static void removeCommand(String command) {
|
||||
try {
|
||||
Class<?> serverClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer");
|
||||
|
||||
|
||||
Field f1 = serverClass.getDeclaredField("commandMap");
|
||||
f1.setAccessible(true);
|
||||
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
|
||||
|
||||
Field f2 = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
f2.setAccessible(true);
|
||||
Map<String, Command> knownCommands = (Map<String, Command>) f2.get(commandMap);
|
||||
|
||||
knownCommands.remove(command.toLowerCase());
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not remove command", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +1,28 @@
|
||||
package de.warking.hunjy;
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.warking.hunjy.MySQL.MySQL;
|
||||
import de.warking.hunjy.MySQL.WarkingUser;
|
||||
import de.steamwar.core.FileManager;
|
||||
import de.steamwar.sql.SQL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public class Core extends JavaPlugin{
|
||||
|
||||
public static MySQL sql;
|
||||
|
||||
private static Core instance;
|
||||
private FileManager fileManager;
|
||||
|
||||
private static final int version;
|
||||
|
||||
static{
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
if(packageName.contains("1_14"))
|
||||
version = 14;
|
||||
else if(packageName.contains("1_10"))
|
||||
version = 10;
|
||||
else if(packageName.contains("1_9"))
|
||||
version = 9;
|
||||
else
|
||||
version = 12;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
setInstance(this);
|
||||
@ -23,26 +30,23 @@ public class Core extends JavaPlugin{
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
fileManager = new FileManager();
|
||||
|
||||
setSql(new MySQL());
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, WarkingUser::clearCache, 72000, 72000);
|
||||
@Override
|
||||
public void onDisable(){
|
||||
SQL.closeConnection();
|
||||
}
|
||||
|
||||
public static Core getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public FileManager getFileManager() {
|
||||
return fileManager;
|
||||
public static int getVersion(){
|
||||
return version;
|
||||
}
|
||||
|
||||
private static void setInstance(Core instance) {
|
||||
Core.instance = instance;
|
||||
}
|
||||
private static void setSql(MySQL sql) {
|
||||
Core.sql = sql;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class FileManager {
|
||||
|
||||
private File file;
|
||||
private YamlConfiguration config;
|
||||
|
||||
public FileManager() {
|
||||
file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
private void setDefaults() {
|
||||
if(!file.exists()) {
|
||||
config.set("HOST", "localhost");
|
||||
config.set("PORT", "3306");
|
||||
config.set("DATABASE", "coinsystem");
|
||||
config.set("USER", "root");
|
||||
config.set("PASSWORD", "");
|
||||
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save MySQL Config", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package de.steamwar.core.events;
|
||||
|
||||
import de.warking.hunjy.MySQL.WarkingUser;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -13,7 +13,7 @@ public class PlayerJoinedEvent implements Listener{
|
||||
@EventHandler
|
||||
private void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
WarkingUser user = new WarkingUser(player.getUniqueId());
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
switch(user.getUserGroup()){
|
||||
case Admin:
|
||||
|
@ -1,36 +1,36 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SWInventory implements Listener, Inventory {
|
||||
public class SWInventory implements Listener {
|
||||
|
||||
Player player;
|
||||
private Map<Integer, InvCallback> callbacks;
|
||||
private int inventorySize;
|
||||
private ItemStack[] contents;
|
||||
private String title;
|
||||
Inventory inventory;
|
||||
|
||||
public SWInventory(Player p, int size, String t){
|
||||
title = t;
|
||||
callbacks = new HashMap<>();
|
||||
player = p;
|
||||
inventorySize = size;
|
||||
contents = new ItemStack[inventorySize];
|
||||
switch(Core.getVersion()){
|
||||
case 14:
|
||||
inventory = new SWInventory_v14(p, size, t);
|
||||
break;
|
||||
default:
|
||||
inventory = new SWInventory_v12(p, size, t);
|
||||
}
|
||||
}
|
||||
|
||||
public SWInventory(Player p, int size, String t, Map<Integer, SWItem> items){
|
||||
@ -44,7 +44,7 @@ public class SWInventory implements Listener, Inventory {
|
||||
}
|
||||
|
||||
public void setItem(int pos, SWItem item){
|
||||
contents[pos] = item.getItemStack();
|
||||
inventory.setItem(pos, item.getItemStack());
|
||||
callbacks.put(pos, item.getCallback());
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class SWInventory implements Listener, Inventory {
|
||||
}
|
||||
|
||||
public void open(){
|
||||
player.openInventory(this);
|
||||
player.openInventory(inventory);
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
}
|
||||
|
||||
@ -94,191 +94,4 @@ public class SWInventory implements Listener, Inventory {
|
||||
if(callbacks.containsKey(-1))
|
||||
callbacks.get(-1).clicked(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return inventorySize;
|
||||
}
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return 999;
|
||||
}
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
//Unused
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int index) {
|
||||
return contents[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int index, ItemStack item) {
|
||||
//Unused
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return contents;
|
||||
}
|
||||
@Override
|
||||
public void setContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
//Unused
|
||||
}
|
||||
@Override
|
||||
public ItemStack[] getStorageContents() {
|
||||
return contents;
|
||||
}
|
||||
@Override
|
||||
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int materialId) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(Material material) throws IllegalArgumentException {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(ItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int materialId, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material, int amount) throws IllegalArgumentException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack item, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAtLeast(ItemStack item, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(int materialId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(Material material) throws IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(ItemStack item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(int materialId) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(Material material) throws IllegalArgumentException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(ItemStack item) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int firstEmpty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int materialId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Material material) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int index) {
|
||||
contents[index] = null;
|
||||
callbacks.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
contents = new ItemStack[contents.length];
|
||||
callbacks.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
List<HumanEntity> l = new ArrayList<>();
|
||||
l.add(player);
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return InventoryType.CHEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getHolder() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
11
src/de/steamwar/inventory/SWInventory_v12.java
Normale Datei
11
src/de/steamwar/inventory/SWInventory_v12.java
Normale Datei
@ -0,0 +1,11 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryCustom;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
class SWInventory_v12 extends CraftInventoryCustom {
|
||||
|
||||
SWInventory_v12(Player player, int size, String title) {
|
||||
super(player, size, title);
|
||||
}
|
||||
}
|
11
src/de/steamwar/inventory/SWInventory_v14.java
Normale Datei
11
src/de/steamwar/inventory/SWInventory_v14.java
Normale Datei
@ -0,0 +1,11 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCustom;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
class SWInventory_v14 extends CraftInventoryCustom {
|
||||
|
||||
SWInventory_v14(Player player, int size, String title) {
|
||||
super(player, size, title);
|
||||
}
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -15,6 +18,26 @@ public class SWItem {
|
||||
private ItemMeta itemMeta;
|
||||
private InvCallback callback;
|
||||
|
||||
public static SWItem getPlayerSkull(OfflinePlayer player){
|
||||
SWItem p = new SWItem();
|
||||
ItemStack head = new ItemStack(getMaterial("SKULL_ITEM"), 1, (short) 3);
|
||||
SkullMeta headmeta = (SkullMeta) head.getItemMeta();
|
||||
headmeta.setOwningPlayer(player);
|
||||
headmeta.setDisplayName(player.getName());
|
||||
head.setItemMeta(headmeta);
|
||||
p.setItemStack(head);
|
||||
return p;
|
||||
}
|
||||
|
||||
public static Material getMaterial(String material){
|
||||
switch(Core.getVersion()){
|
||||
case 14:
|
||||
return SWItem_v14.getMaterial(material);
|
||||
default:
|
||||
return SWItem_v12.getMaterial(material);
|
||||
}
|
||||
}
|
||||
|
||||
public SWItem(){
|
||||
itemStack = new ItemStack(Material.AIR);
|
||||
itemMeta = itemStack.getItemMeta();
|
||||
|
11
src/de/steamwar/inventory/SWItem_v12.java
Normale Datei
11
src/de/steamwar/inventory/SWItem_v12.java
Normale Datei
@ -0,0 +1,11 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
class SWItem_v12 {
|
||||
private SWItem_v12(){}
|
||||
|
||||
static Material getMaterial(String material){
|
||||
return Material.valueOf(material);
|
||||
}
|
||||
}
|
11
src/de/steamwar/inventory/SWItem_v14.java
Normale Datei
11
src/de/steamwar/inventory/SWItem_v14.java
Normale Datei
@ -0,0 +1,11 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
class SWItem_v14 {
|
||||
private SWItem_v14(){}
|
||||
|
||||
static Material getMaterial(String material){
|
||||
return Material.valueOf("LEGACY_" + material);
|
||||
}
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package de.steamwar.inventory;
|
||||
|
||||
import de.warking.hunjy.MySQL.Schematic;
|
||||
import de.warking.hunjy.MySQL.SchematicType;
|
||||
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;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -29,23 +27,23 @@ public class SWListInv<T> extends SWInventory {
|
||||
|
||||
@Override
|
||||
public void open(){
|
||||
clear();
|
||||
inventory.clear();
|
||||
setCallback(-999, (ClickType click) -> player.closeInventory());
|
||||
if(elements.size() > 54){
|
||||
if(page != 0)
|
||||
setItem(45, Material.INK_SACK, (byte)10, "§eSeite zurück", (ClickType click) -> {
|
||||
setItem(45, SWItem.getMaterial("INK_SACK"), (byte)10, "§eSeite zurück", (ClickType click) -> {
|
||||
page--;
|
||||
open();
|
||||
});
|
||||
else
|
||||
setItem(45, Material.INK_SACK, (byte)8, "§7Seite zurück", (ClickType click) -> {});
|
||||
setItem(45, SWItem.getMaterial("INK_SACK"), (byte)8, "§7Seite zurück", (ClickType click) -> {});
|
||||
if(page < elements.size()/45)
|
||||
setItem(53, Material.INK_SACK, (byte)10, "§eSeite vor", (ClickType click) -> {
|
||||
setItem(53, SWItem.getMaterial("INK_SACK"), (byte)10, "§eSeite vor", (ClickType click) -> {
|
||||
page++;
|
||||
open();
|
||||
});
|
||||
else
|
||||
setItem(53, Material.INK_SACK, (byte)8, "§7Seite vor", (ClickType click) -> {});
|
||||
setItem(53, SWItem.getMaterial("INK_SACK"), (byte)8, "§7Seite vor", (ClickType click) -> {});
|
||||
}
|
||||
|
||||
int ipageLimit = elements.size() - page*45;
|
||||
@ -78,15 +76,7 @@ public class SWListInv<T> extends SWInventory {
|
||||
if(without != null && player.getUniqueId().equals(without.getUniqueId()))
|
||||
continue;
|
||||
|
||||
SWItem p = new SWItem();
|
||||
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
|
||||
SkullMeta headmeta = (SkullMeta) head.getItemMeta();
|
||||
headmeta.setOwningPlayer(player);
|
||||
headmeta.setDisplayName(player.getName());
|
||||
head.setItemMeta(headmeta);
|
||||
p.setItemStack(head);
|
||||
onlinePlayers.add(new Pair<>(p, player.getUniqueId()));
|
||||
onlinePlayers.add(new Pair<>(SWItem.getPlayerSkull(player), player.getUniqueId()));
|
||||
}
|
||||
return onlinePlayers;
|
||||
}
|
||||
@ -103,9 +93,9 @@ public class SWListInv<T> extends SWInventory {
|
||||
for(Schematic s : schems){
|
||||
Material m;
|
||||
if(s.getItem().isEmpty())
|
||||
m = Material.CAULDRON_ITEM;
|
||||
m = SWItem.getMaterial("CAULDRON_ITEM");
|
||||
else
|
||||
m = Material.valueOf(s.getItem());
|
||||
m = SWItem.getMaterial(s.getItem());
|
||||
SWItem item = new SWItem(m,"§e" + s.getSchemName());
|
||||
schemList.add(new Pair<>(item, s));
|
||||
}
|
||||
|
129
src/de/steamwar/sql/BauweltMember.java
Normale Datei
129
src/de/steamwar/sql/BauweltMember.java
Normale Datei
@ -0,0 +1,129 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BauweltMember{
|
||||
private final int bauweltID;
|
||||
private final int memberID;
|
||||
private boolean build;
|
||||
private boolean worldEdit;
|
||||
private boolean world;
|
||||
|
||||
private static final List<BauweltMember> members = new ArrayList<>();
|
||||
|
||||
private BauweltMember(int ownerID, int memberID, boolean build, boolean worldEdit, boolean world, boolean updateDB){
|
||||
bauweltID = ownerID;
|
||||
this.memberID = memberID;
|
||||
this.build = build;
|
||||
this.worldEdit = worldEdit;
|
||||
this.world = world;
|
||||
if(updateDB)
|
||||
updateDB();
|
||||
members.add(this);
|
||||
}
|
||||
|
||||
public BauweltMember(int ownerID, int memberID, boolean build, boolean worldEdit, boolean world){
|
||||
this(ownerID, memberID, build, worldEdit, world, true);
|
||||
}
|
||||
|
||||
public BauweltMember(UUID ownerID, UUID memberID, boolean build, boolean worldEdit, boolean world){
|
||||
this(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId(), build, worldEdit, world, true);
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
SQL.update("DELETE FROM BauweltMember WHERE BauweltID = " + bauweltID + " AND MemberID = " + 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)");
|
||||
}
|
||||
|
||||
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
||||
return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId());
|
||||
}
|
||||
|
||||
public static BauweltMember getBauMember(int ownerID, int memberID){
|
||||
for(BauweltMember member : members)
|
||||
if(member.memberID == memberID)
|
||||
return member;
|
||||
ResultSet member = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = '" + ownerID + "' AND MemberID = '" + memberID + "'");
|
||||
try {
|
||||
if(member == null || !member.next()){
|
||||
return null;
|
||||
}
|
||||
boolean build = member.getBoolean("Build");
|
||||
boolean worldEdit = member.getBoolean("WorldEdit");
|
||||
boolean testblock = member.getBoolean("World");
|
||||
return new BauweltMember(ownerID, memberID, build, worldEdit, testblock, false);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Did not get member", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<BauweltMember> getMembers(UUID bauweltID){
|
||||
return getMembers(SteamwarUser.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 LinkedList<>();
|
||||
while(memberlist.next()){
|
||||
int memberID = memberlist.getInt("MemberID");
|
||||
boolean build = memberlist.getBoolean("Build");
|
||||
boolean worldEdit = memberlist.getBoolean("WorldEdit");
|
||||
boolean testblock = memberlist.getBoolean("World");
|
||||
members.add(new BauweltMember(bauweltID, memberID, build, worldEdit, testblock, false));
|
||||
}
|
||||
return members;
|
||||
}catch(SQLException e){
|
||||
throw new SecurityException("Did not get members", e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBauweltID() {
|
||||
return bauweltID;
|
||||
}
|
||||
|
||||
public int getMemberID() {
|
||||
return memberID;
|
||||
}
|
||||
|
||||
public boolean isBuild() {
|
||||
return build;
|
||||
}
|
||||
|
||||
public void setBuild(boolean build) {
|
||||
this.build = build;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public boolean isWorldEdit() {
|
||||
return worldEdit;
|
||||
}
|
||||
|
||||
public void setWorldEdit(boolean worldEdit) {
|
||||
this.worldEdit = worldEdit;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public boolean isWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(boolean world) {
|
||||
this.world = world;
|
||||
updateDB();
|
||||
}
|
||||
}
|
98
src/de/steamwar/sql/CheckedSchematic.java
Normale Datei
98
src/de/steamwar/sql/CheckedSchematic.java
Normale Datei
@ -0,0 +1,98 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class CheckedSchematic {
|
||||
|
||||
private final String schemName;
|
||||
private final int schemOwner;
|
||||
private final int validator;
|
||||
private final Timestamp startTime;
|
||||
private final Timestamp endTime;
|
||||
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.schemOwner = schemOwner;
|
||||
this.validator = validator;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.declineReason = SQL.disarmString(declineReason);
|
||||
if(insertDB)
|
||||
insertDB();
|
||||
}
|
||||
|
||||
public CheckedSchematic(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String declineReason){
|
||||
this(schemName, schemOwner, validator, startTime, endTime, declineReason, true);
|
||||
}
|
||||
|
||||
public CheckedSchematic(String schemName, UUID schemOwner, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){
|
||||
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(validator).getId(), startTime, endTime, declineReason, true);
|
||||
}
|
||||
|
||||
private void insertDB(){
|
||||
SQL.update("INSERT INTO CheckedSchematic" +
|
||||
" (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason)" +
|
||||
" VALUES" +
|
||||
" ('"+ schemName + "', '" + schemOwner + "', '" + validator + "', '" + startTime.toString() + "', '" + endTime.toString() + "', '" + declineReason + "')");
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclined(UUID schemOwner){
|
||||
return getLastDelined(SteamwarUser.get(schemOwner).getId());
|
||||
}
|
||||
|
||||
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");
|
||||
while(lastRS.next()){
|
||||
String schemName = lastRS.getString("SchemName");
|
||||
int validator = lastRS.getInt("Validator");
|
||||
Timestamp startTime = lastRS.getTimestamp("StartTime");
|
||||
Timestamp endTime = lastRS.getTimestamp("EndTime");
|
||||
String declineReason = lastRS.getString("DeclineReason");
|
||||
lastDeclined.add(new CheckedSchematic(schemName, schemOwner, validator, startTime, endTime, declineReason, false));
|
||||
}
|
||||
}catch(SQLException e){
|
||||
Bukkit.getLogger().log(Level.SEVERE, "getLastDeclined failed", e);
|
||||
}
|
||||
return lastDeclined;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
SQL.update("DELETE FROM CheckedSchematic WHERE SchemOwner = " + this.schemOwner + " AND SchemName = '" + this.schemName + "'");
|
||||
}
|
||||
|
||||
public String getSchemName() {
|
||||
return schemName;
|
||||
}
|
||||
|
||||
public int getSchemOwner() {
|
||||
return schemOwner;
|
||||
}
|
||||
|
||||
public int getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
public Timestamp getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public Timestamp getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public String getDeclineReason() {
|
||||
return declineReason;
|
||||
}
|
||||
}
|
59
src/de/steamwar/sql/Event.java
Normale Datei
59
src/de/steamwar/sql/Event.java
Normale Datei
@ -0,0 +1,59 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Event {
|
||||
|
||||
private final int eventID;
|
||||
private final String eventName;
|
||||
private final Timestamp start;
|
||||
private final Timestamp end;
|
||||
private final int maximumTeamMembers;
|
||||
private final boolean publicSchemsOnly;
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
public static Event get(int 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"));
|
||||
}catch (SQLException e){
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load Event", e);
|
||||
throw new SecurityException();
|
||||
}
|
||||
}
|
||||
|
||||
public int getEventID() {
|
||||
return eventID;
|
||||
}
|
||||
public String getEventName() {
|
||||
return eventName;
|
||||
}
|
||||
public Timestamp getStart() {
|
||||
return start;
|
||||
}
|
||||
public Timestamp getEnd() {
|
||||
return end;
|
||||
}
|
||||
public int getMaximumTeamMembers() {
|
||||
return maximumTeamMembers;
|
||||
}
|
||||
public boolean publicSchemsOnly() {
|
||||
return publicSchemsOnly;
|
||||
}
|
||||
}
|
76
src/de/steamwar/sql/EventFight.java
Normale Datei
76
src/de/steamwar/sql/EventFight.java
Normale Datei
@ -0,0 +1,76 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class EventFight {
|
||||
private int eventID;
|
||||
private int fightID;
|
||||
private int teamBlue;
|
||||
private int teamRed;
|
||||
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;
|
||||
}
|
||||
|
||||
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"));
|
||||
}catch (SQLException e){
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*public void setErgebnis(FightTeam winner){
|
||||
if (winner == null)
|
||||
ergebnis = 0;
|
||||
else if (winner.isBlue())
|
||||
ergebnis = 1;
|
||||
else
|
||||
ergebnis = 2;
|
||||
SQL.update("UPDATE EventFight SET Ergebnis = " + ergebnis + " WHERE FightID = " + fightID);
|
||||
}*/
|
||||
|
||||
public int getTeamBlue() {
|
||||
return teamBlue;
|
||||
}
|
||||
|
||||
public int getTeamRed() {
|
||||
return teamRed;
|
||||
}
|
||||
|
||||
public int getEventID() {
|
||||
return eventID;
|
||||
}
|
||||
|
||||
public int getFightID() {
|
||||
return fightID;
|
||||
}
|
||||
|
||||
public int getKampfleiter() {
|
||||
return kampfleiter;
|
||||
}
|
||||
|
||||
public int getErgebnis() {
|
||||
return ergebnis;
|
||||
}
|
||||
}
|
101
src/de/steamwar/sql/SQL.java
Normale Datei
101
src/de/steamwar/sql/SQL.java
Normale Datei
@ -0,0 +1,101 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
|
||||
|
||||
public class SQL {
|
||||
|
||||
private SQL(){}
|
||||
|
||||
private static final String host;
|
||||
private static final String port;
|
||||
private static final String database;
|
||||
private static final String user;
|
||||
private static final String password;
|
||||
private static Connection con;
|
||||
|
||||
static{
|
||||
File file = new File(Core.getInstance().getDataFolder(), "MySQL.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
if(!file.exists())
|
||||
throw new SecurityException("SQL-ConfigFile not found!");
|
||||
|
||||
host = config.getString("HOST");
|
||||
port = config.getString("PORT");
|
||||
database = config.getString("DATABASE");
|
||||
user = config.getString("USER");
|
||||
password = config.getString("PASSWORD");
|
||||
|
||||
connect();
|
||||
}
|
||||
|
||||
static Integer booleanToInt(boolean b){
|
||||
if(b)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void closeConnection() {
|
||||
try {
|
||||
con.close();
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("Could not close connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
static void update(String qry) {
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
throw new SecurityException("Could not perform update", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ResultSet select(String qry) {
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
} catch (SQLException ex) {
|
||||
throw new SecurityException("Could not perform select", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String disarmString(String s){
|
||||
return s.replace("'", "");
|
||||
}
|
||||
|
||||
|
||||
private static void connect() {
|
||||
try {
|
||||
con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoreconnect=true", user, password);
|
||||
if(con.isClosed())
|
||||
throw new SQLException("Could not connect to database!");
|
||||
}catch (SQLException e) {
|
||||
throw new SecurityException("No connection to database.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void reconnect(){
|
||||
closeConnection();
|
||||
connect();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.warking.hunjy.MySQL;
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -6,14 +6,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.warking.hunjy.Core.sql;
|
||||
|
||||
public class Schematic {
|
||||
|
||||
private final String SchemName;
|
||||
private final int SchemOwner;
|
||||
private String Item;
|
||||
private SchematicType SchemType;
|
||||
private final String schemName;
|
||||
private final int schemOwner;
|
||||
private String item;
|
||||
private SchematicType schemType;
|
||||
|
||||
private Schematic(ResultSet rs) throws SQLException {
|
||||
this(
|
||||
@ -25,10 +23,10 @@ public class Schematic {
|
||||
}
|
||||
|
||||
private Schematic(String schemName, int schemOwner, String item, SchematicType schemType, boolean updateDB){
|
||||
SchemName = schemName;
|
||||
SchemOwner = schemOwner;
|
||||
Item = item;
|
||||
SchemType = schemType;
|
||||
this.schemName = schemName;
|
||||
this.schemOwner = schemOwner;
|
||||
this.item = item;
|
||||
this.schemType = schemType;
|
||||
if(updateDB)
|
||||
updateDB();
|
||||
}
|
||||
@ -38,25 +36,25 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public Schematic(String schemName, UUID schemOwner, String item, SchematicType schemType){
|
||||
this(schemName, WarkingUser.get(schemOwner).getId(), item, schemType, true);
|
||||
this(schemName, SteamwarUser.get(schemOwner).getId(), item, schemType, true);
|
||||
}
|
||||
|
||||
private void updateDB(){
|
||||
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" +
|
||||
" ('" + schemName + "', '" + schemOwner + "', '" + item + "', '" + schemType.toDB() + "')" +
|
||||
" ON DUPLICATE KEY UPDATE" +
|
||||
" Item = VALUES(Item), SchemType = VALUES(SchemType)");
|
||||
}
|
||||
|
||||
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){
|
||||
return getSchemFromDB(schemName, WarkingUser.get(schemOwner).getId());
|
||||
return getSchemFromDB(schemName, SteamwarUser.get(schemOwner).getId());
|
||||
}
|
||||
|
||||
public static Schematic getSchemFromDB(String schemName, int schemOwner){
|
||||
schemName = MySQL.disarmString(schemName);
|
||||
ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
|
||||
schemName = SQL.disarmString(schemName);
|
||||
ResultSet schematic = SQL.select("SELECT * FROM Schematic WHERE SchemName = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
|
||||
try {
|
||||
if(schematic == null || !schematic.next()){
|
||||
SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner);
|
||||
@ -73,12 +71,12 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public static List<Schematic> getSchemsAccessibleByUser(UUID schemOwner){
|
||||
return getSchemsAccessibleByUser(WarkingUser.get(schemOwner).getId());
|
||||
return getSchemsAccessibleByUser(SteamwarUser.get(schemOwner).getId());
|
||||
}
|
||||
|
||||
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
||||
try{
|
||||
ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemOwner = '" + schemOwner + "'");
|
||||
ResultSet schematic = SQL.select("SELECT * FROM Schematic WHERE SchemOwner = '" + schemOwner + "'");
|
||||
List<Schematic> schematics = new ArrayList<>();
|
||||
while(schematic.next()){
|
||||
schematics.add(new Schematic(schematic));
|
||||
@ -95,7 +93,7 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public static List<Schematic> getSchemsOfType(UUID schemOwner, SchematicType schemType){
|
||||
return getSchemsOfType(WarkingUser.get(schemOwner).getId(), schemType);
|
||||
return getSchemsOfType(SteamwarUser.get(schemOwner).getId(), schemType);
|
||||
}
|
||||
|
||||
public static List<Schematic> getSchemsOfType(int schemOwner, SchematicType schemType){
|
||||
@ -110,7 +108,7 @@ public class Schematic {
|
||||
|
||||
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
||||
try{
|
||||
ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'");
|
||||
ResultSet schematic = SQL.select("SELECT * FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'");
|
||||
List<Schematic> schematics = new ArrayList<>();
|
||||
while(schematic.next()){
|
||||
schematics.add(new Schematic(schematic));
|
||||
@ -123,33 +121,33 @@ public class Schematic {
|
||||
}
|
||||
|
||||
public String getSchemName() {
|
||||
return SchemName;
|
||||
return schemName;
|
||||
}
|
||||
|
||||
public int getSchemOwner() {
|
||||
return SchemOwner;
|
||||
return schemOwner;
|
||||
}
|
||||
|
||||
public String getItem() {
|
||||
return Item;
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(String item) {
|
||||
Item = item;
|
||||
this.item = item;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public SchematicType getSchemType() {
|
||||
return SchemType;
|
||||
return schemType;
|
||||
}
|
||||
|
||||
public void setSchemType(SchematicType schemType) {
|
||||
SchemType = schemType;
|
||||
this.schemType = schemType;
|
||||
updateDB();
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
sql.update("DELETE FROM Schematic WHERE SchemOwner = " + SchemOwner + " AND SchemName = '" + SchemName + "'");
|
||||
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 = " + schemOwner + " AND SchemName = '" + schemName + "'");
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.warking.hunjy.MySQL;
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -6,17 +6,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.warking.hunjy.Core.sql;
|
||||
|
||||
public class SchematicMember {
|
||||
private final int SchemOwner;
|
||||
private final String SchemName;
|
||||
private final int Member;
|
||||
private final int schemOwner;
|
||||
private final String schemName;
|
||||
private final int member;
|
||||
|
||||
private SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDB){
|
||||
SchemOwner = schemOwner;
|
||||
Member = schemMember;
|
||||
SchemName = schemName;
|
||||
this.schemOwner = schemOwner;
|
||||
member = schemMember;
|
||||
this.schemName = schemName;
|
||||
if(updateDB)
|
||||
updateDB();
|
||||
}
|
||||
@ -26,35 +24,34 @@ public class SchematicMember {
|
||||
}
|
||||
|
||||
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){
|
||||
this(schemName, WarkingUser.get(schemOwner).getId(), WarkingUser.get(schemMember).getId(), true);
|
||||
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true);
|
||||
}
|
||||
|
||||
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){
|
||||
return getSchemMemberFromDB(schemName, WarkingUser.get(schemOwner).getId(), WarkingUser.get(schemMember).getId());
|
||||
return getSchemMemberFromDB(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId());
|
||||
}
|
||||
|
||||
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 = '" + 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();
|
||||
throw new SecurityException("Could not get schemmember", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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 = '" + schemName + "' AND Member = '" + schemMember + "'");
|
||||
try {
|
||||
if(schematicMember == null || !schematicMember.next()){
|
||||
return null;
|
||||
@ -62,17 +59,16 @@ public class SchematicMember {
|
||||
int schemOwner = schematicMember.getInt("SchemOwner");
|
||||
return new SchematicMember(schemName, schemOwner, schemMember, false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Could not get member", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){
|
||||
return getSchemMembers(schemName, WarkingUser.get(schemOwner).getId());
|
||||
return getSchemMembers(schemName, SteamwarUser.get(schemOwner).getId());
|
||||
}
|
||||
|
||||
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 = '" + schemName + "' AND SchemOwner = '" + schemOwner + "'");
|
||||
try {
|
||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
||||
while(schematicMember.next()){
|
||||
@ -81,17 +77,16 @@ public class SchematicMember {
|
||||
}
|
||||
return schematicMembers;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Could not get schemmembers", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
|
||||
return getAccessibleSchems(WarkingUser.get(schemMember).getId());
|
||||
return getAccessibleSchems(SteamwarUser.get(schemMember).getId());
|
||||
}
|
||||
|
||||
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()){
|
||||
@ -101,24 +96,23 @@ public class SchematicMember {
|
||||
}
|
||||
return schematicMembers;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Could not get accessible schems", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSchemOwner() {
|
||||
return SchemOwner;
|
||||
return schemOwner;
|
||||
}
|
||||
|
||||
public String getSchemName() {
|
||||
return SchemName;
|
||||
return schemName;
|
||||
}
|
||||
|
||||
public int getMember() {
|
||||
return Member;
|
||||
return member;
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
sql.update("DELETE FROM SchemMember WHERE SchemOwner = " + SchemOwner + " AND SchemName = '" + SchemName + "' AND Member = '" + Member + "'");
|
||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "' AND Member = '" + member + "'");
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.warking.hunjy.MySQL;
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
98
src/de/steamwar/sql/SteamwarUser.java
Normale Datei
98
src/de/steamwar/sql/SteamwarUser.java
Normale Datei
@ -0,0 +1,98 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
public class SteamwarUser {
|
||||
|
||||
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
|
||||
private static final Map<String, SteamwarUser> byName = new HashMap<>();
|
||||
private static final Map<Integer, SteamwarUser> byId = new HashMap<>();
|
||||
|
||||
static{
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
byId.clear();
|
||||
byName.clear();
|
||||
byUUID.clear();
|
||||
}, 72000, 72000);
|
||||
}
|
||||
|
||||
private final int id;
|
||||
private final UUID uuid;
|
||||
private final String userName;
|
||||
private final UserGroup userGroup;
|
||||
private final int team;
|
||||
|
||||
private SteamwarUser(ResultSet rs){
|
||||
try {
|
||||
id = rs.getInt("id");
|
||||
uuid = java.util.UUID.fromString(rs.getString("UUID"));
|
||||
userName = rs.getString("UserName");
|
||||
userGroup = de.steamwar.sql.UserGroup.valueOf(rs.getString("UserGroup"));
|
||||
team = rs.getInt("Team");
|
||||
|
||||
byUUID.put(uuid, this);
|
||||
byName.put(userName.toLowerCase(), this);
|
||||
byId.put(id, this);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not instance User", e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public UserGroup getUserGroup() {
|
||||
return userGroup;
|
||||
}
|
||||
|
||||
public int getTeam(){
|
||||
return team;
|
||||
}
|
||||
|
||||
private static SteamwarUser fromDB(String statement){
|
||||
ResultSet rs = SQL.select(statement);
|
||||
try {
|
||||
if(rs.next())
|
||||
return new SteamwarUser(rs);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("SQL Statement failed to get User", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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() + "'");
|
||||
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() + "'");
|
||||
return user;
|
||||
}
|
||||
|
||||
public static SteamwarUser get(int id) {
|
||||
SteamwarUser user = byId.get(id);
|
||||
if(user == null)
|
||||
user = fromDB("SELECT * FROM UserData WHERE id = '" + id + "'");
|
||||
return user;
|
||||
}
|
||||
}
|
63
src/de/steamwar/sql/Team.java
Normale Datei
63
src/de/steamwar/sql/Team.java
Normale Datei
@ -0,0 +1,63 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Team {
|
||||
private final int teamId;
|
||||
private final String teamKuerzel;
|
||||
private final String teamName;
|
||||
private final int teamLeader;
|
||||
|
||||
private Team(ResultSet rs){
|
||||
try {
|
||||
teamId = rs.getInt("TeamID");
|
||||
teamKuerzel = rs.getString("TeamKuerzel");
|
||||
teamName = rs.getString("TeamName");
|
||||
teamLeader = rs.getInt("TeamLeader");
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not load team", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Team get(int id){
|
||||
ResultSet rs = SQL.select("SELECT * FROM Team WHERE TeamID = " + id);
|
||||
try {
|
||||
if(!rs.next())
|
||||
return null;
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not load team", e);
|
||||
}
|
||||
return new Team(rs);
|
||||
}
|
||||
|
||||
public int getTeamId() {
|
||||
return teamId;
|
||||
}
|
||||
|
||||
public String getTeamKuerzel() {
|
||||
return teamKuerzel;
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public int getTeamLeader() {
|
||||
return teamLeader;
|
||||
}
|
||||
|
||||
public List<Integer> getMembers(){
|
||||
try{
|
||||
ResultSet memberlist = SQL.select("SELECT id FROM UserData WHERE Team = '" + teamId + "'");
|
||||
List<Integer> members = new LinkedList<>();
|
||||
while(memberlist.next())
|
||||
members.add(memberlist.getInt("id"));
|
||||
return members;
|
||||
}catch(SQLException e){
|
||||
throw new SecurityException("Could not load Teammembers", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.warking.hunjy.MySQL;
|
||||
package de.steamwar.sql;
|
||||
|
||||
public enum UserGroup {
|
||||
Admin,
|
@ -1,98 +0,0 @@
|
||||
package de.warking.hunjy.MySQL;
|
||||
|
||||
import de.warking.hunjy.Core;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
|
||||
public class MySQL {
|
||||
private String host;
|
||||
private String port;
|
||||
private String database;
|
||||
private String user;
|
||||
private String password;
|
||||
private Connection con;
|
||||
|
||||
public static Integer booleanToInt(boolean b){
|
||||
if(b)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public MySQL() {
|
||||
this.host = Core.getInstance().getFileManager().getConfig().getString("HOST");
|
||||
this.port = Core.getInstance().getFileManager().getConfig().getString("PORT");
|
||||
this.database = Core.getInstance().getFileManager().getConfig().getString("DATABASE");
|
||||
this.user = Core.getInstance().getFileManager().getConfig().getString("USER");
|
||||
this.password = Core.getInstance().getFileManager().getConfig().getString("PASSWORD");
|
||||
|
||||
connect();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
try {
|
||||
con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoreconnect=true", user, password);
|
||||
if(con == null)
|
||||
System.err.println("Fatal ERROR: Could not connect to database!");
|
||||
}catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void reconnect(){
|
||||
closeConnection();
|
||||
connect();
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
try {
|
||||
if(con != null)
|
||||
con.close();
|
||||
}catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void update(String qry) {
|
||||
if(con == null){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
st.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet select(String qry) {
|
||||
if(con == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
reconnect();
|
||||
try {
|
||||
PreparedStatement st = con.prepareStatement(qry);
|
||||
return st.executeQuery();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String disarmString(String s){
|
||||
return s.replace("'", "");
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
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 WarkingUser {
|
||||
|
||||
private static final List<WarkingUser> allUsers = new ArrayList<>();
|
||||
|
||||
private int id;
|
||||
private UUID UUID;
|
||||
private String UserName;
|
||||
private UserGroup UserGroup;
|
||||
private int Team;
|
||||
|
||||
public WarkingUser(UUID uuid){
|
||||
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 lower(UserName) = '" + name.toLowerCase() + "'");
|
||||
init(dbplayer);
|
||||
}
|
||||
|
||||
private void init(ResultSet dbplayer){
|
||||
try {
|
||||
if(!dbplayer.next())
|
||||
return;
|
||||
id = dbplayer.getInt("id");
|
||||
this.UUID = java.util.UUID.fromString(dbplayer.getString("UUID"));
|
||||
UserName = dbplayer.getString("UserName");
|
||||
UserGroup = de.warking.hunjy.MySQL.UserGroup.valueOf(dbplayer.getString("UserGroup"));
|
||||
Team = dbplayer.getInt("Team");
|
||||
allUsers.add(this);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public java.util.UUID getUUID() {
|
||||
return UUID;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return UserName;
|
||||
}
|
||||
|
||||
public UserGroup getUserGroup() {
|
||||
return UserGroup;
|
||||
}
|
||||
|
||||
public int getTeam(){
|
||||
return Team;
|
||||
}
|
||||
|
||||
public static WarkingUser get(String userName){
|
||||
userName = MySQL.disarmString(userName);
|
||||
for(WarkingUser user : allUsers)
|
||||
if(user.UserName.equalsIgnoreCase(userName))
|
||||
return user;
|
||||
WarkingUser offline = new WarkingUser(userName);
|
||||
return offline;
|
||||
}
|
||||
|
||||
public static WarkingUser get(UUID uuid){
|
||||
for(WarkingUser user : allUsers)
|
||||
if(user.UUID.equals(uuid))
|
||||
return user;
|
||||
WarkingUser offline = new WarkingUser(uuid);
|
||||
return offline;
|
||||
}
|
||||
|
||||
public static WarkingUser get(int id){
|
||||
for(WarkingUser user : allUsers)
|
||||
if(user.id == id)
|
||||
return user;
|
||||
WarkingUser offline = new WarkingUser(id);
|
||||
return offline;
|
||||
}
|
||||
|
||||
public static void clearCache(){
|
||||
allUsers.clear();
|
||||
}
|
||||
}
|
@ -3,6 +3,6 @@ version: 1.0
|
||||
|
||||
author: hunjy, Lixfel
|
||||
|
||||
main: de.warking.hunjy.Core
|
||||
main: de.steamwar.core.Core
|
||||
|
||||
commands:
|
In neuem Issue referenzieren
Einen Benutzer sperren