1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Vote Plugin

Discussion in 'Development' started by DiamondGamer30, Jul 31, 2018.

  1. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    Hi, my vote plugin doesn't seem to be working for some reason. Nothing pops up in the logger or sends any messages. I'm pretty sure it's supposed to work.

    Vote API Documentation: https://minecraftpocket-servers.com/help/api/

    Code:
    PHP:
    <?php

    namespace core\essential\task;

    use 
    core\CorePlayer;
    use 
    core\crate\object\Crate;
    use 
    pocketmine\scheduler\AsyncTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Utils;

    class 
    CheckVoteTask extends AsyncTask {

        const 
    NO_DATA 0;

        const 
    NOT_CLAIMED 1;

        const 
    CLAIMED 2;

        
    /** @var string */
        
    private $player;

        
    /** @var array */
        
    private $data;

        
    /**
         * CheckVoteTask constructor.
         *
         * @param string $player
         * @param array $data
         */
        
    public function __construct(string $player, array $data) {
            
    $this->player $player;
            
    $this->data $data;
        }

        public function 
    onRun() {
            
    $get Utils::getURL(str_replace("{USERNAME}"$this->player$this->data["check"]));
            
    $this->setResult($get);
        }

        
    /**
         * @param Server $server
         */
        
    public function onCompletion(Server $server) {
            
    $player $server->getPlayer($this->player);
            if(!
    $player instanceof CorePlayer) {
                return;
            }
            switch(
    $this->getResult()) {
                case 
    self::NO_DATA:
                    
    $player->sendTranslatedMessage("VOTE_CHECK_NO_DATA");
                    break;
                case 
    self::NOT_CLAIMED:
                    
    $player->sendTranslatedMessage("VOTE_SUCCESS");
                    
    $player->getCore()->broadcastMessage("VOTE_BROADCAST", ["name" => $this->player]);
                    
    $player->addKeys(Crate::SPECIAL2);
                    
    $player->setChecked();
                    
    $player->setVoted();
                    
    $server->getAsyncPool()->submitTask(new ClaimVoteTask($this->player$this->data));
                    break;
                case 
    self::CLAIMED:
                    
    $player->sendTranslatedMessage("VOTE_CHECK_CLAIMED");
                    
    $player->setChecked();
                    
    $player->setVoted();
                    break;
                default:
                    
    $player->sendTranslatedMessage("VOTE_CHECK_ERROR");
            }
        }
    }
    PHP:
    <?php

    namespace core\essential\task;

    use 
    pocketmine\scheduler\AsyncTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Utils;

    class 
    ClaimVoteTask extends AsyncTask {

        const 
    NOT_CLAIMED 0;

        const 
    CLAIMED 1;

        
    /** @var string */
        
    private $player;

        
    /** @var array */
        
    private $data;

        
    /**
         * ClaimVoteTask constructor.
         *
         * @param string $player
         * @param array $data
         */
        
    public function __construct(string $player, array $data) {
            
    $this->player $player;
            
    $this->data $data;
        }

        public function 
    onRun() {
            
    $post Utils::postURL(str_replace("{USERNAME}"$this->player$this->data["claim"]), []);
            
    $this->setResult($post);
        }

        
    /**
         * @param Server $server
         */
        
    public function onCompletion(Server $server) {
            switch(
    $this->getResult()) {
                case 
    self::NOT_CLAIMED:
                    
    $server->getLogger()->info("Successfully set {$this->player}'s vote as claimed!");
                    break;
                case 
    self::CLAIMED:
                    
    $server->getLogger()->info("{$this->player}'s is already claimed!");
                    break;
                default:
                    
    $server->getLogger()->warning("Error while claiming {$this->player}'s vote!");
            }
        }
    }
     
  2. hikingjungle

    hikingjungle Baby Zombie

    Messages:
    123
    GitHub:
    hikingjungle
    it looks like that is for api 2.0.0 from the old forums (api documentation)
     
  3. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    What? What are you even talking about?
     
  4. hikingjungle

    hikingjungle Baby Zombie

    Messages:
    123
    GitHub:
    hikingjungle
    the download link in the api documentation refers to ldx's vote reward plugin from the old pocketmine
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    If it weren't compatible with the current API, it would give an API error on startup, unless this was bypassed without properly updating the plugin. Since OP said there was no output, I assume that wasn't the case.
    Does the plugin not load? Where did you download the plugin from? If I can see all of the source code, it would be helpful
     
  6. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    I coded it.
     
  7. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    I'm only showing a minimum amount of code because some of it includes some private info. $data variable represents the json decoded version of a vrc file from https://minecraftpocket-servers.com/.
     
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You didn't specify what part of the plugin didn't work, so I have no clue whether it loads, the command runs, what you expect to happen, etc. If it isn't loading, I need to see your PluginBase file, or at least part of it.
     
  9. hikingjungle

    hikingjungle Baby Zombie

    Messages:
    123
    GitHub:
    hikingjungle
    in the consule does it say
    loading vote plugin
    enabling vote plugin
     
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    this is on coding an API interface for the site
    PMMP plugin is irrelevant here
    please stop creating false information

    it make no sense since you properly set default thus there will at least be error
     
    EdwardHamHam and DiamondGamer30 like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.