-
-
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 3 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 state changes | ||
|
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. Needs to be |
||
| // | ||
| // @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 | ||
| // <ListTag(ItemTag)> to determine the new items that are outputted. | ||
| // | ||
| // --> | ||
|
|
||
| public BlockDispenseLootScriptEvent() { | ||
| registerCouldMatcher("loot dispenses from <block>"); | ||
| this.<BlockDispenseLootScriptEvent, ListTag>registerDetermination(null, ListTag.class, (evt, context, input) -> { | ||
|
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. Just in general, prefixed determinations (to match their |
||
| List<ItemStack> items = new ArrayList<>(); | ||
|
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. Nitpick, but can initialize to |
||
| 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,73 @@ | ||
| 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, item) -> { | ||
| this.item = item; | ||
| evt.event.setDisplayItem(item.getItemStack()); | ||
| }); | ||
| } | ||
|
|
||
| public LocationTag location; | ||
| public ItemTag item; | ||
| public VaultDisplayItemEvent event; | ||
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!runInCheck(path, location)) { | ||
| return false; | ||
| } | ||
| if (!path.tryArgObject(2, item)) { | ||
| return false; | ||
| } | ||
| return super.matches(path); | ||
| } | ||
|
|
||
| @Override | ||
| public ObjectTag getContext(String name) { | ||
| return switch (name) { | ||
| case "item" -> item; | ||
|
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 has the same issue with the context potentially becoming outdated due to another plugin accessing it (e.g. if you |
||
| case "location" -> location; | ||
| default -> super.getContext(name); | ||
| }; | ||
| } | ||
|
|
||
| @EventHandler | ||
| public void onVaultDisplayItemEvent(VaultDisplayItemEvent event) { | ||
| location = new LocationTag(event.getBlock().getLocation()); | ||
| item = new ItemTag(event.getDisplayItem()); | ||
| 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.