mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2024-12-04 03:49:07 +00:00
rebuilt project...
This commit is contained in:
parent
2e63f5643e
commit
962eed36e2
41
.classpath
41
.classpath
@ -1,21 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="lib" path="lib/Vault.jar"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
<attributes>
|
||||||
<attributes>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
</attributes>
|
||||||
</attributes>
|
</classpathentry>
|
||||||
</classpathentry>
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<attributes>
|
||||||
<attributes>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
</attributes>
|
||||||
</attributes>
|
</classpathentry>
|
||||||
</classpathentry>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
</classpath>
|
||||||
</classpath>
|
|
||||||
|
@ -1,177 +1,177 @@
|
|||||||
package cn.citycraft.RealBackpacks.util;
|
package cn.citycraft.RealBackpacks.util;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import cn.citycraft.RealBackpacks.RealBackpacks;
|
import cn.citycraft.RealBackpacks.RealBackpacks;
|
||||||
|
|
||||||
public class MysqlFunctions {
|
public class MysqlFunctions {
|
||||||
|
|
||||||
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
|
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
|
||||||
|
|
||||||
public static void addBackpackData(final String playerName,
|
public static void addBackpackData(final String playerName,
|
||||||
final String backpack, final List<String> invString)
|
final String backpack, final List<String> invString)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
plugin.getServer().getScheduler()
|
plugin.getServer().getScheduler()
|
||||||
.runTaskAsynchronously(plugin, new Runnable() {
|
.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl()
|
String url = plugin.getUrl()
|
||||||
+ "?"
|
+ "?"
|
||||||
+ "user="
|
+ "user="
|
||||||
+ plugin.getUser()
|
+ plugin.getUser()
|
||||||
+ "&password="
|
+ "&password="
|
||||||
+ plugin.getPass()
|
+ plugin.getPass()
|
||||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||||
final Connection conn = DriverManager
|
final Connection conn = DriverManager
|
||||||
.getConnection(url);
|
.getConnection(url);
|
||||||
PreparedStatement statement = conn
|
PreparedStatement statement = conn
|
||||||
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
||||||
statement.setString(1, playerName);
|
statement.setString(1, playerName);
|
||||||
statement.setString(2, backpack);
|
statement.setString(2, backpack);
|
||||||
final ResultSet res = statement.executeQuery();
|
final ResultSet res = statement.executeQuery();
|
||||||
PreparedStatement state = null;
|
PreparedStatement state = null;
|
||||||
if (res.next()) {
|
if (res.next()) {
|
||||||
if (res.getInt(1) == 1) {
|
if (res.getInt(1) == 1) {
|
||||||
state = conn
|
state = conn
|
||||||
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
state.setString(3, Serialization
|
state.setString(3, Serialization
|
||||||
.listToString(invString));
|
.listToString(invString));
|
||||||
state.setString(4, playerName);
|
state.setString(4, playerName);
|
||||||
state.setString(5, backpack);
|
state.setString(5, backpack);
|
||||||
} else {
|
} else {
|
||||||
state = conn
|
state = conn
|
||||||
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
state.setString(3, Serialization
|
state.setString(3, Serialization
|
||||||
.listToString(invString));
|
.listToString(invString));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.executeUpdate();
|
state.executeUpdate();
|
||||||
state.close();
|
state.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkIfTableExists(final String table) {
|
public static boolean checkIfTableExists(final String table) {
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||||
+ "&password=" + plugin.getPass()
|
+ "&password=" + plugin.getPass()
|
||||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||||
final Connection conn = DriverManager.getConnection(url);
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final Statement state = conn.createStatement();
|
final Statement state = conn.createStatement();
|
||||||
final DatabaseMetaData dbm = conn.getMetaData();
|
final DatabaseMetaData dbm = conn.getMetaData();
|
||||||
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
|
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
|
||||||
state.close();
|
state.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
if (tables.next())
|
if (tables.next())
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createTables() {
|
public static void createTables() {
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||||
+ "&password=" + plugin.getPass()
|
+ "&password=" + plugin.getPass()
|
||||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||||
final Connection conn = DriverManager.getConnection(url);
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final PreparedStatement state = conn
|
final PreparedStatement state = conn
|
||||||
.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
|
.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
|
||||||
state.executeUpdate();
|
state.executeUpdate();
|
||||||
state.close();
|
state.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void delete(final String playerName, final String backpack) {
|
public static void delete(final String playerName, final String backpack) {
|
||||||
plugin.getServer().getScheduler()
|
plugin.getServer().getScheduler()
|
||||||
.runTaskAsynchronously(plugin, new Runnable() {
|
.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl()
|
String url = plugin.getUrl()
|
||||||
+ "?"
|
+ "?"
|
||||||
+ "user="
|
+ "user="
|
||||||
+ plugin.getUser()
|
+ plugin.getUser()
|
||||||
+ "&password="
|
+ "&password="
|
||||||
+ plugin.getPass()
|
+ plugin.getPass()
|
||||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||||
final Connection conn = DriverManager
|
final Connection conn = DriverManager
|
||||||
.getConnection(url);
|
.getConnection(url);
|
||||||
final PreparedStatement state = conn
|
final PreparedStatement state = conn
|
||||||
.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
|
.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
state.executeUpdate();
|
state.executeUpdate();
|
||||||
state.close();
|
state.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Inventory getBackpackInv(final String playerName,
|
public static Inventory getBackpackInv(final String playerName,
|
||||||
final String backpack) throws SQLException {
|
final String backpack) throws SQLException {
|
||||||
Inventory returnInv = null;
|
Inventory returnInv = null;
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||||
+ "&password=" + plugin.getPass()
|
+ "&password=" + plugin.getPass()
|
||||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||||
final Connection conn = DriverManager.getConnection(url);
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final PreparedStatement state = conn
|
final PreparedStatement state = conn
|
||||||
.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
final ResultSet res = state.executeQuery();
|
final ResultSet res = state.executeQuery();
|
||||||
if (res.next()) {
|
if (res.next()) {
|
||||||
final String invString = res.getString(1);
|
final String invString = res.getString(1);
|
||||||
if (invString != null) {
|
if (invString != null) {
|
||||||
returnInv = Serialization.toInventory(Serialization
|
returnInv = Serialization.toInventory(Serialization
|
||||||
.stringToList(invString), ChatColor
|
.stringToList(invString), ChatColor
|
||||||
.translateAlternateColorCodes('&',
|
.translateAlternateColorCodes('&',
|
||||||
plugin.backpackData.get(backpack).get(3)),
|
plugin.backpackData.get(backpack).get(3)),
|
||||||
Integer.parseInt(plugin.backpackData.get(backpack)
|
Integer.parseInt(plugin.backpackData.get(backpack)
|
||||||
.get(0)));
|
.get(0)));
|
||||||
} else {
|
} else {
|
||||||
returnInv = null;
|
returnInv = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.close();
|
state.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return returnInv;
|
return returnInv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMysqlFunc(final RealBackpacks plugin) {
|
public static void setMysqlFunc(final RealBackpacks plugin) {
|
||||||
MysqlFunctions.plugin = plugin;
|
MysqlFunctions.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user