Skip to content
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

Add expressions Region Flag and Region Priority #5

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

DereWah
Copy link

@DereWah DereWah commented Apr 30, 2023

Related issue: #4

@DereWah DereWah changed the title Add expression Region Flag Add expressions Region Flag and Region Priority Apr 30, 2023
@AyhamAl-Ali AyhamAl-Ali added the feature Pull request adding a new feature. label Apr 30, 2023
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

The structure here is good, just needs some cleanup. Files should also be using tabs instead of spaces.


static {

Skript.registerExpression(ExprRegionFlag.class, String.class, ExpressionType.COMBINED, "[the] flag %string% of region %string% in [world] %world%");
Copy link
Member

Choose a reason for hiding this comment

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

You can use the worldguardregion classinfo here


@Override
public String toString(Event arg0, boolean arg1) {
return "WorldGuard region flag";
Copy link
Member

Choose a reason for hiding this comment

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

the toString should represent the actual input of the user
ex: flag <flag> of <region> (take a look at some of the other syntax elements too :))

Comment on lines 48 to 49
WorldGuard wg = WorldGuard.getInstance();
RegionContainer container = wg.getPlatform().getRegionContainer();
Copy link
Member

Choose a reason for hiding this comment

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

Can these be put in static fields instead of getting them each time? Not sure the details on WG's API, so just a question.

Copy link
Member

@AyhamAl-Ali AyhamAl-Ali left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution ⚡

Most of the requested changes are regarding Code Conventions
Please take your time reading them and change the code according to them.

I haven't listed all the changes needed but there are various places where my requested changes apply to other than the ones I commented on so please change them as well.

I will be reviewing again after these changes.

}

@Override
protected String[] get(Event e, WorldGuardRegion[] region) {
Copy link
Member

Choose a reason for hiding this comment

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

Use event instead of e everywhere

Suggested change
protected String[] get(Event e, WorldGuardRegion[] region) {
protected String[] get(Event event, WorldGuardRegion[] region) {

Comment on lines 61 to 63



Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

import java.util.List;


public class ExprRegionFlag extends PropertyExpression<WorldGuardRegion, String> {
Copy link
Member

Choose a reason for hiding this comment

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

Can we create a classinfo for WorldGuardFlag? if so this expr should return WorldGuardFlag classinfo instead of String

Copy link
Author

Choose a reason for hiding this comment

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

I will prepare the class to work with a ClassInfo for the Flag type then. If I have time I will create the Flag type aswell

Copy link
Author

Choose a reason for hiding this comment

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

Would setting the return type to a WorldGuardFlag classinfo mean that it will also only accept WorldGuardFlag as changers?

If so, wouldn't this make it "harder" to manage flags?

set flag "greeting" of region %worldguardregion% to %worldguardflag% looks repetitive.

Also, while creating the classinfo, what's the difference between using the normal Flag.class from WorldGuard and creating a WorldGuardClass.class with getters to access its Flag class inside?

I saw that this 2nd way is used for the WorldGuardRegion class for example. Why this double step?

Copy link
Member

Choose a reason for hiding this comment

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

No, region flags accept various types of data (boolean/string/numbers/etc.) so you may need to either accept Object.class or accept all types mentioned here

You will then have to do the proper checking and casting for change method

As for creating a wrapper class for Flag, if that helps a lot I think it's fine, but if it's not really needed then we better stick with WG Flag class

Copy link
Member

Choose a reason for hiding this comment

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

Oh I think my comment here never posted...

the WorldGuardRegion wrapper exists because ProtectedRegion seemingly does not provide any details as to the world it is located in

Copy link
Author

Choose a reason for hiding this comment

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

Gotcha, tysm guys!

Copy link
Member

Choose a reason for hiding this comment

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

I am a little unsure about a flag classinfo, mainly for the fact that it may be rather large + I'm not sure how it might handle WorldGuard addons that add new flags (e.g. defining lang entries)



@Override
public Class<?>[] acceptChange(final Changer.ChangeMode mode){
Copy link
Member

Choose a reason for hiding this comment

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

  • We don't use final modifier on method pararms anymore
  • Import ChangeMode directly (not static import)
Suggested change
public Class<?>[] acceptChange(final Changer.ChangeMode mode){
public Class<?>[] acceptChange(ChangeMode mode) {

@DereWah DereWah requested a review from AyhamAl-Ali May 5, 2023 16:58
@DereWah
Copy link
Author

DereWah commented May 14, 2023

Anything else that should be changed?

@APickledWalrus
Copy link
Member

I'll take a look this week and let you know :)

@DereWah
Copy link
Author

DereWah commented May 16, 2023

Almost did all of the required changes (I still have to allow multiple regions in the Priority expression). Also, can I add to the PR the effect for deleting regions? I saw that there isn't one yet.

@NotSoDelayed
Copy link
Contributor

The SkriptLang team loves contributions, so feel free to do so!

@APickledWalrus
Copy link
Member

Almost did all of the required changes (I still have to allow multiple regions in the Priority expression). Also, can I add to the PR the effect for deleting regions? I saw that there isn't one yet.

I would do it in a separate PR if possible. Might be difficult since this PR is based on your main branch. Also, you can just add a changer to ExprRegionNamed

Comment on lines +115 to +117
public Class<? extends Flag> getReturnType() {
return Flag.class;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public Class<? extends Flag> getReturnType() {
return Flag.class;
}
public Class<Object> getReturnType() {
return Object.class;
}


@Override
public String toString(Event event, boolean debug) {
return "flag " + exprFlag.toString(event, debug) + " of region " + getExpr().toString(event, debug) ;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return "flag " + exprFlag.toString(event, debug) + " of region " + getExpr().toString(event, debug) ;
return "the worldguard flag " + exprFlag.toString(event, debug) + " of " + getExpr().toString(event, debug) ;

region is not part of the syntax and thus not necessary

}
}

public void change(Event event, Object[] delta, Changer.ChangeMode mode){
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to worry about warnings IMO. You can just silently fail.

@Override
protected Object[] get(Event event, WorldGuardRegion[] regions) {
String flag = exprFlag.getSingle(event);
if(flag != null) {
Copy link
Member

Choose a reason for hiding this comment

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

You should prefer to exit if the condition fails. Essentially, this helps prevent code from flying off into space with a bunch of indents. Example:

if (flag == null)
    return;
flag.whatever();

Also, your if statements should have a space between the f and opening parenthesis )

Comment on lines +24 to +30
case SET:
case ADD:
case REMOVE:
return CollectionUtils.array(Number.class);
case RESET:
case DELETE:
return CollectionUtils.array();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
case SET:
case ADD:
case REMOVE:
return CollectionUtils.array(Number.class);
case RESET:
case DELETE:
return CollectionUtils.array();
case SET:
case ADD:
case REMOVE:
case RESET:
case DELETE:
return CollectionUtils.array(Number.class);

you can just combine them :)


public void change(Event event, Object[] delta, ChangeMode mode) {
WorldGuardRegion[] regions = getExpr().getArray(event);
assert regions != null;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert regions != null;

shouldn't need to assert here

@Override
protected String getPropertyName() {
return "priority";
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

import org.bukkit.event.Event;
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;

public class ExprRegionPriority extends SimplePropertyExpression<WorldGuardRegion, Number> {
Copy link
Member

Choose a reason for hiding this comment

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

needs documentation annotations

import java.util.ArrayList;
import java.util.List;

public class ExprRegionFlag extends PropertyExpression<WorldGuardRegion, Object> {
Copy link
Member

Choose a reason for hiding this comment

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

needs documentation annotations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants