Skip to content

Commit

Permalink
Merge pull request #23 from OneLiteFeatherNET/feature/annotationUsage
Browse files Browse the repository at this point in the history
Improve annotation usage
  • Loading branch information
TheMeinerLP authored Jun 15, 2024
2 parents 9424341 + 481537a commit 0241318
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 157 deletions.
21 changes: 10 additions & 11 deletions src/main/java/net/onelitefeather/bettergopaint/BetterGoPaint.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@

public class BetterGoPaint extends JavaPlugin implements Listener {

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

public static final @NotNull String USE_PERMISSION = "bettergopaint.use";
public static final @NotNull String ADMIN_PERMISSION = "bettergopaint.admin";
public static final @NotNull String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
public static final @NotNull String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";

private final @NotNull PlayerBrushManager brushManager = new PlayerBrushManager();
private final @NotNull Metrics metrics = new Metrics(this, 18734);
private final PlayerBrushManager brushManager = new PlayerBrushManager();
private final Metrics metrics = new Metrics(this, 18734);

@Override
public void onLoad() {
Expand All @@ -82,7 +81,7 @@ public void onEnable() {

reloadConfig();

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

} catch (Exception e) {
getLogger().log(Level.SEVERE, "Cannot init command manager");
} catch (Exception exception) {
getLogger().log(Level.SEVERE, "Cannot init command manager", exception);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,31 @@ public interface BrushSettings {
*
* @return the axis used by the brush settings
*/
@NotNull
Axis axis();
@NotNull Axis axis();

/**
* Returns the brush used by the brush settings.
*
* @return The brush used by the brush settings.
*/
@NotNull
Brush brush();
@NotNull Brush brush();

/**
* Returns the list of blocks used by the brush settings.
*
* @return the list of blocks used by the brush settings
*/
@NotNull
List<Material> blocks();
@NotNull List<Material> blocks();

/**
* Retrieves the mask material used by the brush settings.
*
* @return The mask material.
* @deprecated the mask-material is going to be replaced with a WorldEdit Mask
*/
@NotNull
@Deprecated(since = "1.1.0-SNAPSHOT")
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
Material mask();
@NotNull Material mask();

/**
* Checks if the brush is enabled.
Expand All @@ -89,7 +85,7 @@ public interface BrushSettings {
*
* @return The surface mode used by the brush settings.
*/
SurfaceMode surfaceMode();
@NotNull SurfaceMode surfaceMode();

/**
* Returns the angle-height difference used by the brush settings.
Expand Down Expand Up @@ -152,15 +148,13 @@ public interface BrushSettings {
*
* @return The randomly picked block material.
*/
@NotNull
Material randomBlock();
@NotNull Material randomBlock();

/**
* The random number generator instance.
*
* @return a Random instance
*/
@NotNull
Random random();
@NotNull Random random();

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public record ExportedPlayerBrush(
double angleHeightDifference
) implements BrushSettings {

private static final @NotNull Random RANDOM = new SecureRandom();
private static final Random RANDOM = new SecureRandom();

public ExportedPlayerBrush(@NotNull Builder builder) {
this(
Expand Down Expand Up @@ -91,19 +91,19 @@ public boolean maskEnabled() {
return RANDOM;
}

public static Builder builder(Brush brush) {
public static Builder builder(@NotNull Brush brush) {
return new Builder(brush);
}

public static final class Builder {

private final @NotNull Brush brush;
private final Brush brush;

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

private @Nullable Material mask;
private Material mask;

private int size;
private int chance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
*/
public final class PlayerBrush implements BrushSettings {

private final @NotNull PlayerBrushManager brushManager;
private final @NotNull Random random = new SecureRandom();
private final PlayerBrushManager brushManager;
private final Random random = new SecureRandom();

private boolean maskEnabled;
private boolean enabled;
Expand All @@ -67,31 +67,31 @@ public final class PlayerBrush implements BrushSettings {
private int falloffStrength;
private int mixingStrength;
private double angleHeightDifference;
private @NotNull Axis axis;
private @NotNull SurfaceMode surfaceMode;
private Axis axis;
private SurfaceMode surfaceMode;

private @NotNull Brush brush;
private @NotNull Material mask;
private final @NotNull List<Material> blocks = new ArrayList<>();
private Brush brush;
private Material mask;
private final List<Material> blocks = new ArrayList<>();

private final @NotNull Inventory gui;
private final Inventory gui;

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

surfaceMode = Settings.settings().GENERIC.SURFACE_MODE;
maskEnabled = Settings.settings().GENERIC.MASK_ENABLED;
enabled = Settings.settings().GENERIC.ENABLED_BY_DEFAULT;
chance = Settings.settings().GENERIC.DEFAULT_CHANCE;
thickness = Settings.settings().THICKNESS.DEFAULT_THICKNESS;
fractureDistance = Settings.settings().FRACTURE.DEFAULT_FRACTURE_DISTANCE;
angleDistance = Settings.settings().ANGLE.DEFAULT_ANGLE_DISTANCE;
angleHeightDifference = Settings.settings().ANGLE.DEFAULT_ANGLE_HEIGHT_DIFFERENCE;
falloffStrength = Settings.settings().GENERIC.DEFAULT_FALLOFF_STRENGTH;
mixingStrength = Settings.settings().GENERIC.DEFAULT_MIXING_STRENGTH;
axis = Settings.settings().GENERIC.DEFAULT_AXIS;
size = Settings.settings().GENERIC.DEFAULT_SIZE;
mask = Settings.settings().GENERIC.DEFAULT_MASK;
surfaceMode = Settings.settings().generic.SURFACE_MODE;
maskEnabled = Settings.settings().generic.MASK_ENABLED;
enabled = Settings.settings().generic.ENABLED_BY_DEFAULT;
chance = Settings.settings().generic.DEFAULT_CHANCE;
thickness = Settings.settings().thickness.DEFAULT_THICKNESS;
fractureDistance = Settings.settings().fracture.DEFAULT_FRACTURE_DISTANCE;
angleDistance = Settings.settings().angle.DEFAULT_ANGLE_DISTANCE;
angleHeightDifference = Settings.settings().angle.DEFAULT_ANGLE_HEIGHT_DIFFERENCE;
falloffStrength = Settings.settings().generic.DEFAULT_FALLOFF_STRENGTH;
mixingStrength = Settings.settings().generic.DEFAULT_MIXING_STRENGTH;
axis = Settings.settings().generic.DEFAULT_AXIS;
size = Settings.settings().generic.DEFAULT_SIZE;
mask = Settings.settings().generic.DEFAULT_MASK;
brush = brushManager.cycleForward(null);
blocks.add(Material.STONE);
gui = GUI.create(this);
Expand Down Expand Up @@ -170,7 +170,7 @@ public int chance() {
}

@Override
public SurfaceMode surfaceMode() {
public @NotNull SurfaceMode surfaceMode() {
return surfaceMode;
}

Expand Down Expand Up @@ -248,10 +248,10 @@ public void cycleBrushBackwards() {
}

public void setSize(int size) {
if (size <= Settings.settings().GENERIC.MAX_SIZE && size > 0) {
if (size <= Settings.settings().generic.MAX_SIZE && size > 0) {
this.size = size;
} else if (size > Settings.settings().GENERIC.MAX_SIZE) {
this.size = Settings.settings().GENERIC.MAX_SIZE;
} else if (size > Settings.settings().generic.MAX_SIZE) {
this.size = Settings.settings().generic.MAX_SIZE;
} else {
this.size = 1;
}
Expand All @@ -264,13 +264,13 @@ public Inventory getInventory() {

public void increaseBrushSize(boolean x10) {
if (x10) {
if (size + 10 <= Settings.settings().GENERIC.MAX_SIZE) {
if (size + 10 <= Settings.settings().generic.MAX_SIZE) {
size += 10;
} else {
size = Settings.settings().GENERIC.MAX_SIZE;
size = Settings.settings().generic.MAX_SIZE;
}
} else {
if (size < Settings.settings().GENERIC.MAX_SIZE) {
if (size < Settings.settings().generic.MAX_SIZE) {
size += 1;
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ public void decreaseChance() {
}

public void increaseThickness() {
if (thickness < Settings.settings().THICKNESS.MAX_THICKNESS) {
if (thickness < Settings.settings().thickness.MAX_THICKNESS) {
thickness += 1;
}
updateInventory();
Expand All @@ -326,7 +326,7 @@ public void decreaseThickness() {
}

public void increaseAngleDistance() {
if (angleDistance < Settings.settings().ANGLE.MAX_ANGLE_DISTANCE) {
if (angleDistance < Settings.settings().angle.MAX_ANGLE_DISTANCE) {
angleDistance += 1;
}
updateInventory();
Expand All @@ -340,7 +340,7 @@ public void decreaseAngleDistance() {
}

public void increaseFractureDistance() {
if (this.fractureDistance < Settings.settings().FRACTURE.MAX_FRACTURE_DISTANCE) {
if (this.fractureDistance < Settings.settings().fracture.MAX_FRACTURE_DISTANCE) {
this.fractureDistance += 1;
}
updateInventory();
Expand All @@ -359,8 +359,8 @@ public void increaseAngleHeightDifference(boolean d15) {
} else {
angleHeightDifference += 5.0;
}
if (angleHeightDifference > Settings.settings().ANGLE.MAX_ANGLE_HEIGHT_DIFFERENCE) {
angleHeightDifference = Settings.settings().ANGLE.MAX_ANGLE_HEIGHT_DIFFERENCE;
if (angleHeightDifference > Settings.settings().angle.MAX_ANGLE_HEIGHT_DIFFERENCE) {
angleHeightDifference = Settings.settings().angle.MAX_ANGLE_HEIGHT_DIFFERENCE;
}
updateInventory();
}
Expand All @@ -371,8 +371,8 @@ public void decreaseAngleHeightDifference(boolean d15) {
} else {
angleHeightDifference -= 5.0;
}
if (angleHeightDifference < Settings.settings().ANGLE.MIN_ANGLE_HEIGHT_DIFFERENCE) {
angleHeightDifference = Settings.settings().ANGLE.MIN_ANGLE_HEIGHT_DIFFERENCE;
if (angleHeightDifference < Settings.settings().angle.MIN_ANGLE_HEIGHT_DIFFERENCE) {
angleHeightDifference = Settings.settings().angle.MIN_ANGLE_HEIGHT_DIFFERENCE;
}
updateInventory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package net.onelitefeather.bettergopaint.brush;

import com.google.common.collect.ImmutableList;
import net.onelitefeather.bettergopaint.objects.brush.AngleBrush;
import net.onelitefeather.bettergopaint.objects.brush.Brush;
import net.onelitefeather.bettergopaint.objects.brush.BucketBrush;
Expand Down Expand Up @@ -46,20 +45,25 @@
*/
public class PlayerBrushManager {

private final @NotNull HashMap<UUID, PlayerBrush> playerBrushes = new HashMap<>();
private final @NotNull List<Brush> brushes = ImmutableList.of(
new SphereBrush(),
new SprayBrush(),
new SplatterBrush(),
new DiscBrush(),
new BucketBrush(),
new AngleBrush(),
new OverlayBrush(),
new UnderlayBrush(),
new FractureBrush(),
new GradientBrush(),
new PaintBrush()
);
private final HashMap<UUID, PlayerBrush> playerBrushes;
private final List<Brush> brushes;

public PlayerBrushManager() {
this.playerBrushes = new HashMap<>();
this.brushes = List.of(
new SphereBrush(),
new SprayBrush(),
new SplatterBrush(),
new DiscBrush(),
new BucketBrush(),
new AngleBrush(),
new OverlayBrush(),
new UnderlayBrush(),
new FractureBrush(),
new GradientBrush(),
new PaintBrush()
);
}

/**
* Retrieves the brush for the given player.
Expand Down Expand Up @@ -151,5 +155,4 @@ public void removeBrush(@NotNull Player player) {
}
return brushes.getLast();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean execute(
return false;
}
PlayerBrush pb = plugin.getBrushManager().getBrush(p);
String prefix = Settings.settings().GENERIC.PREFIX;
String prefix = Settings.settings().generic.PREFIX;
if (!p.hasPermission(BetterGoPaint.USE_PERMISSION)) {
p.sendRichMessage(prefix + "<red>You are lacking the permission bettergopaint.use");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull;

public class ConnectListener implements Listener {

private final PlayerBrushManager brushManager;

public ConnectListener(PlayerBrushManager brushManager) {
public ConnectListener(@NotNull PlayerBrushManager brushManager) {
this.brushManager = brushManager;
}

@EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event) {
public void onQuit(@NotNull PlayerQuitEvent event) {
brushManager.removeBrush(event.getPlayer());
}

}
Loading

0 comments on commit 0241318

Please sign in to comment.