Skip to content

Commit

Permalink
Fix damage related issue
Browse files Browse the repository at this point in the history
blocks and items are cloned when we call Factory::get method, so we have to register them when they're modified

And more...
* bump version 0.0.2 -> 0.1.0
* Adjust load order (POSTWORLD)
  • Loading branch information
solo5star committed Jul 15, 2018
1 parent 9e31ee0 commit 8af3b74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: KoreanItem
version: 0.0.2
version: 0.1.0
author: solo
main: solo\koreanitem\KoreanItem
api: [3.0.0, 3.1.0, 4.0.0]
load: STARTUP
load: POSTWORLD
55 changes: 26 additions & 29 deletions src/solo/koreanitem/KoreanItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class KoreanItem extends PluginBase{
/** @var array */
private $list;

public function onLoad(){
public function onEnable(){
@mkdir($this->getDataFolder());

$this->saveResource("list.json");
Expand All @@ -32,7 +32,7 @@ public function onLoad(){
foreach($this->list as $id_meta => $name){
$token = explode(":", $id_meta);
$id = intval($token[0]);
$meta = intval($token[1] ?? 0);
$meta = intval($token[1]);

// 0 ~ 255 : Block
if($id < 256) $this->setBlockName($id, $meta, $name);
Expand All @@ -42,44 +42,41 @@ public function onLoad(){
}
}

public function setItemName(int $id, int $meta, string $name){
$item = ItemFactory::get($id, $meta);
if(!$item instanceof Renameable){
if($item instanceof Air){
$item = new Item($id, $meta);
}
$item = createRenameableItem($item);
$item->rename($meta, $name);
ItemFactory::registerItem($item, true); // override
}else{
$item->rename($meta, $name);
}
}

public function setBlockName(int $id, int $meta, string $name){
$block = BlockFactory::get($id, $meta);
if(!$block instanceof Renameable){
if($block instanceof UnknownBlock){
$block = new Block($id, $meta);
}
$block = createRenameableBlock($block);
$block->rename($meta, $name);
BlockFactory::registerBlock($block, true); // override
}else{
$block->rename($meta, $name);
}
$block->rename($meta, $name);
BlockFactory::registerBlock($block, true); // override
}

private function dump($obj){
$ref = new \ReflectionObject($obj);
echo PHP_EOL . "----- " . $ref->getShortName() . " -----" . PHP_EOL;
echo "class " . $ref->getName() . " extends " . $ref->getParentClass()->getName() . " implements " . implode($ref->getInterfaceNames(), " ") . PHP_EOL;
echo "Object name : " . $obj->getName() . PHP_EOL;
echo "...start dump..." . PHP_EOL;
var_dump($obj);
echo "...end dump..." . PHP_EOL;
echo "-----------------" . PHP_EOL;
public function setItemName(int $id, int $meta, string $name){
$item = ItemFactory::get($id, $meta);
if(!$item instanceof Renameable){
if($item instanceof Air){
$item = new Item($id, $meta);
}
$item = createRenameableItem($item);
$item->rename($meta, $name);
}
ItemFactory::registerItem($item, true); // override
$item->rename($meta, $name);
}

// private function dump($obj){
// $ref = new \ReflectionObject($obj);
// echo PHP_EOL . "----- " . $ref->getShortName() . " -----" . PHP_EOL;
// echo "class " . $ref->getName() . " extends " . $ref->getParentClass()->getName() . " implements " . implode($ref->getInterfaceNames(), " ") . PHP_EOL;
// echo "Object name : " . $obj->getName() . PHP_EOL;
// echo "...start dump..." . PHP_EOL;
// var_dump($obj);
// echo "...end dump..." . PHP_EOL;
// echo "-----------------" . PHP_EOL;
// }
}


Expand Down

0 comments on commit 8af3b74

Please sign in to comment.