8000 Add infinite attribute to blocks by CoWinkKeyDinkInc · Pull Request #931 · PGMDev/PGM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add infinite attribute to blocks #931

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

Merged
merged 9 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/src/main/java/tc/oc/pgm/kits/KitMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
Expand Down Expand Up @@ -172,4 +173,13 @@ public void checkItemTransfer(ItemTransferEvent event) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void checkInfiniteBlocks(BlockPlaceEvent event) {
final ItemStack item = event.getPlayer().getItemInHand();
if (ItemTags.INFINITE.has(item)) {
// infinite block contains -1 items, giving -1 items sets the amount back to -1
item.setAmount(-1);
}
}
}
14 changes: 13 additions & 1 deletion core/src/main/java/tc/oc/pgm/kits/KitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ public ItemStack parseItem(Element el, Material type) throws InvalidXMLException
}

public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException {
int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1);
int amount = XMLUtils.parseNumber(Node.fromAttr(el, "amount"), Integer.class, true, 1);

// amount returns max value of integer if "oo" is given as amount
if (amount == Integer.MAX_VALUE) amount = -1;

// must be CraftItemStack to keep track of NBT data
ItemStack itemStack = NMSHacks.craftItemCopy(new ItemStack(type, amount, damage));
Expand All @@ -422,7 +425,12 @@ public ItemStack parseItem(Element el, Material type, short damage) throws Inval
throw new InvalidXMLException("Invalid item/block", el);
}

if (amount == -1 && !itemStack.getType().isBlock()) {
throw new InvalidXMLException("infinity can only be applied to a block material", el);
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we support infinite snowballs or enderpearls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't tested them at the time, I'll see if works.

}

ItemMeta meta = itemStack.getItemMeta();

if (meta != null) { // This happens if the item is "air"
parseItemMeta(el, meta);
itemStack.setItemMeta(meta);
Expand Down Expand Up @@ -539,6 +547,10 @@ public void parseCustomNBT(Element el, ItemStack itemStack) throws InvalidXMLExc
ItemTags.PREVENT_SHARING.set(itemStack, true);
}

if (itemStack.getAmount() == -1) {
ItemTags.INFINITE.set(itemStack, true);
}

Node projectileNode = Node.fromAttr(el, "projectile");
if (projectileNode != null) {
ItemTags.PROJECTILE.set(
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/tc/oc/pgm/kits/tag/ItemTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ItemTags {
public static final ItemTag<Boolean> PREVENT_SHARING = ItemTag.newBoolean("prevent-sharing");
public static final ItemTag<String> PROJECTILE = ItemTag.newString("projectile");
public static final ItemTag<String> ORIGINAL_NAME = ItemTag.newString("original-name");
public static final ItemTag<Boolean> INFINITE = ItemTag.newBoolean("infinite");

private ItemTags() {}
}
0