Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v1.1.2 Fix translations & test solution entity spawn check error #153

Merged
merged 9 commits into from Apr 16, 2019
Merged
12 changes: 8 additions & 4 deletions README.md
@@ -1,8 +1,8 @@

## Festival

If you like Festival please [vote](https://poggit.pmmp.io/p/Festival/1.1.1) and [share your experience](https://github.com/genboy/Festival/issues) to help Festival plugin improve, thank you!

Consider posting your first [share your experience and issues](https://github.com/genboy/Festival/issues) before posting a [vote](https://poggit.pmmp.io/p/Festival/1.1.1) if you like to use Festival!
That way it will improve Festival, my coding skills, your PMMP insights and the PMMP community, thank you!
![Festival plugin logo large](https://genboy.net/wp-content/uploads/2018/02/festival_plugin_logo.png)
Create a festival with this custom area events plugin for Pocketmine Server:

Expand All @@ -17,7 +17,7 @@ Create a festival with this custom area events plugin for Pocketmine Server:
---

## Info
Festival 1.1.1 functionalities will not extend further more. Important bug fixes will still be done untill Festival 2 is ready.
Festival 1.1.2 functionalities will not extend further more. Important bug fixes will still be done untill Festival 2 is ready.
Festival 2 is in [development](https://github.com/genboy/Festival/projects/2) including FormUI for easy control, a new code structure and some of the flags will be completely rewritten. I probably dump the translations untill there is request for it. Just to let you know ..

# Festival
Expand Down Expand Up @@ -429,6 +429,10 @@ Thank you

**Since v1.1.0**
- fix griefing bug: adjusted in some functions to determine the needed position to validate the action(flag).

**Since v1.1.2**
- fix translation bug: adjusted utf-8 json encoding,
- Thanks to [@bptube](https://github.com/bptube) now including Spanish language!

------

Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
@@ -1,6 +1,6 @@
name: Festival
author: Genboy
version: 1.1.1
version: 1.1.2
main: genboy\Festival\Main
load: POSTWORLD
api: [3.0.0]
Expand Down
4 changes: 2 additions & 2 deletions resources/config.yml
Expand Up @@ -2,8 +2,8 @@

# Festival options
Options:
# select a language: English = en, Dutch = nl, translate please !
language: es
# select a language: English = en, Dutch = nl, translate please
Language: en

# Area Messages Display position (msg/title/tip/pop)
Msgtype: msg
Expand Down
30 changes: 20 additions & 10 deletions src/genboy/Festival/Main.php
Expand Up @@ -201,7 +201,8 @@ public function onEnable() : void{
}
$this->options = $c["Options"];
}else{
$this->options = array("Language"=>"en", "Msgtype"=>"pop", "Msgdisplay"=>"off", "AutoWhitelist"=>"on"); // Fallback defaults
$this->options = array("Language"=>"en", "Msgtype"=>"pop", "Msgdisplay"=>"off", "AutoWhitelist"=>"on"); // Fallback defaults
//$newchange['Options'] = "! Config Options missing in config.yml, defaults are set for now; please see /resources/config.yml";
$newchange['Options'] = "! ".Language::translate("option-missing-in-config")."; ". Language::translate("option-see-configfile");
}

Expand Down Expand Up @@ -430,7 +431,7 @@ public function onEnable() : void{
$this->saveAreas(); // all save $this->areaList available :)

/** load language translation class */
$this->loadLanguage( $languageCode = $this->options["Language"] );
$this->loadLanguage( $this->options["Language"] );

/** console output */
$this->getLogger()->info( Language::translate("enabled-console-msg") );
Expand Down Expand Up @@ -463,14 +464,22 @@ public function onEnable() : void{
* @file resources nl.json
* @var obj Language
*/
public function loadLanguage($languageCode = 'en' ){
public function loadLanguage( $languageCode = false ){

if( !$languageCode ){
$languageCode = 'en';
}

$resources = $this->getResources(); // read files in resources folder
foreach($resources as $resource){

foreach($resources as $resource){
if($resource->getFilename() === "en.json"){
$default = json_decode(file_get_contents($resource->getPathname(), true), true);
$text = utf8_encode( file_get_contents($resource->getPathname(), true) ); // json content in utf-8
$default = json_decode($text, true); // php decode utf-8
}
if($resource->getFilename() === $languageCode.".json"){
$setting = json_decode(file_get_contents($resource->getPathname(), true), true);
$text = utf8_encode( file_get_contents($resource->getPathname(), true) );
$setting = json_decode($text, true); // php decode utf-8
}
}
if(isset($setting)){
Expand All @@ -486,8 +495,8 @@ public function loadLanguage($languageCode = 'en' ){
* @var obj Player
*/
public function setLanguage( $lang, $player ){
$this->options["Language"] = $lang;
$this->loadLanguage();
$this->options["Language"] = strtolower( $lang );
$this->loadLanguage( $this->options["Language"] );
$msg = TextFormat::AQUA . Language::translate("language-selected");
$this->areaMessage( $msg, $player );
}
Expand Down Expand Up @@ -603,7 +612,7 @@ public function onCommand(CommandSender $sender, Command $cmd, string $label, ar
switch($action){
case "lang": // experiment v1.0.7.7-dev
if( isset($args[1]) ){
if($sender->hasPermission("festival") || $sender->hasPermission("festival.command") || $sender->hasPermission("festival.command.fe.lang")){
if($sender->hasPermission("festival") || $sender->hasPermission("festival.command") || $sender->hasPermission("festival.command.fe.lang")){
$lang = $args[1];
$this->setLanguage( $lang, $sender );
}
Expand Down Expand Up @@ -1539,6 +1548,7 @@ public function onDamage(EntityDamageEvent $event) : void{
$this->canDamage( $event );
}


/** Mob / Animal spawning
* @param EntitySpawnEvent $event
* @ignoreCancelled true
Expand All @@ -1547,7 +1557,7 @@ public function onEntitySpawn( EntitySpawnEvent $event ): void{

$e = $event->getEntity();
//($e instanceof Fire && !$this->canBurn( $e->getPosition() )) || (
if( !$e instanceof Player && !$this->canEntitySpawn( $e ) ){
if( !($e instanceof Player) && !$this->canEntitySpawn( $e ) ){
//$e->flagForDespawn() to slow / ? $e->close(); private..
$this->getServer()->getPluginManager()->callEvent(new EntityDespawnEvent($e));
$e->despawnFromAll();
Expand Down
9 changes: 0 additions & 9 deletions src/genboy/Festival/lang/Language.php
@@ -1,31 +1,22 @@
<?php declare(strict_types = 1);

/** src/genboy/Festival/lang/Language.php */

namespace genboy\Festival\lang;

class Language{

public static $instance;

public function __construct($owner, $langjson){

$this->owner = $owner;
$this->trans = $langjson;
self::$instance = $this;

}

static function translate($key){

$txt = self::$instance->trans[$key];
if (strpos($txt, "%n") != false) {
$text = str_replace("%n", "\n", $txt);
} else {
$text = $txt;
}
return $text;

}

}