SteamWar/SpigotCore
Archiviert
13
0

Merge branch 'multiversion' of SteamWar/SpigotCore into master

Dieser Commit ist enthalten in:
Lixfel 2019-11-23 22:23:51 +01:00 committet von Gitea
Commit ca5d074219
37 geänderte Dateien mit 1237 neuen und 670 gelöschten Zeilen

1
.gitignore vendored
Datei anzeigen

@ -1,2 +1,3 @@
.idea .idea
target target
dependency-reduced-pom.xml

37
SpigotCore_12/pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId>
<version>2.0</version>
</parent>
<artifactId>SpigotCore_12</artifactId>
<version>2.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
<artifactId>Spigot</artifactId>
<version>1.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,13 @@
package de.steamwar.inventory;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryCustom;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
class SWInventory_12 {
private SWInventory_12(){}
static Inventory get(Player player, int size, String title){
return new CraftInventoryCustom(player, size, title);
}
}

Datei anzeigen

@ -0,0 +1,21 @@
package de.steamwar.inventory;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.meta.SkullMeta;
class SWItem_12 {
private SWItem_12(){}
static Material getMaterial(String material){
return Material.valueOf(material);
}
static Material getDye(){
return Material.INK_SACK;
}
static void setSkullOwner(OfflinePlayer player, SkullMeta meta){
meta.setOwningPlayer(player);
}
}

37
SpigotCore_14/pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId>
<version>2.0</version>
</parent>
<artifactId>SpigotCore_14</artifactId>
<version>2.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
<artifactId>Spigot</artifactId>
<version>1.14</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,13 @@
package de.steamwar.inventory;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCustom;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
class SWInventory_14 {
private SWInventory_14() {}
static Inventory get(Player player, int size, String title){
return new CraftInventoryCustom(player, size, title);
}
}

Datei anzeigen

@ -0,0 +1,48 @@
package de.steamwar.inventory;
import org.bukkit.Material;
class SWItem_14 {
private SWItem_14(){}
static Material getMaterial(String material) {
return Material.valueOf("LEGACY_" + material);
}
static Material getDye(int colorCode){
switch(colorCode){
case 1:
return Material.RED_DYE;
case 2:
return Material.GREEN_DYE;
case 3:
return Material.BROWN_DYE;
case 4:
return Material.LAPIS_LAZULI;
case 5:
return Material.PURPLE_DYE;
case 6:
return Material.CYAN_DYE;
case 7:
return Material.LIGHT_GRAY_DYE;
case 8:
return Material.GRAY_DYE;
case 9:
return Material.PINK_DYE;
case 10:
return Material.LIME_DYE;
case 11:
return Material.YELLOW_DYE;
case 12:
return Material.LIGHT_BLUE_DYE;
case 13:
return Material.MAGENTA_DYE;
case 14:
return Material.ORANGE_DYE;
case 15:
return Material.WHITE_DYE;
default:
return Material.BLACK_DYE;
}
}
}

37
SpigotCore_8/pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId>
<version>2.0</version>
</parent>
<artifactId>SpigotCore_8</artifactId>
<version>2.0</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
<artifactId>Spigot</artifactId>
<version>1.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,13 @@
package de.steamwar.inventory;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
class SWInventory_8 {
private SWInventory_8(){}
static Inventory get(Player player, int size, String title){
return new CraftInventoryCustom(player, size, title);
}
}

Datei anzeigen

@ -0,0 +1,12 @@
package de.steamwar.inventory;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.meta.SkullMeta;
class SWItem_8 {
private SWItem_8(){}
static void setSkullOwner(OfflinePlayer player, SkullMeta meta){
meta.setOwner(player.getName());
}
}

72
SpigotCore_Main/pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId>
<version>2.0</version>
</parent>
<artifactId>SpigotCore_Main</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>SpigotCore</finalName>
</build>
<dependencies>
<dependency>
<groupId>steamwar</groupId>
<artifactId>Spigot</artifactId>
<version>1.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>SpigotCore_8</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>SpigotCore_12</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>SpigotCore_14</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -1,20 +1,29 @@
package de.warking.hunjy; package de.steamwar.core;
import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChattingEvent;
import de.steamwar.core.events.PlayerJoinedEvent; import de.steamwar.core.events.PlayerJoinedEvent;
import de.warking.hunjy.MySQL.MySQL; import de.steamwar.sql.SQL;
import de.warking.hunjy.MySQL.WarkingUser;
import de.steamwar.core.FileManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class Core extends JavaPlugin{ public class Core extends JavaPlugin{
public static MySQL sql;
private static Core instance; 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 if(packageName.contains("1_8"))
version = 8;
else
version = 12;
}
@Override @Override
public void onLoad() { public void onLoad() {
@ -23,26 +32,23 @@ public class Core extends JavaPlugin{
@Override @Override
public void onEnable() { public void onEnable() {
fileManager = new FileManager();
setSql(new MySQL());
Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this); Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this);
Bukkit.getPluginManager().registerEvents(new ChattingEvent(), 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() { public static Core getInstance() {
return instance; return instance;
} }
public FileManager getFileManager() { public static int getVersion(){
return fileManager; return version;
} }
private static void setInstance(Core instance) { private static void setInstance(Core instance) {
Core.instance = instance; Core.instance = instance;
} }
private static void setSql(MySQL sql) {
Core.sql = sql;
}
} }

Datei anzeigen

@ -1,6 +1,5 @@
package de.steamwar.core.events; package de.steamwar.core.events;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
@ -9,7 +8,6 @@ public class ChattingEvent implements Listener {
@EventHandler @EventHandler
private void onChat(AsyncPlayerChatEvent event) { private void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer(); event.setFormat("§eLokal §r"+ event.getPlayer().getDisplayName() + "§8» §7" + event.getMessage());
event.setFormat("§eLokal §r"+ player.getDisplayName() + "§8» §7" + event.getMessage());
} }
} }

Datei anzeigen

@ -1,6 +1,6 @@
package de.steamwar.core.events; package de.steamwar.core.events;
import de.warking.hunjy.MySQL.WarkingUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -13,7 +13,7 @@ public class PlayerJoinedEvent 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.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
switch(user.getUserGroup()){ switch(user.getUserGroup()){
case Admin: case Admin:

Datei anzeigen

@ -0,0 +1,100 @@
package de.steamwar.inventory;
import de.steamwar.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.Material;
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.inventory.Inventory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SWInventory implements Listener {
Player player;
private Map<Integer, InvCallback> callbacks;
Inventory inventory;
public SWInventory(Player p, int size, String t){
callbacks = new HashMap<>();
player = p;
switch(Core.getVersion()){
case 8:
inventory = SWInventory_8.get(p, size, t);
break;
case 14:
inventory = SWInventory_14.get(p, size, t);
break;
default:
inventory = SWInventory_12.get(p, size, t);
}
}
public SWInventory(Player p, int size, String t, Map<Integer, SWItem> items){
this(p, size, t);
items.forEach(this::setItem);
open();
}
public void addCloseCallback(InvCallback c){
callbacks.put(-1, c);
}
public void setItem(int pos, SWItem item){
inventory.setItem(pos, item.getItemStack());
callbacks.put(pos, item.getCallback());
}
public void setItem(int pos, Material m, String name, InvCallback c){
setItem(pos, m, name, new ArrayList<>(), false, c);
}
public void setItem(int pos, Material m, byte meta, String name, InvCallback c){
setItem(pos, m, meta, name, new ArrayList<>(), false, c);
}
public void setItem(int pos, Material m, String name, List<String> lore, boolean e, InvCallback c){
setItem(pos, m, (byte)0, name, lore, e, c);
}
public void setItem(int pos, Material m, byte meta, String name, List<String> lore, boolean e, InvCallback c){
SWItem item = new SWItem(m, meta, name, lore, e, c);
setItem(pos, item);
}
public void setCallback(int pos, InvCallback c){
callbacks.put(pos, c);
}
public void open(){
player.openInventory(inventory);
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
if(!player.equals(e.getWhoClicked()))
return;
e.setCancelled(true);
if(callbacks.containsKey(e.getRawSlot()))
callbacks.get(e.getRawSlot()).clicked(e.getClick());
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent e){
if(!player.equals(e.getPlayer()))
return;
InventoryClickEvent.getHandlerList().unregister(this);
InventoryCloseEvent.getHandlerList().unregister(this);
if(callbacks.containsKey(-1))
callbacks.get(-1).clicked(null);
}
}

Datei anzeigen

@ -1,10 +1,13 @@
package de.steamwar.inventory; package de.steamwar.inventory;
import de.steamwar.core.Core;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -15,6 +18,45 @@ public class SWItem {
private ItemMeta itemMeta; private ItemMeta itemMeta;
private InvCallback callback; 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();
switch(Core.getVersion()){
case 8:
SWItem_8.setSkullOwner(player, headmeta);
break;
default:
SWItem_12.setSkullOwner(player, headmeta);
}
headmeta.setDisplayName(player.getName());
head.setItemMeta(headmeta);
p.setItemStack(head);
return p;
}
public static Material getMaterial(String material){
try{
switch(Core.getVersion()){
case 14:
return SWItem_14.getMaterial(material);
default:
return SWItem_12.getMaterial(material);
}
}catch(IllegalArgumentException e){
return Material.STONE;
}
}
public static Material getDye(int colorCode){
switch(Core.getVersion()){
case 14:
return SWItem_14.getDye(colorCode);
default:
return SWItem_12.getDye();
}
}
public SWItem(){ public SWItem(){
itemStack = new ItemStack(Material.AIR); itemStack = new ItemStack(Material.AIR);
itemMeta = itemStack.getItemMeta(); itemMeta = itemStack.getItemMeta();
@ -30,7 +72,11 @@ public class SWItem {
} }
public SWItem(Material material, byte meta, String name, List<String> lore, boolean enchanted, InvCallback c){ public SWItem(Material material, byte meta, String name, List<String> lore, boolean enchanted, InvCallback c){
try{
itemStack = new ItemStack(material, 1, (short)0, meta); itemStack = new ItemStack(material, 1, (short)0, meta);
}catch(IllegalArgumentException e){
itemStack = new ItemStack(material, 1);
}
itemMeta = itemStack.getItemMeta(); itemMeta = itemStack.getItemMeta();
if(itemMeta != null){ if(itemMeta != null){

Datei anzeigen

@ -1,14 +1,12 @@
package de.steamwar.inventory; package de.steamwar.inventory;
import de.warking.hunjy.MySQL.Schematic; import de.steamwar.sql.Schematic;
import de.warking.hunjy.MySQL.SchematicType; import de.steamwar.sql.SchematicType;
import javafx.util.Pair; 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;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -29,23 +27,23 @@ public class SWListInv<T> extends SWInventory {
@Override @Override
public void open(){ public void open(){
clear(); inventory.clear();
setCallback(-999, (ClickType click) -> player.closeInventory()); setCallback(-999, (ClickType click) -> player.closeInventory());
if(elements.size() > 54){ if(elements.size() > 54){
if(page != 0) if(page != 0)
setItem(45, Material.INK_SACK, (byte)10, "§eSeite zurück", (ClickType click) -> { setItem(45, SWItem.getDye(10), (byte)10, "§eSeite zurück", (ClickType click) -> {
page--; page--;
open(); open();
}); });
else else
setItem(45, Material.INK_SACK, (byte)8, "§7Seite zurück", (ClickType click) -> {}); setItem(45, SWItem.getDye(8), (byte)8, "§7Seite zurück", (ClickType click) -> {});
if(page < elements.size()/45) if(page < elements.size()/45)
setItem(53, Material.INK_SACK, (byte)10, "§eSeite vor", (ClickType click) -> { setItem(53, SWItem.getDye(10), (byte)10, "§eSeite vor", (ClickType click) -> {
page++; page++;
open(); open();
}); });
else else
setItem(53, Material.INK_SACK, (byte)8, "§7Seite vor", (ClickType click) -> {}); setItem(53, SWItem.getDye(8), (byte)8, "§7Seite vor", (ClickType click) -> {});
} }
int ipageLimit = elements.size() - page*45; int ipageLimit = elements.size() - page*45;
@ -78,15 +76,7 @@ public class SWListInv<T> extends SWInventory {
if(without != null && player.getUniqueId().equals(without.getUniqueId())) if(without != null && player.getUniqueId().equals(without.getUniqueId()))
continue; continue;
SWItem p = new SWItem(); onlinePlayers.add(new Pair<>(SWItem.getPlayerSkull(player), player.getUniqueId()));
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()));
} }
return onlinePlayers; return onlinePlayers;
} }
@ -103,9 +93,9 @@ public class SWListInv<T> extends SWInventory {
for(Schematic s : schems){ for(Schematic s : schems){
Material m; Material m;
if(s.getItem().isEmpty()) if(s.getItem().isEmpty())
m = Material.CAULDRON_ITEM; m = SWItem.getMaterial("CAULDRON_ITEM");
else else
m = Material.valueOf(s.getItem()); m = SWItem.getMaterial(s.getItem());
SWItem item = new SWItem(m,"§e" + s.getSchemName()); SWItem item = new SWItem(m,"§e" + s.getSchemName());
schemList.add(new Pair<>(item, s)); schemList.add(new Pair<>(item, s));
} }

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -0,0 +1,70 @@
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(int winner){
SQL.update("UPDATE EventFight SET Ergebnis = " + winner + " 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;
}
}

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package de.warking.hunjy.MySQL; package de.steamwar.sql;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -6,14 +6,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static de.warking.hunjy.Core.sql;
public class Schematic { public class Schematic {
private final String SchemName; private final String schemName;
private final int SchemOwner; private final int schemOwner;
private String Item; private String item;
private SchematicType SchemType; private SchematicType schemType;
private Schematic(ResultSet rs) throws SQLException { private Schematic(ResultSet rs) throws SQLException {
this( this(
@ -25,10 +23,10 @@ public class Schematic {
} }
private Schematic(String schemName, int schemOwner, String item, SchematicType schemType, boolean updateDB){ private Schematic(String schemName, int schemOwner, String item, SchematicType schemType, boolean updateDB){
SchemName = schemName; this.schemName = schemName;
SchemOwner = schemOwner; this.schemOwner = schemOwner;
Item = item; this.item = item;
SchemType = schemType; this.schemType = schemType;
if(updateDB) if(updateDB)
updateDB(); updateDB();
} }
@ -38,25 +36,25 @@ public class Schematic {
} }
public Schematic(String schemName, UUID schemOwner, String item, SchematicType schemType){ 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(){ private void updateDB(){
sql.update("INSERT INTO Schematic" + SQL.update("INSERT INTO Schematic" +
" (SchemName, SchemOwner, Item, SchemType)" + " (SchemName, SchemOwner, Item, SchemType)" +
" VALUES" + " VALUES" +
" ('" + SchemName + "', '" + SchemOwner + "', '" + Item + "', '" + SchemType.toDB() + "')" + " ('" + schemName + "', '" + schemOwner + "', '" + item + "', '" + schemType.toDB() + "')" +
" ON DUPLICATE KEY UPDATE" + " ON DUPLICATE KEY UPDATE" +
" Item = VALUES(Item), SchemType = VALUES(SchemType)"); " Item = VALUES(Item), SchemType = VALUES(SchemType)");
} }
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){ 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){ public static Schematic getSchemFromDB(String schemName, int schemOwner){
schemName = MySQL.disarmString(schemName); schemName = SQL.disarmString(schemName);
ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemName = '" + schemName + "' AND 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()){
SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner); SchematicMember member = SchematicMember.getMemberBySchematic(schemName, schemOwner);
@ -73,12 +71,12 @@ public class Schematic {
} }
public static List<Schematic> getSchemsAccessibleByUser(UUID schemOwner){ 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){ public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
try{ 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<>(); List<Schematic> schematics = new ArrayList<>();
while(schematic.next()){ while(schematic.next()){
schematics.add(new Schematic(schematic)); schematics.add(new Schematic(schematic));
@ -95,7 +93,7 @@ public class Schematic {
} }
public static List<Schematic> getSchemsOfType(UUID schemOwner, SchematicType schemType){ 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){ public static List<Schematic> getSchemsOfType(int schemOwner, SchematicType schemType){
@ -110,7 +108,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 * FROM Schematic WHERE SchemType = '" + schemType.toDB() + "'"); ResultSet schematic = SQL.select("SELECT * 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));
@ -123,33 +121,33 @@ public class Schematic {
} }
public String getSchemName() { public String getSchemName() {
return SchemName; return schemName;
} }
public int getSchemOwner() { public int getSchemOwner() {
return SchemOwner; return schemOwner;
} }
public String getItem() { public String getItem() {
return Item; return item;
} }
public void setItem(String item) { public void setItem(String item) {
Item = item; this.item = item;
updateDB(); updateDB();
} }
public SchematicType getSchemType() { public SchematicType getSchemType() {
return SchemType; return schemType;
} }
public void setSchemType(SchematicType schemType) { public void setSchemType(SchematicType schemType) {
SchemType = schemType; this.schemType = schemType;
updateDB(); updateDB();
} }
public void remove(){ public void remove(){
sql.update("DELETE FROM Schematic 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 + "'"); SQL.update("DELETE FROM SchemMember WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
} }
} }

Datei anzeigen

@ -1,4 +1,4 @@
package de.warking.hunjy.MySQL; package de.steamwar.sql;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -6,17 +6,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static de.warking.hunjy.Core.sql;
public class SchematicMember { public class SchematicMember {
private final int SchemOwner; private final int schemOwner;
private final String SchemName; private final String schemName;
private final int Member; private final int member;
private SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDB){ private SchematicMember(String schemName, int schemOwner, int schemMember, boolean updateDB){
SchemOwner = schemOwner; this.schemOwner = schemOwner;
Member = schemMember; member = schemMember;
SchemName = schemName; this.schemName = schemName;
if(updateDB) if(updateDB)
updateDB(); updateDB();
} }
@ -26,35 +24,34 @@ public class SchematicMember {
} }
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){ 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(){ private void updateDB(){
sql.update("INSERT INTO SchemMember" + SQL.update("INSERT INTO SchemMember" +
" (SchemName, SchemOwner, Member)" + " (SchemName, SchemOwner, Member)" +
" VALUES" + " VALUES" +
" ('" + SchemName + "', '" + SchemOwner + "', '" + Member + "')"); " ('" + schemName + "', '" + schemOwner + "', '" + member + "')");
} }
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){ 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){ 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 { try {
if(schematicMember == null || !schematicMember.next()){ if(schematicMember == null || !schematicMember.next()){
return null; return null;
} }
return new SchematicMember(schemName, schemOwner, schemMember, false); return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); throw new SecurityException("Could not get schemmember", e);
} }
return null;
} }
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 = '" + schemName + "' AND Member = '" + schemMember + "'");
try { try {
if(schematicMember == null || !schematicMember.next()){ if(schematicMember == null || !schematicMember.next()){
return null; return null;
@ -62,17 +59,16 @@ public class SchematicMember {
int schemOwner = schematicMember.getInt("SchemOwner"); int schemOwner = schematicMember.getInt("SchemOwner");
return new SchematicMember(schemName, schemOwner, schemMember, false); return new SchematicMember(schemName, schemOwner, schemMember, false);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); throw new SecurityException("Could not get member", e);
} }
return null;
} }
public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){ 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){ 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 { try {
List<SchematicMember> schematicMembers = new ArrayList<>(); List<SchematicMember> schematicMembers = new ArrayList<>();
while(schematicMember.next()){ while(schematicMember.next()){
@ -81,17 +77,16 @@ public class SchematicMember {
} }
return schematicMembers; return schematicMembers;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); throw new SecurityException("Could not get schemmembers", e);
} }
return null;
} }
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){ 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){ 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()){
@ -101,24 +96,23 @@ public class SchematicMember {
} }
return schematicMembers; return schematicMembers;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); throw new SecurityException("Could not get accessible schems", e);
} }
return null;
} }
public int getSchemOwner() { public int getSchemOwner() {
return SchemOwner; return schemOwner;
} }
public String getSchemName() { public String getSchemName() {
return SchemName; return schemName;
} }
public int getMember() { public int getMember() {
return Member; return member;
} }
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 = " + schemOwner + " AND SchemName = '" + schemName + "' AND Member = '" + member + "'");
} }
} }

Datei anzeigen

@ -1,4 +1,4 @@
package de.warking.hunjy.MySQL; package de.steamwar.sql;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -13,10 +13,14 @@ public enum SchematicType {
WarGear("WG", Type.FIGHT_TYPE, CWarGear), WarGear("WG", Type.FIGHT_TYPE, CWarGear),
WarShip("WS", Type.FIGHT_TYPE, CWarShip), WarShip("WS", Type.FIGHT_TYPE, CWarShip),
MiniWarGear("MWG", Type.FIGHT_TYPE, CMiniWarGear), MiniWarGear("MWG", Type.FIGHT_TYPE, CMiniWarGear),
CGearUp("CGU", Type.CHECK_TYPE),
GearUp("GU", Type.FIGHT_TYPE, CGearUp),
CEiszeit("CEZ", Type.CHECK_TYPE), CEiszeit("CEZ", Type.CHECK_TYPE),
Eiszeit("EZ", Type.FIGHT_TYPE); Eiszeit("EZ", Type.FIGHT_TYPE),
CWarShip1_8("CWS1.8", Type.CHECK_TYPE),
CWarGear1_7("CWG1.7", Type.CHECK_TYPE),
WarShip1_8("WS1.8", Type.FIGHT_TYPE, CWarShip1_8),
WarGear1_7("WG1.7", Type.FIGHT_TYPE, CWarGear1_7),
CMPPWarGear1_12("CMPPWG", Type.CHECK_TYPE),
MPPWarGear1_12("MPPWG", Type.FIGHT_TYPE, CMPPWarGear1_12);
private static Map<String, SchematicType> fromDB = new HashMap<>(); private static Map<String, SchematicType> fromDB = new HashMap<>();

Datei anzeigen

@ -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 = 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;
}
}

Datei anzeigen

@ -0,0 +1,67 @@
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 static final Team pub = new Team(0, "PUB", "Öffentlich", 0);
private Team(int teamId, String teamKuerzel, String teamName, int teamLeader){
this.teamId = teamId;
this.teamKuerzel = teamKuerzel;
this.teamName = teamName;
this.teamLeader = teamLeader;
}
private Team(ResultSet rs) throws SQLException {
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getInt("TeamLeader"));
}
public static Team get(int id){
if(id == 0)
return pub;
ResultSet rs = SQL.select("SELECT * FROM Team WHERE TeamID = " + id);
try {
if(!rs.next())
return null;
return new Team(rs);
} catch (SQLException e) {
throw new SecurityException("Could not load team", e);
}
}
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);
}
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package de.warking.hunjy.MySQL; package de.steamwar.sql;
public enum UserGroup { public enum UserGroup {
Admin, Admin,

Datei anzeigen

@ -0,0 +1,7 @@
name: SpigotCore
version: 1.0
author: Lixfel
api-version: 1.13
main: de.steamwar.core.Core
commands:

33
pom.xml
Datei anzeigen

@ -4,10 +4,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<groupId>de.warking</groupId> <groupId>steamwar</groupId>
<artifactId>SpigotCore</artifactId> <artifactId>SpigotCore</artifactId>
<version>1.0</version> <version>2.0</version>
<packaging>jar</packaging> <packaging>pom</packaging>
<url>https://maven.apache.org</url> <url>https://maven.apache.org</url>
<properties> <properties>
@ -17,21 +17,11 @@
<repositories> <repositories>
<repository> <repository>
<id>steamwar</id> <id>steamwar</id>
<url>https://steamwar.de/maven/</url> <url>https://steamwar.de:81/maven/</url>
</repository> </repository>
</repositories> </repositories>
<build> <build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -43,14 +33,13 @@
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
<finalName>${project.name}</finalName>
</build> </build>
<dependencies> <modules>
<dependency> <module>SpigotCore_8</module>
<groupId>steamwar</groupId> <module>SpigotCore_12</module>
<artifactId>Spigot</artifactId> <module>SpigotCore_14</module>
<version>1.0</version> <module>SpigotCore_Main</module>
<scope>provided</scope> </modules>
</dependency>
</dependencies>
</project> </project>

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -1,284 +0,0 @@
package de.steamwar.inventory;
import de.warking.hunjy.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.*;
public class SWInventory implements Listener, Inventory {
Player player;
private Map<Integer, InvCallback> callbacks;
private int inventorySize;
private ItemStack[] contents;
private String title;
public SWInventory(Player p, int size, String t){
title = t;
callbacks = new HashMap<>();
player = p;
inventorySize = size;
contents = new ItemStack[inventorySize];
}
public SWInventory(Player p, int size, String t, Map<Integer, SWItem> items){
this(p, size, t);
items.forEach(this::setItem);
open();
}
public void addCloseCallback(InvCallback c){
callbacks.put(-1, c);
}
public void setItem(int pos, SWItem item){
contents[pos] = item.getItemStack();
callbacks.put(pos, item.getCallback());
}
public void setItem(int pos, Material m, String name, InvCallback c){
setItem(pos, m, name, new ArrayList<>(), false, c);
}
public void setItem(int pos, Material m, byte meta, String name, InvCallback c){
setItem(pos, m, meta, name, new ArrayList<>(), false, c);
}
public void setItem(int pos, Material m, String name, List<String> lore, boolean e, InvCallback c){
setItem(pos, m, (byte)0, name, lore, e, c);
}
public void setItem(int pos, Material m, byte meta, String name, List<String> lore, boolean e, InvCallback c){
SWItem item = new SWItem(m, meta, name, lore, e, c);
setItem(pos, item);
}
public void setCallback(int pos, InvCallback c){
callbacks.put(pos, c);
}
public void open(){
player.openInventory(this);
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
if(!player.equals(e.getWhoClicked()))
return;
e.setCancelled(true);
if(callbacks.containsKey(e.getRawSlot()))
callbacks.get(e.getSlot()).clicked(e.getClick());
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent e){
if(!player.equals(e.getPlayer()))
return;
InventoryClickEvent.getHandlerList().unregister(this);
InventoryCloseEvent.getHandlerList().unregister(this);
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;
}
}

Datei anzeigen

@ -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("'", "");
}
}

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -1,8 +0,0 @@
name: CoreSystem
version: 1.0
author: hunjy, Lixfel
main: de.warking.hunjy.Core
commands: