Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Commit

Permalink
Move XP Handling to PMMP + Discord Badge
Browse files Browse the repository at this point in the history
Remove Deprecated XPOrb entity
Transfer everything that'd using the old XP Utilities class to PMMP... // close #158
Add Discord badge to README
Remove unused 'use' statement in EndCrystal

TODO: Add better XP LootTable

                                  `-
                           h+    -my
                         `dM+  `oMM-
                        /NMM+ :mMN/
                     -sNMMMMhmMMMhhdddddys/-
                 -+hNMMMMMMMMMMMMMMMMMMMMMMMNy:
           `:oymMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd:
        -odMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy`
      .dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd.
     :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN:
     mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMs`
    :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm/
    yMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm+`
    hMMMMMMMMd/mMMMMMMMMMMMNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh/`
    dMMMMMMMMy.-sMMMMMMMMMN-yMMMMMMMMMMMMMMMMMMMMMMMMMMMhhmNMMms
    yMMMMMMMMs..oMMMMMMMMM/.-omMMMMMMMMMMMMMMMMMMMMMMMMMs    `
    :MMMMMMMMh..oMMMMMMMNds/-hosNMMMMMMmNMMMMMMMMMMMMMMMh
     /NMMMMMMN..oMMMMMMm-+Myhhmy-sNMMMMs.+dMMMMMMMMMMMMMd
      .sNMMMMMo.+MMMMMm-.-dh:+oMmyoyMMMs...+NMMMMMMMMMMMN`
        oMMMMMN::MMMMM:.../moy-mMMMMNMMs..-+sMMMMMMMMMMMM+
    .ysyNMMMMMMNsNMMMd......:oyNMMMmd/MNsys/-:NdyMMMMMMMMN-
     -shdsoMMMMMMMMMMh..........:/-...om-s/NNhhmoMMMMMMMMMN/
          .MMMMMMMMMMh......+/........-/sdsdMMMMMMMMMMMMMMMMy.
           mMMMNMMMMMN-..../mNds/.........-/shyMMMMMMd:sdMMMMMy-
           +MMmsMMMysMh....-mddmmmyssso:.....+NMMMMMm`   `/oydmmy`
       .+ssodMN.NMM/.-/.-..-Ndddmh-oo/-.....sMMMMMMN.
    -ohddddmmmNmmM+.....+h+.-oo+:........:smMMMNNMM-
 -sdmddmmmmNNmmNNo........+yyo/--.--:+oss+hMMNs`:NN`
hmhhmNmdhmdmhNNNmo........./o.:/++++/-` `hMm+`   .h:
mdmmmNhhdNmNdmmNdN-......`oms`         /ho-
mNdhdNmmNmNdmNmNNNh``...`/Nmmmso/`
dmhmNNdhdmdddMmmdmmo`````oNNdMmdmmy.
dNmmdmdmmNddmNmNmNdN+````+NNNMddNmmN:
mmdmmNMNNmmmNmmmmmmdNo``-NNdNmmddNNmN-
dNmmdmddmNddmNmNmmdNo....+NNNNddNmmN:
mmdddNNNmdmmNmmmmmddNo..:NmdNmmddNNmN-

 ~~ kewl commit message sig huh. lolz
  • Loading branch information
CortexPE committed Jan 6, 2018
1 parent b12453a commit 69c1958
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 214 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>TeaSpoon<img src="https://raw.githubusercontent.com/CortexPE/stuff/master/TeaSpoonLogo.png" height="64" width="64" align="left"></img></h1>
<br />

[![Build Status](http://cortexpe.xyz:8080/job/TeaSpoon/badge/icon)](http://cortexpe.xyz:8080/job/TeaSpoon/) [![Poggit](https://poggit.pmmp.io/ci.shield/CortexPE/TeaSpoon/~)](https://poggit.pmmp.io/ci/CortexPE/TeaSpoon/~) [![Donate](https://img.shields.io/badge/donate-PayPal-yellow.svg?style=flat-square)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MABFZPDR8F5UG) [![HitCount](http://hits.dwyl.io/CortexPE/TeaSpoon.svg)](http://hits.dwyl.io/CortexPE/TeaSpoon) [![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/CortexPE/TeaSpoon/pulls) [![License](https://img.shields.io/badge/License-GNU%20AGPL%20v3-brightgreen.svg?style=flat-square)](https://github.com/CortexPE/TeaSpoon/blob/master/LICENSE)
[![Build Status](http://cortexpe.xyz:8080/job/TeaSpoon/badge/icon)](http://cortexpe.xyz:8080/job/TeaSpoon/) [![Poggit](https://poggit.pmmp.io/ci.shield/CortexPE/TeaSpoon/~)](https://poggit.pmmp.io/ci/CortexPE/TeaSpoon/~) [![Donate](https://img.shields.io/badge/donate-PayPal-yellow.svg?style=flat-square)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MABFZPDR8F5UG) [![HitCount](http://hits.dwyl.io/CortexPE/TeaSpoon.svg)](http://hits.dwyl.io/CortexPE/TeaSpoon) [![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/CortexPE/TeaSpoon/pulls) [![License](https://img.shields.io/badge/license-GNU%20AGPL%20v3-brightgreen.svg?style=flat-square)](https://github.com/CortexPE/TeaSpoon/blob/master/LICENSE) [![Discord](https://img.shields.io/discord/350333413737365522.svg?style=flat-square&label=discord%20chat)](https://discord.gg/QA3eSjw)

A Massive PocketMine-MP plugin designed and is aiming to extend PMMP's functionalities (Without completely changing it) to Make it more Vanilla-Like.

Expand Down
4 changes: 2 additions & 2 deletions src/CortexPE/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function onCheat(PlayerIllegalMoveEvent $ev){
public function onEntityDeath(EntityDeathEvent $ev){
$xp = Xp::getXpDropsForEntity($ev->getEntity());
if($xp > 0){
Xp::spawnXpOrb($ev->getEntity()->getPosition(), $ev->getEntity()->getLevel(), $xp);
$ev->getEntity()->getLevel()->dropExperience($ev->getEntity()->asVector3(), $xp);
}
}

Expand All @@ -270,7 +270,7 @@ public function onBlockBreak(BlockBreakEvent $ev){
if($ev->isCancelled()) return;
$xp = Xp::getXpDropsForBlock($ev->getBlock());
if($xp > 0){
Xp::spawnXpOrb($ev->getBlock(), $ev->getBlock()->getLevel(), $xp);
$ev->getPlayer()->getLevel()->dropExperience($ev->getBlock()->asVector3(), $xp);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/CortexPE/entity/EndCrystal.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\Server;

class EndCrystal extends Entity {
const NETWORK_ID = self::ENDER_CRYSTAL;
Expand Down
1 change: 0 additions & 1 deletion src/CortexPE/entity/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public static function init(): void{
self::registerEntity(Arrow::class, true, ['Arrow', 'minecraft:arrow']);

// Other Entities ////
self::registerEntity(XPOrb::class, true, ['XPOrb', 'minecraft:xporb']);
self::registerEntity(AreaEffectCloud::class, true, ['AreaEffectCloud', 'minecraft:areaeffectcloud']);
self::registerEntity(Lightning::class, true, ['Lightning', 'minecraft:lightning']);
self::registerEntity(EndCrystal::class, true, ['EnderCrystal', 'minecraft:ender_crystal']);
Expand Down
144 changes: 0 additions & 144 deletions src/CortexPE/entity/XPOrb.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/CortexPE/entity/projectile/EnchantingBottle.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
namespace CortexPE\entity\projectile;

use CortexPE\level\particle\SpellParticle;
use CortexPE\utils\Xp;
use pocketmine\entity\{
Entity, projectile\Throwable
};
Expand All @@ -57,7 +56,7 @@ public function onUpdate(int $currentTick): bool{
$randomY = self::RAND_POS_Y[array_rand(self::RAND_POS_Y)];
$randomZ = self::RAND_POS_Z[array_rand(self::RAND_POS_Z)];

Xp::spawnXpOrb($this->add($randomX, $randomY, $randomZ), $this->getLevel(), mt_rand(1, 4));
$this->getLevel()->dropExperience($this->add($randomX, $randomY, $randomZ), mt_rand(1,4));
}
$this->kill();
}
Expand Down
4 changes: 2 additions & 2 deletions src/CortexPE/item/FishingRod.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use CortexPE\Session;
use CortexPE\Utils;
use CortexPE\utils\FishingLootTable;
use CortexPE\utils\Xp;
use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Projectile;
Expand Down Expand Up @@ -152,7 +151,8 @@ public function onClickAir(Player $player, Vector3 $directionVector): bool{
}
$item = FishingLootTable::getRandom($lvl);
$player->getInventory()->addItem($item);
Xp::addXp($player, mt_rand(1, 6));

$player->addXp(mt_rand(1, 6));
}

$projectile->flagForDespawn();
Expand Down
64 changes: 3 additions & 61 deletions src/CortexPE/utils/Xp.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,67 +36,21 @@
namespace CortexPE\utils;

use CortexPE\entity\Lightning;
use CortexPE\entity\XPOrb;
use CortexPE\Utils;
use pocketmine\block\Block;
use pocketmine\entity\Animal;
use pocketmine\entity\Entity;
use pocketmine\entity\Human;
use pocketmine\entity\Monster;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\Player;

class Xp extends Utils {
// [ROT13 Encoded and is pretty Explicit] Jul gur shpx unfa'g CZZC Vzcyrzragrq n CEBCRE KC Flfgrz Lrg? Guvf vf Shpxvat fghcvq naq vf bar bs gur znal ernfbaf jul Crbcyr ybir fcbbaf -_-
// hacky code to *SOMEHOW* get it working...

// TODO: Base it all from this list: https://minecraft.gamepedia.com/Experience#Experience_amounts_by_source

public static function addXp(Player $player, int $amount){
$add = self::getLevelFromXp($player->getTotalXp() + $amount);
$player->setXpProgress($add[1]);
$player->setXpLevel(intval($player->getXpLevel() + round($player->getXpProgress())));
self::saveData($player);
}

private static function saveData(Player $player){
if(!isset($player->namedtag->XpLevel) or !($player->namedtag->XpLevel instanceof IntTag)){
$player->namedtag->XpLevel = new IntTag("XpLevel", $player->getXpLevel());
}else{
$player->namedtag["XpLevel"] = $player->getXpLevel();
}

if(!isset($player->namedtag->XpP) or !($player->namedtag->XpP instanceof FloatTag)){
$player->namedtag->XpP = new FloatTag("XpP", $player->getXpProgress());
}else{
$player->namedtag["XpP"] = $player->getXpProgress();
}

if(!isset($player->namedtag->XpTotal) or !($player->namedtag->XpTotal instanceof IntTag)){
$player->namedtag->XpTotal = new IntTag("XpTotal", $player->getTotalXp());
}else{
$player->namedtag["XpTotal"] = $player->getTotalXp();
}
$player->getServer()->saveOfflinePlayerData($player->getName(), $player->namedtag, true);
}

public static function takeXp(Player $player, int $amount){
if(($player->getTotalXp() - $amount) >= 0){
$add = self::getLevelFromXp($player->getTotalXp() - $amount);
$player->setXpProgress($add[1]);
$player->setXpLevel(intval($player->getXpLevel() + round($player->getXpProgress())));
self::saveData($player);
}
}

public static function getXpDropsForEntity(Entity $e): int{
switch($e::NETWORK_ID){
case Lightning::NETWORK_ID:
return 0;
default:
case Human::NETWORK_ID: // Handled by PMMP ;)
return 0;
default: // todo: add proper XP Drop table
if($e instanceof Monster){
switch($e->getName()){
default:
Expand All @@ -107,8 +61,6 @@ public static function getXpDropsForEntity(Entity $e): int{
default:
return mt_rand(1, 3);
}
}elseif($e instanceof Human){
return 7;
}

return 0;
Expand Down Expand Up @@ -138,14 +90,4 @@ public static function getXpDropsForBlock(Block $b): int{
return 0;
}
}

public static function spawnXpOrb(Vector3 $pos, Level $lvl, int $exp): XPOrb{
$nbt = XPOrb::createBaseNBT($pos);
$nbt->setLong("Experience", $exp);
/** @var XPOrb $entity */
$entity = Entity::createEntity("XPOrb", $lvl, $nbt);
$entity->spawnToAll();

return $entity;
}
}

0 comments on commit 69c1958

Please sign in to comment.