Re: PocketMine Plugin - VoteKick

From Subtle Cheetah, 3 Years ago, written in PHP, viewed 266 times. This paste is a reply to PocketMine Plugin - VoteKick from NAT - go back
URL https://code.nat.moe/view/5ba97c45/diff Embed
Viewing differences between PocketMine Plugin - VoteKick and Re: PocketMine Plugin - VoteKick
<?php
/*
<?php
/*
__PocketMine Plugin__
name=VoteKick
Plugin__
name=VoteKick
description=Vote to kick a player
player
version=0.2
author=NAT
class=VoteKick
apiversion=9
*/
2
author=NAT
class=VoteKick
apiversion=9
*/
//NOTICE : This plugins is STILL IN DEBUG .

DEBUG .

class VoteKick implements Plugin{
        
Plugin{
        
private $api,$server;
        
$api,$server;
        
public function __construct(ServerAPI $api, $server = false){
                
false){
                
$this->api = $api;
                
$api;
                
$this->server = ServerAPI::request();
        }
        
ServerAPI::request();
        }
        
public function init(){
                
init(){
                
$this->api->console->register("startvote", "<player>", array($this, "handleCommand"));
                
"handleCommand"));
                
$this->api->console->register("vote","<player>", array($this, "handleCommand"));
                $this->server->api->ban->cmdWhitelist("vote");
                $this->server->api->ban->cmdWhitelist("startvote");
"handleCommand"));
                $this->server->api->ban->cmdWhitelist("vote");
                $this->server->api->ban->cmdWhitelist("startvote");
                $this->api->addHandler("player.quit", array($this, "handler"), 5);
                $this->voting=0;
        }
        
5);
                $this->voting=0;
        }
        
public function __destruct(){
        }
        
__destruct(){
        }
        
public function handler(&$data, $event){
                switch($data){
$event){
                switch($data){
                    case "player.quit":
                       for($k=1;$k=$this->volting;$k++){
                         if($this->canvote1[$data->iusername][$this->vote[$k][1]]=="false"){
                        $this->vote[$k][1]=$this->vote[$k][1]-1;
                        $this->canvote1[$data->iusername][1]=="";
                        }
                     }
                }
        }
        
quit":
                       for($k=1;$k=$this->volting;$k++){
                         if($this->canvote1[$data->iusername][$this->vote[$k][1]]=="false"){
                        $this->vote[$k][1]=$this->vote[$k][1]-1;
                        $this->canvote1[$data->iusername][1]=="";
                        }
                     }
                }
        }
        
public function handleCommand($cmd, $arg ,$issuer , $alias){
                
                switch($cmd){
                
$alias){
                
                switch($cmd){
                
case "startvote":
                        $this->newvote(array_shift($arg));
                        break;
                
"startvote":
                        $this->newvote(array_shift($arg));
                        break;
                
case "vote":
                        $this->vote(array_shift($arg));
                        break;
                }
                
"vote":
                        $this->vote(array_shift($arg));
                        break;
                }
                
return $this->output;
        }
        
$this->output;
        }
        
public function canvote($name,$tovote){
                if(empty($this->canvote1[$name][$tovote])){
                        $this->canvote1[$name][$tovote]="false";
                        
canvote($name,$tovote){
                if(empty($this->canvote1[$name][$tovote])){
                        $this->canvote1[$name][$tovote]="false";
                        
return true;
                }else{
                        
true;
                }else{
                        
return false;
                }
        }        
        
false;
                }
        }        
        
public function isonline($totest){
                        
isonline($totest){
                        
$player = $this->api->player->get($totest);
                        if(!$player){
                                
$this->api->player->get($totest);
                        if(!$player){
                                
return false;
                        }
                        
false;
                        }
                        
return true;
        }
        
true;
        }
        
public function invote($tovote)
        {
                $invote=false;
                if($this->voting!=0){
                for($i=1;$i=$this->voting;$i++){
                        if($this->vote[$i][1]=$tovote){
                                $this->tmp=$i;
                                $invote=true;
                                break;
                                }
                        }
                }
                
invote($tovote)
        {
                $invote=false;
                if($this->voting!=0){
                for($i=1;$i=$this->voting;$i++){
                        if($this->vote[$i][1]=$tovote){
                                $this->tmp=$i;
                                $invote=true;
                                break;
                                }
                        }
                }
                
return $invote;
        }
        
$invote;
        }
        
public function newvote($tovote){
                if(empty($tovote)){
                        
newvote($tovote){
                if(empty($tovote)){
                        
$this->output="Usage : /startvote <player> (start a vote to kick someone)";
                        
someone)";
                        
return 0;
                        }
                if($this->invote($tovote)||!$this->isonline($tovote))
                {
0;
                        }
                if($this->invote($tovote)||!$this->isonline($tovote))
                {
                        $this->output="Error During Try to start vote,Player might not online or already in vote.";
                }else{
";
                }else{
                        $this->api->chat->broadcast("Voting to kick ".$tovote." Using /vote ".$tovote." to vote it.");
                        $this->voting=$this->voting+1;
                        $this->vote[$this->voting][1]=$tovote;
                        $this->vote[$this->voting][2]=1;
                }
        }
        
");
                        $this->voting=$this->voting+1;
                        $this->vote[$this->voting][1]=$tovote;
                        $this->vote[$this->voting][2]=1;
                }
        }
        
public function vote($tovote){
                
vote($tovote){
                
if(empty($tovote)) {
                        
{
                        
$this->output="Usage : /vote <player> (vote to kick someone)";
                        
someone)";
                        
return 0;
                        }
                if(!$this->invote($tovote)||!$this->isonline($tovote)||!$this->canvote($issuer,$tovote)){
                        
0;
                        }
                if(!$this->invote($tovote)||!$this->isonline($tovote)||!$this->canvote($issuer,$tovote)){
                        
$this->snd("Error During Try to vote,Player might not online, isn't in vote , you has voted or running command from console");
                        
console");
                        
return 0;
                }else{
0;
                }else{
                        $this->output="Vote to kick Player ".$tovote." Successful!";
                        $this->vote[$this->tmp][2]=$vote[$this->tmp][2]+1;
                }
                if($this->vote[$this->tmp][2]>count($this->clients)/2)
                {
                        
Successful!";
                        $this->vote[$this->tmp][2]=$vote[$this->tmp][2]+1;
                }
                if($this->vote[$this->tmp][2]>count($this->clients)/2)
                {
                        
$player = $this->api->player->get($tovote);
$this->api->player->get($tovote);
                        $this->api->chat->broadcast($tovote." has been kicked by voting");
                        
voting");
                        
$player->close("You has been vote to kick");
                }
        }
}
kick");
                }
        }
}
?>

Reply to "Re: PocketMine Plugin - VoteKick"

Here you can reply to the paste above

captcha