diff --git a/docs/01) Getting Started/A) Installation And Setup.md b/docs/01) Getting Started/A) Installation And Setup.md index 621842d..6a062e7 100644 --- a/docs/01) Getting Started/A) Installation And Setup.md +++ b/docs/01) Getting Started/A) Installation And Setup.md @@ -55,10 +55,20 @@ Your plugins folder should now contain: ``` plugins/ └── RS-Warehouse/ + └── db-files-templates + ├── empty_database.db + └── populated_database.db ├── config.yml └── database.db + + ``` -📷 Screenshot +``` +NOTE: +RS-Warehouse comes with 2 additional database files. +1) empty_database.md = A totally empty database file. No categories, no items. + the only items contained in this databse are the Uncategorized, Server + Rules, Server Commands, and Auto-Deposit categories -![Plugins Folder](../images/PluginFolderFiles.png) \ No newline at end of file +``` diff --git a/docs/images/PluginFolderFiles.png b/docs/images/PluginFolderFiles.png deleted file mode 100644 index a727919..0000000 Binary files a/docs/images/PluginFolderFiles.png and /dev/null differ diff --git a/pom.xml b/pom.xml index 44659be..11a67eb 100644 --- a/pom.xml +++ b/pom.xml @@ -19,22 +19,65 @@ + + src/main/resources + true - database.db + + + database.db + + + + db-files-templates/*.db + + + + + src/main/resources + false - database.db + + + database.db + + + + + + + + + + src/main/resources/db-files-templates + + + + db-files-templates + + + false + + + + + *.db + + + + diff --git a/src/main/java/com/rsscripting/rswarehouse/category/categorymenu/CategoryMenu.java b/src/main/java/com/rsscripting/rswarehouse/category/categorymenu/CategoryMenu.java index 557e0a3..89c5142 100644 --- a/src/main/java/com/rsscripting/rswarehouse/category/categorymenu/CategoryMenu.java +++ b/src/main/java/com/rsscripting/rswarehouse/category/categorymenu/CategoryMenu.java @@ -2,6 +2,7 @@ package com.rsscripting.rswarehouse.category.categorymenu; import com.rsscripting.rswarehouse.dao.CategoryDAO; import com.rsscripting.rswarehouse.config.ConfigManager; +import com.rsscripting.rswarehouse.dao.ItemDAO; import com.rsscripting.rswarehouse.menuholder.RSMenuHolder; import com.rsscripting.rswarehouse.model.WarehouseCategory; import com.rsscripting.rswarehouse.constants.RSKeys; @@ -404,7 +405,15 @@ public class CategoryMenu { } - if (uncategorized != null) { + if ( + uncategorized != null + && ( + ConfigManager.isAlwaysShowUncategorized() + || ItemDAO.categoryHasItems( + uncategorized.id() + ) + ) + ) { ItemStack icon = RSMenuUtils.createMenuItem( diff --git a/src/main/java/com/rsscripting/rswarehouse/config/ConfigManager.java b/src/main/java/com/rsscripting/rswarehouse/config/ConfigManager.java index 4b15abf..9286461 100644 --- a/src/main/java/com/rsscripting/rswarehouse/config/ConfigManager.java +++ b/src/main/java/com/rsscripting/rswarehouse/config/ConfigManager.java @@ -3,6 +3,12 @@ package com.rsscripting.rswarehouse.config; import com.rsscripting.rswarehouse.RSWarehouse; import org.bukkit.configuration.file.FileConfiguration; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.logging.Level; +import java.io.InputStream; + public class ConfigManager { private static FileConfiguration config; @@ -22,6 +28,10 @@ public class ConfigManager { RSWarehouse.getInstance() .getConfig(); + setupDefaultDatabase(); + + setupDatabaseTemplates(); + } /* @@ -53,19 +63,6 @@ public class ConfigManager { } - /* - | Uncateforized enabled - */ - - public boolean isUncategorizedEnabled() { - - return config.getBoolean( - "allow-uncategorized-item-creation", - true - ); - - } - /* |-------------------------------------------------------------------------- | Server Commands Enabled @@ -90,4 +87,127 @@ public class ConfigManager { } + /* +|-------------------------------------------------------------------------- +| UnCategorized Enabled +|-------------------------------------------------------------------------- +*/ + + public static boolean isAlwaysShowUncategorized() { + + return config.getBoolean( + "always-show-uncategorized", + false + ); + + } + + private static void setupDatabaseTemplates() { + + RSWarehouse plugin = + RSWarehouse.getInstance(); + + File templatesFolder = + new File( + plugin.getDataFolder(), + "db-files-templates" + ); + + if (!templatesFolder.exists()) { + + templatesFolder.mkdirs(); + + } + + File emptyDatabase = + new File( + templatesFolder, + "empty_database.db" + ); + + if (!emptyDatabase.exists()) { + + plugin.saveResource( + "db-files-templates/empty_database.db", + false + ); + + } + + File populatedDatabase = + new File( + templatesFolder, + "populated_database.db" + ); + + if (!populatedDatabase.exists()) { + + plugin.saveResource( + "db-files-templates/populated_database.db", + false + ); + + } + + } + + private static void setupDefaultDatabase() { + + RSWarehouse plugin = + RSWarehouse.getInstance(); + + File databaseFile = + new File( + plugin.getDataFolder(), + "database.db" + ); + + if (databaseFile.exists()) { + + return; + + } + + if (!plugin.getDataFolder().exists()) { + + plugin.getDataFolder().mkdirs(); + + } + + try ( + InputStream input = + plugin.getResource( + "db-files-templates/populated_database.db" + ) + ) { + + if (input == null) { + + plugin.getLogger().severe( + "Could not find populated_database.db in plugin resources." + ); + + return; + + } + + Files.copy( + input, + databaseFile.toPath() + ); + + } + + catch (IOException exception) { + + plugin.getLogger().log( + Level.SEVERE, + "Failed to create default database.", + exception + ); + + } + + } + } \ No newline at end of file diff --git a/src/main/java/com/rsscripting/rswarehouse/item/ItemsMenuListener.java b/src/main/java/com/rsscripting/rswarehouse/item/ItemsMenuListener.java index 246f3d7..223f28f 100644 --- a/src/main/java/com/rsscripting/rswarehouse/item/ItemsMenuListener.java +++ b/src/main/java/com/rsscripting/rswarehouse/item/ItemsMenuListener.java @@ -1,5 +1,7 @@ package com.rsscripting.rswarehouse.item; +import com.rsscripting.rswarehouse.adminmenu.AdminMenu; +import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu; import com.rsscripting.rswarehouse.dao.CategoryDAO; import com.rsscripting.rswarehouse.dao.ItemDAO; import com.rsscripting.rswarehouse.item.options.ItemOptionsMenu; @@ -81,7 +83,37 @@ public class ItemsMenuListener if (event.getSlot() == 4) { - NavigationManager.back(player); + if ( + session.getItemsCategoryId() == 1000 + || session.getItemsCategoryId() == 1001 + ) { + + if (session.isRulesAndCommandsReturnToAdmin()) { + + session.setRulesAndCommandsReturnToAdmin( + false + ); + + AdminMenu.open( + player + ); + + } else { + + CategoryMenu.open( + player, + 0 + ); + + } + + return; + + } + + NavigationManager.back( + player + ); return; diff --git a/src/main/java/com/rsscripting/rswarehouse/item/deleteitem/DeleteConfirmationMenuListener.java b/src/main/java/com/rsscripting/rswarehouse/item/deleteitem/DeleteConfirmationMenuListener.java index 5ab65a1..aa8296e 100644 --- a/src/main/java/com/rsscripting/rswarehouse/item/deleteitem/DeleteConfirmationMenuListener.java +++ b/src/main/java/com/rsscripting/rswarehouse/item/deleteitem/DeleteConfirmationMenuListener.java @@ -1,5 +1,6 @@ package com.rsscripting.rswarehouse.item.deleteitem; +import com.rsscripting.rswarehouse.category.categorymenu.CategoryMenu; import com.rsscripting.rswarehouse.item.options.ItemOptionsMenu; import com.rsscripting.rswarehouse.dao.InventoryQuantityDAO; import com.rsscripting.rswarehouse.dao.WarehouseReferenceDAO; @@ -100,6 +101,12 @@ public class DeleteConfirmationMenuListener warehouseItem.inventoryId() ); + /* + * More than one reference means another item also + * points to this inventory row. + * + * Delete this reference only. + */ if (references > 1) { WarehouseReferenceDAO.deleteItemReference( @@ -110,12 +117,40 @@ public class DeleteConfirmationMenuListener "§aItem reference deleted." ); - player.closeInventory(); + CategoryMenu.open( + player, + 1 + ); return; } + /* + * This is the only reference. + * + * Check whether inventory still contains items. + */ + long quantity = + InventoryQuantityDAO.getInventoryQuantity( + warehouseItem.inventoryId() + ); + + if (quantity > 0) { + + player.sendMessage( + "§cCannot delete this item because it still has " + + quantity + + " item(s) in the warehouse." + ); + + return; + + } + + /* + * Do not delete if variants still exist. + */ if (DamagedVariantsDAO.hasDamagedVariants( warehouseItem.inventoryId() )) { @@ -152,6 +187,13 @@ public class DeleteConfirmationMenuListener } + /* + * Only reference remaining. + * Quantity is zero. + * No variants exist. + * + * Safe to delete both. + */ WarehouseReferenceDAO.deleteItemReference( warehouseItem.id() ); @@ -164,7 +206,12 @@ public class DeleteConfirmationMenuListener "§aItem deleted." ); - player.closeInventory(); + CategoryMenu.open( + player, + 1 + ); + + return; } diff --git a/src/main/java/com/rsscripting/rswarehouse/servercommands/ServerCommandMaterialPickerMenuListener.java b/src/main/java/com/rsscripting/rswarehouse/servercommands/ServerCommandMaterialPickerMenuListener.java index 5af9764..6b29b2c 100644 --- a/src/main/java/com/rsscripting/rswarehouse/servercommands/ServerCommandMaterialPickerMenuListener.java +++ b/src/main/java/com/rsscripting/rswarehouse/servercommands/ServerCommandMaterialPickerMenuListener.java @@ -5,6 +5,8 @@ import com.rsscripting.rswarehouse.item.ItemsMenu; import com.rsscripting.rswarehouse.menuholder.RSMenuHolder; import com.rsscripting.rswarehouse.session.admin.ServerCommandCreationSession; import com.rsscripting.rswarehouse.session.admin.ServerCommandCreationSessionManager; +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; @@ -120,6 +122,15 @@ public class ServerCommandMaterialPickerMenuListener "§aServer Command created successfully." ); + GuiSession guiSession = + GuiSessionManager.getSession( + player + ); + + guiSession.setRulesAndCommandsReturnToAdmin( + true + ); + ItemsMenu.open( player, 1001, diff --git a/src/main/java/com/rsscripting/rswarehouse/serverrule/ServerRuleMaterialPickerMenuListener.java b/src/main/java/com/rsscripting/rswarehouse/serverrule/ServerRuleMaterialPickerMenuListener.java index c9be506..73a3437 100644 --- a/src/main/java/com/rsscripting/rswarehouse/serverrule/ServerRuleMaterialPickerMenuListener.java +++ b/src/main/java/com/rsscripting/rswarehouse/serverrule/ServerRuleMaterialPickerMenuListener.java @@ -3,6 +3,8 @@ package com.rsscripting.rswarehouse.serverrule; import com.rsscripting.rswarehouse.dao.admin.CreateServerRuleDAO; import com.rsscripting.rswarehouse.item.ItemsMenu; import com.rsscripting.rswarehouse.menuholder.RSMenuHolder; +import com.rsscripting.rswarehouse.session.GuiSession; +import com.rsscripting.rswarehouse.session.GuiSessionManager; import com.rsscripting.rswarehouse.session.admin.ServerRuleCreationSession; import com.rsscripting.rswarehouse.session.admin.ServerRuleCreationSessionManager; import org.bukkit.entity.Player; @@ -69,10 +71,6 @@ public class ServerRuleMaterialPickerMenuListener } - /* - * Previous page - */ - /* * Current material picker page. */ @@ -157,6 +155,14 @@ public class ServerRuleMaterialPickerMenuListener "§aServer Rule created successfully." ); + GuiSession guiSession = + GuiSessionManager.getSession( + player + ); + + guiSession.setRulesAndCommandsReturnToAdmin( + true + ); ItemsMenu.open( player, diff --git a/src/main/java/com/rsscripting/rswarehouse/session/GuiSession.java b/src/main/java/com/rsscripting/rswarehouse/session/GuiSession.java index 00e59a2..3480dd4 100644 --- a/src/main/java/com/rsscripting/rswarehouse/session/GuiSession.java +++ b/src/main/java/com/rsscripting/rswarehouse/session/GuiSession.java @@ -6,6 +6,8 @@ import java.util.UUID; public class GuiSession { + private boolean rulesAndCommandsReturnToAdmin; + /* |-------------------------------------------------------------------------- | Player Session @@ -500,5 +502,20 @@ public class GuiSession { } + public boolean isRulesAndCommandsReturnToAdmin() { + + return rulesAndCommandsReturnToAdmin; + + } + + public void setRulesAndCommandsReturnToAdmin( + boolean rulesAndCommandsReturnToAdmin + ) { + + this.rulesAndCommandsReturnToAdmin = + rulesAndCommandsReturnToAdmin; + + } + } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 242b1d0..67e9939 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -36,6 +36,11 @@ chest-auto-processing: # if item is not currently in warehouse. allow-uncategorized-item-creation: true + # Whether or not to always show the Uncategorized category. + # True = Uncategorized will always show. + # False = Uncategorized will only show if it has items inside. +always-show-uncategorized: false + # Allow damaged items to be added to # damaged variant menu of base items. allow-damaged-item-creation: true diff --git a/src/main/resources/database.db b/src/main/resources/database.db index 22d5158..074f89f 100644 Binary files a/src/main/resources/database.db and b/src/main/resources/database.db differ diff --git a/src/main/resources/db-files-templates/empty_database.db b/src/main/resources/db-files-templates/empty_database.db new file mode 100644 index 0000000..1853e49 Binary files /dev/null and b/src/main/resources/db-files-templates/empty_database.db differ diff --git a/src/main/resources/db-files-templates/populated_database.db b/src/main/resources/db-files-templates/populated_database.db new file mode 100644 index 0000000..074f89f Binary files /dev/null and b/src/main/resources/db-files-templates/populated_database.db differ