PocketMine Plugin - VoteKick

From NAT, 7 Years ago, written in PHP, viewed 924 times.
URL https://code.nat.moe/view/7dc886aa Embed
Download Paste or View Raw
  1. <?php
  2. /*
  3. __PocketMine Plugin__
  4. name=VoteKick
  5. description=Vote to kick a player
  6. version=0.2
  7. author=NAT
  8. class=VoteKick
  9. apiversion=9
  10. */
  11. //NOTICE : This plugins is STILL IN DEBUG .
  12.  
  13. class VoteKick implements Plugin{
  14.         private $api,$server;
  15.         public function __construct(ServerAPI $api, $server = false){
  16.                 $this->api = $api;
  17.                 $this->server = ServerAPI::request();
  18.         }
  19.         public function init(){
  20.                 $this->api->console->register("startvote", "<player>", array($this, "handleCommand"));
  21.                 $this->api->console->register("vote","<player>", array($this, "handleCommand"));
  22.                 $this->server->api->ban->cmdWhitelist("vote");
  23.                 $this->server->api->ban->cmdWhitelist("startvote");
  24.                 $this->api->addHandler("player.quit", array($this, "handler"), 5);
  25.                 $this->voting=0;
  26.         }
  27.         public function __destruct(){
  28.         }
  29.         public function handler(&$data, $event){
  30.                 switch($data){
  31.                    case "player.quit":
  32.                      for($k=1;$k=$this->volting;$k++){
  33.                      if($this->canvote1[$data->iusername][$this->vote[$k][1]]=="false"){
  34.                         $this->vote[$k][1]=$this->vote[$k][1]-1;
  35.                         $this->canvote1[$data->iusername][1]=="";
  36.                         }
  37.                      }
  38.                 }
  39.         }
  40.         public function handleCommand($cmd, $arg ,$issuer , $alias){
  41.                
  42.                 switch($cmd){
  43.                 case "startvote":
  44.                         $this->newvote(array_shift($arg));
  45.                         break;
  46.                 case "vote":
  47.                         $this->vote(array_shift($arg));
  48.                         break;
  49.                 }
  50.                 return $this->output;
  51.         }
  52.         public function canvote($name,$tovote){
  53.                 if(empty($this->canvote1[$name][$tovote])){
  54.                         $this->canvote1[$name][$tovote]="false";
  55.                         return true;
  56.                 }else{
  57.                         return false;
  58.                 }
  59.         }      
  60.         public function isonline($totest){
  61.                         $player = $this->api->player->get($totest);
  62.                         if(!$player){
  63.                                 return false;
  64.                         }
  65.                         return true;
  66.         }
  67.         public function invote($tovote)
  68.         {
  69.                 $invote=false;
  70.                 if($this->voting!=0){
  71.                 for($i=1;$i=$this->voting;$i++){
  72.                         if($this->vote[$i][1]=$tovote){
  73.                                 $this->tmp=$i;
  74.                                 $invote=true;
  75.                                 break;
  76.                                 }
  77.                         }
  78.                 }
  79.                 return $invote;
  80.         }
  81.         public function newvote($tovote){
  82.                 if(empty($tovote)){
  83.                         $this->output="Usage : /startvote <player> (start a vote to kick someone)";
  84.                         return 0;
  85.                         }
  86.                 if($this->invote($tovote)||!$this->isonline($tovote))
  87.                 {
  88.                         $this->output="Error During Try to start vote,Player might not online or already in vote.";
  89.                 }else{
  90.                         $this->api->chat->broadcast("Voting to kick ".$tovote." Using /vote ".$tovote." to vote it.");
  91.                         $this->voting=$this->voting+1;
  92.                         $this->vote[$this->voting][1]=$tovote;
  93.                         $this->vote[$this->voting][2]=1;
  94.                 }
  95.         }
  96.         public function vote($tovote){
  97.                 if(empty($tovote)) {
  98.                         $this->output="Usage : /vote <player> (vote to kick someone)";
  99.                         return 0;
  100.                         }
  101.                 if(!$this->invote($tovote)||!$this->isonline($tovote)||!$this->canvote($issuer,$tovote)){
  102.                         $this->snd("Error During Try to vote,Player might not online, isn't in vote , you has voted or running command from console");
  103.                         return 0;
  104.                 }else{
  105.                         $this->output="Vote to kick Player ".$tovote." Successful!";
  106.                         $this->vote[$this->tmp][2]=$vote[$this->tmp][2]+1;
  107.                 }
  108.                 if($this->vote[$this->tmp][2]>count($this->clients)/2)
  109.                 {
  110.                         $player = $this->api->player->get($tovote);
  111.                         $this->api->chat->broadcast($tovote." has been kicked by voting");
  112.                         $player->close("You has been vote to kick");
  113.                 }
  114.         }
  115. }
  116. ?>

Replies to PocketMine Plugin - VoteKick rss

Title Name Language When
Re: PocketMine Plugin - VoteKick Subtle Cheetah php 2 Years ago.
Re: PocketMine Plugin - VoteKick Queen Sheep php 2 Years ago.

Reply to "PocketMine Plugin - VoteKick"

Here you can reply to the paste above

captcha