Residence bridge update#397
Conversation
| // --> | ||
|
|
||
| public PlayerCreatesResidenceScriptEvent() { | ||
| registerCouldMatcher("residence player creates residence"); registerCouldMatcher("residence player create residence"); |
There was a problem hiding this comment.
This shouldn't both be on one line like this
| // <--[event] | ||
| // @Events | ||
| // residence player creates residence | ||
| // residence player create residence |
There was a problem hiding this comment.
remove this second variant
| // <--[event] | ||
| // @Events | ||
| // residence player enters <'residence'> | ||
| // residence player enter <'residence'> |
| // | ||
| // @Switch cause:<cause> to only process the event if the cause equals specified cause | ||
| // | ||
| // @Triggers when a player deletes a Residence. |
There was a problem hiding this comment.
This trigger text doesn't make sense to me when looking at the cause list below
| // residence gets deleted | ||
| // residence get deleted | ||
| // | ||
| // @Switch cause:<cause> to only process the event if the cause equals specified cause |
There was a problem hiding this comment.
matches not equals, need period at end
|
|
||
| @EventHandler | ||
| public void onResidenceRaidStartsScriptEvent(ResidenceRaidStartEvent event) { | ||
| if (event.getRes() == null) { |
There was a problem hiding this comment.
When/why would this occur?
| public ResidenceRaidStartEvent event; | ||
| public ResidenceTag residence; | ||
| public ListTag attackers; | ||
| public ListTag defenders; |
There was a problem hiding this comment.
these fields shouldn't be retained.
| @Override | ||
| public void init() { | ||
| ObjectFetcher.registerWithObjectFetcher(ResidenceTag.class); | ||
| ObjectFetcher.registerWithObjectFetcher(ResidenceTag.class, ResidenceTag.tagProcessor); |
There was a problem hiding this comment.
Should use generateTagBase here instead of adding one manually
| if (event.getResidence() == null) { | ||
| return; | ||
| } |
|
|
||
| // <--[event] | ||
| // @Events | ||
| // residence gets deleted |
| // @Events | ||
| // residence gets deleted | ||
| // | ||
| // @Switch cause:<cause> to only process the event if the cause matches specified cause. |
| // @Triggers when a Residence gets deleted. | ||
| // | ||
| // @Context | ||
| // <context.cause> Returns the cause of deletion. ( Available causes: PLAYER_DELETE, OTHER, LEASE_EXPIRE ) |
There was a problem hiding this comment.
Should match the format used by other events, something like ...deletion. Can be: X, Y, or Z
| } | ||
|
|
||
| public ResidenceDeleteEvent event; | ||
| public String cause; |
There was a problem hiding this comment.
This field is redundant, should use getCause().name() in matches, and the ElementTag enum constructor in getContext
| } | ||
|
|
||
| public ResidenceRaidEndEvent event; | ||
| public ClaimedResidence residence; |
There was a problem hiding this comment.
This field is redundant, can just use event.getRes() directly
| // @Triggers when a player(s) starts raiding a Residence. | ||
| // | ||
| // @Context | ||
| // <context.residence> Returns a ResidenceTag of residence that is being attacked. |
| switch (name) { | ||
| case "attackers": | ||
| ListTag attackers = new ListTag(); | ||
| for (RaidAttacker player : event.getAttackers().values()) { |
There was a problem hiding this comment.
This appears to be a map of attacker UUIDs to their RaidAttacker objects, if that's the case then can probably use the UUID PlayerTag constructor to save the extra method calls / have cleaner code
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!runGenericSwitchCheck(path, "residence", event.getRes().getName())) { |
There was a problem hiding this comment.
Should implement advancedMatches in ResidenceTag and use path.tryObjectSwitch here (and probably update other usages as well)
| // @Triggers when a player creates a Residence. | ||
| // | ||
| // @Context | ||
| // <context.residence> Returns the ResidenceTag of created residence. |
| case "residence": | ||
| return new ResidenceTag(event.getRes()); |
| default: | ||
| return super.getContext(name); |
There was a problem hiding this comment.
Should probably be outside the switch for consistency
| return tagProcessor.getObjectAttribute(this, attribute); | ||
| } | ||
|
|
||
| public static void registerTags() { |
There was a problem hiding this comment.
registerTags was replaced with register
| // Returns the owner of the residence. | ||
| // Returns a PlayerTag of owner in this Residence. |
There was a problem hiding this comment.
I think this was better as it was before? the return type is specified in the @returns meta
| // @returns ListTag | ||
| // @plugin Depenizen, Residence | ||
| // @description | ||
| // Returns a ListTag(ResidenceTag) of subzones in this Residence. |
There was a problem hiding this comment.
Same here, the returns should specify what object type does the list include (ListTag(ResidenceTag)), and the description doesn't need to mention the exact type, I.e. something like Returns a list of subzones in this Residence.
| tagProcessor.registerTag(ElementTag.class, "is_within", (attribute, object) -> { | ||
| if (attribute.hasParam()) { | ||
| LocationTag location = attribute.paramAsType(LocationTag.class); |
There was a problem hiding this comment.
Should use the registerTag method for tags with a param, see this for an example
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import com.denizenscript.denizencore.tags.Attribute; | ||
|
|
||
| public class ResidenceLocationProperties implements Property { |
There was a problem hiding this comment.
This (and ResidencePlayerProperties) are extension properties, properties used for the sole purpose of adding tags / mechs; the modern alternative to that is extension classes - here's an example, but feel free to ask on Discord if you need any help converting them
|
What's the status of this PR? |
| // @description | ||
| // Returns the ResidenceTag of given residence name. | ||
| // --> | ||
| TagManager.registerTagHandler(ResidenceTag.class, "residence", attribute -> { |
There was a problem hiding this comment.
This custom registered base tag conflicts with the generateBaseTag
| public ScriptEntryData getScriptEntryData() { | ||
| return new BukkitScriptEntryData(event.getPlayer()); | ||
| } | ||
| public ScriptEntryData getScriptEntryData() { return new BukkitScriptEntryData(event.getPlayer()); } |
| // @plugin Depenizen, Residence | ||
| // @description | ||
| // Returns whether the specified location is within this Residence. | ||
| // Returns boolean whether the specified location is within this Residence. |
| // @plugin Depenizen, Residence | ||
| // @description | ||
| // Returns if the location has a residence. | ||
| // Returns boolean whether the location has a Residence. |
There was a problem hiding this comment.
Also should not have the random boolean thrown in the middle
| @Override | ||
| public ObjectTag getObjectAttribute(Attribute attribute) { | ||
| public class ResidencePlayerProperties { | ||
| public static void register() { |
| // @plugin Depenizen, Residence | ||
| // @description | ||
| // Returns whether the player has a main Residence. | ||
| // Returns boolean whether the player has a main Residence. |
| @Override | ||
| public ObjectTag getContext(String name) { | ||
| switch (name) { | ||
| case "cause": return new ElementTag(event.getCause().name()); |
There was a problem hiding this comment.
Should use the ElementTag enum constructor
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!runGenericSwitchCheck(path, "residence", event.getRes().getName())) { |
There was a problem hiding this comment.
Should use tryObjectSwitch, and also update the switch meta accordingly
|
|
||
| public class ResidenceLocationProperties implements Property { | ||
| public class ResidenceLocationProperties { | ||
| public static void register() { |
There was a problem hiding this comment.
Should be ResidenceLocationExtensions, also newline above register
|
|
||
| @Override | ||
| public ObjectTag getObjectAttribute(Attribute attribute) { | ||
| public class ResidencePlayerProperties { |
There was a problem hiding this comment.
Should be ResidencePlayerExtensions
|
|
||
| @Override | ||
| public boolean matches(ScriptPath path) { | ||
| if (!path.tryObjectSwitch("residence", new ElementTag(event.getRes().getName()))) { |
There was a problem hiding this comment.
Why is this not using ResidenceTag?
| // @description | ||
| // Returns a residence object constructed from the input value. | ||
| // --> |
There was a problem hiding this comment.
Should have a Refer to <@link objecttype ResidenceTag>. to match the format used by other constructor tag meta
New events:
New tags:
Updated tags to the new registerTag format.
Updated Residence dependency to
5.1.0.0