-
-
Notifications
You must be signed in to change notification settings - Fork 115
Trial Spawner and Vaults 1.21 additions #2790
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
Changes from 6 commits
1a3467e
2fe9140
405bd9c
f9e83cc
e6d417f
6d75f5d
24735b9
a350d99
d656153
4fc35e7
50b36f8
f49ba9e
196794a
949977a
33f8d89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.denizenscript.denizen.paper.events; | ||
|
|
||
| import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
| import com.denizenscript.denizen.objects.LocationTag; | ||
| import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
| import io.papermc.paper.event.block.VaultChangeStateEvent; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
|
|
||
| public class VaultChangeStateScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
|
||
| // <--[event] | ||
| // @Events | ||
| // vault changes state | ||
| // | ||
| // @Plugin Paper | ||
| // | ||
| // @Group Block | ||
| // | ||
| // @Cancellable true | ||
| // | ||
| // @Location true | ||
| // | ||
| // @Triggers when a vault block's state changes. A list of states can be found at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/TrialSpawner.State.html>. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // | ||
| // @Context | ||
| // <context.location> returns the LocationTag of the vault block. | ||
| // <context.old_state> returns the vault state before the change. | ||
| // <context.new_state> returns the vault state after the change. | ||
| // | ||
| // @Player when the entity who triggered the change is a player. | ||
| // | ||
| // --> | ||
|
|
||
| public VaultChangeStateScriptEvent() { | ||
| registerCouldMatcher("vault changes state"); | ||
| } | ||
|
|
||
| public LocationTag location; | ||
| public VaultChangeStateEvent event; | ||
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!runInCheck(path, location)) { | ||
| return false; | ||
| } | ||
| return super.matches(path); | ||
| } | ||
|
|
||
| @Override | ||
| public ScriptEntryData getScriptEntryData() { | ||
| return new BukkitScriptEntryData(event.getPlayer()); | ||
| } | ||
|
|
||
| @Override | ||
| public ObjectTag getContext(String name) { | ||
| return switch (name) { | ||
| case "old_state" -> new ElementTag(event.getCurrentState()); | ||
| case "new_state" -> new ElementTag(event.getNewState()); | ||
| case "location" -> location; | ||
| default -> super.getContext(name); | ||
| }; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void onVaultChangeStateEvent(VaultChangeStateEvent event) { | ||
| location = new LocationTag(event.getBlock().getLocation()); | ||
| this.event = event; | ||
| fire(event); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.denizenscript.denizen.events.block; | ||
|
|
||
| import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
| import com.denizenscript.denizen.objects.*; | ||
| import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import com.denizenscript.denizencore.objects.core.ListTag; | ||
| import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.BlockDispenseLootEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class BlockDispenseLootScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the class name usually matches the Denizen name over the bukkit name, so that it's easier to spot in code for us. |
||
|
|
||
| // <--[event] | ||
| // @Events | ||
| // loot dispenses from <block> | ||
| // | ||
| // @Group Block | ||
| // | ||
| // @Location true | ||
| // | ||
| // @Cancellable true | ||
| // | ||
| // @Player Always. | ||
| // | ||
| // @Triggers when a block dispenses loot containing multiple items. | ||
| // | ||
| // @Context | ||
| // <context.loot> returns a ListTag(ItemTag) of outcome items. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // <context.location> returns a LocationTag of the block that is dispensing the items. | ||
| // | ||
| // @Determine | ||
| // "LOOT:<ListTag(ItemTag)>" to determine the new items that are outputted. | ||
| // | ||
| // --> | ||
|
|
||
| public BlockDispenseLootScriptEvent() { | ||
| registerCouldMatcher("loot dispenses from <block>"); | ||
| this.<BlockDispenseLootScriptEvent, ListTag>registerDetermination("loot", ListTag.class, (evt, context, input) -> { | ||
| List<ItemStack> items = new ArrayList<>(input.size()); | ||
| for (ItemTag item : input.filter(ItemTag.class, context)) { | ||
| items.add(item.getItemStack()); | ||
| } | ||
| evt.event.setDispensedLoot(items); | ||
| }); | ||
| } | ||
|
|
||
| public MaterialTag block; | ||
| public LocationTag location; | ||
| public BlockDispenseLootEvent event; | ||
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!path.tryArgObject(3, block)) { | ||
| return false; | ||
| } | ||
| if (!runInCheck(path, location)) { | ||
| return false; | ||
| } | ||
| return super.matches(path); | ||
| } | ||
|
|
||
| @Override | ||
| public ScriptEntryData getScriptEntryData() { | ||
| return new BukkitScriptEntryData(new PlayerTag(event.getPlayer()), null); | ||
| } | ||
|
|
||
| @Override | ||
| public ObjectTag getContext(String name) { | ||
| return switch (name) { | ||
| case "loot" -> new ListTag(event.getDispensedLoot(), ItemTag::new); | ||
| case "location" -> location; | ||
| default -> super.getContext(name); | ||
| }; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void onBlockLootDispense(BlockDispenseLootEvent event) { | ||
| block = new MaterialTag(event.getBlock().getType()); | ||
| location = new LocationTag(event.getBlock().getLocation()); | ||
| this.event = event; | ||
| fire(event); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.denizenscript.denizen.events.block; | ||
|
|
||
| import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
| import com.denizenscript.denizen.objects.ItemTag; | ||
| import com.denizenscript.denizen.objects.LocationTag; | ||
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.VaultDisplayItemEvent; | ||
|
|
||
| public class VaultDisplayItemScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
|
||
| // <--[event] | ||
| // @Events | ||
| // vault displays <item> | ||
| // | ||
| // @Group Block | ||
| // | ||
| // @Location true | ||
| // | ||
| // @Cancellable true | ||
| // | ||
| // @Triggers when a vault block displays an item. | ||
| // | ||
| // @Context | ||
| // <context.location> returns the LocationTag of the vault block. | ||
| // <context.item> returns the ItemTag being displayed. | ||
| // | ||
| // @Determine | ||
| // ItemTag to set the item being displayed. | ||
| // | ||
| // --> | ||
|
|
||
| public VaultDisplayItemScriptEvent() { | ||
| registerCouldMatcher("vault displays <item>"); | ||
| this.<VaultDisplayItemScriptEvent, ItemTag>registerDetermination(null, ItemTag.class, (evt, context, input) -> { | ||
| evt.event.setDisplayItem(input.getItemStack()); | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally prefixed determinations are preferred - easier to read/work with in code, and easier to manage for us when more get added. |
||
| } | ||
|
|
||
| public LocationTag location; | ||
| public VaultDisplayItemEvent event; | ||
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!runInCheck(path, location)) { | ||
| return false; | ||
| } | ||
| if (!path.tryArgObject(2, new ItemTag(event.getDisplayItem()))) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be put in a field for |
||
| return false; | ||
| } | ||
| return super.matches(path); | ||
| } | ||
|
|
||
| @Override | ||
| public ObjectTag getContext(String name) { | ||
| return switch (name) { | ||
| case "item" -> new ItemTag(event.getDisplayItem()); | ||
| case "location" -> location; | ||
| default -> super.getContext(name); | ||
| }; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void onVaultDisplayItemEvent(VaultDisplayItemEvent event) { | ||
| location = new LocationTag(event.getBlock().getLocation()); | ||
| this.event = event; | ||
| fire(event); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but the event is called
changesand this sayschange.