Skip to content

Commit

Permalink
Support for NBT changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Feb 17, 2018
1 parent 52e8a51 commit f594d36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PiggyCustomEnchants
main: PiggyCustomEnchants\Main
version: 1.1.1
version: 1.1.2
api: 3.0.0-ALPHA11
load: POSTWORLD
author: DaPigGuy
Expand Down
35 changes: 15 additions & 20 deletions src/PiggyCustomEnchants/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,40 +481,30 @@ public function addEnchantment(Item $item, $enchants, $levels, $check = true, Co
if ($item->getId() == Item::BOOK) {
$item = Item::get(Item::ENCHANTED_BOOK, $level);
}
if (!$item->hasCompoundTag()) {
$tag = new CompoundTag("", []);
} else {
$tag = $item->getNamedTag();
}
if (!isset($tag->ench)) {
$tag->ench = new ListTag("ench", []);
$tag->ench->setTagType(NBT::TAG_Compound);
}
$found = false;
$ench = $item->getNamedTagEntry(Item::TAG_ENCH);
$found = false;
if (!($ench instanceof ListTag)) {
$ench = new ListTag(Item::TAG_ENCH, [], NBT::TAG_Compound);
} else {
foreach ($ench as $k => $entry) {
if ($entry->getShort("id") === $enchant->getId()) {
$ench[$k] = new CompoundTag("", [
$ench->set($k, new CompoundTag("", [
new ShortTag("id", $enchant->getId()),
new ShortTag("lvl", $level)
]);
]));
$item->setCustomName(str_replace($this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($entry["lvl"]), $this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($level), $item->getName()));
$found = true;
break;
}
}
}
if (!$found) {
$ench[count($ench)] = new CompoundTag("", [
$ench->push(new CompoundTag("", [
new ShortTag("id", $enchant->getId()),
new ShortTag("lvl", $level)
]);
]));
$item->setCustomName($item->getName() . "\n" . $this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($level));
}
$item->setNamedTagEntry($ench);
if ($sender !== null) {
$sender->sendMessage(TextFormat::GREEN . "Enchanting succeeded.");
}
Expand Down Expand Up @@ -558,13 +548,18 @@ public function removeEnchantment(Item $item, $enchant, $level = -1)
if ($enchant instanceof EnchantmentInstance) {
$enchant = $enchant->getType();
}
$tag = $item->getNamedTag();
$item = Item::get($item->getId(), $item->getDamage(), $item->getCount());
foreach ($tag->ench as $k => $enchantment) {
if (($enchantment["id"] == $enchant->getId() && ($enchantment["lvl"] == $level || $level == -1)) !== true) {
$item = $this->addEnchantment($item, $enchantment["id"], $enchantment["lvl"], true);
$ench = $item->getNamedTagEntry(Item::TAG_ENCH);
if (!($ench instanceof ListTag)) {
return false;
}
foreach ($ench as $k => $entry) {
if ($entry->getShort("id") === $enchant->getId() and ($level === -1 or $entry->getShort("lvl") === $level)) {
$ench->remove($k);
$item->setCustomName(str_replace("\n" . $this->getRarityColor($enchant->getRarity()) . $enchant->getName() . " " . $this->getRomanNumber($entry->getShort("lvl")), "", $item->getCustomName()));
break;
}
}
$item->setNamedTagEntry($ench);
return $item;
}

Expand Down

1 comment on commit f594d36

@robske110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear @DaPigGuy:
I regret to inform you that the release you submitted, named "PiggyCustomEnchants" (v1.1.2), for the project PiggyCustomEnchants on 2018-02-17T20:44:08.000Z, has been rejected.

This release is not compatible with the ALPHA11 release.
Please note that changes on master do not reflect the current API version. The "Alpha" promotion on jenkins/github releases do indicate the latest api version plugins should be aiming for. You can resubmit these changes for ALPHA12(or maybe something else, new versioning scheme is in the wroks), but I recommend reverting the commit/moving it to another branch right now or maintaining a (true) ALPHA11 compatible branch.

Note: This comment is created here because this is the last commit when the released build was created.

via Poggit (@poggit-bot)

Please sign in to comment.