Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

No Drops

Comments in 'Plugin Development' started by Devin5411, Oct 15, 2016.

  1. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    I made a Mob stacking plugin, but the mobs don't drop anything?

    Can someone help?

    Attached Files:

  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Please give us the source code directly
  3. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT

    Attached Files:

  4. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Pleas show your code in chat
  5. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    What?
  6. Devin5411
    Offline

    Devin5411 Active Member

    Joined:
    Oct 9, 2014
    Posts:
    113
    Minecraft User:
    MC_DevinYT
    PHP:
    <?php __HALT_COMPILER(); ?>
                        resources/Settings.yml’  wX’  Œ½î¶      #   src/stackingmobs/StackHeartbeat.phpø  wXø  Qµ¶      !   src/stackingmobs/StackFactory.php  wX  yl궠        src/stackingmobs/Main.phpØ
      wXØ
      ®p‚¶      "   src/stackingmobs/EventListener.php  wX  #=PE¶         Settings.yml’  wX’  Œ½î¶     
       plugin.ymlv   wXv   ØV§Û¶      # StackingMobs v0.0.1 Settings.yml config file
    #
    stack-format: "&l&e{name}&r\n&l&ex{amount}&r"
    #
    # How many blocks out can mobs stack from?
    stacking-range: 8
    #
    # Should a mob look for a mob stack as soon as they spawn?
    spawn-stack: true
    #
    # Period between checking all mobs for nearby stacks (seconds)
    stack-delay: 10
    #
    # Levels to check mobs for stacking (names are cAsE sEnSiTiVe)
    levels:
      - "world"<?php

    /*
    * StackingMobs Plugin
    *
    * Copyright (C) 2016 DevinDaBomb11
    *
    * This is private software, you cannot redistribute and/or modify it in any way
    * unless otherwise given permission to do so. If you have not been given explicit
    * permission to view or modify this software you should take the appropriate actions
    * to remove this software from your device immediately.
    *
    * @author DevinDaBomb11
    *
    * Created on 8/08/2016 at 6:49 PM
    *
    */

    namespace stackingmobs;

    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\entity\Living;
    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;

    /**
    * Task that loops through all entities and attempts to stack them
    */
    class StackHeartbeat extends PluginTask {

        
    /** @var Main */
        
    private $plugin;

        
    /** @var int */
        
    private $stackingRange 8;

        
    /** @var array */
        
    protected $levels = [];

        
    /**
         * StackHeartBeat constructor
         *
         * @param Main $plugin
         */
        
    public function __construct(Main $plugin) {
            
    parent::__construct($plugin);
            
    $this->plugin $plugin;
            
    $this->levels $plugin->getSettings()->get("levels", []);
            
    $plugin->getServer()->getScheduler()->scheduleRepeatingTask($this, (int) $plugin->getSettings()->get("stack-delay"10) * 20);
        }

        
    /**
         * @param $tick
         */
        
    public function onRun($tick) {
            foreach(
    $this->plugin->getServer()->getLevels() as $level) {
                if(!
    in_array($level->getName(), $this->levels)) continue;
                foreach(
    $level->getEntities() as $e) {
                    if((
    $e instanceof Player or !$e instanceof Living) or ($e->getDataProperty(Entity::DATA_NO_AI) == true false)) continue;
                    if(
    StackFactory::addToClosestStack($e$this->stackingRange$this->plugin->getSettings())) $this->plugin->getLogger()->debug("Added entity ({$e->getId()}) to the closest stack successfully!");
                }
            }
        }

    }<?
    php

    /*
    * StackingMobs Plugin
    *
    * Copyright (C) 2016 DevinDaBomb11
    *
    * This is private software, you cannot redistribute and/or modify it in any way
    * unless otherwise given permission to do so. If you have not been given explicit
    * permission to view or modify this software you should take the appropriate actions
    * to remove this software from your device immediately.
    *
    * @author DevinDaBomb11
    *
    * Created on 8/08/2016 at 6:49 PM
    *
    */

    namespace stackingmobs;

    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\entity\Item;
    use 
    pocketmine\entity\Living;
    use 
    pocketmine\event\entity\EntityDeathEvent;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\utils\Config;

    /**
    * The amazing class that does all the fancy stacking crap
    */
    class StackFactory {

        
    /**
         * Check if an entity is a stack
         *
         * @param mixed $entity
         *
         * @return bool
         */
        
    public static function isStack($entity) {
            return 
    $entity instanceof Living and (!$entity instanceof Item) and isset($entity->namedtag->StackData);
        }

        
    /**
         * Get the size of an entity stack
         *
         * @param Living $entity
         *
         * @return int
         */
        
    public static function getStackSize(Living $entity) {
            
    assert(self::isStack($entity));

            if(isset(
    $entity->namedtag->StackData->Amount) and $entity->namedtag->StackData->Amount instanceof IntTag) {
                return 
    $entity->namedtag->StackData["Amount"];
            }
            return 
    1;
        }

        
    /**
         * Increase the size of a stack
         *
         * @param Living $entity
         * @param int $amount
         *
         * @return bool
         */
        
    public static function increaseStackSize(Living $entity$amount 1) {
            if(
    self::isStack($entity) and isset($entity->namedtag->StackData->Amount)) {
                
    $entity->namedtag->StackData->Amount->setValue(self::getStackSize($entity) + $amount);
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Living $entity
         * @param int $amount
         *
         * @return bool
         */
        
    public static function decreaseStackSize(Living $entity$amount 1) {
            if(
    self::isStack($entity) and isset($entity->namedtag->StackData->Amount)) {
                
    $entity->namedtag->StackData->Amount->setValue(self::getStackSize($entity) - $amount);
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Living $entity
         * @param int $count
         */
        
    public static function createStack(Living $entity$count 1) {
            
    $entity->namedtag->StackData = new CompoundTag("StackData", [
                
    "Amount" => new IntTag("Amount"$count),
            ]);
        }

        
    /**
         * Attempt to add an entity to a stack
         *
         * @param Living $stack
         * @param Living $entity
         *
         * @return bool
         */
        
    public static function addToStack(Living $stackLiving $entity) {
            if(
    is_a($entityget_class($stack)) and $stack !== $entity) {
                if(
    self::increaseStackSize($stackself::getStackSize($entity))) {
                    
    $entity->close();
                    return 
    true;
                }
            }
            return 
    false;
        }

        
    /**
         * Attempt to kill one entity from a stack
         *
         * @param Living $entity
         *
         * @return bool
         */
        
    public static function removeFromStack(Living $entity) {
            
    assert(self::isStack($entity));

            if(
    self::decreaseStackSize($entity)) {
                if(
    self::getStackSize($entity) <= 0) return false;
                
    $level $entity->getLevel();
                
    $pos = new Vector3($entity->z$entity->y$entity->z);
                
    $server $level->getServer();
                
    $server->getPluginManager()->callEvent($ev = new EntityDeathEvent($entity$entity->getDrops()));
                foreach(
    $ev->getDrops() as $drops) {
                    
    $level->dropItem($pos$drops);
                }
                if(
    $server->expEnabled) {
                    
    $exp mt_rand($entity->getDropExpMin(), $entity->getDropExpMax());
                    if(
    $exp 0$level->spawnXPOrb($entity$exp);
                }
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Living $entity
         * @param Config $settings
         */
        
    public static function recalculateStackName(Living $entityConfig $settings) {
            
    assert(self::isStack($entity));

            
    $count self::getStackSize($entity);
            
    $entity->setNameTagVisible(true);
            
    $entity->setNameTag(str_replace(["{name}""{amount}"], [$entity->getName(), $count], Main::translateColors($settings->get("stack-format"))));
        }

        
    /**
         * Finds the closest stack near an entity
         *
         * @param Living $entity
         * @param int $range
         *
         * @return null|Living
         */
        
    public static function findNearbyStack(Living $entity$range 8) {
            
    $stack null;
            
    $closest $range;
            
    $bb $entity->getBoundingBox();
            
    $bb $bb->grow($range$range$range);
            foreach(
    $entity->getLevel()->getCollidingEntities($bb) as $e) {
                if(
    is_a($eget_class($entity)) and $stack !== $entity) {
                    
    $distance $e->distance($entity);
                    if(
    $distance $closest) {
                        if(!
    self::isStack($e) and self::isStack($stack)) continue;
                        
    $closest $distance;
                        
    $stack $e;
                    }
                }
            }
            return 
    $stack;
        }

        
    /**
         * Add the entity to the closest stack or turn the entity into a stack
         *
         * @param Living $entity
         * @param int $range
         * @param Config $settings
         *
         * @return bool
         */
        
    public static function addToClosestStack(Living $entity$range 8Config $settings) {
            
    $stack self::findNearbyStack($entity$range);
                if(
    self::isStack($stack)) {
                    if(
    self::addToStack($stack$entity)) {
                        
    self::recalculateStackName($stack$settings);
                        return 
    true;
                    }
                } else {
                    if(
    $stack instanceof Living) {
                        
    self::createStack($stack);
                        
    self::addToStack($stack$entity);
                        
    self::recalculateStackName($stack$settings);
                        return 
    true;
                    }
                }
            return 
    false;
        }

    }<?
    php

    /*
    * StackingMobs Plugin
    *
    * Copyright (C) 2016 DevinDaBomb11
    *
    * This is private software, you cannot redistribute and/or modify it in any way
    * unless otherwise given permission to do so. If you have not been given explicit
    * permission to view or modify this software you should take the appropriate actions
    * to remove this software from your device immediately.
    *
    * @author DevinDaBomb11
    *
    * Created on 8/08/2016 at 6:49 PM
    *
    */

    namespace stackingmobs;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat as TF;

    class 
    Main extends PluginBase {

        
    /** @var Config */
        
    private $settings;

        
    /** @var EventListener */
        
    private $listener;

        
    /** @var StackHeartBeat */
        
    private $stackHeartbeat;

        
    /** Config file names */
        
    const SETTINGS_FILE "Settings.yml";

        public function 
    onEnable() {
            
    $this->loadConfigs();
            
    $this->startStackHeartbeat();
            
    $this->setListener();
            
    $this->getLogger()->info(TF::AQUA "StackingMobs v0.0.1" TF::GREEN " by " TF::YELLOW "DevinDaBomb11" TF::GREEN ", Loaded successfully!");
        }

        public function 
    loadConfigs() {
            
    $this->saveResource(self::SETTINGS_FILE);
            
    $this->settings = new Config($this->getDataFolder() . self::SETTINGS_FILEConfig::YAML);
        }

        
    /**
         * Start the stack heartbeat
         */
        
    public function startStackHeartbeat() {
            
    $this->stackHeartbeat = new StackHeartbeat($this);
        }

        public function 
    onDisable() {
            
    $this->settings->save(true);
            
    $this->getLogger()->info(TF::AQUA "AdvancedSpawners v0.0.1" TF::GOLD " by " TF::YELLOW "DevinDaBomb11" TF::GOLD ", has been disabled!");
        }

        
    /**
         * @return Config
         */
        
    public function getSettings() {
            return 
    $this->settings;
        }

        
    /**
         * @return EventListener
         */
        
    public function getListener() {
            return 
    $this->listener;
        }

        
    /**
         * Set the event listener
         */
        
    public function setListener() {
            
    $this->listener = new EventListener($this);
        }

        
    /**
         * Apply minecraft color codes to a string from our custom ones
         *
         * @param string $string
         * @param string $symbol
         *
         * @return mixed
         */
        
    public static function translateColors($string$symbol "&") {
            
    $string str_replace($symbol "0"TF::BLACK$string);
            
    $string str_replace($symbol "1"TF::DARK_BLUE$string);
            
    $string str_replace($symbol "2"TF::DARK_GREEN$string);
            
    $string str_replace($symbol "3"TF::DARK_AQUA$string);
            
    $string str_replace($symbol "4"TF::DARK_RED$string);
            
    $string str_replace($symbol "5"TF::DARK_PURPLE$string);
            
    $string str_replace($symbol "6"TF::GOLD$string);
            
    $string str_replace($symbol "7"TF::GRAY$string);
            
    $string str_replace($symbol "8"TF::DARK_GRAY$string);
            
    $string str_replace($symbol "9"TF::BLUE$string);
            
    $string str_replace($symbol "a"TF::GREEN$string);
            
    $string str_replace($symbol "b"TF::AQUA$string);
            
    $string str_replace($symbol "c"TF::RED$string);
            
    $string str_replace($symbol "d"TF::LIGHT_PURPLE$string);
            
    $string str_replace($symbol "e"TF::YELLOW$string);
            
    $string str_replace($symbol "f"TF::WHITE$string);

            
    $string str_replace($symbol "k"TF::OBFUSCATED$string);
            
    $string str_replace($symbol "l"TF::BOLD$string);
            
    $string str_replace($symbol "m"TF::STRIKETHROUGH$string);
            
    $string str_replace($symbol "n"TF::UNDERLINE$string);
            
    $string str_replace($symbol "o"TF::ITALIC$string);
            
    $string str_replace($symbol "r"TF::RESET$string);

            return 
    $string;
        }

    }<?
    php

    /*
    * StackingMobs Plugin
    *
    * Copyright (C) 2016 DevinDaBomb11
    *
    * This is private software, you cannot redistribute and/or modify it in any way
    * unless otherwise given permission to do so. If you have not been given explicit
    * permission to view or modify this software you should take the appropriate actions
    * to remove this software from your device immediately.
    *
    * @author DevinDaBomb11
    *
    * Created on 8/08/2016 at 6:49 PM
    *
    */

    namespace stackingmobs;

    use 
    pocketmine\entity\Living;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntitySpawnEvent;
    use 
    pocketmine\event\Listener;

    class 
    EventListener implements Listener {

        
    /** @var Main */
        
    private $plugin;

        
    /** @var int */
        
    protected $stackingRange 8;

        
    /** @var bool */
        
    protected $spawnStack true;

        public function 
    __construct(Main $plugin) {
            
    $this->plugin $plugin;
            
    $this->stackingRange $plugin->getSettings()->get("stacking-range"8);
            
    $this->spawnStack $plugin->getSettings()->get("spawn-stack"true);
            
    $plugin->getServer()->getPluginManager()->registerEvents($this$plugin);
        }

        
    /**
         * @param EntityDamageEvent $event
         *
         * @ignoreCancelled true
         *
         * @priority HIGHEST
         */
        
    public function onDamage(EntityDamageEvent $event) {
            
    $victim $event->getEntity();
            if(
    $event->getDamage() >= $victim->getHealth()) {
                if(
    $victim instanceof Living and StackFactory::isStack($victim)) {
                    
    $victim->setLastDamageCause($event);
                    if(
    StackFactory::removeFromStack($victim)) {
                        
    $event->setCancelled(true);
                        
    $victim->setHealth($victim->getMaxHealth());
                    }
                    
    StackFactory::recalculateStackName($victim$this->plugin->getSettings());
                }
            }
        }

        
    /**
         * @param EntitySpawnEvent $event
         *
         * @ignoreCancelled true
         *
         * @priority HIGHEST
         */
        
    public function onSpawn(EntitySpawnEvent $event) {
            if(
    $this->spawnStack) {
                
    $entity $event->getEntity();
                if(
    $entity instanceof Living) {
                    
    StackFactory::addToClosestStack($entity$this->stackingRange$this->plugin->getSettings());
                }
            }
        }

    }
    # StackingMobs v0.0.1 Settings.yml config file
    #
    stack-format"&l&e{name}&r\n&l&ex{amount}&r"
    #
    # How many blocks out can mobs stack from?
    stacking-range8
    #
    # Should a mob look for a mob stack as soon as they spawn?
    spawn-stacktrue
    #
    # Period between checking all mobs for nearby stacks (seconds)
    stack-delay10
    #
    # Levels to check mobs for stacking (names are cAsE sEnSiTiVe)
    levels:
      - 
    "world"nameStackingMobs
    authors
    :
      - 
    "DevinDaBomb11"
    version0.0.1
    main
    : \stackingmobs\Main
    load
    POSTWORLD
    api
    :
      - 
    2.0.0†y°öf^îåÙb÷tLOa,   GBMB
  7. daniktheboss
    Offline

    daniktheboss New Member

    Joined:
    Sep 28, 2016
    Posts:
    1
    Minecraft User:
    Daniktheboss
    So, did u fix it
  8. Magicode
    Offline

    Magicode Active Member

    Joined:
    Aug 3, 2016
    Posts:
    54
    Minecraft User:
    PokemonHero101
    HimbeersaftLP likes this.
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Hate to break it to you but that's my plugin that someone bought off me, too bad you didn't manage to get your slimey hands on the latest version c;

    Also, I suggest you read the license and not just change the name next time.
  10. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    I hate it when people do that... You written a plugin, and people right off steals it, and claim it as their own.
    I also hate it when people (Not looking at someone who's name rhymes with "Pan") copy someone else's work.
    jasonwynn10 and HimbeersaftLP like this.
  11. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
  12. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    too bad for PHP you cant just add a DRM and people wont be able to reverse engineer it, but i guess constantly updating your plugin will somewhat make other who get it one step behind
  13. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Read the the license in the header.
    The worst part is it was a closed source plugin only one other person was supposed to have access to.
  14. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    Please consider moving to the new forums http://forums.pmmp.io
  15. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    the only problem is, no one is obligated to follow,
    So in a sense it is kinda pointless
    And sometimes people resell plugins they bought to make the money back or even worst for a profit

    wont happen any time soon, it is for here to stay ATM
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Please consider reading my latest status update on this forum, along with the time/date stamp.
  17. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    That's what you get for selling plugins...

    BOOM!

    You never know who have access to it after it being sold to 1-person...

    [​IMG]

    But hey, @CrazedMiner you can't do shit about now, nor can the license help protect it,
    it's already . . . . .. :D
    jasonwynn10 and Thunder33345 like this.

Share This Page

Advertisement