-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: main
Are you sure you want to change the base?
Conversation
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.
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%"); |
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 can use the worldguardregion classinfo here
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public String toString(Event arg0, boolean arg1) { | ||
return "WorldGuard region flag"; |
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.
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 :))
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
WorldGuard wg = WorldGuard.getInstance(); | ||
RegionContainer container = wg.getPlatform().getRegionContainer(); |
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.
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.
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.
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.
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
protected String[] get(Event e, WorldGuardRegion[] region) { |
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.
Use event
instead of e
everywhere
protected String[] get(Event e, WorldGuardRegion[] region) { | |
protected String[] get(Event event, WorldGuardRegion[] region) { | |
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
|
||
|
||
|
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.
import java.util.List; | ||
|
||
|
||
public class ExprRegionFlag extends PropertyExpression<WorldGuardRegion, String> { |
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.
Can we create a classinfo for WorldGuardFlag
? if so this expr should return WorldGuardFlag classinfo instead of String
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 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
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.
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?
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.
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
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.
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
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.
Gotcha, tysm guys!
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 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){ |
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.
- We don't use
final
modifier on method pararms anymore - Import
ChangeMode
directly (not static import)
public Class<?>[] acceptChange(final Changer.ChangeMode mode){ | |
public Class<?>[] acceptChange(ChangeMode mode) { |
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
Anything else that should be changed? |
I'll take a look this week and let you know :) |
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionFlag.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skriptworldguard/elements/expressions/ExprRegionPriority.java
Outdated
Show resolved
Hide resolved
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. |
The SkriptLang team loves contributions, so feel free to do so! |
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 |
I will PR a change to this after Flag and Priority is done.
public Class<? extends Flag> getReturnType() { | ||
return Flag.class; | ||
} |
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.
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) ; |
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.
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){ |
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 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) { |
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 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 )
case SET: | ||
case ADD: | ||
case REMOVE: | ||
return CollectionUtils.array(Number.class); | ||
case RESET: | ||
case DELETE: | ||
return CollectionUtils.array(); |
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.
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; |
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.
assert regions != null; |
shouldn't need to assert here
@Override | ||
protected String getPropertyName() { | ||
return "priority"; | ||
} |
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.
} | |
} | |
import org.bukkit.event.Event; | ||
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion; | ||
|
||
public class ExprRegionPriority extends SimplePropertyExpression<WorldGuardRegion, Number> { |
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.
needs documentation annotations
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ExprRegionFlag extends PropertyExpression<WorldGuardRegion, Object> { |
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.
needs documentation annotations
Related issue: #4