-
-
Notifications
You must be signed in to change notification settings - Fork 446
Initial work on inner PDC support #8629
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
ShaneBeee
wants to merge
7
commits into
SkriptLang:feature/nested-pdc
Choose a base branch
from
ShaneBeee:dev/inner_pdc
base: feature/nested-pdc
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.
+156
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f9e00d
Initial work on inner PDC support
ShaneBeee 8b389b2
cleanup
ShaneBeee cd4a778
PDCModule - change up user
ShaneBeee bfca335
PDCModule - change up user - part 2
ShaneBeee bffbd99
SecEditContainer - doc update a bit
ShaneBeee 8891347
SecEditContainer - more doc updates, suggested from eult
ShaneBeee 3102aec
SecEditContainer - undo eult's AI description
ShaneBeee 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
39 changes: 38 additions & 1 deletion
39
src/main/java/org/skriptlang/skript/bukkit/pdc/PDCModule.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
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
115 changes: 115 additions & 0 deletions
115
src/main/java/org/skriptlang/skript/bukkit/pdc/elements/SecEditContainer.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,115 @@ | ||
| package org.skriptlang.skript.bukkit.pdc.elements; | ||
|
|
||
| import ch.njol.skript.bukkitutil.NamespacedUtils; | ||
| import ch.njol.skript.config.SectionNode; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Examples; | ||
| import ch.njol.skript.doc.Keywords; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.Since; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.Section; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.Trigger; | ||
| import ch.njol.skript.lang.TriggerItem; | ||
| import ch.njol.skript.registrations.EventValues; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.NamespacedKey; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.persistence.PersistentDataContainer; | ||
| import org.bukkit.persistence.PersistentDataType; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.bukkit.pdc.PDCUtils; | ||
| import org.skriptlang.skript.registration.SyntaxInfo; | ||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
||
| @Name("Edit Sub Persistent Data Containers") | ||
| @Description("Needs a description!") | ||
| @Examples(""" | ||
| edit data container "my_stuff" of player's tool: | ||
| set data tag "health" of event-pdc to 1 | ||
| set data tag "name" of event-pdc to "Some Name" | ||
| """) | ||
| @Since("INSERT VERSION") | ||
| @Keywords({"pdc", "persistent data container", "custom data", "nbt"}) | ||
| public class SecEditContainer extends Section { | ||
|
|
||
| private static class EditContainerEvent extends Event { | ||
|
|
||
| private final PersistentDataContainer container; | ||
|
|
||
| public EditContainerEvent(PersistentDataContainer container) { | ||
| this.container = container; | ||
| } | ||
|
|
||
| public PersistentDataContainer getContainer() { | ||
| return container; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull HandlerList getHandlers() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | ||
|
|
||
| public static void register(SyntaxRegistry registry) { | ||
| registry.register(SyntaxRegistry.SECTION, SyntaxInfo.builder(Section.class) | ||
| .addPatterns("edit data container %string% of %chunks/worlds/entities/blocks/itemtypes/offlineplayers/persistentdatacontainers%") | ||
| .supplier(SecEditContainer::new) | ||
| .build()); | ||
|
|
||
| // I know you're not supposed to be here, but where SHOULD you go? | ||
| EventValues.registerEventValue(EditContainerEvent.class, PersistentDataContainer.class, EditContainerEvent::getContainer); | ||
| } | ||
|
|
||
| private Expression<String> key; | ||
| private Expression<?> targets; | ||
| private Trigger trigger; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, SectionNode sectionNode, List<TriggerItem> triggerItems) { | ||
| this.key = (Expression<String>) expressions[0]; | ||
| this.targets = expressions[1]; | ||
| this.trigger = loadCode(sectionNode, "edit data container section", EditContainerEvent.class); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected @Nullable TriggerItem walk(Event event) { | ||
| String tagName = this.key.getSingle(event); | ||
| if (tagName == null) | ||
| return super.walk(event, false); | ||
|
|
||
| NamespacedKey key = NamespacedUtils.checkValidationAndSend(tagName.toLowerCase(Locale.ENGLISH), this); | ||
| if (key == null) | ||
| return super.walk(event, false); | ||
|
|
||
| for (Object target : this.targets.getArray(event)) { | ||
| PDCUtils.editPersistentDataContainer(target, pdc -> { | ||
| // Get or create new container | ||
| PersistentDataContainer container = pdc.getOrDefault(key, PersistentDataType.TAG_CONTAINER, pdc.getAdapterContext().newPersistentDataContainer()); | ||
|
|
||
| // Walk and edit | ||
| EditContainerEvent editEvent = new EditContainerEvent(container); | ||
| Trigger.walk(this.trigger, editEvent); | ||
|
|
||
| // Pass back | ||
| pdc.set(key, PersistentDataType.TAG_CONTAINER, container); | ||
| }); | ||
| } | ||
| return super.walk(event, false); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return "edit data container " + this.key.toString(event, debug) + " of " + this.targets.toString(event, debug); | ||
| } | ||
|
|
||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
You could move this into the PDCModule, that way you can access the EventValueRegistry from the SkriptAddon
or just make a
registerEVfunction here and pass along the EVR, up to youAs long as it uses the new EventValue registration
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.
I'm going to leave it as is right now, because Sovde wants to rework it to not rely on event values.
Sovde: "i'm probably going to rework it so it doesn't rely on event-values at all"