Added base translation system

This commit is contained in:
Shoghi Cervantes
2015-04-11 01:32:08 +02:00
parent 3224cd7dc5
commit 0c041ebca3
38 changed files with 646 additions and 132 deletions

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

View File

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