Skip to content

Residence bridge update#397

Merged
mcmonkey4eva merged 17 commits into
DenizenScript:masterfrom
davight:Residence-update
Jan 15, 2023
Merged

Residence bridge update#397
mcmonkey4eva merged 17 commits into
DenizenScript:masterfrom
davight:Residence-update

Conversation

@davight
Copy link
Copy Markdown
Contributor

@davight davight commented Nov 21, 2022

New events:

- residence player creates residence
- residence gets deleted (cause: <cause>)
- residence raid ends (residence: <name>)
- residence raid starts (residence: <name>)

New tags:

- ResidenceTag.area > Returns CuboidTag of this Residence.
- ResidenceTag.subzones > Returns ListTag(ResidenceTag) of subzones in this Residence.
- residence[<name>] > Returns the ResidenceTag from the given name.

Updated tags to the new registerTag format.
Updated Residence dependency to 5.1.0.0

// -->

public PlayerCreatesResidenceScriptEvent() {
registerCouldMatcher("residence player creates residence"); registerCouldMatcher("residence player create residence");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't both be on one line like this

// <--[event]
// @Events
// residence player creates residence
// residence player create residence
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this second variant

// <--[event]
// @Events
// residence player enters <'residence'>
// residence player enter <'residence'>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't

//
// @Switch cause:<cause> to only process the event if the cause equals specified cause
//
// @Triggers when a player deletes a Residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matches not equals, need period at end


@EventHandler
public void onResidenceRaidStartsScriptEvent(ResidenceRaidStartEvent event) {
if (event.getRes() == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When/why would this occur?

public ResidenceRaidStartEvent event;
public ResidenceTag residence;
public ListTag attackers;
public ListTag defenders;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these fields shouldn't be retained.

@Override
public void init() {
ObjectFetcher.registerWithObjectFetcher(ResidenceTag.class);
ObjectFetcher.registerWithObjectFetcher(ResidenceTag.class, ResidenceTag.tagProcessor);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use generateTagBase here instead of adding one manually

Comment on lines +52 to +54
if (event.getResidence() == null) {
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever happen?


// <--[event]
// @Events
// residence gets deleted
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just residence deleted?

// @Events
// residence gets deleted
//
// @Switch cause:<cause> to only process the event if the cause matches specified cause.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the cause of deletion matches

// @Triggers when a Residence gets deleted.
//
// @Context
// <context.cause> Returns the cause of deletion. ( Available causes: PLAYER_DELETE, OTHER, LEASE_EXPIRE )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should match the format used by other events, something like ...deletion. Can be: X, Y, or Z

}

public ResidenceDeleteEvent event;
public String cause;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is redundant, should use getCause().name() in matches, and the ElementTag enum constructor in getContext

}

public ResidenceRaidEndEvent event;
public ClaimedResidence residence;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of the

switch (name) {
case "attackers":
ListTag attackers = new ListTag();
for (RaidAttacker player : event.getAttackers().values()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should implement advancedMatches in ResidenceTag and use path.tryObjectSwitch here (and probably update other usages as well)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still unresolved

// @Triggers when a player creates a Residence.
//
// @Context
// <context.residence> Returns the ResidenceTag of created residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns the created ResidenceTag.

Comment on lines +66 to +67
case "residence":
return new ResidenceTag(event.getRes());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should inline this

Comment on lines +68 to +69
default:
return super.getContext(name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be outside the switch for consistency

return tagProcessor.getObjectAttribute(this, attribute);
}

public static void registerTags() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerTags was replaced with register

Comment on lines +131 to +138
// Returns the owner of the residence.
// Returns a PlayerTag of owner in this Residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was better as it was before? the return type is specified in the @returns meta

Comment on lines +146 to +149
// @returns ListTag
// @plugin Depenizen, Residence
// @description
// Returns a ListTag(ResidenceTag) of subzones in this Residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +178 to +180
tagProcessor.registerTag(ElementTag.class, "is_within", (attribute, object) -> {
if (attribute.hasParam()) {
LocationTag location = attribute.paramAsType(LocationTag.class);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mcmonkey4eva
Copy link
Copy Markdown
Member

What's the status of this PR?

// @description
// Returns the ResidenceTag of given residence name.
// -->
TagManager.registerTagHandler(ResidenceTag.class, "residence", attribute -> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... why did you do this?

// @plugin Depenizen, Residence
// @description
// Returns whether the specified location is within this Residence.
// Returns boolean whether the specified location is within this Residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes no sense

// @plugin Depenizen, Residence
// @description
// Returns if the location has a residence.
// Returns boolean whether the location has a Residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should not have the random boolean thrown in the middle

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
public class ResidencePlayerProperties {
public static void register() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline above this line

// @plugin Depenizen, Residence
// @description
// Returns whether the player has a main Residence.
// Returns boolean whether the player has a main Residence.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also no

@Override
public ObjectTag getContext(String name) {
switch (name) {
case "cause": return new ElementTag(event.getCause().name());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the ElementTag enum constructor


@Override
public boolean matches(ScriptPath path) {
if (!runGenericSwitchCheck(path, "residence", event.getRes().getName())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use tryObjectSwitch, and also update the switch meta accordingly


public class ResidenceLocationProperties implements Property {
public class ResidenceLocationProperties {
public static void register() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ResidenceLocationExtensions, also newline above register


@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
public class ResidencePlayerProperties {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ResidencePlayerExtensions


@Override
public boolean matches(ScriptPath path) {
if (!path.tryObjectSwitch("residence", new ElementTag(event.getRes().getName()))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not using ResidenceTag?

Comment on lines +19 to +21
// @description
// Returns a residence object constructed from the input value.
// -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a Refer to <@link objecttype ResidenceTag>. to match the format used by other constructor tag meta

@mcmonkey4eva mcmonkey4eva merged commit d5ea97c into DenizenScript:master Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants