Skip to content

Commit c7f43a5

Browse files
Use JetBrains annotations
1 parent 456c517 commit c7f43a5

22 files changed

+94
-128
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ repositories {
2424
}
2525

2626
dependencies {
27+
// eclipse annotations are only present for IDE analysis, they should not be used
2728
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.2.600'
29+
implementation group: 'org.jetbrains', name: 'annotations', version: '24.1.0'
2830

2931
implementation group: 'org.spigotmc', name: 'spigot-api', version: '1.13.2-R0.1-SNAPSHOT'
30-
implementation (group: 'com.github.SkriptLang', name: 'Skript', version: '2.7.1') {
32+
implementation (group: 'com.github.SkriptLang', name: 'Skript', version: '2.7.3') {
3133
transitive = false
3234
}
3335
implementation (group: 'com.sk89q.worldguard', name: 'worldguard-bukkit', version: '7.0.0') {

src/main/java/org/skriptlang/skriptworldguard/RegionClasses.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
import ch.njol.skript.util.EnumUtils;
1010
import ch.njol.yggdrasil.Fields;
1111
import com.sk89q.worldguard.session.MoveType;
12+
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
1214
import org.skriptlang.skriptworldguard.worldguard.RegionUtils;
1315
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;
1416
import org.bukkit.Bukkit;
1517
import org.bukkit.World;
16-
import org.eclipse.jdt.annotation.Nullable;
1718

1819
import java.io.StreamCorruptedException;
1920
import java.util.regex.Matcher;
@@ -36,11 +37,10 @@ public RegionClasses() {
3637
"(?:the )?(?:worldguard )?region (?:with (?:the )?(?:name|id) |named )?\"(.+)\" (?:in|of) (?:(?:the )?world )?\"(.+)\""
3738
);
3839

39-
@Nullable
4040
@Override
41-
public WorldGuardRegion parse(String s, ParseContext context) {
41+
public @Nullable WorldGuardRegion parse(@NotNull String input, @NotNull ParseContext context) {
4242
if (context == ParseContext.EVENT || context == ParseContext.COMMAND) {
43-
Matcher matcher = regionPattern.matcher(s);
43+
Matcher matcher = regionPattern.matcher(input);
4444
if (matcher.matches()) {
4545
String id = matcher.group(1);
4646
World world = Bukkit.getWorld(matcher.group(2));
@@ -51,36 +51,36 @@ public WorldGuardRegion parse(String s, ParseContext context) {
5151
}
5252

5353
@Override
54-
public boolean canParse(ParseContext context) {
54+
public boolean canParse(@NotNull ParseContext context) {
5555
return true;
5656
}
5757

5858
@Override
59-
public String toString(WorldGuardRegion region, int flags) {
59+
public @NotNull String toString(WorldGuardRegion region, int flags) {
6060
return region.toString();
6161
}
6262

6363
@Override
64-
public String toVariableNameString(WorldGuardRegion region) {
64+
public @NotNull String toVariableNameString(WorldGuardRegion region) {
6565
return "worldguardregion:" + region;
6666
}
6767
})
6868
.serializer(new Serializer<WorldGuardRegion>() {
6969
@Override
70-
public Fields serialize(WorldGuardRegion region) {
70+
public @NotNull Fields serialize(WorldGuardRegion region) {
7171
Fields f = new Fields();
7272
f.putObject("world", region.getWorld());
7373
f.putObject("id", region.getRegion().getId());
7474
return f;
7575
}
7676

7777
@Override
78-
public void deserialize(WorldGuardRegion region, Fields fields) {
78+
public void deserialize(WorldGuardRegion region, @NotNull Fields fields) {
7979
assert false;
8080
}
8181

8282
@Override
83-
protected WorldGuardRegion deserialize(Fields fields) throws StreamCorruptedException {
83+
protected WorldGuardRegion deserialize(@NotNull Fields fields) throws StreamCorruptedException {
8484
World world = fields.getObject("world", World.class);
8585
String id = fields.getObject("id", String.class);
8686
if (world == null || id == null) {
@@ -118,22 +118,22 @@ protected boolean canBeInstantiated() {
118118
.parser(new Parser<MoveType>() {
119119
@Override
120120
@Nullable
121-
public MoveType parse(String s, ParseContext context) {
122-
return moveTypes.parse(s);
121+
public MoveType parse(@NotNull String input, @NotNull ParseContext context) {
122+
return moveTypes.parse(input);
123123
}
124124

125125
@Override
126-
public boolean canParse(ParseContext context) {
126+
public boolean canParse(@NotNull ParseContext context) {
127127
return true;
128128
}
129129

130130
@Override
131-
public String toString(MoveType moveType, int flags) {
131+
public @NotNull String toString(MoveType moveType, int flags) {
132132
return moveTypes.toString(moveType, flags);
133133
}
134134

135135
@Override
136-
public String toVariableNameString(MoveType moveType) {
136+
public @NotNull String toVariableNameString(MoveType moveType) {
137137
return "movetype:" + moveType.name();
138138
}
139139
})

src/main/java/org/skriptlang/skriptworldguard/SkriptWorldGuard.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
public class SkriptWorldGuard extends JavaPlugin {
1818

19-
@SuppressWarnings("NotNullFieldNotInitialized")
2019
private static SkriptWorldGuard instance;
2120

2221
@Override

src/main/java/org/skriptlang/skriptworldguard/elements/conditions/CondCanBuildInRegions.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@
1313
import ch.njol.skript.util.Direction;
1414
import ch.njol.util.Kleenean;
1515
import com.sk89q.worldedit.math.BlockVector3;
16+
import org.jetbrains.annotations.NotNull;
17+
import org.jetbrains.annotations.Nullable;
1618
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;
1719
import org.skriptlang.skriptworldguard.worldguard.RegionUtils;
1820
import org.bukkit.Location;
1921
import org.bukkit.entity.Player;
2022
import org.bukkit.event.Event;
21-
import org.eclipse.jdt.annotation.Nullable;
2223

2324
@Name("Can Build In Regions")
2425
@Description("A condition that tests whether the given players can build in the given regions or the regions of the given locations.")
2526
@Examples({
2627
"command /setblock <material>:",
27-
"\tdescription: set the block at your crosshair to a different type",
28-
"\ttrigger:",
29-
"\t\tif the player cannot build at the targeted block:",
30-
"\t\t\tmessage \"<red>You do not have permission to change blocks there!\"",
31-
"\t\telse:",
32-
"\t\t\tset the targeted block to argument"
28+
"\tdescription: set the block at your crosshair to a different type",
29+
"\ttrigger:",
30+
"\t\tif the player cannot build at the targeted block:",
31+
"\t\t\tmessage \"<red>You do not have permission to change blocks there!\"",
32+
"\t\telse:",
33+
"\t\t\tset the targeted block to argument"
3334
})
3435
@RequiredPlugins("WorldGuard 7")
3536
@Since("1.0")
@@ -42,16 +43,13 @@ public class CondCanBuildInRegions extends Condition {
4243
);
4344
}
4445

45-
@SuppressWarnings("NotNullFieldNotInitialized")
4646
private Expression<Player> players;
47-
@Nullable
4847
private Expression<Location> locations;
49-
@Nullable
5048
private Expression<WorldGuardRegion> regions;
5149

5250
@Override
5351
@SuppressWarnings("unchecked")
54-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
52+
public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, @NotNull ParseResult parseResult) {
5553
players = (Expression<Player>) exprs[0];
5654
if (exprs[1] != null) { // We are using directions and locations
5755
locations = Direction.combine(
@@ -66,7 +64,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
6664
}
6765

6866
@Override
69-
public boolean check(Event event) {
67+
public boolean check(@NotNull Event event) {
7068
if (locations != null) {
7169
Location[] locations = this.locations.getAll(event);
7270
return players.check(event, player -> SimpleExpression.check(
@@ -92,7 +90,7 @@ public boolean check(Event event) {
9290
}
9391

9492
@Override
95-
public String toString(@Nullable Event event, boolean debug) {
93+
public @NotNull String toString(@Nullable Event event, boolean debug) {
9694
assert (locations != null && regions == null) || (locations == null && regions != null);
9795
return players.toString(event, debug) + " can build " + ((locations != null ? locations : regions).toString(event, debug));
9896
}

src/main/java/org/skriptlang/skriptworldguard/elements/conditions/CondIsMemberOwner.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
import ch.njol.util.Kleenean;
1414
import com.sk89q.worldguard.LocalPlayer;
1515
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
16+
import org.jetbrains.annotations.NotNull;
17+
import org.jetbrains.annotations.Nullable;
1618
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;
1719
import org.bukkit.OfflinePlayer;
1820
import org.bukkit.event.Event;
19-
import org.eclipse.jdt.annotation.Nullable;
2021

2122
@Name("Is Member/Owner of Region")
2223
@Description("A condition that tests whether the given players or groups are a member or owner of the given regions.")
2324
@Examples({
2425
"on region enter:",
25-
"\tplayer is the owner of the region",
26-
"\tmessage \"Welcome back to %region%!\"",
27-
"\tsend \"%player% just entered %region%!\" to the members of the region"
26+
"\tplayer is the owner of the region",
27+
"\tmessage \"Welcome back to %region%!\"",
28+
"\tsend \"%player% just entered %region%!\" to the members of the region"
2829
})
2930
@RequiredPlugins("WorldGuard 7")
3031
@Since("1.0")
@@ -37,15 +38,13 @@ public class CondIsMemberOwner extends Condition {
3738
);
3839
}
3940

40-
@SuppressWarnings("NotNullFieldNotInitialized")
4141
private Expression<Object> users;
42-
@SuppressWarnings("NotNullFieldNotInitialized")
4342
private Expression<WorldGuardRegion> regions;
4443
private boolean owner;
4544

4645
@Override
4746
@SuppressWarnings("unchecked")
48-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
47+
public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, @NotNull ParseResult parseResult) {
4948
users = (Expression<Object>) exprs[0];
5049
regions = (Expression<WorldGuardRegion>) exprs[1];
5150
owner = parseResult.hasTag("owner");
@@ -54,7 +53,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
5453
}
5554

5655
@Override
57-
public boolean check(Event event) {
56+
public boolean check(@NotNull Event event) {
5857
WorldGuardRegion[] regions = this.regions.getAll(event);
5958
return users.check(event, user -> {
6059
if (user instanceof OfflinePlayer) {
@@ -78,7 +77,7 @@ public boolean check(Event event) {
7877
}
7978

8079
@Override
81-
public String toString(@Nullable Event event, boolean debug) {
80+
public @NotNull String toString(@Nullable Event event, boolean debug) {
8281
boolean isSingle = users.isSingle();
8382
return users.toString(event, debug) + " " + (isSingle ? "is" : "are")
8483
+ (isNegated() ? " not" : "")

src/main/java/org/skriptlang/skriptworldguard/elements/conditions/CondIsValidId.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import ch.njol.skript.doc.RequiredPlugins;
88
import ch.njol.skript.doc.Since;
99
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
10+
import org.jetbrains.annotations.NotNull;
1011

1112
@Name("Is Valid Region ID")
1213
@Description({
@@ -28,7 +29,7 @@ public boolean check(String id) {
2829
}
2930

3031
@Override
31-
protected String getPropertyName() {
32+
protected @NotNull String getPropertyName() {
3233
return "valid region id";
3334
}
3435

src/main/java/org/skriptlang/skriptworldguard/elements/conditions/CondRegionContains.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import ch.njol.skript.lang.util.SimpleExpression;
1313
import ch.njol.util.Kleenean;
1414
import com.sk89q.worldedit.bukkit.BukkitAdapter;
15+
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
1517
import org.skriptlang.skriptworldguard.worldguard.WorldGuardRegion;
1618
import org.bukkit.Location;
1719
import org.bukkit.event.Event;
18-
import org.eclipse.jdt.annotation.Nullable;
1920

2021
@Name("Region Contains")
2122
@Description("A condition that tests whether the given locations are inside of the given regions")
@@ -38,14 +39,12 @@ public class CondRegionContains extends Condition {
3839
);
3940
}
4041

41-
@SuppressWarnings("NotNullFieldNotInitialized")
4242
private Expression<WorldGuardRegion> regions;
43-
@SuppressWarnings("NotNullFieldNotInitialized")
4443
private Expression<Location> locations;
4544

4645
@Override
4746
@SuppressWarnings("unchecked")
48-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
47+
public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, @NotNull ParseResult parseResult) {
4948
boolean locationsFirst = matchedPattern % 2 != 0;
5049
regions = (Expression<WorldGuardRegion>) exprs[locationsFirst ? 1 : 0];
5150
locations = (Expression<Location>) exprs[locationsFirst ? 0 : 1];
@@ -54,7 +53,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
5453
}
5554

5655
@Override
57-
public boolean check(Event event) {
56+
public boolean check(@NotNull Event event) {
5857
Location[] locations = this.locations.getAll(event);
5958
return regions.check(event, region -> SimpleExpression.check(
6059
locations,
@@ -65,7 +64,7 @@ public boolean check(Event event) {
6564
}
6665

6766
@Override
68-
public String toString(@Nullable Event event, boolean debug) {
67+
public @NotNull String toString(@Nullable Event event, boolean debug) {
6968
return regions.toString(event, debug) + " contain" + (regions.isSingle() ? "s" : "") +
7069
" " + locations.toString(event, debug);
7170
}

src/main/java/org/skriptlang/skriptworldguard/elements/conditions/package-info.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/org/skriptlang/skriptworldguard/elements/effects/EffCreateRegion.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
1818
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
1919
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
20+
import org.jetbrains.annotations.NotNull;
21+
import org.jetbrains.annotations.Nullable;
2022
import org.skriptlang.skriptworldguard.worldguard.RegionUtils;
2123
import org.bukkit.Location;
2224
import org.bukkit.World;
2325
import org.bukkit.event.Event;
24-
import org.eclipse.jdt.annotation.Nullable;
2526

2627
import java.util.ArrayList;
2728
import java.util.List;
@@ -57,7 +58,6 @@ public class EffCreateRegion extends Effect {
5758

5859
// Shared Values
5960
private boolean temporary;
60-
@SuppressWarnings("NotNullFieldNotInitialized")
6161
private Expression<String> id;
6262
@Nullable
6363
private Expression<World> world;
@@ -76,7 +76,7 @@ public class EffCreateRegion extends Effect {
7676

7777
@Override
7878
@SuppressWarnings("unchecked")
79-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
79+
public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, @NotNull ParseResult parseResult) {
8080
temporary = parseResult.hasTag("temporary");
8181
id = (Expression<String>) exprs[0];
8282
world = (Expression<World>) exprs[1];
@@ -92,7 +92,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
9292
}
9393

9494
@Override
95-
protected void execute(Event event) {
95+
protected void execute(@NotNull Event event) {
9696
String id = this.id.getSingle(event);
9797
World world = this.world != null ? this.world.getSingle(event) : null; // May be null, but that is not necessarily a bad thing
9898
if (id == null || !ProtectedRegion.isValidId(id)) {
@@ -161,7 +161,7 @@ protected void execute(Event event) {
161161
}
162162

163163
@Override
164-
public String toString(@Nullable Event event, boolean debug) {
164+
public @NotNull String toString(@Nullable Event event, boolean debug) {
165165
if (firstCorner != null) { // Cuboid region
166166
assert secondCorner != null;
167167
return "create a new " + (temporary ? "temporary " : "") + "cuboid region named " + id.toString(event, debug)

src/main/java/org/skriptlang/skriptworldguard/elements/effects/package-info.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)