├── resources ├── img │ ├── PiggyCrates.gif │ └── PiggyCrates.png ├── config.yml ├── messages.yml └── crates.yml ├── .github ├── ISSUE_TEMPLATE │ ├── support.md │ ├── outdated_api.md │ ├── suggestion.md │ ├── crash.md │ └── bug_report.md ├── CONTRIBUTING.md ├── workflows │ └── main.yml └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitattributes ├── phpstan.neon.dist ├── .poggit.yml ├── plugin.yml ├── src └── DaPigGuy │ └── PiggyCrates │ ├── crates │ ├── CrateItem.php │ └── Crate.php │ ├── utils │ └── Utils.php │ ├── commands │ ├── KeyAllCommand.php │ ├── CrateCommand.php │ └── KeyCommand.php │ ├── EventListener.php │ ├── tasks │ └── RouletteTask.php │ ├── PiggyCrates.php │ └── tiles │ └── CrateTile.php ├── README.md └── LICENSE /resources/img/PiggyCrates.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaPigGuy/PiggyCrates/HEAD/resources/img/PiggyCrates.gif -------------------------------------------------------------------------------- /resources/img/PiggyCrates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaPigGuy/PiggyCrates/HEAD/resources/img/PiggyCrates.png -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support 3 | about: Please do not create an issue for this. Join our Discord for support (link in README). 4 | title: '' 5 | labels: 'Resolution: Invalid' 6 | assignees: '' 7 | 8 | --- 9 | Please do not create an issue for this. Join our Discord for support (link in README). -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/outdated_api.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Outdated API Version 3 | about: Please do not create an issue for this. The plugin will be updated to the latest PMMP version as soon as possible. 4 | title: 'Outdated API Version' 5 | labels: 'Resolution: Invalid' 6 | assignees: '' 7 | --- 8 | 9 | Please do not create an issue. Doing so will only delay an update. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # JetBrains IDE 21 | \.idea 22 | 23 | # Floobits 24 | \.floo -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | parameters: 2 | paths: 3 | - /source/src 4 | level: 8 5 | bootstrapFiles: 6 | - phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php 7 | scanDirectories: 8 | - /source/src 9 | - phar:///deps/PiggyCustomEnchants.phar/src/ 10 | - phar:///source/vendor/Commando.phar/src/ 11 | - phar:///source/vendor/InvMenu.phar/src/ 12 | - phar:///source/vendor/libPiggyUpdateChecker.phar/src/ 13 | excludePaths: 14 | analyse: 15 | - source/vendor 16 | checkMissingIterableValueType: false -------------------------------------------------------------------------------- /resources/config.yml: -------------------------------------------------------------------------------- 1 | keys: 2 | id: 131 3 | meta: 0 4 | name: "{CRATE} Key" 5 | lore: "Claim rewards from a {CRATE} Crate" 6 | crates: 7 | # Options: instant, roulette 8 | mode: roulette 9 | roulette: 10 | # Minimum duration: (duration/speed) >= 5.5 11 | # If (duration/speed) ends up being less than 5.5, then your default time will be set to (6*speed) 12 | duration: 30 13 | # Minimum speed: speed >= 1 14 | # If speed ends up being less than 1, then your default speed will be set to 1. 15 | speed: 2 16 | -------------------------------------------------------------------------------- /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/DaPigGuy/PiggyCrates 2 | branches: 3 | - master 4 | projects: 5 | PiggyCrates: 6 | path: "" 7 | icon: "resources/img/PiggyCrates.gif" 8 | libs: 9 | - src: Paroxity/Commando/Commando 10 | version: ^3.0.0 11 | - src: muqsit/InvMenu/InvMenu 12 | version: ^4.4.1 13 | branch: "4.0" 14 | - src: DaPigGuy/libPiggyUpdateChecker/libPiggyUpdateChecker 15 | version: ^1.0.0 16 | lint: 17 | phpstan: false 18 | ... 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggestion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Suggestion 3 | about: Suggest features you would like added to PiggyCrates 4 | title: '' 5 | labels: 'Type: Enhancement' 6 | assignees: 'DaPigGuy' 7 | --- 8 | 9 | 10 | Please make sure your issue complies with these guidelines: 11 | - * [ ] Idea must have not been suggested previously 12 | - * [ ] Be detailed on what you want & make sure the idea is plausible 13 | 14 | ### Description 15 | 16 | 17 | ### Extra Information -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # PiggyCrates 2 | 3 | ## Contribution Guidelines 4 | 5 | ### Issues 6 | If you are submitting an issue ticket, you must: 7 | * Must be PMMP w/o vanilla patching plugins (i.e. TeaSpoon) 8 | * Issue must have not been reported previously 9 | * Must be on latest version of PMMP & PiggyCrates 10 | * Have a detailed title. 11 | * If possible, provide crashdumps/errors related to the issue. 12 | 13 | ### Pull Requests 14 | If you are submitting a pull request, you must: 15 | * Use same formatting 16 | * Changes must have been tested on PMMP. 17 | * Unless it is a minor code modification, you must use an IDE. 18 | * Have a detailed title, like "Fix Crate items don't appear in inventory" 19 | 20 | Last updated: Sunday, March 15, 2020. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/crash.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Crash 3 | about: Report a crash in PiggyCrates 4 | title: '' 5 | labels: 'Type: Bug' 6 | assignees: 'DaPigGuy' 7 | --- 8 | 9 | 10 | Please make sure your issue complies with these guidelines: 11 | - * [ ] Server Software must be the official PMMP w/o vanilla patching plugins (i.e. TeaSpoon) 12 | - * [ ] Issue must have not been reported previously 13 | - * [ ] Make sure you are on the latest version of PMMP & PiggyCrates 14 | - * [ ] Have a detailed title. 15 | 16 | 17 | Link to Crashdump: 18 | 19 | 20 | ### Extra Information -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | name: PiggyCrates 2 | main: DaPigGuy\PiggyCrates\PiggyCrates 3 | version: 3.0.4 4 | api: 4.0.0 5 | load: POSTWORLD 6 | author: DaPigGuy 7 | softdepend: ["PiggyCustomEnchants"] 8 | website: "https://github.com/DaPigGuy/PiggyCrates/" 9 | permissions: 10 | piggycrates: 11 | default: false 12 | description: "Allows usage of all PiggyCrates features" 13 | piggycrates.command: 14 | default: op 15 | description: "Allow usage of all PiggyCrates commands" 16 | piggycrates.command.crate: 17 | default: op 18 | description: "Allow usage of the /crate command" 19 | piggycrates.command.key: 20 | default: op 21 | description: "Allow usage of the /key command" 22 | piggycrates.command.keyall: 23 | default: op 24 | description: "Allow usage of the /keyall command" 25 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: PHPStan 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | phpstan: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | with: 11 | ref: ${{ github.ref }} 12 | - name: Create Vendor Directory 13 | run: mkdir vendor 14 | - name: Download Virion Dependencies 15 | run: | 16 | wget -O vendor/Commando.phar https://poggit.pmmp.io/r/162923/Commando_dev-30.phar 17 | wget -O vendor/InvMenu.phar https://poggit.pmmp.io/r/186359/InvMenu_dev-179.phar 18 | wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/163495/libPiggyUpdateChecker_dev-1.phar 19 | - name: Run PHPStan 20 | uses: paroxity/pmmp-phpstan-action@4.2.0 21 | with: 22 | phpstan-config: phpstan.neon.dist 23 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | Please make sure your issue complies with these guidelines: 3 | - * [ ] Use same formatting 4 | - * [ ] Changes must have been tested on PMMP. 5 | - * [ ] Unless it is a minor code modification, you must use an IDE. 6 | - * [ ] Have a detailed title. 7 | 8 | ### What does the PR change? 9 | 14 | 15 | ### Testing Environment 16 | 17 | * PocketMine-MP: 18 | * PHP: 19 | * Server OS: 20 | 21 | 22 | ### Extra Information 23 | -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/crates/CrateItem.php: -------------------------------------------------------------------------------- 1 | item; 21 | } 22 | 23 | public function getType(): string 24 | { 25 | return $this->type; 26 | } 27 | 28 | /** 29 | * @return string[] 30 | */ 31 | public function getCommands(): array 32 | { 33 | return $this->commands; 34 | } 35 | 36 | public function getChance(): int 37 | { 38 | return $this->chance; 39 | } 40 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Unexpected non-crash behavior with PiggyCrates 4 | title: '' 5 | labels: 'Type: Bug' 6 | assignees: 'DaPigGuy' 7 | --- 8 | 9 | 10 | Please make sure your issue complies with these guidelines: 11 | - * [ ] Server Software must be the official PMMP w/o vanilla patching plugins (i.e. TeaSpoon) 12 | - * [ ] Issue must have not been reported previously 13 | - * [ ] Make sure you are on the latest version of PMMP & PiggyCrates 14 | - * [ ] Have a detailed title. 15 | 16 | ### Issue Description 17 | 18 | - Expected result: What were you expecting to happen? 19 | - Actual result: What actually happened? 20 | 21 | #### Steps to Reproduce the Issue 22 | 1. ... 23 | 2. ... 24 | 25 | ### OS and Versions 26 | 27 | * PocketMine-MP: 28 | * PiggyCrates: 29 | * PHP: 30 | * Server OS: 31 | 32 | 33 | ### Extra Information -------------------------------------------------------------------------------- /resources/messages.yml: -------------------------------------------------------------------------------- 1 | commands: 2 | use-in-game: "{RED}Please use this in-game." 3 | crate: 4 | error: 5 | invalid-crate: "{RED}Invalid crate." 6 | success: "{GREEN}Please tap a chest block to create a crate, or use /crate cancel to cancel." 7 | creation-mode: 8 | not-in-mode: "{RED}You are not in crate creation mode." 9 | cancelled: "{GREEN}Crate creation cancelled." 10 | key: 11 | error: 12 | invalid-player: "{RED}Invalid player." 13 | invalid-crate: "{RED}Invalid crate type." 14 | not-numeric: "{RED}Amount must be numeric." 15 | success: 16 | sender: "{GREEN}You've received the {CRATE} key." 17 | target: "{GREEN}You've given {TARGET} the {CRATE} key." 18 | keyall: 19 | error: 20 | invalid-crate: "{RED}Invalid crate type." 21 | not-numeric: "{RED}Amount must be numeric." 22 | success: 23 | sender: "{GREEN}You've received the {CRATE} key." 24 | target: "{GREEN}You've given all online players the {CRATE} key." 25 | crates: 26 | menu-name: "{CRATE} Crate" 27 | preview: 28 | item: 29 | name: "{GREEN}{COUNT}x {RESET}{ITEM}" 30 | lore: "{GOLD}Chance: {CHANCE}%" 31 | error: 32 | invalid-crate: "{RED}Invalid or missing crate type." 33 | currently-opened: "{RED}Crate is currently being opened." 34 | inventory-full: "{RED}You must have {COUNT} empty slots." 35 | success: 36 | crate-created: "{GREEN}{CRATE} Crate created." -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/utils/Utils.php: -------------------------------------------------------------------------------- 1 | TextFormat::BLACK, 15 | "{DARK_BLUE}" => TextFormat::DARK_BLUE, 16 | "{DARK_GREEN}" => TextFormat::DARK_GREEN, 17 | "{DARK_AQUA}" => TextFormat::DARK_AQUA, 18 | "{DARK_RED}" => TextFormat::DARK_RED, 19 | "{DARK_PURPLE}" => TextFormat::DARK_PURPLE, 20 | "{GOLD}" => TextFormat::GOLD, 21 | "{GRAY}" => TextFormat::GRAY, 22 | "{DARK_GRAY}" => TextFormat::DARK_GRAY, 23 | "{BLUE}" => TextFormat::BLUE, 24 | "{GREEN}" => TextFormat::GREEN, 25 | "{AQUA}" => TextFormat::AQUA, 26 | "{RED}" => TextFormat::RED, 27 | "{LIGHT_PURPLE}" => TextFormat::LIGHT_PURPLE, 28 | "{YELLOW}" => TextFormat::YELLOW, 29 | "{WHITE}" => TextFormat::WHITE, 30 | "{OBFUSCATED}" => TextFormat::OBFUSCATED, 31 | "{BOLD}" => TextFormat::BOLD, 32 | "{STRIKETHROUGH}" => TextFormat::STRIKETHROUGH, 33 | "{UNDERLINE}" => TextFormat::UNDERLINE, 34 | "{ITALIC}" => TextFormat::ITALIC, 35 | "{RESET}" => TextFormat::RESET 36 | ]; 37 | return str_replace(array_keys($replacements), $replacements, $message); 38 | } 39 | } -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/commands/KeyAllCommand.php: -------------------------------------------------------------------------------- 1 | sendMessage("Usage: /keyall "); 23 | return; 24 | } 25 | /** @var int $amount */ 26 | $amount = $args["amount"] ?? 1; 27 | if (!is_numeric($amount)) { 28 | $sender->sendMessage($this->plugin->getMessage("commands.keyall.error.not-numeric")); 29 | return; 30 | } 31 | $crate = $this->plugin->getCrate($args["type"]); 32 | if ($crate === null) { 33 | $sender->sendMessage($this->plugin->getMessage("commands.keyall.error.invalid-crate")); 34 | return; 35 | } 36 | foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { 37 | $crate->giveKey($player, $amount); 38 | $player->sendMessage($this->plugin->getMessage("commands.keyall.success.sender", ["{CRATE}" => $crate->getName()])); 39 | } 40 | $sender->sendMessage($this->plugin->getMessage("commands.keyall.success.target", ["{CRATE}" => $crate->getName()])); 41 | 42 | } 43 | 44 | /** 45 | * @throws ArgumentOrderException 46 | */ 47 | public function prepare(): void 48 | { 49 | $this->setPermission("piggycrates.command.keyall"); 50 | $this->registerArgument(0, new RawStringArgument("type")); 51 | $this->registerArgument(1, new IntegerArgument("amount", true)); 52 | } 53 | } -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/commands/CrateCommand.php: -------------------------------------------------------------------------------- 1 | sendMessage($this->plugin->getMessage("commands.use-in-game")); 23 | return; 24 | } 25 | if (!isset($args["type"])) { 26 | $sender->sendMessage("Usage: /crate "); 27 | return; 28 | } 29 | if ($args["type"] === "cancel") { 30 | if (!$this->plugin->inCrateCreationMode($sender)) { 31 | $sender->sendMessage($this->plugin->getMessage("commands.crate.creation-mode.not-in-mode")); 32 | return; 33 | } 34 | $this->plugin->setInCrateCreationMode($sender, null); 35 | $sender->sendMessage($this->plugin->getMessage("commands.crate.creation-mode.cancelled")); 36 | return; 37 | } 38 | $crate = $this->plugin->getCrate($args["type"]); 39 | if ($crate === null) { 40 | $sender->sendMessage($this->plugin->getMessage("commands.crate.error.invalid-crate")); 41 | return; 42 | } 43 | $this->plugin->setInCrateCreationMode($sender, $crate); 44 | $sender->sendMessage($this->plugin->getMessage("commands.crate.success")); 45 | } 46 | 47 | /** 48 | * @throws ArgumentOrderException 49 | */ 50 | public function prepare(): void 51 | { 52 | $this->setPermission("piggycrates.command.crate"); 53 | $this->registerArgument(0, new RawStringArgument("type")); 54 | } 55 | } -------------------------------------------------------------------------------- /resources/crates.yml: -------------------------------------------------------------------------------- 1 | crates: 2 | Common: 3 | drops: 4 | - id: 1 5 | meta: 0 6 | amount: 16 7 | chance: 25 8 | - id: 263 9 | meta: 0 10 | amount: 10 11 | chance: 75 12 | amount: 1 13 | commands: ["say {PLAYER} has opened an Common Crate"] 14 | floating-text: "Common Crate" 15 | Uncommon: 16 | drops: 17 | - id: 263 18 | meta: 0 19 | amount: 10 20 | chance: 75 21 | - id: 50 22 | meta: 0 23 | amount: 16 24 | chance: 15 25 | - id: 366 26 | meta: 0 27 | amount: 16 28 | chance: 10 29 | amount: 1 30 | commands: ["say {PLAYER} has opened an Uncommon Crate"] 31 | floating-text: "Uncommon Crate" 32 | Vote: 33 | drops: 34 | - id: 265 35 | meta: 0 36 | amount: 10 37 | chance: 35 38 | - id: 266 39 | meta: 0 40 | amount: 10 41 | chance: 15 42 | - id: 17 43 | meta: 0 44 | amount: 64 45 | chance: 50 46 | amount: 1 47 | commands: ["say {PLAYER} has opened an Vote Crate"] 48 | floating-text: "Vote Crate" 49 | Mythic: 50 | drops: 51 | - id: 264 52 | meta: 0 53 | amount: 16 54 | chance: 35 55 | - id: 388 56 | meta: 0 57 | amount: 16 58 | chance: 15 59 | - id: 322 60 | meta: 0 61 | amount: 16 62 | chance: 50 63 | amount: 1 64 | commands: ["say {PLAYER} has opened an Mythic Crate"] 65 | floating-text: "Mythic Crate" 66 | Legendary: 67 | drops: 68 | - id: 278 69 | meta: 0 70 | amount: 1 71 | chance: 10 72 | name: "Telepathic Pickaxe" 73 | lore: "Items mined are transported into your inventory" 74 | enchantments: 75 | - name: "telepathy" 76 | level: 1 77 | - id: 49 78 | meta: 0 79 | amount: 32 80 | chance: 15 81 | - id: 466 82 | meta: 0 83 | amount: 16 84 | chance: 70 85 | - id: 7 86 | meta: 0 87 | amount: 5 88 | chance: 5 89 | amount: 1 90 | commands: ["say {PLAYER} has opened an Legendary Crate"] 91 | floating-text: "Legendary Crate" -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/EventListener.php: -------------------------------------------------------------------------------- 1 | getPlayer(); 24 | $block = $event->getBlock(); 25 | $world = $block->getPosition()->getWorld(); 26 | $item = $player->getInventory()->getItemInHand(); 27 | 28 | if ($block->getId() === BlockLegacyIds::CHEST) { 29 | $tile = $world->getTile($block->getPosition()); 30 | if ($tile instanceof CrateTile) { 31 | if ($tile->getCrateType() === null) { 32 | $player->sendTip($this->plugin->getMessage("crates.error.invalid-crate")); 33 | } elseif ($tile->getCrateType()->isValidKey($item)) { 34 | $tile->openCrate($player, $item); 35 | } elseif ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK) { 36 | $tile->previewCrate($player); 37 | } 38 | $event->cancel(); 39 | return; 40 | } 41 | if ($tile instanceof Chest) { 42 | if (($crate = $this->plugin->getCrateToCreate($player)) !== null) { 43 | $newTile = new CrateTile($world, $block->getPosition()); 44 | $newTile->setCrateType($crate); 45 | $tile->close(); 46 | $world->addTile($newTile); 47 | $player->sendMessage($this->plugin->getMessage("crates.success.crate-created", ["{CRATE}" => $crate->getName()])); 48 | $this->plugin->setInCrateCreationMode($player, null); 49 | $event->cancel(); 50 | return; 51 | } 52 | } 53 | } 54 | if ($item->getNamedTag()->getTag("KeyType") !== null) $event->cancel(); 55 | } 56 | } -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/commands/KeyCommand.php: -------------------------------------------------------------------------------- 1 | sendMessage("Usage: /key "); 24 | return; 25 | } 26 | if (!$sender instanceof Player && !isset($args["player"])) { 27 | $sender->sendMessage("Usage: /key "); 28 | return; 29 | } 30 | $target = empty($args["player"]) ? $sender : $this->plugin->getServer()->getPlayerExact($args["player"]); 31 | if (!$target instanceof Player) { 32 | $sender->sendMessage($this->plugin->getMessage("commands.key.error.invalid-player")); 33 | return; 34 | } 35 | /** @var int $amount */ 36 | $amount = $args["amount"] ?? 1; 37 | if (!is_numeric($amount)) { 38 | $sender->sendMessage($this->plugin->getMessage("commands.key.error.not-numeric")); 39 | return; 40 | } 41 | $crate = $this->plugin->getCrate($args["type"]); 42 | if ($crate === null) { 43 | $sender->sendMessage($this->plugin->getMessage("commands.key.error.invalid-crate")); 44 | return; 45 | } 46 | $crate->giveKey($target, $amount); 47 | $target->sendMessage($this->plugin->getMessage("commands.key.success.sender", ["{CRATE}" => $crate->getName()])); 48 | $sender->sendMessage($this->plugin->getMessage("commands.key.success.target", ["{CRATE}" => $crate->getName(), "{TARGET}" => $target->getName()])); 49 | 50 | } 51 | 52 | /** 53 | * @throws ArgumentOrderException 54 | */ 55 | public function prepare(): void 56 | { 57 | $this->setPermission("piggycrates.command.key"); 58 | $this->registerArgument(0, new RawStringArgument("type")); 59 | $this->registerArgument(1, new IntegerArgument("amount", true)); 60 | $this->registerArgument(2, new RawStringArgument("player", true)); 61 | } 62 | } -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/crates/Crate.php: -------------------------------------------------------------------------------- 1 | name; 26 | } 27 | 28 | public function getFloatingText(): string 29 | { 30 | return $this->floatingText; 31 | } 32 | 33 | /** 34 | * @return CrateItem[] 35 | */ 36 | public function getDrops(): array 37 | { 38 | return $this->drops; 39 | } 40 | 41 | /** 42 | * @return CrateItem[] 43 | */ 44 | public function getDrop(int $amount): array 45 | { 46 | $dropTable = []; 47 | foreach ($this->drops as $drop) { 48 | for ($i = 0; $i < $drop->getChance(); $i++) { 49 | $dropTable[] = $drop; 50 | } 51 | } 52 | 53 | $keys = array_rand($dropTable, $amount); 54 | if (!is_array($keys)) $keys = [$keys]; 55 | return array_map(function ($key) use ($dropTable) { 56 | return $dropTable[$key]; 57 | }, $keys); 58 | } 59 | 60 | public function getDropCount(): int 61 | { 62 | return $this->dropCount; 63 | } 64 | 65 | /** 66 | * @return string[] 67 | */ 68 | public function getCommands(): array 69 | { 70 | return $this->commands; 71 | } 72 | 73 | public function giveKey(Player $player, int $amount): void 74 | { 75 | $key = ItemFactory::getInstance()->get((int)$this->plugin->getConfig()->getNested("keys.id"), (int)$this->plugin->getConfig()->getNested("keys.meta"), $amount); 76 | $key->setCustomName(ucfirst(str_replace("{CRATE}", $this->getName(), $this->plugin->getConfig()->getNested("keys.name")))); 77 | $key->setLore([str_replace("{CRATE}", $this->getName(), $this->plugin->getConfig()->getNested("keys.lore"))]); 78 | $key->getNamedTag()->setString("KeyType", $this->getName()); 79 | $player->getInventory()->addItem($key); 80 | } 81 | 82 | public function isValidKey(Item $item): bool 83 | { 84 | return $item->getId() === (int)$this->plugin->getConfig()->getNested("keys.id") && 85 | $item->getMeta() === (int)$this->plugin->getConfig()->getNested("keys.meta") && 86 | ($keyTypeTag = $item->getNamedTag()->getTag("KeyType")) instanceof StringTag && 87 | $keyTypeTag->getValue() === $this->getName(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/tasks/RouletteTask.php: -------------------------------------------------------------------------------- 1 | getCurrentPlayer(); 40 | $this->player = $player; 41 | 42 | /** @var Crate $crate */ 43 | $crate = $tile->getCrateType(); 44 | $this->crate = $crate; 45 | 46 | $this->tile = $tile; 47 | 48 | $this->menu = InvMenu::create(InvMenuTypeIds::TYPE_CHEST); 49 | $this->menu->setName(PiggyCrates::getInstance()->getMessage("crates.menu-name", ["{CRATE}" => $crate->getName()])); 50 | $this->menu->getInventory()->setContents([4 => ($endRod = ItemFactory::getInstance()->get(ItemIds::END_ROD)->setCustomName(TextFormat::ITALIC)), 22 => $endRod]); 51 | $this->menu->setListener(InvMenu::readonly()); 52 | $this->menu->send($player); 53 | 54 | $this->itemsLeft = $crate->getDropCount(); 55 | } 56 | 57 | public function onRun(): void 58 | { 59 | if (!$this->player->isOnline()) { 60 | $this->tile->closeCrate(); 61 | if (($handler = $this->getHandler()) !== null) $handler->cancel(); 62 | return; 63 | } 64 | $this->currentTick++; 65 | $speed = PiggyCrates::getInstance()->getConfig()->getNested("crates.roulette.speed"); 66 | $safeSpeed = $speed >= 1 ? $speed : 1; 67 | $duration = PiggyCrates::getInstance()->getConfig()->getNested("crates.roulette.duration"); 68 | $safeDuration = (($duration / $safeSpeed) >= 5.5) ? $duration : (5.5 * $safeSpeed); 69 | if ($this->currentTick >= $safeDuration) { 70 | if (!$this->showReward) { 71 | $this->showReward = true; 72 | } elseif ($this->currentTick - $safeDuration > 20) { 73 | $this->itemsLeft--; 74 | $reward = $this->lastRewards[floor(self::INVENTORY_ROW_COUNT / 2)]; 75 | if ($reward->getType() === "item") $this->player->getInventory()->addItem($reward->getItem()); 76 | $server = $this->player->getServer(); 77 | foreach ($reward->getCommands() as $command) { 78 | $server->dispatchCommand(new ConsoleCommandSender($server, $server->getLanguage()), str_replace("{PLAYER}", $this->player->getName(), $command)); 79 | } 80 | if ($this->itemsLeft === 0) { 81 | foreach ($this->crate->getCommands() as $command) { 82 | $server->dispatchCommand(new ConsoleCommandSender($server, $server->getLanguage()), str_replace("{PLAYER}", $this->player->getName(), $command)); 83 | } 84 | $this->player->removeCurrentWindow(); 85 | $this->tile->closeCrate(); 86 | if (($handler = $this->getHandler()) !== null) $handler->cancel(); 87 | } else { 88 | $this->currentTick = 0; 89 | $this->showReward = false; 90 | } 91 | } 92 | return; 93 | } 94 | 95 | if ($this->currentTick % $safeSpeed === 0) { 96 | $this->lastRewards[self::INVENTORY_ROW_COUNT] = $this->crate->getDrop(1)[0]; 97 | /** 98 | * @var int $slot 99 | * @var CrateItem $lastReward 100 | */ 101 | foreach ($this->lastRewards as $slot => $lastReward) { 102 | if ($slot !== 0) { 103 | $this->lastRewards[$slot - 1] = $lastReward; 104 | $this->menu->getInventory()->setItem($slot + self::INVENTORY_ROW_COUNT - 1, $lastReward->getItem()); 105 | } 106 | } 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PiggyCrates [![Poggit-CI](https://poggit.pmmp.io/shield.dl/PiggyCrates)](https://poggit.pmmp.io/p/PiggyCrates) [![Discord](https://img.shields.io/discord/330850307607363585?logo=discord)](https://discord.gg/qmnDsSD) 2 | 3 | PiggyCrates is a simple and customizable crates plugin, supporting an unlimited amount of crate types. It also supports 4 | vanilla and custom enchants, such as [PiggyCustomEnchants](https://github.com/DaPigGuy/PiggyCustomEnchants/). 5 | 6 | ## Prerequisites 7 | 8 | * Basic knowledge on how to install plugins from Poggit Releases and/or Poggit CI 9 | * PMMP 4.0.0+ 10 | 11 | ## Installation & Setup 12 | 13 | 1. Install the plugin from Poggit. 14 | 2. Start your server. 15 | 3. (Optional) The `config.yml` file has a few options that allow you to customize your key items & crate modes (default 16 | is roulette). 17 | 4. Open the `crates.yml`. 18 | 5. PiggyCrates supports an unlimited number of crates. To define a crate, add a key `crates.yourcratename`. 19 | 6. Configure your crate types. Crate types have several different properties: 20 | * (Optional) `floating-text`: Floating text that will appear above the crate type. Leave empty for no floating text. 21 | * (Optional) `commands`: Commands to be run by CONSOLE when crate type is opened. Use `{PLAYER}` as a placeholder 22 | for player name. 23 | * `drops`: Possible drops of a crate type. Items are defined with the properties: 24 | * `id`: Item ID 25 | * `meta`: Item Meta 26 | * `amount`: Item Amount 27 | * (Optional) `type`: Item Type 28 | * (Default) `item`: Runs all crate item commands & gives the item 29 | * `command`: Runs all crate item commands 30 | * (Optional) `chance`: Item Weight 31 | * (Optional) `nbt`: Item NBT as stringified JSON 32 | * (Optional) `name`: Item Name 33 | * (Optional) `lore`: Item Lore as string with line breaks represented as `\n` 34 | * (Optional) `enchantments`: Item enchantments defined like so: 35 | ```yaml 36 | enchantments: 37 | - name: "Protection" 38 | level: 1 39 | - name: "Thorns" 40 | level: 1 41 | ``` 42 | * (Optional) `commands`: Commands to be run by CONSOLE if item is dropped by crate. 43 | * `amount`: Amount of drops a single crate type will give. 44 | 45 | **Example**: 46 | ```yaml 47 | crates: 48 | # Crate type named "Example" 49 | Example: 50 | floating-text: "Example Crate" 51 | amount: 1 52 | # Will run the command "/say" when opened 53 | commands: 54 | - "say {PLAYER} has opened the example crate!" 55 | drops: 56 | # 50% chance for 1x Diamond Sword named Sharpened Diamond Sword w/ Sharpness 5 enchantment 57 | # Will run the command "/tell" on drop 58 | - id: 276 59 | meta: 0 60 | amount: 1 61 | chance: 50 62 | name: "Sharpened Diamond Sword" 63 | enchantments: 64 | - name: "Sharpness" 65 | level: 5 66 | commands: 67 | - "tell {PLAYER} You got a Sharpened Diamond Sword! ;o" 68 | # Identical to the above drop but with a 25% chance and an Iron Sword 69 | - id: 267 70 | meta: 0 71 | amount: 1 72 | chance: 25 73 | name: "Sharpened Iron Sword" 74 | enchantments: 75 | - name: "Sharpness" 76 | level: 5 77 | commands: 78 | - "tell {PLAYER} You got a Sharpened Iron Sword! ;o" 79 | # 25% chance for player to get money 80 | - id: 266 81 | meta: 0 82 | amount: 1 83 | chance: 25 84 | name: "$2500" 85 | type: command 86 | commands: 87 | - "givemoney {PLAYER} 2500" 88 | ``` 89 | 7. Restart your server. 90 | 8. Connect to your server. 91 | 9. Place a chest block where you intend on having a crate. 92 | 9. Run the command `/crate ` 93 | 10. Tap the target chest. 94 | 11. Repeat with other crate types. 95 | 12. You're done! 96 | 97 | ## Commands 98 | 99 | | Command | Description | Permissions | Aliases 100 | | --- | --- | --- | --- | 101 | | `/crate ` | Changes a chest to a crate by tapping | `piggycrates.command.crate` | N/A | 102 | | `/key` | Gives a player a specific crate key | `piggycrates.command.key` | N/A | 103 | | `/keyall` | Gives all online players a specific crate key | `piggycrates.command.keyall` | N/A | 104 | 105 | ## Permissions 106 | 107 | | Permissions | Description | Default | 108 | | --- | --- | --- | 109 | | `piggycrates` | Allows usage of all PiggyCrates features | `false` | 110 | | `piggycrates.command` | Allow usage of all PiggyCrates commands | `op` | 111 | | `piggycrates.command.crate` | Allow usage of all /crate commands | `op` | 112 | | `piggycrates.command.key` | Allow usage of the /key command | `op` | 113 | | `piggycrates.command.keyall` | Allow usage of the /keyall command | `op` | 114 | 115 | ## Issue Reporting 116 | 117 | * If you experience an unexpected non-crash behavior with PiggyCrates, 118 | click [here](https://github.com/DaPigGuy/PiggyCrates/issues/new?assignees=DaPigGuy&labels=bug&template=bug_report.md&title=) 119 | . 120 | * If you experience a crash in PiggyCrates, 121 | click [here](https://github.com/DaPigGuy/PiggyCrates/issues/new?assignees=DaPigGuy&labels=bug&template=crash.md&title=) 122 | . 123 | * If you would like to suggest a feature to be added to PiggyCrates, 124 | click [here](https://github.com/DaPigGuy/PiggyCrates/issues/new?assignees=DaPigGuy&labels=suggestion&template=suggestion.md&title=) 125 | . 126 | * If you require support, please join our discord server [here](https://discord.gg/qmnDsSD). 127 | * Do not file any issues related to outdated API version; we will resolve such issues as soon as possible. 128 | * We do not support any spoons of PocketMine-MP. Anything to do with spoons (Issues or PRs) will be ignored. 129 | * This includes plugins that modify PocketMine-MP's behavior directly, such as TeaSpoon. 130 | 131 | ## License 132 | 133 | ``` 134 | Copyright 2018-2020 DaPigGuy 135 | 136 | Licensed under the Apache License, Version 2.0 (the "License"); 137 | you may not use this file except in compliance with the License. 138 | You may obtain a copy of the License at 139 | 140 | http://www.apache.org/licenses/LICENSE-2.0 141 | 142 | Unless required by applicable law or agreed to in writing, software 143 | distributed under the License is distributed on an "AS IS" BASIS, 144 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145 | See the License for the specific language governing permissions and 146 | limitations under the License. 147 | 148 | ``` -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/PiggyCrates.php: -------------------------------------------------------------------------------- 1 | */ 43 | public array $crateCreation; 44 | 45 | /** 46 | * @throws HookAlreadyRegistered 47 | */ 48 | public function onEnable(): void 49 | { 50 | foreach ( 51 | [ 52 | "Commando" => BaseCommand::class, 53 | "InvMenu" => InvMenuHandler::class, 54 | "libPiggyUpdateChecker" => libPiggyUpdateChecker::class 55 | ] as $virion => $class 56 | ) { 57 | if (!class_exists($class)) { 58 | $this->getLogger()->error($virion . " virion not found. Please download PiggyCrates from Poggit-CI or use DEVirion (not recommended)."); 59 | $this->getServer()->getPluginManager()->disablePlugin($this); 60 | return; 61 | } 62 | } 63 | 64 | if (!InvMenuHandler::isRegistered()) { 65 | InvMenuHandler::register($this); 66 | } 67 | 68 | self::$instance = $this; 69 | 70 | libPiggyUpdateChecker::init($this); 71 | 72 | TileFactory::getInstance()->register(CrateTile::class); 73 | 74 | $this->saveResource("crates.yml"); 75 | $this->saveResource("messages.yml"); 76 | $this->messages = new Config($this->getDataFolder() . "messages.yml"); 77 | $this->saveDefaultConfig(); 78 | 79 | $crateConfig = new Config($this->getDataFolder() . "crates.yml"); 80 | $types = ["item", "command"]; 81 | foreach ($crateConfig->get("crates") as $crateName => $crateData) { 82 | $this->crates[$crateName] = new Crate($this, $crateName, $crateData["floating-text"] ?? "", array_map(function (array $itemData) use ($crateName, $types): CrateItem { 83 | $tags = null; 84 | if (isset($itemData["nbt"])) { 85 | try { 86 | $tags = JsonNbtParser::parseJson($itemData["nbt"]); 87 | } catch (Exception $e) { 88 | $this->getLogger()->warning("Invalid crate item NBT supplied in crate type " . $crateName . "."); 89 | } 90 | } 91 | $item = ItemFactory::getInstance()->get($itemData["id"], $itemData["meta"], $itemData["amount"], $tags); 92 | if (isset($itemData["name"])) $item->setCustomName($itemData["name"]); 93 | if (isset($itemData["lore"])) $item->setLore(explode("\n", $itemData["lore"])); 94 | if (isset($itemData["enchantments"])) foreach ($itemData["enchantments"] as $enchantmentData) { 95 | if (!isset($enchantmentData["name"]) || !isset($enchantmentData["level"])) { 96 | $this->getLogger()->error("Invalid enchantment configuration used in crate " . $crateName); 97 | continue; 98 | } 99 | $enchantment = StringToEnchantmentParser::getInstance()->parse($enchantmentData["name"]) ?? ((($plugin = $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants")) instanceof PiggyCustomEnchants && $plugin->isEnabled()) ? CustomEnchantManager::getEnchantmentByName($enchantmentData["name"]) : null); 100 | if ($enchantment !== null) $item->addEnchantment(new EnchantmentInstance($enchantment, $enchantmentData["level"])); 101 | } 102 | $itemData["type"] = $itemData["type"] ?? "item"; 103 | if (!in_array($itemData["type"], $types)) { 104 | $itemData["type"] = "item"; 105 | $this->getLogger()->warning("Invalid crate item type supplied in crate type " . $crateName . ". Assuming type item."); 106 | } 107 | return new CrateItem($item, $itemData["type"], $itemData["commands"] ?? [], $itemData["chance"] ?? 100); 108 | }, $crateData["drops"] ?? []), $crateData["amount"], $crateData["commands"] ?? []); 109 | } 110 | 111 | if (!PacketHooker::isRegistered()) PacketHooker::register($this); 112 | $this->getServer()->getCommandMap()->register("piggycrates", new CrateCommand($this, "crate", "Create a crate")); 113 | $this->getServer()->getCommandMap()->register("piggycrates", new KeyCommand($this, "key", "Give a crate key")); 114 | $this->getServer()->getCommandMap()->register("piggycrates", new KeyAllCommand($this, "keyall", "Give all online players a crate key")); 115 | 116 | $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); 117 | 118 | $this->getScheduler()->scheduleRepeatingTask(new ClosureTask(function () { 119 | foreach ($this->crateTiles as $crateTile) { 120 | $crateTile->onUpdate(); 121 | } 122 | }), 20); 123 | } 124 | 125 | public static function getInstance(): PiggyCrates 126 | { 127 | return self::$instance; 128 | } 129 | 130 | public function getMessage(string $key, array $tags = []): string 131 | { 132 | return Utils::translateColorTags(str_replace(array_keys($tags), $tags, $this->messages->getNested($key, $key))); 133 | } 134 | 135 | public function getCrate(string $name): ?Crate 136 | { 137 | return $this->crates[$name] ?? null; 138 | } 139 | 140 | public function getCrates(): array 141 | { 142 | return $this->crates; 143 | } 144 | 145 | public function inCrateCreationMode(Player $player): bool 146 | { 147 | return isset($this->crateCreation[$player->getName()]); 148 | } 149 | 150 | public function setInCrateCreationMode(Player $player, ?Crate $crate): void 151 | { 152 | if ($crate === null) { 153 | unset($this->crateCreation[$player->getName()]); 154 | return; 155 | } 156 | $this->crateCreation[$player->getName()] = $crate; 157 | } 158 | 159 | public function getCrateToCreate(Player $player): ?Crate 160 | { 161 | return $this->crateCreation[$player->getName()] ?? null; 162 | } 163 | } -------------------------------------------------------------------------------- /src/DaPigGuy/PiggyCrates/tiles/CrateTile.php: -------------------------------------------------------------------------------- 1 | */ 35 | public array $floatingTextParticles = []; 36 | 37 | public function __construct(World $world, Vector3 $pos) 38 | { 39 | parent::__construct($world, $pos); 40 | PiggyCrates::getInstance()->crateTiles[] = $this; 41 | } 42 | 43 | public function getCrateType(): ?Crate 44 | { 45 | return $this->crateType; 46 | } 47 | 48 | public function setCrateType(Crate $crate): void 49 | { 50 | $this->crateName = $crate->getName(); 51 | $this->crateType = $crate; 52 | } 53 | 54 | public function openCrate(Player $player, Item $key): void 55 | { 56 | if (($crateType = $this->crateType) === null) return; 57 | if ($this->isOpen) { 58 | $player->sendTip(PiggyCrates::getInstance()->getMessage("crates.error.currently-opened")); 59 | return; 60 | } 61 | if (count($player->getInventory()->getContents()) > $player->getInventory()->getSize() - $crateType->getDropCount()) { 62 | $player->sendTip(PiggyCrates::getInstance()->getMessage("crates.error.inventory-full", ["{COUNT}" => $crateType->getDropCount()])); 63 | return; 64 | } 65 | 66 | $player->getInventory()->removeItem($key->setCount(1)); 67 | 68 | $this->getPosition()->getWorld()->broadcastPacketToViewers($this->getPosition(), BlockEventPacket::create(BlockPosition::fromVector3($this->getPosition()->asVector3()), 1, 1)); 69 | 70 | $this->isOpen = true; 71 | $this->currentPlayer = $player; 72 | 73 | switch (PiggyCrates::getInstance()->getConfig()->getNested("crates.mode")) { 74 | case "instant": 75 | $this->closeCrate(); 76 | $server = $player->getServer(); 77 | foreach ($crateType->getDrop($crateType->getDropCount()) as $drop) { 78 | if ($drop->getType() === "item") $player->getInventory()->addItem($drop->getItem()); 79 | foreach ($drop->getCommands() as $command) { 80 | $server->dispatchCommand(new ConsoleCommandSender($server, $server->getLanguage()), str_replace("{PLAYER}", $player->getName(), $command)); 81 | } 82 | } 83 | foreach ($crateType->getCommands() as $command) { 84 | $server->dispatchCommand(new ConsoleCommandSender($server, $server->getLanguage()), str_replace("{PLAYER}", $player->getName(), $command)); 85 | } 86 | break; 87 | case "roulette": 88 | default: 89 | PiggyCrates::getInstance()->getScheduler()->scheduleRepeatingTask(new RouletteTask($this), 1); 90 | break; 91 | } 92 | } 93 | 94 | public function closeCrate(): void 95 | { 96 | if (!$this->isOpen) return; 97 | 98 | $this->getPosition()->getWorld()->broadcastPacketToViewers($this->getPosition(), BlockEventPacket::create(BlockPosition::fromVector3($this->getPosition()->asVector3()), 1, 0)); 99 | 100 | $this->isOpen = false; 101 | $this->currentPlayer = null; 102 | } 103 | 104 | public function previewCrate(Player $player): void 105 | { 106 | if (($crateType = $this->crateType) === null) return; 107 | 108 | $drops = $crateType->getDrops(); 109 | usort($drops, function (CrateItem $a, CrateItem $b) { 110 | if ($a->getChance() > $b->getChance()) return -1; 111 | if ($a->getChance() < $b->getChance()) return 1; 112 | return 0; 113 | }); 114 | 115 | $chances = 0; 116 | foreach ($drops as $crateItem) $chances += $crateItem->chance; 117 | 118 | $menu = InvMenu::create(count($drops) > 27 ? InvMenuTypeIds::TYPE_DOUBLE_CHEST : InvMenuTypeIds::TYPE_CHEST); 119 | $menu->setListener(InvMenu::readonly()); 120 | $menu->setName(PiggyCrates::getInstance()->getMessage("crates.menu-name", ["{CRATE}" => $crateType->getName()])); 121 | 122 | $slot = 0; 123 | foreach ($drops as $crateItem) { 124 | if ($slot > 53) break; // Maximum supported preview items is 54, meaning lowest chances are not shown. 125 | $item = clone $crateItem->item; 126 | $item->setCustomName(TextFormat::RESET . PiggyCrates::getInstance()->getMessage("crates.preview.item.name", ["{COUNT}" => $crateItem->getItem()->getCount(), "{ITEM}" => $item->getName()])); 127 | $item->setLore([TextFormat::RESET, TextFormat::RESET . PiggyCrates::getInstance()->getMessage("crates.preview.item.lore", ["{CHANCE}" => round(($crateItem->chance / $chances) * 100, 2, PHP_ROUND_HALF_UP)])]); 128 | $menu->getInventory()->setItem($slot, $item); 129 | $slot++; 130 | } 131 | $menu->send($player); 132 | } 133 | 134 | public function close(): void 135 | { 136 | foreach ($this->floatingTextParticles as $key => $particle) { 137 | $player = Server::getInstance()->getPlayerExact($key); 138 | $particle->setInvisible(); 139 | if ($player !== null) $player->getWorld()->addParticle($this->getPosition(), $particle, [$player]); 140 | } 141 | unset(PiggyCrates::getInstance()->crateTiles[array_search($this, PiggyCrates::getInstance()->crateTiles)]); 142 | parent::close(); 143 | } 144 | 145 | public function isOpen(): bool 146 | { 147 | return $this->isOpen; 148 | } 149 | 150 | public function getCurrentPlayer(): ?Player 151 | { 152 | return $this->currentPlayer; 153 | } 154 | 155 | public function addAdditionalSpawnData(CompoundTag $nbt): void 156 | { 157 | parent::addAdditionalSpawnData($nbt); 158 | $nbt->setString(self::TAG_ID, "Chest"); 159 | $nbt->setString(self::TAG_CUSTOM_NAME, ($this->crateType === null ? "Unknown" : $this->crateType->getName()) . " Crate"); 160 | } 161 | 162 | public function onUpdate(): bool 163 | { 164 | if (!$this->closed && $this->crateType !== null && $this->crateType->getFloatingText() !== "") { 165 | $world = $this->getPosition()->getWorld(); 166 | foreach ($this->floatingTextParticles as $key => $particle) { 167 | $player = Server::getInstance()->getPlayerExact($key); 168 | if ($player === null) { 169 | unset($this->floatingTextParticles[$key]); 170 | } else if ($player->getWorld() !== $world) { 171 | $particle->setInvisible(); 172 | $player->getWorld()->addParticle($this->getPosition(), $particle, [$player]); 173 | unset($this->floatingTextParticles[$key]); 174 | } 175 | } 176 | foreach ($world->getPlayers() as $player) { 177 | if (!isset($this->floatingTextParticles[$player->getName()])) { 178 | $this->floatingTextParticles[$player->getName()] = new FloatingTextParticle($this->crateType->getFloatingText()); 179 | $world->addParticle($this->getPosition()->add(0.5, 1, 0.5), $this->floatingTextParticles[$player->getName()], [$player]); 180 | } 181 | } 182 | } 183 | return !$this->closed; 184 | } 185 | 186 | public function readSaveData(CompoundTag $nbt): void 187 | { 188 | parent::readSaveData($nbt); 189 | $this->crateName = $nbt->getString("CrateType"); 190 | $this->crateType = PiggyCrates::getInstance()->getCrate($this->crateName); 191 | } 192 | 193 | protected function writeSaveData(CompoundTag $nbt): void 194 | { 195 | parent::writeSaveData($nbt); 196 | $nbt->setString("CrateType", $this->crateName); 197 | } 198 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018-2020 DaPigGuy 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------