Added base translation system

This commit is contained in:
Shoghi Cervantes 2015-04-11 01:32:08 +02:00
parent 3224cd7dc5
commit 0c041ebca3
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
38 changed files with 646 additions and 132 deletions

View File

@ -31,6 +31,7 @@ use pocketmine\entity\Item as DroppedItem;
use pocketmine\entity\Living; use pocketmine\entity\Living;
use pocketmine\entity\Projectile; use pocketmine\entity\Projectile;
use pocketmine\event\block\SignChangeEvent; use pocketmine\event\block\SignChangeEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntityRegainHealthEvent;
@ -59,7 +60,9 @@ use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerRespawnEvent; use pocketmine\event\player\PlayerRespawnEvent;
use pocketmine\event\server\DataPacketReceiveEvent; use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent; use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\TextContainer;
use pocketmine\event\Timings; use pocketmine\event\Timings;
use pocketmine\event\TranslationContainer;
use pocketmine\inventory\BaseTransaction; use pocketmine\inventory\BaseTransaction;
use pocketmine\inventory\BigShapelessRecipe; use pocketmine\inventory\BigShapelessRecipe;
use pocketmine\inventory\CraftingTransactionGroup; use pocketmine\inventory\CraftingTransactionGroup;
@ -218,6 +221,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
/** @var PermissibleBase */ /** @var PermissibleBase */
private $perm = null; private $perm = null;
public function getLeaveMessage(){
return new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.leave", [
$this->getDisplayName()
]);
}
public function getClientId(){ public function getClientId(){
return $this->randomClientId; return $this->randomClientId;
} }
@ -642,7 +651,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk->status = PlayStatusPacket::PLAYER_SPAWN; $pk->status = PlayStatusPacket::PLAYER_SPAWN;
$this->dataPacket($pk); $this->dataPacket($pk);
$this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, TextFormat::YELLOW . $this->getName() . " joined the game")); $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this,
new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.joined", [
$this->getDisplayName()
])
));
if(strlen(trim($ev->getJoinMessage())) > 0){ if(strlen(trim($ev->getJoinMessage())) > 0){
$this->server->broadcastMessage($ev->getJoinMessage()); $this->server->broadcastMessage($ev->getJoinMessage());
} }
@ -916,10 +929,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if(($this->gamemode & 0x01) === ($gm & 0x01)){ if(($this->gamemode & 0x01) === ($gm & 0x01)){
$this->gamemode = $gm; $this->gamemode = $gm;
$this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n"); $this->sendMessage(new TranslationContainer("gameMode.changed"));
}else{ }else{
$this->gamemode = $gm; $this->gamemode = $gm;
$this->sendMessage("Your gamemode has been changed to " . Server::getGamemodeString($this->getGamemode()) . ".\n"); $this->sendMessage(new TranslationContainer("gameMode.changed"));
$this->inventory->clearAll(); $this->inventory->clearAll();
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
$this->inventory->sendContents($this->getViewers()); $this->inventory->sendContents($this->getViewers());
@ -1381,11 +1394,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if(!$this->server->isWhitelisted(strtolower($this->getName()))){ if(!$this->server->isWhitelisted(strtolower($this->getName()))){
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is white-listed"); $this->close($this->getLeaveMessage(), "Server is white-listed");
return; return;
}elseif($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())){ }elseif($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())){
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You are banned"); $this->close($this->getLeaveMessage(), "You are banned");
return; return;
} }
@ -1400,7 +1413,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
foreach($this->server->getOnlinePlayers() as $p){ foreach($this->server->getOnlinePlayers() as $p){
if($p !== $this and strtolower($p->getName()) === strtolower($this->getName())){ if($p !== $this and strtolower($p->getName()) === strtolower($this->getName())){
if($p->kick("logged in from another location") === false){ if($p->kick("logged in from another location") === false){
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "Logged in from another location"); $this->close($this->getLeaveMessage(), "Logged in from another location");
return; return;
}else{ }else{
@ -1431,7 +1444,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
if(!($nbt instanceof Compound)){ if(!($nbt instanceof Compound)){
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Invalid data"); $this->close($this->getLeaveMessage(), "Invalid data");
return; return;
} }
@ -1450,7 +1463,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason")); $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){ if($ev->isCancelled()){
$this->close(TextFormat::YELLOW . $this->username . " has left the game", $ev->getKickMessage()); $this->close($this->getLeaveMessage(), $ev->getKickMessage());
return; return;
} }
@ -2372,7 +2385,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
* @return bool * @return bool
*/ */
public function kick($reason = ""){ public function kick($reason = ""){
$this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game")); $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage()));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
$this->close($ev->getQuitMessage(), $message); $this->close($ev->getQuitMessage(), $message);
@ -2386,9 +2399,17 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
/** /**
* Sends a direct chat message to a player * Sends a direct chat message to a player
* *
* @param string $message * @param string|TextContainer $message
*/ */
public function sendMessage($message){ public function sendMessage($message){
if($message instanceof TextContainer){
if($message instanceof TranslationContainer){
$this->sendTranslation($message->getText(), $message->getParameters());
return;
}
$message = $message->getText();
}
$mes = explode("\n", $message); $mes = explode("\n", $message);
foreach($mes as $m){ foreach($mes as $m){
if($m !== ""){ if($m !== ""){
@ -2534,84 +2555,104 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return; return;
} }
$message = $this->getName() . " died"; $message = "death.attack.generic";
$cause = $this->getLastDamageCause();
$ev = null;
if($cause instanceof EntityDamageEvent){
$ev = $cause;
$cause = $ev->getCause();
}
switch($cause){ $params = [
$this->getName()
];
$cause = $this->getLastDamageCause();
switch($cause->getCause()){
case EntityDamageEvent::CAUSE_ENTITY_ATTACK: case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
if($ev instanceof EntityDamageByEntityEvent){ if($cause instanceof EntityDamageByEntityEvent){
$e = $ev->getDamager(); $e = $cause->getDamager();
if($e instanceof Player){ if($e instanceof Player){
$message = $this->getName() . " was killed by " . $e->getName(); $message = "death.attack.player";
$params[] = $e->getName();
break; break;
}elseif($e instanceof Living){ }elseif($e instanceof Living){
$message = $this->getName() . " was slain by " . $e->getName(); $message = "death.attack.mob";
$params[] = $e->getName();
break; break;
}else{
$params[] = "Unknown";
} }
} }
$message = $this->getName() . " was killed";
break; break;
case EntityDamageEvent::CAUSE_PROJECTILE: case EntityDamageEvent::CAUSE_PROJECTILE:
if($ev instanceof EntityDamageByEntityEvent){ if($cause instanceof EntityDamageByEntityEvent){
$e = $ev->getDamager(); $e = $cause->getDamager();
if($e instanceof Living){ if($e instanceof Living){
$message = $this->getName() . " was shot by " . $e->getName(); $message = "death.attack.arrow";
$params[] = $e->getName();
break; break;
}else{
$params[] = "Unknown";
} }
} }
$message = $this->getName() . " was shot by arrow";
break; break;
case EntityDamageEvent::CAUSE_SUICIDE: case EntityDamageEvent::CAUSE_SUICIDE:
$message = $this->getName() . " died"; $message = "death.attack.generic";
break; break;
case EntityDamageEvent::CAUSE_VOID: case EntityDamageEvent::CAUSE_VOID:
$message = $this->getName() . " fell out of the world"; $message = "death.attack.outOfWorld";
break; break;
case EntityDamageEvent::CAUSE_FALL: case EntityDamageEvent::CAUSE_FALL:
if($ev instanceof EntityDamageEvent){ if($cause instanceof EntityDamageEvent){
if($ev->getFinalDamage() > 2){ if($cause->getFinalDamage() > 2){
$message = $this->getName() . " fell from a high place"; $message = "death.fell.accident.generic";
break; break;
} }
} }
$message = $this->getName() . " hit the ground too hard"; $message = "death.attack.fall";
break; break;
case EntityDamageEvent::CAUSE_SUFFOCATION: case EntityDamageEvent::CAUSE_SUFFOCATION:
$message = $this->getName() . " suffocated in a wall"; $message = "death.attack.inWall";
break; break;
case EntityDamageEvent::CAUSE_LAVA: case EntityDamageEvent::CAUSE_LAVA:
$message = $this->getName() . " tried to swim in lava"; $message = "death.attack.lava";
break; break;
case EntityDamageEvent::CAUSE_FIRE: case EntityDamageEvent::CAUSE_FIRE:
$message = $this->getName() . " went up in flames"; $message = "death.attack.onFire";
break; break;
case EntityDamageEvent::CAUSE_FIRE_TICK: case EntityDamageEvent::CAUSE_FIRE_TICK:
$message = $this->getName() . " burned to death"; $message = "death.attack.inFire";
break; break;
case EntityDamageEvent::CAUSE_DROWNING: case EntityDamageEvent::CAUSE_DROWNING:
$message = $this->getName() . " drowned"; $message = "death.attack.drown";
break; break;
case EntityDamageEvent::CAUSE_CONTACT: case EntityDamageEvent::CAUSE_CONTACT:
$message = $this->getName() . " was pricked to death"; if($cause instanceof EntityDamageByBlockEvent){
if($cause->getDamager()->getId() === Block::CACTUS){
$message = "death.attack.cactus";
}
}
break; break;
case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
$message = $this->getName() . " blew up"; if($cause instanceof EntityDamageByEntityEvent){
$e = $cause->getDamager();
if($e instanceof Living){
$message = "death.attack.explosion.player";
$params[] = $e->getName();
}
}else{
$message = "death.attack.explosion";
}
break; break;
case EntityDamageEvent::CAUSE_MAGIC: case EntityDamageEvent::CAUSE_MAGIC:
$message = "death.attack.magic";
break;
case EntityDamageEvent::CAUSE_CUSTOM: case EntityDamageEvent::CAUSE_CUSTOM:
default: default:
@ -2624,7 +2665,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
Entity::kill(); Entity::kill();
$this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), $message)); $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params)));
if(!$ev->getKeepInventory()){ if(!$ev->getKeepInventory()){
foreach($ev->getDrops() as $item){ foreach($ev->getDrops() as $item){

View File

@ -48,18 +48,18 @@ use pocketmine\event\level\LevelLoadEvent;
use pocketmine\event\server\ServerCommandEvent; use pocketmine\event\server\ServerCommandEvent;
use pocketmine\event\Timings; use pocketmine\event\Timings;
use pocketmine\event\TimingsHandler; use pocketmine\event\TimingsHandler;
use pocketmine\event\TranslationContainer;
use pocketmine\inventory\CraftingManager; use pocketmine\inventory\CraftingManager;
use pocketmine\inventory\InventoryType; use pocketmine\inventory\InventoryType;
use pocketmine\inventory\Recipe; use pocketmine\inventory\Recipe;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\lang\BaseLang;
use pocketmine\level\format\anvil\Anvil; use pocketmine\level\format\anvil\Anvil;
use pocketmine\level\format\leveldb\LevelDB; use pocketmine\level\format\leveldb\LevelDB;
use pocketmine\level\format\LevelProviderManager; use pocketmine\level\format\LevelProviderManager;
use pocketmine\level\format\mcregion\McRegion; use pocketmine\level\format\mcregion\McRegion;
use pocketmine\level\generator\biome\Biome; use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Flat; use pocketmine\level\generator\Flat;
use pocketmine\level\generator\GenerationInstanceManager;
use pocketmine\level\generator\GenerationRequestManager;
use pocketmine\level\generator\Generator; use pocketmine\level\generator\Generator;
use pocketmine\level\generator\normal\Normal; use pocketmine\level\generator\normal\Normal;
use pocketmine\level\Level; use pocketmine\level\Level;
@ -196,6 +196,9 @@ class Server{
private $networkCompressionAsync = true; private $networkCompressionAsync = true;
private $networkCompressionLevel = 7; private $networkCompressionLevel = 7;
/** @var BaseLang */
private $baseLang;
private $serverID; private $serverID;
private $autoloader; private $autoloader;
@ -380,13 +383,13 @@ class Server{
public static function getGamemodeString($mode){ public static function getGamemodeString($mode){
switch((int) $mode){ switch((int) $mode){
case Player::SURVIVAL: case Player::SURVIVAL:
return "SURVIVAL"; return "%gameMode.survival";
case Player::CREATIVE: case Player::CREATIVE:
return "CREATIVE"; return "%gameMode.creative";
case Player::ADVENTURE: case Player::ADVENTURE:
return "ADVENTURE"; return "%gameMode.adventure";
case Player::SPECTATOR: case Player::SPECTATOR:
return "SPECTATOR"; return "%gameMode.spectator";
} }
return "UNKNOWN"; return "UNKNOWN";
@ -404,22 +407,26 @@ class Server{
case (string) Player::SURVIVAL: case (string) Player::SURVIVAL:
case "survival": case "survival":
case "s": case "s":
case strtolower(Server::getInstance()->getLanguage()->get("gameMode.survival")):
return Player::SURVIVAL; return Player::SURVIVAL;
case (string) Player::CREATIVE: case (string) Player::CREATIVE:
case "creative": case "creative":
case "c": case "c":
case strtolower(Server::getInstance()->getLanguage()->get("gameMode.creative")):
return Player::CREATIVE; return Player::CREATIVE;
case (string) Player::ADVENTURE: case (string) Player::ADVENTURE:
case "adventure": case "adventure":
case "a": case "a":
case strtolower(Server::getInstance()->getLanguage()->get("gameMode.adventure")):
return Player::ADVENTURE; return Player::ADVENTURE;
case (string) Player::SPECTATOR: case (string) Player::SPECTATOR:
case "spectator": case "spectator":
case "view": case "view":
case "v": case "v":
case strtolower(Server::getInstance()->getLanguage()->get("gameMode.spectator")):
return Player::SPECTATOR; return Player::SPECTATOR;
} }
return -1; return -1;
@ -1512,6 +1519,8 @@ class Server{
"auto-save" => true, "auto-save" => true,
]); ]);
$this->baseLang = new BaseLang($this->getProperty("settings.settings.language", "en"));
ServerScheduler::$WORKERS = $this->getProperty("settings.async-workers", ServerScheduler::$WORKERS); ServerScheduler::$WORKERS = $this->getProperty("settings.async-workers", ServerScheduler::$WORKERS);
if($this->getProperty("network.batch-threshold", 256) >= 0){ if($this->getProperty("network.batch-threshold", 256) >= 0){
@ -1859,11 +1868,8 @@ class Server{
return true; return true;
} }
if($sender instanceof Player){
$sender->sendMessage("Unknown command. Type \"/help\" for help."); $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.notFound"));
}else{
$sender->sendMessage("Unknown command. Type \"help\" for help.");
}
return false; return false;
} }
@ -1943,7 +1949,7 @@ class Server{
$this->pluginManager->disablePlugins(); $this->pluginManager->disablePlugins();
foreach($this->players as $player){ foreach($this->players as $player){
$player->close(TextFormat::YELLOW . $player->getName() . " has left the game", $this->getProperty("settings.shutdown-message", "Server closed")); $player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed"));
} }
foreach($this->getLevels() as $level){ foreach($this->getLevels() as $level){
@ -2005,7 +2011,7 @@ class Server{
$this->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "checkTicks"]), 20 * 5); $this->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "checkTicks"]), 20 * 5);
$this->logger->info("Default game type: " . self::getGamemodeString($this->getGamemode())); $this->logger->info("Default game type: " . $this->getLanguage()->get(self::getGamemodeString($this->getGamemode())));
$this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"'); $this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"');
@ -2255,6 +2261,17 @@ class Server{
$this->scheduler->scheduleAsyncTask($this->lastSendUsage); $this->scheduler->scheduleAsyncTask($this->lastSendUsage);
} }
/**
* @return BaseLang
*/
public function getLanguage(){
return $this->baseLang;
}
/**
* @return Network
*/
public function getNetwork(){ public function getNetwork(){
return $this->network; return $this->network;
} }

View File

@ -24,7 +24,9 @@
*/ */
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\event\TextContainer;
use pocketmine\event\TimingsHandler; use pocketmine\event\TimingsHandler;
use pocketmine\event\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -124,7 +126,7 @@ abstract class Command{
} }
if($this->permissionMessage === null){ if($this->permissionMessage === null){
$target->sendMessage(TextFormat::RED . "You don't have permissions to use this command."); $target->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
}elseif($this->permissionMessage !== ""){ }elseif($this->permissionMessage !== ""){
$target->sendMessage(str_replace("<permission>", $this->permission, $this->permissionMessage)); $target->sendMessage(str_replace("<permission>", $this->permission, $this->permissionMessage));
} }
@ -285,12 +287,25 @@ abstract class Command{
* @param bool $sendToSource * @param bool $sendToSource
*/ */
public static function broadcastCommandMessage(CommandSender $source, $message, $sendToSource = true){ public static function broadcastCommandMessage(CommandSender $source, $message, $sendToSource = true){
if($message instanceof TextContainer){
$m = clone $message;
$result = $source->getName() . ": " . $m->getText();
$users = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
$colored = TextFormat::GRAY . TextFormat::ITALIC . "[$result" . TextFormat::GRAY . TextFormat::ITALIC . "]";
$m->setText($result);
$result = clone $m;
$m->setText($colored);
$colored = clone $m;
}else{
$result = $source->getName() . ": " . $message; $result = $source->getName() . ": " . $message;
//Command minecarts or command blocks are not implemented //Command minecarts or command blocks are not implemented
$users = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_ADMINISTRATIVE); $users = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
$colored = TextFormat::GRAY . TextFormat::ITALIC . "[$result" . TextFormat::GRAY . TextFormat::ITALIC . "]"; $colored = TextFormat::GRAY . TextFormat::ITALIC . "[$result" . TextFormat::GRAY . TextFormat::ITALIC . "]";
}
if($sendToSource === true and !($source instanceof ConsoleCommandSender)){ if($sendToSource === true and !($source instanceof ConsoleCommandSender)){
$source->sendMessage($message); $source->sendMessage($message);
} }

View File

@ -21,6 +21,7 @@
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\event\TextContainer;
use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissionAttachment; use pocketmine\permission\PermissionAttachment;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
@ -102,6 +103,10 @@ class ConsoleCommandSender implements CommandSender{
* @param string $message * @param string $message
*/ */
public function sendMessage($message){ public function sendMessage($message){
if($message instanceof TextContainer){
$message = $this->getServer()->getLanguage()->translate($message);
}
foreach(explode("\n", trim($message)) as $line){ foreach(explode("\n", trim($message)) as $line){
MainLogger::getLogger()->info($line); MainLogger::getLogger()->info($line);
} }

View File

@ -21,6 +21,7 @@
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\event\TranslationContainer;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -56,7 +57,7 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
$success = $this->executor->onCommand($sender, $this, $commandLabel, $args); $success = $this->executor->onCommand($sender, $this, $commandLabel, $args);
if(!$success and $this->usageMessage !== ""){ if(!$success and $this->usageMessage !== ""){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
} }
return $success; return $success;

View File

@ -57,8 +57,10 @@ use pocketmine\command\defaults\TimingsCommand;
use pocketmine\command\defaults\VanillaCommand; use pocketmine\command\defaults\VanillaCommand;
use pocketmine\command\defaults\VersionCommand; use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WhitelistCommand; use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\event\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\MainLogger; use pocketmine\utils\MainLogger;
use pocketmine\utils\TextFormat;
class SimpleCommandMap implements CommandMap{ class SimpleCommandMap implements CommandMap{
@ -186,6 +188,7 @@ class SimpleCommandMap implements CommandMap{
try{ try{
$target->execute($sender, $sentCommandLabel, $args); $target->execute($sender, $sentCommandLabel, $args);
}catch(\Exception $e){ }catch(\Exception $e){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
$this->server->getLogger()->critical("Unhandled exception executing command '" . $commandLine . "' in " . $target . ": " . $e->getMessage()); $this->server->getLogger()->critical("Unhandled exception executing command '" . $commandLine . "' in " . $target . ": " . $e->getMessage());
$logger = $sender->getServer()->getLogger(); $logger = $sender->getServer()->getLogger();
if($logger instanceof MainLogger){ if($logger instanceof MainLogger){

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class BanCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class BanIpCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }
@ -57,7 +58,7 @@ class BanIpCommand extends VanillaCommand{
if(($player = $sender->getServer()->getPlayer($value)) instanceof Player){ if(($player = $sender->getServer()->getPlayer($value)) instanceof Player){
$this->processIPBan($player->getAddress(), $sender, $reason); $this->processIPBan($player->getAddress(), $sender, $reason);
}else{ }else{
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -22,6 +22,7 @@
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -42,7 +43,7 @@ class DefaultGamemodeCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }
@ -51,7 +52,7 @@ class DefaultGamemodeCommand extends VanillaCommand{
if($gameMode !== -1){ if($gameMode !== -1){
$sender->getServer()->setConfigInt("gamemode", $gameMode); $sender->getServer()->setConfigInt("gamemode", $gameMode);
$sender->sendMessage("Default game mode set to " . strtolower(Server::getGamemodeString($gameMode))); $sender->sendMessage(new TranslationContainer("commands.defaultgamemode.success", [Server::getGamemodeString($gameMode)]));
}else{ }else{
$sender->sendMessage("Unknown game mode"); $sender->sendMessage("Unknown game mode");
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class DeopCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -22,6 +22,7 @@
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class DifficultyCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -25,6 +25,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\entity\Effect; use pocketmine\entity\Effect;
use pocketmine\entity\InstantEffect; use pocketmine\entity\InstantEffect;
use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
class EffectCommand extends VanillaCommand{ class EffectCommand extends VanillaCommand{
@ -33,7 +34,7 @@ class EffectCommand extends VanillaCommand{
parent::__construct( parent::__construct(
$name, $name,
"Adds/Removes effects on players", "Adds/Removes effects on players",
"/effect <player> <effect|clear> [seconds] [amplifier]" "%commands.effect.usage"
); );
$this->setPermission("pocketmine.command.effect"); $this->setPermission("pocketmine.command.effect");
} }
@ -44,7 +45,7 @@ class EffectCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }
@ -61,7 +62,7 @@ class EffectCommand extends VanillaCommand{
$player->removeEffect($effect->getId()); $player->removeEffect($effect->getId());
} }
$sender->sendMessage("Took all effects from " . $player->getDisplayName()); $sender->sendMessage(new TranslationContainer("commands.effect.success.removed.all", [$player->getDisplayName()]));
return true; return true;
} }
@ -72,7 +73,7 @@ class EffectCommand extends VanillaCommand{
} }
if($effect === null){ if($effect === null){
$sender->sendMessage(TextFormat::RED . "Effect {$args[1]} not found"); $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.effect.notFound", [(string) $args[1]]));
return true; return true;
} }
@ -92,19 +93,30 @@ class EffectCommand extends VanillaCommand{
$amplification = (int) $args[3]; $amplification = (int) $args[3];
} }
if(count($args) >= 5){
$v = strtolower($args[4]);
if($v === "on" or $v === "true" or $v === "t" or $v === "1"){
$effect->setVisible(false);
}
}
if($duration === 0){ if($duration === 0){
if(!$player->hasEffect($effect->getId())){ if(!$player->hasEffect($effect->getId())){
$sender->sendMessage("Couldn't take ". $effect->getName() ." from ". $player->getDisplayName()); if(count($player->getEffects()) === 0){
$sender->sendMessage(new TranslationContainer("commands.effect.failure.notActive.all", [$player->getDisplayName()]));
}else{
$sender->sendMessage(new TranslationContainer("commands.effect.failure.notActive", [$effect->getName(), $player->getDisplayName()]));
}
return true; return true;
} }
$player->removeEffect($effect->getId()); $player->removeEffect($effect->getId());
$sender->sendMessage("Took ". $effect->getName() ." from ". $player->getDisplayName()); $sender->sendMessage(new TranslationContainer("commands.effect.success.removed", [$effect->getName(), $player->getDisplayName()]));
}else{ }else{
$effect->setDuration($duration)->setAmplifier($amplification); $effect->setDuration($duration)->setAmplifier($amplification);
$player->addEffect($effect); $player->addEffect($effect);
self::broadcastCommandMessage($sender, "Given ". $effect->getName() ." (ID ". $effect->getId().") * ". $effect->getAmplifier()." to ". $player->getDisplayName() ." for ". ($effect->getDuration() / 20) ." seconds"); self::broadcastCommandMessage($sender, new TranslationContainer("%commands.effect.success", [$effect->getName(), $effect->getId(), $effect->getAmplifier(), $player->getDisplayName(), $effect->getDuration() / 20]));
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -44,7 +45,7 @@ class GamemodeCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }
@ -66,7 +67,7 @@ class GamemodeCommand extends VanillaCommand{
return true; return true;
} }
}elseif(!($sender instanceof Player)){ }elseif(!($sender instanceof Player)){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -33,7 +34,7 @@ class GiveCommand extends VanillaCommand{
parent::__construct( parent::__construct(
$name, $name,
"Gives the specified player a certain amount of items", "Gives the specified player a certain amount of items",
"/give <player> <item[:damage]> [amount]" "/give <player> <item[:damage]> [amount]" //No translation :(
); );
$this->setPermission("pocketmine.command.give"); $this->setPermission("pocketmine.command.give");
} }
@ -44,7 +45,7 @@ class GiveCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }
@ -59,13 +60,8 @@ class GiveCommand extends VanillaCommand{
} }
if($player instanceof Player){ if($player instanceof Player){
if(($player->getGamemode() & 0x01) === 0x01){ if($item->getId() === 0){
$sender->sendMessage(TextFormat::RED . "Player is in creative mode"); $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]]));
return true;
}
if($item->getId() == 0){
$sender->sendMessage(TextFormat::RED . "There is no item called " . $args[1] . ".");
return true; return true;
} }
@ -78,8 +74,11 @@ class GiveCommand extends VanillaCommand{
return true; return true;
} }
Command::broadcastCommandMessage($sender, "Gave " . $player->getName() . " " . $item->getCount() . " of " . $item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")"); Command::broadcastCommandMessage($sender, new TranslationContainer("%commands.give.success", [
$item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")",
(string) $item->getCount(),
$player->getName()
]));
return true; return true;
} }
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class KickCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -22,6 +22,7 @@
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
@ -31,7 +32,7 @@ class ListCommand extends VanillaCommand{
parent::__construct( parent::__construct(
$name, $name,
"Lists all online players", "Lists all online players",
"/list" "%command.players.usage"
); );
$this->setPermission("pocketmine.command.list"); $this->setPermission("pocketmine.command.list");
} }
@ -51,7 +52,7 @@ class ListCommand extends VanillaCommand{
} }
} }
$sender->sendMessage("There are " . $onlineCount . "/" . $sender->getServer()->getMaxPlayers() . " players online:\n" . substr($online, 0, -2)); $sender->sendMessage(new TranslationContainer("%commands.players.list " . substr($online, 0, -2), [$onlineCount, $sender->getServer()->getMaxPlayers()]));
return true; return true;
} }

View File

@ -22,6 +22,7 @@
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -42,7 +43,7 @@ class MeCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class OpCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
class PardonCommand extends VanillaCommand{ class PardonCommand extends VanillaCommand{
@ -42,7 +43,7 @@ class PardonCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
class PardonIpCommand extends VanillaCommand{ class PardonIpCommand extends VanillaCommand{
@ -42,7 +43,7 @@ class PardonIpCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\particle\BubbleParticle; use pocketmine\level\particle\BubbleParticle;
use pocketmine\level\particle\CriticalParticle; use pocketmine\level\particle\CriticalParticle;
@ -55,7 +56,7 @@ class ParticleCommand extends VanillaCommand{
parent::__construct( parent::__construct(
$name, $name,
"Adds particles to a world", "Adds particles to a world",
"/particle <name> <x> <y> <z> <xd> <yd> <zd> [count] [data]" "/particle <name> <x> <y> <z> <xd> <yd> <zd> [count] [data]" //No translation, different!
); );
$this->setPermission("pocketmine.command.particle"); $this->setPermission("pocketmine.command.particle");
} }
@ -66,7 +67,7 @@ class ParticleCommand extends VanillaCommand{
} }
if(count($args) < 7){ if(count($args) < 7){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }
@ -92,12 +93,12 @@ class ParticleCommand extends VanillaCommand{
$particle = $this->getParticle($name, $pos, $xd, $yd, $zd, $data); $particle = $this->getParticle($name, $pos, $xd, $yd, $zd, $data);
if($particle === null){ if($particle === null){
$sender->sendMessage(TextFormat::RED . "Unknown particle name (" . $name . ")"); $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.particle.notFound", [$name]));
return true; return true;
} }
$sender->sendMessage("Playing particle ". $name ." for ". $count ." times"); $sender->sendMessage(new TranslationContainer("commands.particle.success", [$name, $count]));
$random = new Random((int) (microtime(true) * 1000) + mt_rand()); $random = new Random((int) (microtime(true) * 1000) + mt_rand());

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender; use pocketmine\command\ConsoleCommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class SayCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -56,7 +57,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
$level = $sender->getServer()->getDefaultLevel(); $level = $sender->getServer()->getDefaultLevel();
$pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2])); $pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2]));
}else{ }else{
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\level\Position; use pocketmine\level\Position;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -89,7 +90,7 @@ class SpawnpointCommand extends VanillaCommand{
} }
} }
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -44,7 +45,7 @@ class TeleportCommand extends VanillaCommand{
} }
if(count($args) < 1 or count($args) > 4){ if(count($args) < 1 or count($args) > 4){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }
@ -102,7 +103,7 @@ class TeleportCommand extends VanillaCommand{
return true; return true;
} }
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }

View File

@ -22,6 +22,7 @@
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -43,7 +44,7 @@ class TellCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -39,7 +40,7 @@ class TimeCommand extends VanillaCommand{
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, $currentAlias, array $args){
if(count($args) < 1){ if(count($args) < 1){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }
@ -74,7 +75,7 @@ class TimeCommand extends VanillaCommand{
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false; return false;
} }
@ -115,7 +116,7 @@ class TimeCommand extends VanillaCommand{
} }
Command::broadcastCommandMessage($sender, "Added " . $value . " to time"); Command::broadcastCommandMessage($sender, "Added " . $value . " to time");
}else{ }else{
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
} }
return true; return true;

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TimingsHandler; use pocketmine\event\TimingsHandler;
use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
class TimingsCommand extends VanillaCommand{ class TimingsCommand extends VanillaCommand{
@ -44,7 +45,7 @@ class TimingsCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return true; return true;
} }

View File

@ -60,23 +60,27 @@ class Effect{
public static function init(){ public static function init(){
self::$effects = new \SplFixedArray(256); self::$effects = new \SplFixedArray(256);
self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "Speed", 124, 175, 198); self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "%potion.moveSpeed", 124, 175, 198);
self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "Slowness", 90, 108, 129, true); self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "%potion.moveSlowdown", 90, 108, 129, true);
self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "Swiftness", 217, 192, 67); self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "%potion.digSpeed", 217, 192, 67);
self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "Mining Fatigue", 74, 66, 23, true); self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "%potion.digSlowDown", 74, 66, 23, true);
self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "Strength", 147, 36, 35); self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "%potion.damageBoost", 147, 36, 35);
//self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "Healing", 248, 36, 35); //self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "%potion.heal", 248, 36, 35);
//self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "Harming", 67, 10, 9, true); //self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "%potion.harm", 67, 10, 9, true);
self::$effects[Effect::NAUSEA] = new Effect(Effect::NAUSEA, "Nausea", 85, 29, 74, true); self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "%potion.jump", 34, 255, 76);
self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "Jump", 34, 255, 76); self::$effects[Effect::NAUSEA] = new Effect(Effect::NAUSEA, "%potion.confusion", 85, 29, 74, true);
self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "Regeneration", 205, 92, 171); self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "%potion.regeneration", 205, 92, 171);
self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance", 153, 69, 58); self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "%potion.resistance", 153, 69, 58);
self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "Fire Resistance", 228, 154, 58); self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58);
self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "Water Breathing", 46, 82, 153); self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "waterBreathing", 46, 82, 153);
self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "Invisibility", 127, 131, 146); self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146);
self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", 72, 77, 72 , true); //Hunger
self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", 78, 147, 49, true); self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weaknesss", 72, 77, 72 , true);
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", 53, 42, 39, true); self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true);
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true);
//Health Boost
//Absorption
//Saturation
} }
/** /**

View File

@ -587,7 +587,7 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* @return int|EntityDamageEvent|null * @return EntityDamageEvent|null
*/ */
public function getLastDamageCause(){ public function getLastDamageCause(){
return $this->lastDamageCause; return $this->lastDamageCause;

View File

@ -0,0 +1,56 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\event;
use pocketmine\Player;
class TextContainer{
/** @var string $text */
protected $text;
public function __construct($text){
$this->text = $text;
}
public function setText($text){
$this->text = $text;
}
/**
* @return string
*/
public function getText(){
return $this->text;
}
public function send(Player $p){
$p->sendMessage($this->getText());
}
/**
* @return string
*/
public function __toString(){
return $this->getText();
}
}

View File

@ -0,0 +1,84 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\event;
use pocketmine\Player;
class TranslationContainer extends TextContainer{
/** @var string[] $params */
protected $params = [];
/**
* @param string $text
* @param string[] $params
*/
public function __construct($text, array $params = []){
parent::__construct($text);
$this->setParameters($params);
}
/**
* @return string[]
*/
public function getParameters(){
return $this->params;
}
/**
* @param int $i
*
* @return string
*/
public function getParameter($i){
return isset($this->params[$i]) ? $this->params[$i] : null;
}
/**
* @param int $i
* @param string $str
*/
public function setParameter($i, $str){
if($i < 0 or $i > count($this->params)){ //Intended, allow to set the last
throw new \InvalidArgumentException("Invalid index $i, have " . count($this->params));
}
$this->params[(int) $i] = $str;
}
/**
* @param string[] $params
*/
public function setParameters(array $params){
$i = 0;
foreach($params as $str){
$this->params[$i] = (string) $str;
++$i;
}
}
public function send(Player $p){
$p->sendTranslation($this->getText(), $this->getParameters());
}
}

View File

@ -22,19 +22,21 @@
namespace pocketmine\event\player; namespace pocketmine\event\player;
use pocketmine\event\entity\EntityDeathEvent; use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\TextContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\Player; use pocketmine\Player;
class PlayerDeathEvent extends EntityDeathEvent{ class PlayerDeathEvent extends EntityDeathEvent{
public static $handlerList = null; public static $handlerList = null;
/** @var TextContainer|string */
private $deathMessage; private $deathMessage;
private $keepInventory = false; private $keepInventory = false;
/** /**
* @param Player $entity * @param Player $entity
* @param Item[] $drops * @param Item[] $drops
* @param string $deathMessage * @param string|TextContainer $deathMessage
*/ */
public function __construct(Player $entity, array $drops, $deathMessage){ public function __construct(Player $entity, array $drops, $deathMessage){
parent::__construct($entity, $drops); parent::__construct($entity, $drops);
@ -48,10 +50,16 @@ class PlayerDeathEvent extends EntityDeathEvent{
return $this->entity; return $this->entity;
} }
/**
* @return TextContainer|string
*/
public function getDeathMessage(){ public function getDeathMessage(){
return $this->deathMessage; return $this->deathMessage;
} }
/**
* @param string|TextContainer $deathMessage
*/
public function setDeathMessage($deathMessage){ public function setDeathMessage($deathMessage){
$this->deathMessage = $deathMessage; $this->deathMessage = $deathMessage;
} }

View File

@ -21,6 +21,7 @@
namespace pocketmine\event\player; namespace pocketmine\event\player;
use pocketmine\event\TextContainer;
use pocketmine\Player; use pocketmine\Player;
/** /**
@ -29,7 +30,7 @@ use pocketmine\Player;
class PlayerJoinEvent extends PlayerEvent{ class PlayerJoinEvent extends PlayerEvent{
public static $handlerList = null; public static $handlerList = null;
/** @var string */ /** @var string|TextContainer */
protected $joinMessage; protected $joinMessage;
public function __construct(Player $player, $joinMessage){ public function __construct(Player $player, $joinMessage){
@ -38,12 +39,15 @@ class PlayerJoinEvent extends PlayerEvent{
} }
/** /**
* @param string $joinMessage * @param string|TextContainer $joinMessage
*/ */
public function setJoinMessage($joinMessage){ public function setJoinMessage($joinMessage){
$this->joinMessage = $joinMessage; $this->joinMessage = $joinMessage;
} }
/**
* @return string|TextContainer
*/
public function getJoinMessage(){ public function getJoinMessage(){
return $this->joinMessage; return $this->joinMessage;
} }

View File

@ -0,0 +1,159 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\lang;
use pocketmine\event\TextContainer;
use pocketmine\event\TranslationContainer;
class BaseLang{
const FALLBACK_LANGUAGE = "en";
protected $langName;
protected $lang = [];
protected $fallbackLang = [];
public function __construct($lang, $path = null){
$this->langName = strtolower($lang);
if($path === null){
$path = \pocketmine\PATH . "src/pocketmine/lang/base/";
}
$this->loadLang($path . $this->langName . ".ini", $this->lang);
$this->loadLang($path . self::FALLBACK_LANGUAGE . ".ini", $this->fallbackLang);
}
public function getName(){
return $this->get("language.name");
}
public function getLang(){
return $this->langName;
}
protected function loadLang($path, array &$d){
if(file_exists($path) and strlen($content = file_get_contents($path)) > 0){
foreach(explode("\n", $content) as $line){
$line = trim($line);
if($line === "" or $line{0} === "#"){
continue;
}
$t = explode("=", $line);
if(count($t) < 2){
continue;
}
$key = trim(array_shift($t));
$value = trim(implode("=", $t));
if($value === ""){
continue;
}
$d[$key] = $value;
}
}
}
public function translate(TextContainer $c){
if($c instanceof TranslationContainer){
$baseText = $this->get($c->getText());
$baseText = $this->parseTranslation( $baseText !== null ? $baseText : $c->getText());
foreach($c->getParameters() as $i => $p){
$baseText = str_replace("{%$i}", $this->parseTranslation($p), $baseText);
}
}else{
$baseText = $this->parseTranslation($c->getText());
}
return $baseText;
}
public function internalGet($id){
if(isset($this->lang[$id])){
return $this->lang[$id];
}elseif(isset($this->fallbackLang[$id])){
return $this->fallbackLang[$id];
}
return null;
}
public function get($id){
$id = trim($id, "%");
if(isset($this->lang[$id])){
return $this->lang[$id];
}elseif(isset($this->fallbackLang[$id])){
return $this->fallbackLang[$id];
}
return $id;
}
protected function parseTranslation($text){
$newString = "";
$replaceString = null;
$len = strlen($text);
for($i = 0; $i < $len; ++$i){
$c = $text{$i};
if($replaceString !== null){
if((ord($c) >= 0x30 and ord($c) <= 0x39) or (ord($c) >= 0x41 and ord($c) <= 0x5a) or (ord($c) >= 0x61 and ord($c) <= 0x7a) or $c === "."){
$replaceString .= $c;
}else{
if(($t = $this->internalGet(substr($replaceString, 1)))){
$newString .= $t;
}else{
$newString .= $replaceString;
}
$replaceString = null;
if($c === "%"){
$replaceString = $c;
}else{
$newString .= $c;
}
}
}elseif($c === "%"){
$replaceString = $c;
}else{
$newString .= $c;
}
}
if($replaceString !== null){
if(($t = $this->internalGet(substr($replaceString, 1)))){
$newString .= $t;
}else{
$newString .= $replaceString;
}
}
return $newString;
}
}

View File

@ -0,0 +1,84 @@
# Language file compatible with Minecraft: Pocket Edition identifiers
#
# A message doesn't need to be there to be shown correctly on the client.
# Only messages shown in PocketMine itself need to be here
language.name=English
multiplayer.player.joined={%0} joined the game
multiplayer.player.leave={%0} left the game
death.fell.accident.generic={%0} fell from a high place
death.attack.inFire={%0} went up in flames
death.attack.onFire={%0} burned to death
death.attack.lava={%0} tried to swim in lava
death.attack.inWall={%0} suffocated in a wall
death.attack.drown={%0} drowned
death.attack.cactus={%0} was pricked to death
death.attack.generic={%0} died
death.attack.explosion={%0} blew up
death.attack.explosion.player={%0} was blown up by {%1}
death.attack.magic={%0} was killed by magic
death.attack.wither={%0} withered away
death.attack.mob={%0} was slain by {%1}
death.attack.player={%0} was slain by {%1}
death.attack.player.item={%0} was slain by {%1} using {%2}
death.attack.arrow={%0} was shot by {%1}
death.attack.arrow.item={%0} was shot by {%1} using {%2}
death.attack.fall={%0} hit the ground too hard
death.attack.outOfWorld={%0} fell out of the world
gameMode.survival=Survival Mode
gameMode.creative=Creative Mode
gameMode.adventure=Adventure Mode
gameMode.spectator=Spectator Mode
gameMode.changed=Your game mode has been updated
potion.moveSpeed=Speed
potion.moveSlowdown=Slowness
potion.digSpeed=Haste
potion.digSlowDown=Mining Fatigue
potion.damageBoost=Strength
potion.heal=Instant Health
potion.harm=Instant Damage
potion.jump=Jump Boost
potion.confusion=Nausea
potion.regeneration=Regeneration
potion.resistance=Resistance
potion.fireResistance=Fire Resistance
potion.waterBreathing=Water Breathing
potion.invisibility=Invisibility
potion.blindness=Blindness
potion.nightVision=Night Vision
potion.hunger=Hunger
potion.weakness=Weakness
potion.poison=Poison
potion.wither=Wither
potion.healthBoost=Health Boost
potion.absorption=Absorption
potion.saturation=Saturation
commands.generic.exception=An unknown error occurred while attempting to perform this command
commands.generic.permission=You do not have permission to use this command
commands.generic.notFound=Unknown command. Try /help for a list of commands
commands.generic.usage=Usage: {%0}
commands.give.item.notFound=There is no such item with name {%0}
commands.give.success=Given {%0} * {%1} to {%2}
commands.effect.usage=/effect <player> <effect> [seconds] [amplifier] [hideParticles] OR /effect <player> clear
commands.effect.notFound=There is no such mob effect with ID {%0}
commands.effect.success=Given {%0} (ID {%1}) * {%2} to {%3} for {%4} seconds
commands.effect.success.removed=Took {%0} from {%1}
commands.effect.success.removed.all=Took all effects from {%0}
commands.effect.failure.notActive=Couldn't take {%0} from {%1} as they do not have the effect
commands.effect.failure.notActive.all=Couldn't take any effects from {%0} as they do not have any
commands.particle.success=Playing effect {%0} for {%1} times
commands.particle.notFound=Unknown effect name {%0}
commands.players.usage=/list
commands.players.list=There are {%0}/{%1} players online:
commands.defaultgamemode.usage=/defaultgamemode <mode>
commands.defaultgamemode.success=The world's default game mode is now {%0}

View File

@ -443,7 +443,7 @@ class Level implements ChunkManager, Metadatable{
$defaultLevel = $this->server->getDefaultLevel(); $defaultLevel = $this->server->getDefaultLevel();
foreach($this->getPlayers() as $player){ foreach($this->getPlayers() as $player){
if($this === $defaultLevel or $defaultLevel === null){ if($this === $defaultLevel or $defaultLevel === null){
$player->close(TextFormat::YELLOW . $player->getName() . " has left the game", "Forced default level unload"); $player->close($player->getLeaveMessage(), "Forced default level unload");
}elseif($defaultLevel instanceof Level){ }elseif($defaultLevel instanceof Level){
$player->teleport($this->server->getDefaultLevel()->getSafeSpawn()); $player->teleport($this->server->getDefaultLevel()->getSafeSpawn());
} }

View File

@ -117,7 +117,9 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
unset($this->players[$identifier]); unset($this->players[$identifier]);
unset($this->batchedPackets[$identifier]); unset($this->batchedPackets[$identifier]);
unset($this->identifiersACK[$identifier]); unset($this->identifiersACK[$identifier]);
$player->close(TextFormat::YELLOW . $player->getName() . " has left the game", $reason); if(!$player->closed){
$player->close($player->getLeaveMessage(), $reason);
}
} }
} }