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

What's this error

Discussion in 'Help' started by Alex, Jan 6, 2018.

  1. Alex

    Alex Spider Jockey

    Messages:
    28
    GitHub:
    Bichwha
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    We will definitely need to see parts of the code in BanSystem, that error is really generic.
     
  3. Alex

    Alex Spider Jockey

    Messages:
    28
    GitHub:
    Bichwha
    public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args) : bool {

    switch($cmd->getName()){

    case "modban":
    if($sender instanceof Player) {
    if($sender->hasPermission("gpe.ban")){

    $name = $this->getServer()->getPlayerExact($args[0]);

    if($args[1] == "24"){
    $hour = "24";
    } else if ($args[1] == "336"){
    $hour = "336";
    } else if ($args[1] == "720"){
    $hour = "720";
    } else if ($args[1] == "48"){
    $hour = "48";
    } else if ($args[1] == "8760"){
    $hour = "8760";
    } else if ($args[1] == "1000"){
    $hour = "1000";
    } else if ($args[1] == "96"){
    $hour = "96";
    }

    if(count($args) >= 2) {
    $reason = "";
    for ($i = 2; $i < count($args); $i++) {
    $reason .= $args[$i];
    $reason .= " ";
    }
    }

    $reason = substr($reason, 0, strlen($reason) - 1);

    if($hour == "24"){
    $totalTime = 24 * 3600;
    $banCount = 24;
    } else if ($hour == "336"){
    $totalTime = 336 * 3600;
    $banCount = 336;
    } else if ($hour == "720"){
    $totalTime = 720 * 3600;
    $banCount = 720;
    } else if ($hour == "48"){
    $totalTime = 48 * 3600;
    $banCount = 48;
    } else if ($hour == "8760"){
    $totalTime = 8760 * 3600;
    $banCount = 8760;
    } else if ($hour == "1000"){
    $totalTime = 1000 * 3600;
    $banCount = 1000;
    } else if ($hour == "96"){
    $totalTime = 96 * 3600;
    $banCount = 96;
    }

    if($name instanceof Player) {
    $name->kick(TextFormat::RED . "You have been mod banned for " . TextFormat::AQUA . $hour . " hours. " . TextFormat::RED . "Comment: " . TextFormat::AQUA . $reason);
    $this->banList[strtolower($name->getName())] = $name;

    $name = trim(strtolower($name->getName()));
    $config = new Config($this->getDataFolder() . "players/" . strtolower($name) . ".yml", Config::YAML);
    $data = $config->getAll();
    $totalBanCount = $data["BanCount"];
    $newBanCount = $totalBanCount + $banCount;

    $config = new Config($this->getDataFolder() . "players/" . strtolower($name) . ".yml", Config::YAML);
    $config->set("Ban", "True");
    $config->set("BanCount", $newBanCount);
    $config->set("Hour", $hour);
    $config->set("TotalTime", $totalTime);
    $config->set("Reason", $reason);
    $config->save();
    $this->getServer()->broadcastMessage(TextFormat::WHITE . "•" .TextFormat::GREEN . $name . " has been [BANNED] for " . $reason . ".");
    $sender->sendMessage(TextFormat::WHITE . "•" . TextFormat::BLUE . $name . " has been banned!");
    }
    }
    }
    else{
    $sender->sendMessage(TextFormat::RED . "Use this Command in-game.");
    return true;
    }
    break;
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Sorry, but i did totally lmao there.
    The whole hour whatever-the-f*ck converting part can be compressed into:
    PHP:
    $hour $args[1];
    $totalTime $args[1] * 3600;
    $banCount $args[1];
    and to get back to your error, it's probably because you're not checking if your user has supplied arg 1/ the time.
    so, this should be "fixing" it:
    PHP:
    public function onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool {

    switch(
    $cmd->getName()){

    case 
    "modban":
    if(
    $sender instanceof Player) {
    if(
    $sender->hasPermission("gpe.ban")){

    $name $this->getServer()->getPlayerExact($args[0]);

    if(!isset(
    $args[1]){
    return 
    false;
    }

    $hour $args[1];
    $totalTime $args[1] * 3600;
    $banCount $args[1];

    if(
    count($args) >= 2) {
    $reason "";
    for (
    $i 2$i count($args); $i++) {
    $reason .= $args[$i];
    $reason .= " ";
    }
    }

    $reason substr($reason0strlen($reason) - 1);

    if(
    $name instanceof Player) {
    $name->kick(TextFormat::RED "You have been mod banned for " TextFormat::AQUA $hour " hours. " TextFormat::RED "Comment: " TextFormat::AQUA $reason);
    $this->banList[strtolower($name->getName())] = $name;

    $name trim(strtolower($name->getName()));
    $config = new Config($this->getDataFolder() . "players/" strtolower($name) . ".yml"Config::YAML);
    $data $config->getAll();
    $totalBanCount $data["BanCount"];
    $newBanCount $totalBanCount $banCount;

    $config = new Config($this->getDataFolder() . "players/" strtolower($name) . ".yml"Config::YAML);
    $config->set("Ban""True");
    $config->set("BanCount"$newBanCount);
    $config->set("Hour"$hour);
    $config->set("TotalTime"$totalTime);
    $config->set("Reason"$reason);
    $config->save();
    $this->getServer()->broadcastMessage(TextFormat::WHITE "•" .TextFormat::GREEN $name " has been [BANNED] for " $reason ".");
    $sender->sendMessage(TextFormat::WHITE "•" TextFormat::BLUE $name " has been banned!");
    }
    }
    }
    else{
    $sender->sendMessage(TextFormat::RED "Use this Command in-game.");
    return 
    true;
    }
    break;
    But seriously, keep your hands off that plugin, it deserves to burn.
     
  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.