Skip to content
This repository has been archived by the owner on May 30, 2018. It is now read-only.

Commit

Permalink
Added a new "Gamemode" command!
Browse files Browse the repository at this point in the history
Also fixed a bug with "Tempban" (Fixes #64) and a bug with the messages of the "Vanish" command
  • Loading branch information
iksaku committed Feb 4, 2015
1 parent 917707a commit cec3164
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 108 deletions.
5 changes: 4 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: EssentialsPE
main: EssentialsPE\Loader
version: 1.1.0 Beta 3
version: 1.1.0 Beta 4
api: 1.9.0
author: LegendsOfMCPE Team
website: https://github.com/LegendOfMCPE/EssentialsPE
Expand Down Expand Up @@ -98,6 +98,9 @@ permissions:
essentials.extinguish.other:
default: op
description: "Extinguish other players"
essentials.gamemode:
deault: op
description: "Change your gamemode!"
essentials.getpos:
default: op
description: "Get any player's position"
Expand Down
147 changes: 75 additions & 72 deletions src/EssentialsPE/Commands/Override/Gamemode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use EssentialsPE\Loader;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\TextFormat;

class Gamemode extends BaseCommand{
Expand All @@ -18,95 +17,99 @@ public function execute(CommandSender $sender, $alias, array $args){
if(!$this->testPermission($sender)){
return false;
}
$gm = 0;
switch(count($args)){
case 0:
case "gma":
case "adventure":
$gm = 2;
if(strtolower($alias) !== "gamemode" && strtolower($alias) !== "gm"){
if(isset($args[0])){
$args[1] = $args[0];
}
switch(strtolower($alias)){
case "survival":
case "gms":
$args[0] = "survival";
break;
case "gmc":
case "creative":
$gm = 1;
case "gmc":
$args[0] = "creative";
break;
case "gms":
case "survival":
$gm = 0;
case "adventure":
case "gma":
$args[0] = "adventure";
break;
case "gmt":
case "spectator":
case "viewer":
$gm = 3;
case "gmt":
$args[0] = "spectator";
break;
case 1:
case 2:
if(!$sender instanceof Player && !isset($arg[1])){
$sender->sendMessage(TextFormat::RED . "Usage: /gamemode <mode> <player>");
default:
return false;
}
switch($alias){
case "gamemode":
case "gm":
switch(strtolower($args[0])){
case "adventure":
case "a":
case 2:
$gm = 2;
break;
case "cretive":
case "c":
case 1:
$gm = 1;
break;
case "survival":
case "s":
case 0:
$gm = 0;
break;
case "spectator":
case "t":
case 3:
$gm = 3;
break;
default:
$sender->sendMessage(TextFormat::RED . "[Error] Invalid gamemode");
return false;
break;
}
break;
}
break;
default:
$sender->sendMessage(TextFormat::RED . ($sender instanceof Player ? $this->getUsage() : "Usage: /gamemode <mode> <player>"));
return false;
break;
break;
}
}
$gmstring = strtolower($sender->getServer()->getGamemodeString($gm));
if($alias === "gm" || $alias === "gamemode"){
$arg = 1;
}else{
$arg = 0;
$player = $sender;
if(!$player instanceof Player && !isset($args[1])){
$player->sendMessage(TextFormat::RED . "Usage: /gamemode <mode> <player>");
return false;
}
if(isset($args[$arg])){
$player = $this->getPlugin()->getPlayer($args[$arg]);
if(isset($args[1])){
$player = $this->getPlugin()->getPlayer($args[1]);
if(!$player){
$sender->sendMessage(TextFormat::RED . "[Error] Player not found");
return false;
}
if($player->getGamemode() !== $gm){
$sender->getServer()->broadcast(TextFormat::GREEN . "Setting " . $args[$arg] . (substr($args[$arg], -1, 1) === "s" ? "'" : "'s") . " gamemode to " . $gmstring, Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
$player->sendMessage("Changing your gamemode to " . $gmstring);
$player->setGamemode($gm);
}else{
$sender->sendMessage(TextFormat::RED . "[Error] " . $args[$arg] . " is already on " . $sender->getServer()->getGamemodeString($gm) . " mode");
}

/**
* The following switch is applied when the user execute:
* /gamemode <MODE>
*/
if(is_int($args[0])){
switch($args[0]){
case 0:
case 1:
case 2:
case 3:
$gm = $args[0];
break;
default:
$sender->sendMessage(TextFormat::RED . "[Error] Please specify a valid gamemode");
return false;
break;
}
}else{
if($sender->getGamemode() !== $gm){
$this->broadcastCommandMessage($sender, "Set own gamemode to " . $gmstring . " mode");
$sender->sendMessage("Changing your gamemode to " . $gmstring . " mode");
$sender->setGamemode($gm);
switch(strtolower($args[0])){
case "survival":
case "s":
$gm = 0;
break;
case "creative":
case "c":
$gm = 1;
break;
case "adventure":
case "a":
$gm = 2;
break;
case "spectator":
case "viewer":
case "view":
case "v":
case "t":
$gm = 3;
break;
default:
$sender->sendMessage(TextFormat::RED . "[Error] Please specify a valid gamemode");
return false;
break;
}
}
$gmstring = $this->getPlugin()->getServer()->getGamemodeString($gm);
if($player->getGamemode() === $gm){
$player->sendMessage(TextFormat::RED . "[Error] " . ($player === $sender ? "You're" : $args[1] . " is") . " already in " . $gmstring . " mode");
return false;
}
if($player !== $sender){
$sender->sendMessage(TextFormat::GREEN . $args[1] . " is now on " . $gmstring . " mode");
}
$player->setGamemode($gm);
return true;
}
}
48 changes: 17 additions & 31 deletions src/EssentialsPE/Commands/TempBan.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use EssentialsPE\BaseCommand;
use EssentialsPE\Loader;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\utils\TextFormat;

class TempBan extends BaseCommand{
Expand All @@ -21,58 +22,43 @@ public function execute(CommandSender $sender, $alias, array $args){
return false;
}
$player = $this->getPlugin()->getPlayer($name = array_shift($args));
/**
* s = Seconds (with leading zeros)
* i = Minutes
* h = Hour (12 hours format with leading zeros)
* j = Day number (1 - 30/31)
* m = Month number
* Y = Year in 4 digits (1999)
*/
$seconds = 0;
$v = explode(",", array_shift($args));
foreach($v as $t){

$date = new \DateTime();
foreach(explode(",", array_shift($args)) as $t){
if(strpos($t, "s")){
$time = substr($t, -2);
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("P" . strtoupper($t)));
}elseif(strpos($t, "m")){
$time = substr($t, -2) * 60;
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("PT" . strtoupper($t)));
}elseif(strpos($t, "h")){
$time = substr($t, -2) * 60 * 60;
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("P" . strtoupper($t)));
}elseif(strpos($t, "d")){
$time = substr($t, -2) * 24 * 60 * 60;
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("P" . strtoupper($t)));
}elseif(strpos($t, "w")){
$time = substr($t, -2) * 7 * 24 * 60 * 60;
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("P" . strtoupper($t)));
}elseif(strpos($t, "mo")){
$time = substr($t, -3) * 30 * 24 * 60 * 60;
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("P" . strtoupper($t)));
}elseif(strpos($t, "y")){
$time = substr($t, -2) * 365 * 24 * 60 * 60;
$seconds += (is_numeric($time) ? $time : 0);
$date->add(new \DateInterval("P" . strtoupper($t)));
}elseif(is_int((int) $t)){
$date->add(new \DateInterval("P" . $t . "S"));
}else{
$time = substr($t, -2);
$seconds += (is_numeric($time) ? $time : 0);
$sender->sendMessage(TextFormat::RED . ($sender instanceof Player ? "" : "Usage: ") . $this->getUsage());
return false;
}
}
$reason = implode(" ", $args);
$date = new \DateTime();
$date->setTimestamp($time = time() + $seconds);
if($player !== false){
if($player->hasPermission("essentials.banexempt")){
$sender->sendMessage(TextFormat::RED . "[Error] ". $name . " can't be banned");
return false;
}else{
$name = $player->getName();
$player->kick(TextFormat::RED . "Banned until " . TextFormat::AQUA . date("l, F j, Y", $time) . TextFormat::RED . " at " . TextFormat::AQUA . date("h:1a", $time));
$player->kick(TextFormat::RED . "Banned until " . TextFormat::AQUA . $date->format("l, F j, Y") . TextFormat::RED . " at " . TextFormat::AQUA . $date->format("h:ia"));
}
}
$sender->getServer()->getNameBans()->addBan($name, ($reason !== "" ? $reason : null), $date, "essentialspe");

$this->broadcastCommandMessage($sender, "Banned player " . $name);
$this->broadcastCommandMessage($sender, "Banned player " . $name . " until " . $date->format("l, F j, Y") . " at " . $date->format("h:ia"));
return true;
}
}
4 changes: 2 additions & 2 deletions src/EssentialsPE/Commands/Vanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function execute(CommandSender $sender, $alias, array $args){
return false;
}
$this->getPlugin()->switchVanish($player);
$sender->sendMessage(TextFormat::GRAY . $args[0] . " is now " . $this->getPlugin()->isVanished($player) ? "vanished!" : "visible!");
$player->sendMessage(TextFormat::GRAY . "You're now " . $this->getPlugin()->isVanished($player) ? "vanished!" : "visible!");
$sender->sendMessage(TextFormat::GRAY . $args[0] . " is now " . ($this->getPlugin()->isVanished($player) ? "vanished!" : "visible!"));
$player->sendMessage(TextFormat::GRAY . "You're now " . ($this->getPlugin()->isVanished($player) ? "vanished!" : "visible!"));
break;
default:
$sender->sendMessage(TextFormat::RED . ($sender instanceof Player ? $this->getUsage() : "Usage: /vanish <player>"));
Expand Down
5 changes: 3 additions & 2 deletions src/EssentialsPE/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use EssentialsPE\Commands\Near;
use EssentialsPE\Commands\Nick;
use EssentialsPE\Commands\Nuke;
use EssentialsPE\Commands\Override\Gamemode;
use EssentialsPE\Commands\Override\Kill;
use EssentialsPE\Commands\Override\Msg;
use EssentialsPE\Commands\PowerTool\PowerTool;
Expand Down Expand Up @@ -178,7 +179,7 @@ private function unregisterCommands(array $commands){
private function registerCommands(){
//Unregister commands to override
$this->unregisterCommands([
//"gamemode", // TODO: ReWrite
"gamemode",
"kill",
"tell"
]);
Expand Down Expand Up @@ -261,7 +262,7 @@ private function registerCommands(){
new Warp($this),

//Override
//new Gamemode($this), // TODO: ReWrite
new Gamemode($this),
new Kill($this)
]);
}
Expand Down

0 comments on commit cec3164

Please sign in to comment.