Allow querying for item types in chestaccess

This commit is contained in:
Brokkonaut
2018-07-31 03:01:26 +02:00
parent 58e5cdf890
commit 6680e9e3eb
6 changed files with 21 additions and 11 deletions

View File

@ -57,7 +57,7 @@ public class BlockChange implements LookupCacheElement {
if (p.needChestAccess) {
ItemStack stack = Utils.loadItemStack(rs.getBytes("item"));
if (stack != null) {
catemp = new ChestAccess(stack, rs.getBoolean("itemremove"));
catemp = new ChestAccess(stack, rs.getBoolean("itemremove"), rs.getInt("itemtype"));
}
}
ca = catemp;

View File

@ -5,9 +5,11 @@ import org.bukkit.inventory.ItemStack;
public class ChestAccess {
final ItemStack itemStack;
final boolean remove;
final int itemType;
public ChestAccess(ItemStack itemStack, boolean remove) {
public ChestAccess(ItemStack itemStack, boolean remove, int itemType) {
this.itemStack = itemStack;
this.remove = remove;
this.itemType = itemType;
}
}

View File

@ -664,7 +664,7 @@ public class CommandsHandler implements CommandExecutor {
ChestAccess chestaccess = null;
ItemStack stack = Utils.loadItemStack(rs.getBytes("item"));
if (stack != null) {
chestaccess = new ChestAccess(stack, rs.getBoolean("itemremove"));
chestaccess = new ChestAccess(stack, rs.getBoolean("itemremove"), rs.getInt("itemtype"));
}
editor.queueEdit(rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getInt("replaced"), rs.getInt("replacedData"), rs.getBytes("replacedState"), rs.getInt("type"), rs.getInt("typeData"), rs.getBytes("typeState"), chestaccess);
}
@ -738,7 +738,7 @@ public class CommandsHandler implements CommandExecutor {
ChestAccess chestaccess = null;
ItemStack stack = Utils.loadItemStack(rs.getBytes("item"));
if (stack != null) {
chestaccess = new ChestAccess(stack, !rs.getBoolean("itemremove"));
chestaccess = new ChestAccess(stack, !rs.getBoolean("itemremove"), rs.getInt("itemtype"));
}
editor.queueEdit(rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getInt("type"), rs.getInt("typeData"), rs.getBytes("typeState"), rs.getInt("replaced"), rs.getInt("replacedData"), rs.getBytes("replacedState"), chestaccess);
}

View File

@ -212,7 +212,7 @@ public class Consumer extends TimerTask {
* Data of the item taken/stored
*/
public void queueChestAccess(Actor actor, Location loc, BlockData type, ItemStack itemStack, boolean remove) {
queueBlock(actor, loc, type, type, null, null, new ChestAccess(itemStack, remove));
queueBlock(actor, loc, type, type, null, null, new ChestAccess(itemStack, remove, MaterialConverter.getOrAddMaterialId(itemStack.getType().getKey())));
}
/**
@ -682,7 +682,7 @@ public class Consumer extends TimerTask {
if (replacedState != null || typeState != null) {
inserts[1] = "INSERT INTO `" + table + "-state` (replacedState, typeState, id) VALUES('" + Utils.mysqlEscapeBytes(replacedState) + "', '" + Utils.mysqlEscapeBytes(typeState) + "', LAST_INSERT_ID());";
} else if (ca != null) {
inserts[1] = "INSERT INTO `" + table + "-chestdata` (id, item, itemremoved) values (LAST_INSERT_ID(), '" + Utils.mysqlEscapeBytes(Utils.saveItemStack(ca.itemStack)) + "', " + (ca.remove ? 1 : 0) + ");";
inserts[1] = "INSERT INTO `" + table + "-chestdata` (id, item, itemremoved, itemtype) values (LAST_INSERT_ID(), '" + Utils.mysqlEscapeBytes(Utils.saveItemStack(ca.itemStack)) + "', " + (ca.remove ? 1 : 0) + ", " + ca.itemType + ");";
}
return inserts;
}
@ -732,10 +732,11 @@ public class Consumer extends TimerTask {
ps.setInt(3, id);
ps.executeUpdate();
} else if (ca != null) {
ps = connection.prepareStatement("INSERT INTO `" + table + "-chestdata` (item, itemremove, id) values (?, ?, ?)");
ps = connection.prepareStatement("INSERT INTO `" + table + "-chestdata` (item, itemremove, id, itemtype) values (?, ?, ?, ?)");
ps.setBytes(1, Utils.saveItemStack(ca.itemStack));
ps.setInt(2, ca.remove ? 1 : 0);
ps.setInt(3, id);
ps.setInt(4, ca.itemType);
ps.executeUpdate();
}
} catch (final SQLException ex) {

View File

@ -149,7 +149,7 @@ public final class QueryParams implements Cloneable {
select += "replacedState, typeState, ";
}
if (needChestAccess) {
select += "item, itemremove, ";
select += "item, itemremove, itemtype, ";
}
select = select.substring(0, select.length() - 2);
}
@ -605,7 +605,7 @@ public final class QueryParams implements Cloneable {
throw new IllegalArgumentException("No or wrong count of arguments for '" + param + "'");
}
for (final String weaponName : values) {
Material mat = Material.matchMaterial(weaponName);
Material mat = weaponName.equalsIgnoreCase("fist") ? Material.AIR : Material.matchMaterial(weaponName);
if (mat == null) {
throw new IllegalArgumentException("No material matching: '" + weaponName + "'");
}

View File

@ -514,7 +514,7 @@ class Updater {
}
rs.close();
PreparedStatement insertChestData = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-chestdata` (id, item, itemremove) VALUES (?, ?, ?)");
PreparedStatement insertChestData = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-chestdata` (id, item, itemremove, itemtype) VALUES (?, ?, ?, ?)");
PreparedStatement deleteChest = conn.prepareStatement("DELETE FROM `" + wcfg.table + "-chest` WHERE id = ?");
while (true) {
rs = st.executeQuery("SELECT id, itemtype, itemamount, itemdata FROM `" + wcfg.table + "-chest` ORDER BY id ASC LIMIT 10000");
@ -533,6 +533,7 @@ class Updater {
insertChestData.setInt(1, id);
insertChestData.setBytes(2, Utils.saveItemStack(stack));
insertChestData.setInt(3, amount >= 0 ? 0 : 1);
insertChestData.setInt(4, MaterialConverter.getOrAddMaterialId(weaponMaterial.getKey()));
insertChestData.addBatch();
deleteChest.setInt(1, id);
@ -632,6 +633,12 @@ class Updater {
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
getLogger().info("Processing world " + wcfg.world + "...");
ResultSet rsCol = st.executeQuery("SHOW COLUMNS FROM `" + wcfg.table + "-chestdata` LIKE 'itemtype'");
if (!rsCol.next()) {
st.execute("ALTER TABLE `" + wcfg.table + "-chestdata` ADD COLUMN `itemtype` SMALLINT NOT NULL DEFAULT '0'");
}
rsCol.close();
conn.commit();
if (wcfg.isLogging(Logging.SIGNTEXT)) {
int rowsToConvert = 0;
int done = 0;
@ -747,7 +754,7 @@ class Updater {
for (final WorldConfig wcfg : getLoggedWorlds()) {
createTable(dbm, state, wcfg.table + "-blocks", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, replaced SMALLINT UNSIGNED NOT NULL, replacedData SMALLINT NOT NULL, type SMALLINT UNSIGNED NOT NULL, typeData SMALLINT NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT UNSIGNED NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))");
// createTable(dbm, state, wcfg.table + "-sign", "(id INT UNSIGNED NOT NULL, signtext VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset);
createTable(dbm, state, wcfg.table + "-chestdata", "(id INT UNSIGNED NOT NULL, item MEDIUMBLOB, itemremove TINYINT, PRIMARY KEY (id))");
createTable(dbm, state, wcfg.table + "-chestdata", "(id INT UNSIGNED NOT NULL, item MEDIUMBLOB, itemremove TINYINT, itemtype SMALLINT NOT NULL DEFAULT '0', PRIMARY KEY (id))");
createTable(dbm, state, wcfg.table + "-state", "(id INT UNSIGNED NOT NULL, replacedState MEDIUMBLOB NULL, typeState MEDIUMBLOB NULL, PRIMARY KEY (id))");
if (wcfg.isLogging(Logging.KILL)) {
createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer INT UNSIGNED, victim INT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id))");