├── .gitattributes ├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── bug-report.yaml │ └── config.yml ├── .gitignore ├── API ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── bgsoftware │ └── wildchests │ └── api │ ├── WildChests.java │ ├── WildChestsAPI.java │ ├── events │ └── SellChestTaskEvent.java │ ├── handlers │ ├── ChestsManager.java │ └── ProvidersManager.java │ ├── hooks │ ├── BankProvider.java │ ├── PricesProvider.java │ └── StackerProvider.java │ ├── key │ └── Key.java │ └── objects │ ├── ChestType.java │ ├── DepositMethod.java │ ├── chests │ ├── Chest.java │ ├── LinkedChest.java │ ├── RegularChest.java │ └── StorageChest.java │ └── data │ ├── ChestData.java │ └── InventoryData.java ├── Hooks ├── ChestShop │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ └── ChestShopHook.java ├── CoreProtect │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ └── CoreProtectHook.java ├── Folia │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── scheduler │ │ └── FoliaSchedulerImplementation.java ├── RoseStacker │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ └── StackerProvider_RoseStacker.java ├── SuperiorSkyblock │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ ├── BankProvider_SuperiorSkyblock.java │ │ └── SuperiorSkyblockHook.java ├── TransportPipes │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ └── TransportPipesHook.java ├── Vault │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ └── BankProvider_Vault.java ├── WildStacker │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── hooks │ │ └── StackerProvider_WildStacker.java └── build.gradle ├── LICENSE ├── NMS ├── build.gradle ├── v1_12_R1 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_12_R1 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventory.java │ │ ├── TileEntityWildChest.java │ │ ├── WildContainerChest.java │ │ ├── WildContainerHopper.java │ │ ├── WildContainerItemImpl.java │ │ └── WildInventory.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_16_R3 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_16_R3 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventory.java │ │ ├── TileEntityWildChest.java │ │ ├── WildContainerChest.java │ │ ├── WildContainerHopper.java │ │ ├── WildContainerItemImpl.java │ │ └── WildInventory.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_17 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_17 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_18 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_18 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_19 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_19 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_20_3 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_20_3 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_20_4 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_20_4 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_21 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_21 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_21_3 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_21_3 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_21_4 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_21_4 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java ├── v1_21_5 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── bgsoftware │ │ └── wildchests │ │ └── nms │ │ └── v1_21_5 │ │ ├── NMSAdapterImpl.java │ │ ├── NMSInventoryImpl.java │ │ ├── inventory │ │ ├── BaseNMSMenu.java │ │ ├── CraftWildInventoryImpl.java │ │ ├── WildChestBlockEntity.java │ │ ├── WildChestMenu.java │ │ ├── WildContainer.java │ │ ├── WildContainerItemImpl.java │ │ └── WildHopperMenu.java │ │ └── utils │ │ ├── NbtUtils.java │ │ └── TransformingNonNullList.java └── v1_8_R3 │ ├── build.gradle │ └── src │ └── main │ └── java │ └── com │ └── bgsoftware │ └── wildchests │ └── nms │ └── v1_8_R3 │ ├── NMSAdapterImpl.java │ ├── NMSInventoryImpl.java │ ├── inventory │ ├── BaseNMSMenu.java │ ├── CraftWildInventory.java │ ├── TileEntityWildChest.java │ ├── WildContainerChest.java │ ├── WildContainerHopper.java │ ├── WildContainerItemImpl.java │ └── WildInventory.java │ └── utils │ └── NbtUtils.java ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── com │ └── bgsoftware │ └── wildchests │ ├── Locale.java │ ├── WildChestsPlugin.java │ ├── command │ ├── CommandsHandler.java │ ├── ICommand.java │ └── commands │ │ ├── CommandGive.java │ │ ├── CommandInfo.java │ │ ├── CommandLink.java │ │ ├── CommandReload.java │ │ ├── CommandSave.java │ │ └── CommandSettings.java │ ├── database │ ├── DatabaseObject.java │ ├── Query.java │ ├── SQLHelper.java │ └── StatementHolder.java │ ├── handlers │ ├── ChestsHandler.java │ ├── DataHandler.java │ ├── ProvidersHandler.java │ └── SettingsHandler.java │ ├── hooks │ ├── PricesProvider_Default.java │ ├── PricesProvider_ShopsBridgeWrapper.java │ ├── StackerProviderType.java │ ├── StackerProvider_Default.java │ └── listener │ │ ├── IChestBreakListener.java │ │ └── IChestPlaceListener.java │ ├── key │ └── KeySet.java │ ├── listeners │ ├── BlockListener.java │ ├── ChunksListener.java │ ├── InventoryListener.java │ └── PlayerListener.java │ ├── nms │ ├── NMSAdapter.java │ └── NMSInventory.java │ ├── objects │ ├── Materials.java │ ├── chests │ │ ├── WChest.java │ │ ├── WLinkedChest.java │ │ ├── WRegularChest.java │ │ └── WStorageChest.java │ ├── containers │ │ └── TileEntityContainer.java │ ├── data │ │ ├── WChestData.java │ │ └── WInventoryData.java │ └── inventory │ │ ├── CraftWildInventory.java │ │ ├── InventoryHolder.java │ │ └── WildContainerItem.java │ ├── scheduler │ ├── BukkitSchedulerImplementation.java │ ├── ISchedulerImplementation.java │ ├── ScheduledTask.java │ └── Scheduler.java │ ├── task │ ├── CraftingDetails.java │ ├── NotifierTask.java │ └── TransactionDetails.java │ └── utils │ ├── BlockPosition.java │ ├── ChestUtils.java │ ├── ChunkPosition.java │ ├── Counter.java │ ├── DatabaseThread.java │ ├── ItemStackMap.java │ ├── ItemUtils.java │ ├── LinkedChestInteractEvent.java │ ├── LocationUtils.java │ ├── Pair.java │ ├── RecipeUtils.java │ ├── ServerVersion.java │ ├── StringUtils.java │ └── SyncedArray.java └── resources ├── config.yml ├── lang.yml └── plugin.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: Ome_R 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Feature Requests 4 | url: https://github.com/OmerBenGera/WildChests/discussions 5 | about: Create feature requests, any posted in issue tracker will be removed. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | gradle.properties 4 | 5 | # Ignore Gradle build output directory 6 | build 7 | 8 | # Ignore intellij files 9 | .idea 10 | *.iml 11 | 12 | # Ignore output generated files 13 | target 14 | out -------------------------------------------------------------------------------- /API/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'maven-publish' 3 | } 4 | 5 | java { 6 | withSourcesJar() 7 | } 8 | 9 | group 'API' 10 | 11 | dependencies { 12 | compileOnly "org.spigotmc:v1_8_R1:latest" 13 | } 14 | 15 | publishing { 16 | publications { 17 | maven(MavenPublication) { 18 | groupId = 'com.bgsoftware' 19 | artifactId = 'WildChestsAPI' 20 | version = parent.version 21 | 22 | from components.java 23 | } 24 | } 25 | 26 | repositories { 27 | String mavenUsername = System.getenv('mavenUsername'); 28 | String mavenPassword = System.getenv('mavenPassword'); 29 | 30 | if (mavenUsername != null && mavenPassword != null) { 31 | maven { 32 | url 'https://repo.bg-software.com/repository/api/' 33 | credentials { 34 | username mavenUsername 35 | password mavenPassword 36 | } 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/WildChests.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api; 2 | 3 | import com.bgsoftware.wildchests.api.handlers.ChestsManager; 4 | import com.bgsoftware.wildchests.api.handlers.ProvidersManager; 5 | 6 | public interface WildChests { 7 | 8 | /** 9 | * Get the chests manager instance. 10 | */ 11 | ChestsManager getChestsManager(); 12 | 13 | /** 14 | * Get the providers manager instance. 15 | */ 16 | ProvidersManager getProviders(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/events/SellChestTaskEvent.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.events; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import org.bukkit.event.Cancellable; 5 | import org.bukkit.event.Event; 6 | import org.bukkit.event.HandlerList; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | /** 10 | * This event is fired when a chest attempts to sell an item. 11 | */ 12 | public final class SellChestTaskEvent extends Event implements Cancellable { 13 | 14 | private static final HandlerList handlers = new HandlerList(); 15 | 16 | private final Chest chest; 17 | private final ItemStack item; 18 | private boolean cancelled = false; 19 | private double multiplier; 20 | 21 | /** 22 | * The constructor of the event. 23 | * @param chest The chest that sells the item. 24 | * @param item The item to be sold. 25 | * @param multiplier The applied price multiplier. 26 | */ 27 | public SellChestTaskEvent(Chest chest, ItemStack item, double multiplier){ 28 | this.chest = chest; 29 | this.item = item; 30 | this.multiplier = multiplier; 31 | } 32 | 33 | /** 34 | * Get the chest that sells the item. 35 | */ 36 | public Chest getChest() { 37 | return chest; 38 | } 39 | 40 | /** 41 | * Get the item that is sold. 42 | */ 43 | public ItemStack getItem() { 44 | return item; 45 | } 46 | 47 | /** 48 | * Get the applied price multiplier. 49 | */ 50 | public double getMultiplier() { 51 | return multiplier; 52 | } 53 | 54 | /** 55 | * Set a price multiplier. 56 | * @param multiplier The new price multiplier. 57 | */ 58 | public void setMultiplier(double multiplier) { 59 | this.multiplier = multiplier; 60 | } 61 | 62 | @Override 63 | public boolean isCancelled() { 64 | return cancelled; 65 | } 66 | 67 | @Override 68 | public void setCancelled(boolean cancelled) { 69 | this.cancelled = cancelled; 70 | } 71 | 72 | @Override 73 | public HandlerList getHandlers() { 74 | return handlers; 75 | } 76 | 77 | public static HandlerList getHandlerList() { 78 | return handlers; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/handlers/ProvidersManager.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.handlers; 2 | 3 | import com.bgsoftware.wildchests.api.hooks.BankProvider; 4 | import com.bgsoftware.wildchests.api.hooks.PricesProvider; 5 | import com.bgsoftware.wildchests.api.hooks.StackerProvider; 6 | 7 | public interface ProvidersManager { 8 | 9 | /** 10 | * Set the prices provider for the core. 11 | * @param pricesProvider The provider to set. 12 | */ 13 | void setPricesProvider(PricesProvider pricesProvider); 14 | 15 | /** 16 | * Set the stacker provider for the core. 17 | * @param stackerProvider The provider to set. 18 | */ 19 | void setStackerProvider(StackerProvider stackerProvider); 20 | 21 | /** 22 | * Register custom banks provider for the core. 23 | * @param banksProvider The provider to set. 24 | */ 25 | void setBanksProvider(BankProvider banksProvider); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/hooks/BankProvider.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.hooks; 2 | 3 | import org.bukkit.OfflinePlayer; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public interface BankProvider { 8 | 9 | /** 10 | * Deposit money to a player. 11 | * @param offlinePlayer The player to deposit money to. 12 | * @param money The amount of money to deposit. 13 | * @return Whether the transaction was successful or not. 14 | */ 15 | boolean depositMoney(OfflinePlayer offlinePlayer, BigDecimal money); 16 | 17 | /** 18 | * Withdraw money from a player. 19 | * @param offlinePlayer The player to withdraw money from. 20 | * @param money The amount of money to withdraw. 21 | * @return Whether the transaction was successful or not. 22 | */ 23 | boolean withdrawPlayer(OfflinePlayer offlinePlayer, double money); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/hooks/PricesProvider.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.hooks; 2 | 3 | import org.bukkit.OfflinePlayer; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | import java.util.concurrent.CompletableFuture; 8 | 9 | public interface PricesProvider { 10 | 11 | double getPrice(OfflinePlayer offlinePlayer, ItemStack itemStack); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/hooks/StackerProvider.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.hooks; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.entity.Item; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | public interface StackerProvider { 8 | 9 | /** 10 | * Get the amount of a dropped item. 11 | * @param item The item to check. 12 | */ 13 | int getItemAmount(Item item); 14 | 15 | /** 16 | * Set the amount of a dropped item. 17 | * @param item The item to change the amount to. 18 | * @param amount The amount to set. 19 | */ 20 | void setItemAmount(Item item, int amount); 21 | 22 | /** 23 | * Drop an item on ground. 24 | * @param location The location to drop the item at. 25 | * @param itemStack The item to drop. 26 | * @param amount The amount to drop of this item. 27 | * @return True if the item was dropped, otherwise false. 28 | */ 29 | default boolean dropItem(Location location, ItemStack itemStack, int amount){ 30 | return false; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/key/Key.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.key; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.inventory.ItemStack; 5 | 6 | /** 7 | * Class to convert item-stacks into a comparable object. 8 | * This doesn't support ItemMeta, used for detection of blacklists & whitelists. 9 | */ 10 | public final class Key { 11 | 12 | private final String key; 13 | 14 | private Key(String key){ 15 | this.key = key; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return key; 21 | } 22 | 23 | public static Key of(ItemStack itemStack){ 24 | return of(itemStack.getType(), itemStack.getDurability()); 25 | } 26 | 27 | public static Key of(Material material, short data){ 28 | return of(material + ":" + data); 29 | } 30 | 31 | public static Key of(String key){ 32 | return new Key(key); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/objects/ChestType.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.objects; 2 | 3 | public enum ChestType { 4 | 5 | LINKED_CHEST, 6 | CHEST, 7 | STORAGE_UNIT 8 | 9 | } 10 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/objects/DepositMethod.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.objects; 2 | 3 | public enum DepositMethod { 4 | 5 | VAULT, 6 | SUPERIORSKYBLOCK2, 7 | CUSTOM 8 | 9 | } 10 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/objects/chests/LinkedChest.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.objects.chests; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * LinkedChests are regular chests that can be linked into other linked chests. 7 | * It means that all of their stats and contents will be synced with their linked chests. 8 | */ 9 | public interface LinkedChest extends RegularChest, Chest{ 10 | 11 | /** 12 | * Link this chest into another chest. 13 | * 14 | * If the target link is not linked to any chests, 15 | * this chest will be the source chest, and the other chests will link into this chest. 16 | * Otherwise, this chest will be linked into the source chest of the target chest. 17 | * 18 | * @param linkedChest The target chest. 19 | * If null, you'll unlink this chest with all the linked chests. 20 | */ 21 | void linkIntoChest(LinkedChest linkedChest); 22 | 23 | /** 24 | * Get the source chest of this chest. 25 | */ 26 | LinkedChest getLinkedChest(); 27 | 28 | /** 29 | * Checks if this chest is linked into another chest, and it's not the source chest. 30 | */ 31 | boolean isLinkedIntoChest(); 32 | 33 | /** 34 | * Get all the linked chests of the source chest of this chest, excluding the source chest. 35 | */ 36 | List getAllLinkedChests(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/objects/chests/RegularChest.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.objects.chests; 2 | 3 | /** 4 | * RegularChests are non-storage chests. They can have multiple pages, have their items being sold, crafted, etc. 5 | */ 6 | public interface RegularChest extends Chest{ 7 | } 8 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/objects/chests/StorageChest.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.objects.chests; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | import java.math.BigInteger; 6 | 7 | 8 | /** 9 | * StorageChests (Storage-Units) are chests that can hold only one item, but with unlimited amount of it. 10 | */ 11 | public interface StorageChest extends RegularChest, Chest { 12 | 13 | /** 14 | * Get the stored item of this chest. 15 | * If the chest is empty, AIR item will be returned. 16 | */ 17 | ItemStack getItemStack(); 18 | 19 | /** 20 | * Change the item that is stored in this chest. 21 | * @param itemStack The new item to store. 22 | */ 23 | void setItemStack(ItemStack itemStack); 24 | 25 | /** 26 | * Get the amount of the stored item. 27 | */ 28 | BigInteger getAmount(); 29 | 30 | /** 31 | * Get the amount of the stored item. 32 | * @deprecated Use getAmount() 33 | */ 34 | @Deprecated 35 | BigInteger getExactAmount(); 36 | 37 | /** 38 | * Set the amount of the stored item. 39 | * @param amount The new amount of the item. 40 | */ 41 | void setAmount(BigInteger amount); 42 | 43 | /** 44 | * Set the amount of the stored item. 45 | * @param amount The new amount of the item. 46 | * @deprecated Use setAmount(BigInteger amount) 47 | */ 48 | @Deprecated 49 | void setAmount(int amount); 50 | 51 | /** 52 | * Get the maximum amount that can be stored. 53 | * If there's no limit, -1 will be returned. 54 | */ 55 | BigInteger getMaxAmount(); 56 | 57 | /** 58 | * Set the maximum amount of the item that can be stored. 59 | * @param maxAmount The maximum amount 60 | */ 61 | void setMaxAmount(BigInteger maxAmount); 62 | 63 | /** 64 | * Update the inventory for all the viewers. 65 | * Used when the title is changed so it will be updated to all the viewers. 66 | */ 67 | void update(); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /API/src/main/java/com/bgsoftware/wildchests/api/objects/data/InventoryData.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.api.objects.data; 2 | 3 | /** 4 | * InventoryData is used to save data about a page. 5 | */ 6 | public interface InventoryData { 7 | 8 | /** 9 | * Get the title of the page. 10 | */ 11 | String getTitle(); 12 | 13 | /** 14 | * Get the price of the page (unlock price). 15 | */ 16 | double getPrice(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Hooks/ChestShop/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:ChestShop' 2 | 3 | dependencies { 4 | compileOnly "com.acrobot:ChestShop:3.11" 5 | compileOnly "org.spigotmc:v1_16_R3:latest" 6 | compileOnly project(":API") 7 | compileOnly rootProject 8 | } 9 | 10 | if (project.hasProperty('hook.compile_chestshop') && 11 | !Boolean.valueOf(project.findProperty("hook.compile_chestshop").toString())) { 12 | project.tasks.all { task -> task.enabled = false } 13 | } -------------------------------------------------------------------------------- /Hooks/ChestShop/src/main/java/com/bgsoftware/wildchests/hooks/ChestShopHook.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.Acrobot.ChestShop.Events.PreShopCreationEvent; 4 | import com.bgsoftware.wildchests.WildChestsPlugin; 5 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.Location; 8 | import org.bukkit.block.Block; 9 | import org.bukkit.block.data.BlockData; 10 | import org.bukkit.block.data.type.Sign; 11 | import org.bukkit.block.data.type.WallSign; 12 | import org.bukkit.event.EventHandler; 13 | import org.bukkit.event.EventPriority; 14 | import org.bukkit.event.Listener; 15 | 16 | public final class ChestShopHook { 17 | 18 | public static void register(WildChestsPlugin plugin) { 19 | Bukkit.getPluginManager().registerEvents(new Listener() { 20 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) 21 | public void onChestShopCreate(PreShopCreationEvent e) { 22 | try { 23 | BlockData blockData = e.getSign().getBlockData(); 24 | if (blockData instanceof WallSign || blockData instanceof Sign) { 25 | for (Location location : getPotentialChests(e.getSign().getBlock())) { 26 | Chest chest = plugin.getChestsManager().getChest(location); 27 | if (chest != null) { 28 | e.setCancelled(true); 29 | e.setSignLines(new String[]{"", "", "", ""}); 30 | break; 31 | } 32 | } 33 | } 34 | } catch (Exception ex) { 35 | ex.printStackTrace(); 36 | } 37 | } 38 | }, plugin); 39 | } 40 | 41 | private static Location[] getPotentialChests(Block block) { 42 | return new Location[]{ 43 | block.getLocation().add(1, 0, 0), 44 | block.getLocation().add(0, 1, 0), 45 | block.getLocation().add(0, 0, 1), 46 | block.getLocation().add(-1, 0, 0), 47 | block.getLocation().add(0, -1, 0), 48 | block.getLocation().add(0, 0, -1) 49 | }; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Hooks/CoreProtect/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:CoreProtect' 2 | 3 | dependencies { 4 | compileOnly 'net.coreprotect:CoreProtect:19.0' 5 | compileOnly "org.spigotmc:v1_16_R3:latest" 6 | compileOnly project(":API") 7 | compileOnly rootProject 8 | } 9 | 10 | if (project.hasProperty('hook.compile_coreprotect') && 11 | !Boolean.valueOf(project.findProperty("hook.compile_coreprotect").toString())) { 12 | project.tasks.all { task -> task.enabled = false } 13 | } -------------------------------------------------------------------------------- /Hooks/CoreProtect/src/main/java/com/bgsoftware/wildchests/hooks/CoreProtectHook.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 5 | import com.bgsoftware.wildchests.scheduler.Scheduler; 6 | import net.coreprotect.CoreProtect; 7 | import net.coreprotect.CoreProtectAPI; 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.Location; 10 | import org.bukkit.Material; 11 | import org.bukkit.OfflinePlayer; 12 | import org.bukkit.plugin.Plugin; 13 | 14 | import javax.annotation.Nullable; 15 | 16 | @SuppressWarnings({"deprecation", "unused"}) 17 | public final class CoreProtectHook { 18 | 19 | private static WildChestsPlugin plugin; 20 | 21 | private static Plugin coreProtect; 22 | private static boolean warningDisplayed = false; 23 | 24 | public static void register(WildChestsPlugin plugin) { 25 | CoreProtectHook.plugin = plugin; 26 | coreProtect = Bukkit.getPluginManager().getPlugin("CoreProtect"); 27 | plugin.getProviders().registerChestBreakListener(CoreProtectHook::recordBlockBreak); 28 | } 29 | 30 | public static void recordBlockBreak(@Nullable OfflinePlayer offlinePlayer, Chest chest) { 31 | if (offlinePlayer == null) // We don't want entities to record block breaks 32 | return; 33 | 34 | Location location = chest.getLocation(); 35 | 36 | if (!Scheduler.isScheduledForRegion(location)) { 37 | Scheduler.runTask(location, () -> recordBlockBreak(offlinePlayer, chest)); 38 | return; 39 | } 40 | 41 | CoreProtectAPI coreProtectAPI = ((CoreProtect) coreProtect).getAPI(); 42 | 43 | if (coreProtectAPI.APIVersion() == 5) { 44 | coreProtectAPI.logRemoval(offlinePlayer.getName(), location, Material.CHEST, (byte) 0); 45 | } else if (coreProtectAPI.APIVersion() <= 10) { 46 | coreProtectAPI.logRemoval(offlinePlayer.getName(), location, Material.CHEST, 47 | Material.CHEST.createBlockData()); 48 | } else if (!warningDisplayed) { 49 | warningDisplayed = true; 50 | WildChestsPlugin.log("&cDetected an API version of CoreProtect that is not supported: " + coreProtectAPI.APIVersion()); 51 | WildChestsPlugin.log("&cOpen an issue on github regarding this!"); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Hooks/Folia/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:Folia' 2 | 3 | java { 4 | toolchain { 5 | languageVersion.set(JavaLanguageVersion.of(17)) 6 | } 7 | } 8 | 9 | repositories { 10 | maven { url 'https://repo.papermc.io/repository/maven-public/' } 11 | } 12 | 13 | dependencies { 14 | compileOnly 'dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT' 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | if (project.hasProperty('hook.compile_folia') && 20 | !Boolean.valueOf(project.findProperty("hook.compile_folia").toString())) { 21 | project.tasks.all { task -> task.enabled = false } 22 | } -------------------------------------------------------------------------------- /Hooks/RoseStacker/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:RoseStacker' 2 | 3 | dependencies { 4 | compileOnly "dev.rosewood:RoseStacker:1.4.1" 5 | compileOnly "org.spigotmc:v1_16_R3:latest" 6 | compileOnly project(":API") 7 | compileOnly rootProject 8 | } 9 | 10 | if (project.hasProperty('hook.compile_rosestacker') && 11 | !Boolean.valueOf(project.findProperty("hook.compile_rosestacker").toString())) { 12 | project.tasks.all { task -> task.enabled = false } 13 | } -------------------------------------------------------------------------------- /Hooks/RoseStacker/src/main/java/com/bgsoftware/wildchests/hooks/StackerProvider_RoseStacker.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.wildchests.api.hooks.StackerProvider; 4 | import dev.rosewood.rosestacker.api.RoseStackerAPI; 5 | import dev.rosewood.rosestacker.stack.StackedItem; 6 | import org.bukkit.entity.Item; 7 | 8 | public final class StackerProvider_RoseStacker implements StackerProvider { 9 | 10 | @Override 11 | public int getItemAmount(Item item) { 12 | StackedItem stackedItem = RoseStackerAPI.getInstance().getStackedItem(item); 13 | return stackedItem == null ? item.getItemStack().getAmount() : stackedItem.getStackSize(); 14 | } 15 | 16 | @Override 17 | public void setItemAmount(Item item, int amount) { 18 | StackedItem stackedItem = RoseStackerAPI.getInstance().getStackedItem(item); 19 | if (stackedItem != null) 20 | stackedItem.setStackSize(amount); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Hooks/SuperiorSkyblock/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:SuperiorSkyblock' 2 | 3 | dependencies { 4 | compileOnly "com.bgsoftware:SuperiorSkyblockAPI:1.8.2" 5 | compileOnly "org.spigotmc:v1_16_R3:latest" 6 | compileOnly project(":API") 7 | compileOnly rootProject 8 | } 9 | 10 | if (project.hasProperty('hook.compile_superiorskyblock') && 11 | !Boolean.valueOf(project.findProperty("hook.compile_superiorskyblock").toString())) { 12 | project.tasks.all { task -> task.enabled = false } 13 | } -------------------------------------------------------------------------------- /Hooks/SuperiorSkyblock/src/main/java/com/bgsoftware/wildchests/hooks/BankProvider_SuperiorSkyblock.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI; 4 | import com.bgsoftware.superiorskyblock.api.island.Island; 5 | import com.bgsoftware.superiorskyblock.api.island.bank.BankTransaction; 6 | import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer; 7 | import com.bgsoftware.wildchests.api.hooks.BankProvider; 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.OfflinePlayer; 10 | 11 | import java.math.BigDecimal; 12 | 13 | public final class BankProvider_SuperiorSkyblock implements BankProvider { 14 | 15 | @Override 16 | public boolean depositMoney(OfflinePlayer offlinePlayer, BigDecimal money) { 17 | SuperiorPlayer superiorPlayer = SuperiorSkyblockAPI.getPlayer(offlinePlayer.getUniqueId()); 18 | Island island = superiorPlayer.getIsland(); 19 | 20 | if (island == null) 21 | return false; 22 | 23 | BankTransaction bankTransaction = island.getIslandBank().depositAdminMoney(Bukkit.getConsoleSender(), money); 24 | return bankTransaction.getFailureReason().isEmpty(); 25 | } 26 | 27 | @Override 28 | public boolean withdrawPlayer(OfflinePlayer offlinePlayer, double money) { 29 | throw new UnsupportedOperationException("This method is not supported for SuperiorSkyblock bank."); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Hooks/TransportPipes/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:TransportPipes' 2 | 3 | java { 4 | toolchain { 5 | languageVersion.set(JavaLanguageVersion.of(17)) 6 | } 7 | } 8 | 9 | dependencies { 10 | compileOnly "de.robotricker:TransportPipes:5.4.0" 11 | compileOnly "org.spigotmc:v1_8_R3-Taco:latest" 12 | compileOnly project(":API") 13 | compileOnly rootProject 14 | } 15 | 16 | if (project.hasProperty('hook.compile_transportpipes') && 17 | !Boolean.valueOf(project.findProperty("hook.compile_transportpipes").toString())) { 18 | project.tasks.all { task -> task.enabled = false } 19 | } -------------------------------------------------------------------------------- /Hooks/Vault/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:Vault' 2 | 3 | dependencies { 4 | compileOnly "net.milkbowl:Vault:1.6.1" 5 | compileOnly "org.spigotmc:v1_16_R3:latest" 6 | compileOnly project(":API") 7 | compileOnly rootProject 8 | } 9 | 10 | if (project.hasProperty('hook.compile_vault') && 11 | !Boolean.valueOf(project.findProperty("hook.compile_vault").toString())) { 12 | project.tasks.all { task -> task.enabled = false } 13 | } -------------------------------------------------------------------------------- /Hooks/Vault/src/main/java/com/bgsoftware/wildchests/hooks/BankProvider_Vault.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.wildchests.api.hooks.BankProvider; 4 | import net.milkbowl.vault.economy.Economy; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.OfflinePlayer; 7 | import org.bukkit.plugin.RegisteredServiceProvider; 8 | 9 | import java.math.BigDecimal; 10 | 11 | public final class BankProvider_Vault implements BankProvider { 12 | 13 | private final Economy economy; 14 | 15 | public BankProvider_Vault() { 16 | RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class); 17 | economy = rsp == null ? null : rsp.getProvider(); 18 | } 19 | 20 | @Override 21 | public boolean depositMoney(OfflinePlayer offlinePlayer, BigDecimal money) { 22 | if(economy == null) 23 | return false; 24 | 25 | if (!economy.hasAccount(offlinePlayer)) 26 | economy.createPlayerAccount(offlinePlayer); 27 | 28 | try { 29 | return economy.depositPlayer(offlinePlayer, money.doubleValue()).transactionSuccess(); 30 | } catch (Throwable error) { 31 | return false; 32 | } 33 | } 34 | 35 | @Override 36 | public boolean withdrawPlayer(OfflinePlayer offlinePlayer, double money) { 37 | if (!economy.hasAccount(offlinePlayer)) 38 | economy.createPlayerAccount(offlinePlayer); 39 | 40 | try { 41 | return economy.withdrawPlayer(offlinePlayer, money).transactionSuccess(); 42 | } catch (Throwable error) { 43 | return false; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Hooks/WildStacker/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks:WildStacker' 2 | 3 | dependencies { 4 | compileOnly "com.bgsoftware:WildStackerAPI:3.6.1" 5 | compileOnly "org.spigotmc:v1_16_R3:latest" 6 | compileOnly project(":API") 7 | compileOnly rootProject 8 | } 9 | 10 | if (project.hasProperty('hook.compile_wildstacker') && 11 | !Boolean.valueOf(project.findProperty("hook.compile_wildstacker").toString())) { 12 | project.tasks.all { task -> task.enabled = false } 13 | } -------------------------------------------------------------------------------- /Hooks/WildStacker/src/main/java/com/bgsoftware/wildchests/hooks/StackerProvider_WildStacker.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.wildchests.api.hooks.StackerProvider; 4 | import com.bgsoftware.wildstacker.api.WildStackerAPI; 5 | import org.bukkit.Location; 6 | import org.bukkit.entity.Item; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | public final class StackerProvider_WildStacker implements StackerProvider { 10 | 11 | @Override 12 | public int getItemAmount(Item item) { 13 | return WildStackerAPI.getItemAmount(item); 14 | } 15 | 16 | @Override 17 | public void setItemAmount(Item item, int amount) { 18 | WildStackerAPI.getStackedItem(item).setStackAmount(amount, true); 19 | } 20 | 21 | @Override 22 | public boolean dropItem(Location location, ItemStack itemStack, int amount) { 23 | WildStackerAPI.getWildStacker().getSystemManager().spawnItemWithAmount(location, itemStack, amount); 24 | return true; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Hooks/build.gradle: -------------------------------------------------------------------------------- 1 | group 'Hooks' -------------------------------------------------------------------------------- /NMS/build.gradle: -------------------------------------------------------------------------------- 1 | group 'NMS' -------------------------------------------------------------------------------- /NMS/v1_12_R1/build.gradle: -------------------------------------------------------------------------------- 1 | group 'NMS:v1_12_R1' 2 | 3 | dependencies { 4 | compileOnly "org.spigotmc:v1_12_R1:latest" 5 | compileOnly project(":API") 6 | compileOnly rootProject 7 | } 8 | 9 | if (project.hasProperty('nms.compile_v1_12') && !Boolean.valueOf(project.findProperty("nms.compile_v1_12").toString())) { 10 | project.tasks.all { task -> task.enabled = false } 11 | } -------------------------------------------------------------------------------- /NMS/v1_12_R1/src/main/java/com/bgsoftware/wildchests/nms/v1_12_R1/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_12_R1.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.server.v1_12_R1.Container; 6 | import net.minecraft.server.v1_12_R1.EntityHuman; 7 | import net.minecraft.server.v1_12_R1.PlayerInventory; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final Container container; 16 | private final PlayerInventory playerInventory; 17 | private final WildInventory inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(Container container, PlayerInventory playerInventory, WildInventory inventory) { 23 | this.container = container; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventory inventory = new CraftWildInventory(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, container); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(EntityHuman entityHuman) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(entityHuman)); 41 | } else { 42 | doRemoved(entityHuman); 43 | } 44 | } 45 | 46 | private void doRemoved(EntityHuman entityHuman) { 47 | ((TileEntityWildChest) ((WChest) inventory.chest).getTileEntityContainer()).closeContainer(entityHuman); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_12_R1/src/main/java/com/bgsoftware/wildchests/nms/v1_12_R1/inventory/CraftWildInventory.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_12_R1.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 5 | import net.minecraft.server.v1_12_R1.IInventory; 6 | import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory; 7 | 8 | import java.util.List; 9 | 10 | public class CraftWildInventory extends CraftInventory implements com.bgsoftware.wildchests.objects.inventory.CraftWildInventory { 11 | 12 | public CraftWildInventory(IInventory inventory) { 13 | super(inventory); 14 | } 15 | 16 | @Override 17 | public Chest getOwner() { 18 | return getInventory().chest; 19 | } 20 | 21 | @Override 22 | public WildContainerItemImpl getWildItem(int slot) { 23 | return getInventory().getWildItem(slot); 24 | } 25 | 26 | @Override 27 | public void setItem(int i, WildContainerItem itemStack) { 28 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 29 | } 30 | 31 | @Override 32 | public List getWildContents() { 33 | return getInventory().items; 34 | } 35 | 36 | @Override 37 | public WildInventory getInventory() { 38 | return (WildInventory) super.getInventory(); 39 | } 40 | 41 | @Override 42 | public void setTitle(String title) { 43 | getInventory().setTitle(title); 44 | } 45 | 46 | @Override 47 | public String getTitle() { 48 | return getInventory().getTitle(); 49 | } 50 | 51 | @Override 52 | public boolean isFull() { 53 | return getInventory().isFull(); 54 | } 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | return obj instanceof CraftWildInventory && getInventory() == ((CraftWildInventory) obj).getInventory(); 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /NMS/v1_12_R1/src/main/java/com/bgsoftware/wildchests/nms/v1_12_R1/inventory/WildContainerChest.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_12_R1.inventory; 2 | 3 | import com.bgsoftware.wildchests.listeners.InventoryListener; 4 | import net.minecraft.server.v1_12_R1.Container; 5 | import net.minecraft.server.v1_12_R1.ContainerChest; 6 | import net.minecraft.server.v1_12_R1.EntityHuman; 7 | import net.minecraft.server.v1_12_R1.PlayerInventory; 8 | import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView; 9 | 10 | public class WildContainerChest extends ContainerChest { 11 | 12 | private final BaseNMSMenu base; 13 | 14 | private WildContainerChest(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 15 | super(playerInventory, inventory, entityHuman); 16 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 17 | } 18 | 19 | @Override 20 | public CraftInventoryView getBukkitView() { 21 | return this.base.getBukkitView(); 22 | } 23 | 24 | @Override 25 | public void b(EntityHuman entityhuman) { 26 | if (!InventoryListener.buyNewPage.containsKey(entityhuman.getUniqueID())) 27 | this.base.removed(entityhuman); 28 | } 29 | 30 | public static Container of(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 31 | return new WildContainerChest(playerInventory, entityHuman, inventory); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /NMS/v1_12_R1/src/main/java/com/bgsoftware/wildchests/nms/v1_12_R1/inventory/WildContainerHopper.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_12_R1.inventory; 2 | 3 | import net.minecraft.server.v1_12_R1.ContainerHopper; 4 | import net.minecraft.server.v1_12_R1.EntityHuman; 5 | import net.minecraft.server.v1_12_R1.PlayerInventory; 6 | import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView; 7 | 8 | public class WildContainerHopper extends ContainerHopper { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildContainerHopper(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 13 | super(playerInventory, inventory, entityHuman); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void b(EntityHuman entityhuman) { 24 | this.base.removed(entityhuman); 25 | } 26 | 27 | public static WildContainerHopper of(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 28 | return new WildContainerHopper(playerInventory, entityHuman, inventory); 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /NMS/v1_12_R1/src/main/java/com/bgsoftware/wildchests/nms/v1_12_R1/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_12_R1.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.server.v1_12_R1.ItemStack; 5 | import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.cloneItemStack()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_12_R1/src/main/java/com/bgsoftware/wildchests/nms/v1_12_R1/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_12_R1.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.server.v1_12_R1.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/build.gradle: -------------------------------------------------------------------------------- 1 | group 'NMS:v1_16_R3' 2 | 3 | dependencies { 4 | compileOnly "org.spigotmc:v1_16_R3:latest" 5 | compileOnly project(":API") 6 | compileOnly rootProject 7 | } 8 | 9 | if (project.hasProperty('nms.compile_v1_16') && !Boolean.valueOf(project.findProperty("nms.compile_v1_16").toString())) { 10 | project.tasks.all { task -> task.enabled = false } 11 | } -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.server.v1_16_R3.Container; 6 | import net.minecraft.server.v1_16_R3.EntityHuman; 7 | import net.minecraft.server.v1_16_R3.PlayerInventory; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final Container container; 16 | private final PlayerInventory playerInventory; 17 | private final WildInventory inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(Container container, PlayerInventory playerInventory, WildInventory inventory) { 23 | this.container = container; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventory inventory = new CraftWildInventory(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, container); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(EntityHuman entityHuman) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(entityHuman)); 41 | } else { 42 | doRemoved(entityHuman); 43 | } 44 | } 45 | 46 | private void doRemoved(EntityHuman entityHuman) { 47 | ((TileEntityWildChest) ((WChest) inventory.chest).getTileEntityContainer()).closeContainer(entityHuman); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/inventory/CraftWildInventory.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 5 | import net.minecraft.server.v1_16_R3.IInventory; 6 | import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory; 7 | 8 | import java.util.List; 9 | 10 | public class CraftWildInventory extends CraftInventory implements com.bgsoftware.wildchests.objects.inventory.CraftWildInventory { 11 | 12 | public CraftWildInventory(IInventory inventory) { 13 | super(inventory); 14 | } 15 | 16 | @Override 17 | public Chest getOwner() { 18 | return getInventory().chest; 19 | } 20 | 21 | @Override 22 | public WildContainerItemImpl getWildItem(int slot) { 23 | return getInventory().getWildItem(slot); 24 | } 25 | 26 | @Override 27 | public void setItem(int i, WildContainerItem itemStack) { 28 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 29 | } 30 | 31 | @Override 32 | public List getWildContents() { 33 | return getInventory().items; 34 | } 35 | 36 | @Override 37 | public WildInventory getInventory() { 38 | return (WildInventory) super.getInventory(); 39 | } 40 | 41 | @Override 42 | public void setTitle(String title) { 43 | getInventory().setTitle(title); 44 | } 45 | 46 | @Override 47 | public String getTitle() { 48 | return getInventory().getTitle(); 49 | } 50 | 51 | @Override 52 | public boolean isFull() { 53 | return getInventory().isFull(); 54 | } 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | return obj instanceof CraftWildInventory && getInventory() == ((CraftWildInventory) obj).getInventory(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/inventory/WildContainerChest.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.listeners.InventoryListener; 4 | import net.minecraft.server.v1_16_R3.Container; 5 | import net.minecraft.server.v1_16_R3.ContainerChest; 6 | import net.minecraft.server.v1_16_R3.Containers; 7 | import net.minecraft.server.v1_16_R3.EntityHuman; 8 | import net.minecraft.server.v1_16_R3.PlayerInventory; 9 | import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; 10 | 11 | public class WildContainerChest extends ContainerChest { 12 | 13 | private final BaseNMSMenu base; 14 | 15 | private WildContainerChest(Containers containers, int id, PlayerInventory playerInventory, WildInventory inventory, int rows) { 16 | super(containers, id, playerInventory, inventory, rows); 17 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 18 | } 19 | 20 | @Override 21 | public CraftInventoryView getBukkitView() { 22 | return this.base.getBukkitView(); 23 | } 24 | 25 | @Override 26 | public void b(EntityHuman entityhuman) { 27 | if (!InventoryListener.buyNewPage.containsKey(entityhuman.getUniqueID())) 28 | this.base.removed(entityhuman); 29 | } 30 | 31 | public static Container of(int id, PlayerInventory playerInventory, WildInventory inventory) { 32 | Containers containers = Containers.GENERIC_9X3; 33 | int rows = 3; 34 | 35 | switch (inventory.getSize()) { 36 | case 9: 37 | rows = 1; 38 | containers = Containers.GENERIC_9X1; 39 | break; 40 | case 18: 41 | rows = 2; 42 | containers = Containers.GENERIC_9X2; 43 | break; 44 | case 36: 45 | rows = 4; 46 | containers = Containers.GENERIC_9X4; 47 | break; 48 | case 45: 49 | rows = 5; 50 | containers = Containers.GENERIC_9X5; 51 | break; 52 | case 54: 53 | rows = 6; 54 | containers = Containers.GENERIC_9X6; 55 | break; 56 | } 57 | 58 | return new WildContainerChest(containers, id, playerInventory, inventory, rows); 59 | } 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/inventory/WildContainerHopper.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.inventory; 2 | 3 | import net.minecraft.server.v1_16_R3.ContainerHopper; 4 | import net.minecraft.server.v1_16_R3.EntityHuman; 5 | import net.minecraft.server.v1_16_R3.PlayerInventory; 6 | import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; 7 | 8 | public class WildContainerHopper extends ContainerHopper { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildContainerHopper(int id, PlayerInventory playerInventory, WildInventory inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void b(EntityHuman entityhuman) { 24 | this.base.removed(entityhuman); 25 | } 26 | 27 | public static WildContainerHopper of(int id, PlayerInventory playerInventory, WildInventory inventory) { 28 | return new WildContainerHopper(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.server.v1_16_R3.ItemStack; 5 | import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.cloneItemStack()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.utils; 2 | 3 | import net.minecraft.server.v1_16_R3.NBTBase; 4 | import net.minecraft.server.v1_16_R3.NBTReadLimiter; 5 | import net.minecraft.server.v1_16_R3.NBTTagCompound; 6 | import net.minecraft.server.v1_16_R3.NBTTagEnd; 7 | import net.minecraft.server.v1_16_R3.NBTTagTypes; 8 | 9 | import java.io.DataInput; 10 | import java.io.IOException; 11 | 12 | /** 13 | * This class reimplements {@link net.minecraft.server.v1_16_R3.NBTCompressedStreamTools} without the CrashReport part. 14 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 15 | */ 16 | public class NbtUtils { 17 | 18 | private NbtUtils() { 19 | 20 | } 21 | 22 | public static NBTTagCompound read(DataInput input, NBTReadLimiter tracker) throws IOException { 23 | NBTBase nbtBase = readUnnamedTag(input, tracker); 24 | 25 | if (nbtBase instanceof NBTTagCompound) { 26 | return (NBTTagCompound) nbtBase; 27 | } 28 | 29 | throw new IOException("Root tag must be a named compound tag"); 30 | } 31 | 32 | private static NBTBase readUnnamedTag(DataInput input, NBTReadLimiter tracker) throws IOException { 33 | byte firstByte = input.readByte(); 34 | 35 | if (firstByte == 0) { 36 | return NBTTagEnd.b; 37 | } 38 | 39 | input.readUTF(); 40 | return readTag(input, tracker, firstByte); 41 | } 42 | 43 | private static NBTBase readTag(DataInput input, NBTReadLimiter tracker, byte typeId) throws IOException { 44 | return NBTTagTypes.a(typeId).b(input, 0, tracker); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /NMS/v1_16_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_16_R3/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_16_R3.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.server.v1_16_R3.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_17/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(17)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_17' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_17') && !Boolean.valueOf(project.findProperty("nms.compile_v1_17").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_17/src/main/java/com/bgsoftware/wildchests/nms/v1_17/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_17.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_17/src/main/java/com/bgsoftware/wildchests/nms/v1_17/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_17.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_17/src/main/java/com/bgsoftware/wildchests/nms/v1_17/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_17.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_17/src/main/java/com/bgsoftware/wildchests/nms/v1_17/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_17.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_17/src/main/java/com/bgsoftware/wildchests/nms/v1_17/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_17.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.Tag; 7 | import net.minecraft.nbt.TagTypes; 8 | 9 | import java.io.BufferedInputStream; 10 | import java.io.DataInput; 11 | import java.io.DataInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.util.zip.GZIPInputStream; 15 | 16 | /** 17 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 18 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 19 | */ 20 | public class NbtUtils { 21 | 22 | private NbtUtils() { 23 | 24 | } 25 | 26 | public static CompoundTag read(DataInput input) throws IOException { 27 | return read(input, NbtAccounter.UNLIMITED); 28 | } 29 | 30 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 31 | Tag nbtBase = readUnnamedTag(input, tracker); 32 | 33 | if (nbtBase instanceof CompoundTag) { 34 | return (CompoundTag) nbtBase; 35 | } 36 | 37 | throw new IOException("Root tag must be a named compound tag"); 38 | } 39 | 40 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 41 | byte firstByte = input.readByte(); 42 | 43 | if (firstByte == 0) { 44 | return EndTag.INSTANCE; 45 | } 46 | 47 | input.readUTF(); 48 | return readTag(input, tracker, firstByte); 49 | } 50 | 51 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 52 | return TagTypes.getType(typeId).load(input, 0, tracker); 53 | } 54 | 55 | public static CompoundTag readCompressed(InputStream stream) throws IOException { 56 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 57 | return read(dataInputStream); 58 | } 59 | } 60 | 61 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 62 | return new DataInputStream(new BufferedInputStream(new GZIPInputStream(stream))); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /NMS/v1_17/src/main/java/com/bgsoftware/wildchests/nms/v1_17/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_17.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_18/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(17)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_18' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_18') && !Boolean.valueOf(project.findProperty("nms.compile_v1_18").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_18/src/main/java/com/bgsoftware/wildchests/nms/v1_18/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_18.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_18/src/main/java/com/bgsoftware/wildchests/nms/v1_18/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_18.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_18/src/main/java/com/bgsoftware/wildchests/nms/v1_18/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_18.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_18/src/main/java/com/bgsoftware/wildchests/nms/v1_18/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_18.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_18/src/main/java/com/bgsoftware/wildchests/nms/v1_18/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_18.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.UNLIMITED); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, 0, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_18/src/main/java/com/bgsoftware/wildchests/nms/v1_18/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_18.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_19/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(17)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_19' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_19') && !Boolean.valueOf(project.findProperty("nms.compile_v1_19").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_19/src/main/java/com/bgsoftware/wildchests/nms/v1_19/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_19.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_19/src/main/java/com/bgsoftware/wildchests/nms/v1_19/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_19.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_19/src/main/java/com/bgsoftware/wildchests/nms/v1_19/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_19.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_19/src/main/java/com/bgsoftware/wildchests/nms/v1_19/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_19.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_19/src/main/java/com/bgsoftware/wildchests/nms/v1_19/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_19.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.UNLIMITED); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, 0, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_19/src/main/java/com/bgsoftware/wildchests/nms/v1_19/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_19.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_20_3/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(17)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_20_3' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_20') && !Boolean.valueOf(project.findProperty("nms.compile_v1_20").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_20_3/src/main/java/com/bgsoftware/wildchests/nms/v1_20_3/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_20_3/src/main/java/com/bgsoftware/wildchests/nms/v1_20_3/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_3.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_20_3/src/main/java/com/bgsoftware/wildchests/nms/v1_20_3/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_20_3/src/main/java/com/bgsoftware/wildchests/nms/v1_20_3/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_3.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_20_3/src/main/java/com/bgsoftware/wildchests/nms/v1_20_3/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_3.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.unlimitedHeap()); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream, NbtAccounter tagSizeTracker) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream, tagSizeTracker); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_20_3/src/main/java/com/bgsoftware/wildchests/nms/v1_20_3/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_3.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_20_4/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(21)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_20_4' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_20') && !Boolean.valueOf(project.findProperty("nms.compile_v1_20").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_20_4/src/main/java/com/bgsoftware/wildchests/nms/v1_20_4/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_4.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_20_4/src/main/java/com/bgsoftware/wildchests/nms/v1_20_4/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_4.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_20_4/src/main/java/com/bgsoftware/wildchests/nms/v1_20_4/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_4.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_20_4/src/main/java/com/bgsoftware/wildchests/nms/v1_20_4/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_4.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_20_4/src/main/java/com/bgsoftware/wildchests/nms/v1_20_4/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_4.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.unlimitedHeap()); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream, NbtAccounter tagSizeTracker) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream, tagSizeTracker); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_20_4/src/main/java/com/bgsoftware/wildchests/nms/v1_20_4/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_20_4.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_21/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(21)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_21' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_21') && !Boolean.valueOf(project.findProperty("nms.compile_v1_21").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/inventory/WildChestMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.inventory; 2 | 3 | import com.bgsoftware.wildchests.listeners.InventoryListener; 4 | import net.minecraft.world.entity.player.Inventory; 5 | import net.minecraft.world.entity.player.Player; 6 | import net.minecraft.world.inventory.ChestMenu; 7 | import net.minecraft.world.inventory.MenuType; 8 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 9 | 10 | public class WildChestMenu extends ChestMenu { 11 | 12 | private final BaseNMSMenu base; 13 | 14 | private WildChestMenu(MenuType menuType, int id, Inventory playerInventory, WildContainer inventory, int rows) { 15 | super(menuType, id, playerInventory, inventory, rows); 16 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 17 | } 18 | 19 | @Override 20 | public CraftInventoryView getBukkitView() { 21 | return this.base.getBukkitView(); 22 | } 23 | 24 | @Override 25 | public void removed(Player player) { 26 | if (!InventoryListener.buyNewPage.containsKey(player.getUUID())) 27 | this.base.removed(player); 28 | } 29 | 30 | public static WildChestMenu of(int id, Inventory playerInventory, WildContainer inventory) { 31 | MenuType menuType; 32 | int rows; 33 | 34 | switch (inventory.getContainerSize()) { 35 | case 9 -> { 36 | rows = 1; 37 | menuType = MenuType.GENERIC_9x1; 38 | } 39 | case 18 -> { 40 | rows = 2; 41 | menuType = MenuType.GENERIC_9x2; 42 | } 43 | case 27 -> { 44 | rows = 3; 45 | menuType = MenuType.GENERIC_9x3; 46 | } 47 | case 36 -> { 48 | rows = 4; 49 | menuType = MenuType.GENERIC_9x4; 50 | } 51 | case 45 -> { 52 | rows = 5; 53 | menuType = MenuType.GENERIC_9x5; 54 | } 55 | case 54 -> { 56 | rows = 6; 57 | menuType = MenuType.GENERIC_9x6; 58 | } 59 | default -> { 60 | throw new IllegalArgumentException("Invalid inventory size: " + inventory.getContainerSize()); 61 | } 62 | } 63 | 64 | return new WildChestMenu(menuType, id, playerInventory, inventory, rows); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.unlimitedHeap()); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream, NbtAccounter tagSizeTracker) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream, tagSizeTracker); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_21/src/main/java/com/bgsoftware/wildchests/nms/v1_21/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_21_3/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(21)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_21_3' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_21') && !Boolean.valueOf(project.findProperty("nms.compile_v1_21").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_21_3/src/main/java/com/bgsoftware/wildchests/nms/v1_21_3/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_21_3/src/main/java/com/bgsoftware/wildchests/nms/v1_21_3/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_3.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_21_3/src/main/java/com/bgsoftware/wildchests/nms/v1_21_3/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_21_3/src/main/java/com/bgsoftware/wildchests/nms/v1_21_3/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_3.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_21_3/src/main/java/com/bgsoftware/wildchests/nms/v1_21_3/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_3.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.unlimitedHeap()); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream, NbtAccounter tagSizeTracker) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream, tagSizeTracker); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_21_3/src/main/java/com/bgsoftware/wildchests/nms/v1_21_3/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_3.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_21_4/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(21)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_21_4' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_21') && !Boolean.valueOf(project.findProperty("nms.compile_v1_21").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_21_4/src/main/java/com/bgsoftware/wildchests/nms/v1_21_4/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_4.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_21_4/src/main/java/com/bgsoftware/wildchests/nms/v1_21_4/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_4.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_21_4/src/main/java/com/bgsoftware/wildchests/nms/v1_21_4/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_4.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_21_4/src/main/java/com/bgsoftware/wildchests/nms/v1_21_4/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_4.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_21_4/src/main/java/com/bgsoftware/wildchests/nms/v1_21_4/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_4.utils; 2 | 3 | import net.minecraft.nbt.CompoundTag; 4 | import net.minecraft.nbt.EndTag; 5 | import net.minecraft.nbt.NbtAccounter; 6 | import net.minecraft.nbt.StringTag; 7 | import net.minecraft.nbt.Tag; 8 | import net.minecraft.nbt.TagTypes; 9 | import net.minecraft.util.FastBufferedInputStream; 10 | 11 | import java.io.DataInput; 12 | import java.io.DataInputStream; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.util.zip.GZIPInputStream; 16 | 17 | /** 18 | * This class reimplements {@link net.minecraft.nbt.NbtIo} without the CrashReport part. 19 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 20 | */ 21 | public class NbtUtils { 22 | 23 | private NbtUtils() { 24 | 25 | } 26 | 27 | public static CompoundTag read(DataInput input) throws IOException { 28 | return read(input, NbtAccounter.unlimitedHeap()); 29 | } 30 | 31 | private static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException { 32 | Tag nbtBase = readUnnamedTag(input, tracker); 33 | 34 | if (nbtBase instanceof CompoundTag) { 35 | return (CompoundTag) nbtBase; 36 | } 37 | 38 | throw new IOException("Root tag must be a named compound tag"); 39 | } 40 | 41 | private static Tag readUnnamedTag(DataInput input, NbtAccounter tracker) throws IOException { 42 | byte firstByte = input.readByte(); 43 | 44 | if (firstByte == 0) { 45 | return EndTag.INSTANCE; 46 | } 47 | 48 | StringTag.skipString(input); 49 | return readTag(input, tracker, firstByte); 50 | } 51 | 52 | private static Tag readTag(DataInput input, NbtAccounter tracker, byte typeId) throws IOException { 53 | return TagTypes.getType(typeId).load(input, tracker); 54 | } 55 | 56 | public static CompoundTag readCompressed(InputStream stream, NbtAccounter tagSizeTracker) throws IOException { 57 | try (DataInputStream dataInputStream = createDecompressorStream(stream)) { 58 | return read(dataInputStream, tagSizeTracker); 59 | } 60 | } 61 | 62 | private static DataInputStream createDecompressorStream(InputStream stream) throws IOException { 63 | return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(stream))); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NMS/v1_21_4/src/main/java/com/bgsoftware/wildchests/nms/v1_21_4/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_4.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_21_5/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.papermc.paperweight.userdev") version "2.0.0-beta.11" 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion.set(JavaLanguageVersion.of(21)) 8 | } 9 | } 10 | 11 | group 'NMS:v1_21_5' 12 | 13 | dependencies { 14 | paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT") 15 | compileOnly project(":API") 16 | compileOnly rootProject 17 | } 18 | 19 | shadowJar { 20 | archiveFileName = "${project.name}-exclude.jar" 21 | } 22 | 23 | assemble { 24 | dependsOn(reobfJar) 25 | } 26 | 27 | tasks { 28 | reobfJar { 29 | File outputFile = new File(rootProject.archiveFolder, "reobf/${project.name}.jar") 30 | outputJar.set(layout.buildDirectory.file(outputFile.getPath())) 31 | } 32 | } 33 | 34 | if (project.hasProperty('nms.compile_v1_21') && !Boolean.valueOf(project.findProperty("nms.compile_v1_21").toString())) { 35 | project.tasks.all { task -> task.enabled = false } 36 | } -------------------------------------------------------------------------------- /NMS/v1_21_5/src/main/java/com/bgsoftware/wildchests/nms/v1_21_5/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_5.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.world.entity.player.Inventory; 6 | import net.minecraft.world.entity.player.Player; 7 | import net.minecraft.world.inventory.AbstractContainerMenu; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final AbstractContainerMenu containerMenu; 16 | private final Inventory playerInventory; 17 | private final WildContainer inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(AbstractContainerMenu containerMenu, Inventory playerInventory, WildContainer inventory) { 23 | this.containerMenu = containerMenu; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventoryImpl inventory = new CraftWildInventoryImpl(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, containerMenu); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(Player player) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(player)); 41 | } else { 42 | doRemoved(player); 43 | } 44 | } 45 | 46 | private void doRemoved(Player player) { 47 | ((WildChestBlockEntity) ((WChest) inventory.chest).getTileEntityContainer()).stopOpen(player); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_21_5/src/main/java/com/bgsoftware/wildchests/nms/v1_21_5/inventory/CraftWildInventoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_5.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import net.minecraft.world.Container; 7 | import org.bukkit.craftbukkit.inventory.CraftInventory; 8 | 9 | import java.util.List; 10 | 11 | public class CraftWildInventoryImpl extends CraftInventory implements CraftWildInventory { 12 | 13 | public CraftWildInventoryImpl(Container container) { 14 | super(container); 15 | } 16 | 17 | @Override 18 | public Chest getOwner() { 19 | return getInventory().chest; 20 | } 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildContainer getInventory() { 39 | return (WildContainer) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | return obj instanceof CraftWildInventoryImpl && getInventory() == ((CraftWildInventoryImpl) obj).getInventory(); 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /NMS/v1_21_5/src/main/java/com/bgsoftware/wildchests/nms/v1_21_5/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_5.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.world.item.ItemStack; 5 | import org.bukkit.craftbukkit.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.copy()); 33 | } 34 | 35 | public static ItemStack transform(WildContainerItem input) { 36 | return ((WildContainerItemImpl) input).getHandle(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NMS/v1_21_5/src/main/java/com/bgsoftware/wildchests/nms/v1_21_5/inventory/WildHopperMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_5.inventory; 2 | 3 | import net.minecraft.world.entity.player.Inventory; 4 | import net.minecraft.world.entity.player.Player; 5 | import net.minecraft.world.inventory.HopperMenu; 6 | import org.bukkit.craftbukkit.inventory.CraftInventoryView; 7 | 8 | public class WildHopperMenu extends HopperMenu { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildHopperMenu(int id, Inventory playerInventory, WildContainer inventory) { 13 | super(id, playerInventory, inventory); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void removed(Player player) { 24 | this.base.removed(player); 25 | } 26 | 27 | public static WildHopperMenu of(int id, Inventory playerInventory, WildContainer inventory) { 28 | return new WildHopperMenu(id, playerInventory, inventory); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NMS/v1_21_5/src/main/java/com/bgsoftware/wildchests/nms/v1_21_5/utils/TransformingNonNullList.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_21_5.utils; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.collect.ForwardingList; 5 | import com.google.common.collect.Lists; 6 | import net.minecraft.core.NonNullList; 7 | 8 | import java.util.List; 9 | import java.util.RandomAccess; 10 | 11 | public class TransformingNonNullList extends NonNullList { 12 | 13 | public static NonNullList transform(List delegate, T initialElement, Function transformer) { 14 | return new TransformingNonNullList<>(Lists.transform(new RandomAccessNonNullList<>(delegate), transformer), initialElement); 15 | } 16 | 17 | private TransformingNonNullList(List delegate, T initialElement) { 18 | super(delegate, initialElement); 19 | } 20 | 21 | /* Patch for Lists#transform to detect NonNullList as a RandomAccess list */ 22 | private static class RandomAccessNonNullList extends ForwardingList implements RandomAccess { 23 | 24 | private final List delegate; 25 | 26 | public RandomAccessNonNullList(List delegate) { 27 | this.delegate = delegate; 28 | } 29 | 30 | @Override 31 | protected List delegate() { 32 | return this.delegate; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NMS/v1_8_R3/build.gradle: -------------------------------------------------------------------------------- 1 | group 'NMS:v1_8_R3' 2 | 3 | dependencies { 4 | compileOnly "org.spigotmc:v1_8_R3:latest" 5 | compileOnly project(":API") 6 | compileOnly rootProject 7 | } 8 | 9 | if (project.hasProperty('nms.compile_v1_8') && !Boolean.valueOf(project.findProperty("nms.compile_v1_8").toString())) { 10 | project.tasks.all { task -> task.enabled = false } 11 | } -------------------------------------------------------------------------------- /NMS/v1_8_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_8_R3/inventory/BaseNMSMenu.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_8_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.chests.WChest; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import net.minecraft.server.v1_8_R3.Container; 6 | import net.minecraft.server.v1_8_R3.EntityHuman; 7 | import net.minecraft.server.v1_8_R3.PlayerInventory; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | public class BaseNMSMenu { 14 | 15 | private final Container container; 16 | private final PlayerInventory playerInventory; 17 | private final WildInventory inventory; 18 | private final Location location; 19 | @Nullable 20 | private CraftInventoryView bukkitEntity; 21 | 22 | public BaseNMSMenu(Container container, PlayerInventory playerInventory, WildInventory inventory) { 23 | this.container = container; 24 | this.playerInventory = playerInventory; 25 | this.inventory = inventory; 26 | this.location = inventory.chest.getLocation(); 27 | } 28 | 29 | public CraftInventoryView getBukkitView() { 30 | if (bukkitEntity == null) { 31 | CraftWildInventory inventory = new CraftWildInventory(this.inventory); 32 | bukkitEntity = new CraftInventoryView(playerInventory.player.getBukkitEntity(), inventory, container); 33 | } 34 | 35 | return bukkitEntity; 36 | } 37 | 38 | public void removed(EntityHuman entityHuman) { 39 | if (Scheduler.isRegionScheduler() && !Scheduler.isScheduledForRegion(location)) { 40 | Scheduler.runTask(location, () -> doRemoved(entityHuman)); 41 | } else { 42 | doRemoved(entityHuman); 43 | } 44 | } 45 | 46 | private void doRemoved(EntityHuman entityHuman) { 47 | ((TileEntityWildChest) ((WChest) inventory.chest).getTileEntityContainer()).closeContainer(entityHuman); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /NMS/v1_8_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_8_R3/inventory/CraftWildInventory.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_8_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 5 | import net.minecraft.server.v1_8_R3.IInventory; 6 | import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; 7 | 8 | import java.util.List; 9 | 10 | public class CraftWildInventory extends CraftInventory implements com.bgsoftware.wildchests.objects.inventory.CraftWildInventory { 11 | 12 | public CraftWildInventory(IInventory inventory) { 13 | super(inventory); 14 | } 15 | 16 | @Override 17 | public Chest getOwner() { 18 | return getInventory().chest; 19 | } 20 | 21 | 22 | @Override 23 | public WildContainerItemImpl getWildItem(int slot) { 24 | return getInventory().getWildItem(slot); 25 | } 26 | 27 | @Override 28 | public void setItem(int i, WildContainerItem itemStack) { 29 | getInventory().setItem(i, (WildContainerItemImpl) itemStack, true); 30 | } 31 | 32 | @Override 33 | public List getWildContents() { 34 | return getInventory().items; 35 | } 36 | 37 | @Override 38 | public WildInventory getInventory() { 39 | return (WildInventory) super.getInventory(); 40 | } 41 | 42 | @Override 43 | public void setTitle(String title) { 44 | getInventory().setTitle(title); 45 | } 46 | 47 | @Override 48 | public String getTitle() { 49 | return getInventory().getTitle(); 50 | } 51 | 52 | @Override 53 | public boolean isFull() { 54 | return getInventory().isFull(); 55 | } 56 | 57 | @Override 58 | public void setContents(org.bukkit.inventory.ItemStack[] items) { 59 | for (int i = 0; i < items.length; i++) 60 | setItem(i, items[i]); 61 | } 62 | 63 | @Override 64 | public boolean equals(Object obj) { 65 | return obj instanceof CraftWildInventory && getInventory() == ((CraftWildInventory) obj).getInventory(); 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /NMS/v1_8_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_8_R3/inventory/WildContainerChest.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_8_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.listeners.InventoryListener; 4 | import net.minecraft.server.v1_8_R3.Container; 5 | import net.minecraft.server.v1_8_R3.ContainerChest; 6 | import net.minecraft.server.v1_8_R3.EntityHuman; 7 | import net.minecraft.server.v1_8_R3.PlayerInventory; 8 | import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView; 9 | 10 | public class WildContainerChest extends ContainerChest { 11 | 12 | private final BaseNMSMenu base; 13 | 14 | private WildContainerChest(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 15 | super(playerInventory, inventory, entityHuman); 16 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 17 | } 18 | 19 | @Override 20 | public CraftInventoryView getBukkitView() { 21 | return this.base.getBukkitView(); 22 | } 23 | 24 | @Override 25 | public void b(EntityHuman entityhuman) { 26 | if (!InventoryListener.buyNewPage.containsKey(entityhuman.getUniqueID())) 27 | this.base.removed(entityhuman); 28 | } 29 | 30 | public static Container of(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 31 | return new WildContainerChest(playerInventory, entityHuman, inventory); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /NMS/v1_8_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_8_R3/inventory/WildContainerHopper.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_8_R3.inventory; 2 | 3 | import net.minecraft.server.v1_8_R3.ContainerHopper; 4 | import net.minecraft.server.v1_8_R3.EntityHuman; 5 | import net.minecraft.server.v1_8_R3.PlayerInventory; 6 | import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView; 7 | 8 | public class WildContainerHopper extends ContainerHopper { 9 | 10 | private final BaseNMSMenu base; 11 | 12 | private WildContainerHopper(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 13 | super(playerInventory, inventory, entityHuman); 14 | this.base = new BaseNMSMenu(this, playerInventory, inventory); 15 | } 16 | 17 | @Override 18 | public CraftInventoryView getBukkitView() { 19 | return this.base.getBukkitView(); 20 | } 21 | 22 | @Override 23 | public void b(EntityHuman entityhuman) { 24 | this.base.removed(entityhuman); 25 | } 26 | 27 | public static WildContainerHopper of(PlayerInventory playerInventory, EntityHuman entityHuman, WildInventory inventory) { 28 | return new WildContainerHopper(playerInventory, entityHuman, inventory); 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /NMS/v1_8_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_8_R3/inventory/WildContainerItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_8_R3.inventory; 2 | 3 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 4 | import net.minecraft.server.v1_8_R3.ItemStack; 5 | import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; 6 | 7 | public class WildContainerItemImpl implements WildContainerItem { 8 | 9 | private final ItemStack handle; 10 | private final CraftItemStack craftItemStack; 11 | 12 | public WildContainerItemImpl(ItemStack nmsItemStack) { 13 | this(nmsItemStack, CraftItemStack.asCraftMirror(nmsItemStack)); 14 | } 15 | 16 | public WildContainerItemImpl(ItemStack handle, CraftItemStack craftItemStack) { 17 | this.handle = handle; 18 | this.craftItemStack = craftItemStack; 19 | } 20 | 21 | @Override 22 | public CraftItemStack getBukkitItem() { 23 | return craftItemStack; 24 | } 25 | 26 | public ItemStack getHandle() { 27 | return handle; 28 | } 29 | 30 | @Override 31 | public WildContainerItem copy() { 32 | return new WildContainerItemImpl(handle.cloneItemStack()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /NMS/v1_8_R3/src/main/java/com/bgsoftware/wildchests/nms/v1_8_R3/utils/NbtUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms.v1_8_R3.utils; 2 | 3 | import com.bgsoftware.common.reflection.ReflectConstructor; 4 | import com.bgsoftware.common.reflection.ReflectMethod; 5 | import net.minecraft.server.v1_8_R3.NBTBase; 6 | import net.minecraft.server.v1_8_R3.NBTReadLimiter; 7 | import net.minecraft.server.v1_8_R3.NBTTagCompound; 8 | import net.minecraft.server.v1_8_R3.NBTTagEnd; 9 | 10 | import java.io.DataInput; 11 | import java.io.IOException; 12 | 13 | /** 14 | * This class reimplements {@link net.minecraft.server.v1_8_R3.NBTCompressedStreamTools} without the CrashReport part. 15 | * For more information, see https://github.com/BG-Software-LLC/WildChests/issues/258 16 | */ 17 | public class NbtUtils { 18 | 19 | private static final ReflectMethod NBT_BASE_CREATE_TAG = new ReflectMethod<>( 20 | NBTBase.class, "createTag", byte.class); 21 | private static final ReflectMethod NBT_BASE_LOAD = new ReflectMethod<>( 22 | NBTBase.class, "load", DataInput.class, int.class, NBTReadLimiter.class); 23 | 24 | private static final NBTTagEnd TAG_END = (NBTTagEnd) new ReflectConstructor<>(NBTTagEnd.class).newInstance(); 25 | 26 | private NbtUtils() { 27 | 28 | } 29 | 30 | public static NBTTagCompound read(DataInput input) throws IOException { 31 | return read(input, NBTReadLimiter.a); 32 | } 33 | 34 | private static NBTTagCompound read(DataInput input, NBTReadLimiter tracker) throws IOException { 35 | NBTBase nbtBase = readUnnamedTag(input, tracker); 36 | 37 | if (nbtBase instanceof NBTTagCompound) { 38 | return (NBTTagCompound) nbtBase; 39 | } 40 | 41 | throw new IOException("Root tag must be a named compound tag"); 42 | } 43 | 44 | private static NBTBase readUnnamedTag(DataInput input, NBTReadLimiter tracker) throws IOException { 45 | byte firstByte = input.readByte(); 46 | 47 | if (firstByte == 0) { 48 | return TAG_END; 49 | } 50 | 51 | input.readUTF(); 52 | return readTag(input, tracker, firstByte); 53 | } 54 | 55 | private static NBTBase readTag(DataInput input, NBTReadLimiter tracker, byte typeId) throws IOException { 56 | NBTBase nbtBase = NBT_BASE_CREATE_TAG.invoke(null, typeId); 57 | NBT_BASE_LOAD.invoke(nbtBase, input, 0, tracker); 58 | return nbtBase; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Compiling settings 2 | # You can turn-off compiling of specific modules here by setting them to `false` 3 | nms.compile_v1_8=true 4 | nms.compile_v1_12=true 5 | nms.compile_v1_16=true 6 | nms.compile_v1_17=true 7 | nms.compile_v1_18=true 8 | nms.compile_v1_19=true 9 | nms.compile_v1_20=true 10 | nms.compile_v1_21=true 11 | hook.compile_chestshop=true 12 | hook.compile_cmi=true 13 | hook.compile_coreprotect=true 14 | hook.compile_folia=true 15 | hook.compile_economyshopgui=true 16 | hook.compile_essentials=true 17 | hook.compile_quantumshop=true 18 | hook.compile_rosestacker=true 19 | hook.compile_shopguiplus12=true 20 | hook.compile_shopguiplus14=true 21 | hook.compile_superiorskyblock=true 22 | hook.compile_transportpipes=true 23 | hook.compile_vault=true 24 | hook.compile_wildstacker=true 25 | hook.compile_zshop=true 26 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BG-Software-LLC/WildChests/a835febc3b664b2edb61197f2576def1bdd9cae0/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | maven { url "https://repo.papermc.io/repository/maven-public/" } 5 | } 6 | } 7 | 8 | rootProject.name = 'WildChests' 9 | 10 | include 'API' 11 | include 'Hooks' 12 | include 'Hooks:ChestShop' 13 | include 'Hooks:CoreProtect' 14 | include 'Hooks:Folia' 15 | include 'Hooks:RoseStacker' 16 | include 'Hooks:SuperiorSkyblock' 17 | include 'Hooks:TransportPipes' 18 | include 'Hooks:Vault' 19 | include 'Hooks:WildStacker' 20 | include 'NMS' 21 | include 'NMS:v1_8_R3' 22 | include 'NMS:v1_12_R1' 23 | include 'NMS:v1_16_R3' 24 | include 'NMS:v1_17' 25 | include 'NMS:v1_18' 26 | include 'NMS:v1_19' 27 | include 'NMS:v1_20_3' 28 | include 'NMS:v1_20_4' 29 | include 'NMS:v1_21' 30 | include 'NMS:v1_21_3' 31 | include 'NMS:v1_21_4' 32 | include 'NMS:v1_21_5' -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/command/ICommand.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.command; 2 | 3 | import org.bukkit.command.CommandSender; 4 | import com.bgsoftware.wildchests.WildChestsPlugin; 5 | 6 | import java.util.List; 7 | 8 | public interface ICommand { 9 | 10 | String getLabel(); 11 | 12 | String getUsage(); 13 | 14 | String getPermission(); 15 | 16 | String getDescription(); 17 | 18 | int getMinArgs(); 19 | 20 | int getMaxArgs(); 21 | 22 | void perform(WildChestsPlugin plugin, CommandSender sender, String[] args); 23 | 24 | List tabComplete(WildChestsPlugin plugin, CommandSender sender, String[] args); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/command/commands/CommandReload.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.command.commands; 2 | 3 | import com.bgsoftware.wildchests.Locale; 4 | import com.bgsoftware.wildchests.WildChestsPlugin; 5 | import com.bgsoftware.wildchests.command.ICommand; 6 | import com.bgsoftware.wildchests.handlers.SettingsHandler; 7 | import com.bgsoftware.wildchests.scheduler.Scheduler; 8 | import com.bgsoftware.wildchests.task.NotifierTask; 9 | import org.bukkit.command.CommandSender; 10 | 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public final class CommandReload implements ICommand { 15 | 16 | @Override 17 | public String getLabel() { 18 | return "reload"; 19 | } 20 | 21 | @Override 22 | public String getUsage() { 23 | return "chests reload"; 24 | } 25 | 26 | @Override 27 | public String getPermission() { 28 | return "wildchests.reload"; 29 | } 30 | 31 | @Override 32 | public String getDescription() { 33 | return "Reload the settings and the language files."; 34 | } 35 | 36 | @Override 37 | public int getMinArgs() { 38 | return 1; 39 | } 40 | 41 | @Override 42 | public int getMaxArgs() { 43 | return 1; 44 | } 45 | 46 | @Override 47 | public void perform(WildChestsPlugin plugin, CommandSender sender, String[] args) { 48 | Scheduler.runTaskAsync(() -> { 49 | SettingsHandler.reload(); 50 | Locale.reload(plugin); 51 | NotifierTask.start(); 52 | Locale.RELOAD_SUCCESS.send(sender); 53 | }); 54 | } 55 | 56 | @Override 57 | public List tabComplete(WildChestsPlugin plugin, CommandSender sender, String[] args) { 58 | return Collections.emptyList(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/command/commands/CommandSave.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.command.commands; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import com.bgsoftware.wildchests.command.ICommand; 5 | import com.bgsoftware.wildchests.scheduler.Scheduler; 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.command.CommandSender; 8 | 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | public final class CommandSave implements ICommand { 13 | 14 | @Override 15 | public String getLabel() { 16 | return "save"; 17 | } 18 | 19 | @Override 20 | public String getUsage() { 21 | return "chests save"; 22 | } 23 | 24 | @Override 25 | public String getPermission() { 26 | return "wildchests.save"; 27 | } 28 | 29 | @Override 30 | public String getDescription() { 31 | return "Save all cached data into files."; 32 | } 33 | 34 | @Override 35 | public int getMinArgs() { 36 | return 1; 37 | } 38 | 39 | @Override 40 | public int getMaxArgs() { 41 | return 1; 42 | } 43 | 44 | @Override 45 | public void perform(WildChestsPlugin plugin, CommandSender sender, String[] args) { 46 | Scheduler.runTaskAsync(() -> { 47 | plugin.getDataHandler().saveDatabase(null, false); 48 | sender.sendMessage(ChatColor.YELLOW + "Successfully saved all cached data."); 49 | }); 50 | } 51 | 52 | @Override 53 | public List tabComplete(WildChestsPlugin plugin, CommandSender sender, String[] args) { 54 | return Collections.emptyList(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/command/commands/CommandSettings.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.command.commands; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import com.bgsoftware.wildchests.command.ICommand; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | 9 | import java.util.Collections; 10 | import java.util.List; 11 | 12 | public final class CommandSettings implements ICommand { 13 | 14 | @Override 15 | public String getLabel() { 16 | return "settings"; 17 | } 18 | 19 | @Override 20 | public String getUsage() { 21 | return "chests settings"; 22 | } 23 | 24 | @Override 25 | public String getPermission() { 26 | return "wildchests.settings"; 27 | } 28 | 29 | @Override 30 | public String getDescription() { 31 | return "Open settings editor."; 32 | } 33 | 34 | @Override 35 | public int getMinArgs() { 36 | return 1; 37 | } 38 | 39 | @Override 40 | public int getMaxArgs() { 41 | return 1; 42 | } 43 | 44 | @Override 45 | public void perform(WildChestsPlugin plugin, CommandSender sender, String[] args) { 46 | if (!(sender instanceof Player)) { 47 | sender.sendMessage(ChatColor.RED + "Only players can perform this command."); 48 | return; 49 | } 50 | 51 | Player pl = (Player) sender; 52 | pl.sendMessage("Soon"); 53 | //TODO 54 | } 55 | 56 | @Override 57 | public List tabComplete(WildChestsPlugin plugin, CommandSender sender, String[] args) { 58 | return Collections.emptyList(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/database/DatabaseObject.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.database; 2 | 3 | import java.util.EnumMap; 4 | import java.util.Optional; 5 | 6 | public abstract class DatabaseObject { 7 | 8 | public static final DatabaseObject NULL_DATA = new DatabaseObject() { 9 | @Override 10 | public StatementHolder setUpdateStatement(StatementHolder statementHolder) { 11 | return null; 12 | } 13 | 14 | @Override 15 | public void executeUpdateStatement(boolean async) { 16 | 17 | } 18 | 19 | @Override 20 | public void executeInsertStatement(boolean async) { 21 | 22 | } 23 | 24 | @Override 25 | public void executeDeleteStatement(boolean async) { 26 | 27 | } 28 | }; 29 | 30 | private final EnumMap modifiedCalls = new EnumMap<>(Query.class); 31 | 32 | public abstract StatementHolder setUpdateStatement(StatementHolder statementHolder); 33 | 34 | public abstract void executeUpdateStatement(boolean async); 35 | 36 | public abstract void executeInsertStatement(boolean async); 37 | 38 | public abstract void executeDeleteStatement(boolean async); 39 | 40 | public void setModified(Query query){ 41 | modifiedCalls.put(query, modifiedCalls.getOrDefault(query, 0) + 1); 42 | } 43 | 44 | public void setUpdated(Query query){ 45 | Optional.of(modifiedCalls.get(query)).ifPresent(calls -> modifiedCalls.put(query, calls - 1)); 46 | } 47 | 48 | public boolean isModified(){ 49 | return !modifiedCalls.isEmpty(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/database/Query.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.database; 2 | 3 | public enum Query { 4 | 5 | REGULAR_CHEST_INSERT("REPLACE INTO chests(location, placer, chest_data, inventories) VALUES (?, ?, ?, ?)"), 6 | REGULAR_CHEST_DELETE("DELETE FROM chests WHERE location = ?"), 7 | REGULAR_CHEST_UPDATE_INVENTORIES("UPDATE chests SET inventories = ? WHERE location = ?"), 8 | 9 | STORAGE_UNIT_INSERT("REPLACE INTO storage_units(location, placer, chest_data, item, amount, max_amount) VALUES (?, ?, ?, ?, ?, ?)"), 10 | STORAGE_UNIT_DELETE("DELETE from storage_units WHERE location = ?"), 11 | STORAGE_UNIT_UPDATE_ITEM("UPDATE storage_units SET item = ?, amount = ? WHERE location = ?"), 12 | 13 | LINKED_CHEST_INSERT("REPLACE INTO linked_chests(location, placer, chest_data, inventories, linked_chest) VALUES (?, ?, ?, ?, ?)"), 14 | LINKED_CHEST_DELETE("DELETE from linked_chests WHERE location = ?"), 15 | LINKED_CHEST_UPDATE_INVENTORIES("UPDATE linked_chests SET inventories = ? WHERE location = ?"), 16 | LINKED_CHEST_UPDATE_LINKED_CHEST("UPDATE linked_chests SET linked_chest = ? WHERE location = ?"); 17 | 18 | private final String query; 19 | 20 | Query(String query) { 21 | this.query = query; 22 | } 23 | 24 | public String getStatement(){ 25 | return query; 26 | } 27 | 28 | public StatementHolder getStatementHolder(DatabaseObject databaseObject){ 29 | return new StatementHolder(databaseObject, this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/hooks/PricesProvider_Default.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.wildchests.api.hooks.PricesProvider; 4 | import org.bukkit.OfflinePlayer; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | import java.util.Map; 8 | import java.util.concurrent.ConcurrentHashMap; 9 | 10 | @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") 11 | public final class PricesProvider_Default implements PricesProvider { 12 | 13 | public static Map prices = new ConcurrentHashMap<>(); 14 | 15 | @Override 16 | public double getPrice(OfflinePlayer offlinePlayer, ItemStack itemStack) { 17 | //Checks for 'TYPE' item 18 | if(prices.containsKey(itemStack.getType().name())) 19 | return prices.get(itemStack.getType().name()) * itemStack.getAmount(); 20 | //Checks for 'TYPE:DATA' item 21 | if(prices.containsKey(itemStack.getType().name() + ":" + itemStack.getDurability())) 22 | return prices.get(itemStack.getType().name() + ":" + itemStack.getDurability()) * itemStack.getAmount(); 23 | //Couldn't find a price for this item 24 | return -1; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/hooks/PricesProvider_ShopsBridgeWrapper.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.common.shopsbridge.BulkTransaction; 4 | import com.bgsoftware.common.shopsbridge.IShopsBridge; 5 | import com.bgsoftware.common.shopsbridge.ShopsProvider; 6 | import com.bgsoftware.common.shopsbridge.Transaction; 7 | import com.bgsoftware.wildchests.WildChestsPlugin; 8 | import com.bgsoftware.wildchests.api.hooks.PricesProvider; 9 | import org.bukkit.OfflinePlayer; 10 | import org.bukkit.inventory.ItemStack; 11 | 12 | public class PricesProvider_ShopsBridgeWrapper implements PricesProvider { 13 | 14 | private final IShopsBridge shopsBridge; 15 | private BulkTransaction bulkTransaction; 16 | 17 | public PricesProvider_ShopsBridgeWrapper(ShopsProvider shopsProvider, IShopsBridge shopsBridge) { 18 | WildChestsPlugin.log(" - Using " + shopsProvider.getPluginName() + " as PricesProvider."); 19 | this.shopsBridge = shopsBridge; 20 | } 21 | 22 | @Override 23 | public double getPrice(OfflinePlayer offlinePlayer, ItemStack itemStack) { 24 | return getTransaction(offlinePlayer, itemStack).getPrice().doubleValue(); 25 | } 26 | 27 | public Transaction getTransaction(OfflinePlayer offlinePlayer, ItemStack itemStack) { 28 | return (this.bulkTransaction == null ? this.shopsBridge : this.bulkTransaction).getSellPrice(offlinePlayer, itemStack); 29 | } 30 | 31 | public void startBulkTransaction() { 32 | this.bulkTransaction = this.shopsBridge.startBulkTransaction(); 33 | } 34 | 35 | public void stopBulkTransaction() { 36 | this.bulkTransaction = null; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/hooks/StackerProviderType.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import javax.annotation.Nullable; 4 | import java.util.Optional; 5 | 6 | public enum StackerProviderType { 7 | 8 | WILDSTACKER, 9 | ROSESTACKER, 10 | AUTO; 11 | 12 | public static Optional fromName(@Nullable String name) { 13 | if (name != null) { 14 | try { 15 | return Optional.of(StackerProviderType.valueOf(name.toUpperCase())); 16 | } catch (IllegalArgumentException error) { 17 | } 18 | } 19 | 20 | return Optional.empty(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/hooks/StackerProvider_Default.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks; 2 | 3 | import com.bgsoftware.wildchests.api.hooks.StackerProvider; 4 | import org.bukkit.entity.Item; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | public final class StackerProvider_Default implements StackerProvider { 8 | 9 | @Override 10 | public int getItemAmount(Item item) { 11 | return item.getItemStack().getAmount(); 12 | } 13 | 14 | @Override 15 | public void setItemAmount(Item item, int amount) { 16 | ItemStack itemStack = item.getItemStack().clone(); 17 | itemStack.setAmount(amount); 18 | item.setItemStack(itemStack); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/hooks/listener/IChestBreakListener.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks.listener; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import org.bukkit.OfflinePlayer; 5 | 6 | import javax.annotation.Nullable; 7 | 8 | public interface IChestBreakListener { 9 | 10 | void breakChest(@Nullable OfflinePlayer offlinePlayer, Chest chest); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/hooks/listener/IChestPlaceListener.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.hooks.listener; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | 5 | public interface IChestPlaceListener { 6 | 7 | void placeChest(Chest chest); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/key/KeySet.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.key; 2 | 3 | import com.bgsoftware.wildchests.api.key.Key; 4 | import org.bukkit.Material; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | import java.util.AbstractSet; 8 | import java.util.Collections; 9 | import java.util.HashSet; 10 | import java.util.Iterator; 11 | import java.util.List; 12 | import java.util.Set; 13 | 14 | @SuppressWarnings("all") 15 | public class KeySet extends AbstractSet implements Set { 16 | 17 | private Set set; 18 | 19 | public KeySet() { 20 | this(Collections.emptyList()); 21 | } 22 | 23 | public KeySet(List keys) { 24 | this.set = new HashSet<>(keys); 25 | } 26 | 27 | @Override 28 | public Iterator iterator() { 29 | return asKeySet().iterator(); 30 | } 31 | 32 | @Override 33 | public int size() { 34 | return set.size(); 35 | } 36 | 37 | public boolean contains(ItemStack itemStack) { 38 | return contains(Key.of(itemStack)); 39 | } 40 | 41 | public boolean contains(Material material, short data) { 42 | return contains(Key.of(material, data)); 43 | } 44 | 45 | public boolean contains(String key) { 46 | return contains(Key.of(key)); 47 | } 48 | 49 | @Override 50 | public boolean contains(Object o) { 51 | if (o instanceof Key) { 52 | String key = o.toString(); 53 | if (set.contains(key)) 54 | return true; 55 | else if (key.contains(":") && set.contains(key.split(":")[0])) 56 | return true; 57 | else if (key.contains(";") && set.contains(key.split(";")[0])) 58 | return true; 59 | } 60 | return super.contains(o); 61 | } 62 | 63 | @Override 64 | public boolean add(Key key) { 65 | return set.add(key.toString()); 66 | } 67 | 68 | @Override 69 | public boolean remove(Object o) { 70 | return set.remove(o); 71 | } 72 | 73 | public Set asStringSet() { 74 | return new HashSet<>(set); 75 | } 76 | 77 | private Set asKeySet() { 78 | Set set = new HashSet<>(); 79 | this.set.forEach(string -> set.add(Key.of(string))); 80 | return set; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/listeners/ChunksListener.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.listeners; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import com.bgsoftware.wildchests.objects.chests.WChest; 5 | import com.bgsoftware.wildchests.scheduler.Scheduler; 6 | import org.bukkit.Chunk; 7 | import org.bukkit.Location; 8 | import org.bukkit.Material; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.world.ChunkLoadEvent; 13 | import org.bukkit.event.world.ChunkUnloadEvent; 14 | 15 | public final class ChunksListener implements Listener { 16 | 17 | private final WildChestsPlugin plugin; 18 | 19 | public ChunksListener(WildChestsPlugin plugin) { 20 | this.plugin = plugin; 21 | } 22 | 23 | @EventHandler(priority = EventPriority.LOWEST) 24 | public void onChunkLoad(ChunkLoadEvent e) { 25 | handleChunkLoad(plugin, e.getChunk()); 26 | } 27 | 28 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 29 | public void onChunkUnload(ChunkUnloadEvent e) { 30 | plugin.getDataHandler().saveDatabase(e.getChunk(), true); 31 | } 32 | 33 | public static void handleChunkLoad(WildChestsPlugin plugin, Chunk chunk) { 34 | plugin.getChestsManager().loadChestsForChunk(chunk); 35 | 36 | if(Scheduler.isRegionScheduler()) { 37 | Scheduler.runTask(chunk, () -> loadChestsForChunk(plugin, chunk)); 38 | } else { 39 | loadChestsForChunk(plugin, chunk); 40 | } 41 | } 42 | 43 | private static void loadChestsForChunk(WildChestsPlugin plugin, Chunk chunk) { 44 | plugin.getChestsManager().getChests(chunk).forEach(chest -> { 45 | Location location = chest.getLocation(); 46 | Material blockType = location.getBlock().getType(); 47 | if (blockType != Material.CHEST) { 48 | WildChestsPlugin.log("Loading chunk " + chunk.getX() + ", " + chunk.getX() + " but found a chest not " + 49 | "associated with a chest block but " + blockType + " at " + location.getWorld().getName() + ", " + 50 | location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ()); 51 | chest.remove(); 52 | } else { 53 | ((WChest) chest).onChunkLoad(); 54 | } 55 | }); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/listeners/PlayerListener.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.listeners; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import com.bgsoftware.wildchests.scheduler.Scheduler; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.player.PlayerJoinEvent; 9 | 10 | @SuppressWarnings("unused") 11 | public final class PlayerListener implements Listener { 12 | 13 | private final WildChestsPlugin plugin; 14 | 15 | public PlayerListener(WildChestsPlugin plugin){ 16 | this.plugin = plugin; 17 | } 18 | 19 | /* 20 | Just notifies me if the server is using WildBuster 21 | */ 22 | 23 | @EventHandler 24 | public void onPlayerJoin(PlayerJoinEvent e){ 25 | if(e.getPlayer().getUniqueId().toString().equals("45713654-41bf-45a1-aa6f-00fe6598703b")){ 26 | Scheduler.runTask(e.getPlayer(), () -> 27 | e.getPlayer().sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.WHITE + "WildSeries" + ChatColor.DARK_GRAY + "] " + 28 | ChatColor.GRAY + "This server is using WildChests v" + plugin.getDescription().getVersion()), 5L); 29 | } 30 | 31 | if(e.getPlayer().isOp() && plugin.getUpdater().isOutdated()){ 32 | Scheduler.runTask(e.getPlayer(), () -> 33 | e.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "WildChests" + 34 | ChatColor.GRAY + " A new version is available (v" + plugin.getUpdater().getLatestVersion() + ")!"), 20L); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/nms/NMSAdapter.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms; 2 | 3 | import com.bgsoftware.wildchests.api.objects.ChestType; 4 | import com.bgsoftware.wildchests.objects.inventory.InventoryHolder; 5 | import org.bukkit.Location; 6 | import org.bukkit.entity.HumanEntity; 7 | import org.bukkit.inventory.Inventory; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | public interface NMSAdapter { 13 | 14 | String serialize(ItemStack itemStack); 15 | 16 | String serialize(Inventory[] inventories); 17 | 18 | InventoryHolder[] deserialze(String serialized); 19 | 20 | ItemStack deserialzeItem(String serialized); 21 | 22 | void playChestAction(Location location, boolean open); 23 | 24 | ItemStack setChestType(ItemStack itemStack, ChestType chestType); 25 | 26 | ItemStack setChestName(ItemStack itemStack, String chestName); 27 | 28 | @Nullable 29 | String getChestName(ItemStack itemStack); 30 | 31 | void dropItemAsPlayer(HumanEntity humanEntity, ItemStack bukkitItem); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/nms/NMSInventory.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.nms; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import com.bgsoftware.wildchests.objects.inventory.CraftWildInventory; 5 | import com.bgsoftware.wildchests.objects.inventory.WildContainerItem; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | public interface NMSInventory { 10 | 11 | void updateTileEntity(Chest chest); 12 | 13 | void removeTileEntity(Chest chest); 14 | 15 | WildContainerItem createItemStack(ItemStack itemStack); 16 | 17 | CraftWildInventory createInventory(Chest chest, int size, String title, int index); 18 | 19 | void openPage(Player player, CraftWildInventory inventory); 20 | 21 | void createDesignItem(CraftWildInventory inventory, ItemStack itemStack); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/objects/Materials.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.objects; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.inventory.ItemStack; 5 | 6 | public enum Materials { 7 | 8 | GREEN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", 13), 9 | RED_STAINED_GLASS_PANE("STAINED_GLASS_PANE", 14), 10 | BLACK_STAINED_GLASS_PANE("STAINED_GLASS_PANE", 15); 11 | 12 | Materials(String legacyType, int legacyData){ 13 | this.legacyType = legacyType; 14 | this.legacyData = (byte) legacyData; 15 | } 16 | 17 | private String legacyType; 18 | private byte legacyData; 19 | 20 | private static boolean isLegacy = isLegacy(); 21 | 22 | public ItemStack toBukkitItem(){ 23 | return !isLegacy ? new ItemStack(Material.matchMaterial(name())) : new ItemStack(Material.matchMaterial(legacyType), 1, legacyData); 24 | } 25 | 26 | private static boolean isLegacy(){ 27 | try{ 28 | Material.valueOf("STAINED_GLASS_PANE"); 29 | return true; 30 | }catch(Throwable ignored){ 31 | return false; 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/objects/containers/TileEntityContainer.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.objects.containers; 2 | 3 | import org.bukkit.entity.HumanEntity; 4 | 5 | import java.util.List; 6 | 7 | public interface TileEntityContainer { 8 | 9 | int getViewingCount(); 10 | 11 | List getTransaction(); 12 | 13 | void updateData(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/objects/data/WInventoryData.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.objects.data; 2 | 3 | import org.bukkit.ChatColor; 4 | import com.bgsoftware.wildchests.api.objects.data.InventoryData; 5 | 6 | public class WInventoryData implements InventoryData { 7 | 8 | private String title; 9 | private double price; 10 | 11 | public WInventoryData(String title, double price){ 12 | this.title = ChatColor.translateAlternateColorCodes('&', title); 13 | this.price = price; 14 | } 15 | 16 | @Override 17 | public String getTitle() { 18 | return title; 19 | } 20 | 21 | @Override 22 | public double getPrice() { 23 | return price; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/objects/inventory/CraftWildInventory.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.objects.inventory; 2 | 3 | import com.bgsoftware.wildchests.api.objects.chests.Chest; 4 | import org.bukkit.inventory.Inventory; 5 | 6 | import java.util.List; 7 | 8 | public interface CraftWildInventory extends Inventory { 9 | 10 | Chest getOwner(); 11 | 12 | WildContainerItem getWildItem(int slot); 13 | 14 | void setItem(int i, WildContainerItem itemStack); 15 | 16 | List getWildContents(); 17 | 18 | void setTitle(String title); 19 | 20 | String getTitle(); 21 | 22 | boolean isFull(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/objects/inventory/InventoryHolder.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.objects.inventory; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | public final class InventoryHolder { 6 | 7 | private final String title; 8 | private final ItemStack[] contents; 9 | 10 | public InventoryHolder(int size, String title){ 11 | this(title, new ItemStack[size]); 12 | } 13 | 14 | public InventoryHolder(String title, ItemStack[] contents){ 15 | this.title = title == null ? "Chest" : title; 16 | this.contents = contents; 17 | } 18 | 19 | public ItemStack[] getContents() { 20 | return contents; 21 | } 22 | 23 | public int getSize(){ 24 | return contents.length; 25 | } 26 | 27 | public String getTitle() { 28 | return title; 29 | } 30 | 31 | public void setItem(int slot, ItemStack itemStack){ 32 | contents[slot] = itemStack; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/objects/inventory/WildContainerItem.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.objects.inventory; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import org.bukkit.Material; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | public interface WildContainerItem { 8 | 9 | WildContainerItem AIR = WildChestsPlugin.getPlugin().getNMSInventory().createItemStack(new ItemStack(Material.AIR)); 10 | 11 | ItemStack getBukkitItem(); 12 | 13 | WildContainerItem copy(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/scheduler/ISchedulerImplementation.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.scheduler; 2 | 3 | import org.bukkit.World; 4 | import org.bukkit.entity.Entity; 5 | 6 | public interface ISchedulerImplementation { 7 | 8 | boolean isRegionScheduler(); 9 | 10 | void cancelTasks(); 11 | 12 | ScheduledTask scheduleTask(World world, int chunkX, int chunkZ, Runnable task, long delay); 13 | 14 | ScheduledTask scheduleTask(Entity entity, Runnable task, long delay); 15 | 16 | ScheduledTask scheduleTask(Runnable task, long delay); 17 | 18 | ScheduledTask scheduleAsyncTask(Runnable task, long delay); 19 | 20 | ScheduledTask scheduleRepeatingAsyncTask(Runnable task, long delay); 21 | 22 | boolean isScheduledForRegion(World world, int chunkX, int chunkZ); 23 | 24 | boolean isScheduledForRegion(Entity entity); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/scheduler/ScheduledTask.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.scheduler; 2 | 3 | public interface ScheduledTask { 4 | 5 | void cancel(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/task/CraftingDetails.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.task; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | public class CraftingDetails { 6 | 7 | private final ItemStack itemStack; 8 | private int amount; 9 | 10 | public CraftingDetails(ItemStack itemStack, int amount) { 11 | this.itemStack = itemStack; 12 | this.amount = amount; 13 | } 14 | 15 | public ItemStack getItemStack() { 16 | return itemStack; 17 | } 18 | 19 | public int getAmount() { 20 | return amount; 21 | } 22 | 23 | public void increaseAmount(int amount) { 24 | this.amount += amount; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/task/TransactionDetails.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.task; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public class TransactionDetails { 8 | 9 | private final ItemStack itemStack; 10 | private int amount; 11 | private BigDecimal amountEarned; 12 | 13 | public TransactionDetails(ItemStack itemStack, int amount, BigDecimal amountEarned) { 14 | this.itemStack = itemStack; 15 | this.amount = amount; 16 | this.amountEarned = amountEarned; 17 | } 18 | 19 | public ItemStack getItemStack() { 20 | return itemStack; 21 | } 22 | 23 | public int getAmount() { 24 | return amount; 25 | } 26 | 27 | public BigDecimal getEarnings() { 28 | return amountEarned; 29 | } 30 | 31 | public void increaseAmount(int amount) { 32 | this.amount += amount; 33 | } 34 | 35 | public void increaseEarnings(BigDecimal balance) { 36 | amountEarned = amountEarned.add(balance); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/BlockPosition.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import org.bukkit.Location; 4 | 5 | import java.util.Objects; 6 | 7 | public class BlockPosition { 8 | 9 | private final String worldName; 10 | private final int x; 11 | private final int y; 12 | private final int z; 13 | 14 | public static BlockPosition deserialize(String serialized) { 15 | String[] sections = serialized.split(", "); 16 | return new BlockPosition(sections[0], Integer.parseInt(sections[1]), 17 | Integer.parseInt(sections[2]), Integer.parseInt(sections[3])); 18 | } 19 | 20 | public static BlockPosition of(Location location) { 21 | return new BlockPosition(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); 22 | } 23 | 24 | public BlockPosition(String worldName, int x, int y, int z) { 25 | this.worldName = worldName; 26 | this.x = x; 27 | this.y = y; 28 | this.z = z; 29 | } 30 | 31 | public String getWorldName() { 32 | return worldName; 33 | } 34 | 35 | public int getX() { 36 | return x; 37 | } 38 | 39 | public int getY() { 40 | return y; 41 | } 42 | 43 | public int getZ() { 44 | return z; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object o) { 49 | if (this == o) return true; 50 | if (o == null || getClass() != o.getClass()) return false; 51 | BlockPosition that = (BlockPosition) o; 52 | return x == that.x && y == that.y && z == that.z && Objects.equals(worldName, that.worldName); 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return Objects.hash(worldName, x, y, z); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/ChunkPosition.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import org.bukkit.Chunk; 4 | import org.bukkit.Location; 5 | 6 | import java.util.Objects; 7 | 8 | public final class ChunkPosition { 9 | 10 | private final String world; 11 | private final int x, z; 12 | 13 | private ChunkPosition(String world, int x, int z){ 14 | this.world = world; 15 | this.x = x; 16 | this.z = z; 17 | } 18 | 19 | public int getX() { 20 | return x; 21 | } 22 | 23 | public int getZ() { 24 | return z; 25 | } 26 | 27 | @Override 28 | public boolean equals(Object o) { 29 | if (this == o) return true; 30 | if (o == null || getClass() != o.getClass()) return false; 31 | ChunkPosition that = (ChunkPosition) o; 32 | return x == that.x && 33 | z == that.z && 34 | world.equals(that.world); 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(world, x, z); 40 | } 41 | 42 | public static ChunkPosition of(Chunk chunk){ 43 | return new ChunkPosition(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); 44 | } 45 | 46 | public static ChunkPosition of(Location location){ 47 | return new ChunkPosition(location.getWorld().getName(), location.getBlockX() >> 4, location.getBlockZ() >> 4); 48 | } 49 | 50 | public static ChunkPosition of(BlockPosition blockPosition){ 51 | return new ChunkPosition(blockPosition.getWorldName(), blockPosition.getX() >> 4, blockPosition.getZ() >> 4); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/Counter.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | public class Counter { 4 | 5 | private long value = 0; 6 | 7 | public Counter() { 8 | 9 | } 10 | 11 | public void increase(int delta) { 12 | this.value += delta; 13 | } 14 | 15 | public long get() { 16 | return value; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/DatabaseThread.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import com.bgsoftware.wildchests.WildChestsPlugin; 4 | import com.google.common.util.concurrent.ThreadFactoryBuilder; 5 | 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | public final class DatabaseThread { 11 | private static final ExecutorService databaseExecutor = Executors.newFixedThreadPool(3, 12 | new ThreadFactoryBuilder().setNameFormat("WildChests Database Thread %d").build()); 13 | 14 | private static boolean shutdown = false; 15 | 16 | public static boolean isDataThread() { 17 | return Thread.currentThread().getName().contains("WildChests Database Thread"); 18 | } 19 | 20 | public static void schedule(Runnable runnable) { 21 | if (shutdown) 22 | return; 23 | 24 | databaseExecutor.execute(runnable); 25 | } 26 | 27 | public static void stop() { 28 | try { 29 | shutdown = true; 30 | WildChestsPlugin.log("Shutting down database executor"); 31 | shutdownAndAwaitTermination(); 32 | } catch (Exception ex) { 33 | ex.printStackTrace(); 34 | } 35 | } 36 | 37 | private static void shutdownAndAwaitTermination() { 38 | databaseExecutor.shutdown(); // Disable new tasks from being submitted 39 | try { 40 | // Wait a while for existing tasks to terminate 41 | if (!databaseExecutor.awaitTermination(60, TimeUnit.SECONDS)) { 42 | databaseExecutor.shutdownNow(); // Cancel currently executing tasks 43 | // Wait a while for tasks to respond to being cancelled 44 | if (!databaseExecutor.awaitTermination(60, TimeUnit.SECONDS)) 45 | WildChestsPlugin.log("Pool did not terminate"); 46 | } 47 | } catch (InterruptedException ie) { 48 | // (Re-)Cancel if current thread also interrupted 49 | databaseExecutor.shutdownNow(); 50 | // Preserve interrupt status 51 | Thread.currentThread().interrupt(); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/ItemStackMap.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | import javax.annotation.Nullable; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.function.BiConsumer; 9 | import java.util.function.Function; 10 | 11 | public class ItemStackMap { 12 | 13 | private final Map backendData = new HashMap<>(); 14 | 15 | @Nullable 16 | public V put(ItemStack key, V value) { 17 | return this.backendData.put(getKeyFromItemStack(key), value); 18 | } 19 | 20 | @Nullable 21 | public V get(ItemStack key) { 22 | return this.backendData.get(getKeyFromItemStack(key)); 23 | } 24 | 25 | public V computeIfAbsent(ItemStack key, Function mapper) { 26 | return this.backendData.computeIfAbsent(getKeyFromItemStack(key), mapper); 27 | } 28 | 29 | public void forEach(BiConsumer consumer) { 30 | this.backendData.forEach(consumer); 31 | } 32 | 33 | private static ItemStack getKeyFromItemStack(ItemStack itemStack) { 34 | ItemStack key = itemStack.clone(); 35 | key.setAmount(1); 36 | return key; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/LinkedChestInteractEvent.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import org.bukkit.block.Block; 4 | import org.bukkit.block.BlockFace; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.block.Action; 7 | import org.bukkit.event.player.PlayerInteractEvent; 8 | 9 | public final class LinkedChestInteractEvent extends PlayerInteractEvent { 10 | 11 | public LinkedChestInteractEvent(Player player, Block block){ 12 | super(player, Action.RIGHT_CLICK_BLOCK, player.getItemInHand(), block, BlockFace.UP); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/LocationUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.Location; 5 | 6 | import javax.annotation.Nullable; 7 | 8 | public final class LocationUtils { 9 | 10 | public static boolean isInRange(Location loc1, Location loc2, int range) { 11 | return Math.abs(loc1.getBlockX() - loc2.getBlockX()) <= range && 12 | Math.abs(loc1.getBlockY() - loc2.getBlockY()) <= range && 13 | Math.abs(loc1.getBlockZ() - loc2.getBlockZ()) <= range; 14 | } 15 | 16 | public static boolean isSameChunk(Location loc1, Location loc2) { 17 | return loc1.getBlockX() >> 4 == loc2.getBlockX() >> 4 && loc1.getBlockZ() >> 4 == loc2.getBlockZ() >> 4; 18 | } 19 | 20 | @Nullable 21 | public static Location fromString(@Nullable String str, boolean allowInvalidLocations) { 22 | if (str == null || str.isEmpty()) { 23 | if (allowInvalidLocations) 24 | return null; 25 | 26 | throw new IllegalArgumentException("Couldn't convert string '" + str + "' into a location."); 27 | } 28 | 29 | String[] sections = str.split(", "); 30 | 31 | if (sections.length == 4) { 32 | return new Location( 33 | Bukkit.getWorld(sections[0]), 34 | Integer.parseInt(sections[1]), 35 | Integer.parseInt(sections[2]), 36 | Integer.parseInt(sections[3]) 37 | ); 38 | } 39 | 40 | throw new IllegalArgumentException("Couldn't convert string '" + str + "' into a location."); 41 | } 42 | 43 | public static String toString(Location location) { 44 | return location.getWorld().getName() + ", " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/Pair.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | public final class Pair { 4 | 5 | public K key; 6 | public V value; 7 | 8 | public Pair(K key, V value){ 9 | this.key = key; 10 | this.value = value; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return "Pair{" + key + ", " + value + "}"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/ServerVersion.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import org.bukkit.Bukkit; 4 | 5 | public enum ServerVersion { 6 | 7 | v1_7(17), 8 | v1_8(18), 9 | v1_9(19), 10 | v1_10(110), 11 | v1_11(111), 12 | v1_12(112), 13 | v1_13(113), 14 | v1_14(114), 15 | v1_15(115), 16 | v1_16(116), 17 | v1_17(117), 18 | v1_18(118), 19 | v1_19(119), 20 | v1_20(120); 21 | 22 | private static final ServerVersion currentVersion; 23 | private static final String bukkitVersion; 24 | private static final boolean legacy; 25 | 26 | static { 27 | bukkitVersion = Bukkit.getBukkitVersion().split("-")[0]; 28 | String[] sections = bukkitVersion.split("\\."); 29 | currentVersion = ServerVersion.valueOf("v" + sections[0] + "_" + sections[1]); 30 | legacy = isLessThan(ServerVersion.v1_13); 31 | } 32 | 33 | private final int code; 34 | 35 | ServerVersion(int code) { 36 | this.code = code; 37 | } 38 | 39 | 40 | public static boolean isAtLeast(ServerVersion serverVersion) { 41 | return currentVersion.code >= serverVersion.code; 42 | } 43 | 44 | public static boolean isLessThan(ServerVersion serverVersion) { 45 | return currentVersion.code < serverVersion.code; 46 | } 47 | 48 | public static boolean isEquals(ServerVersion serverVersion) { 49 | return currentVersion.code == serverVersion.code; 50 | } 51 | 52 | public static boolean isLegacy() { 53 | return legacy; 54 | } 55 | 56 | public static String getBukkitVersion() { 57 | return bukkitVersion; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import com.bgsoftware.wildchests.Locale; 4 | 5 | import java.math.BigDecimal; 6 | import java.math.RoundingMode; 7 | import java.text.DecimalFormat; 8 | 9 | public final class StringUtils { 10 | 11 | private static final DecimalFormat numberFormatter = new DecimalFormat("###,###,###,###,###,###,###,###,###,##0.00"); 12 | private static final BigDecimal K = BigDecimal.valueOf(1000), M = K.multiply(K), B = M.multiply(K), 13 | T = B.multiply(K), Q = T.multiply(K); 14 | 15 | public static String format(BigDecimal bigDecimal) { 16 | String s = numberFormatter.format(Double.parseDouble(bigDecimal.toString())); 17 | return s.endsWith(".00") ? s.replace(".00", "") : s; 18 | } 19 | 20 | public static String fancyFormat(BigDecimal bigDecimal) { 21 | if (bigDecimal.compareTo(Q) >= 0) 22 | return format(bigDecimal.divide(Q, 2, RoundingMode.HALF_UP)) + Locale.FORMAT_QUAD.getMessage(); 23 | 24 | if (bigDecimal.compareTo(T) >= 0) 25 | return format(bigDecimal.divide(T, 2, RoundingMode.HALF_UP)) + Locale.FORMAT_TRILLION.getMessage(); 26 | 27 | if (bigDecimal.compareTo(B) >= 0) 28 | return format(bigDecimal.divide(B, 2, RoundingMode.HALF_UP)) + Locale.FORMAT_BILLION.getMessage(); 29 | 30 | if (bigDecimal.compareTo(M) >= 0) 31 | return format(bigDecimal.divide(M, 2, RoundingMode.HALF_UP)) + Locale.FORMAT_MILLION.getMessage(); 32 | 33 | if (bigDecimal.compareTo(K) >= 0) 34 | return format(bigDecimal.divide(K, 2, RoundingMode.HALF_UP)) + Locale.FORMAT_THOUSANDS.getMessage(); 35 | 36 | return format(bigDecimal); 37 | } 38 | 39 | public static String format(String format) { 40 | String[] words = format.split(" "); 41 | String[] formattedWords = new String[words.length]; 42 | 43 | for (int i = 0; i < words.length; ++i) { 44 | String curr = words[i]; 45 | formattedWords[i] = Character.toUpperCase(curr.charAt(0)) + curr.substring(1).toLowerCase(java.util.Locale.ENGLISH); 46 | } 47 | 48 | return String.join(" ", formattedWords); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/bgsoftware/wildchests/utils/SyncedArray.java: -------------------------------------------------------------------------------- 1 | package com.bgsoftware.wildchests.utils; 2 | 3 | import java.util.Arrays; 4 | import java.util.stream.Stream; 5 | 6 | public final class SyncedArray { 7 | 8 | private Object[] arr; 9 | 10 | public SyncedArray(int length){ 11 | arr = new Object[length]; 12 | } 13 | 14 | public void set(int index, E element){ 15 | arr[index] = element; 16 | } 17 | 18 | public E get(int index){ 19 | //noinspection all 20 | return (E) arr[index]; 21 | } 22 | 23 | public int length(){ 24 | return arr.length; 25 | } 26 | 27 | public Stream stream(){ 28 | //noinspection all 29 | return Arrays.stream(arr).map(e -> (E) e); 30 | } 31 | 32 | public void increaseCapacity(int newSize){ 33 | if(newSize > length()) 34 | arr = Arrays.copyOf(arr, newSize); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: WildChests 2 | version: ${project.version} 3 | main: com.bgsoftware.wildchests.WildChestsPlugin 4 | 5 | description: Sell wildchests, auto-crafters, pouches and more in one plugin! 6 | website: https://bg-software.com/ 7 | api-version: 1.13 8 | author: Ome_R 9 | folia-supported: true 10 | 11 | # Custom section used by DependenciesManager, which replaces softdepend. 12 | class-depends: 13 | - ChestShop 14 | - EconomyShopGUI 15 | - EconomyShopGUI-Premium 16 | - Essentials 17 | - QuantumShop 18 | - ShopGUIPlus 19 | - SuperiorSkyblock2 20 | 21 | commands: 22 | chests: 23 | description: Main command for the plugin 24 | 25 | permissions: 26 | wildchests.*: 27 | description: Gives access to all the commands 28 | default: op 29 | children: 30 | wildchests.give: true 31 | wildchests.info: true 32 | wildchests.link: true 33 | wildchests.reload: true 34 | wildchests.save: true 35 | wildchests.settings: true 36 | wildchests.give: 37 | description: Gives access to give chests to other players. 38 | wildchests.info: 39 | description: Gives access to see information about a chest. 40 | wildchests.link: 41 | description: Gives access to link linked chests into other chests. 42 | wildchests.reload: 43 | description: Gives access to reload all configuration files. 44 | wildchests.save: 45 | description: Gives access to save database into files. 46 | wildchests.settings: 47 | description: Gives access to use settings editor. --------------------------------------------------------------------------------