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

Make event values return item stacks instead of item types if possible #4128

Merged
merged 4 commits into from
Jul 15, 2022
Merged
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
123 changes: 60 additions & 63 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ public Block get(final BlockIgniteEvent e) {
}
}, 0);
// BlockDispenseEvent
EventValues.registerEventValue(BlockDispenseEvent.class, ItemType.class, new Getter<ItemType, BlockDispenseEvent>() {
EventValues.registerEventValue(BlockDispenseEvent.class, ItemStack.class, new Getter<ItemStack, BlockDispenseEvent>() {
@Override
@Nullable
public ItemType get(final BlockDispenseEvent e) {
return new ItemType(e.getItem());
public ItemStack get(final BlockDispenseEvent e) {
return e.getItem();
}
}, 0);
// BlockCanBuildEvent
Expand Down Expand Up @@ -552,11 +552,11 @@ public PotionEffectType get(AreaEffectCloudApplyEvent e) {
}, 0);
}
// ItemSpawnEvent
EventValues.registerEventValue(ItemSpawnEvent.class, ItemType.class, new Getter<ItemType, ItemSpawnEvent>() {
EventValues.registerEventValue(ItemSpawnEvent.class, ItemStack.class, new Getter<ItemStack, ItemSpawnEvent>() {
@Override
@Nullable
public ItemType get(final ItemSpawnEvent e) {
return new ItemType(e.getEntity().getItemStack());
public ItemStack get(final ItemSpawnEvent e) {
return e.getEntity().getItemStack();
}
}, 0);
// LightningStrikeEvent
Expand Down Expand Up @@ -648,11 +648,11 @@ public Item get(final PlayerDropItemEvent e) {
return e.getItemDrop();
}
}, 0);
EventValues.registerEventValue(PlayerDropItemEvent.class, ItemType.class, new Getter<ItemType, PlayerDropItemEvent>() {
EventValues.registerEventValue(PlayerDropItemEvent.class, ItemStack.class, new Getter<ItemStack, PlayerDropItemEvent>() {
@Override
@Nullable
public ItemType get(final PlayerDropItemEvent e) {
return new ItemType(e.getItemDrop().getItemStack());
public ItemStack get(final PlayerDropItemEvent e) {
return e.getItemDrop().getItemStack();
}
}, 0);
// PlayerPickupItemEvent
Expand All @@ -670,11 +670,11 @@ public Item get(final PlayerPickupItemEvent e) {
return e.getItem();
}
}, 0);
EventValues.registerEventValue(PlayerPickupItemEvent.class, ItemType.class, new Getter<ItemType, PlayerPickupItemEvent>() {
EventValues.registerEventValue(PlayerPickupItemEvent.class, ItemStack.class, new Getter<ItemStack, PlayerPickupItemEvent>() {
@Override
@Nullable
public ItemType get(final PlayerPickupItemEvent e) {
return new ItemType(e.getItem().getItemStack());
public ItemStack get(final PlayerPickupItemEvent e) {
return e.getItem().getItemStack();
}
}, 0);
// EntityPickupItemEvent
Expand Down Expand Up @@ -702,21 +702,21 @@ public ItemType get(final EntityPickupItemEvent e) {
}
// PlayerItemConsumeEvent
if (Skript.supports("org.bukkit.event.player.PlayerItemConsumeEvent")) {
EventValues.registerEventValue(PlayerItemConsumeEvent.class, ItemType.class, new Getter<ItemType, PlayerItemConsumeEvent>() {
EventValues.registerEventValue(PlayerItemConsumeEvent.class, ItemStack.class, new Getter<ItemStack, PlayerItemConsumeEvent>() {
@Override
@Nullable
public ItemType get(final PlayerItemConsumeEvent e) {
return new ItemType(e.getItem());
public ItemStack get(final PlayerItemConsumeEvent e) {
return e.getItem();
}
}, 0);
}
// PlayerItemBreakEvent
if (Skript.supports("org.bukkit.event.player.PlayerItemBreakEvent")) {
EventValues.registerEventValue(PlayerItemBreakEvent.class, ItemType.class, new Getter<ItemType, PlayerItemBreakEvent>() {
EventValues.registerEventValue(PlayerItemBreakEvent.class, ItemStack.class, new Getter<ItemStack, PlayerItemBreakEvent>() {
@Override
@Nullable
public ItemType get(final PlayerItemBreakEvent e) {
return new ItemType(e.getBrokenItem());
public ItemStack get(final PlayerItemBreakEvent e) {
return e.getBrokenItem();
}
}, 0);
}
Expand All @@ -728,30 +728,29 @@ public Entity get(final PlayerInteractEntityEvent e) {
return e.getRightClicked();
}
}, 0);
EventValues.registerEventValue(PlayerInteractEntityEvent.class, ItemType.class, new Getter<ItemType, PlayerInteractEntityEvent>() {
EventValues.registerEventValue(PlayerInteractEntityEvent.class, ItemStack.class, new Getter<ItemStack, PlayerInteractEntityEvent>() {
@Override
@Nullable
public ItemType get(final PlayerInteractEntityEvent e) {
public ItemStack get(final PlayerInteractEntityEvent e) {
if (offHandSupport) {
EquipmentSlot hand = e.getHand();
if (hand == EquipmentSlot.HAND)
return new ItemType(e.getPlayer().getInventory().getItemInMainHand());
return e.getPlayer().getInventory().getItemInMainHand();
else if (hand == EquipmentSlot.OFF_HAND)
return new ItemType(e.getPlayer().getInventory().getItemInOffHand());
return e.getPlayer().getInventory().getItemInOffHand();
else
return null;
} else {
return new ItemType(e.getPlayer().getItemInHand());
return e.getPlayer().getItemInHand();
}
}
}, 0);
// PlayerInteractEvent
EventValues.registerEventValue(PlayerInteractEvent.class, ItemType.class, new Getter<ItemType, PlayerInteractEvent>() {
EventValues.registerEventValue(PlayerInteractEvent.class, ItemStack.class, new Getter<ItemStack, PlayerInteractEvent>() {
@Override
@Nullable
public ItemType get(final PlayerInteractEvent e) {
ItemStack item = e.getItem();
return item == null ? null : new ItemType(item);
public ItemStack get(final PlayerInteractEvent e) {
return e.getItem();
}
}, 0);
EventValues.registerEventValue(PlayerInteractEvent.class, Block.class, new Getter<Block, PlayerInteractEvent>() {
Expand Down Expand Up @@ -785,10 +784,10 @@ public Block get(final PlayerMoveEvent e) {
}
}, 0);
// PlayerItemDamageEvent
EventValues.registerEventValue(PlayerItemDamageEvent.class, ItemType.class, new Getter<ItemType, PlayerItemDamageEvent>() {
EventValues.registerEventValue(PlayerItemDamageEvent.class, ItemStack.class, new Getter<ItemStack, PlayerItemDamageEvent>() {
@Override
public ItemType get(PlayerItemDamageEvent event) {
return new ItemType(event.getItem());
public ItemStack get(PlayerItemDamageEvent event) {
return event.getItem();
}
}, 0);
//PlayerItemMendEvent
Expand All @@ -800,11 +799,11 @@ public Player get(PlayerItemMendEvent e) {
return e.getPlayer();
}
}, 0);
EventValues.registerEventValue(PlayerItemMendEvent.class, ItemType.class, new Getter<ItemType, PlayerItemMendEvent>() {
EventValues.registerEventValue(PlayerItemMendEvent.class, ItemStack.class, new Getter<ItemStack, PlayerItemMendEvent>() {
@Override
@Nullable
public ItemType get(PlayerItemMendEvent e) {
return new ItemType(e.getItem());
public ItemStack get(PlayerItemMendEvent e) {
return e.getItem();
}
}, 0);
EventValues.registerEventValue(PlayerItemMendEvent.class, Entity.class, new Getter<Entity, PlayerItemMendEvent>() {
Expand Down Expand Up @@ -982,14 +981,13 @@ public World get(final InventoryClickEvent e) {
return e.getWhoClicked().getWorld();
}
}, 0);
EventValues.registerEventValue(InventoryClickEvent.class, ItemType.class, new Getter<ItemType, InventoryClickEvent>() {
EventValues.registerEventValue(InventoryClickEvent.class, ItemStack.class, new Getter<ItemStack, InventoryClickEvent>() {
@Override
@Nullable
public ItemType get(final InventoryClickEvent e) {
public ItemStack get(final InventoryClickEvent e) {
if (e instanceof CraftItemEvent)
return new ItemType(((CraftItemEvent) e).getRecipe().getResult());
ItemStack item = e.getCurrentItem();
return item == null ? null : new ItemType(item);
return ((CraftItemEvent) e).getRecipe().getResult();
return e.getCurrentItem();
}
}, 0);
EventValues.registerEventValue(InventoryClickEvent.class, Slot.class, new Getter<Slot, InventoryClickEvent>() {
Expand Down Expand Up @@ -1148,11 +1146,11 @@ public Item get(InventoryPickupItemEvent event) {
return event.getItem();
}
}, 0);
EventValues.registerEventValue(InventoryPickupItemEvent.class, ItemType.class, new Getter<ItemType, InventoryPickupItemEvent>() {
EventValues.registerEventValue(InventoryPickupItemEvent.class, ItemStack.class, new Getter<ItemStack, InventoryPickupItemEvent>() {
@Nullable
@Override
public ItemType get(InventoryPickupItemEvent event) {
return new ItemType(event.getItem().getItemStack());
public ItemStack get(InventoryPickupItemEvent event) {
return event.getItem().getItemStack();
}
}, 0);
//PortalCreateEvent
Expand All @@ -1173,12 +1171,12 @@ public Entity get(final PortalCreateEvent e) {
}, 0);
}
//PlayerEditBookEvent
EventValues.registerEventValue(PlayerEditBookEvent.class, ItemType.class, new Getter<ItemType, PlayerEditBookEvent>() {
EventValues.registerEventValue(PlayerEditBookEvent.class, ItemStack.class, new Getter<ItemStack, PlayerEditBookEvent>() {
@Override
public ItemType get(PlayerEditBookEvent e) {
public ItemStack get(PlayerEditBookEvent e) {
ItemStack book = new ItemStack(e.getPlayer().getItemInHand().getType());
book.setItemMeta(e.getNewBookMeta());
return new ItemType(book); //TODO: Find better way to derive this event value
return book; // TODO: Find better way to derive this event value
}
}, 0);
//ItemDespawnEvent
Expand All @@ -1189,11 +1187,11 @@ public Item get(ItemDespawnEvent e) {
return e.getEntity();
}
}, 0);
EventValues.registerEventValue(ItemDespawnEvent.class, ItemType.class, new Getter<ItemType, ItemDespawnEvent>() {
EventValues.registerEventValue(ItemDespawnEvent.class, ItemStack.class, new Getter<ItemStack, ItemDespawnEvent>() {
@Override
@Nullable
public ItemType get(ItemDespawnEvent e) {
return new ItemType(e.getEntity().getItemStack());
public ItemStack get(ItemDespawnEvent e) {
return e.getEntity().getItemStack();
}
}, 0);
//ItemMergeEvent
Expand All @@ -1211,11 +1209,11 @@ public Item get(ItemMergeEvent e) {
return e.getTarget();
}
}, 1);
EventValues.registerEventValue(ItemMergeEvent.class, ItemType.class, new Getter<ItemType, ItemMergeEvent>() {
EventValues.registerEventValue(ItemMergeEvent.class, ItemStack.class, new Getter<ItemStack, ItemMergeEvent>() {
@Override
@Nullable
public ItemType get(ItemMergeEvent e) {
return new ItemType(e.getEntity().getItemStack());
public ItemStack get(ItemMergeEvent e) {
return e.getEntity().getItemStack();
}
}, 0);
//PlayerTeleportEvent
Expand Down Expand Up @@ -1271,21 +1269,20 @@ public FireworkEffect get(FireworkExplodeEvent e) {
}
//PlayerRiptideEvent
if (Skript.classExists("org.bukkit.event.player.PlayerRiptideEvent")) {
EventValues.registerEventValue(PlayerRiptideEvent.class, ItemType.class, new Getter<ItemType, PlayerRiptideEvent>() {
EventValues.registerEventValue(PlayerRiptideEvent.class, ItemStack.class, new Getter<ItemStack, PlayerRiptideEvent>() {
@Override
public ItemType get(PlayerRiptideEvent e) {
return new ItemType(e.getItem());
public ItemStack get(PlayerRiptideEvent e) {
return e.getItem();
}
}, 0);
}
//PlayerArmorChangeEvent
if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerArmorChangeEvent")) {
EventValues.registerEventValue(PlayerArmorChangeEvent.class, ItemType.class, new Getter<ItemType, PlayerArmorChangeEvent>() {
EventValues.registerEventValue(PlayerArmorChangeEvent.class, ItemStack.class, new Getter<ItemStack, PlayerArmorChangeEvent>() {
@Override
@Nullable
public ItemType get(PlayerArmorChangeEvent e) {
ItemStack stack = e.getNewItem();
return stack == null ? null : new ItemType(stack);
public ItemStack get(PlayerArmorChangeEvent e) {
return e.getNewItem();
}
}, 0);
}
Expand All @@ -1297,11 +1294,11 @@ public Player get(PrepareItemEnchantEvent e) {
return e.getEnchanter();
}
}, 0);
EventValues.registerEventValue(PrepareItemEnchantEvent.class, ItemType.class, new Getter<ItemType, PrepareItemEnchantEvent>() {
EventValues.registerEventValue(PrepareItemEnchantEvent.class, ItemStack.class, new Getter<ItemStack, PrepareItemEnchantEvent>() {
@Override
@Nullable
public ItemType get(PrepareItemEnchantEvent e) {
return new ItemType(e.getItem());
public ItemStack get(PrepareItemEnchantEvent e) {
return e.getItem();
}
}, 0);
EventValues.registerEventValue(PrepareItemEnchantEvent.class, Block.class, new Getter<Block, PrepareItemEnchantEvent>() {
Expand All @@ -1319,11 +1316,11 @@ public Player get(EnchantItemEvent e) {
return e.getEnchanter();
}
}, 0);
EventValues.registerEventValue(EnchantItemEvent.class, ItemType.class, new Getter<ItemType, EnchantItemEvent>() {
EventValues.registerEventValue(EnchantItemEvent.class, ItemStack.class, new Getter<ItemStack, EnchantItemEvent>() {
@Override
@Nullable
public ItemType get(EnchantItemEvent e) {
return new ItemType(e.getItem());
public ItemStack get(EnchantItemEvent e) {
return e.getItem();
}
}, 0);
EventValues.registerEventValue(EnchantItemEvent.class, Block.class, new Getter<Block, EnchantItemEvent>() {
Expand Down