Initial release v1.0.0
This commit is contained in:
commit
3fef65b903
314 files changed
+27448
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package com.rsscripting.rswarehouse.deposit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public final class DepositInventory {
|
||||
|
||||
private static final String TITLE = "Warehouse Deposit";
|
||||
|
||||
private DepositInventory() {
|
||||
}
|
||||
|
||||
public static void open(Player player) {
|
||||
|
||||
Inventory inventory = Bukkit.createInventory(
|
||||
new DepositInventoryHolder(),
|
||||
54,
|
||||
TITLE
|
||||
);
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.rsscripting.rswarehouse.deposit;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public final class DepositInventoryHolder implements InventoryHolder {
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
package com.rsscripting.rswarehouse.deposit;
|
||||
|
||||
import com.rsscripting.rswarehouse.deposit.dao.ChestDAO;
|
||||
import com.rsscripting.rswarehouse.inventory.inventorydao.InventoryCreationDAO;
|
||||
import com.rsscripting.rswarehouse.inventory.inventorydao.InventoryLookupDAO;
|
||||
import com.rsscripting.rswarehouse.variants.dao.DamagedVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.variants.dao.EnchantedVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.variants.dao.PartiallyFilledVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.config.ConfigManager;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
|
||||
public class WarehouseChestProcessor {
|
||||
|
||||
public static int[] processWarehouseChest(
|
||||
Chest chest
|
||||
) {
|
||||
|
||||
int processedStacks = 0;
|
||||
int processedItems = 0;
|
||||
|
||||
String ownerUuid =
|
||||
ChestDAO.getOwnerUuid(
|
||||
chest.getBlock()
|
||||
);
|
||||
|
||||
String ownerName =
|
||||
ChestDAO.getOwnerName(
|
||||
chest.getBlock()
|
||||
);
|
||||
|
||||
ItemStack[] contents =
|
||||
chest.getInventory()
|
||||
.getContents();
|
||||
|
||||
boolean allowUncategorizedItemCreation =
|
||||
ConfigManager.get()
|
||||
.getBoolean(
|
||||
"allow-uncategorized-item-creation"
|
||||
);
|
||||
|
||||
boolean allowDamagedItemCreation =
|
||||
ConfigManager.get()
|
||||
.getBoolean(
|
||||
"allow-damaged-item-creation"
|
||||
);
|
||||
|
||||
for (ItemStack item : contents) {
|
||||
|
||||
if (item == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
int amount =
|
||||
item.getAmount();
|
||||
|
||||
ItemStack baseItem =
|
||||
ItemStackUtils.createBaseItem(
|
||||
item
|
||||
);
|
||||
|
||||
Integer parentId =
|
||||
InventoryLookupDAO.findInventoryId(
|
||||
baseItem
|
||||
);
|
||||
|
||||
if (parentId == null) {
|
||||
|
||||
if (!allowUncategorizedItemCreation) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
parentId =
|
||||
InventoryCreationDAO.createParentInventoryItem(
|
||||
baseItem,
|
||||
ownerUuid,
|
||||
ownerName
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Damaged item test path
|
||||
*/
|
||||
|
||||
if (
|
||||
item.hasItemMeta()
|
||||
&& item.getItemMeta()
|
||||
instanceof Damageable damageable
|
||||
&& damageable.getDamage() > 0
|
||||
) {
|
||||
|
||||
if (!allowDamagedItemCreation) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
DamagedVariantsDAO.createDamagedVariant(
|
||||
parentId,
|
||||
item
|
||||
);
|
||||
|
||||
item.setAmount(
|
||||
0
|
||||
);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Enchanted item test path
|
||||
*/
|
||||
|
||||
if (
|
||||
item.hasItemMeta()
|
||||
&& item.getItemMeta().hasEnchants()
|
||||
) {
|
||||
|
||||
EnchantedVariantsDAO.createEnchantedVariant(
|
||||
parentId,
|
||||
item
|
||||
);
|
||||
|
||||
item.setAmount(
|
||||
0
|
||||
);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Partially Filled item test path
|
||||
*/
|
||||
|
||||
if (
|
||||
ItemStackUtils.hasStoredContents(
|
||||
item
|
||||
)
|
||||
) {
|
||||
|
||||
PartiallyFilledVariantsDAO.createPartiallyFilledVariant(
|
||||
parentId,
|
||||
item
|
||||
);
|
||||
|
||||
item.setAmount(
|
||||
0
|
||||
);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
ItemDAO.addItem(
|
||||
ownerUuid,
|
||||
ownerName,
|
||||
baseItem,
|
||||
item.getAmount(),
|
||||
parentId
|
||||
);
|
||||
|
||||
item.setAmount(
|
||||
0
|
||||
);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
}
|
||||
|
||||
return new int[] {
|
||||
processedStacks,
|
||||
processedItems
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static int[] processDepositInventory(
|
||||
Inventory inventory,
|
||||
String ownerUuid,
|
||||
String ownerName
|
||||
) {
|
||||
|
||||
int processedStacks = 0;
|
||||
int processedItems = 0;
|
||||
|
||||
ItemStack[] contents =
|
||||
inventory.getContents();
|
||||
|
||||
boolean allowUncategorizedItemCreation =
|
||||
ConfigManager.get()
|
||||
.getBoolean(
|
||||
"allow-uncategorized-item-creation"
|
||||
);
|
||||
|
||||
boolean allowDamagedItemCreation =
|
||||
ConfigManager.get()
|
||||
.getBoolean(
|
||||
"allow-damaged-item-creation"
|
||||
);
|
||||
|
||||
for (ItemStack item : contents) {
|
||||
|
||||
if (item == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
int amount =
|
||||
item.getAmount();
|
||||
|
||||
ItemStack baseItem =
|
||||
ItemStackUtils.createBaseItem(
|
||||
item
|
||||
);
|
||||
|
||||
Integer parentId =
|
||||
InventoryLookupDAO.findInventoryId(
|
||||
baseItem
|
||||
);
|
||||
|
||||
if (parentId == null) {
|
||||
|
||||
if (!allowUncategorizedItemCreation) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
parentId =
|
||||
InventoryCreationDAO.createParentInventoryItem(
|
||||
baseItem,
|
||||
ownerUuid,
|
||||
ownerName
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
item.hasItemMeta()
|
||||
&& item.getItemMeta()
|
||||
instanceof Damageable damageable
|
||||
&& damageable.getDamage() > 0
|
||||
) {
|
||||
|
||||
if (!allowDamagedItemCreation) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
DamagedVariantsDAO.createDamagedVariant(
|
||||
parentId,
|
||||
item
|
||||
);
|
||||
|
||||
item.setAmount(0);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
item.hasItemMeta()
|
||||
&& item.getItemMeta().hasEnchants()
|
||||
) {
|
||||
|
||||
EnchantedVariantsDAO.createEnchantedVariant(
|
||||
parentId,
|
||||
item
|
||||
);
|
||||
|
||||
item.setAmount(0);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
ItemStackUtils.hasStoredContents(
|
||||
item
|
||||
)
|
||||
) {
|
||||
|
||||
PartiallyFilledVariantsDAO.createPartiallyFilledVariant(
|
||||
parentId,
|
||||
item
|
||||
);
|
||||
|
||||
item.setAmount(0);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
ItemDAO.addItem(
|
||||
ownerUuid,
|
||||
ownerName,
|
||||
baseItem,
|
||||
item.getAmount(),
|
||||
parentId
|
||||
);
|
||||
|
||||
item.setAmount(0);
|
||||
|
||||
processedStacks++;
|
||||
processedItems += amount;
|
||||
|
||||
}
|
||||
|
||||
return new int[] {
|
||||
processedStacks,
|
||||
processedItems
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.rsscripting.rswarehouse.deposit;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.PurgeVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.deposit.dao.VerifyIsChestDAO;
|
||||
import com.rsscripting.rswarehouse.config.ConfigManager;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class WarehouseCloseListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
boolean chestCloseProcessingEnabled =
|
||||
ConfigManager.get()
|
||||
.getBoolean(
|
||||
"chest-close-processing.enabled"
|
||||
);
|
||||
|
||||
if (!chestCloseProcessingEnabled) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getPlayer();
|
||||
|
||||
InventoryHolder holder =
|
||||
event.getInventory()
|
||||
.getHolder();
|
||||
|
||||
Chest chest;
|
||||
|
||||
if (holder instanceof Chest singleChest) {
|
||||
|
||||
chest = singleChest;
|
||||
|
||||
} else if (holder instanceof DoubleChest doubleChest) {
|
||||
|
||||
Chest leftChest =
|
||||
(Chest) doubleChest
|
||||
.getLeftSide();
|
||||
|
||||
Chest rightChest =
|
||||
(Chest) doubleChest
|
||||
.getRightSide();
|
||||
|
||||
if (
|
||||
VerifyIsChestDAO.isWarehouseChest(
|
||||
leftChest.getBlock()
|
||||
)
|
||||
) {
|
||||
|
||||
chest = leftChest;
|
||||
|
||||
} else {
|
||||
|
||||
chest = rightChest;
|
||||
|
||||
}
|
||||
|
||||
} else if (holder instanceof DepositInventoryHolder) {
|
||||
|
||||
WarehouseChestProcessor.processDepositInventory(
|
||||
event.getInventory(),
|
||||
player.getUniqueId().toString(),
|
||||
player.getName()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
!VerifyIsChestDAO.isWarehouseChest(
|
||||
chest.getBlock()
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
WarehouseChestProcessor.processWarehouseChest(
|
||||
chest
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
package com.rsscripting.rswarehouse.deposit.dao;
|
||||
|
||||
import com.rsscripting.rswarehouse.RSWarehouse;
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class ChestDAO {
|
||||
|
||||
public static String getOwnerUuid(
|
||||
Block block
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT owner_uuid
|
||||
FROM warehouse_chests
|
||||
WHERE world = ?
|
||||
AND x = ?
|
||||
AND y = ?
|
||||
AND z = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
block.getWorld().getName()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
block.getX()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
3,
|
||||
block.getY()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
4,
|
||||
block.getZ()
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
return resultSet.getString(
|
||||
"owner_uuid"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Failed getting warehouse owner UUID."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static String getOwnerName(
|
||||
Block block
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT owner_name
|
||||
FROM warehouse_chests
|
||||
WHERE world = ?
|
||||
AND x = ?
|
||||
AND y = ?
|
||||
AND z = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
block.getWorld().getName()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
block.getX()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
3,
|
||||
block.getY()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
4,
|
||||
block.getZ()
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
return resultSet.getString(
|
||||
"owner_name"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Failed getting warehouse owner name."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Player getOnlineOwner(
|
||||
Chest chest
|
||||
) {
|
||||
|
||||
String ownerUuid =
|
||||
getOwnerUuid(
|
||||
chest.getBlock()
|
||||
);
|
||||
|
||||
if (ownerUuid == null) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
return Bukkit.getPlayer(
|
||||
java.util.UUID.fromString(
|
||||
ownerUuid
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (IllegalArgumentException e) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean isOwner(
|
||||
Block block,
|
||||
Player player
|
||||
) {
|
||||
|
||||
String ownerUuid =
|
||||
getOwnerUuid(
|
||||
block
|
||||
);
|
||||
|
||||
return ownerUuid != null
|
||||
&&
|
||||
ownerUuid.equals(
|
||||
player.getUniqueId().toString()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.rsscripting.rswarehouse.deposit.dao;
|
||||
|
||||
import com.rsscripting.rswarehouse.RSWarehouse;
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class VerifyIsChestDAO {
|
||||
|
||||
public static boolean isWarehouseChest(
|
||||
Block block
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT 1
|
||||
FROM warehouse_chests
|
||||
WHERE world = ?
|
||||
AND x = ?
|
||||
AND y = ?
|
||||
AND z = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
block.getWorld().getName()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
block.getX()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
3,
|
||||
block.getY()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
4,
|
||||
block.getZ()
|
||||
);
|
||||
|
||||
return statement.executeQuery().next();
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Failed checking Community Warehouse chest registration."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
package com.rsscripting.rswarehouse.deposit.dao;
|
||||
|
||||
import com.rsscripting.rswarehouse.RSWarehouse;
|
||||
import com.rsscripting.rswarehouse.config.ConfigManager;
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.rsscripting.rswarehouse.deposit.dao.VerifyIsChestDAO.isWarehouseChest;
|
||||
|
||||
public class WarehouseChestDAO {
|
||||
|
||||
public static void unregisterChest(
|
||||
Block block
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE FROM warehouse_chests
|
||||
WHERE world = ?
|
||||
AND x = ?
|
||||
AND y = ?
|
||||
AND z = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
block.getWorld().getName()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
block.getX()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
3,
|
||||
block.getY()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
4,
|
||||
block.getZ()
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Failed to unregister Community Warehouse chest."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void registerChest(
|
||||
Block block,
|
||||
Player player
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
|
||||
INSERT INTO warehouse_chests (
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
owner_uuid,
|
||||
owner_name,
|
||||
created_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
block.getWorld().getName()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
block.getX()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
3,
|
||||
block.getY()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
4,
|
||||
block.getZ()
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
5,
|
||||
player.getUniqueId().toString()
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
6,
|
||||
player.getName()
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
7,
|
||||
String.valueOf(
|
||||
System.currentTimeMillis()
|
||||
)
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
if (block.getState() instanceof Chest chest) {
|
||||
|
||||
chest.customName(
|
||||
Component.text(
|
||||
ConfigManager.get()
|
||||
.getString(
|
||||
"warehouse-chest-name",
|
||||
"Community Warehouse"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
chest.update();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Failed to register Community Warehouse chest."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Block getWarehouseChest(
|
||||
Block block
|
||||
) {
|
||||
|
||||
if (isWarehouseChest(block)) {
|
||||
|
||||
return block;
|
||||
|
||||
}
|
||||
|
||||
if (!(block.getState() instanceof Chest chest)) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
InventoryHolder holder =
|
||||
chest.getInventory()
|
||||
.getHolder();
|
||||
|
||||
if (!(holder instanceof DoubleChest doubleChest)) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
if (doubleChest.getLeftSide()
|
||||
instanceof Chest leftChest
|
||||
&& isWarehouseChest(
|
||||
leftChest.getBlock()
|
||||
)) {
|
||||
|
||||
return leftChest.getBlock();
|
||||
|
||||
}
|
||||
|
||||
if (doubleChest.getRightSide()
|
||||
instanceof Chest rightChest
|
||||
&& isWarehouseChest(
|
||||
rightChest.getBlock()
|
||||
)) {
|
||||
|
||||
return rightChest.getBlock();
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static List<Block> getAllWarehouseChests() {
|
||||
|
||||
List<Block> chests =
|
||||
new ArrayList<>();
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT world, x, y, z
|
||||
FROM warehouse_chests
|
||||
"""
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
World world =
|
||||
Bukkit.getWorld(
|
||||
resultSet.getString(
|
||||
"world"
|
||||
)
|
||||
);
|
||||
|
||||
if (world == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
int x =
|
||||
resultSet.getInt(
|
||||
"x"
|
||||
);
|
||||
|
||||
int y =
|
||||
resultSet.getInt(
|
||||
"y"
|
||||
);
|
||||
|
||||
int z =
|
||||
resultSet.getInt(
|
||||
"z"
|
||||
);
|
||||
|
||||
Block block =
|
||||
world.getBlockAt(
|
||||
x,
|
||||
y,
|
||||
z
|
||||
);
|
||||
|
||||
chests.add(
|
||||
block
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Failed loading warehouse chests."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return chests;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user