Skip to content

Commit 0241318

Browse files
authored
Merge pull request #23 from OneLiteFeatherNET/feature/annotationUsage
Improve annotation usage
2 parents 9424341 + 481537a commit 0241318

30 files changed

+189
-157
lines changed

src/main/java/net/onelitefeather/bettergopaint/BetterGoPaint.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@
4949

5050
public class BetterGoPaint extends JavaPlugin implements Listener {
5151

52-
public static final @NotNull String PAPER_DOCS = "https://jd.papermc.io/paper/1.20.6/org/bukkit/Material.html#enum-constant-summary";
52+
public static final String PAPER_DOCS = "https://jd.papermc.io/paper/1.20.6/org/bukkit/Material.html#enum-constant-summary";
53+
public static final String USE_PERMISSION = "bettergopaint.use";
54+
public static final String ADMIN_PERMISSION = "bettergopaint.admin";
55+
public static final String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
56+
public static final String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";
5357

54-
public static final @NotNull String USE_PERMISSION = "bettergopaint.use";
55-
public static final @NotNull String ADMIN_PERMISSION = "bettergopaint.admin";
56-
public static final @NotNull String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
57-
public static final @NotNull String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";
58-
59-
private final @NotNull PlayerBrushManager brushManager = new PlayerBrushManager();
60-
private final @NotNull Metrics metrics = new Metrics(this, 18734);
58+
private final PlayerBrushManager brushManager = new PlayerBrushManager();
59+
private final Metrics metrics = new Metrics(this, 18734);
6160

6261
@Override
6362
public void onLoad() {
@@ -82,7 +81,7 @@ public void onEnable() {
8281

8382
reloadConfig();
8483

85-
Material brush = Settings.settings().GENERIC.DEFAULT_BRUSH;
84+
Material brush = Settings.settings().generic.DEFAULT_BRUSH;
8685
if (!brush.isItem()) {
8786
getComponentLogger().error("{} is not a valid default brush, it has to be an item", brush.name());
8887
getComponentLogger().error("For more information visit {}", PAPER_DOCS);
@@ -141,8 +140,8 @@ private boolean hasOriginalGoPaint() {
141140
}
142141
return new AnnotationParser<>(commandManager, CommandSender.class);
143142

144-
} catch (Exception e) {
145-
getLogger().log(Level.SEVERE, "Cannot init command manager");
143+
} catch (Exception exception) {
144+
getLogger().log(Level.SEVERE, "Cannot init command manager", exception);
146145
return null;
147146
}
148147
}

src/main/java/net/onelitefeather/bettergopaint/brush/BrushSettings.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,31 @@ public interface BrushSettings {
4040
*
4141
* @return the axis used by the brush settings
4242
*/
43-
@NotNull
44-
Axis axis();
43+
@NotNull Axis axis();
4544

4645
/**
4746
* Returns the brush used by the brush settings.
4847
*
4948
* @return The brush used by the brush settings.
5049
*/
51-
@NotNull
52-
Brush brush();
50+
@NotNull Brush brush();
5351

5452
/**
5553
* Returns the list of blocks used by the brush settings.
5654
*
5755
* @return the list of blocks used by the brush settings
5856
*/
59-
@NotNull
60-
List<Material> blocks();
57+
@NotNull List<Material> blocks();
6158

6259
/**
6360
* Retrieves the mask material used by the brush settings.
6461
*
6562
* @return The mask material.
6663
* @deprecated the mask-material is going to be replaced with a WorldEdit Mask
6764
*/
68-
@NotNull
6965
@Deprecated(since = "1.1.0-SNAPSHOT")
7066
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
71-
Material mask();
67+
@NotNull Material mask();
7268

7369
/**
7470
* Checks if the brush is enabled.
@@ -89,7 +85,7 @@ public interface BrushSettings {
8985
*
9086
* @return The surface mode used by the brush settings.
9187
*/
92-
SurfaceMode surfaceMode();
88+
@NotNull SurfaceMode surfaceMode();
9389

9490
/**
9591
* Returns the angle-height difference used by the brush settings.
@@ -152,15 +148,13 @@ public interface BrushSettings {
152148
*
153149
* @return The randomly picked block material.
154150
*/
155-
@NotNull
156-
Material randomBlock();
151+
@NotNull Material randomBlock();
157152

158153
/**
159154
* The random number generator instance.
160155
*
161156
* @return a Random instance
162157
*/
163-
@NotNull
164-
Random random();
158+
@NotNull Random random();
165159

166160
}

src/main/java/net/onelitefeather/bettergopaint/brush/ExportedPlayerBrush.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public record ExportedPlayerBrush(
5151
double angleHeightDifference
5252
) implements BrushSettings {
5353

54-
private static final @NotNull Random RANDOM = new SecureRandom();
54+
private static final Random RANDOM = new SecureRandom();
5555

5656
public ExportedPlayerBrush(@NotNull Builder builder) {
5757
this(
@@ -91,19 +91,19 @@ public boolean maskEnabled() {
9191
return RANDOM;
9292
}
9393

94-
public static Builder builder(Brush brush) {
94+
public static Builder builder(@NotNull Brush brush) {
9595
return new Builder(brush);
9696
}
9797

9898
public static final class Builder {
9999

100-
private final @NotNull Brush brush;
100+
private final Brush brush;
101101

102-
private @NotNull List<Material> blocks = Collections.emptyList();
103-
private @NotNull Axis axis = Settings.settings().GENERIC.DEFAULT_AXIS;
104-
private @NotNull SurfaceMode surfaceMode = SurfaceMode.DISABLED;
102+
private List<Material> blocks = Collections.emptyList();
103+
private Axis axis = Settings.settings().generic.DEFAULT_AXIS;
104+
private SurfaceMode surfaceMode = SurfaceMode.DISABLED;
105105

106-
private @Nullable Material mask;
106+
private Material mask;
107107

108108
private int size;
109109
private int chance;

src/main/java/net/onelitefeather/bettergopaint/brush/PlayerBrush.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
*/
5555
public final class PlayerBrush implements BrushSettings {
5656

57-
private final @NotNull PlayerBrushManager brushManager;
58-
private final @NotNull Random random = new SecureRandom();
57+
private final PlayerBrushManager brushManager;
58+
private final Random random = new SecureRandom();
5959

6060
private boolean maskEnabled;
6161
private boolean enabled;
@@ -67,31 +67,31 @@ public final class PlayerBrush implements BrushSettings {
6767
private int falloffStrength;
6868
private int mixingStrength;
6969
private double angleHeightDifference;
70-
private @NotNull Axis axis;
71-
private @NotNull SurfaceMode surfaceMode;
70+
private Axis axis;
71+
private SurfaceMode surfaceMode;
7272

73-
private @NotNull Brush brush;
74-
private @NotNull Material mask;
75-
private final @NotNull List<Material> blocks = new ArrayList<>();
73+
private Brush brush;
74+
private Material mask;
75+
private final List<Material> blocks = new ArrayList<>();
7676

77-
private final @NotNull Inventory gui;
77+
private final Inventory gui;
7878

7979
public PlayerBrush(@NotNull PlayerBrushManager brushManager) {
8080
this.brushManager = brushManager;
8181

82-
surfaceMode = Settings.settings().GENERIC.SURFACE_MODE;
83-
maskEnabled = Settings.settings().GENERIC.MASK_ENABLED;
84-
enabled = Settings.settings().GENERIC.ENABLED_BY_DEFAULT;
85-
chance = Settings.settings().GENERIC.DEFAULT_CHANCE;
86-
thickness = Settings.settings().THICKNESS.DEFAULT_THICKNESS;
87-
fractureDistance = Settings.settings().FRACTURE.DEFAULT_FRACTURE_DISTANCE;
88-
angleDistance = Settings.settings().ANGLE.DEFAULT_ANGLE_DISTANCE;
89-
angleHeightDifference = Settings.settings().ANGLE.DEFAULT_ANGLE_HEIGHT_DIFFERENCE;
90-
falloffStrength = Settings.settings().GENERIC.DEFAULT_FALLOFF_STRENGTH;
91-
mixingStrength = Settings.settings().GENERIC.DEFAULT_MIXING_STRENGTH;
92-
axis = Settings.settings().GENERIC.DEFAULT_AXIS;
93-
size = Settings.settings().GENERIC.DEFAULT_SIZE;
94-
mask = Settings.settings().GENERIC.DEFAULT_MASK;
82+
surfaceMode = Settings.settings().generic.SURFACE_MODE;
83+
maskEnabled = Settings.settings().generic.MASK_ENABLED;
84+
enabled = Settings.settings().generic.ENABLED_BY_DEFAULT;
85+
chance = Settings.settings().generic.DEFAULT_CHANCE;
86+
thickness = Settings.settings().thickness.DEFAULT_THICKNESS;
87+
fractureDistance = Settings.settings().fracture.DEFAULT_FRACTURE_DISTANCE;
88+
angleDistance = Settings.settings().angle.DEFAULT_ANGLE_DISTANCE;
89+
angleHeightDifference = Settings.settings().angle.DEFAULT_ANGLE_HEIGHT_DIFFERENCE;
90+
falloffStrength = Settings.settings().generic.DEFAULT_FALLOFF_STRENGTH;
91+
mixingStrength = Settings.settings().generic.DEFAULT_MIXING_STRENGTH;
92+
axis = Settings.settings().generic.DEFAULT_AXIS;
93+
size = Settings.settings().generic.DEFAULT_SIZE;
94+
mask = Settings.settings().generic.DEFAULT_MASK;
9595
brush = brushManager.cycleForward(null);
9696
blocks.add(Material.STONE);
9797
gui = GUI.create(this);
@@ -170,7 +170,7 @@ public int chance() {
170170
}
171171

172172
@Override
173-
public SurfaceMode surfaceMode() {
173+
public @NotNull SurfaceMode surfaceMode() {
174174
return surfaceMode;
175175
}
176176

@@ -248,10 +248,10 @@ public void cycleBrushBackwards() {
248248
}
249249

250250
public void setSize(int size) {
251-
if (size <= Settings.settings().GENERIC.MAX_SIZE && size > 0) {
251+
if (size <= Settings.settings().generic.MAX_SIZE && size > 0) {
252252
this.size = size;
253-
} else if (size > Settings.settings().GENERIC.MAX_SIZE) {
254-
this.size = Settings.settings().GENERIC.MAX_SIZE;
253+
} else if (size > Settings.settings().generic.MAX_SIZE) {
254+
this.size = Settings.settings().generic.MAX_SIZE;
255255
} else {
256256
this.size = 1;
257257
}
@@ -264,13 +264,13 @@ public Inventory getInventory() {
264264

265265
public void increaseBrushSize(boolean x10) {
266266
if (x10) {
267-
if (size + 10 <= Settings.settings().GENERIC.MAX_SIZE) {
267+
if (size + 10 <= Settings.settings().generic.MAX_SIZE) {
268268
size += 10;
269269
} else {
270-
size = Settings.settings().GENERIC.MAX_SIZE;
270+
size = Settings.settings().generic.MAX_SIZE;
271271
}
272272
} else {
273-
if (size < Settings.settings().GENERIC.MAX_SIZE) {
273+
if (size < Settings.settings().generic.MAX_SIZE) {
274274
size += 1;
275275
}
276276
}
@@ -312,7 +312,7 @@ public void decreaseChance() {
312312
}
313313

314314
public void increaseThickness() {
315-
if (thickness < Settings.settings().THICKNESS.MAX_THICKNESS) {
315+
if (thickness < Settings.settings().thickness.MAX_THICKNESS) {
316316
thickness += 1;
317317
}
318318
updateInventory();
@@ -326,7 +326,7 @@ public void decreaseThickness() {
326326
}
327327

328328
public void increaseAngleDistance() {
329-
if (angleDistance < Settings.settings().ANGLE.MAX_ANGLE_DISTANCE) {
329+
if (angleDistance < Settings.settings().angle.MAX_ANGLE_DISTANCE) {
330330
angleDistance += 1;
331331
}
332332
updateInventory();
@@ -340,7 +340,7 @@ public void decreaseAngleDistance() {
340340
}
341341

342342
public void increaseFractureDistance() {
343-
if (this.fractureDistance < Settings.settings().FRACTURE.MAX_FRACTURE_DISTANCE) {
343+
if (this.fractureDistance < Settings.settings().fracture.MAX_FRACTURE_DISTANCE) {
344344
this.fractureDistance += 1;
345345
}
346346
updateInventory();
@@ -359,8 +359,8 @@ public void increaseAngleHeightDifference(boolean d15) {
359359
} else {
360360
angleHeightDifference += 5.0;
361361
}
362-
if (angleHeightDifference > Settings.settings().ANGLE.MAX_ANGLE_HEIGHT_DIFFERENCE) {
363-
angleHeightDifference = Settings.settings().ANGLE.MAX_ANGLE_HEIGHT_DIFFERENCE;
362+
if (angleHeightDifference > Settings.settings().angle.MAX_ANGLE_HEIGHT_DIFFERENCE) {
363+
angleHeightDifference = Settings.settings().angle.MAX_ANGLE_HEIGHT_DIFFERENCE;
364364
}
365365
updateInventory();
366366
}
@@ -371,8 +371,8 @@ public void decreaseAngleHeightDifference(boolean d15) {
371371
} else {
372372
angleHeightDifference -= 5.0;
373373
}
374-
if (angleHeightDifference < Settings.settings().ANGLE.MIN_ANGLE_HEIGHT_DIFFERENCE) {
375-
angleHeightDifference = Settings.settings().ANGLE.MIN_ANGLE_HEIGHT_DIFFERENCE;
374+
if (angleHeightDifference < Settings.settings().angle.MIN_ANGLE_HEIGHT_DIFFERENCE) {
375+
angleHeightDifference = Settings.settings().angle.MIN_ANGLE_HEIGHT_DIFFERENCE;
376376
}
377377
updateInventory();
378378
}

src/main/java/net/onelitefeather/bettergopaint/brush/PlayerBrushManager.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package net.onelitefeather.bettergopaint.brush;
2020

21-
import com.google.common.collect.ImmutableList;
2221
import net.onelitefeather.bettergopaint.objects.brush.AngleBrush;
2322
import net.onelitefeather.bettergopaint.objects.brush.Brush;
2423
import net.onelitefeather.bettergopaint.objects.brush.BucketBrush;
@@ -46,20 +45,25 @@
4645
*/
4746
public class PlayerBrushManager {
4847

49-
private final @NotNull HashMap<UUID, PlayerBrush> playerBrushes = new HashMap<>();
50-
private final @NotNull List<Brush> brushes = ImmutableList.of(
51-
new SphereBrush(),
52-
new SprayBrush(),
53-
new SplatterBrush(),
54-
new DiscBrush(),
55-
new BucketBrush(),
56-
new AngleBrush(),
57-
new OverlayBrush(),
58-
new UnderlayBrush(),
59-
new FractureBrush(),
60-
new GradientBrush(),
61-
new PaintBrush()
62-
);
48+
private final HashMap<UUID, PlayerBrush> playerBrushes;
49+
private final List<Brush> brushes;
50+
51+
public PlayerBrushManager() {
52+
this.playerBrushes = new HashMap<>();
53+
this.brushes = List.of(
54+
new SphereBrush(),
55+
new SprayBrush(),
56+
new SplatterBrush(),
57+
new DiscBrush(),
58+
new BucketBrush(),
59+
new AngleBrush(),
60+
new OverlayBrush(),
61+
new UnderlayBrush(),
62+
new FractureBrush(),
63+
new GradientBrush(),
64+
new PaintBrush()
65+
);
66+
}
6367

6468
/**
6569
* Retrieves the brush for the given player.
@@ -151,5 +155,4 @@ public void removeBrush(@NotNull Player player) {
151155
}
152156
return brushes.getLast();
153157
}
154-
155158
}

src/main/java/net/onelitefeather/bettergopaint/command/GoPaintCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public boolean execute(
4949
return false;
5050
}
5151
PlayerBrush pb = plugin.getBrushManager().getBrush(p);
52-
String prefix = Settings.settings().GENERIC.PREFIX;
52+
String prefix = Settings.settings().generic.PREFIX;
5353
if (!p.hasPermission(BetterGoPaint.USE_PERMISSION)) {
5454
p.sendRichMessage(prefix + "<red>You are lacking the permission bettergopaint.use");
5555
return true;

src/main/java/net/onelitefeather/bettergopaint/listeners/ConnectListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
import org.bukkit.event.EventPriority;
2424
import org.bukkit.event.Listener;
2525
import org.bukkit.event.player.PlayerQuitEvent;
26+
import org.jetbrains.annotations.NotNull;
2627

2728
public class ConnectListener implements Listener {
2829

2930
private final PlayerBrushManager brushManager;
3031

31-
public ConnectListener(PlayerBrushManager brushManager) {
32+
public ConnectListener(@NotNull PlayerBrushManager brushManager) {
3233
this.brushManager = brushManager;
3334
}
3435

3536
@EventHandler(priority = EventPriority.LOWEST)
36-
public void onQuit(PlayerQuitEvent event) {
37+
public void onQuit(@NotNull PlayerQuitEvent event) {
3738
brushManager.removeBrush(event.getPlayer());
3839
}
39-
4040
}

0 commit comments

Comments
 (0)