-
-
Notifications
You must be signed in to change notification settings - Fork 109
Vault & Trial Spawners additions #2771
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
Open
MrMaleficus
wants to merge
11
commits into
DenizenScript:dev
Choose a base branch
from
MrMaleficus:vault_trial_spawners
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
009dc8a
Create VaultChangeStateScriptEvent.java
MrMaleficus 5c9b24a
Update PaperModule.java
MrMaleficus 3253c6c
Update PropertyRegistry.java
MrMaleficus 566c5f3
Create MaterialVaultState.java
MrMaleficus 8909f23
Create MaterialOminous.java
MrMaleficus d70637d
Update ScriptEventRegistry.java
MrMaleficus 5d261e1
Create VaultDisplayItemScriptEvent.java
MrMaleficus 7c988c7
Update ScriptEventRegistry.java
MrMaleficus c70c255
Create EntityTrialSpawnerSpawnScriptEvent.java
MrMaleficus a61c69c
Merge remote-tracking branch 'upstream/dev' into vault_trial_spawners
MrMaleficus 9402db5
Merge remote-tracking branch 'upstream/dev' into vault_trial_spawners
MrMaleficus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
paper/src/main/java/com/denizenscript/denizen/paper/events/VaultChangeStateScriptEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.denizenscript.denizen.paper.events; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
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 | ||
// | ||
// @Context | ||
// <context.location> returns the LocationTag of the vault block. | ||
// <context.current_state> returns the ElementTag of the vault state on change. | ||
// <context.new_state> returns the ElementTag of the new vault state. | ||
// | ||
// @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 ObjectTag getContext(String name) { | ||
return switch (name) { | ||
case "current_state" -> new ElementTag(event.getCurrentState().toString().toLowerCase()); | ||
case "new_state" -> new ElementTag(event.getNewState().toString().toLowerCase()); | ||
case "location" -> location; | ||
default -> super.getContext(name); | ||
}; | ||
} | ||
|
||
@EventHandler | ||
public void onVaultChangeStateEvent(VaultChangeStateEvent event) { | ||
location = new LocationTag(event.getBlock().getLocation()); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
plugin/src/main/java/com/denizenscript/denizen/events/block/VaultDisplayItemScriptEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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 | ||
// "ITEM:<ItemTag>" to set the item being displayed. | ||
// | ||
// --> | ||
|
||
public VaultDisplayItemScriptEvent() { | ||
registerCouldMatcher("vault displays <item>"); | ||
this.<VaultDisplayItemScriptEvent, ItemTag>registerDetermination("item", ItemTag.class, (evt, context, item) -> { | ||
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" -> new ItemTag(event.getDisplayItem()); | ||
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); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...main/java/com/denizenscript/denizen/events/entity/EntityTrialSpawnerSpawnScriptEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.denizenscript.denizen.events.entity; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.TrialSpawnerSpawnEvent; | ||
|
||
public class EntityTrialSpawnerSpawnScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// trial_spawner spawns <entity> | ||
// | ||
// @Group Entity | ||
// | ||
// @Location true | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity spawns from a trial spawner. | ||
// | ||
// @Switch spawner:<location> to only process the event if the trial spawner's location matches. | ||
// | ||
// @Context | ||
// <context.entity> returns the EntityTag that spawned. | ||
// <context.location> returns the LocationTag the entity will spawn at. | ||
// <context.spawner_location> returns the LocationTag of the trial spawner. | ||
// | ||
// --> | ||
|
||
public EntityTrialSpawnerSpawnScriptEvent() { | ||
registerCouldMatcher("trial_spawner spawns <entity>"); | ||
registerSwitches("spawner"); | ||
} | ||
|
||
private EntityTag entity; | ||
private LocationTag location; | ||
private LocationTag trialSpawnerLocation; | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!path.tryArgObject(2, entity)) { | ||
return false; | ||
} | ||
if (!path.tryObjectSwitch("spawner", trialSpawnerLocation)) { | ||
return false; | ||
} | ||
if (!runInCheck(path, location)) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(entity); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
return switch (name) { | ||
case "entity" -> entity; | ||
case "location" -> location; | ||
case "spawner_location" -> trialSpawnerLocation; | ||
default -> super.getContext(name); | ||
}; | ||
} | ||
|
||
@EventHandler | ||
public void onTrialSpawnerSpawn(TrialSpawnerSpawnEvent event) { | ||
Entity entity = event.getEntity(); | ||
this.entity = new EntityTag(entity); | ||
location = new LocationTag(event.getLocation()); | ||
trialSpawnerLocation = new LocationTag(event.getTrialSpawner().getLocation()); | ||
EntityTag.rememberEntity(entity); | ||
fire(event); | ||
EntityTag.forgetEntity(entity); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
.../src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialOminous.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.denizenscript.denizen.objects.properties.material; | ||
|
||
import com.denizenscript.denizen.objects.MaterialTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
import org.bukkit.block.data.type.TrialSpawner; | ||
import org.bukkit.block.data.type.Vault; | ||
|
||
public class MaterialOminous implements Property { | ||
|
||
public static boolean describes(ObjectTag material) { | ||
return material instanceof MaterialTag | ||
&& ((MaterialTag) material).hasModernData() | ||
&& (((MaterialTag) material).getModernData() instanceof Vault | ||
|| ((MaterialTag) material).getModernData() instanceof TrialSpawner); | ||
} | ||
|
||
public static MaterialOminous getFrom(ObjectTag _material) { | ||
if (!describes(_material)) { | ||
return null; | ||
} else { | ||
return new MaterialOminous((MaterialTag) _material); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[]{ | ||
"ominous" | ||
}; | ||
|
||
public MaterialOminous(MaterialTag _material) { | ||
material = _material; | ||
} | ||
|
||
MaterialTag material; | ||
|
||
public static void register() { | ||
|
||
// <--[tag] | ||
// @attribute <MaterialTag.is_ominous> | ||
// @returns ElementTag(Boolean) | ||
// @mechanism MaterialTag.ominous | ||
// @group properties | ||
// @description | ||
// Returns whether the block is ominous or not. | ||
// Currently supports Vault and Trial Spawner blocks. | ||
// --> | ||
PropertyParser.registerStaticTag(MaterialOminous.class, ElementTag.class, "is_ominous", (attribute, material) -> { | ||
return new ElementTag(material.getOminous()); | ||
}); | ||
} | ||
|
||
public boolean getOminous() { | ||
if (material.getModernData() instanceof Vault) { | ||
return ((Vault) material.getModernData()).isOminous(); | ||
} else if (material.getModernData() instanceof TrialSpawner) { | ||
return ((TrialSpawner) material.getModernData()).isOminous(); | ||
} | ||
return false; | ||
} | ||
|
||
public void setOminous(boolean ominous) { | ||
if (material.getModernData() instanceof Vault vault) { | ||
vault.setOminous(ominous); | ||
} else if (material.getModernData() instanceof TrialSpawner spawner) { | ||
spawner.setOminous(ominous); | ||
} | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(getOminous()); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "ominous"; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object MaterialTag | ||
// @name ominous | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// Sets the ominousness of the block (trial spawner or vault). | ||
// @tags | ||
// <MaterialTag.is_ominous> | ||
// --> | ||
if (mechanism.matches("ominous") && mechanism.requireBoolean()) { | ||
setOminous(mechanism.getValue().asBoolean()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should use the new format, which extends MaterialProperty, example commit 0559148