Initial release v1.0.0
This commit is contained in:
commit
3fef65b903
314 files changed
+27448
No files matched your search
@@ -0,0 +1,164 @@
|
||||
package com.rsscripting.rswarehouse;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.PurgeVariantsDAO;
|
||||
import com.rsscripting.rswarehouse.chestautoprocess.ChestAutoProcessingTask;
|
||||
import com.rsscripting.rswarehouse.commands.RSPluginCommand;
|
||||
import com.rsscripting.rswarehouse.commands.RSTabCompleter;
|
||||
import com.rsscripting.rswarehouse.commands.ShopCommand;
|
||||
import com.rsscripting.rswarehouse.config.ConfigManager;
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import com.rsscripting.rswarehouse.registration.ListenerRegistration;
|
||||
import com.rsscripting.rswarehouse.constants.RSConstants;
|
||||
import com.rsscripting.rswarehouse.updatechecker.GitHubUpdateChecker;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class RSWarehouse
|
||||
extends JavaPlugin {
|
||||
|
||||
private static RSWarehouse instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
instance = this;
|
||||
|
||||
/* CONFIG */
|
||||
ConfigManager.setup();
|
||||
|
||||
/* Database */
|
||||
DatabaseManager.initialize(
|
||||
this
|
||||
);
|
||||
|
||||
PurgeVariantsDAO
|
||||
.purgeAll();
|
||||
|
||||
/* REGISTER LISTENERS */
|
||||
ListenerRegistration.registerAll(
|
||||
this
|
||||
);
|
||||
|
||||
/* REGISTER COMMANDS */
|
||||
registerCommands();
|
||||
|
||||
/* UPDATE CHECKER */
|
||||
GitHubUpdateChecker.checkForUpdates();
|
||||
|
||||
/* ENABLE MESSAGE */
|
||||
logEnabledMessage();
|
||||
|
||||
/* Start Chest Auto-Processing Tasks */
|
||||
startChestAutoProcessingTask();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
getLogger().info(
|
||||
RSConstants.PLUGIN_NAME
|
||||
+ " Disabled"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* Register Commands method */
|
||||
private void registerCommands() {
|
||||
|
||||
/* rswarehous command */
|
||||
PluginCommand command =
|
||||
getCommand(
|
||||
RSConstants.COMMAND_ALIAS
|
||||
);
|
||||
|
||||
if (command != null) {
|
||||
|
||||
command.setExecutor(
|
||||
new RSPluginCommand()
|
||||
);
|
||||
|
||||
command.setTabCompleter(
|
||||
new RSTabCompleter()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* Shop Comment */
|
||||
PluginCommand shopCommand = getCommand("shop");
|
||||
|
||||
if (shopCommand != null) {
|
||||
shopCommand.setExecutor(new ShopCommand());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Start Chest Auto Processing Task method */
|
||||
private void startChestAutoProcessingTask() {
|
||||
|
||||
boolean chestAutoProcessingEnabled =
|
||||
ConfigManager.get()
|
||||
.getBoolean(
|
||||
"chest-auto-processing.enabled"
|
||||
);
|
||||
|
||||
if (!chestAutoProcessingEnabled) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int intervalSeconds =
|
||||
ConfigManager.get()
|
||||
.getInt(
|
||||
"chest-auto-processing.interval-seconds"
|
||||
);
|
||||
|
||||
if (intervalSeconds < 15) {
|
||||
|
||||
getLogger().warning(
|
||||
"Chest auto processing interval "
|
||||
+ "cannot be less than 15 seconds. "
|
||||
+ "Using 15 seconds."
|
||||
);
|
||||
|
||||
intervalSeconds = 15;
|
||||
|
||||
}
|
||||
|
||||
new ChestAutoProcessingTask()
|
||||
.runTaskTimer(
|
||||
this,
|
||||
intervalSeconds * 20L,
|
||||
intervalSeconds * 20L
|
||||
);
|
||||
|
||||
getLogger().info(
|
||||
"Chest auto processing enabled. "
|
||||
+ "Interval: "
|
||||
+ intervalSeconds
|
||||
+ " seconds."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* Log Enabled Message */
|
||||
private void logEnabledMessage() {
|
||||
|
||||
getLogger().info(
|
||||
RSConstants.PLUGIN_NAME
|
||||
+ " Enabled"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* Get Instance */
|
||||
public static RSWarehouse getInstance() {
|
||||
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.rsscripting.rswarehouse.admin;
|
||||
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.WarehouseStatisticsDAO;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import com.rsscripting.rswarehouse.utils.VersionUtils;
|
||||
import com.rsscripting.rswarehouse.updatechecker.GitHubUpdateChecker;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AdminMenu {
|
||||
|
||||
public static final String MENU_TITLE = "Admin";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"ADMIN"
|
||||
),
|
||||
54,
|
||||
Component.text(
|
||||
MENU_TITLE
|
||||
).color(
|
||||
NamedTextColor.GOLD
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FILLER
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, filler);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| BACK
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
|
||||
Material.OAK_DOOR,
|
||||
|
||||
"§eBack"
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RELOAD
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
menu.setItem(
|
||||
1,
|
||||
RSMenuUtils.createMenuItem(
|
||||
|
||||
Material.ENCHANTED_BOOK,
|
||||
|
||||
"§cReload Plugin"
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| VERSION
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
menu.setItem(
|
||||
7,
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
|
||||
Material.BOOK,
|
||||
|
||||
"§ePlugin Version",
|
||||
|
||||
List.of(
|
||||
|
||||
"§7Installed: §f"
|
||||
+ VersionUtils.getVersion(),
|
||||
|
||||
"",
|
||||
|
||||
"§7Status: §f"
|
||||
+ GitHubUpdateChecker.getUpdateStatus(),
|
||||
|
||||
"",
|
||||
|
||||
"§7Latest: §f"
|
||||
+ (
|
||||
GitHubUpdateChecker.getLatestVersion()
|
||||
== null
|
||||
? "Unknown"
|
||||
: GitHubUpdateChecker.getLatestVersion()
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
10,
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
Material.BOOKSHELF,
|
||||
"§aCreate Category",
|
||||
List.of(
|
||||
"§7Create a new warehouse category."
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
16,
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
|
||||
Material.WRITABLE_BOOK,
|
||||
|
||||
"§aWarehouse Statistics",
|
||||
|
||||
List.of(
|
||||
|
||||
"§7Total Unique Items: §f"
|
||||
+ String.format(
|
||||
"%,d",
|
||||
WarehouseStatisticsDAO.getTotalUniqueItems()
|
||||
),
|
||||
|
||||
"§7Total Items: §f"
|
||||
+ String.format(
|
||||
"%,d",
|
||||
WarehouseStatisticsDAO.getTotalInventory()
|
||||
),
|
||||
|
||||
"",
|
||||
|
||||
"§7Unique Enchanted Variants: §f"
|
||||
+ String.format(
|
||||
"%,d",
|
||||
WarehouseStatisticsDAO.getTotalEnchantedVariants()
|
||||
),
|
||||
|
||||
"§7Unique Damaged Variants: §f"
|
||||
+ String.format(
|
||||
"%,d",
|
||||
WarehouseStatisticsDAO.getTotalDamagedVariants()
|
||||
),
|
||||
|
||||
"§7Unique Partially Filled Variants: §f"
|
||||
+ String.format(
|
||||
"%,d",
|
||||
WarehouseStatisticsDAO.getTotalPartiallyFilledVariants()
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
player.openInventory(menu);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.rsscripting.rswarehouse.admin;
|
||||
|
||||
import com.rsscripting.rswarehouse.config.ConfigManager;
|
||||
import com.rsscripting.rswarehouse.conversion.ConvertMenuListener;
|
||||
import com.rsscripting.rswarehouse.category.categorycreation.CategoryNameMenu;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.constants.RSConstants;
|
||||
import com.rsscripting.rswarehouse.main.MainMenu;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import org.bukkit.block.Block;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class AdminMenuListener
|
||||
implements Listener {
|
||||
|
||||
private final ConvertMenuListener
|
||||
conversionListener;
|
||||
|
||||
public AdminMenuListener(
|
||||
ConvertMenuListener conversionListener
|
||||
) {
|
||||
|
||||
this.conversionListener =
|
||||
conversionListener;
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getWhoClicked()
|
||||
instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!holder.getMenuId()
|
||||
.equals(
|
||||
"ADMIN"
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| SECURITY
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (!player.isOp()
|
||||
||
|
||||
|
||||
!player.hasPermission(
|
||||
RSConstants.ADMIN_PERMISSION
|
||||
)) {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| BACK
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (event.getRawSlot() == 4) {
|
||||
|
||||
Block block =
|
||||
conversionListener.getSelectedBlock(player);
|
||||
|
||||
if (block == null) {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
GuiSessionManager
|
||||
.getSession(player)
|
||||
.setSelectedBlock(block);
|
||||
|
||||
NavigationManager.openMain(player);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RELOAD
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
ConfigManager.reload();
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Configuration reloaded."
|
||||
);
|
||||
|
||||
AdminMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 10) {
|
||||
|
||||
CategoryNameMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.rsscripting.rswarehouse.admin.admindao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class CategoryPlacementDAO {
|
||||
|
||||
public static void assignPageSlot(
|
||||
int categoryId,
|
||||
int page,
|
||||
int slot
|
||||
) {
|
||||
|
||||
String sql =
|
||||
"""
|
||||
UPDATE warehouse_categories
|
||||
SET page = ?,
|
||||
slot = ?
|
||||
WHERE id = ?
|
||||
""";
|
||||
|
||||
try (
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
sql
|
||||
)
|
||||
) {
|
||||
|
||||
statement.setInt(
|
||||
1,
|
||||
page
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
slot
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
3,
|
||||
categoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
catch (
|
||||
Exception exception
|
||||
) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.rsscripting.rswarehouse.admin.admindao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class CreateCategoryDAO {
|
||||
|
||||
public static void createCategory(
|
||||
String internalName,
|
||||
String displayName,
|
||||
String material,
|
||||
String lore
|
||||
) {
|
||||
|
||||
int nextDisplayOrder = 1;
|
||||
|
||||
try (
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
INSERT INTO warehouse_categories (
|
||||
internal_name,
|
||||
display_name,
|
||||
material,
|
||||
lore,
|
||||
display_order,
|
||||
page,
|
||||
slot
|
||||
)
|
||||
VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
"""
|
||||
)
|
||||
) {
|
||||
|
||||
try (
|
||||
PreparedStatement maxStatement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT COALESCE(
|
||||
MAX(display_order),
|
||||
0
|
||||
)
|
||||
FROM warehouse_categories
|
||||
"""
|
||||
)
|
||||
) {
|
||||
|
||||
ResultSet resultSet =
|
||||
maxStatement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
nextDisplayOrder =
|
||||
resultSet.getInt(1) + 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
statement.setString(1, internalName);
|
||||
statement.setString(2, displayName);
|
||||
statement.setString(3, material);
|
||||
statement.setString(4, lore);
|
||||
statement.setInt(5, nextDisplayOrder);
|
||||
statement.setInt(6, 0);
|
||||
statement.setInt(7, 0);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.rsscripting.rswarehouse.admin.admindao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class CreateSubCategoryDAO {
|
||||
|
||||
public static int createSubCategory(
|
||||
int parentCategoryId,
|
||||
String internalName,
|
||||
String displayName,
|
||||
String material,
|
||||
String lore
|
||||
) {
|
||||
|
||||
int nextDisplayOrder = 1;
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
INSERT INTO warehouse_categories (
|
||||
parent_category_id,
|
||||
internal_name,
|
||||
display_name,
|
||||
material,
|
||||
lore,
|
||||
display_order,
|
||||
page,
|
||||
slot
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
Statement.RETURN_GENERATED_KEYS
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
PreparedStatement maxStatement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT COALESCE(
|
||||
MAX(display_order),
|
||||
0
|
||||
)
|
||||
FROM warehouse_categories
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
ResultSet resultSet =
|
||||
maxStatement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
nextDisplayOrder =
|
||||
resultSet.getInt(1) + 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
statement.setInt(
|
||||
1,
|
||||
parentCategoryId
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
2,
|
||||
internalName
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
3,
|
||||
displayName
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
4,
|
||||
material
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
5,
|
||||
lore
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
6,
|
||||
nextDisplayOrder
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
7,
|
||||
0
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
8,
|
||||
0
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
ResultSet keys =
|
||||
statement.getGeneratedKeys();
|
||||
|
||||
if (keys.next()) {
|
||||
|
||||
return keys.getInt(
|
||||
1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.rsscripting.rswarehouse.admin.admindao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class PurgeVariantsDAO {
|
||||
|
||||
public static void purgeZeroQuantityDamagedVariants() {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE
|
||||
FROM damaged_variants
|
||||
WHERE quantity <= 0
|
||||
"""
|
||||
);
|
||||
|
||||
int deleted =
|
||||
statement.executeUpdate();
|
||||
|
||||
Bukkit.getLogger().info(
|
||||
"[RS-Warehouse] Purged "
|
||||
+ deleted
|
||||
+ " empty damaged variants."
|
||||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void purgeZeroQuantityEnchantedVariants() {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE
|
||||
FROM enchanted_variants
|
||||
WHERE quantity <= 0
|
||||
"""
|
||||
);
|
||||
|
||||
int deleted =
|
||||
statement.executeUpdate();
|
||||
|
||||
Bukkit.getLogger().info(
|
||||
"[RS-Warehouse] Purged "
|
||||
+ deleted
|
||||
+ " empty enchanted variants."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (Exception exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void purgeZeroQuantityPartiallyFilledVariants() {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE
|
||||
FROM partially_filled_variants
|
||||
WHERE quantity <= 0
|
||||
"""
|
||||
);
|
||||
|
||||
int deleted =
|
||||
statement.executeUpdate();
|
||||
|
||||
Bukkit.getLogger().info(
|
||||
"[RS-Warehouse] Purged "
|
||||
+ deleted
|
||||
+ " empty partially filled variants."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (Exception exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void purgeAll() {
|
||||
|
||||
purgeZeroQuantityDamagedVariants();
|
||||
|
||||
purgeZeroQuantityEnchantedVariants();
|
||||
|
||||
purgeZeroQuantityPartiallyFilledVariants();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.rsscripting.rswarehouse.admin.admindao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UpdateCategoryDAO {
|
||||
|
||||
public static void updateMaterial(
|
||||
int categoryId,
|
||||
String material
|
||||
) {
|
||||
|
||||
String sql =
|
||||
"""
|
||||
UPDATE warehouse_categories
|
||||
SET material = ?
|
||||
WHERE id = ?
|
||||
""";
|
||||
|
||||
try (
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
sql
|
||||
)
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
material
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
categoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void updateDisplayName(
|
||||
int categoryId,
|
||||
String displayName
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
UPDATE warehouse_categories
|
||||
SET display_name = ?
|
||||
WHERE id = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
displayName
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
categoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void updateLore(
|
||||
int categoryId,
|
||||
String lore
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
UPDATE warehouse_categories
|
||||
SET lore = ?
|
||||
WHERE id = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
lore
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
categoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.rsscripting.rswarehouse.admin.admindao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class WarehouseStatisticsDAO {
|
||||
|
||||
public static long getTotalInventory() {
|
||||
|
||||
long total = 0;
|
||||
|
||||
total += getSum(
|
||||
"warehouse_inventory"
|
||||
);
|
||||
|
||||
total += getSum(
|
||||
"damaged_variants"
|
||||
);
|
||||
|
||||
total += getSum(
|
||||
"enchanted_variants"
|
||||
);
|
||||
|
||||
total += getSum(
|
||||
"partially_filled_variants"
|
||||
);
|
||||
|
||||
return total;
|
||||
|
||||
}
|
||||
|
||||
public static int getTotalUniqueItems() {
|
||||
|
||||
int total = 0;
|
||||
|
||||
total += getCount(
|
||||
"warehouse_inventory"
|
||||
);
|
||||
|
||||
total += getCount(
|
||||
"damaged_variants"
|
||||
);
|
||||
|
||||
total += getCount(
|
||||
"enchanted_variants"
|
||||
);
|
||||
|
||||
total += getCount(
|
||||
"partially_filled_variants"
|
||||
);
|
||||
|
||||
return total;
|
||||
|
||||
}
|
||||
|
||||
public static int getTotalDamagedVariants() {
|
||||
|
||||
return getCount(
|
||||
"damaged_variants"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static int getTotalEnchantedVariants() {
|
||||
|
||||
return getCount(
|
||||
"enchanted_variants"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static int getTotalPartiallyFilledVariants() {
|
||||
|
||||
return getCount(
|
||||
"partially_filled_variants"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static int getCount(
|
||||
String table
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"SELECT COUNT(*) FROM "
|
||||
+ table
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
ResultSet result =
|
||||
statement.executeQuery();
|
||||
|
||||
if (
|
||||
result.next()
|
||||
) {
|
||||
|
||||
return result.getInt(
|
||||
1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (
|
||||
Exception ignored
|
||||
) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
private static long getSum(
|
||||
String table
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"SELECT COALESCE(SUM(quantity),0) FROM "
|
||||
+ table
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
ResultSet result =
|
||||
statement.executeQuery();
|
||||
|
||||
if (
|
||||
result.next()
|
||||
) {
|
||||
|
||||
return result.getLong(
|
||||
1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (
|
||||
Exception exception
|
||||
)
|
||||
{
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
public class CategoryEditSession {
|
||||
|
||||
private final int categoryId;
|
||||
|
||||
private final String[] lore =
|
||||
new String[5];
|
||||
|
||||
private int loreSlot = -1;
|
||||
|
||||
private long loreExpiration = 0;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private boolean editingDisplayName = false;
|
||||
|
||||
private long displayNameExpiration = 0;
|
||||
|
||||
public CategoryEditSession(
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
this.categoryId =
|
||||
categoryId;
|
||||
|
||||
}
|
||||
|
||||
public int getCategoryId() {
|
||||
|
||||
return categoryId;
|
||||
|
||||
}
|
||||
|
||||
public String getLore(
|
||||
int index
|
||||
) {
|
||||
|
||||
return lore[index];
|
||||
|
||||
}
|
||||
|
||||
public void setLore(
|
||||
int index,
|
||||
String value
|
||||
) {
|
||||
|
||||
lore[index] =
|
||||
value;
|
||||
|
||||
}
|
||||
|
||||
public int getLoreSlot() {
|
||||
|
||||
return loreSlot;
|
||||
|
||||
}
|
||||
|
||||
public void setLoreSlot(
|
||||
int loreSlot
|
||||
) {
|
||||
|
||||
this.loreSlot =
|
||||
loreSlot;
|
||||
|
||||
}
|
||||
|
||||
public long getLoreExpiration() {
|
||||
|
||||
return loreExpiration;
|
||||
|
||||
}
|
||||
|
||||
public void setLoreExpiration(
|
||||
long loreExpiration
|
||||
) {
|
||||
|
||||
this.loreExpiration =
|
||||
loreExpiration;
|
||||
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
|
||||
return displayName;
|
||||
|
||||
}
|
||||
|
||||
public void setDisplayName(
|
||||
String displayName
|
||||
) {
|
||||
|
||||
this.displayName =
|
||||
displayName;
|
||||
|
||||
}
|
||||
|
||||
public boolean isEditingDisplayName() {
|
||||
|
||||
return editingDisplayName;
|
||||
|
||||
}
|
||||
|
||||
public void setEditingDisplayName(
|
||||
boolean editingDisplayName
|
||||
) {
|
||||
|
||||
this.editingDisplayName =
|
||||
editingDisplayName;
|
||||
|
||||
}
|
||||
|
||||
public long getDisplayNameExpiration() {
|
||||
|
||||
return displayNameExpiration;
|
||||
|
||||
}
|
||||
|
||||
public void setDisplayNameExpiration(
|
||||
long displayNameExpiration
|
||||
) {
|
||||
|
||||
this.displayNameExpiration =
|
||||
displayNameExpiration;
|
||||
|
||||
}
|
||||
|
||||
private int materialPickerPage = 0;
|
||||
|
||||
public int getMaterialPickerPage() {
|
||||
return materialPickerPage;
|
||||
}
|
||||
|
||||
public void setMaterialPickerPage(int materialPickerPage) {
|
||||
this.materialPickerPage = materialPickerPage;
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CategoryEditSessionManager {
|
||||
|
||||
private static final Map<
|
||||
UUID,
|
||||
CategoryEditSession
|
||||
> sessions =
|
||||
new HashMap<>();
|
||||
|
||||
public static CategoryEditSession createSession(
|
||||
UUID uuid,
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
CategoryEditSession session =
|
||||
new CategoryEditSession(
|
||||
categoryId
|
||||
);
|
||||
|
||||
sessions.put(
|
||||
uuid,
|
||||
session
|
||||
);
|
||||
|
||||
return session;
|
||||
|
||||
}
|
||||
|
||||
public static CategoryEditSession getSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
return sessions.get(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void removeSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
sessions.remove(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
public class CategoryOptionsMenuListener {
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
public class CategoryPageSlotSession {
|
||||
|
||||
private final int categoryId;
|
||||
|
||||
private Integer page;
|
||||
|
||||
private Integer slot;
|
||||
|
||||
public CategoryPageSlotSession(
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
this.categoryId =
|
||||
categoryId;
|
||||
|
||||
}
|
||||
|
||||
public int getCategoryId() {
|
||||
|
||||
return categoryId;
|
||||
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
public void setPage(
|
||||
Integer page
|
||||
) {
|
||||
|
||||
this.page =
|
||||
page;
|
||||
|
||||
}
|
||||
|
||||
public Integer getSlot() {
|
||||
|
||||
return slot;
|
||||
|
||||
}
|
||||
|
||||
public void setSlot(
|
||||
Integer slot
|
||||
) {
|
||||
|
||||
this.slot =
|
||||
slot;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CategoryPageSlotSessionManager {
|
||||
|
||||
private static final Map<
|
||||
UUID,
|
||||
CategoryPageSlotSession
|
||||
> sessions =
|
||||
new HashMap<>();
|
||||
|
||||
public static void createSession(
|
||||
UUID uuid,
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
sessions.put(
|
||||
uuid,
|
||||
new CategoryPageSlotSession(
|
||||
categoryId
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static CategoryPageSlotSession getSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
return sessions.get(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void removeSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
sessions.remove(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
public class PageSlotAssignmentSession {
|
||||
|
||||
private final int itemId;
|
||||
|
||||
private int categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer page;
|
||||
|
||||
private Integer slot;
|
||||
|
||||
public PageSlotAssignmentSession(
|
||||
int itemId
|
||||
) {
|
||||
|
||||
this.itemId = itemId;
|
||||
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
|
||||
return itemId;
|
||||
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
public void setPage(
|
||||
Integer page
|
||||
) {
|
||||
|
||||
this.page = page;
|
||||
|
||||
}
|
||||
|
||||
public Integer getSlot() {
|
||||
|
||||
return slot;
|
||||
|
||||
}
|
||||
|
||||
public void setSlot(
|
||||
Integer slot
|
||||
) {
|
||||
|
||||
this.slot = slot;
|
||||
|
||||
}
|
||||
|
||||
public int getCategoryId() {
|
||||
|
||||
return categoryId;
|
||||
|
||||
}
|
||||
|
||||
public void setCategoryId(
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
this.categoryId = categoryId;
|
||||
|
||||
}
|
||||
|
||||
public String getCategoryName() {
|
||||
|
||||
return categoryName;
|
||||
|
||||
}
|
||||
|
||||
public void setCategoryName(
|
||||
String categoryName
|
||||
) {
|
||||
|
||||
this.categoryName = categoryName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PageSlotAssignmentSessionManager {
|
||||
|
||||
private static final Map<UUID, PageSlotAssignmentSession> sessions =
|
||||
new HashMap<>();
|
||||
|
||||
public static void createSession(
|
||||
UUID uuid,
|
||||
int itemId
|
||||
) {
|
||||
|
||||
PageSlotAssignmentSession session =
|
||||
new PageSlotAssignmentSession(
|
||||
itemId
|
||||
);
|
||||
|
||||
WarehouseItem item =
|
||||
ItemDAO.getItemById(
|
||||
itemId
|
||||
);
|
||||
|
||||
if (item != null) {
|
||||
|
||||
session.setCategoryId(
|
||||
item.categoryId()
|
||||
);
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
item.categoryId()
|
||||
);
|
||||
|
||||
if (category != null) {
|
||||
|
||||
session.setCategoryName(
|
||||
category.displayName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sessions.put(
|
||||
uuid,
|
||||
session
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static PageSlotAssignmentSession getSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
return sessions.get(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void removeSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
sessions.remove(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
public class SubCategoryCreationSession {
|
||||
|
||||
private final int itemId;
|
||||
|
||||
private String internalName;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private final String[] lore =
|
||||
new String[5];
|
||||
|
||||
private int loreSlot =
|
||||
-1;
|
||||
|
||||
private long loreExpiration =
|
||||
0;
|
||||
|
||||
public SubCategoryCreationSession(
|
||||
int itemId
|
||||
) {
|
||||
|
||||
this.itemId = itemId;
|
||||
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
|
||||
return itemId;
|
||||
|
||||
}
|
||||
|
||||
public String getInternalName() {
|
||||
|
||||
return internalName;
|
||||
|
||||
}
|
||||
|
||||
public void setInternalName(
|
||||
String internalName
|
||||
) {
|
||||
|
||||
this.internalName = internalName;
|
||||
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
|
||||
return displayName;
|
||||
|
||||
}
|
||||
|
||||
public void setDisplayName(
|
||||
String displayName
|
||||
) {
|
||||
|
||||
this.displayName = displayName;
|
||||
|
||||
}
|
||||
|
||||
public void setLore(
|
||||
int slot,
|
||||
String value
|
||||
) {
|
||||
|
||||
lore[slot] = value;
|
||||
|
||||
}
|
||||
|
||||
public String getLore(
|
||||
int slot
|
||||
) {
|
||||
|
||||
return lore[slot];
|
||||
|
||||
}
|
||||
|
||||
public void clearLore() {
|
||||
|
||||
for (int i = 0; i < lore.length; i++) {
|
||||
|
||||
lore[i] = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getLoreSlot() {
|
||||
|
||||
return loreSlot;
|
||||
|
||||
}
|
||||
|
||||
public void setLoreSlot(
|
||||
int loreSlot
|
||||
) {
|
||||
|
||||
this.loreSlot = loreSlot;
|
||||
|
||||
}
|
||||
|
||||
public long getLoreExpiration() {
|
||||
|
||||
return loreExpiration;
|
||||
|
||||
}
|
||||
|
||||
public void setLoreExpiration(
|
||||
long loreExpiration
|
||||
) {
|
||||
|
||||
this.loreExpiration = loreExpiration;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubCategoryCreationSessionManager {
|
||||
|
||||
private static final Map<UUID, SubCategoryCreationSession> sessions =
|
||||
new HashMap<>();
|
||||
|
||||
public static void createSession(
|
||||
UUID uuid,
|
||||
int itemId
|
||||
) {
|
||||
|
||||
sessions.put(
|
||||
uuid,
|
||||
new SubCategoryCreationSession(
|
||||
itemId
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static SubCategoryCreationSession getSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
return sessions.get(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void removeSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
sessions.remove(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
public class SubCategoryEditSession {
|
||||
|
||||
private final int itemId;
|
||||
|
||||
private final int subCategoryId;
|
||||
|
||||
private final String[] lore =
|
||||
new String[5];
|
||||
|
||||
private int loreSlot = -1;
|
||||
|
||||
private long loreExpiration = 0;
|
||||
|
||||
public String getLore(
|
||||
int index
|
||||
) {
|
||||
|
||||
return lore[index];
|
||||
|
||||
}
|
||||
|
||||
public void setLore(
|
||||
int index,
|
||||
String value
|
||||
) {
|
||||
|
||||
lore[index] = value;
|
||||
|
||||
}
|
||||
|
||||
public int getLoreSlot() {
|
||||
|
||||
return loreSlot;
|
||||
|
||||
}
|
||||
|
||||
public void setLoreSlot(
|
||||
int loreSlot
|
||||
) {
|
||||
|
||||
this.loreSlot = loreSlot;
|
||||
|
||||
}
|
||||
|
||||
public long getLoreExpiration() {
|
||||
|
||||
return loreExpiration;
|
||||
|
||||
}
|
||||
|
||||
public void setLoreExpiration(
|
||||
long loreExpiration
|
||||
) {
|
||||
|
||||
this.loreExpiration = loreExpiration;
|
||||
|
||||
}
|
||||
|
||||
public SubCategoryEditSession(
|
||||
int itemId,
|
||||
int subCategoryId
|
||||
) {
|
||||
|
||||
this.itemId = itemId;
|
||||
this.subCategoryId = subCategoryId;
|
||||
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
|
||||
return itemId;
|
||||
|
||||
}
|
||||
|
||||
public int getSubCategoryId() {
|
||||
|
||||
return subCategoryId;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.rsscripting.rswarehouse.admin.adminsessions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SubCategoryEditSessionManager {
|
||||
|
||||
private static final Map<UUID, SubCategoryEditSession> sessions =
|
||||
new HashMap<>();
|
||||
|
||||
public static SubCategoryEditSession createSession(
|
||||
UUID uuid,
|
||||
int itemId,
|
||||
int subCategoryId
|
||||
) {
|
||||
|
||||
SubCategoryEditSession session =
|
||||
new SubCategoryEditSession(
|
||||
itemId,
|
||||
subCategoryId
|
||||
);
|
||||
|
||||
sessions.put(
|
||||
uuid,
|
||||
session
|
||||
);
|
||||
|
||||
return session;
|
||||
|
||||
}
|
||||
|
||||
public static SubCategoryEditSession getSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
return sessions.get(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void removeSession(
|
||||
UUID uuid
|
||||
) {
|
||||
|
||||
sessions.remove(
|
||||
uuid
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSessionManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryPageNumberMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Page Number";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
CategoryPageSlotSession session =
|
||||
CategoryPageSlotSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AnvilView view =
|
||||
MenuType.ANVIL.builder()
|
||||
.title(
|
||||
Component.text(TITLE)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm =
|
||||
new ItemStack(Material.LIME_WOOL);
|
||||
|
||||
ItemMeta meta =
|
||||
confirm.getItemMeta();
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
if (
|
||||
category != null
|
||||
&& category.page() > 0
|
||||
) {
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
String.valueOf(
|
||||
category.page()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
meta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Save page."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(meta);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
ItemStack cancel =
|
||||
new ItemStack(Material.RED_WOOL);
|
||||
|
||||
ItemMeta cancelMeta =
|
||||
cancel.getItemMeta();
|
||||
|
||||
cancelMeta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
cancelMeta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Cancel"
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
cancel.setItemMeta(
|
||||
cancelMeta
|
||||
);
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
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.view.AnvilView;
|
||||
|
||||
public class CategoryPageNumberMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(CategoryPageNumberMenu.TITLE)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
CategoryPageSlotSession session =
|
||||
CategoryPageSlotSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String pageText =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (pageText.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Page cannot be blank."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int page;
|
||||
|
||||
try {
|
||||
|
||||
page =
|
||||
Integer.parseInt(
|
||||
pageText
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (NumberFormatException exception) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Page must be a number."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (page < 1) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Page must be 1 or greater."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPage(
|
||||
page
|
||||
);
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
CategorySlotNumberMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(PageNumberMenu.TITLE)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSessionManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CategorySlotNumberMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Slot Number";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
CategoryPageSlotSession session =
|
||||
CategoryPageSlotSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
AnvilView view =
|
||||
MenuType.ANVIL.builder()
|
||||
.title(
|
||||
Component.text(TITLE)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm =
|
||||
new ItemStack(Material.LIME_WOOL);
|
||||
|
||||
ItemMeta meta =
|
||||
confirm.getItemMeta();
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
if (
|
||||
category != null
|
||||
&& category.slot() > 0
|
||||
) {
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
String.valueOf(
|
||||
category.slot()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
meta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Save slot."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(meta);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
ItemStack cancel =
|
||||
new ItemStack(Material.RED_WOOL);
|
||||
|
||||
ItemMeta cancelMeta =
|
||||
cancel.getItemMeta();
|
||||
|
||||
cancelMeta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
cancel.setItemMeta(
|
||||
cancelMeta
|
||||
);
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.CategoryPlacementDAO;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSessionManager;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
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.view.AnvilView;
|
||||
|
||||
public class CategorySlotNumberMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategorySlotNumberMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
CategoryPageSlotSession session =
|
||||
CategoryPageSlotSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String slotText =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (slotText.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Slot cannot be blank."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int slot;
|
||||
|
||||
try {
|
||||
|
||||
slot =
|
||||
Integer.parseInt(
|
||||
slotText
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (NumberFormatException exception) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Slot must be a number."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (slot < 9 || slot > 53) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Slot must be between 9 and 53."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setSlot(
|
||||
slot
|
||||
);
|
||||
|
||||
CategoryPlacementDAO.assignPageSlot(
|
||||
session.getCategoryId(),
|
||||
session.getPage(),
|
||||
session.getSlot()
|
||||
);
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
CategoryMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
CategoryPageSlotSessionManager.removeSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Item page/slot updated."
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategorySlotNumberMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSessionManager;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageNumberMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Page Number";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
PageSlotAssignmentSession session =
|
||||
PageSlotAssignmentSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WarehouseItem item =
|
||||
ItemDAO.getItemById(
|
||||
session.getItemId()
|
||||
);
|
||||
|
||||
AnvilView view =
|
||||
MenuType.ANVIL.builder()
|
||||
.title(
|
||||
Component.text(TITLE)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm =
|
||||
new ItemStack(Material.LIME_WOOL);
|
||||
|
||||
ItemMeta meta =
|
||||
confirm.getItemMeta();
|
||||
|
||||
if (item != null && item.page() != null) {
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
String.valueOf(item.page())
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
meta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Save page."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(meta);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
ItemStack cancel =
|
||||
new ItemStack(Material.RED_WOOL);
|
||||
|
||||
ItemMeta cancelMeta =
|
||||
cancel.getItemMeta();
|
||||
|
||||
cancelMeta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
cancelMeta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Cancel"
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
cancel.setItemMeta(
|
||||
cancelMeta
|
||||
);
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
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.view.AnvilView;
|
||||
|
||||
public class PageNumberMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(PageNumberMenu.TITLE)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
PageSlotAssignmentSession session =
|
||||
PageSlotAssignmentSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String pageText =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (pageText.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Page cannot be blank."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int page;
|
||||
|
||||
try {
|
||||
|
||||
page =
|
||||
Integer.parseInt(
|
||||
pageText
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (NumberFormatException exception) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Page must be a number."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (page < 1) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Page must be 1 or greater."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPage(
|
||||
page
|
||||
);
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
SlotNumberMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(PageNumberMenu.TITLE)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSessionManager;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SlotNumberMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Slot Number";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
PageSlotAssignmentSession session =
|
||||
PageSlotAssignmentSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
WarehouseItem item =
|
||||
ItemDAO.getItemById(
|
||||
session.getItemId()
|
||||
);
|
||||
|
||||
AnvilView view =
|
||||
MenuType.ANVIL.builder()
|
||||
.title(
|
||||
Component.text(TITLE)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm =
|
||||
new ItemStack(Material.LIME_WOOL);
|
||||
|
||||
ItemMeta meta =
|
||||
confirm.getItemMeta();
|
||||
|
||||
if (item != null && item.slot() != null) {
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
String.valueOf(item.slot())
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
meta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Save slot."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(meta);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
ItemStack cancel =
|
||||
new ItemStack(Material.RED_WOOL);
|
||||
|
||||
ItemMeta cancelMeta =
|
||||
cancel.getItemMeta();
|
||||
|
||||
cancelMeta.displayName(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
cancel.setItemMeta(
|
||||
cancelMeta
|
||||
);
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
package com.rsscripting.rswarehouse.admin.assignpageslot;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.PageSlotAssignmentSessionManager;
|
||||
import com.rsscripting.rswarehouse.placement.placementdao.ItemPlacementDAO;
|
||||
import com.rsscripting.rswarehouse.item.ItemsMenu;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
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.view.AnvilView;
|
||||
|
||||
public class SlotNumberMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
SlotNumberMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
PageSlotAssignmentSession session =
|
||||
PageSlotAssignmentSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String slotText =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (slotText.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Slot cannot be blank."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int slot;
|
||||
|
||||
try {
|
||||
|
||||
slot =
|
||||
Integer.parseInt(
|
||||
slotText
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (NumberFormatException exception) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Slot must be a number."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (slot < 9 || slot > 53) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Slot must be between 9 and 53."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setSlot(
|
||||
slot
|
||||
);
|
||||
|
||||
ItemPlacementDAO.assignPageSlot(
|
||||
session.getItemId(),
|
||||
session.getPage(),
|
||||
session.getSlot()
|
||||
);
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
ItemsMenu.open(
|
||||
player,
|
||||
session.getCategoryId(),
|
||||
session.getCategoryName(),
|
||||
session.getPage() - 1
|
||||
);
|
||||
|
||||
PageSlotAssignmentSessionManager.removeSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Item page/slot updated."
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
SlotNumberMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package com.rsscripting.rswarehouse.autodeposit;
|
||||
|
||||
import com.rsscripting.rswarehouse.autodeposit.autodepositdao.AutoDepositDAO;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AutoDepositMenu {
|
||||
|
||||
public static final String MENU_ID =
|
||||
"AUTO_DEPOSIT";
|
||||
|
||||
public static final String TITLE =
|
||||
"Auto Deposit";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
int page =
|
||||
Math.max(
|
||||
1,
|
||||
session.getAutoDepositPage()
|
||||
);
|
||||
|
||||
session.setAutoDepositPage(
|
||||
page
|
||||
);
|
||||
|
||||
Inventory inventory =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
MENU_ID
|
||||
),
|
||||
54,
|
||||
Component.text(
|
||||
TITLE
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (
|
||||
int slot = 0;
|
||||
slot <= 8;
|
||||
slot++
|
||||
) {
|
||||
|
||||
inventory.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
boolean enabled =
|
||||
AutoDepositDAO.isEnabled(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
inventory.setItem(
|
||||
2,
|
||||
enabled
|
||||
? RSMenuUtils.createMenuItem(
|
||||
Material.GREEN_DYE,
|
||||
"Enabled"
|
||||
)
|
||||
: RSMenuUtils.createMenuItem(
|
||||
Material.RED_DYE,
|
||||
"Disabled"
|
||||
)
|
||||
);
|
||||
|
||||
inventory.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.OAK_DOOR,
|
||||
"§a Back to Category Menu"
|
||||
)
|
||||
);
|
||||
|
||||
List<ItemStack> filters =
|
||||
AutoDepositDAO.getFilters(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
int highestPage =
|
||||
filters.size() / 45 + 1;
|
||||
|
||||
int start =
|
||||
(page - 1) * 45;
|
||||
|
||||
int slot =
|
||||
9;
|
||||
|
||||
for (
|
||||
int i = start;
|
||||
i < filters.size()
|
||||
&& slot <= 53;
|
||||
i++
|
||||
) {
|
||||
|
||||
inventory.setItem(
|
||||
slot++,
|
||||
filters.get(
|
||||
i
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
page > 1
|
||||
) {
|
||||
|
||||
inventory.setItem(
|
||||
0,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§ePrevious Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
page < highestPage + 1
|
||||
) {
|
||||
|
||||
inventory.setItem(
|
||||
8,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§eNext Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
inventory
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package com.rsscripting.rswarehouse.autodeposit;
|
||||
|
||||
import com.rsscripting.rswarehouse.autodeposit.autodepositdao.AutoDepositDAO;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AutoDepositMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
AutoDepositMenu.MENU_ID
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getClickedInventory()
|
||||
== event.getView()
|
||||
.getTopInventory()
|
||||
) {
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
int slot =
|
||||
event.getRawSlot();
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
if (
|
||||
slot == 0
|
||||
) {
|
||||
|
||||
session.setAutoDepositPage(
|
||||
session.getAutoDepositPage()
|
||||
- 1
|
||||
);
|
||||
|
||||
AutoDepositMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
slot == 8
|
||||
) {
|
||||
|
||||
session.setAutoDepositPage(
|
||||
session.getAutoDepositPage()
|
||||
+ 1
|
||||
);
|
||||
|
||||
AutoDepositMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
slot == 4
|
||||
) {
|
||||
|
||||
CategoryMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
slot >= 9
|
||||
&& slot <= 53
|
||||
&& event.getCursor() != null
|
||||
&& !event.getCursor()
|
||||
.getType()
|
||||
.isAir()
|
||||
) {
|
||||
|
||||
ItemStack filter =
|
||||
event.getCursor()
|
||||
.clone();
|
||||
|
||||
filter.setAmount(
|
||||
1
|
||||
);
|
||||
|
||||
AutoDepositDAO.addFilter(
|
||||
player.getUniqueId(),
|
||||
filter
|
||||
);
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Filter added."
|
||||
);
|
||||
|
||||
AutoDepositMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (slot == 2) {
|
||||
|
||||
boolean enabled =
|
||||
AutoDepositDAO.isEnabled(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
AutoDepositDAO.setEnabled(
|
||||
player.getUniqueId(),
|
||||
!enabled
|
||||
);
|
||||
|
||||
AutoDepositMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
slot >= 9
|
||||
&& slot <= 53
|
||||
&& event.getCurrentItem() != null
|
||||
&& !event.getCurrentItem()
|
||||
.getType()
|
||||
.isAir()
|
||||
) {
|
||||
|
||||
AutoDepositDAO.removeFilter(
|
||||
player.getUniqueId(),
|
||||
event.getCurrentItem()
|
||||
);
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Filter removed."
|
||||
);
|
||||
|
||||
AutoDepositMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.rsscripting.rswarehouse.autodeposit;
|
||||
|
||||
import com.rsscripting.rswarehouse.autodeposit.autodepositdao.AutoDepositDAO;
|
||||
import com.rsscripting.rswarehouse.inventory.inventorydao.InventoryLookupDAO;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AutoDepositPickupListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityPickupItem(
|
||||
EntityPickupItemEvent event
|
||||
) {
|
||||
|
||||
if (
|
||||
!(event.getEntity()
|
||||
instanceof Player player)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
!AutoDepositDAO.isEnabled(
|
||||
player.getUniqueId()
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Item entity =
|
||||
event.getItem();
|
||||
|
||||
ItemStack item =
|
||||
entity.getItemStack();
|
||||
|
||||
if (
|
||||
!AutoDepositDAO.matchesFilter(
|
||||
player.getUniqueId(),
|
||||
item
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Integer inventoryId =
|
||||
InventoryLookupDAO.findInventoryId(
|
||||
item
|
||||
);
|
||||
|
||||
if (
|
||||
inventoryId == null
|
||||
&&
|
||||
!player.getServer()
|
||||
.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
)
|
||||
.getConfig()
|
||||
.getBoolean(
|
||||
"allow-uncategorized-item-creation",
|
||||
true
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ItemDAO.addItem(
|
||||
player.getUniqueId()
|
||||
.toString(),
|
||||
player.getName(),
|
||||
item,
|
||||
item.getAmount()
|
||||
);
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
entity.remove();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+346
@@ -0,0 +1,346 @@
|
||||
package com.rsscripting.rswarehouse.autodeposit.autodepositdao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AutoDepositDAO {
|
||||
|
||||
public static boolean isEnabled(
|
||||
UUID playerUuid
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT enabled
|
||||
FROM auto_deposit_settings
|
||||
WHERE player_uuid = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
playerUuid.toString()
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
if (
|
||||
resultSet.next()
|
||||
) {
|
||||
|
||||
return resultSet.getInt(
|
||||
"enabled"
|
||||
) == 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public static void setEnabled(
|
||||
UUID playerUuid,
|
||||
boolean enabled
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
INSERT OR REPLACE
|
||||
INTO auto_deposit_settings (
|
||||
player_uuid,
|
||||
enabled
|
||||
)
|
||||
VALUES (
|
||||
?,
|
||||
?
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
playerUuid.toString()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
enabled
|
||||
? 1
|
||||
: 0
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void addFilter(
|
||||
UUID playerUuid,
|
||||
ItemStack item
|
||||
) {
|
||||
|
||||
item =
|
||||
normalize(
|
||||
item
|
||||
);
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
INSERT OR IGNORE
|
||||
INTO auto_deposit_filters (
|
||||
player_uuid,
|
||||
serialized_item
|
||||
)
|
||||
VALUES (
|
||||
?,
|
||||
?
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
playerUuid.toString()
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
2,
|
||||
ItemStackUtils.serialize(
|
||||
item
|
||||
)
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void removeFilter(
|
||||
UUID playerUuid,
|
||||
ItemStack item
|
||||
) {
|
||||
|
||||
item =
|
||||
normalize(
|
||||
item
|
||||
);
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE
|
||||
FROM auto_deposit_filters
|
||||
WHERE player_uuid = ?
|
||||
AND serialized_item = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
playerUuid.toString()
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
2,
|
||||
ItemStackUtils.serialize(
|
||||
item
|
||||
)
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<ItemStack> getFilters(
|
||||
UUID playerUuid
|
||||
) {
|
||||
|
||||
List<ItemStack> filters =
|
||||
new ArrayList<>();
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT serialized_item
|
||||
FROM auto_deposit_filters
|
||||
WHERE player_uuid = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
playerUuid.toString()
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
while (
|
||||
resultSet.next()
|
||||
) {
|
||||
|
||||
filters.add(
|
||||
ItemStackUtils.deserialize(
|
||||
resultSet.getString(
|
||||
"serialized_item"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return filters;
|
||||
|
||||
}
|
||||
|
||||
public static boolean matchesFilter(
|
||||
UUID playerUuid,
|
||||
ItemStack item
|
||||
) {
|
||||
|
||||
item =
|
||||
normalize(
|
||||
item
|
||||
);
|
||||
|
||||
for (
|
||||
ItemStack filter
|
||||
: getFilters(
|
||||
playerUuid
|
||||
)
|
||||
) {
|
||||
|
||||
if (
|
||||
filter.isSimilar(
|
||||
item
|
||||
)
|
||||
) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public static boolean shouldBlockWithdrawal(
|
||||
UUID playerUuid,
|
||||
ItemStack item
|
||||
) {
|
||||
|
||||
return isEnabled(
|
||||
playerUuid
|
||||
)
|
||||
&&
|
||||
matchesFilter(
|
||||
playerUuid,
|
||||
item
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static ItemStack normalize(
|
||||
ItemStack item
|
||||
) {
|
||||
|
||||
ItemStack copy =
|
||||
item.clone();
|
||||
|
||||
copy.setAmount(
|
||||
1
|
||||
);
|
||||
|
||||
return copy;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryDisplayNameMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Display Name";
|
||||
|
||||
public static void open(Player player) {
|
||||
|
||||
AnvilView view = MenuType.ANVIL
|
||||
.builder()
|
||||
.title(
|
||||
Component.text(
|
||||
TITLE
|
||||
)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm = new ItemStack(Material.LIME_WOOL);
|
||||
|
||||
ItemMeta meta = confirm.getItemMeta();
|
||||
|
||||
meta.displayName(
|
||||
Component.text("")
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Save and proceed to material picker."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(meta);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
|
||||
ItemStack cancel = new ItemStack(Material.RED_WOOL);
|
||||
|
||||
ItemMeta metacancel = cancel.getItemMeta();
|
||||
|
||||
metacancel.displayName(
|
||||
Component.text("")
|
||||
);
|
||||
|
||||
metacancel.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Cancel"
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
cancel.setItemMeta(metacancel);
|
||||
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
).setCategoryDisplayNameMenuOpen(
|
||||
true
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.admin.AdminMenu;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class CategoryDisplayNameMenuListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategoryDisplayNameMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
if (!session.isCategoryDisplayNameMenuOpen()) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String categoryName =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (categoryName.length() > 25) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Category names may not exceed 25 characters."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (categoryName.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Category name cannot be empty."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
CategoryDAO.categoryExists(
|
||||
categoryName
|
||||
)
|
||||
) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"A category with that name already exists."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPendingCategoryDisplayName(
|
||||
categoryName
|
||||
);
|
||||
|
||||
session.setCategoryDisplayNameMenuOpen(
|
||||
false
|
||||
);
|
||||
|
||||
session.clearPendingCategoryLore();
|
||||
|
||||
event.getView().getTopInventory().clear();
|
||||
|
||||
CategoryMaterialPickerMenu.open(
|
||||
player,
|
||||
0
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView().getTopInventory().clear();
|
||||
|
||||
AdminMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView()
|
||||
instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategoryDisplayNameMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class CategoryLoreChatListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(
|
||||
AsyncPlayerChatEvent event
|
||||
) {
|
||||
|
||||
Player player =
|
||||
event.getPlayer();
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
int loreSlot =
|
||||
session.getPendingCategoryLoreSlot();
|
||||
|
||||
if (loreSlot < 0) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
String message =
|
||||
event.getMessage();
|
||||
|
||||
if (message.length() > 50) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Lore lines may not exceed 50 characters."
|
||||
);
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTask(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> CategoryLoreMenu.open(
|
||||
player
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
message.equalsIgnoreCase(
|
||||
"cancel"
|
||||
)
|
||||
) {
|
||||
|
||||
session.setPendingCategoryLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
session.setPendingCategoryLoreExpiration(
|
||||
0
|
||||
);
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTask(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> CategoryLoreMenu.open(
|
||||
player
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPendingCategoryLore(
|
||||
loreSlot,
|
||||
message
|
||||
);
|
||||
|
||||
session.setPendingCategoryLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
session.setPendingCategoryLoreExpiration(
|
||||
0
|
||||
);
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTask(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> {
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Lore line saved."
|
||||
);
|
||||
|
||||
CategoryLoreMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryLoreMenu {
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"CATEGORY_LORE"
|
||||
),
|
||||
27,
|
||||
Component.text(
|
||||
"Category Lore"
|
||||
)
|
||||
);
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(
|
||||
i,
|
||||
RSMenuUtils.createFillerPane()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
ItemStack book =
|
||||
new ItemStack(
|
||||
Material.WRITABLE_BOOK
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
book.getItemMeta();
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
"Lore Line "
|
||||
+ (i + 1)
|
||||
)
|
||||
);
|
||||
|
||||
List<Component> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
String value =
|
||||
session.getPendingCategoryLore(
|
||||
i
|
||||
);
|
||||
|
||||
if (
|
||||
value == null
|
||||
|| value.isBlank()
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"(Empty)"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
value
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
lore.add(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Click to edit."
|
||||
)
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
lore
|
||||
);
|
||||
|
||||
book.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
11 + i,
|
||||
book
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
22,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.LIME_WOOL,
|
||||
"§aCreate Category"
|
||||
)
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.OAK_DOOR,
|
||||
"§eBack"
|
||||
)
|
||||
);
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.CreateCategoryDAO;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class CategoryLoreMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"CATEGORY_LORE"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
switch (event.getSlot()) {
|
||||
|
||||
case 4 -> CategoryMaterialPickerMenu.open(
|
||||
player,
|
||||
0
|
||||
);
|
||||
|
||||
case 11 -> editLore(
|
||||
player,
|
||||
session,
|
||||
0
|
||||
);
|
||||
|
||||
case 12 -> editLore(
|
||||
player,
|
||||
session,
|
||||
1
|
||||
);
|
||||
|
||||
case 13 -> editLore(
|
||||
player,
|
||||
session,
|
||||
2
|
||||
);
|
||||
|
||||
case 14 -> editLore(
|
||||
player,
|
||||
session,
|
||||
3
|
||||
);
|
||||
|
||||
case 15 -> editLore(
|
||||
player,
|
||||
session,
|
||||
4
|
||||
);
|
||||
|
||||
case 22 -> createCategory(
|
||||
player,
|
||||
session
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void editLore(
|
||||
Player player,
|
||||
GuiSession session,
|
||||
int loreSlot
|
||||
) {
|
||||
|
||||
session.setPendingCategoryLoreSlot(
|
||||
loreSlot
|
||||
);
|
||||
|
||||
session.setPendingCategoryLoreExpiration(
|
||||
System.currentTimeMillis()
|
||||
+ 30000
|
||||
);
|
||||
|
||||
final long expiration =
|
||||
session.getPendingCategoryLoreExpiration();
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> {
|
||||
|
||||
if (
|
||||
session.getPendingCategoryLoreExpiration()
|
||||
!= expiration
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPendingCategoryLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
session.setPendingCategoryLoreExpiration(
|
||||
0
|
||||
);
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Lore input timed out."
|
||||
);
|
||||
|
||||
},
|
||||
20L * 30
|
||||
);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Enter lore for line "
|
||||
+ (loreSlot + 1)
|
||||
+ " in chat."
|
||||
);
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Type 'cancel' to abort."
|
||||
);
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Auto-Cancels after 30 seconds."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void createCategory(
|
||||
Player player,
|
||||
GuiSession session
|
||||
) {
|
||||
|
||||
StringBuilder loreBuilder =
|
||||
new StringBuilder();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
String line =
|
||||
session.getPendingCategoryLore(
|
||||
i
|
||||
);
|
||||
|
||||
if (line == null) {
|
||||
|
||||
line = "";
|
||||
|
||||
}
|
||||
|
||||
loreBuilder.append(
|
||||
line
|
||||
);
|
||||
|
||||
if (i < 4) {
|
||||
|
||||
loreBuilder.append(
|
||||
"\n"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CreateCategoryDAO.createCategory(
|
||||
session.getPendingCategoryInternalName(),
|
||||
session.getPendingCategoryDisplayName(),
|
||||
session.getPendingCategoryMaterial(),
|
||||
loreBuilder.toString()
|
||||
);
|
||||
|
||||
session.setPendingCategoryInternalName(
|
||||
null
|
||||
);
|
||||
|
||||
session.setPendingCategoryDisplayName(
|
||||
null
|
||||
);
|
||||
|
||||
session.setPendingCategoryMaterial(
|
||||
null
|
||||
);
|
||||
|
||||
session.clearPendingCategoryLore();
|
||||
|
||||
session.setPendingCategoryLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
CategoryMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryMaterialPickerMenu {
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int page
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"CATEGORY_MATERIAL_PICKER"
|
||||
),
|
||||
54,
|
||||
"Select Material"
|
||||
);
|
||||
|
||||
int slot = 0;
|
||||
|
||||
List<Material> materials =
|
||||
Arrays.stream(
|
||||
Material.values()
|
||||
)
|
||||
.filter(
|
||||
Material::isItem
|
||||
)
|
||||
.filter(
|
||||
material ->
|
||||
!material.name().endsWith(
|
||||
"_SMITHING_TEMPLATE"
|
||||
)
|
||||
)
|
||||
.toList();
|
||||
|
||||
int startIndex =
|
||||
page * 45;
|
||||
|
||||
int maxPages =
|
||||
(int) Math.ceil(
|
||||
(double) materials.size()
|
||||
/ 45
|
||||
);
|
||||
|
||||
for (int inventorySlot = 0;
|
||||
inventorySlot < 45;
|
||||
inventorySlot++) {
|
||||
|
||||
int materialIndex =
|
||||
startIndex + inventorySlot;
|
||||
|
||||
if (materialIndex >= materials.size()) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
inventorySlot,
|
||||
new ItemStack(
|
||||
materials.get(
|
||||
materialIndex
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (page > 0) {
|
||||
|
||||
menu.setItem(
|
||||
45,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§cPrevious Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (page < maxPages - 1) {
|
||||
|
||||
menu.setItem(
|
||||
53,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aNext Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class CategoryMaterialPickerMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"CATEGORY_MATERIAL_PICKER"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
String categoryName =
|
||||
session.getPendingCategoryInternalName();
|
||||
|
||||
if (categoryName == null) {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getSlot() == 45) {
|
||||
|
||||
session.setMaterialPickerPage(
|
||||
Math.max(
|
||||
0,
|
||||
session.getMaterialPickerPage() - 1
|
||||
)
|
||||
);
|
||||
|
||||
CategoryMaterialPickerMenu.open(
|
||||
player,
|
||||
session.getMaterialPickerPage()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getSlot() == 53) {
|
||||
|
||||
session.setMaterialPickerPage(
|
||||
session.getMaterialPickerPage() + 1
|
||||
);
|
||||
|
||||
CategoryMaterialPickerMenu.open(
|
||||
player,
|
||||
session.getMaterialPickerPage()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPendingCategoryMaterial(
|
||||
event.getCurrentItem()
|
||||
.getType()
|
||||
.name()
|
||||
);
|
||||
|
||||
CategoryLoreMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CategoryNameMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Category Name";
|
||||
|
||||
public static void open(Player player) {
|
||||
|
||||
AnvilView view = MenuType.ANVIL
|
||||
.builder()
|
||||
.title(
|
||||
Component.text(
|
||||
TITLE
|
||||
)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm = new ItemStack(Material.LIME_WOOL);
|
||||
|
||||
ItemMeta meta = confirm.getItemMeta();
|
||||
|
||||
meta.displayName(
|
||||
Component.text("")
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Save and proceed to material picker."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(meta);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
|
||||
ItemStack cancel = new ItemStack(Material.RED_WOOL);
|
||||
|
||||
ItemMeta metacancel = cancel.getItemMeta();
|
||||
|
||||
metacancel.displayName(
|
||||
Component.text("")
|
||||
);
|
||||
|
||||
metacancel.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Cancel"
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
cancel.setItemMeta(metacancel);
|
||||
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
).setCategoryInternalNameMenuOpen(
|
||||
true
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package com.rsscripting.rswarehouse.category.categorycreation;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.AdminMenu;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class CategoryNameMenuListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategoryNameMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
if (!session.isCategoryInternalNameMenuOpen()) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String categoryName =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (categoryName.length() > 25) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Category names may not exceed 25 characters."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (categoryName.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Category name cannot be empty."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setPendingCategoryInternalName(
|
||||
categoryName
|
||||
);
|
||||
|
||||
session.setPendingCategoryMaterial(
|
||||
null
|
||||
);
|
||||
|
||||
session.clearPendingCategoryLore();
|
||||
|
||||
event.getView().getTopInventory().clear();
|
||||
|
||||
session.setCategoryInternalNameMenuOpen(
|
||||
false
|
||||
);
|
||||
|
||||
CategoryDisplayNameMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView().getTopInventory().clear();
|
||||
|
||||
AdminMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView()
|
||||
instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategoryNameMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.view.AnvilView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryEditDisplayNameMenu {
|
||||
|
||||
public static final String TITLE =
|
||||
"Edit Display Name";
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
String currentDisplayName
|
||||
) {
|
||||
|
||||
AnvilView view = MenuType.ANVIL
|
||||
.builder()
|
||||
.title(
|
||||
Component.text(
|
||||
TITLE
|
||||
)
|
||||
)
|
||||
.build(player);
|
||||
|
||||
ItemStack confirm =
|
||||
new ItemStack(
|
||||
Material.LIME_WOOL
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
confirm.getItemMeta();
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
currentDisplayName
|
||||
)
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"§aSave display name."
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
confirm.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
view.setItem(
|
||||
0,
|
||||
confirm
|
||||
);
|
||||
|
||||
ItemStack cancel =
|
||||
new ItemStack(
|
||||
Material.RED_WOOL
|
||||
);
|
||||
|
||||
ItemMeta cancelMeta =
|
||||
cancel.getItemMeta();
|
||||
|
||||
cancelMeta.displayName(
|
||||
Component.text("")
|
||||
);
|
||||
|
||||
cancelMeta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"Cancel"
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
cancel.setItemMeta(
|
||||
cancelMeta
|
||||
);
|
||||
|
||||
view.setItem(
|
||||
1,
|
||||
cancel
|
||||
);
|
||||
|
||||
view.open();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.UpdateCategoryDAO;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSessionManager;
|
||||
import com.rsscripting.rswarehouse.category.categoryoptions.CategoryOptionsMenu;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
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.view.AnvilView;
|
||||
|
||||
public class CategoryEditDisplayNameMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView() instanceof AnvilView anvilView)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategoryEditDisplayNameMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
CategoryEditSession session =
|
||||
CategoryEditSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 0) {
|
||||
|
||||
String displayName =
|
||||
anvilView.getRenameText();
|
||||
|
||||
if (displayName.length() > 25) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Category names may not exceed 25 characters."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (displayName.isBlank()) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Category name cannot be empty."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
UpdateCategoryDAO.updateDisplayName(
|
||||
session.getCategoryId(),
|
||||
displayName
|
||||
);
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
CategoryOptionsMenu.open(
|
||||
player,
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryEditSessionManager.removeSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getRawSlot() == 1) {
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
CategoryOptionsMenu.open(
|
||||
player,
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryEditSessionManager.removeSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(
|
||||
InventoryCloseEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView()
|
||||
instanceof AnvilView)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!event.getView()
|
||||
.title()
|
||||
.toString()
|
||||
.contains(
|
||||
CategoryEditDisplayNameMenu.TITLE
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSessionManager;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryEditLoreMenu {
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"CATEGORY_EDIT_LORE"
|
||||
),
|
||||
27,
|
||||
Component.text(
|
||||
" Edit Category Lore"
|
||||
)
|
||||
);
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(
|
||||
i,
|
||||
RSMenuUtils.createFillerPane()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
CategoryEditSession session =
|
||||
CategoryEditSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
String[] loreLines =
|
||||
category.lore() == null
|
||||
? new String[5]
|
||||
: category.lore().split("\n", -1);
|
||||
|
||||
if (session.getLore(0) == null) {
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
if (i < loreLines.length) {
|
||||
|
||||
session.setLore(
|
||||
i,
|
||||
loreLines[i]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
ItemStack book =
|
||||
new ItemStack(
|
||||
Material.WRITABLE_BOOK
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
book.getItemMeta();
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
"Lore Line "
|
||||
+ (i + 1)
|
||||
)
|
||||
);
|
||||
|
||||
List<Component> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
String value =
|
||||
session.getLore(i);
|
||||
|
||||
if (
|
||||
value == null
|
||||
|| value.isBlank()
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"(Empty)"
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
value
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
lore.add(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Click to edit."
|
||||
)
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
lore
|
||||
);
|
||||
|
||||
book.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
11 + i,
|
||||
book
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
22,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.LIME_WOOL,
|
||||
"§aSave Lore"
|
||||
)
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.OAK_DOOR,
|
||||
"§eBack"
|
||||
)
|
||||
);
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class CategoryEditLoreMenuChatListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(
|
||||
AsyncPlayerChatEvent event
|
||||
) {
|
||||
|
||||
Player player =
|
||||
event.getPlayer();
|
||||
|
||||
CategoryEditSession session =
|
||||
CategoryEditSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (session == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int loreSlot =
|
||||
session.getLoreSlot();
|
||||
|
||||
if (loreSlot < 0) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
String message =
|
||||
event.getMessage();
|
||||
|
||||
if (message.length() > 50) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Lore lines may not exceed 50 characters."
|
||||
);
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTask(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> CategoryEditLoreMenu.open(player)
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
message.equalsIgnoreCase(
|
||||
"cancel"
|
||||
)
|
||||
) {
|
||||
|
||||
session.setLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
session.setLoreExpiration(
|
||||
0
|
||||
);
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTask(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> CategoryEditLoreMenu.open(player)
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
message.equalsIgnoreCase("clear")
|
||||
) {
|
||||
|
||||
session.setLore(
|
||||
loreSlot,
|
||||
""
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
session.setLore(
|
||||
loreSlot,
|
||||
message
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
session.setLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
session.setLoreExpiration(
|
||||
0
|
||||
);
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTask(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> {
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Lore line saved."
|
||||
);
|
||||
|
||||
CategoryEditLoreMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.UpdateCategoryDAO;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSessionManager;
|
||||
import com.rsscripting.rswarehouse.category.categoryoptions.CategoryOptionsMenu;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class CategoryEditLoreMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"CATEGORY_EDIT_LORE"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
CategoryEditSession session =
|
||||
CategoryEditSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
switch (event.getSlot()) {
|
||||
|
||||
case 4 -> {
|
||||
|
||||
CategoryOptionsMenu.open(
|
||||
player,
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
case 11 -> editLore(
|
||||
player,
|
||||
session,
|
||||
0
|
||||
);
|
||||
|
||||
case 12 -> editLore(
|
||||
player,
|
||||
session,
|
||||
1
|
||||
);
|
||||
|
||||
case 13 -> editLore(
|
||||
player,
|
||||
session,
|
||||
2
|
||||
);
|
||||
|
||||
case 14 -> editLore(
|
||||
player,
|
||||
session,
|
||||
3
|
||||
);
|
||||
|
||||
case 15 -> editLore(
|
||||
player,
|
||||
session,
|
||||
4
|
||||
);
|
||||
|
||||
case 22 -> saveLore(
|
||||
player,
|
||||
session
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void editLore(
|
||||
Player player,
|
||||
CategoryEditSession session,
|
||||
int loreSlot
|
||||
){
|
||||
|
||||
session.setLoreSlot(
|
||||
loreSlot
|
||||
);
|
||||
|
||||
session.setLoreExpiration(
|
||||
System.currentTimeMillis()
|
||||
+ 30000
|
||||
);
|
||||
|
||||
final long expiration =
|
||||
session.getLoreExpiration();
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(
|
||||
Bukkit.getPluginManager()
|
||||
.getPlugin(
|
||||
"RS-Warehouse"
|
||||
),
|
||||
() -> {
|
||||
|
||||
if (
|
||||
session.getLoreExpiration()
|
||||
!= expiration
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setLoreSlot(
|
||||
-1
|
||||
);
|
||||
|
||||
session.setLoreExpiration(
|
||||
0
|
||||
);
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Lore input timed out."
|
||||
);
|
||||
|
||||
},
|
||||
20L * 30
|
||||
);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Enter lore for line "
|
||||
+ (loreSlot + 1)
|
||||
+ " in chat."
|
||||
);
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Type 'cancel' to abort."
|
||||
);
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Type 'clear' to clear the lore line."
|
||||
);
|
||||
|
||||
RSMessageUtils.info(
|
||||
player,
|
||||
"Auto-Cancels after 30 seconds."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void saveLore(
|
||||
Player player,
|
||||
CategoryEditSession session
|
||||
) {
|
||||
|
||||
StringBuilder loreBuilder =
|
||||
new StringBuilder();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
String line =
|
||||
session.getLore(i);
|
||||
|
||||
if (line == null) {
|
||||
|
||||
line = "";
|
||||
|
||||
}
|
||||
|
||||
loreBuilder.append(
|
||||
line
|
||||
);
|
||||
|
||||
if (i < 4) {
|
||||
|
||||
loreBuilder.append(
|
||||
"\n"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UpdateCategoryDAO.updateLore(
|
||||
session.getCategoryId(),
|
||||
loreBuilder.toString()
|
||||
);
|
||||
|
||||
CategoryEditSessionManager.removeSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
CategoryOptionsMenu.open(
|
||||
player,
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryEditMaterialMenu {
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int page
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"CATEGORY_EDIT_MATERIAL_PICKER"
|
||||
),
|
||||
54,
|
||||
"Select Material"
|
||||
);
|
||||
|
||||
int slot = 0;
|
||||
|
||||
List<Material> materials =
|
||||
Arrays.stream(
|
||||
Material.values()
|
||||
)
|
||||
.filter(
|
||||
Material::isItem
|
||||
)
|
||||
.filter(
|
||||
material ->
|
||||
!material.name().endsWith(
|
||||
"_SMITHING_TEMPLATE"
|
||||
)
|
||||
)
|
||||
.toList();
|
||||
|
||||
int startIndex =
|
||||
page * 45;
|
||||
|
||||
int maxPages =
|
||||
(int) Math.ceil(
|
||||
(double) materials.size()
|
||||
/ 45
|
||||
);
|
||||
|
||||
for (int inventorySlot = 0;
|
||||
inventorySlot < 45;
|
||||
inventorySlot++) {
|
||||
|
||||
int materialIndex =
|
||||
startIndex + inventorySlot;
|
||||
|
||||
if (materialIndex >= materials.size()) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
inventorySlot,
|
||||
new ItemStack(
|
||||
materials.get(
|
||||
materialIndex
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (page > 0) {
|
||||
|
||||
menu.setItem(
|
||||
45,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§cPrevious Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (page < maxPages - 1) {
|
||||
|
||||
menu.setItem(
|
||||
53,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aNext Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryedit;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.admindao.UpdateCategoryDAO;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSessionManager;
|
||||
import com.rsscripting.rswarehouse.category.categoryoptions.CategoryOptionsMenu;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class CategoryEditMaterialMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"CATEGORY_EDIT_MATERIAL_PICKER"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
CategoryEditSession session =
|
||||
CategoryEditSessionManager.getSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
if (event.getSlot() == 45) {
|
||||
|
||||
session.setMaterialPickerPage(
|
||||
Math.max(
|
||||
0,
|
||||
session.getMaterialPickerPage() - 1
|
||||
)
|
||||
);
|
||||
|
||||
CategoryEditMaterialMenu.open(
|
||||
player,
|
||||
session.getMaterialPickerPage()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getSlot() == 53) {
|
||||
|
||||
session.setMaterialPickerPage(
|
||||
session.getMaterialPickerPage() + 1
|
||||
);
|
||||
|
||||
CategoryEditMaterialMenu.open(
|
||||
player,
|
||||
session.getMaterialPickerPage()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
UpdateCategoryDAO.updateMaterial(
|
||||
session.getCategoryId(),
|
||||
event.getCurrentItem()
|
||||
.getType()
|
||||
.name()
|
||||
);
|
||||
|
||||
CategoryOptionsMenu.open(
|
||||
player,
|
||||
session.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryEditSessionManager.removeSession(
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package com.rsscripting.rswarehouse.category.categorymenu;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryDAO {
|
||||
|
||||
public static List<WarehouseCategory> getCategories(){
|
||||
|
||||
List<WarehouseCategory> categories =
|
||||
new ArrayList<>();
|
||||
|
||||
try (
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT
|
||||
id,
|
||||
parent_category_id,
|
||||
internal_name,
|
||||
display_name,
|
||||
material,
|
||||
lore,
|
||||
display_order,
|
||||
page,
|
||||
slot
|
||||
FROM warehouse_categories
|
||||
WHERE parent_category_id IS NULL
|
||||
ORDER BY display_order ASC
|
||||
"""
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery()
|
||||
) {
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
categories.add(
|
||||
new WarehouseCategory(
|
||||
resultSet.getInt(
|
||||
"id"
|
||||
),
|
||||
resultSet.getObject(
|
||||
"parent_category_id"
|
||||
) == null
|
||||
? null
|
||||
: resultSet.getInt(
|
||||
"parent_category_id"
|
||||
),
|
||||
resultSet.getString(
|
||||
"internal_name"
|
||||
),
|
||||
resultSet.getString(
|
||||
"display_name"
|
||||
),
|
||||
resultSet.getString(
|
||||
"material"
|
||||
),
|
||||
resultSet.getString(
|
||||
"lore"
|
||||
),
|
||||
resultSet.getInt(
|
||||
"display_order"
|
||||
),
|
||||
resultSet.getInt(
|
||||
"page"
|
||||
),
|
||||
resultSet.getInt(
|
||||
"slot"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return categories;
|
||||
|
||||
}
|
||||
|
||||
public static WarehouseCategory getCategoryById(
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT
|
||||
id,
|
||||
parent_category_id,
|
||||
internal_name,
|
||||
display_name,
|
||||
material,
|
||||
lore,
|
||||
display_order,
|
||||
page,
|
||||
slot
|
||||
FROM warehouse_categories
|
||||
WHERE id = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setInt(
|
||||
1,
|
||||
categoryId
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
return new WarehouseCategory(
|
||||
resultSet.getInt(
|
||||
"id"
|
||||
),
|
||||
resultSet.getObject(
|
||||
"parent_category_id"
|
||||
) == null
|
||||
? null
|
||||
: resultSet.getInt(
|
||||
"parent_category_id"
|
||||
),
|
||||
resultSet.getString(
|
||||
"internal_name"
|
||||
),
|
||||
resultSet.getString(
|
||||
"display_name"
|
||||
),
|
||||
resultSet.getString(
|
||||
"material"
|
||||
),
|
||||
resultSet.getString(
|
||||
"lore"
|
||||
),
|
||||
resultSet.getInt(
|
||||
"display_order"
|
||||
),
|
||||
resultSet.getInt(
|
||||
"page"
|
||||
),
|
||||
resultSet.getInt(
|
||||
"slot"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static boolean categoryExists(
|
||||
String name
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT 1
|
||||
FROM warehouse_categories
|
||||
WHERE LOWER(internal_name) = LOWER(?)
|
||||
LIMIT 1
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
name
|
||||
);
|
||||
|
||||
return statement.executeQuery().next();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public static void deleteCategory(
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE
|
||||
FROM warehouse_categories
|
||||
WHERE id = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setInt(
|
||||
1,
|
||||
categoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package com.rsscripting.rswarehouse.category.categorymenu;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryMenu {
|
||||
|
||||
public static final String MENU_TITLE =
|
||||
"Categories";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
open(
|
||||
player,
|
||||
1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int page
|
||||
) {
|
||||
|
||||
RSMenuHolder holder =
|
||||
new RSMenuHolder(
|
||||
"CATEGORIES"
|
||||
);
|
||||
|
||||
holder.setPage(
|
||||
page
|
||||
);
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
holder,
|
||||
54,
|
||||
Component.text(
|
||||
MENU_TITLE
|
||||
).color(
|
||||
NamedTextColor.BLUE
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (
|
||||
int slot = 0;
|
||||
slot <= 8;
|
||||
slot++
|
||||
) {
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
2,
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
Material.HOPPER,
|
||||
"§aAuto Deposit",
|
||||
List.of(
|
||||
"§7Automatically deposits",
|
||||
"§7matching items into",
|
||||
"§7Warehouse when picked up.",
|
||||
"",
|
||||
"§eClick to open."
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
List<WarehouseCategory> categories =
|
||||
CategoryDAO.getCategories();
|
||||
|
||||
WarehouseCategory uncategorized =
|
||||
null;
|
||||
|
||||
List<WarehouseCategory> displayCategories =
|
||||
new ArrayList<>();
|
||||
|
||||
for (
|
||||
WarehouseCategory category
|
||||
: categories
|
||||
) {
|
||||
|
||||
if (
|
||||
category.displayName()
|
||||
.equalsIgnoreCase(
|
||||
"Uncategorized"
|
||||
)
|
||||
) {
|
||||
|
||||
uncategorized =
|
||||
category;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
displayCategories.add(
|
||||
category
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (page > 1) {
|
||||
|
||||
menu.setItem(
|
||||
0,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aPrevious Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
for (
|
||||
WarehouseCategory category
|
||||
: displayCategories
|
||||
) {
|
||||
|
||||
if (
|
||||
category.page() <= 0
|
||||
|| category.slot() <= 0
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
category.page()
|
||||
!= page
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
int slot =
|
||||
category.slot();
|
||||
|
||||
if (
|
||||
slot < 9
|
||||
|| slot > 53
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
List<String> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
if (
|
||||
category.lore() != null
|
||||
&& !category.lore()
|
||||
.isBlank()
|
||||
) {
|
||||
|
||||
lore.addAll(
|
||||
Arrays.asList(
|
||||
category.lore()
|
||||
.split(
|
||||
"\n"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemStack icon =
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
Material.valueOf(
|
||||
category.material()
|
||||
),
|
||||
"§a"
|
||||
+ category.displayName(),
|
||||
lore
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
icon.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
meta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
|
||||
meta.getPersistentDataContainer()
|
||||
.set(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
category.id()
|
||||
);
|
||||
|
||||
icon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
icon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
int highestAssignedPage = 1;
|
||||
|
||||
List<WarehouseCategory> unassigned =
|
||||
new ArrayList<>();
|
||||
|
||||
for (
|
||||
WarehouseCategory category
|
||||
: displayCategories
|
||||
) {
|
||||
|
||||
if (
|
||||
category.page() > 0
|
||||
) {
|
||||
|
||||
highestAssignedPage =
|
||||
Math.max(
|
||||
highestAssignedPage,
|
||||
category.page()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
category.page() <= 0
|
||||
|| category.slot() <= 0
|
||||
) {
|
||||
|
||||
unassigned.add(
|
||||
category
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean hasNextPage =
|
||||
displayCategories.stream()
|
||||
.anyMatch(
|
||||
category ->
|
||||
category.page()
|
||||
> page
|
||||
);
|
||||
|
||||
if (
|
||||
!unassigned.isEmpty()
|
||||
&& page
|
||||
== highestAssignedPage
|
||||
) {
|
||||
|
||||
hasNextPage =
|
||||
true;
|
||||
|
||||
}
|
||||
|
||||
if (hasNextPage) {
|
||||
|
||||
menu.setItem(
|
||||
8,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aNext Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
page
|
||||
== highestAssignedPage + 1
|
||||
) {
|
||||
|
||||
int slot = 9;
|
||||
|
||||
for (
|
||||
WarehouseCategory category
|
||||
: unassigned
|
||||
) {
|
||||
|
||||
if (slot > 53) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<String> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
if (
|
||||
category.lore() != null
|
||||
&& !category.lore()
|
||||
.isBlank()
|
||||
) {
|
||||
|
||||
lore.addAll(
|
||||
Arrays.asList(
|
||||
category.lore()
|
||||
.split(
|
||||
"\n"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemStack icon =
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
Material.valueOf(
|
||||
category.material()
|
||||
),
|
||||
"§a"
|
||||
+ category.displayName(),
|
||||
lore
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
icon.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
meta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
|
||||
meta.getPersistentDataContainer()
|
||||
.set(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
category.id()
|
||||
);
|
||||
|
||||
icon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
icon
|
||||
);
|
||||
|
||||
slot++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (uncategorized != null) {
|
||||
|
||||
ItemStack icon =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.valueOf(
|
||||
uncategorized.material()
|
||||
),
|
||||
"§a"
|
||||
+ uncategorized.displayName()
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
icon.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
meta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
|
||||
meta.getPersistentDataContainer()
|
||||
.set(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
uncategorized.id()
|
||||
);
|
||||
|
||||
icon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
icon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
package com.rsscripting.rswarehouse.category.categorymenu;
|
||||
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categoryoptions.CategoryOptionsMenu;
|
||||
import com.rsscripting.rswarehouse.autodeposit.AutoDepositMenu;
|
||||
import com.rsscripting.rswarehouse.item.ItemsMenu;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
|
||||
public class CategoryMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
if (event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder
|
||||
&& holder.getMenuId().equals(
|
||||
"CATEGORIES"
|
||||
)) {
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
ItemStack clicked =
|
||||
event.getCurrentItem();
|
||||
|
||||
if (clicked == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta =
|
||||
clicked.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
RSMenuHolder menuHolder =
|
||||
(RSMenuHolder)
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder();
|
||||
|
||||
int currentPage =
|
||||
menuHolder.getPage();
|
||||
|
||||
if (
|
||||
event.getRawSlot() == 2
|
||||
) {
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
session.setAutoDepositPage(
|
||||
1
|
||||
);
|
||||
|
||||
AutoDepositMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 0
|
||||
) {
|
||||
|
||||
CategoryMenu.open(
|
||||
player,
|
||||
currentPage - 1
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 8
|
||||
) {
|
||||
|
||||
CategoryMenu.open(
|
||||
player,
|
||||
currentPage + 1
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Integer categoryId =
|
||||
meta.getPersistentDataContainer().get(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER
|
||||
);
|
||||
|
||||
if (categoryId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
player.isOp()
|
||||
&& event.getClick()
|
||||
== ClickType.SHIFT_RIGHT
|
||||
) {
|
||||
|
||||
CategoryOptionsMenu.open(
|
||||
player,
|
||||
categoryId
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
String categoryName =
|
||||
clicked.getItemMeta()
|
||||
.getDisplayName();
|
||||
|
||||
NavigationManager.openItems(
|
||||
player,
|
||||
categoryId,
|
||||
categoryName,
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+236
@@ -0,0 +1,236 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryoptions;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class CategoryOptionsMenu {
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new CategoryOptionsMenuHolder(
|
||||
categoryId
|
||||
),
|
||||
27,
|
||||
"Category Options"
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
new ItemStack(
|
||||
Material.LIGHT_BLUE_STAINED_GLASS_PANE
|
||||
);
|
||||
|
||||
ItemMeta fillerMeta =
|
||||
filler.getItemMeta();
|
||||
|
||||
fillerMeta.displayName(
|
||||
Component.text(
|
||||
" "
|
||||
)
|
||||
);
|
||||
|
||||
filler.setItemMeta(
|
||||
fillerMeta
|
||||
);
|
||||
|
||||
for (
|
||||
int i = 0;
|
||||
i <= 8;
|
||||
i++
|
||||
) {
|
||||
|
||||
menu.setItem(
|
||||
i,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemStack back =
|
||||
new ItemStack(
|
||||
Material.OAK_DOOR
|
||||
);
|
||||
|
||||
ItemMeta backMeta =
|
||||
back.getItemMeta();
|
||||
|
||||
backMeta.displayName(
|
||||
Component.text(
|
||||
"Back"
|
||||
).color(
|
||||
NamedTextColor.GREEN
|
||||
)
|
||||
);
|
||||
|
||||
back.setItemMeta(
|
||||
backMeta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
back
|
||||
);
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
ItemStack editName =
|
||||
new ItemStack(
|
||||
Material.NAME_TAG
|
||||
);
|
||||
|
||||
ItemMeta editNameMeta =
|
||||
editName.getItemMeta();
|
||||
|
||||
editNameMeta.displayName(
|
||||
Component.text(
|
||||
"Edit Display Name"
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
);
|
||||
|
||||
editName.setItemMeta(
|
||||
editNameMeta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
9,
|
||||
editName
|
||||
);
|
||||
|
||||
ItemStack pageSlot =
|
||||
new ItemStack(
|
||||
Material.BOOK
|
||||
);
|
||||
|
||||
ItemMeta pageSlotMeta =
|
||||
pageSlot.getItemMeta();
|
||||
|
||||
pageSlotMeta.displayName(
|
||||
Component.text(
|
||||
"Assign Page / Slot"
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
);
|
||||
|
||||
pageSlot.setItemMeta(
|
||||
pageSlotMeta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
11,
|
||||
pageSlot
|
||||
);
|
||||
|
||||
ItemStack editLore =
|
||||
new ItemStack(
|
||||
Material.WRITABLE_BOOK
|
||||
);
|
||||
|
||||
ItemMeta editLoreMeta =
|
||||
editLore.getItemMeta();
|
||||
|
||||
editLoreMeta.displayName(
|
||||
Component.text(
|
||||
"Edit Lore"
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
);
|
||||
|
||||
editLore.setItemMeta(
|
||||
editLoreMeta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
13,
|
||||
editLore
|
||||
);
|
||||
|
||||
ItemStack material =
|
||||
new ItemStack(
|
||||
Material.ITEM_FRAME
|
||||
);
|
||||
|
||||
ItemMeta materialMeta =
|
||||
material.getItemMeta();
|
||||
|
||||
materialMeta.displayName(
|
||||
Component.text(
|
||||
"Change Material"
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
);
|
||||
|
||||
material.setItemMeta(
|
||||
materialMeta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
15,
|
||||
material
|
||||
);
|
||||
|
||||
ItemStack delete =
|
||||
new ItemStack(
|
||||
Material.BARRIER
|
||||
);
|
||||
|
||||
ItemMeta deleteMeta =
|
||||
delete.getItemMeta();
|
||||
|
||||
deleteMeta.displayName(
|
||||
Component.text(
|
||||
"Delete Category"
|
||||
).color(
|
||||
NamedTextColor.RED
|
||||
)
|
||||
);
|
||||
|
||||
deleteMeta.lore(
|
||||
java.util.List.of(
|
||||
Component.text(
|
||||
"Warning!!"
|
||||
).color(
|
||||
NamedTextColor.RED
|
||||
),
|
||||
Component.text(
|
||||
"This cannot be undone."
|
||||
).color(
|
||||
NamedTextColor.GRAY
|
||||
),
|
||||
Component.empty(),
|
||||
Component.text(
|
||||
"Category must be empty."
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
delete.setItemMeta(
|
||||
deleteMeta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
17,
|
||||
delete
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryoptions;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class CategoryOptionsMenuHolder
|
||||
implements InventoryHolder {
|
||||
|
||||
private final int categoryId;
|
||||
|
||||
public CategoryOptionsMenuHolder(
|
||||
int categoryId
|
||||
) {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public int getCategoryId() {
|
||||
return categoryId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
package com.rsscripting.rswarehouse.category.categoryoptions;
|
||||
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSession;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryEditSessionManager;
|
||||
import com.rsscripting.rswarehouse.admin.assignpageslot.CategoryPageNumberMenu;
|
||||
import com.rsscripting.rswarehouse.admin.adminsessions.CategoryPageSlotSessionManager;
|
||||
import com.rsscripting.rswarehouse.category.categoryedit.CategoryEditDisplayNameMenu;
|
||||
import com.rsscripting.rswarehouse.category.categoryedit.CategoryEditLoreMenu;
|
||||
import com.rsscripting.rswarehouse.category.categoryedit.CategoryEditMaterialMenu;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class CategoryOptionsMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder()
|
||||
instanceof CategoryOptionsMenuHolder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 4
|
||||
) {
|
||||
|
||||
CategoryMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 9
|
||||
)
|
||||
{
|
||||
|
||||
CategoryOptionsMenuHolder holder =
|
||||
(CategoryOptionsMenuHolder)
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder();
|
||||
|
||||
CategoryEditSession session =
|
||||
CategoryEditSessionManager.createSession(
|
||||
player.getUniqueId(),
|
||||
holder.getCategoryId()
|
||||
);
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
holder.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryEditDisplayNameMenu.open(
|
||||
player,
|
||||
category.displayName()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 11
|
||||
) {
|
||||
|
||||
CategoryOptionsMenuHolder holder =
|
||||
(CategoryOptionsMenuHolder)
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder();
|
||||
|
||||
CategoryPageSlotSessionManager.createSession(
|
||||
player.getUniqueId(),
|
||||
holder.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryPageNumberMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 13
|
||||
)
|
||||
{
|
||||
|
||||
CategoryOptionsMenuHolder holder =
|
||||
(CategoryOptionsMenuHolder)
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder();
|
||||
|
||||
CategoryEditSessionManager.createSession(
|
||||
player.getUniqueId(),
|
||||
holder.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryEditLoreMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 15
|
||||
)
|
||||
{
|
||||
|
||||
CategoryOptionsMenuHolder holder =
|
||||
(CategoryOptionsMenuHolder)
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder();
|
||||
|
||||
CategoryEditSessionManager.createSession(
|
||||
player.getUniqueId(),
|
||||
holder.getCategoryId()
|
||||
);
|
||||
|
||||
CategoryEditMaterialMenu.open(
|
||||
player,
|
||||
0
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
event.getRawSlot()
|
||||
== 17
|
||||
)
|
||||
{
|
||||
|
||||
CategoryOptionsMenuHolder holder =
|
||||
(CategoryOptionsMenuHolder)
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder();
|
||||
|
||||
int categoryId =
|
||||
holder.getCategoryId();
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
categoryId
|
||||
);
|
||||
|
||||
if (
|
||||
category != null
|
||||
&&
|
||||
category.internalName()
|
||||
.equalsIgnoreCase(
|
||||
"uncategorized"
|
||||
)
|
||||
) {
|
||||
|
||||
player.sendMessage(
|
||||
Component.text(
|
||||
"Uncategorized cannot be deleted."
|
||||
).color(
|
||||
NamedTextColor.RED
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
ItemDAO.categoryHasItems(
|
||||
categoryId
|
||||
)
|
||||
) {
|
||||
|
||||
player.sendMessage(
|
||||
Component.text(
|
||||
"Cannot delete category. Category not empty."
|
||||
).color(
|
||||
NamedTextColor.RED
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
CategoryDAO.deleteCategory(
|
||||
categoryId
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
Component.text(
|
||||
"Category deleted."
|
||||
).color(
|
||||
NamedTextColor.GREEN
|
||||
)
|
||||
);
|
||||
|
||||
CategoryMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
package com.rsscripting.rswarehouse.category.copytocategory;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CopyToCategoryMenu {
|
||||
|
||||
public static final String MENU_TITLE =
|
||||
"Copy To Category";
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int itemId,
|
||||
int page
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new CopyToCategoryMenuHolder(
|
||||
itemId,
|
||||
page
|
||||
),
|
||||
54,
|
||||
Component.text(
|
||||
MENU_TITLE
|
||||
).color(
|
||||
NamedTextColor.BLUE
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (int slot = 0; slot <= 8; slot++) {
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
for (int slot = 45; slot <= 53; slot++) {
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
List<WarehouseCategory> categories =
|
||||
CategoryDAO.getCategories();
|
||||
|
||||
List<WarehouseCategory> displayCategories =
|
||||
new ArrayList<>();
|
||||
|
||||
for (WarehouseCategory category : categories) {
|
||||
displayCategories.add(
|
||||
category
|
||||
);
|
||||
}
|
||||
|
||||
int pageSize = 36;
|
||||
|
||||
int maxPage =
|
||||
Math.max(
|
||||
0,
|
||||
(displayCategories.size() - 1)
|
||||
/ pageSize
|
||||
);
|
||||
|
||||
int startIndex =
|
||||
page * pageSize;
|
||||
|
||||
int endIndex =
|
||||
Math.min(
|
||||
startIndex + pageSize,
|
||||
displayCategories.size()
|
||||
);
|
||||
|
||||
boolean hasPrevious =
|
||||
page > 0;
|
||||
|
||||
boolean hasNext =
|
||||
page < maxPage;
|
||||
|
||||
if (hasPrevious) {
|
||||
|
||||
menu.setItem(
|
||||
0,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aPrevious Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (hasNext) {
|
||||
|
||||
menu.setItem(
|
||||
8,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aNext Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
int slot = 9;
|
||||
|
||||
for (
|
||||
|
||||
int i = startIndex;
|
||||
|
||||
i < endIndex;
|
||||
|
||||
i++
|
||||
|
||||
) {
|
||||
|
||||
WarehouseCategory category =
|
||||
displayCategories.get(
|
||||
i
|
||||
);
|
||||
|
||||
List<String> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
if (
|
||||
category.lore() != null
|
||||
&&
|
||||
!category.lore().isBlank()
|
||||
) {
|
||||
|
||||
lore.addAll(
|
||||
Arrays.asList(
|
||||
category.lore().split("\n")
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemStack icon =
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
Material.valueOf(
|
||||
category.material()
|
||||
),
|
||||
"§a" + category.displayName(),
|
||||
lore
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
icon.getItemMeta();
|
||||
|
||||
meta.getPersistentDataContainer().set(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
category.id()
|
||||
);
|
||||
|
||||
icon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
slot++,
|
||||
icon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.rsscripting.rswarehouse.category.copytocategory;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
|
||||
public class CopyToCategoryMenuHolder
|
||||
extends RSMenuHolder {
|
||||
|
||||
private final int itemId;
|
||||
|
||||
private final int page;
|
||||
|
||||
public CopyToCategoryMenuHolder(
|
||||
int itemId,
|
||||
int page
|
||||
) {
|
||||
|
||||
super(
|
||||
"COPY_TO_CATEGORY"
|
||||
);
|
||||
|
||||
this.itemId =
|
||||
itemId;
|
||||
|
||||
this.page =
|
||||
page;
|
||||
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
|
||||
return itemId;
|
||||
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package com.rsscripting.rswarehouse.category.copytocategory;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.placement.placementdao.ItemPlacementDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import com.rsscripting.rswarehouse.item.ItemsMenu;
|
||||
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.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class CopyToCategoryMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getWhoClicked()
|
||||
instanceof Player player)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof CopyToCategoryMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"COPY_TO_CATEGORY"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
ItemStack clicked =
|
||||
event.getCurrentItem();
|
||||
|
||||
if (clicked == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ItemMeta meta =
|
||||
clicked.getItemMeta();
|
||||
|
||||
if (
|
||||
clicked.getType() == Material.ARROW
|
||||
) {
|
||||
|
||||
String name =
|
||||
clicked.getItemMeta()
|
||||
.getDisplayName();
|
||||
|
||||
if (name.equals("§aPrevious Page")) {
|
||||
|
||||
CopyToCategoryMenu.open(
|
||||
player,
|
||||
holder.getItemId(),
|
||||
holder.getPage() - 1
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (name.equals("§aNext Page")) {
|
||||
|
||||
CopyToCategoryMenu.open(
|
||||
player,
|
||||
holder.getItemId(),
|
||||
holder.getPage() + 1
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (meta == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Integer categoryId =
|
||||
meta.getPersistentDataContainer().get(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER
|
||||
);
|
||||
|
||||
if (categoryId == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ItemPlacementDAO.copyItemToCategory(
|
||||
holder.getItemId(),
|
||||
categoryId
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
"§aItem copied successfully."
|
||||
);
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
categoryId
|
||||
);
|
||||
|
||||
if (category != null) {
|
||||
|
||||
ItemsMenu.open(
|
||||
player,
|
||||
category.id(),
|
||||
category.displayName(),
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
package com.rsscripting.rswarehouse.category.movetocategory;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.utils.MenuAutoCenterAndPagenation;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MoveToCategoryMenu {
|
||||
|
||||
public static final String MENU_TITLE =
|
||||
"Move Item To Category";
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int itemId
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new MoveToCategoryMenuHolder(
|
||||
itemId
|
||||
),
|
||||
54,
|
||||
Component.text(
|
||||
MENU_TITLE
|
||||
).color(
|
||||
NamedTextColor.BLUE
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (int slot = 0; slot <= 8; slot++) {
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
for (int slot = 45; slot <= 53; slot++) {
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
List<WarehouseCategory> categories =
|
||||
CategoryDAO.getCategories();
|
||||
|
||||
WarehouseCategory uncategorized = null;
|
||||
|
||||
List<WarehouseCategory> displayCategories =
|
||||
new ArrayList<>();
|
||||
|
||||
for (WarehouseCategory category : categories) {
|
||||
|
||||
if (category.displayName().equalsIgnoreCase(
|
||||
"Uncategorized"
|
||||
)) {
|
||||
|
||||
uncategorized = category;
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
displayCategories.add(
|
||||
category
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int categoryIndex = 0;
|
||||
|
||||
for (int row = 0;
|
||||
row < 4;
|
||||
row++) {
|
||||
|
||||
int remaining =
|
||||
displayCategories.size()
|
||||
- categoryIndex;
|
||||
|
||||
if (remaining <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
int itemsThisRow;
|
||||
|
||||
if (remaining > 9) {
|
||||
|
||||
itemsThisRow = 9;
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
itemsThisRow = remaining;
|
||||
|
||||
}
|
||||
|
||||
List<Integer> rowSlots =
|
||||
MenuAutoCenterAndPagenation
|
||||
.getCenteredRowSlots(
|
||||
itemsThisRow
|
||||
);
|
||||
|
||||
if (itemsThisRow == 9) {
|
||||
|
||||
rowSlots = List.of(
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
int rowOffset =
|
||||
9 + (row * 9);
|
||||
|
||||
for (int slot : rowSlots) {
|
||||
|
||||
if (categoryIndex >=
|
||||
displayCategories.size()) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
WarehouseCategory category =
|
||||
displayCategories.get(
|
||||
categoryIndex
|
||||
);
|
||||
|
||||
List<String> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
if (
|
||||
category.lore() != null
|
||||
&& !category.lore().isBlank()
|
||||
) {
|
||||
|
||||
lore.addAll(
|
||||
Arrays.asList(
|
||||
category.lore()
|
||||
.split("\n")
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemStack icon =
|
||||
RSMenuUtils.createMenuItemWithLore(
|
||||
Material.valueOf(
|
||||
category.material()
|
||||
),
|
||||
"§a" + category.displayName(),
|
||||
lore
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
icon.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
meta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
|
||||
meta.getPersistentDataContainer().set(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
category.id()
|
||||
);
|
||||
|
||||
icon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
rowOffset + slot,
|
||||
icon
|
||||
);
|
||||
|
||||
categoryIndex++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (uncategorized != null) {
|
||||
|
||||
ItemStack icon =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.valueOf(
|
||||
uncategorized.material()
|
||||
),
|
||||
"§a" + uncategorized.displayName()
|
||||
);
|
||||
|
||||
ItemMeta meta =
|
||||
icon.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
meta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
|
||||
meta.getPersistentDataContainer().set(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
uncategorized.id()
|
||||
);
|
||||
|
||||
icon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
icon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.rsscripting.rswarehouse.category.movetocategory;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
|
||||
public class MoveToCategoryMenuHolder
|
||||
extends RSMenuHolder {
|
||||
|
||||
private final int itemId;
|
||||
|
||||
public MoveToCategoryMenuHolder(
|
||||
int itemId
|
||||
) {
|
||||
|
||||
super(
|
||||
"MOVE_TO_CATEGORY"
|
||||
);
|
||||
|
||||
this.itemId =
|
||||
itemId;
|
||||
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
|
||||
return itemId;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package com.rsscripting.rswarehouse.category.movetocategory;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.placement.placementdao.ItemPlacementDAO;
|
||||
import com.rsscripting.rswarehouse.item.ItemsMenu;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class MoveToCategoryMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getWhoClicked()
|
||||
instanceof Player player)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof MoveToCategoryMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"MOVE_TO_CATEGORY"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
ItemStack clicked =
|
||||
event.getCurrentItem();
|
||||
|
||||
if (clicked == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ItemMeta meta =
|
||||
clicked.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Integer categoryId =
|
||||
meta.getPersistentDataContainer().get(
|
||||
RSKeys.CATEGORY_ID,
|
||||
PersistentDataType.INTEGER
|
||||
);
|
||||
|
||||
if (categoryId == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ItemPlacementDAO.moveItemToCategory(
|
||||
holder.getItemId(),
|
||||
categoryId
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
"§aItem moved successfully."
|
||||
);
|
||||
|
||||
WarehouseCategory category =
|
||||
CategoryDAO.getCategoryById(
|
||||
categoryId
|
||||
);
|
||||
|
||||
if (category != null) {
|
||||
|
||||
ItemsMenu.open(
|
||||
player,
|
||||
category.id(),
|
||||
category.displayName(),
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package com.rsscripting.rswarehouse.chestautoprocess;
|
||||
|
||||
import com.rsscripting.rswarehouse.deposit.dao.ChestDAO;
|
||||
import com.rsscripting.rswarehouse.deposit.dao.WarehouseChestDAO;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import com.rsscripting.rswarehouse.deposit.WarehouseChestProcessor;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChestAutoProcessingTask
|
||||
extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
List<Block> chests =
|
||||
WarehouseChestDAO.getAllWarehouseChests();
|
||||
|
||||
for (Block block : chests) {
|
||||
|
||||
if (!block.getChunk().isLoaded()) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (!(block.getState()
|
||||
instanceof Chest chest)) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
String ownerName =
|
||||
ChestDAO.getOwnerName(
|
||||
chest.getBlock()
|
||||
);
|
||||
|
||||
String ownerUuid =
|
||||
ChestDAO.getOwnerUuid(
|
||||
chest.getBlock()
|
||||
);
|
||||
|
||||
int[] results =
|
||||
WarehouseChestProcessor.processWarehouseChest(
|
||||
chest
|
||||
);
|
||||
|
||||
int processedStacks =
|
||||
results[0];
|
||||
|
||||
int processedItems =
|
||||
results[1];
|
||||
|
||||
if (processedStacks <= 0) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
Player owner =
|
||||
ChestDAO.getOnlineOwner(
|
||||
chest
|
||||
);
|
||||
|
||||
if (owner == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
owner.sendMessage(
|
||||
"§aYour Community Warehouse processed "
|
||||
+ processedItems
|
||||
+ " item"
|
||||
+ (processedItems == 1 ? "" : "s")
|
||||
+ " from "
|
||||
+ processedStacks
|
||||
+ " stack"
|
||||
+ (processedStacks == 1 ? "" : "s")
|
||||
+ "."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.rsscripting.rswarehouse.commands;
|
||||
|
||||
import com.rsscripting.rswarehouse.config.ConfigManager;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.constants.RSConstants;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import com.rsscripting.rswarehouse.utils.VersionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RSPluginCommand
|
||||
implements CommandExecutor {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
|
||||
@NotNull CommandSender sender,
|
||||
@NotNull Command command,
|
||||
@NotNull String label,
|
||||
@NotNull String @NotNull [] args
|
||||
|
||||
) {
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| BASE COMMAND
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (args.length == 0) {
|
||||
|
||||
sender.sendMessage(
|
||||
RSConstants.PREFIX
|
||||
+ "Running "
|
||||
+ RSConstants.PLUGIN_NAME
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RELOAD COMMAND
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (args[0].equalsIgnoreCase(
|
||||
"reload"
|
||||
)) {
|
||||
|
||||
if (!sender.hasPermission(
|
||||
RSConstants.ADMIN_PERMISSION
|
||||
)) {
|
||||
|
||||
sender.sendMessage(
|
||||
RSConstants.PREFIX
|
||||
+ "No permission."
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
ConfigManager.reload();
|
||||
|
||||
sender.sendMessage(
|
||||
RSConstants.PREFIX
|
||||
+ "Configuration reloaded."
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| OPEN COMMAND
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (args[0].equalsIgnoreCase(
|
||||
"open"
|
||||
)) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
|
||||
sender.sendMessage(
|
||||
RSConstants.PREFIX
|
||||
+ "Players only."
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
NavigationManager.clear(player);
|
||||
NavigationManager.openCategory(player, 1);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| VERSION COMMAND
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (args[0].equalsIgnoreCase(
|
||||
"version"
|
||||
)) {
|
||||
|
||||
sender.sendMessage(
|
||||
RSConstants.PREFIX
|
||||
+ RSConstants.PLUGIN_NAME
|
||||
+ " v"
|
||||
+ VersionUtils.getVersion()
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.rsscripting.rswarehouse.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RSTabCompleter
|
||||
implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(
|
||||
|
||||
@NotNull CommandSender sender,
|
||||
@NotNull Command command,
|
||||
@NotNull String label,
|
||||
@NotNull String @NotNull [] args
|
||||
|
||||
|
||||
) {
|
||||
|
||||
List<String> completions =
|
||||
new ArrayList<>();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FIRST ARGUMENT
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (args.length == 1) {
|
||||
|
||||
completions.add("reload");
|
||||
|
||||
completions.add("version");
|
||||
|
||||
completions.add("open");
|
||||
|
||||
}
|
||||
|
||||
return completions;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.rsscripting.rswarehouse.commands;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.deposit.DepositInventory;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ShopCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
@NotNull CommandSender sender,
|
||||
@NotNull Command command,
|
||||
@NotNull String label,
|
||||
@NotNull String[] args
|
||||
) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("deposit")) {
|
||||
DepositInventory.open(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
NavigationManager.clear(player);
|
||||
NavigationManager.openCategory(player, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.rsscripting.rswarehouse.config;
|
||||
|
||||
import com.rsscripting.rswarehouse.RSWarehouse;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private static FileConfiguration config;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| SETUP
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static void setup() {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.saveDefaultConfig();
|
||||
|
||||
config =
|
||||
RSWarehouse.getInstance()
|
||||
.getConfig();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RELOAD
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static void reload() {
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.reloadConfig();
|
||||
|
||||
config =
|
||||
RSWarehouse.getInstance()
|
||||
.getConfig();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| GET CONFIG
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static FileConfiguration get() {
|
||||
|
||||
return config;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
| Warehouse Chest name
|
||||
*/
|
||||
|
||||
public String getWarehouseChestName() {
|
||||
|
||||
return config.getString(
|
||||
"warehouse-chest-name",
|
||||
"Community Warehouse"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
| Uncateforized enabled
|
||||
*/
|
||||
|
||||
public boolean isUncategorizedEnabled() {
|
||||
|
||||
return config.getBoolean(
|
||||
"allow-uncategorized-item-creation",
|
||||
true
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
| Chest Protection Enabled
|
||||
*/
|
||||
|
||||
public boolean isWarehouseChestProtectionEnabled() {
|
||||
|
||||
return config.getBoolean(
|
||||
"protect-warehouse-chests",
|
||||
true
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.rsscripting.rswarehouse.constants;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class RSConstants {
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| PLUGIN INFO
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final String PLUGIN_NAME =
|
||||
"RS-Warehouse";
|
||||
|
||||
public static final String PREFIX =
|
||||
"§7[§cRS-Warehouse§7] §r";
|
||||
|
||||
public static final String COMMAND_ALIAS =
|
||||
"rswarehouse";
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| GITHUB
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final String GITHUB_USER =
|
||||
"RS-Scripting";
|
||||
|
||||
public static final String GITHUB_REPOSITORY =
|
||||
"RS-Warehouse";
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| PERMISSIONS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final String ADMIN_PERMISSION =
|
||||
"rswarehouse.admin";
|
||||
|
||||
public static final String BYPASS_PERMISSION =
|
||||
"rswarehouse.bypass";
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| REQUIRED CONVERSION ITEMS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final Material REQUIRED_HELD_ITEM =
|
||||
Material.STICK;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| REQUIRED TARGET ENTITY
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final Material
|
||||
REQUIRED_TARGET_BLOCK =
|
||||
Material.CHEST;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| MENU SETTINGS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final Material MENU_FILLER_MATERIAL =
|
||||
Material.WHITE_STAINED_GLASS_PANE;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.rsscripting.rswarehouse.constants;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import com.rsscripting.rswarehouse.RSWarehouse;
|
||||
|
||||
public class RSKeys {
|
||||
|
||||
public static final String FILTER_ALLOW_ALL =
|
||||
"allow_all";
|
||||
|
||||
public static final String FILTER_WHITELIST =
|
||||
"whitelist";
|
||||
|
||||
public static final String FILTER_BLACKLIST =
|
||||
"blacklist";
|
||||
|
||||
public static final NamespacedKey CATEGORY_ID =
|
||||
new NamespacedKey(
|
||||
RSWarehouse.getInstance(),
|
||||
"category_id"
|
||||
);
|
||||
|
||||
public static final NamespacedKey ITEM_ID =
|
||||
new NamespacedKey(
|
||||
RSWarehouse.getInstance(),
|
||||
"item_id"
|
||||
);
|
||||
|
||||
public static final NamespacedKey DAMAGED_VARIANT_ID =
|
||||
new NamespacedKey(
|
||||
RSWarehouse.getInstance(),
|
||||
"damaged_variant_id"
|
||||
);
|
||||
|
||||
public static final NamespacedKey PARTIALLY_FILLED_VARIANT_ID =
|
||||
new NamespacedKey(
|
||||
RSWarehouse.getInstance(),
|
||||
"partially_filled_variant_id"
|
||||
);
|
||||
|
||||
public static final NamespacedKey ENCHANTED_VARIANT_ID =
|
||||
new NamespacedKey(
|
||||
RSWarehouse.getInstance(),
|
||||
"enchanted_variant_id"
|
||||
);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.rsscripting.rswarehouse.conversion;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ConvertMenu {
|
||||
|
||||
public static final String MENU_TITLE = "Activate Warehouse Chest";
|
||||
|
||||
public static void open(
|
||||
Player player
|
||||
) {
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"CONVERT"
|
||||
),
|
||||
9,
|
||||
Component.text(
|
||||
MENU_TITLE
|
||||
).color(
|
||||
NamedTextColor.BLUE
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FILLER
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, filler);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CONVERT BUTTON
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.CRAFTING_TABLE,
|
||||
"§aConvert"
|
||||
)
|
||||
);
|
||||
|
||||
player.openInventory(menu);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package com.rsscripting.rswarehouse.conversion;
|
||||
|
||||
import com.rsscripting.rswarehouse.deposit.dao.ChestDAO;
|
||||
import com.rsscripting.rswarehouse.deposit.dao.WarehouseChestDAO;
|
||||
import com.rsscripting.rswarehouse.deposit.dao.VerifyIsChestDAO;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.main.MainMenu;
|
||||
import com.rsscripting.rswarehouse.constants.RSConstants;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class ConvertMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractBlock(
|
||||
PlayerInteractEvent event
|
||||
) {
|
||||
|
||||
Player player =
|
||||
event.getPlayer();
|
||||
|
||||
if (event.getHand() != EquipmentSlot.HAND) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block =
|
||||
event.getClickedBlock();
|
||||
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| REQUIRE SNEAKING
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (!player.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| VALIDATE TARGET ENTITY
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (block.getType() !=
|
||||
RSConstants.REQUIRED_TARGET_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| VALIDATE HELD ITEM
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ItemStack heldItem =
|
||||
player.getInventory()
|
||||
.getItemInMainHand();
|
||||
|
||||
if (heldItem.getType() !=
|
||||
RSConstants.REQUIRED_HELD_ITEM) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CANCEL VANILLA ACTION
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| STORE SELECTED ENTITY
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
Block warehouseBlock =
|
||||
WarehouseChestDAO.getWarehouseChest(
|
||||
block
|
||||
);
|
||||
|
||||
if (warehouseBlock != null) {
|
||||
|
||||
session.setSelectedBlock(
|
||||
warehouseBlock
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
session.setSelectedBlock(
|
||||
block
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ALREADY CONVERTED
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
boolean warehouseChest =
|
||||
VerifyIsChestDAO.isWarehouseChest(
|
||||
block
|
||||
);
|
||||
|
||||
if (!warehouseChest
|
||||
&& block.getState()
|
||||
instanceof Chest chest) {
|
||||
|
||||
InventoryHolder holder =
|
||||
chest.getInventory()
|
||||
.getHolder();
|
||||
|
||||
if (holder instanceof DoubleChest doubleChest) {
|
||||
|
||||
if (doubleChest.getLeftSide()
|
||||
instanceof Chest leftChest
|
||||
&& VerifyIsChestDAO.isWarehouseChest(
|
||||
leftChest.getBlock()
|
||||
)) {
|
||||
|
||||
warehouseChest = true;
|
||||
|
||||
}
|
||||
|
||||
if (doubleChest.getRightSide()
|
||||
instanceof Chest rightChest
|
||||
&& VerifyIsChestDAO.isWarehouseChest(
|
||||
rightChest.getBlock()
|
||||
)) {
|
||||
|
||||
warehouseChest = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (warehouseChest) {
|
||||
|
||||
Block selectedBlock =
|
||||
WarehouseChestDAO.getWarehouseChest(
|
||||
block
|
||||
);
|
||||
|
||||
if (selectedBlock == null) {
|
||||
|
||||
selectedBlock = block;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
player.isOp()
|
||||
|
||||
||
|
||||
|
||||
ChestDAO.isOwner(
|
||||
selectedBlock,
|
||||
player
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
NavigationManager.clear(player);
|
||||
|
||||
GuiSessionManager
|
||||
.getSession(player)
|
||||
.setSelectedBlock(selectedBlock);
|
||||
|
||||
NavigationManager.openMain(player);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
CategoryMenu.open(
|
||||
player
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| OPEN CONVERSION MENU
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ConvertMenu.open(player);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| GET SELECTED ENTITY
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public Block getSelectedBlock(
|
||||
Player player
|
||||
) {
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
return session.getSelectedBlock();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Convert Back
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void convertBack(
|
||||
Player player
|
||||
) {
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
Block block =
|
||||
session.getSelectedBlock();
|
||||
|
||||
if (block == null) {
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
WarehouseChestDAO.unregisterChest(
|
||||
block
|
||||
);
|
||||
|
||||
if (block.getState() instanceof Chest chest) {
|
||||
|
||||
chest.customName(
|
||||
null
|
||||
);
|
||||
|
||||
chest.update();
|
||||
|
||||
}
|
||||
|
||||
RSMessageUtils.success(
|
||||
player,
|
||||
"Warehouse Chest removed."
|
||||
);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.rsscripting.rswarehouse.database;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DatabaseManager {
|
||||
|
||||
private static JavaPlugin plugin;
|
||||
|
||||
private static String databaseUrl;
|
||||
|
||||
public static void initialize(
|
||||
JavaPlugin pluginInstance
|
||||
) {
|
||||
|
||||
plugin = pluginInstance;
|
||||
|
||||
createDatabase();
|
||||
|
||||
DatabaseTableCreator.createTables(
|
||||
plugin,
|
||||
databaseUrl
|
||||
);
|
||||
|
||||
DatabaseUpdater.updateDatabase(
|
||||
plugin,
|
||||
databaseUrl
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static void createDatabase() {
|
||||
|
||||
try {
|
||||
|
||||
File databaseFile =
|
||||
new File(
|
||||
plugin.getDataFolder(),
|
||||
"database.db"
|
||||
);
|
||||
|
||||
if (!plugin.getDataFolder().exists()) {
|
||||
|
||||
if (!plugin.getDataFolder().mkdirs()) {
|
||||
|
||||
plugin.getLogger().severe(
|
||||
"Failed to create plugin data folder."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
databaseUrl =
|
||||
"jdbc:sqlite:"
|
||||
+ databaseFile.getAbsolutePath();
|
||||
|
||||
Connection connection =
|
||||
DriverManager.getConnection(
|
||||
databaseUrl
|
||||
);
|
||||
|
||||
connection.close();
|
||||
|
||||
plugin.getLogger().info(
|
||||
"SQLite database initialized."
|
||||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
plugin.getLogger().log(
|
||||
Level.SEVERE,
|
||||
"Failed to initialize database.",
|
||||
e
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Connection getConnection()
|
||||
throws SQLException {
|
||||
|
||||
return DriverManager.getConnection(
|
||||
databaseUrl
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.rsscripting.rswarehouse.database;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DatabaseTableCreator {
|
||||
|
||||
public static void createTables(
|
||||
JavaPlugin plugin,
|
||||
String databaseUrl
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DriverManager.getConnection(
|
||||
databaseUrl
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS warehouse_chests (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
world TEXT NOT NULL,
|
||||
x INTEGER NOT NULL,
|
||||
y INTEGER NOT NULL,
|
||||
z INTEGER NOT NULL,
|
||||
owner_uuid TEXT NOT NULL,
|
||||
owner_name TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL
|
||||
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS warehouse_items (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
category_id INTEGER NOT NULL,
|
||||
serialized_item TEXT NOT NULL,
|
||||
default_lore TEXT,
|
||||
inventory_id INTEGER,
|
||||
subcategory_id INTEGER,
|
||||
page INTEGER,
|
||||
slot INTEGER,
|
||||
created_at TEXT NOT NULL
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS warehouse_categories (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
parent_category_id INTEGER,
|
||||
internal_name TEXT NOT NULL UNIQUE,
|
||||
display_name TEXT NOT NULL,
|
||||
material TEXT NOT NULL,
|
||||
lore TEXT,
|
||||
display_order INTEGER NOT NULL DEFAULT 0,
|
||||
page INTEGER NOT NULL DEFAULT 0,
|
||||
slot INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
INSERT OR IGNORE INTO warehouse_categories (
|
||||
internal_name,
|
||||
display_name,
|
||||
material,
|
||||
display_order,
|
||||
page,
|
||||
slot
|
||||
)
|
||||
VALUES (
|
||||
'uncategorized',
|
||||
'Uncategorized',
|
||||
'CHEST',
|
||||
0,
|
||||
0,
|
||||
4
|
||||
)
|
||||
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
|
||||
CREATE TABLE IF NOT EXISTS warehouse_inventory (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
serialized_item TEXT NOT NULL,
|
||||
quantity INTEGER NOT NULL,
|
||||
discoverer_uuid TEXT NULL,
|
||||
discoverer_name TEXT NULL,
|
||||
discovered_date TEXT NULL,
|
||||
lore TEXT
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
|
||||
CREATE TABLE IF NOT EXISTS partially_filled_variants (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
parent_inventory_id INTEGER NOT NULL,
|
||||
serialized_item TEXT NOT NULL,
|
||||
quantity INTEGER NOT NULL,
|
||||
lore TEXT,
|
||||
FOREIGN KEY(parent_inventory_id)
|
||||
REFERENCES warehouse_inventory(id)
|
||||
ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS damaged_variants (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
parent_inventory_id INTEGER NOT NULL,
|
||||
serialized_item TEXT NOT NULL,
|
||||
quantity INTEGER NOT NULL,
|
||||
lore TEXT
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS enchanted_variants (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
parent_inventory_id INTEGER NOT NULL,
|
||||
serialized_item TEXT NOT NULL,
|
||||
quantity INTEGER NOT NULL,
|
||||
lore TEXT
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS auto_deposit_settings (
|
||||
player_uuid TEXT PRIMARY KEY,
|
||||
enabled INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS auto_deposit_filters (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
player_uuid TEXT NOT NULL,
|
||||
serialized_item TEXT NOT NULL
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
connection.createStatement().execute(
|
||||
"""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS
|
||||
idx_auto_deposit_filter
|
||||
ON auto_deposit_filters (
|
||||
player_uuid,
|
||||
serialized_item
|
||||
)
|
||||
"""
|
||||
);
|
||||
|
||||
|
||||
plugin.getLogger().info(
|
||||
"Database tables initialized."
|
||||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
plugin.getLogger().log(
|
||||
Level.SEVERE,
|
||||
"Failed to create tables.",
|
||||
e
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.rsscripting.rswarehouse.database;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DatabaseUpdater {
|
||||
|
||||
public static void updateDatabase(
|
||||
JavaPlugin plugin,
|
||||
String databaseUrl
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DriverManager.getConnection(
|
||||
databaseUrl
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
ensureColumnExists(
|
||||
connection,
|
||||
"warehouse_items",
|
||||
"page",
|
||||
"INTEGER"
|
||||
);
|
||||
|
||||
ensureColumnExists(
|
||||
connection,
|
||||
"warehouse_items",
|
||||
"slot",
|
||||
"INTEGER"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
|
||||
plugin.getLogger().log(
|
||||
Level.SEVERE,
|
||||
"Failed updating database.",
|
||||
e
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void ensureColumnExists(
|
||||
Connection connection,
|
||||
String table,
|
||||
String column,
|
||||
String definition
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
var columns =
|
||||
connection
|
||||
.getMetaData()
|
||||
.getColumns(
|
||||
null,
|
||||
null,
|
||||
table,
|
||||
column
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
if (!columns.next()) {
|
||||
|
||||
connection.createStatement().execute(
|
||||
"ALTER TABLE "
|
||||
+ table
|
||||
+ " ADD COLUMN "
|
||||
+ column
|
||||
+ " "
|
||||
+ definition
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
JavaPlugin.getProvidingPlugin(
|
||||
DatabaseUpdater.class
|
||||
).getLogger().log(
|
||||
Level.SEVERE,
|
||||
"Failed updating column "
|
||||
+ column,
|
||||
e
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,70 @@
|
||||
package com.rsscripting.rswarehouse.discovery.discoverydao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class DiscoveryDAO {
|
||||
|
||||
public static void assignDiscovererIfNull(
|
||||
int inventoryId,
|
||||
String discovererUuid,
|
||||
String discovererName
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
UPDATE warehouse_inventory
|
||||
SET
|
||||
discoverer_uuid = ?,
|
||||
discoverer_name = ?,
|
||||
discovered_date = ?
|
||||
WHERE
|
||||
id = ?
|
||||
AND
|
||||
discoverer_uuid IS NULL
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
discovererUuid
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
2,
|
||||
discovererName
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
3,
|
||||
LocalDate.now().toString()
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
4,
|
||||
inventoryId
|
||||
);
|
||||
|
||||
int updated =
|
||||
statement.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.rsscripting.rswarehouse.inventory;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class InventoryQuantityDAO {
|
||||
|
||||
public static void deleteInventory(
|
||||
int inventoryId
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection();
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
DELETE
|
||||
FROM warehouse_inventory
|
||||
WHERE id = ?
|
||||
"""
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
statement.setInt(
|
||||
1,
|
||||
inventoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException exception) {
|
||||
|
||||
exception.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static long getInventoryQuantity(
|
||||
int inventoryId
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT quantity
|
||||
FROM warehouse_inventory
|
||||
WHERE id = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
1,
|
||||
inventoryId
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
return resultSet.getLong(
|
||||
"quantity"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
public static void updateInventoryQuantity(
|
||||
int inventoryId,
|
||||
long quantity
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
UPDATE warehouse_inventory
|
||||
SET quantity = quantity + ?
|
||||
WHERE id = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setLong(
|
||||
1,
|
||||
quantity
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
inventoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void removeInventoryQuantity(
|
||||
int inventoryId,
|
||||
long quantity
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
UPDATE warehouse_inventory
|
||||
SET quantity = quantity - ?
|
||||
WHERE id = ?
|
||||
"""
|
||||
);
|
||||
|
||||
statement.setLong(
|
||||
1,
|
||||
quantity
|
||||
);
|
||||
|
||||
statement.setInt(
|
||||
2,
|
||||
inventoryId
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package com.rsscripting.rswarehouse.inventory.inventorydao;
|
||||
|
||||
import com.rsscripting.rswarehouse.references.referencesdao.WarehouseReferenceDAO;
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class InventoryCreationDAO {
|
||||
|
||||
public static Integer createParentInventoryItem(
|
||||
ItemStack item,
|
||||
String discovererUuid,
|
||||
String discovererName
|
||||
) {
|
||||
|
||||
int inventoryId =
|
||||
createInventoryItem(
|
||||
item,
|
||||
0,
|
||||
discovererUuid,
|
||||
discovererName
|
||||
);
|
||||
|
||||
if (inventoryId == -1) {
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
WarehouseReferenceDAO.createWarehouseItemReference(
|
||||
item,
|
||||
inventoryId
|
||||
);
|
||||
|
||||
return inventoryId;
|
||||
|
||||
}
|
||||
|
||||
public static int createInventoryItem(
|
||||
ItemStack item,
|
||||
long quantity,
|
||||
String discovererUuid,
|
||||
String discovererName
|
||||
) {
|
||||
|
||||
String serializedItem =
|
||||
ItemStackUtils.serialize(
|
||||
item
|
||||
);
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
|
||||
INSERT INTO warehouse_inventory (
|
||||
serialized_item,
|
||||
quantity,
|
||||
discoverer_uuid,
|
||||
discoverer_name,
|
||||
discovered_date
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
""",
|
||||
Statement.RETURN_GENERATED_KEYS
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
1,
|
||||
serializedItem
|
||||
);
|
||||
|
||||
statement.setLong(
|
||||
2,
|
||||
quantity
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
3,
|
||||
discovererUuid
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
4,
|
||||
discovererName
|
||||
);
|
||||
|
||||
statement.setString(
|
||||
5,
|
||||
LocalDate.now().toString()
|
||||
);
|
||||
|
||||
statement.executeUpdate();
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.getGeneratedKeys();
|
||||
|
||||
if (resultSet.next()) {
|
||||
|
||||
return resultSet.getInt(
|
||||
1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.rsscripting.rswarehouse.inventory.inventorydao;
|
||||
|
||||
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class InventoryLookupDAO {
|
||||
|
||||
public static Integer findInventoryId(
|
||||
ItemStack item
|
||||
) {
|
||||
|
||||
try (
|
||||
|
||||
Connection connection =
|
||||
DatabaseManager.getConnection()
|
||||
|
||||
) {
|
||||
|
||||
PreparedStatement statement =
|
||||
connection.prepareStatement(
|
||||
"""
|
||||
SELECT id, serialized_item
|
||||
FROM warehouse_inventory
|
||||
"""
|
||||
);
|
||||
|
||||
ResultSet resultSet =
|
||||
statement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
ItemStack stored =
|
||||
ItemStackUtils.deserialize(
|
||||
resultSet.getString(
|
||||
"serialized_item"
|
||||
)
|
||||
);
|
||||
|
||||
if (stored == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
stored =
|
||||
ItemStackUtils.createBaseItem(
|
||||
stored
|
||||
);
|
||||
|
||||
stored =
|
||||
ItemStackUtils.createBaseItem(
|
||||
stored
|
||||
);
|
||||
|
||||
ItemStack compare =
|
||||
ItemStackUtils.createBaseItem(
|
||||
item.clone()
|
||||
);
|
||||
|
||||
if (stored.isSimilar(compare)) {
|
||||
|
||||
return resultSet.getInt(
|
||||
"id"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ItemsBuilder {
|
||||
|
||||
public static void applyDiscoveryLore(
|
||||
WarehouseItem warehouseItem,
|
||||
List<Component> lore
|
||||
){
|
||||
|
||||
lore.add(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
String discoveredDate = null;
|
||||
|
||||
if (warehouseItem.discoveredDate() != null) {
|
||||
|
||||
discoveredDate =
|
||||
LocalDate.parse(
|
||||
warehouseItem.discoveredDate()
|
||||
).format(
|
||||
DateTimeFormatter.ofPattern(
|
||||
"MM-dd-yyyy"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
String discovererName =
|
||||
warehouseItem.discovererName();
|
||||
|
||||
if (
|
||||
|
||||
discoveredDate == null
|
||||
&& discovererName == null
|
||||
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Currently Undiscovered"
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
else if (
|
||||
|
||||
discoveredDate != null
|
||||
&& discovererName != null
|
||||
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Discovered on "
|
||||
+ discoveredDate
|
||||
+ " by "
|
||||
+ discovererName
|
||||
).color(
|
||||
NamedTextColor.GRAY
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
else if (
|
||||
|
||||
discoveredDate != null
|
||||
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Discovered on "
|
||||
+ discoveredDate
|
||||
).color(
|
||||
NamedTextColor.GRAY
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Discovered by "
|
||||
+ discovererName
|
||||
).color(
|
||||
NamedTextColor.GRAY
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void applyStockLore(
|
||||
WarehouseItem warehouseItem,
|
||||
List<Component> lore
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"In Stock: "
|
||||
+ String.format(
|
||||
"%,d",
|
||||
warehouseItem.quantity()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void applySubCategoryLore(
|
||||
WarehouseItem warehouseItem,
|
||||
List<Component> lore
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Click to open subcategory"
|
||||
).color(
|
||||
NamedTextColor.GOLD
|
||||
)
|
||||
);
|
||||
|
||||
String displayLore = null;
|
||||
|
||||
if (
|
||||
warehouseItem.subcategoryId() != null
|
||||
) {
|
||||
|
||||
WarehouseCategory subCategory =
|
||||
CategoryDAO.getCategoryById(
|
||||
warehouseItem.subcategoryId()
|
||||
);
|
||||
|
||||
if (subCategory != null) {
|
||||
|
||||
displayLore =
|
||||
subCategory.lore();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
displayLore =
|
||||
warehouseItem.defaultLore();
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
displayLore != null
|
||||
&&
|
||||
!displayLore.isBlank()
|
||||
) {
|
||||
|
||||
lore.add(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
for (
|
||||
String line :
|
||||
displayLore.split(
|
||||
"\n",
|
||||
-1
|
||||
)
|
||||
) {
|
||||
|
||||
if (
|
||||
line.isBlank()
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
line
|
||||
).color(
|
||||
NamedTextColor.GRAY
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static List<Component> createLore(
|
||||
ItemMeta meta,
|
||||
boolean isSubCategory
|
||||
) {
|
||||
|
||||
List<Component> lore =
|
||||
new ArrayList<>();
|
||||
|
||||
if (!isSubCategory) {
|
||||
|
||||
List<Component> existingLore =
|
||||
meta.lore();
|
||||
|
||||
if (existingLore != null) {
|
||||
|
||||
lore.addAll(
|
||||
existingLore
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!lore.isEmpty()) {
|
||||
|
||||
lore.add(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return lore;
|
||||
|
||||
}
|
||||
|
||||
public static void applyDisplayName(
|
||||
WarehouseItem warehouseItem,
|
||||
ItemMeta meta
|
||||
){
|
||||
|
||||
boolean isSubCategory =
|
||||
warehouseItem.subcategoryId() != null;
|
||||
|
||||
if (isSubCategory) {
|
||||
|
||||
WarehouseCategory subCategory =
|
||||
CategoryDAO.getCategoryById(
|
||||
warehouseItem.subcategoryId()
|
||||
);
|
||||
|
||||
if (subCategory != null) {
|
||||
|
||||
meta.displayName(
|
||||
Component.text(
|
||||
subCategory.displayName()
|
||||
).color(
|
||||
NamedTextColor.WHITE
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ItemStack buildDisplayItem(
|
||||
WarehouseItem warehouseItem
|
||||
) {
|
||||
|
||||
ItemStack item =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
boolean isSubCategory =
|
||||
warehouseItem.subcategoryId() != null;
|
||||
|
||||
if (isSubCategory) {
|
||||
|
||||
item =
|
||||
ItemStackUtils.createNavigationItem(
|
||||
item
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
|
||||
Bukkit.getLogger().info(
|
||||
"Deserialize Failed"
|
||||
);
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
return item;
|
||||
|
||||
}
|
||||
|
||||
public static void applyOperatorLore(
|
||||
Player player,
|
||||
WarehouseItem warehouseItem,
|
||||
List<Component> lore
|
||||
) {
|
||||
|
||||
if (!player.isOp()) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
lore.add(
|
||||
Component.empty()
|
||||
);
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Item ID: "
|
||||
+ warehouseItem.id()
|
||||
).color(
|
||||
NamedTextColor.DARK_GRAY
|
||||
)
|
||||
);
|
||||
|
||||
lore.add(
|
||||
Component.text(
|
||||
"Shift + Right Click for Item Options"
|
||||
).color(
|
||||
NamedTextColor.GRAY
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static void applyPersistentData(
|
||||
ItemMeta meta,
|
||||
WarehouseItem warehouseItem
|
||||
) {
|
||||
|
||||
meta.getPersistentDataContainer().set(
|
||||
RSKeys.ITEM_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
warehouseItem.id()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.RSWarehouse;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemsMenu {
|
||||
|
||||
public static final String MENU_TITLE = "Items";
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int categoryId,
|
||||
String categoryName,
|
||||
int page
|
||||
){
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
session.setItemsCategoryId(
|
||||
categoryId
|
||||
);
|
||||
|
||||
session.setItemsCategoryName(
|
||||
categoryName
|
||||
);
|
||||
|
||||
session.setItemsPage(
|
||||
page
|
||||
);
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"ITEMS"
|
||||
),
|
||||
54,
|
||||
Component.text(
|
||||
categoryName
|
||||
+ " (Page "
|
||||
+ (page + 1)
|
||||
+ ")"
|
||||
).color(
|
||||
NamedTextColor.BLUE
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (int slot = 0; slot <= 8; slot++) {
|
||||
|
||||
menu.setItem(
|
||||
slot,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.OAK_DOOR,
|
||||
"§a Back"
|
||||
)
|
||||
);
|
||||
|
||||
List<WarehouseItem> items =
|
||||
ItemsPagination.getItemsForDisplay(
|
||||
categoryId,
|
||||
page
|
||||
);
|
||||
|
||||
int maxPage =
|
||||
ItemsPagination.getMaximumPage(
|
||||
categoryId
|
||||
);
|
||||
|
||||
page =
|
||||
Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
page,
|
||||
maxPage
|
||||
)
|
||||
);
|
||||
|
||||
session.setItemsPage(
|
||||
page
|
||||
);
|
||||
|
||||
boolean hasPrevious =
|
||||
page > 0;
|
||||
|
||||
boolean hasNext =
|
||||
page < maxPage;
|
||||
int slot = 9;
|
||||
|
||||
/*
|
||||
* Find the highest assigned slot on this page.
|
||||
* Automatic items begin immediately after it.
|
||||
*/
|
||||
for (WarehouseItem warehouseItem : items) {
|
||||
|
||||
if (
|
||||
warehouseItem.page() != null
|
||||
&&
|
||||
warehouseItem.slot() != null
|
||||
&&
|
||||
warehouseItem.page() == (page + 1)
|
||||
&&
|
||||
warehouseItem.slot() >= 9
|
||||
) {
|
||||
|
||||
slot = Math.max(
|
||||
slot,
|
||||
warehouseItem.slot() + 1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (WarehouseItem warehouseItem : items) {
|
||||
|
||||
ItemStack item =
|
||||
ItemsBuilder.buildDisplayItem(
|
||||
warehouseItem
|
||||
);
|
||||
|
||||
if (item == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
boolean isSubCategory =
|
||||
warehouseItem.subcategoryId() != null;
|
||||
|
||||
ItemMeta meta =
|
||||
item.getItemMeta();
|
||||
|
||||
|
||||
if (meta == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
ItemsBuilder.applyDisplayName(
|
||||
warehouseItem,
|
||||
meta
|
||||
);
|
||||
|
||||
List<Component> lore =
|
||||
ItemsBuilder.createLore(
|
||||
meta,
|
||||
isSubCategory
|
||||
);
|
||||
|
||||
if (isSubCategory) {
|
||||
|
||||
ItemsBuilder.applySubCategoryLore(
|
||||
warehouseItem,
|
||||
lore
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
ItemsBuilder.applyStockLore(
|
||||
warehouseItem,
|
||||
lore
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
!isSubCategory
|
||||
|
||||
&&
|
||||
|
||||
RSWarehouse.getInstance()
|
||||
.getConfig()
|
||||
.getBoolean(
|
||||
"display.show-discovery-information",
|
||||
true
|
||||
)
|
||||
|
||||
) {
|
||||
|
||||
ItemsBuilder.applyDiscoveryLore(
|
||||
warehouseItem,
|
||||
lore
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemsBuilder.applyOperatorLore(
|
||||
player,
|
||||
warehouseItem,
|
||||
lore
|
||||
);
|
||||
|
||||
lore.addAll(
|
||||
ItemStackUtils.getSpecialItemLore(item)
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
lore
|
||||
);
|
||||
|
||||
ItemsBuilder.applyPersistentData(
|
||||
meta,
|
||||
warehouseItem
|
||||
);
|
||||
|
||||
item.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
int displaySlot;
|
||||
|
||||
if (
|
||||
warehouseItem.page() != null
|
||||
&&
|
||||
warehouseItem.slot() != null
|
||||
&&
|
||||
warehouseItem.page() > 0
|
||||
&&
|
||||
warehouseItem.slot() > 0
|
||||
){
|
||||
|
||||
displaySlot =
|
||||
warehouseItem.slot();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
displaySlot =
|
||||
slot++;
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
displaySlot,
|
||||
item
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (hasPrevious) {
|
||||
|
||||
menu.setItem(
|
||||
0,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aPrevious Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (hasNext) {
|
||||
|
||||
menu.setItem(
|
||||
8,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.ARROW,
|
||||
"§aNext Page"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
for (WarehouseItem warehouseItem : items) {
|
||||
|
||||
ItemStack item =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (
|
||||
item == null
|
||||
||
|
||||
item.getType()
|
||||
!= Material.FILLED_MAP
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
!(item.getItemMeta()
|
||||
instanceof MapMeta mapMeta)
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
!mapMeta.hasMapView()
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
MapView mapView =
|
||||
mapMeta.getMapView();
|
||||
|
||||
if (
|
||||
mapView == null
|
||||
) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
player.sendMap(
|
||||
mapView
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryDAO;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.item.options.ItemOptionsMenu;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.navigation.NavigationManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.session.TransactionSession;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseCategory;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class ItemsMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
Player player =
|
||||
(Player) event.getWhoClicked();
|
||||
|
||||
if (
|
||||
event.getView()
|
||||
.getTopInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder
|
||||
&& holder.getMenuId().equals(
|
||||
"ITEMS"
|
||||
)
|
||||
) {
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
if (event.getSlot() == 0) {
|
||||
|
||||
if (session.getItemsPage() > 0) {
|
||||
|
||||
ItemsMenu.open(
|
||||
player,
|
||||
session.getItemsCategoryId(),
|
||||
session.getItemsCategoryName(),
|
||||
session.getItemsPage() - 1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getSlot() == 8) {
|
||||
|
||||
ItemsMenu.open(
|
||||
player,
|
||||
session.getItemsCategoryId(),
|
||||
session.getItemsCategoryName(),
|
||||
session.getItemsPage() + 1
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getSlot() == 4) {
|
||||
|
||||
NavigationManager.back(player);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ItemMeta meta =
|
||||
event.getCurrentItem()
|
||||
.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Integer itemId =
|
||||
meta.getPersistentDataContainer()
|
||||
.get(
|
||||
RSKeys.ITEM_ID,
|
||||
PersistentDataType.INTEGER
|
||||
);
|
||||
|
||||
if (itemId == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
WarehouseItem warehouseItem =
|
||||
ItemDAO.getItemById(
|
||||
itemId
|
||||
);
|
||||
|
||||
if (
|
||||
event.getClick() == ClickType.SHIFT_RIGHT
|
||||
&& player.isOp()
|
||||
) {
|
||||
|
||||
ItemOptionsMenu.open(
|
||||
player,
|
||||
itemId
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
warehouseItem.subcategoryId()
|
||||
!= null
|
||||
|
||||
) {
|
||||
|
||||
WarehouseCategory subCategory =
|
||||
CategoryDAO.getCategoryById(
|
||||
warehouseItem.subcategoryId()
|
||||
);
|
||||
|
||||
NavigationManager.openItems(
|
||||
player,
|
||||
subCategory.id(),
|
||||
subCategory.displayName(),
|
||||
0);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
session.setItemActionSession(
|
||||
new TransactionSession(
|
||||
itemId
|
||||
)
|
||||
);
|
||||
|
||||
TransactionAmountMenu.open(
|
||||
player,
|
||||
itemId,
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemsPagination {
|
||||
|
||||
public static int getMaximumPage(
|
||||
int categoryId
|
||||
) {
|
||||
|
||||
List<WarehouseItem> items =
|
||||
ItemDAO.getItemsForCategory(
|
||||
categoryId
|
||||
);
|
||||
|
||||
int highestAssignedPage = -1;
|
||||
int unassigned = 0;
|
||||
|
||||
for (WarehouseItem item : items) {
|
||||
|
||||
if (
|
||||
item.page() != null
|
||||
&&
|
||||
item.slot() != null
|
||||
&&
|
||||
item.page() > 0
|
||||
&&
|
||||
item.slot() > 0
|
||||
) {
|
||||
|
||||
highestAssignedPage =
|
||||
Math.max(
|
||||
highestAssignedPage,
|
||||
item.page() - 1
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
unassigned++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int consumed = 0;
|
||||
|
||||
for (int assignedPage = 0;
|
||||
assignedPage <= highestAssignedPage;
|
||||
assignedPage++) {
|
||||
|
||||
int highestSlot = 8;
|
||||
|
||||
for (WarehouseItem item : items) {
|
||||
|
||||
if (
|
||||
item.page() != null
|
||||
&&
|
||||
item.slot() != null
|
||||
&&
|
||||
item.page() == assignedPage + 1
|
||||
) {
|
||||
|
||||
highestSlot =
|
||||
Math.max(
|
||||
highestSlot,
|
||||
item.slot()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
consumed +=
|
||||
Math.max(
|
||||
0,
|
||||
53 - highestSlot
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
consumed =
|
||||
Math.min(
|
||||
consumed,
|
||||
unassigned
|
||||
);
|
||||
|
||||
unassigned -= consumed;
|
||||
|
||||
int overflowPages =
|
||||
(unassigned + 44) / 45;
|
||||
|
||||
return Math.max(
|
||||
0,
|
||||
highestAssignedPage + overflowPages
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static List<WarehouseItem> getItemsForDisplay(
|
||||
int categoryId,
|
||||
int page
|
||||
) {
|
||||
|
||||
List<WarehouseItem> allItems =
|
||||
ItemDAO.getItemsForCategory(
|
||||
categoryId
|
||||
);
|
||||
|
||||
List<WarehouseItem> assigned =
|
||||
new ArrayList<>();
|
||||
|
||||
List<WarehouseItem> unassigned =
|
||||
new ArrayList<>();
|
||||
|
||||
int highestAssignedPage = -1;
|
||||
|
||||
for (WarehouseItem item : allItems) {
|
||||
|
||||
if (
|
||||
item.page() != null
|
||||
&&
|
||||
item.slot() != null
|
||||
&&
|
||||
item.page() > 0
|
||||
&&
|
||||
item.slot() > 0
|
||||
) {
|
||||
|
||||
assigned.add(item);
|
||||
|
||||
highestAssignedPage =
|
||||
Math.max(
|
||||
highestAssignedPage,
|
||||
item.page() - 1
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
unassigned.add(item);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Assigned pages
|
||||
*/
|
||||
if (page <= highestAssignedPage) {
|
||||
|
||||
List<WarehouseItem> results =
|
||||
new ArrayList<>();
|
||||
|
||||
int highestSlot = 8;
|
||||
|
||||
for (WarehouseItem item : assigned) {
|
||||
|
||||
if (item.page() == (page + 1)) {
|
||||
|
||||
results.add(item);
|
||||
|
||||
highestSlot =
|
||||
Math.max(
|
||||
highestSlot,
|
||||
item.slot()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Figure out how many unassigned items have
|
||||
* already been consumed by previous assigned pages.
|
||||
*/
|
||||
int consumed = 0;
|
||||
|
||||
for (int previousPage = 0;
|
||||
previousPage < page;
|
||||
previousPage++) {
|
||||
|
||||
int previousHighestSlot = 8;
|
||||
|
||||
for (WarehouseItem item : assigned) {
|
||||
|
||||
if (item.page() == (previousPage + 1)) {
|
||||
|
||||
previousHighestSlot =
|
||||
Math.max(
|
||||
previousHighestSlot,
|
||||
item.slot()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
consumed +=
|
||||
Math.max(
|
||||
0,
|
||||
53 - previousHighestSlot
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
int remainingSlots =
|
||||
Math.max(
|
||||
0,
|
||||
53 - highestSlot
|
||||
);
|
||||
|
||||
while (
|
||||
remainingSlots > 0
|
||||
&&
|
||||
consumed < unassigned.size()
|
||||
) {
|
||||
|
||||
results.add(
|
||||
unassigned.get(
|
||||
consumed
|
||||
)
|
||||
);
|
||||
|
||||
consumed++;
|
||||
remainingSlots--;
|
||||
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
int consumed = 0;
|
||||
|
||||
for (int assignedPage = 0;
|
||||
assignedPage <= highestAssignedPage;
|
||||
assignedPage++) {
|
||||
|
||||
int highestSlot = 8;
|
||||
|
||||
for (WarehouseItem item : assigned) {
|
||||
|
||||
if (item.page() == assignedPage + 1) {
|
||||
|
||||
highestSlot =
|
||||
Math.max(
|
||||
highestSlot,
|
||||
item.slot()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
consumed +=
|
||||
Math.max(
|
||||
0,
|
||||
53 - highestSlot
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
consumed =
|
||||
Math.min(
|
||||
consumed,
|
||||
unassigned.size()
|
||||
);
|
||||
|
||||
/*
|
||||
* Overflow pages
|
||||
*/
|
||||
|
||||
int overflowPage =
|
||||
page
|
||||
- highestAssignedPage
|
||||
- 1;
|
||||
|
||||
int start =
|
||||
consumed
|
||||
+ (overflowPage * 45);
|
||||
|
||||
if (start >= unassigned.size()) {
|
||||
|
||||
return new ArrayList<>();
|
||||
|
||||
}
|
||||
|
||||
int end =
|
||||
Math.min(
|
||||
start + 45,
|
||||
unassigned.size()
|
||||
);
|
||||
|
||||
return new ArrayList<>(
|
||||
unassigned.subList(
|
||||
start,
|
||||
end
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
public class TransactionAmountButtonHandler {
|
||||
|
||||
public static Integer handle(
|
||||
int slot,
|
||||
int amount,
|
||||
long playerHas,
|
||||
long maxWithdraw
|
||||
) {
|
||||
|
||||
switch (slot) {
|
||||
|
||||
case 9 ->
|
||||
amount -= 64;
|
||||
|
||||
case 10 ->
|
||||
amount -= 16;
|
||||
|
||||
case 11 ->
|
||||
amount -= 1;
|
||||
|
||||
case 15 ->
|
||||
amount += 1;
|
||||
|
||||
case 16 ->
|
||||
amount += 16;
|
||||
|
||||
case 17 ->
|
||||
amount += 64;
|
||||
|
||||
default -> {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (amount > playerHas) {
|
||||
|
||||
amount =
|
||||
(int) playerHas;
|
||||
|
||||
}
|
||||
|
||||
if (amount < -maxWithdraw) {
|
||||
|
||||
amount =
|
||||
(int) -maxWithdraw;
|
||||
|
||||
}
|
||||
|
||||
return amount;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TransactionAmountMenu {
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int itemId,
|
||||
int amount
|
||||
) {
|
||||
|
||||
String title;
|
||||
|
||||
if (amount > 0) {
|
||||
|
||||
title =
|
||||
"Deposit: "
|
||||
+ String.format(
|
||||
"%,d",
|
||||
amount
|
||||
);
|
||||
|
||||
} else if (amount < 0) {
|
||||
|
||||
title =
|
||||
"Withdraw: "
|
||||
+ String.format(
|
||||
"%,d",
|
||||
Math.abs(
|
||||
amount
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
title =
|
||||
"Amount: 0";
|
||||
|
||||
}
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new RSMenuHolder(
|
||||
"ITEM_ACTION"
|
||||
),
|
||||
27,
|
||||
Component.text(
|
||||
title
|
||||
).color(
|
||||
NamedTextColor.BLUE
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FILLER
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(
|
||||
i,
|
||||
RSMenuUtils.createFillerPane()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CENTER ITEM
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
WarehouseItem warehouseItem =
|
||||
ItemDAO.getItemById(
|
||||
itemId
|
||||
);
|
||||
|
||||
TransactionCenterItemBuilder.addCenterItem(
|
||||
menu,
|
||||
player,
|
||||
warehouseItem
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| WITHDRAW
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ItemStack subtract64 =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.RED_WOOL,
|
||||
"§cSubtract 64"
|
||||
);
|
||||
|
||||
subtract64.setAmount(
|
||||
64
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
9,
|
||||
subtract64
|
||||
);
|
||||
|
||||
ItemStack subtract16 =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.RED_WOOL,
|
||||
"§cSubtract 16"
|
||||
);
|
||||
|
||||
subtract16.setAmount(
|
||||
16
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
10,
|
||||
subtract16
|
||||
);
|
||||
|
||||
|
||||
ItemStack subtract1 =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.RED_WOOL,
|
||||
"§cSubtract 1"
|
||||
);
|
||||
|
||||
subtract1.setAmount(
|
||||
1
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
11,
|
||||
subtract1
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DEPOSIT
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
ItemStack add1 =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.GREEN_WOOL,
|
||||
"§cAdd 1"
|
||||
);
|
||||
|
||||
add1.setAmount(
|
||||
1
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
15,
|
||||
add1
|
||||
);
|
||||
|
||||
ItemStack add16 =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.GREEN_WOOL,
|
||||
"§cAdd 16"
|
||||
);
|
||||
|
||||
add16.setAmount(
|
||||
16
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
16,
|
||||
add16
|
||||
);
|
||||
|
||||
ItemStack add64 =
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.GREEN_WOOL,
|
||||
"§cAdd 64"
|
||||
);
|
||||
|
||||
add64.setAmount(
|
||||
64
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
17,
|
||||
add64
|
||||
);
|
||||
|
||||
TransactionVariantBuilder.addVariantButtons(
|
||||
menu,
|
||||
warehouseItem
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| BACK
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
menu.setItem(
|
||||
4,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.OAK_DOOR,
|
||||
"§eBack"
|
||||
)
|
||||
);
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu;
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
import com.rsscripting.rswarehouse.session.GuiSession;
|
||||
import com.rsscripting.rswarehouse.session.GuiSessionManager;
|
||||
import com.rsscripting.rswarehouse.session.TransactionSession;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TransactionAmountMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (
|
||||
!(event.getWhoClicked()
|
||||
instanceof Player player)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
!(event.getInventory()
|
||||
.getHolder()
|
||||
instanceof RSMenuHolder holder)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
!holder.getMenuId()
|
||||
.equals(
|
||||
"ITEM_ACTION"
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
|
||||
GuiSession session =
|
||||
GuiSessionManager.getSession(
|
||||
player
|
||||
);
|
||||
|
||||
TransactionSession itemSession =
|
||||
session.getItemActionSession();
|
||||
|
||||
if (itemSession == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int amount =
|
||||
itemSession.getAmount();
|
||||
|
||||
int itemId =
|
||||
itemSession.getWarehouseItemId();
|
||||
|
||||
WarehouseItem warehouseItem =
|
||||
ItemDAO.getItemById(
|
||||
itemId
|
||||
);
|
||||
|
||||
if (warehouseItem == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
TransactionVariantHandler.handle(
|
||||
player,
|
||||
event.getSlot(),
|
||||
event.getCurrentItem(),
|
||||
warehouseItem
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (event.getSlot() == 4) {
|
||||
|
||||
ItemsMenu.open(
|
||||
player,
|
||||
session.getItemsCategoryId(),
|
||||
session.getItemsCategoryName(),
|
||||
session.getItemsPage());
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (item == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
long playerHas =
|
||||
TransactionUtils.getPlayerItemCount(
|
||||
player,
|
||||
item
|
||||
);
|
||||
|
||||
if (event.getSlot() == 13) {
|
||||
|
||||
if (
|
||||
TransactionConfirmHandler.handle(
|
||||
player,
|
||||
itemSession,
|
||||
item,
|
||||
amount
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (amount == 0) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
TransactionWithdrawHandler.handle(
|
||||
player,
|
||||
itemSession,
|
||||
item,
|
||||
amount
|
||||
)
|
||||
) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
long warehouseStock =
|
||||
warehouseItem.quantity();
|
||||
|
||||
int inventoryCapacity =
|
||||
TransactionUtils.getAvailableCapacity(
|
||||
player,
|
||||
item
|
||||
);
|
||||
|
||||
long maxWithdraw =
|
||||
Math.min(
|
||||
warehouseStock,
|
||||
inventoryCapacity
|
||||
);
|
||||
|
||||
Integer newAmount =
|
||||
TransactionAmountButtonHandler.handle(
|
||||
event.getSlot(),
|
||||
amount,
|
||||
playerHas,
|
||||
maxWithdraw
|
||||
);
|
||||
|
||||
if (newAmount == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
amount =
|
||||
newAmount;
|
||||
|
||||
itemSession.setAmount(
|
||||
amount
|
||||
);
|
||||
|
||||
TransactionAmountMenu.open(
|
||||
player,
|
||||
itemSession.getWarehouseItemId(),
|
||||
amount
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TransactionCenterItemBuilder {
|
||||
|
||||
public static void addCenterItem(
|
||||
Inventory menu,
|
||||
Player player,
|
||||
WarehouseItem warehouseItem
|
||||
){
|
||||
|
||||
if (warehouseItem != null) {
|
||||
|
||||
ItemStack item =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (item != null) {
|
||||
|
||||
ItemMeta meta =
|
||||
item.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
long playerHas =
|
||||
TransactionUtils.getPlayerItemCount(
|
||||
player,
|
||||
item
|
||||
);
|
||||
|
||||
meta.lore(
|
||||
List.of(
|
||||
Component.text(
|
||||
"In Stock: "
|
||||
+ String.format(
|
||||
"%,d",
|
||||
warehouseItem.quantity()
|
||||
)
|
||||
).color(
|
||||
NamedTextColor.LIGHT_PURPLE
|
||||
),
|
||||
|
||||
Component.text(
|
||||
"Player Has: "
|
||||
+ String.format(
|
||||
"%,d",
|
||||
playerHas
|
||||
)
|
||||
).color(
|
||||
NamedTextColor.GREEN
|
||||
),
|
||||
|
||||
Component.text(
|
||||
" "
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
),
|
||||
|
||||
Component.text(
|
||||
"Click to complete transaction."
|
||||
).color(
|
||||
NamedTextColor.YELLOW
|
||||
)
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
item.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
13,
|
||||
item
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.session.TransactionSession;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
|
||||
public class TransactionConfirmHandler {
|
||||
|
||||
public static boolean handle(
|
||||
Player player,
|
||||
TransactionSession itemSession,
|
||||
ItemStack item,
|
||||
int amount
|
||||
) {
|
||||
|
||||
if (amount == 0) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (amount > 0) {
|
||||
|
||||
ItemStack depositItem =
|
||||
item.clone();
|
||||
|
||||
depositItem.setAmount(
|
||||
1
|
||||
);
|
||||
|
||||
if (
|
||||
TransactionUtils.removeItems(
|
||||
player,
|
||||
depositItem,
|
||||
amount
|
||||
)
|
||||
) {
|
||||
|
||||
ItemDAO.addItem(
|
||||
player.getUniqueId()
|
||||
.toString(),
|
||||
player.getName(),
|
||||
depositItem,
|
||||
amount
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
"§aYou have deposited "
|
||||
+ amount
|
||||
+ " items."
|
||||
);
|
||||
|
||||
itemSession.setAmount(
|
||||
0
|
||||
);
|
||||
|
||||
TransactionAmountMenu.open(
|
||||
player,
|
||||
itemSession.getWarehouseItemId(),
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TransactionUtils {
|
||||
|
||||
public static long getPlayerItemCount(
|
||||
Player player,
|
||||
ItemStack target
|
||||
) {
|
||||
|
||||
long count = 0;
|
||||
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
item.isSimilar(
|
||||
target
|
||||
)
|
||||
) {
|
||||
|
||||
count += item.getAmount();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
public static int getAvailableCapacity(
|
||||
Player player,
|
||||
ItemStack target
|
||||
) {
|
||||
|
||||
int capacity = 0;
|
||||
|
||||
int maxStack =
|
||||
target.getMaxStackSize();
|
||||
|
||||
for (
|
||||
ItemStack item :
|
||||
player.getInventory()
|
||||
.getStorageContents()
|
||||
) {
|
||||
|
||||
if (item == null) {
|
||||
|
||||
capacity += maxStack;
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
item.isSimilar(
|
||||
target
|
||||
)
|
||||
) {
|
||||
|
||||
capacity +=
|
||||
maxStack
|
||||
- item.getAmount();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return capacity;
|
||||
|
||||
}
|
||||
|
||||
public static boolean removeItems(
|
||||
Player player,
|
||||
ItemStack target,
|
||||
int amount
|
||||
){
|
||||
|
||||
int remaining =
|
||||
amount;
|
||||
|
||||
ItemStack[] contents =
|
||||
player.getInventory()
|
||||
.getContents();
|
||||
|
||||
for (int slot = 0;
|
||||
slot < contents.length;
|
||||
slot++) {
|
||||
|
||||
ItemStack item =
|
||||
contents[slot];
|
||||
|
||||
if (item == null) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (!item.isSimilar(target)) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
item.getAmount()
|
||||
<= remaining
|
||||
) {
|
||||
|
||||
remaining -=
|
||||
item.getAmount();
|
||||
|
||||
player.getInventory()
|
||||
.setItem(
|
||||
slot,
|
||||
null
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
item.setAmount(
|
||||
item.getAmount()
|
||||
- remaining
|
||||
);
|
||||
|
||||
remaining =
|
||||
0;
|
||||
|
||||
}
|
||||
|
||||
if (remaining <= 0) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
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.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class TransactionVariantBuilder {
|
||||
|
||||
public static void addVariantButtons(
|
||||
Inventory menu,
|
||||
WarehouseItem warehouseItem
|
||||
) {
|
||||
|
||||
/*
|
||||
| Enchanted Variants Button
|
||||
*/
|
||||
|
||||
if (
|
||||
warehouseItem != null
|
||||
&& warehouseItem.inventoryId() != null
|
||||
) {
|
||||
|
||||
if (
|
||||
EnchantedVariantsDAO.hasEnchantedVariants(
|
||||
warehouseItem.inventoryId()
|
||||
)
|
||||
) {
|
||||
|
||||
ItemStack enchantedIcon =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (enchantedIcon != null) {
|
||||
|
||||
ItemMeta meta =
|
||||
enchantedIcon.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
|
||||
meta.addEnchant(
|
||||
Enchantment.UNBREAKING,
|
||||
1,
|
||||
true
|
||||
);
|
||||
|
||||
meta.addItemFlags(
|
||||
ItemFlag.HIDE_ENCHANTS
|
||||
);
|
||||
|
||||
enchantedIcon.setItemMeta(
|
||||
meta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ItemStack menuIcon =
|
||||
RSMenuUtils.createMenuItem(
|
||||
enchantedIcon,
|
||||
"§eView Enchanted Variants"
|
||||
);
|
||||
|
||||
ItemMeta menuMeta =
|
||||
menuIcon.getItemMeta();
|
||||
|
||||
menuMeta.getPersistentDataContainer().set(
|
||||
RSKeys.ENCHANTED_VARIANT_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
if (menuMeta != null) {
|
||||
|
||||
menuMeta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES
|
||||
);
|
||||
|
||||
menuIcon.setItemMeta(
|
||||
menuMeta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
1,
|
||||
menuIcon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (
|
||||
PartiallyFilledVariantsDAO.hasPartiallyFilledVariants(
|
||||
warehouseItem.inventoryId()
|
||||
)
|
||||
) {
|
||||
|
||||
ItemStack partiallyFilledIcon =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (partiallyFilledIcon != null) {
|
||||
|
||||
ItemStack menuIcon =
|
||||
RSMenuUtils.createMenuItem(
|
||||
partiallyFilledIcon,
|
||||
"§eView Partially Filled Variants"
|
||||
);
|
||||
|
||||
ItemMeta menuMeta =
|
||||
menuIcon.getItemMeta();
|
||||
|
||||
menuMeta.getPersistentDataContainer().set(
|
||||
RSKeys.PARTIALLY_FILLED_VARIANT_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
if (menuMeta != null) {
|
||||
|
||||
menuMeta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
|
||||
menuIcon.setItemMeta(
|
||||
menuMeta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
2,
|
||||
menuIcon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| VARIANTS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (
|
||||
warehouseItem != null
|
||||
&& warehouseItem.inventoryId() != null
|
||||
&& DamagedVariantsDAO.hasDamagedVariants(
|
||||
warehouseItem.inventoryId()
|
||||
)
|
||||
) {
|
||||
|
||||
ItemStack damagedIcon =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (damagedIcon == null) {
|
||||
|
||||
damagedIcon = new ItemStack(Material.ANVIL);
|
||||
|
||||
}
|
||||
|
||||
if (damagedIcon.getItemMeta() instanceof Damageable damageable) {
|
||||
|
||||
int maxDurability = damagedIcon.getType().getMaxDurability();
|
||||
|
||||
damageable.setDamage(maxDurability / 2);
|
||||
|
||||
damagedIcon.setItemMeta(damageable);
|
||||
|
||||
} else {
|
||||
|
||||
damagedIcon = new ItemStack(Material.ANVIL);
|
||||
|
||||
}
|
||||
|
||||
ItemStack menuIcon =
|
||||
RSMenuUtils.createMenuItem(
|
||||
damagedIcon,
|
||||
"§eView Damaged Variants"
|
||||
);
|
||||
|
||||
ItemMeta menuMeta =
|
||||
menuIcon.getItemMeta();
|
||||
|
||||
if (menuMeta != null) {
|
||||
|
||||
menuMeta.addItemFlags(
|
||||
ItemFlag.HIDE_ATTRIBUTES
|
||||
);
|
||||
|
||||
menuMeta.getPersistentDataContainer().set(
|
||||
RSKeys.DAMAGED_VARIANT_ID,
|
||||
PersistentDataType.INTEGER,
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
menuIcon.setItemMeta(
|
||||
menuMeta
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
0,
|
||||
menuIcon
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.constants.RSKeys;
|
||||
import com.rsscripting.rswarehouse.variantsdamaged.DamagedVariantsMenu;
|
||||
import com.rsscripting.rswarehouse.variantsenchanted.EnchantedVariantsMenu;
|
||||
import com.rsscripting.rswarehouse.variantspartiallyfilled.PartiallyFilledVariantsMenu;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class TransactionVariantHandler {
|
||||
|
||||
public static boolean handle(
|
||||
Player player,
|
||||
int slot,
|
||||
ItemStack clicked,
|
||||
WarehouseItem warehouseItem
|
||||
) {
|
||||
|
||||
if (
|
||||
clicked == null
|
||||
|| !clicked.hasItemMeta()
|
||||
) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
PersistentDataContainer pdc =
|
||||
clicked.getItemMeta()
|
||||
.getPersistentDataContainer();
|
||||
|
||||
if (slot == 0) {
|
||||
|
||||
if (
|
||||
!pdc.has(
|
||||
RSKeys.DAMAGED_VARIANT_ID,
|
||||
PersistentDataType.INTEGER
|
||||
)
|
||||
) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
DamagedVariantsMenu.open(
|
||||
player,
|
||||
warehouseItem.id(),
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (slot == 1) {
|
||||
|
||||
if (
|
||||
!pdc.has(
|
||||
RSKeys.ENCHANTED_VARIANT_ID,
|
||||
PersistentDataType.INTEGER
|
||||
)
|
||||
) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
EnchantedVariantsMenu.open(
|
||||
player,
|
||||
warehouseItem.id(),
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (slot == 2) {
|
||||
|
||||
if (
|
||||
!pdc.has(
|
||||
RSKeys.PARTIALLY_FILLED_VARIANT_ID,
|
||||
PersistentDataType.INTEGER
|
||||
)
|
||||
) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
PartiallyFilledVariantsMenu.open(
|
||||
player,
|
||||
warehouseItem.id(),
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.rsscripting.rswarehouse.item;
|
||||
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.utils.RSMessageUtils;
|
||||
import com.rsscripting.rswarehouse.autodeposit.autodepositdao.AutoDepositDAO;
|
||||
import com.rsscripting.rswarehouse.session.TransactionSession;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TransactionWithdrawHandler {
|
||||
|
||||
public static boolean handle(
|
||||
Player player,
|
||||
TransactionSession itemSession,
|
||||
ItemStack item,
|
||||
int amount
|
||||
) {
|
||||
|
||||
if (amount >= 0) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
int withdrawAmount =
|
||||
Math.abs(
|
||||
amount
|
||||
);
|
||||
|
||||
ItemStack withdrawItem =
|
||||
item.clone();
|
||||
|
||||
withdrawItem.setAmount(
|
||||
withdrawAmount
|
||||
);
|
||||
|
||||
if (
|
||||
AutoDepositDAO.shouldBlockWithdrawal(
|
||||
player.getUniqueId(),
|
||||
withdrawItem
|
||||
)
|
||||
) {
|
||||
|
||||
RSMessageUtils.error(
|
||||
player,
|
||||
"Disable Auto Deposit or remove this item from your filter before withdrawing it."
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
player.getInventory()
|
||||
.addItem(
|
||||
withdrawItem
|
||||
);
|
||||
|
||||
ItemDAO.removeItem(
|
||||
withdrawItem,
|
||||
withdrawAmount
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
"§aYou have withdrawn "
|
||||
+ withdrawAmount
|
||||
+ " items."
|
||||
);
|
||||
|
||||
itemSession.setAmount(
|
||||
0
|
||||
);
|
||||
|
||||
TransactionAmountMenu.open(
|
||||
player,
|
||||
itemSession.getWarehouseItemId(),
|
||||
0
|
||||
);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.rsscripting.rswarehouse.item.deleteitem;
|
||||
|
||||
import com.rsscripting.rswarehouse.item.itemdao.ItemDAO;
|
||||
import com.rsscripting.rswarehouse.model.WarehouseItem;
|
||||
import com.rsscripting.rswarehouse.utils.ItemStackUtils;
|
||||
import com.rsscripting.rswarehouse.utils.RSMenuUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DeleteConfirmationMenu {
|
||||
|
||||
public static void open(
|
||||
Player player,
|
||||
int itemId
|
||||
) {
|
||||
|
||||
WarehouseItem warehouseItem =
|
||||
ItemDAO.getItemById(
|
||||
itemId
|
||||
);
|
||||
|
||||
if (warehouseItem == null) {
|
||||
|
||||
player.sendMessage(
|
||||
"§cUnable to locate warehouse item."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Inventory menu =
|
||||
Bukkit.createInventory(
|
||||
new DeleteConfirmationMenuHolder(
|
||||
itemId
|
||||
),
|
||||
27,
|
||||
Component.text(
|
||||
"Delete Item?"
|
||||
).color(
|
||||
NamedTextColor.RED
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack filler =
|
||||
RSMenuUtils.createFillerPane();
|
||||
|
||||
for (int i = 0; i < 27; i++) {
|
||||
|
||||
menu.setItem(
|
||||
i,
|
||||
filler
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(
|
||||
11,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.RED_WOOL,
|
||||
"§cCancel"
|
||||
)
|
||||
);
|
||||
|
||||
menu.setItem(
|
||||
15,
|
||||
RSMenuUtils.createMenuItem(
|
||||
Material.LIME_WOOL,
|
||||
"§aDelete"
|
||||
)
|
||||
);
|
||||
|
||||
ItemStack displayItem =
|
||||
ItemStackUtils.deserialize(
|
||||
warehouseItem.serializedItem()
|
||||
);
|
||||
|
||||
if (displayItem != null) {
|
||||
|
||||
menu.setItem(
|
||||
13,
|
||||
displayItem
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
player.openInventory(
|
||||
menu
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.rsscripting.rswarehouse.item.deleteitem;
|
||||
|
||||
import com.rsscripting.rswarehouse.menuholder.RSMenuHolder;
|
||||
|
||||
public class DeleteConfirmationMenuHolder
|
||||
extends RSMenuHolder {
|
||||
|
||||
private final int itemId;
|
||||
|
||||
public DeleteConfirmationMenuHolder(
|
||||
int itemId
|
||||
) {
|
||||
|
||||
super(
|
||||
"DELETE_CONFIRMATION"
|
||||
);
|
||||
|
||||
this.itemId =
|
||||
itemId;
|
||||
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
|
||||
return itemId;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
package com.rsscripting.rswarehouse.item.deleteitem;
|
||||
|
||||
import com.rsscripting.rswarehouse.item.options.ItemOptionsMenu;
|
||||
import com.rsscripting.rswarehouse.inventory.InventoryQuantityDAO;
|
||||
import com.rsscripting.rswarehouse.references.referencesdao.WarehouseReferenceDAO;
|
||||
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.model.WarehouseItem;
|
||||
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;
|
||||
|
||||
public class DeleteConfirmationMenuListener
|
||||
implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(
|
||||
InventoryClickEvent event
|
||||
) {
|
||||
|
||||
if (!(event.getWhoClicked()
|
||||
instanceof Player player)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!(event.getInventory().getHolder()
|
||||
instanceof DeleteConfirmationMenuHolder holder)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!holder.getMenuId().equals(
|
||||
"DELETE_CONFIRMATION"
|
||||
)) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
event.setCancelled(
|
||||
true
|
||||
);
|
||||
|
||||
if (event.getCurrentItem() == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Material material =
|
||||
event.getCurrentItem().getType();
|
||||
|
||||
if (material == Material.RED_WOOL) {
|
||||
|
||||
ItemOptionsMenu.open(
|
||||
player,
|
||||
holder.getItemId()
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (material == Material.LIME_WOOL) {
|
||||
|
||||
WarehouseItem warehouseItem =
|
||||
ItemDAO.getItemById(
|
||||
holder.getItemId()
|
||||
);
|
||||
|
||||
if (warehouseItem == null) {
|
||||
|
||||
player.sendMessage(
|
||||
"§cUnable to locate warehouse item."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (warehouseItem.inventoryId() == null) {
|
||||
|
||||
player.sendMessage(
|
||||
"§cCannot delete subcategories yet."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int references =
|
||||
WarehouseReferenceDAO.countInventoryReferences(
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
if (references > 1) {
|
||||
|
||||
WarehouseReferenceDAO.deleteItemReference(
|
||||
warehouseItem.id()
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
"§aItem reference deleted."
|
||||
);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (DamagedVariantsDAO.hasDamagedVariants(
|
||||
warehouseItem.inventoryId()
|
||||
)) {
|
||||
|
||||
player.sendMessage(
|
||||
"§cCannot delete. Inventory contains damaged variants."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (EnchantedVariantsDAO.hasEnchantedVariants(
|
||||
warehouseItem.inventoryId()
|
||||
)) {
|
||||
|
||||
player.sendMessage(
|
||||
"§cCannot delete. Inventory contains enchanted variants."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (PartiallyFilledVariantsDAO.hasPartiallyFilledVariants(
|
||||
warehouseItem.inventoryId()
|
||||
)) {
|
||||
|
||||
player.sendMessage(
|
||||
"§cCannot delete. Inventory contains partially filled variants."
|
||||
);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
WarehouseReferenceDAO.deleteItemReference(
|
||||
warehouseItem.id()
|
||||
);
|
||||
|
||||
InventoryQuantityDAO.deleteInventory(
|
||||
warehouseItem.inventoryId()
|
||||
);
|
||||
|
||||
player.sendMessage(
|
||||
"§aItem deleted."
|
||||
);
|
||||
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loaded 100 of 314 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user