1
0
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:
j502647092 2015-07-16 19:37:58 +08:00
parent 2e63f5643e
commit 962eed36e2
2 changed files with 197 additions and 198 deletions

View File

@ -1,21 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,177 +1,177 @@
package cn.citycraft.RealBackpacks.util;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
public class MysqlFunctions {
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
public static void addBackpackData(final String playerName,
final String backpack, final List<String> invString)
throws SQLException {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()
+ "?"
+ "user="
+ plugin.getUser()
+ "&password="
+ plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager
.getConnection(url);
PreparedStatement statement = conn
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, playerName);
statement.setString(2, backpack);
final ResultSet res = statement.executeQuery();
PreparedStatement state = null;
if (res.next()) {
if (res.getInt(1) == 1) {
state = conn
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
state.setString(4, playerName);
state.setString(5, backpack);
} else {
state = conn
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
}
}
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static boolean checkIfTableExists(final String table) {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
state.close();
conn.close();
if (tables.next())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
return false;
}
public static void createTables() {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
public static void delete(final String playerName, final String backpack) {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()
+ "?"
+ "user="
+ plugin.getUser()
+ "&password="
+ plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager
.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static Inventory getBackpackInv(final String playerName,
final String backpack) throws SQLException {
Inventory returnInv = null;
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
state.setString(1, playerName);
state.setString(2, backpack);
final ResultSet res = state.executeQuery();
if (res.next()) {
final String invString = res.getString(1);
if (invString != null) {
returnInv = Serialization.toInventory(Serialization
.stringToList(invString), ChatColor
.translateAlternateColorCodes('&',
plugin.backpackData.get(backpack).get(3)),
Integer.parseInt(plugin.backpackData.get(backpack)
.get(0)));
} else {
returnInv = null;
}
}
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
return returnInv;
}
public static void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}
package cn.citycraft.RealBackpacks.util;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
public class MysqlFunctions {
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
public static void addBackpackData(final String playerName,
final String backpack, final List<String> invString)
throws SQLException {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()
+ "?"
+ "user="
+ plugin.getUser()
+ "&password="
+ plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager
.getConnection(url);
PreparedStatement statement = conn
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, playerName);
statement.setString(2, backpack);
final ResultSet res = statement.executeQuery();
PreparedStatement state = null;
if (res.next()) {
if (res.getInt(1) == 1) {
state = conn
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
state.setString(4, playerName);
state.setString(5, backpack);
} else {
state = conn
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
}
}
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static boolean checkIfTableExists(final String table) {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
state.close();
conn.close();
if (tables.next())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
return false;
}
public static void createTables() {
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
public static void delete(final String playerName, final String backpack) {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()
+ "?"
+ "user="
+ plugin.getUser()
+ "&password="
+ plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager
.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static Inventory getBackpackInv(final String playerName,
final String backpack) throws SQLException {
Inventory returnInv = null;
try {
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
+ "&password=" + plugin.getPass()
+ "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
final PreparedStatement state = conn
.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
state.setString(1, playerName);
state.setString(2, backpack);
final ResultSet res = state.executeQuery();
if (res.next()) {
final String invString = res.getString(1);
if (invString != null) {
returnInv = Serialization.toInventory(Serialization
.stringToList(invString), ChatColor
.translateAlternateColorCodes('&',
plugin.backpackData.get(backpack).get(3)),
Integer.parseInt(plugin.backpackData.get(backpack)
.get(0)));
} else {
returnInv = null;
}
}
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
return returnInv;
}
public static void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}