diff --git a/.poggit.yml b/.poggit.yml new file mode 100644 index 0000000..ce67b6d --- /dev/null +++ b/.poggit.yml @@ -0,0 +1,90 @@ +--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/jasonwynn10/Other-Plugins +projects: + 2vs2: + path: 2vs2/ + AirSneakBoots: + path: AirSneakBoots/ + BanClientId: + path: BanClientId/ + BasketBall: + path: BasketBall/ + BlockTypeCorrector: + path: BlockTypeCorrector/ + BuildZone: + path: BuildZone/ + ChunkLoaders: + path: ChunkLoaders/ + CrateKeys: + path: CrateKeys/ + Cratechest: + path: Cratechest/ + CrossOnlineCount: + path: CrossOnlineCount/ + libs: + - src: Falkirks/spoondetector/spoondetector + version: ^0.0.0 + - src: jasonwynn10/libpmquery/libpmquery + version: ^0.0.1 + CustomAlerts: + path: CustomAlerts/ + Elytra: + path: Elytra/ + ExplodableUnbreakables: + path: ExplodableUnbreakables/ + Farms: + path: Farms/ + GlowstoneCircleWorld: + path: GlowstoneCircleWorld/ + HiddenUnHidden: + path: HiddenUnHidden/ + HubTP: + path: HubTP/ + Infinity-Stone: + path: Infinity-Stone/ + LateCommands: + path: LateCommands/ + MeteorRain: + path: MeteorRain/ + MoreCommands: + path: MoreCommands/ + Multi-Inv: + path: Multi-Inv/ + NameTagMods: + path: NameTagMods/ + NoPvpFlight: + path: NoPvpFlight/ + PeacefulSpawn: + path: PeacefulSpawn/ + PerWorldChat: + path: PerWorldChat/ + PlayerResizer: + path: PlayerResizer/ + PlayersLifetime: + path: PlayersLifetime/ + PrizeCode: + path: PrizeCode/ + PureChatExtras: + path: PureChatExtras/ + RandomEnchant: + path: RandomEnchant/ + SafeFly: + path: SafeFly/ + Sleep4All: + path: Sleep4All/ + TimeCommander: + path: TimeCommander/ + UHC: + path: UHC/ + VIPfly: + path: VIPfly/ + ViperKits: + path: ViperKits/ + WarpPads: + path: WarpPads/ + WorldEdit: + path: WorldEdit/ + WorldMerge: + path: WorldMerge/ + WorldShift: + path: WorldShift/ +... diff --git a/BanClientId/plugin.yml b/BanClientId/plugin.yml index 9b19b23..bbb01ca 100644 --- a/BanClientId/plugin.yml +++ b/BanClientId/plugin.yml @@ -3,7 +3,7 @@ author: "jasonwynn10" version: 0.1.0 api: - 3.0.0 - - 3.0.0-ALPHA7 + - 3.0.0-ALPHA10 main: jasonwynn10\Main description: "A plugin that allows banning client Ids" commands: diff --git a/BanClientId/src/jasonwynn10/Bancid/Main.php b/BanClientId/src/jasonwynn10/Bancid/Main.php index 1b8bc46..7c1ddd8 100644 --- a/BanClientId/src/jasonwynn10/Bancid/Main.php +++ b/BanClientId/src/jasonwynn10/Bancid/Main.php @@ -28,7 +28,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label if (isset($args[0])) { if(($player = $this->getServer()->getPlayer($args[0])) instanceof Player) { $name = $player->getName(); - $id = $player->getClientId(); + $id = $player->getUniqueId(); $banned = $this->getConfig()->get("Banned", []); $times = $this->getConfig()->get("Times", []); $banned[$name] = $id; @@ -71,7 +71,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label if(isset($args[0]) and isset($args[1])) { if(($player = $this->getServer()->getPlayer($args[0])) instanceof Player and is_int($args[1])) { $name = $player->getName(); - $id = $player->getClientId(); + $id = $player->getUniqueId(); $banned = $this->getConfig()->get("Banned", []); $times = $this->getConfig()->get("Times", []); $banned[$name] = $id; @@ -95,12 +95,12 @@ public function onPreLogin(PlayerPreLoginEvent $ev) { foreach($this->getConfig()->get("Banned", []) as $name => $id) { foreach ($this->getConfig()->get("Times", []) as $key => $time) { if($key === $id) { - if($p->getClientId() === $id) { + if($p->getUniqueId() === $id) { $ev->setKickMessage("You are banned for {$time} more minutes!"); $ev->setCancelled(); } }else{ - if($p->getClientId() === $id) { + if($p->getUniqueId() === $id) { $ev->setKickMessage("You have been banned!"); $ev->setCancelled(); } diff --git a/BlockTypeCorrector/plugin.yml b/BlockTypeCorrector/plugin.yml index 7fa7785..8585a09 100644 --- a/BlockTypeCorrector/plugin.yml +++ b/BlockTypeCorrector/plugin.yml @@ -5,5 +5,6 @@ author: "jasonwynn10" version: 0.2.0 api: - 3.0.0 - - 3.0.0-ALPHA7 + - 3.0.0-ALPHA9 + - 3.0.0-ALPHA10 load: STARTUP diff --git a/BlockTypeCorrector/resources/config.yml b/BlockTypeCorrector/resources/config.yml index 982fd90..62b9c6b 100644 --- a/BlockTypeCorrector/resources/config.yml +++ b/BlockTypeCorrector/resources/config.yml @@ -1,38 +1,45 @@ -BlocksPerTick: 256 blocks: - "243:0": "3:2" - "2:0": "31:1" - "43:6": "43:7" - "44:6": "44:7" - "337:0": "82:0" - "405:0": "112:0" - "372:0": "115:0" - "126:0": "158:0" - "126:1": "158:1" - "126:8": "158:8" - "125:0": "157:0" - "85:1": "188:0" - "85:2": "189:0" - "85:3": "190:0" - "85:5": "191:0" - "85:4": "192:0" - "208:0": "198:0" - "240:0": "199:0" - "201:2": "202:0" - "44:7": "205:0" - "244:0": "207:0" - "198:0": "208:0" - "115:0": "214:0" - "466:0": "322:1" - "422:0": "410:0" - "457:0": "434:0" - "458:0": "435:0" - "459:0": "436:0" - "445:0": "450:0" - "143:1": "143:5" - "77:1": "77:5" - "77:4": "77:2" - "96:4": "96:15" - "96:5": "96:14" - "96:6": "96:13" - "96:7": "96:12" \ No newline at end of file + "243:0": "3:2" + "2:0": "31:1" + "43:6": "43:7" + "44:6": "44:7" + "337:0": "82:0" + "405:0": "112:0" + "372:0": "115:0" + "126:0": "158:0" + "126:1": "158:1" + "126:8": "158:8" + "125:0": "157:0" + "85:1": "188:0" + "85:2": "189:0" + "85:3": "190:0" + "85:5": "191:0" + "85:4": "192:0" + "208:0": "198:0" + "240:0": "199:0" + "201:2": "202:0" + "44:7": "205:0" + "244:0": "207:0" + "198:0": "208:0" + "115:0": "214:0" + "466:0": "322:1" + "422:0": "410:0" + "457:0": "434:0" + "458:0": "435:0" + "459:0": "436:0" + "445:0": "450:0" + "143:1": "143:5" + "77:1": "77:5" + "77:4": "77:2" + "96:4": "96:15" + "96:5": "96:14" + "96:6": "96:13" + "96:7": "96:12" + "188:0": "85:1" + "95:0": "20:0" + "160:0": "102:0" + "188:0": "85:1" + "189:0": "85:2" + "190:0": "85:3" + "191:0": "85:5" + "192:0": "85:4" \ No newline at end of file diff --git a/BlockTypeCorrector/src/jasonwynn10/corrector/Corrector.php b/BlockTypeCorrector/src/jasonwynn10/corrector/Corrector.php deleted file mode 100644 index a7ac5e7..0000000 --- a/BlockTypeCorrector/src/jasonwynn10/corrector/Corrector.php +++ /dev/null @@ -1,52 +0,0 @@ -level = $level; - $this->bpt = $plugin->getConfig()->get("BlocksPerTick",256); - $this->blockTypes = $plugin->getConfig()->get("blocks", []); - $plugin->getLogger()->info("CORRECTOR STARTING"); - } - public function onRun(int $currentTick) { - $this->getOwner()->getLogger()->info("CORRECTOR STARTED"); - $blocks = 0; - $height = $this->level->getProvider()->getWorldHeight(); - foreach($this->level->getChunks() as $chunk) { - if(!$chunk->isPopulated() or !$chunk->isGenerated()) { - continue; - } - $this->getOwner()->getLogger()->info("CORRECTOR found chunk to fix"); - for($x = 0; $x <= 16; $x++) { - for($z = 0; $z <= 16; $z++) { - for($y = 0; $y <= $height; $y++) { - if($blocks < $this->bpt) { - $pos = new Vector3(($chunk->getX() << 4) + $x, $y, ($chunk->getZ() << 4) + $z); - $block = $this->level->getBlock($pos); - if(array_key_exists("{$block->getId()}:{$block->getDamage()}", $this->blockTypes)) { - $arr = explode(":",$this->blockTypes["{$block->getId()}:{$block->getDamage()}"]); - $chunk->setBlock($x, $y, $z, (int)$arr[0], (int)$arr[1]); - $this->getOwner()->getLogger()->info("CORRECTOR fixed a block!"); - $blocks++; - } - }else{ - $this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask($this, 1); - } - } - } - } - } - } -} diff --git a/BlockTypeCorrector/src/jasonwynn10/corrector/Main.php b/BlockTypeCorrector/src/jasonwynn10/corrector/Main.php index a3cf449..3d533a2 100644 --- a/BlockTypeCorrector/src/jasonwynn10/corrector/Main.php +++ b/BlockTypeCorrector/src/jasonwynn10/corrector/Main.php @@ -1,31 +1,89 @@ getServer()->getPluginManager()->registerEvents($this, $this); - $this->saveDefaultConfig(); - foreach ($this->getServer()->getLevels() as $level) { - $this->getServer()->getScheduler()->scheduleTask(new Corrector($this, $level)); - } - } - public function onTap(PlayerInteractEvent $ev) { - $this->getLogger()->info("TAPPED"); - $block = $ev->getBlock(); - $this->getLogger()->info("ID: ".$block->getId().":".$block->getDamage()); - if(array_key_exists("{$block->getId()}:{$block->getDamage()}", $this->getConfig()->get("blocks", []))) { - $arr = explode(":", $this->getConfig()->get("blocks", [])["{$block->getId()}:{$block->getDamage()}"]); - $newBlock = Block::get((int)$arr[0], (int)$arr[1]); - $ev->getPlayer()->getLevel()->setBlock($block, $newBlock,false, true); - $this->getLogger()->info("FIXED"); - $this->getLogger()->info("ID: ".$newBlock->getId().":".$newBlock->getDamage()); - }else{ - $this->getLogger()->info("KEY doesn't exist!"); - } - } + /** @var string[] $blockTypes */ + private $blockTypes = []; + + public function onEnable() : void { + $this->getServer()->getPluginManager()->registerEvents($this, $this); + $this->saveDefaultConfig(); + $this->blockTypes = $this->getConfig()->get("blocks", []); + } + + /** + * @priority MONITOR + * @ignoreCancelled false + * + * @param ChunkLoadEvent $ev + */ + public function onChunkLoad(ChunkLoadEvent $ev) : void { + $chunk = $ev->getChunk(); + if(isset($chunk->fixed)) + return; + $level = $ev->getLevel(); + for($x = 0; $x <= 16; $x++) { + for($z = 0; $z <= 16; $z++) { + for($y = 0; $y <= $chunk->getHeight(); $y++) { + $block = $level->getBlock(new Vector3(($chunk->getX() << 4) + $x, $y, ($chunk->getZ() << 4) + $z)); + $key = "{$block->getId()}:{$block->getDamage()}"; + if(array_key_exists($key, $this->blockTypes)) { + $arr = explode(":",$this->blockTypes[$key]); + $chunk->setBlock($x, $y, $z, (int)$arr[0], (int)($arr[1] ?? 0)); + } + } + } + } + $chunk->setChanged(); + $chunk->fixed = true; + } + + /** + * @priority MONITOR + * @ignoreCancelled false + * + * @param PlayerInteractEvent $ev + */ + public function onTap(PlayerInteractEvent $ev) : void { + if($ev->getPlayer()->getName() !== "jasonwynn10") + return; + $this->getLogger()->info("TAPPED"); + $block = $ev->getBlock(); + $this->getLogger()->info("ID: ".$block->getId().":".$block->getDamage()); + if(array_key_exists("{$block->getId()}:{$block->getDamage()}", $this->getConfig()->get("blocks", []))) { + $arr = explode(":", $this->getConfig()->get("blocks", [])["{$block->getId()}:{$block->getDamage()}"]); + $newBlock = Block::get((int)$arr[0], (int)$arr[1]); + $ev->getPlayer()->getLevel()->setBlock($block, $newBlock,false, false); + $this->getLogger()->info("FIXED"); + $this->getLogger()->info("ID: ".$newBlock->getId().":".$newBlock->getDamage()); + }else{ + $this->getLogger()->info("KEY doesn't exist! Attempting backup method"); + $this->fixBlockIds($block); + } + } + + public function fixBlockIds(Block $block) : void { + $replace = null; + switch($block->getId()) { + case 126: + $replace = Block::get(Block::WOODEN_SLAB, $block->getDamage()); + break; + case 125: + $replace = Block::get(Block::DOUBLE_WOODEN_SLAB, $block->getDamage()); + break; + default: + break; + } + if(isset($replace)) { + $block->getLevel()->setBlock($block, $replace, false, false); + } + } } \ No newline at end of file diff --git a/CrossOnlineCount/plugin.yml b/CrossOnlineCount/plugin.yml index 40bea8e..3576048 100644 --- a/CrossOnlineCount/plugin.yml +++ b/CrossOnlineCount/plugin.yml @@ -1,9 +1,7 @@ name: CombinedSlots main: jasonwynn10\CrossOnlineCount\Main -version: 0.1.0 -api: [3.0.0-ALPHA7] +version: 0.2.0 +api: [3.8.0] load: STARTUP author: "jasonwynn10" description: "A PocketMine plugin which checks other servers for online players and displays THE INFORMATIONvia slappers" -depend: - - Slapper \ No newline at end of file diff --git a/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/Main.php b/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/Main.php index b815e47..3d49183 100644 --- a/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/Main.php +++ b/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/Main.php @@ -1,32 +1,29 @@ getServer()->getScheduler()->scheduleRepeatingTask(new UpdateTask($this), 5); // server updates query data every 5 ticks + $this->getScheduler()->scheduleRepeatingTask(new UpdateTask($this), 5); // server updates query data every 5 ticks $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDisable() { foreach($this->getServer()->getLevels() as $level) { foreach($level->getEntities() as $entity) { - if(isset($entity->namedtag->server)) { + if(!empty($entity->namedtag->getString("server", ""))) { $lines = explode("\n", $entity->getNameTag()); - $lines[0] = $entity->namedtag->server->getValue(); + $lines[0] = $entity->namedtag->getString("server", ""); $nametag = implode("\n", $lines); $entity->setNameTag($nametag); } @@ -43,7 +40,7 @@ public function onSlapperCreate(SlapperCreationEvent $ev) { $entity = $ev->getEntity(); $lines = explode("\n", $entity->getNameTag()); if($this->isValidIP($lines[0]) or $this->is_valid_domain_name($lines[0])) { - $entity->namedtag->server = new StringTag("server", $lines[0]); + $entity->namedtag->setString("server", $lines[0]); $this->update(); } } @@ -55,8 +52,8 @@ public function onSlapperCreate(SlapperCreationEvent $ev) { */ public function onSlapperDelete(SlapperDeletionEvent $ev) { $entity = $ev->getEntity(); - if(isset($entity->namedtag->server)) { - unset($entity->namedtag->server); + if(!empty($entity->namedtag->getString("server", ""))) { + $entity->namedtag->removeTag("server"); } } @@ -66,10 +63,10 @@ public function onSlapperDelete(SlapperDeletionEvent $ev) { public function update() { foreach($this->getServer()->getLevels() as $level) { foreach($level->getEntities() as $entity) { - if(isset($entity->namedtag->server)) { - $server = explode(":", $entity->namedtag->server->getValue()); + if(!empty($entity->namedtag->getString("server", ""))) { + $server = explode(":", $entity->namedtag->getString("server", "")); try { - $queryData = PMQuery::query($server[0], $server[1]); + $queryData = PMQuery::query($server[0], $server[1]); //TODO make async $online = (int) $queryData['num']; $lines = explode("\n", $entity->getNameTag()); @@ -111,4 +108,4 @@ public function is_valid_domain_name(string $domain_name) { public function isValidIP(string $ip) { return (preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/", $ip) !== false); } -} \ No newline at end of file +} diff --git a/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/UpdateTask.php b/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/UpdateTask.php index 4370355..e22993d 100644 --- a/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/UpdateTask.php +++ b/CrossOnlineCount/src/jasonwynn10/CrossOnlineCount/UpdateTask.php @@ -1,10 +1,10 @@ getOwner()->update(); } -} \ No newline at end of file +} diff --git a/EnchantmentUI/plugin.yml b/EnchantmentUI/plugin.yml new file mode 100644 index 0000000..aee15ef --- /dev/null +++ b/EnchantmentUI/plugin.yml @@ -0,0 +1,19 @@ +name: EnchantmentUI +main: jasonwynn10\EnchUI\Main +version: 0.1.0 +api: 3.0.0-ALPHA11 +description: "A commissioned Enchantment Shop plugin" +author: "jasonwynn10" +depend: + - FormAPI + - PiggyCustomEnchants + - EconomyAPI +commands: + enchantmentshop: + description: "Opens the Enchantment Shop" + permission: "enchantmentshop.cmd" + usage: "/enchantmentshop" + aliases: ["enchshop", "enchantshop"] +permissions: + enchantmentshop.cmd: + default: true \ No newline at end of file diff --git a/EnchantmentUI/src/jasonwynn10/EnchUI/Main.php b/EnchantmentUI/src/jasonwynn10/EnchUI/Main.php new file mode 100644 index 0000000..457abf4 --- /dev/null +++ b/EnchantmentUI/src/jasonwynn10/EnchUI/Main.php @@ -0,0 +1,147 @@ +getStaticProperties()['enchantments']; + $enchantments = array_unique(array_filter($enchantments), SORT_REGULAR); + + /** @var FormAPI $formsAPI */ + $formsAPI = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); + $form = $formsAPI->createSimpleForm(function(Player $player, $data) use ($enchantments) { + $i = 0; + foreach($enchantments as $enchantment) { + if($i === $data) { + $dataStore = Main::getFromDataStore($player); + $dataStore[] = $enchantment->getId(); + Main::setToDataStore($player, $dataStore); + break; + } + $i++; + } + + /** @var FormAPI $formsAPI */ + $formsAPI = Server::getInstance()->getPluginManager()->getPlugin("FormAPI"); + $form = $formsAPI->createCustomForm(function(Player $player, $data) { + + $dataStore = Main::getFromDataStore($player); + $dataStore[] = (int) $data[0]; + $dataStore[] = (int) (((int) $data[0]) * 5000000); + Main::setToDataStore($player, $dataStore); + /** @var FormAPI $formsAPI */ + $formsAPI = Server::getInstance()->getPluginManager()->getPlugin("FormAPI"); + + $economy = EconomyAPI::getInstance(); + $money = $economy->myMoney($player); + if($money - $dataStore[2] < 0) { + $form = $formsAPI->createCustomForm(); + $form->setTitle("Enchantment Shop"); + $form->addLabel("You don't have enough money to buy that!"); + }else{ + $form = $formsAPI->createModalForm(function(Player $player, $data) { + if($data) { + $dataStore = Main::getFromDataStore($player); + $enchantment = CustomEnchants::getEnchantment($dataStore[0]); + if($enchantment !== null) { + $inventory = $player->getInventory(); + $item = $inventory->getItemInHand(); + $item->addEnchantment(new EnchantmentInstance($enchantment, $dataStore[1])); + $inventory->setItemInHand($item); + $inventory->sendHeldItem($inventory->getHolder()->getLevel()->getPlayers()); + $inventory->sendContents($inventory->getHolder()); + $economy = EconomyAPI::getInstance(); + $economy->reduceMoney($player, $dataStore[2], false, "EnchantmentShop"); + $player->sendMessage(TextFormat::GREEN."Enchantment Purchased!"); + }else{ + $player->sendMessage(TextFormat::RED."There was an error! That enchantment doesn't exist!"); + } + } + }); + $form->setTitle("Enchantment Shop"); + $form->setContent("Do you accept your charge of " . $economy->getConfig()->get("monetary-unit", "$") . $dataStore[2] . "?"); + $form->setButton1("Yes, I accept the charge"); + $form->setButton2("No, I don't want to pay for this"); + } + $form->sendToPlayer($player); + }); + $form->setTitle("Enchantment Shop"); + $form->addSlider("Enchantment Level", 1, (int) (((int) EconomyAPI::getInstance()->getConfig()->get("max-money", 9999999999)) / 5000000)); + $form->sendToPlayer($player); + }); + $form->setTitle("Enchantment Shop"); + $form->setContent("Choose an enchantment to add to your item"); + + foreach($enchantments as $enchantment) { + $form->addButton($enchantment->getName()); + } + $form->sendToPlayer($sender); + } + return true; + } + + /** + * @param Player $player + * + * @return array + */ + public static function createPlayerDataStore(Player $player) : array { + static::$dataStore[$player->getName()] = []; + return static::$dataStore[$player->getName()]; + } + + /** + * @param Player $player + * + * @return array + */ + public static function getFromDataStore(Player $player) : array { + return static::$dataStore[$player->getName()]; + } + + /** + * @param Player $player + * @param array $data + */ + public static function setToDataStore(Player $player, array $data) : void { + static::$dataStore[$player->getName()] = $data; + } + + /** + * @param Player $player + */ + public static function clearFromDataStore(Player $player) : void { + unset(static::$dataStore[$player->getName()]); + } +} \ No newline at end of file diff --git a/Masks/plugin.yml b/Masks/plugin.yml new file mode 100644 index 0000000..782a908 --- /dev/null +++ b/Masks/plugin.yml @@ -0,0 +1,17 @@ +name: Masks +main: jasonwynn10\masks\Main +version: 0.1.0 +api: 3.0.0-ALPHA11 +description: "A commissioned mask effects plugin" +author: "jasonwynn10" +depend: + - FormAPI +commands: + masksetup: + description: "Opens the mask settings GUI" + usage: "/masksetup" + permission: "maskSetup" +permissions: + maskSetup: + default: op + description: "" \ No newline at end of file diff --git a/Masks/resources/config.yml b/Masks/resources/config.yml new file mode 100644 index 0000000..06238dd --- /dev/null +++ b/Masks/resources/config.yml @@ -0,0 +1,105 @@ +Zombie Mask: + Speed: 3 + Slowness: 0 + Haste: 5 + Fatigue: 0 + Strength: 5 + Jump: 0 + Nausea: 0 + Regeneration: 0 + Resistance: 0 + Fire Resistance: 0 + Water Breathing: 0 + Invisibility: 0 + Blindness: 0 + Night Vision: 0 + Weakness: 0 + Poison: 0 + Wither: 0 + Health Boost: 0 + Flight: false + Poison Attacks: 0 +Skeleton Mask: + Speed: 4 + Slowness: 0 + Haste: 5 + Fatigue: 0 + Strength: 5 + Jump: 0 + Nausea: 0 + Regeneration: 0 + Resistance: 0 + Fire Resistance: 0 + Water Breathing: 0 + Invisibility: 0 + Blindness: 0 + Night Vision: 0 + Weakness: 0 + Poison: 0 + Wither: 0 + Health Boost: 0 + Flight: true + Poison Attacks: 0 +Creeper Mask: + Speed: 3 + Slowness: 0 + Haste: 5 + Fatigue: 0 + Strength: 5 + Jump: 0 + Nausea: 0 + Regeneration: 5 + Resistance: 0 + Fire Resistance: 0 + Water Breathing: 0 + Invisibility: 0 + Blindness: 0 + Night Vision: 0 + Weakness: 0 + Poison: 0 + Wither: 0 + Health Boost: 0 + Flight: true + Poison Attacks: 0 +Dragon Mask: + Speed: 3 + Slowness: 0 + Haste: 5 + Fatigue: 0 + Strength: 5 + Jump: 0 + Nausea: 0 + Regeneration: 0 + Resistance: 0 + Fire Resistance: 0 + Water Breathing: 0 + Invisibility: 0 + Blindness: 0 + Night Vision: 0 + Weakness: 0 + Poison: 0 + Wither: 0 + Health Boost: 0 + Flight: true + Poison Attacks: 0 +No Mask: + Speed: 3 + Slowness: 0 + Haste: 5 + Fatigue: 0 + Strength: 5 + Jump: 0 + Nausea: 0 + Regeneration: 0 + Resistance: 0 + Fire Resistance: 0 + Water Breathing: 0 + Invisibility: 0 + Blindness: 0 + Night Vision: 0 + Weakness: 0 + Poison: 0 + Wither: 0 + Health Boost: 0 + Flight: true + Poison Attacks: 0 \ No newline at end of file diff --git a/Masks/src/jasonwynn10/masks/Main.php b/Masks/src/jasonwynn10/masks/Main.php new file mode 100644 index 0000000..47c3af6 --- /dev/null +++ b/Masks/src/jasonwynn10/masks/Main.php @@ -0,0 +1,443 @@ +saveDefaultConfig(); + $this->getServer()->getPluginManager()->registerEvents($this, $this); + self::$insance = $this; + } + + /** + * @param EntityArmorChangeEvent $event + * @throws \ReflectionException + */ + public function onMask(EntityArmorChangeEvent $event) { + $entity = $event->getEntity(); + if($entity instanceof Player) { + $mask = $event->getNewItem(); + /** @noinspection PhpUnhandledExceptionInspection */ + $class = new \ReflectionClass(Effect::class); + if($mask->getId() === Item::MOB_HEAD) { + switch($mask->getDamage()) { + case 0: //SKELETON + $settings = $this->getConfig()->getNested("Skeleton Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $entity->setAllowFlight(true); + }else { + $entity->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $entity->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $entity->removeEffect($value); + } + break; + } + } + } + break; + case 2: //ZOMBIE + $settings = $this->getConfig()->getNested("Zombie Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $entity->setAllowFlight(true); + }else { + $entity->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $entity->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $entity->removeEffect($value); + } + break; + } + } + } + break; + case 4: //CREEPER + $settings = $this->getConfig()->getNested("Creeper Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $entity->setAllowFlight(true); + }else { + $entity->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $entity->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $entity->removeEffect($value); + } + break; + } + } + } + break; + case 5: //DRAGON + $settings = $this->getConfig()->getNested("Dragon Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $entity->setAllowFlight(true); + }else { + $entity->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $entity->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $entity->removeEffect($value); + } + break; + } + } + } + break; + default: + $settings = $this->getConfig()->getNested("No Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $entity->setAllowFlight(true); + }else { + $entity->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $entity->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $entity->removeEffect($value); + } + break; + } + } + } + break; + } + }elseif($event->getOldItem()->getId() === Item::MOB_HEAD) { + $entity->removeAllEffects(); + $entity->setAllowFlight(false); + } + } + } + + /** + * @param EntityDamageEvent $event + */ + public function onDamage(EntityDamageEvent $event) { + if($event instanceof EntityDamageByEntityEvent) { + $damager = $event->getDamager(); + $damaged = $event->getEntity(); + if($damager instanceof Player and $damaged instanceof Living) { + $mask = $damager->getArmorInventory()->getHelmet(); + if($mask->getId() === Item::MOB_HEAD) { + switch($mask->getDamage()) { + case 0: //SKELETON + $settings = $this->getConfig()->getNested("Skeleton Mask", []); + if($settings["Poison Attacks"] > 0) { + $damaged->addEffect(Effect::getEffect(Effect::POISON)->setDuration(INT32_MAX)->setAmplifier($settings["Poison Attacks"])); + } + break; + case 2: //ZOMBIE + $settings = $this->getConfig()->getNested("Zombie Mask", []); + if($settings["Poison Attacks"] > 0) { + $damaged->addEffect(Effect::getEffect(Effect::POISON)->setDuration(INT32_MAX)->setAmplifier($settings["Poison Attacks"])); + } + break; + case 4: //CREEPER + $settings = $this->getConfig()->getNested("Creeper Mask", []); + if($settings["Poison Attacks"] > 0) { + $damaged->addEffect(Effect::getEffect(Effect::POISON)->setDuration(INT32_MAX)->setAmplifier($settings["Poison Attacks"])); + } + break; + case 5: //DRAGON + $settings = $this->getConfig()->getNested("Dragon Mask", []); + if($settings["Poison Attacks"] > 0) { + $damaged->addEffect(Effect::getEffect(Effect::POISON)->setDuration(INT32_MAX)->setAmplifier($settings["Poison Attacks"])); + } + break; + default: + $settings = $this->getConfig()->getNested("No Mask", []); + if($settings["Poison Attacks"] > 0) { + $damaged->addEffect(Effect::getEffect(Effect::POISON)->setDuration(INT32_MAX)->setAmplifier($settings["Poison Attacks"])); + } + break; + } + }elseif($mask->getId() === Item::AIR) { + $settings = $this->getConfig()->getNested("No Mask", []); + if($settings["Poison Attacks"] > 0) { + $damaged->addEffect(Effect::getEffect(Effect::POISON)->setDuration(INT32_MAX)->setAmplifier($settings["Poison Attacks"])); + } + } + } + } + } + + public function onTap(PlayerInteractEvent $event) { + if($event->getItem()->getId() === Item::BOOK) { + $player = $event->getPlayer(); + $inventory = $player->getInventory(); + $rand = mt_rand(1, 100); + $item = Item::get(Item::MOB_HEAD); + if($rand <= 20) { + $inventory->setItemInHand($item->setDamage(0)); + }elseif($rand > 20 and $rand <= 40) { + $inventory->setItemInHand($item->setDamage(2)); + }elseif($rand > 40 and $rand <= 60) { + $inventory->setItemInHand($item->setDamage(4)); + }elseif($rand > 60 and $rand <= 80) { + $inventory->setItemInHand($item->setDamage(5)); + }elseif($rand > 80 and $rand <= 100) { + $inventory->setItemInHand($item->setDamage(mt_rand(0, 6))); // TODO: make better + } + $inventory->sendHeldItem($inventory->getHolder()->getLevel()->getPlayers()); + $inventory->sendContents($inventory->getHolder()); + } + } + + /** + * @param CommandSender $sender + * @param Command $command + * @param string $label + * @param array $args + * @return bool + */ + public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool { + if($sender instanceof Player) { + $config = $this->getConfig(); + /** @var FormAPI $formsAPI */ + $formsAPI = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); + $form = $formsAPI->createCustomForm(function(Player $player, $data) use ($config) { + if(empty($data)) { + return; + } + $settingsArray = array_chunk($data, 21); + $endSettings = []; + foreach($settingsArray as $key => $settings) { + switch($key) { + case 0: + $mask = "Zombie Mask"; + break; + case 1: + $mask = "Skeleton Mask"; + break; + case 2: + $mask = "Creeper Mask"; + break; + case 3: + $mask = "Dragon Mask"; + break; + default: + $mask = "No mask"; + break; + } + $endSettings[$mask]["Speed"] = (int) $settings[1]; + $endSettings[$mask]["Slowness"] = (int) $settings[2]; + $endSettings[$mask]["Haste"] = (int) $settings[3]; + $endSettings[$mask]["Fatigue"] = (int) $settings[4]; + $endSettings[$mask]["Strength"] = (int) $settings[5]; + $endSettings[$mask]["Jump"] = (int) $settings[6]; + $endSettings[$mask]["Nausea"] = (int) $settings[7]; + $endSettings[$mask]["Regeneration"] = (int) $settings[8]; + $endSettings[$mask]["Resistance"] = (int) $settings[9]; + $endSettings[$mask]["Fire Resistance"] = (int) $settings[10]; + $endSettings[$mask]["Water Breathing"] = (int) $settings[11]; + $endSettings[$mask]["Invisibility"] = (int) $settings[12]; + $endSettings[$mask]["Blindness"] = (int) $settings[13]; + $endSettings[$mask]["Night Vision"] = (int) $settings[14]; + $endSettings[$mask]["Weakness"] = (int) $settings[15]; + $endSettings[$mask]["Poison"] = (int) $settings[16]; + $endSettings[$mask]["Wither"] = (int) $settings[17]; + $endSettings[$mask]["Health Boost"] = (int) $settings[18]; + $endSettings[$mask]["Flight"] = (bool) $settings[19]; + $endSettings[$mask]["Poison Attacks"] = (int) $settings[20]; + } + $config->setAll($endSettings); + $config->save(); + }); + $form->setTitle("Mask Settings"); + + foreach($config->getAll() as $mask => $settings) { + $form->addLabel($mask . " Settings"); + foreach($settings as $setting => $value) { + if($setting === "Flight") { + $form->addToggle($setting, (bool) $value); + }else { + $form->addSlider($setting, 0, 100, -1, $value); + } + } + } + $form->sendToPlayer($sender); + } + return true; + } + + public static function liveUpdateEffects() { + foreach(Server::getInstance()->getOnlinePlayers() as $player) { + $player->removeAllEffects(); + $mask = $player->getArmorInventory()->getHelmet(); + /** @noinspection PhpUnhandledExceptionInspection */ + $class = new \ReflectionClass(Effect::class); + if($mask->getId() === Item::MOB_HEAD) { + switch($mask->getDamage()) { + case 0: //SKELETON + $settings = self::$insance->getConfig()->getNested("Skeleton Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $player->setAllowFlight(true); + }else { + $player->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $player->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $player->removeEffect($value); + } + break; + } + } + } + break; + case 2: //ZOMBIE + $settings = self::$insance->getConfig()->getNested("Zombie Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $player->setAllowFlight(true); + }else { + $player->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $player->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $player->removeEffect($value); + } + break; + } + } + } + break; + case 4: //CREEPER + $settings = self::$insance->getConfig()->getNested("Creeper Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $player->setAllowFlight(true); + }else { + $player->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $player->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $player->removeEffect($value); + } + break; + } + } + } + break; + case 5: //DRAGON + $settings = self::$insance->getConfig()->getNested("Dragon Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $player->setAllowFlight(true); + }else { + $player->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $player->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $player->removeEffect($value); + } + break; + } + } + } + break; + default: + $settings = self::$insance->getConfig()->getNested("No Mask", []); + foreach($settings as $setting => $amplifier) { + if($setting === "Flight") { + if($amplifier == true) { + $player->setAllowFlight(true); + }else { + $player->setAllowFlight(false); + } + continue; + } + foreach($class->getConstants() as $name => $value) { + if(strpos(strtolower($setting), str_replace("_", " ", strtolower($name))) !== false) { + if($amplifier > 0) { + $player->addEffect(Effect::getEffect($value)->setDuration(INT32_MAX)->setAmplifier($amplifier)); + }else { + $player->removeEffect($value); + } + break; + } + } + } + break; + } + } + } + } +} \ No newline at end of file