From 98cfa1138fb18a0be4a7c14544bacc2087c71ea6 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:01:31 +0200 Subject: [PATCH 1/8] ignored multiple instances --- src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java b/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java index b2cd3f14..a8362b76 100644 --- a/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java +++ b/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java @@ -62,14 +62,6 @@ public class GoPaintPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { - // disable if goPaint and goPaintAdvanced are installed simultaneously - if (hasOriginalGoPaint()) { - getComponentLogger().error("goPaintAdvanced is a replacement for goPaint. Please use one instead of both"); - getComponentLogger().error("This plugin is now disabling to prevent future errors"); - Bukkit.getPluginManager().disablePlugin(this); - return; - } - registerListeners(); registerCommands(); } From 36c6498210cdf29ca3f2e94462b7b568f6a18a6e Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:02:57 +0200 Subject: [PATCH 2/8] changed package/module structure --- .../gopaint/api/brush}/package-info.java | 2 +- .../api/brush/setting}/BrushSettings.java | 74 ++---- .../gopaint/api/math}/ConnectedBlocks.java | 3 +- .../thenextlvl/gopaint/api/math}/Height.java | 3 +- .../thenextlvl/gopaint/api/math}/Sphere.java | 3 +- .../thenextlvl/gopaint/api/math}/Surface.java | 5 +- .../gopaint/api/math}/curve/BezierSpline.java | 2 +- .../api/math}/curve/BezierSplineSegment.java | 2 +- .../gopaint/api/math/curve}/package-info.java | 2 +- .../gopaint/api/math}/package-info.java | 2 +- .../gopaint/api/model}/SurfaceMode.java | 22 +- .../{objects => }/brush/AngleBrush.java | 19 +- .../{objects => }/brush/BucketBrush.java | 15 +- ...ushManager.java => CraftBrushManager.java} | 68 ++---- .../{objects => }/brush/DiscBrush.java | 13 +- .../gopaint/brush/ExportedPlayerBrush.java | 218 ----------------- .../{objects => }/brush/FractureBrush.java | 17 +- .../{objects => }/brush/GradientBrush.java | 33 ++- .../{objects => }/brush/OverlayBrush.java | 15 +- .../{objects => }/brush/PaintBrush.java | 26 +- .../{objects => }/brush/SphereBrush.java | 13 +- .../{objects => }/brush/SplatterBrush.java | 23 +- .../{objects => }/brush/SprayBrush.java | 15 +- .../{objects => }/brush/UnderlayBrush.java | 34 +-- .../CraftPlayerBrushSettings.java} | 227 +++++++----------- .../ConnectListener.java | 10 +- .../InteractListener.java | 31 +-- .../InventoryListener.java | 39 ++- .../other => listener}/package-info.java | 2 +- .../other => model}/PluginConfig.java | 3 +- .../{utils => model}/package-info.java | 2 +- .../gopaint/objects/brush/Brush.java | 123 ---------- .../gopaint/{utils => util}/GUI.java | 63 ++--- .../gopaint/{utils => util}/Items.java | 2 +- .../thenextlvl/gopaint/util/package-info.java | 10 + 35 files changed, 316 insertions(+), 825 deletions(-) rename {src/main/java/net/thenextlvl/gopaint/listeners => api/src/main/java/net/thenextlvl/gopaint/api/brush}/package-info.java (88%) rename {src/main/java/net/thenextlvl/gopaint/brush => api/src/main/java/net/thenextlvl/gopaint/api/brush/setting}/BrushSettings.java (63%) rename {src/main/java/net/thenextlvl/gopaint/utils => api/src/main/java/net/thenextlvl/gopaint/api/math}/ConnectedBlocks.java (98%) rename {src/main/java/net/thenextlvl/gopaint/utils => api/src/main/java/net/thenextlvl/gopaint/api/math}/Height.java (99%) rename {src/main/java/net/thenextlvl/gopaint/utils => api/src/main/java/net/thenextlvl/gopaint/api/math}/Sphere.java (99%) rename {src/main/java/net/thenextlvl/gopaint/utils => api/src/main/java/net/thenextlvl/gopaint/api/math}/Surface.java (97%) rename {src/main/java/net/thenextlvl/gopaint/utils => api/src/main/java/net/thenextlvl/gopaint/api/math}/curve/BezierSpline.java (99%) rename {src/main/java/net/thenextlvl/gopaint/utils => api/src/main/java/net/thenextlvl/gopaint/api/math}/curve/BezierSplineSegment.java (98%) rename {src/main/java/net/thenextlvl/gopaint/objects/brush => api/src/main/java/net/thenextlvl/gopaint/api/math/curve}/package-info.java (87%) rename {src/main/java/net/thenextlvl/gopaint/utils/curve => api/src/main/java/net/thenextlvl/gopaint/api/math}/package-info.java (87%) rename {src/main/java/net/thenextlvl/gopaint/objects/other => api/src/main/java/net/thenextlvl/gopaint/api/model}/SurfaceMode.java (52%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/AngleBrush.java (82%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/BucketBrush.java (84%) rename src/main/java/net/thenextlvl/gopaint/brush/{PlayerBrushManager.java => CraftBrushManager.java} (60%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/DiscBrush.java (86%) delete mode 100644 src/main/java/net/thenextlvl/gopaint/brush/ExportedPlayerBrush.java rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/FractureBrush.java (85%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/GradientBrush.java (64%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/OverlayBrush.java (87%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/PaintBrush.java (85%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/SphereBrush.java (86%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/SplatterBrush.java (72%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/SprayBrush.java (82%) rename src/main/java/net/thenextlvl/gopaint/{objects => }/brush/UnderlayBrush.java (54%) rename src/main/java/net/thenextlvl/gopaint/brush/{PlayerBrush.java => setting/CraftPlayerBrushSettings.java} (53%) rename src/main/java/net/thenextlvl/gopaint/{listeners => listener}/ConnectListener.java (82%) rename src/main/java/net/thenextlvl/gopaint/{listeners => listener}/InteractListener.java (77%) rename src/main/java/net/thenextlvl/gopaint/{listeners => listener}/InventoryListener.java (89%) rename src/main/java/net/thenextlvl/gopaint/{objects/other => listener}/package-info.java (87%) rename src/main/java/net/thenextlvl/gopaint/{objects/other => model}/PluginConfig.java (95%) rename src/main/java/net/thenextlvl/gopaint/{utils => model}/package-info.java (89%) delete mode 100644 src/main/java/net/thenextlvl/gopaint/objects/brush/Brush.java rename src/main/java/net/thenextlvl/gopaint/{utils => util}/GUI.java (82%) rename src/main/java/net/thenextlvl/gopaint/{utils => util}/Items.java (98%) create mode 100644 src/main/java/net/thenextlvl/gopaint/util/package-info.java diff --git a/src/main/java/net/thenextlvl/gopaint/listeners/package-info.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/package-info.java similarity index 88% rename from src/main/java/net/thenextlvl/gopaint/listeners/package-info.java rename to api/src/main/java/net/thenextlvl/gopaint/api/brush/package-info.java index d540a4a1..9d043120 100644 --- a/src/main/java/net/thenextlvl/gopaint/listeners/package-info.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/package-info.java @@ -2,7 +2,7 @@ @FieldsAreNotNullByDefault @MethodsReturnNotNullByDefault @ParametersAreNotNullByDefault -package net.thenextlvl.gopaint.listeners; +package net.thenextlvl.gopaint.api.brush; import core.annotation.FieldsAreNotNullByDefault; import core.annotation.MethodsReturnNotNullByDefault; diff --git a/src/main/java/net/thenextlvl/gopaint/brush/BrushSettings.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java similarity index 63% rename from src/main/java/net/thenextlvl/gopaint/brush/BrushSettings.java rename to api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java index 69da3d7e..cbab521b 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/BrushSettings.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/BrushSettings.java @@ -1,29 +1,10 @@ -/* - * goPaint is designed to simplify painting inside of Minecraft. - * Copyright (C) Arcaniax-Development - * Copyright (C) Arcaniax team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.thenextlvl.gopaint.brush; +package net.thenextlvl.gopaint.api.brush.setting; -import net.thenextlvl.gopaint.objects.brush.Brush; -import net.thenextlvl.gopaint.objects.other.SurfaceMode; +import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bukkit.Axis; import org.bukkit.Material; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Random; @@ -34,30 +15,26 @@ * difference, angle distance, chance, falloff strength, fracture distance, mixing strength, size and thickness. */ public interface BrushSettings { - /** * Returns the axis used by the brush settings. * * @return the axis used by the brush settings */ - @NotNull - Axis axis(); + Axis getAxis(); /** * Returns the brush used by the brush settings. * * @return The brush used by the brush settings. */ - @NotNull - Brush brush(); + Brush getBrush(); /** * Returns the list of blocks used by the brush settings. * * @return the list of blocks used by the brush settings */ - @NotNull - List blocks(); + List getBlocks(); /** * Retrieves the mask material used by the brush settings. @@ -65,102 +42,91 @@ public interface BrushSettings { * @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(); - - /** - * Checks if the brush is enabled. - * - * @return true if the brush is enabled, false otherwise - */ - boolean enabled(); + Material getMask(); /** * Checks if the mask is enabled. * * @return true if the mask is enabled, false otherwise. */ - boolean maskEnabled(); + boolean isMaskEnabled(); /** * Returns the surface mode used by the brush settings. * * @return The surface mode used by the brush settings. */ - SurfaceMode surfaceMode(); + SurfaceMode getSurfaceMode(); /** * Returns the angle-height difference used by the brush settings. * * @return The angle-height difference used by the brush settings. */ - double angleHeightDifference(); + double getAngleHeightDifference(); /** * Returns the angle distance used by the brush settings. * * @return The angle distance used by the brush settings. */ - int angleDistance(); + int getAngleDistance(); /** * Returns the chance of the brush being applied to a block. * * @return The chance of the brush being applied to a block. */ - int chance(); + int getChance(); /** * Returns the falloff strength used by the brush settings. * * @return The falloff strength used by the brush settings. */ - int falloffStrength(); + int getFalloffStrength(); /** * Returns the fracture distance used by the brush settings. * * @return The fracture distance used by the brush settings. */ - int fractureDistance(); + int getFractureDistance(); /** * Returns the mixing strength used by the brush settings. * * @return The mixing strength used by the brush settings. */ - int mixingStrength(); + int getMixingStrength(); /** * Returns the size of the brush settings. * * @return The size of the brush settings. */ - int size(); + int getSize(); /** * Returns the thickness used by the brush settings. * * @return The thickness used by the brush settings. */ - int thickness(); + int getThickness(); /** - * Picks a random block material from {@link #blocks()}. + * Picks a random block material from {@link #getBlocks()}. * * @return The randomly picked block material. */ - @NotNull - Material randomBlock(); + Material getRandomBlock(); /** * The random number generator instance. * * @return a Random instance */ - @NotNull - Random random(); - + Random getRandom(); } diff --git a/src/main/java/net/thenextlvl/gopaint/utils/ConnectedBlocks.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/ConnectedBlocks.java similarity index 98% rename from src/main/java/net/thenextlvl/gopaint/utils/ConnectedBlocks.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/ConnectedBlocks.java index acd416c5..5ea4122c 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/ConnectedBlocks.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/ConnectedBlocks.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.api.math; import org.bukkit.Location; import org.bukkit.block.Block; @@ -72,5 +72,4 @@ public static Stream getConnectedBlocks(Location loc, List blocks) return connected.stream(); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/utils/Height.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/Height.java similarity index 99% rename from src/main/java/net/thenextlvl/gopaint/utils/Height.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/Height.java index b1ea1a22..c780015a 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/Height.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/Height.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.api.math; import org.bukkit.Location; import org.bukkit.block.Block; @@ -108,5 +108,4 @@ public static double getAverageHeightDiffAngle(Location location, int distance) double height = (maxHeightDiff2 + maxHeightDiff) / 2.0; return height / (distance * 2d); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/utils/Sphere.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/Sphere.java similarity index 99% rename from src/main/java/net/thenextlvl/gopaint/utils/Sphere.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/Sphere.java index 9d0f80f0..ac75f1fc 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/Sphere.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/Sphere.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.api.math; import org.bukkit.Axis; import org.bukkit.Location; @@ -94,5 +94,4 @@ public static Stream getBlocksInRadius(Location middlePoint, int radius, private static boolean passesDefaultChecks(Location location, Location middlePoint, int radius) { return location.distance(middlePoint) < radius / 2d; } - } diff --git a/src/main/java/net/thenextlvl/gopaint/utils/Surface.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/Surface.java similarity index 97% rename from src/main/java/net/thenextlvl/gopaint/utils/Surface.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/Surface.java index 14d17953..5a823328 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/Surface.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/Surface.java @@ -16,9 +16,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.api.math; -import net.thenextlvl.gopaint.objects.other.SurfaceMode; +import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -93,5 +93,4 @@ public static boolean isOnSurface(Block block, SurfaceMode surfaceMode, Location case DISABLED -> true; }; } - } diff --git a/src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSpline.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/curve/BezierSpline.java similarity index 99% rename from src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSpline.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/curve/BezierSpline.java index b74a4e3f..21e06ee1 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSpline.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/curve/BezierSpline.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils.curve; +package net.thenextlvl.gopaint.api.math.curve; import lombok.Getter; import org.bukkit.util.Vector; diff --git a/src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSplineSegment.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/curve/BezierSplineSegment.java similarity index 98% rename from src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSplineSegment.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/curve/BezierSplineSegment.java index 5aac056b..207c3d2e 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/curve/BezierSplineSegment.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/curve/BezierSplineSegment.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils.curve; +package net.thenextlvl.gopaint.api.math.curve; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/package-info.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/curve/package-info.java similarity index 87% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/package-info.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/curve/package-info.java index 11cc5935..616c0b22 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/package-info.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/curve/package-info.java @@ -2,7 +2,7 @@ @FieldsAreNotNullByDefault @MethodsReturnNotNullByDefault @ParametersAreNotNullByDefault -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.api.math.curve; import core.annotation.FieldsAreNotNullByDefault; import core.annotation.MethodsReturnNotNullByDefault; diff --git a/src/main/java/net/thenextlvl/gopaint/utils/curve/package-info.java b/api/src/main/java/net/thenextlvl/gopaint/api/math/package-info.java similarity index 87% rename from src/main/java/net/thenextlvl/gopaint/utils/curve/package-info.java rename to api/src/main/java/net/thenextlvl/gopaint/api/math/package-info.java index 655d4b0d..86b362f6 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/curve/package-info.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/math/package-info.java @@ -2,7 +2,7 @@ @FieldsAreNotNullByDefault @MethodsReturnNotNullByDefault @ParametersAreNotNullByDefault -package net.thenextlvl.gopaint.utils.curve; +package net.thenextlvl.gopaint.api.math; import core.annotation.FieldsAreNotNullByDefault; import core.annotation.MethodsReturnNotNullByDefault; diff --git a/src/main/java/net/thenextlvl/gopaint/objects/other/SurfaceMode.java b/api/src/main/java/net/thenextlvl/gopaint/api/model/SurfaceMode.java similarity index 52% rename from src/main/java/net/thenextlvl/gopaint/objects/other/SurfaceMode.java rename to api/src/main/java/net/thenextlvl/gopaint/api/model/SurfaceMode.java index 35d9b4fc..4388fb29 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/other/SurfaceMode.java +++ b/api/src/main/java/net/thenextlvl/gopaint/api/model/SurfaceMode.java @@ -1,26 +1,8 @@ -/* - * goPaint is designed to simplify painting inside of Minecraft. - * Copyright (C) Arcaniax-Development - * Copyright (C) Arcaniax team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.thenextlvl.gopaint.objects.other; +package net.thenextlvl.gopaint.api.model; import lombok.Getter; import lombok.RequiredArgsConstructor; -import net.thenextlvl.gopaint.utils.Surface; +import net.thenextlvl.gopaint.api.math.Surface; import org.bukkit.Location; import org.bukkit.block.Block; diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/AngleBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/AngleBrush.java similarity index 82% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/AngleBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/AngleBrush.java index df95260e..62a7920e 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/AngleBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/AngleBrush.java @@ -16,18 +16,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Height; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Height; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class AngleBrush extends Brush { +public class AngleBrush extends CraftBrush { private static final String DESCRIPTION = "Only works on cliffs"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNmRlNDQ4ZjBkYmU3NmJiOGE4MzJjOGYzYjJhMDNkMzViZDRlMjc4NWZhNWU4Mjk4YzI2MTU1MDNmNDdmZmEyIn19fQ=="; @@ -40,13 +40,12 @@ public AngleBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) .filter(block -> Height.getAverageHeightDiffAngle(block.getLocation(), 1) >= 0.1 - && Height.getAverageHeightDiffAngle(block.getLocation(), brushSettings.angleDistance()) - >= Math.tan(Math.toRadians(brushSettings.angleHeightDifference()))) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + && Height.getAverageHeightDiffAngle(block.getLocation(), brushSettings.getAngleDistance()) + >= Math.tan(Math.toRadians(brushSettings.getAngleHeightDifference()))) + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/BucketBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/BucketBrush.java similarity index 84% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/BucketBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/BucketBrush.java index 8c2398b8..0459dd28 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/BucketBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/BucketBrush.java @@ -16,11 +16,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.ConnectedBlocks; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.ConnectedBlocks; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -28,7 +28,7 @@ import java.util.List; import java.util.stream.Stream; -public class BucketBrush extends Brush { +public class BucketBrush extends CraftBrush { private static final String DESCRIPTION = "Paints connected blocks\n§8with the same block type"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTAxOGI0NTc0OTM5Nzg4YTJhZDU1NTJiOTEyZDY3ODEwNjk4ODhjNTEyMzRhNGExM2VhZGI3ZDRjOTc5YzkzIn19fQ=="; @@ -41,11 +41,10 @@ public BucketBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - List blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false).toList(); + List blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false).toList(); Stream connectedBlocks = ConnectedBlocks.getConnectedBlocks(location, blocks); connectedBlocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/PlayerBrushManager.java b/src/main/java/net/thenextlvl/gopaint/brush/CraftBrushManager.java similarity index 60% rename from src/main/java/net/thenextlvl/gopaint/brush/PlayerBrushManager.java rename to src/main/java/net/thenextlvl/gopaint/brush/CraftBrushManager.java index 91f4bef6..6cc207ec 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/PlayerBrushManager.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/CraftBrushManager.java @@ -21,25 +21,22 @@ import com.google.common.collect.ImmutableList; import lombok.Getter; import net.thenextlvl.gopaint.GoPaintPlugin; -import net.thenextlvl.gopaint.objects.brush.*; +import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.brush.BrushManager; +import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; +import net.thenextlvl.gopaint.brush.setting.CraftPlayerBrushSettings; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; -/** - * The PlayerBrushManager class manages the brush selection for each player. - */ -public class PlayerBrushManager { - private final HashMap playerBrushes = new HashMap<>(); +public class CraftBrushManager implements BrushManager { + private final Map playerBrushes = new HashMap<>(); private final @Getter List brushes; private final GoPaintPlugin plugin; - public PlayerBrushManager(GoPaintPlugin plugin) { + public CraftBrushManager(GoPaintPlugin plugin) { brushes = ImmutableList.of( new SphereBrush(), new SprayBrush(), @@ -56,23 +53,12 @@ public PlayerBrushManager(GoPaintPlugin plugin) { this.plugin = plugin; } - /** - * Retrieves the brush for the given player. - * - * @param player The player for which to retrieve the brush. - * @return The brush for the specified player. - */ - public PlayerBrush getBrush(Player player) { - return playerBrushes.computeIfAbsent(player.getUniqueId(), ignored -> new PlayerBrush(plugin)); + @Override + public PlayerBrushSettings getBrush(Player player) { + return playerBrushes.computeIfAbsent(player.getUniqueId(), ignored -> new CraftPlayerBrushSettings(plugin)); } - /** - * Retrieves the lore for a specific brush. Each brush name is preceded by a color code - * indicating whether it is the currently selected brush or not. - * - * @param brush The brush for which to retrieve the lore. - * @return The lore for the specified brush. - */ + @Override public String getBrushLore(Brush brush) { return brushes.stream().map(current -> { if (current.equals(brush)) { @@ -83,33 +69,19 @@ public String getBrushLore(Brush brush) { }).collect(Collectors.joining()); } - /** - * Retrieves the brush handler for the given name. - * - * @param name The name of the brush to look for. - * @return An optional containing the brush handler, or empty if not found. - */ + @Override public Optional getBrushHandler(String name) { return brushes.stream() .filter(brush -> name.contains(brush.getName())) .findAny(); } - /** - * Removes the player from the {@link #playerBrushes} map. - * - * @param player The player who should be removed. - */ + @Override public void removeBrush(Player player) { playerBrushes.remove(player.getUniqueId()); } - /** - * Retrieves the next brush in the list of available brushes. - * - * @param brush The current brush, if null returns the first brush in the list. - * @return The next brush in the list, or the first brush if the current brush is null. - */ + @Override public Brush cycleForward(@Nullable Brush brush) { if (brush == null) { return brushes.getFirst(); @@ -121,13 +93,8 @@ public Brush cycleForward(@Nullable Brush brush) { return brushes.getFirst(); } - /** - * Retrieves the previous brush in the list of available brushes. - * - * @param brush The current brush. - * @return The previous brush in the list, or the first brush if the current brush is null. - */ - public Brush cycleBack(@Nullable Brush brush) { + @Override + public Brush cycleBackward(@Nullable Brush brush) { if (brush == null) { return brushes.getFirst(); } @@ -137,5 +104,4 @@ public Brush cycleBack(@Nullable Brush brush) { } return brushes.getLast(); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/DiscBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/DiscBrush.java similarity index 86% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/DiscBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/DiscBrush.java index baa0c5ca..46e6a23d 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/DiscBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/DiscBrush.java @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class DiscBrush extends Brush { +public class DiscBrush extends CraftBrush { private static final String DESCRIPTION = "Paints blocks in the\n§8same selected axis\n§8from the block you clicked"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjFmMjgyNTBkMWU0MjBhNjUxMWIwMzk2NDg2OGZjYTJmNTYzN2UzYWJhNzlmNGExNjNmNGE4ZDYxM2JlIn19fQ=="; @@ -39,10 +39,9 @@ public DiscBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), brushSettings.axis(), false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), brushSettings.getAxis(), false); blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/ExportedPlayerBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/ExportedPlayerBrush.java deleted file mode 100644 index 6f2c8d68..00000000 --- a/src/main/java/net/thenextlvl/gopaint/brush/ExportedPlayerBrush.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * goPaint is designed to simplify painting inside of Minecraft. - * Copyright (C) Arcaniax-Development - * Copyright (C) Arcaniax team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.thenextlvl.gopaint.brush; - -import net.thenextlvl.gopaint.objects.brush.Brush; -import net.thenextlvl.gopaint.objects.other.SurfaceMode; -import org.bukkit.Axis; -import org.bukkit.Material; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.Nullable; - -import java.security.SecureRandom; -import java.util.*; - -public record ExportedPlayerBrush( - Brush brush, - @Nullable Material mask, - List blocks, - Axis axis, - SurfaceMode surfaceMode, - int size, - int chance, - int thickness, - int angleDistance, - int fractureDistance, - int falloffStrength, - int mixingStrength, - double angleHeightDifference -) implements BrushSettings { - - private static final Random RANDOM = new SecureRandom(); - - public ExportedPlayerBrush(Builder builder) { - this( - builder.brush, - builder.mask, - builder.blocks, - builder.axis, - builder.surfaceMode, - builder.size, - builder.chance, - builder.thickness, - builder.angleDistance, - builder.fractureDistance, - builder.falloffStrength, - builder.mixingStrength, - builder.angleHeightDifference - ); - } - - @Override - public boolean enabled() { - return true; - } - - @Override - public boolean maskEnabled() { - return mask() != null; - } - - @Override - public Material randomBlock() { - return blocks().get(random().nextInt(blocks().size())); - } - - @Override - public Random random() { - return RANDOM; - } - - public static Builder builder(Brush brush) { - return new Builder(brush); - } - - public static final class Builder { - - private final Brush brush; - - private List blocks = Collections.emptyList(); - private Axis axis = Axis.Y; // todo: plugin.config().GENERIC.DEFAULT_AXIS; - private SurfaceMode surfaceMode = SurfaceMode.DISABLED; - - private @Nullable Material mask; - - private int size; - private int chance; - private int thickness; - private int angleDistance; - private int fractureDistance; - private int falloffStrength; - private int mixingStrength; - private double angleHeightDifference; - - private Builder(Brush brush) { - this.brush = brush; - } - - public Builder surfaceMode(SurfaceMode surfaceMode) { - this.surfaceMode = surfaceMode; - return this; - } - - public Builder blocks(List blocks) { - this.blocks = blocks; - return this; - } - - public Builder mask(@Nullable Material mask) { - this.mask = mask; - return this; - } - - public Builder size(int size) { - this.size = size; - return this; - } - - public Builder chance(int chance) { - this.chance = chance; - return this; - } - - public Builder thickness(int thickness) { - this.thickness = thickness; - return this; - } - - public Builder angleDistance(int angleDistance) { - this.angleDistance = angleDistance; - return this; - } - - public Builder fractureDistance(int fractureDistance) { - this.fractureDistance = fractureDistance; - return this; - } - - public Builder falloffStrength(int falloffStrength) { - this.falloffStrength = falloffStrength; - return this; - } - - public Builder mixingStrength(int mixingStrength) { - this.mixingStrength = mixingStrength; - return this; - } - - public Builder angleHeightDifference(double angleHeightDifference) { - this.angleHeightDifference = angleHeightDifference; - return this; - } - - public Builder axis(Axis axis) { - this.axis = axis; - return this; - } - - public ExportedPlayerBrush build() { - return new ExportedPlayerBrush(this); - } - - } - - @Deprecated(forRemoval = true) - public static ExportedPlayerBrush parse(Brush brush, ItemMeta itemMeta) { - ExportedPlayerBrush.Builder builder = ExportedPlayerBrush.builder(brush); - Optional.ofNullable(itemMeta.getLore()).ifPresent(lore -> lore.stream() - .map(line -> line.replace("§8", "")) - .forEach(line -> { - if (line.startsWith("Size: ")) { - builder.size(Integer.parseInt(line.substring(6))); - } else if (line.startsWith("Chance: ")) { - builder.chance(Integer.parseInt(line.substring(8, line.length() - 1))); - } else if (line.startsWith("Thickness: ")) { - builder.thickness(Integer.parseInt(line.substring(11))); - } else if (line.startsWith("Axis: ")) { - builder.axis(Axis.valueOf(line.substring(6).toUpperCase())); - } else if (line.startsWith("FractureDistance: ")) { - builder.fractureDistance(Integer.parseInt(line.substring(18))); - } else if (line.startsWith("AngleDistance: ")) { - builder.angleDistance(Integer.parseInt(line.substring(15))); - } else if (line.startsWith("AngleHeightDifference: ")) { - builder.angleHeightDifference(Double.parseDouble(line.substring(23))); - } else if (line.startsWith("Mixing: ")) { - builder.mixingStrength(Integer.parseInt(line.substring(8))); - } else if (line.startsWith("Falloff: ")) { - builder.falloffStrength(Integer.parseInt(line.substring(9))); - } else if (line.startsWith("Blocks: ")) { - builder.blocks(Arrays.stream(line.substring(8).split(", ")) - .map(Material::matchMaterial) - .filter(Objects::nonNull) - .toList()); - } else if (line.startsWith("Mask: ")) { - builder.mask(Material.matchMaterial(line.substring(6))); - } else if (line.startsWith("Surface Mode: ")) { - SurfaceMode.byName(line.substring(14)).ifPresent(builder::surfaceMode); - } - })); - return builder.build(); - } - -} diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/FractureBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/FractureBrush.java similarity index 85% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/FractureBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/FractureBrush.java index 7a4522c7..4b901c4c 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/FractureBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/FractureBrush.java @@ -16,18 +16,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Height; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Height; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class FractureBrush extends Brush { +public class FractureBrush extends CraftBrush { private static final String DESCRIPTION = "Places blocks in cracks/fisures"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjNkZjczZWVlNjIyNGM1YzVkOTQ4ZDJhMzQ1ZGUyNWYyMDhjYmQ5YWY3MTA4Y2UxZTFiNjFhNTg2ZGU5OGIyIn19fQ=="; @@ -40,7 +40,7 @@ public FractureBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesMaskCheck(brushSettings, block)) .filter(block -> Height.getAverageHeightDiffFracture( block.getLocation(), @@ -50,10 +50,9 @@ public void paint(Location location, Player player, BrushSettings brushSettings) .filter(block -> Height.getAverageHeightDiffFracture( block.getLocation(), Height.getNearestNonEmptyBlock(block.getLocation()), - brushSettings.fractureDistance() + brushSettings.getFractureDistance() ) >= 0.1) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/GradientBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/GradientBrush.java similarity index 64% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/GradientBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/GradientBrush.java index fc0bab7b..21e2fc85 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/GradientBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/GradientBrush.java @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class GradientBrush extends Brush { +public class GradientBrush extends CraftBrush { private static final String DESCRIPTION = "Creates gradients"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjA2MmRhM2QzYjhmMWZkMzUzNDNjYzI3OWZiMGZlNWNmNGE1N2I1YWJjNDMxZmJiNzhhNzNiZjJhZjY3NGYifX19"; @@ -39,25 +39,24 @@ public GradientBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - double y = location.getBlockY() - (brushSettings.size() / 2d); - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + double y = location.getBlockY() - (brushSettings.getSize() / 2d); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)).filter(block -> { - double rate = (block.getLocation().distance(location) - (brushSettings.size() / 2d) - * ((100d - brushSettings.falloffStrength()) / 100d)) - / ((brushSettings.size() / 2d) - (brushSettings.size() / 2d) - * ((100d - brushSettings.falloffStrength()) / 100d)); + double rate = (block.getLocation().distance(location) - (brushSettings.getSize() / 2d) + * ((100d - brushSettings.getFalloffStrength()) / 100d)) + / ((brushSettings.getSize() / 2d) - (brushSettings.getSize() / 2d) + * ((100d - brushSettings.getFalloffStrength()) / 100d)); - return brushSettings.random().nextDouble() > rate; + return brushSettings.getRandom().nextDouble() > rate; }).forEach(block -> { - int random = (int) (((block.getLocation().getBlockY() - y) / brushSettings.size() - * brushSettings.blocks().size()) + (brushSettings.random().nextDouble() * 2 - 1) - * (brushSettings.mixingStrength() / 100d)); + int random = (int) (((block.getLocation().getBlockY() - y) / brushSettings.getSize() + * brushSettings.getBlocks().size()) + (brushSettings.getRandom().nextDouble() * 2 - 1) + * (brushSettings.getMixingStrength() / 100d)); - int index = Math.clamp(random, 0, brushSettings.blocks().size() - 1); + int index = Math.clamp(random, 0, brushSettings.getBlocks().size() - 1); - setBlock(session, block, brushSettings.blocks().get(index)); + setBlock(session, block, brushSettings.getBlocks().get(index)); }); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/OverlayBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/OverlayBrush.java similarity index 87% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/OverlayBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/OverlayBrush.java index 35022d87..dc09ddbe 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/OverlayBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/OverlayBrush.java @@ -16,10 +16,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -27,7 +27,7 @@ import java.util.stream.Stream; -public class OverlayBrush extends Brush { +public class OverlayBrush extends CraftBrush { private static final String DESCRIPTION = "Only paints blocks\n§8that have air above it"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGYzMWQ2Zjk2NTRmODc0ZWE5MDk3YWRlZWEwYzk2OTk2ZTc4ZTNmZDM3NTRmYmY5ZWJlOTYzYWRhZDliZTRjIn19fQ=="; @@ -40,10 +40,10 @@ public OverlayBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesMaskCheck(brushSettings, block)) - .filter(block -> isOverlay(block, brushSettings.thickness())) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .filter(block -> isOverlay(block, brushSettings.getThickness())) + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } @@ -55,5 +55,4 @@ private boolean isOverlay(Block block, int thickness) { } return false; } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/PaintBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/PaintBrush.java similarity index 85% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/PaintBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/PaintBrush.java index 1dc5c57c..035f518c 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/PaintBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/PaintBrush.java @@ -16,14 +16,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; import core.i18n.file.ComponentBundle; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Height; -import net.thenextlvl.gopaint.utils.Sphere; -import net.thenextlvl.gopaint.utils.curve.BezierSpline; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Height; +import net.thenextlvl.gopaint.api.math.Sphere; +import net.thenextlvl.gopaint.api.math.curve.BezierSpline; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ import java.util.*; -public class PaintBrush extends Brush { +public class PaintBrush extends CraftBrush { private static final String DESCRIPTION = "Paints strokes\n§8hold shift to end"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODBiM2E5ZGZhYmVmYmRkOTQ5YjIxN2JiZDRmYTlhNDg2YmQwYzNmMGNhYjBkMGI5ZGZhMjRjMzMyZGQzZTM0MiJ9fX0="; @@ -66,13 +66,13 @@ public void paint(Location target, Player player, BrushSettings brushSettings) { performEdit(player, session -> { var world = player.getWorld(); Location first = locations.getFirst(); - Sphere.getBlocksInRadius(first, brushSettings.size(), null, false) + Sphere.getBlocksInRadius(first, brushSettings.getSize(), null, false) .filter(block -> Height.getAverageHeightDiffAngle(block.getLocation(), 1) < 0.1 - || Height.getAverageHeightDiffAngle(block.getLocation(), brushSettings.angleDistance()) - < Math.tan(Math.toRadians(brushSettings.angleHeightDifference()))) + || Height.getAverageHeightDiffAngle(block.getLocation(), brushSettings.getAngleDistance()) + < Math.tan(Math.toRadians(brushSettings.getAngleHeightDifference()))) .filter(block -> { var rate = calculateRate(block, first, brushSettings); - return brushSettings.random().nextDouble() > rate; + return brushSettings.getRandom().nextDouble() > rate; }).forEach(block -> { var curve = new LinkedList(); curve.add(new Vector(block.getX(), block.getY(), block.getZ())); @@ -92,15 +92,15 @@ public void paint(Location target, Player player, BrushSettings brushSettings) { continue; } - setBlock(session, point, brushSettings.randomBlock()); + setBlock(session, point, brushSettings.getRandomBlock()); } }); }); } private double calculateRate(Block block, Location first, BrushSettings brushSettings) { - double sizeHalf = brushSettings.size() / 2.0; - double falloffStrengthFactor = (100.0 - brushSettings.falloffStrength()) / 100.0; + double sizeHalf = brushSettings.getSize() / 2.0; + double falloffStrengthFactor = (100.0 - brushSettings.getFalloffStrength()) / 100.0; double numerator = block.getLocation().distance(first) - sizeHalf * falloffStrengthFactor; double denominator = sizeHalf - sizeHalf * falloffStrengthFactor; diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/SphereBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/SphereBrush.java similarity index 86% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/SphereBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/SphereBrush.java index d2b72e41..3a068754 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/SphereBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/SphereBrush.java @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class SphereBrush extends Brush { +public class SphereBrush extends CraftBrush { private static final String DESCRIPTION = "Regular sphere brush"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmU5OGY0ODU2MDE0N2MwYTJkNGVkYzE3ZjZkOTg1ZThlYjVkOTRiZDcyZmM2MDc0NGE1YThmMmQ5MDVhMTgifX19"; @@ -39,10 +39,9 @@ public SphereBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/SplatterBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/SplatterBrush.java similarity index 72% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/SplatterBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/SplatterBrush.java index 9fb4cf41..d8a699bd 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/SplatterBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/SplatterBrush.java @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class SplatterBrush extends Brush { +public class SplatterBrush extends CraftBrush { private static final String DESCRIPTION = "More chance when closer\n§8to the clicked point\n§8and configurable chance"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzMzODI5MmUyZTY5ZjA5MDY5NGNlZjY3MmJiNzZmMWQ4Mzc1OGQxMjc0NGJiNmZmYzY4MzRmZGJjMWE5ODMifX19"; @@ -39,21 +39,20 @@ public SplatterBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) .forEach(block -> { - double rate = (block.getLocation().distance(location) - ((double) brushSettings.size() / 2.0) - * ((100.0 - (double) brushSettings.falloffStrength()) / 100.0)) - / (((double) brushSettings.size() / 2.0) - ((double) brushSettings.size() / 2.0) - * ((100.0 - (double) brushSettings.falloffStrength()) / 100.0)); + double rate = (block.getLocation().distance(location) - ((double) brushSettings.getSize() / 2.0) + * ((100.0 - (double) brushSettings.getFalloffStrength()) / 100.0)) + / (((double) brushSettings.getSize() / 2.0) - ((double) brushSettings.getSize() / 2.0) + * ((100.0 - (double) brushSettings.getFalloffStrength()) / 100.0)); - if (brushSettings.random().nextDouble() <= rate) { + if (brushSettings.getRandom().nextDouble() <= rate) { return; } - setBlock(session, block, brushSettings.randomBlock()); + setBlock(session, block, brushSettings.getRandomBlock()); }); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/SprayBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/SprayBrush.java similarity index 82% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/SprayBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/SprayBrush.java index 2ac63bec..7cd6aae6 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/SprayBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/SprayBrush.java @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.objects.brush; +package net.thenextlvl.gopaint.brush; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.stream.Stream; -public class SprayBrush extends Brush { +public class SprayBrush extends CraftBrush { private static final String DESCRIPTION = "Configurable random chance brush"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjg4MGY3NjVlYTgwZGVlMzcwODJkY2RmZDk4MTJlZTM2ZmRhODg0ODY5MmE4NDFiZWMxYmJkOWVkNTFiYTIyIn19fQ=="; @@ -39,11 +39,10 @@ public SprayBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesDefaultChecks(brushSettings, player, block)) - .filter(block -> brushSettings.random().nextInt(100) < brushSettings.chance()) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .filter(block -> brushSettings.getRandom().nextInt(100) < brushSettings.getChance()) + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } - } diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/UnderlayBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/UnderlayBrush.java similarity index 54% rename from src/main/java/net/thenextlvl/gopaint/objects/brush/UnderlayBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/UnderlayBrush.java index 1df216d3..10eb2f50 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/UnderlayBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/UnderlayBrush.java @@ -1,25 +1,7 @@ -/* - * goPaint is designed to simplify painting inside of Minecraft. - * Copyright (C) Arcaniax-Development - * Copyright (C) Arcaniax team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.thenextlvl.gopaint.objects.brush; - -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Sphere; +package net.thenextlvl.gopaint.brush; + +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Sphere; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -27,7 +9,7 @@ import java.util.stream.Stream; -public class UnderlayBrush extends Brush { +public class UnderlayBrush extends CraftBrush { private static final String DESCRIPTION = "Only paints blocks\n§8that have no air above it"; private static final String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzIzNDQ2OTkwZjU4YjY1M2FiNWYwZTdhZjNmZGM3NTYwOTEyNzVmNGMzYzJkZDQxYzdkODYyZGQzZjkyZTg0YSJ9fX0="; @@ -40,10 +22,10 @@ public UnderlayBrush() { @Override public void paint(Location location, Player player, BrushSettings brushSettings) { performEdit(player, session -> { - Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false); + Stream blocks = Sphere.getBlocksInRadius(location, brushSettings.getSize(), null, false); blocks.filter(block -> passesMaskCheck(brushSettings, block)) - .filter(block -> isUnderlay(block, brushSettings.thickness())) - .forEach(block -> setBlock(session, block, brushSettings.randomBlock())); + .filter(block -> isUnderlay(block, brushSettings.getThickness())) + .forEach(block -> setBlock(session, block, brushSettings.getRandomBlock())); }); } diff --git a/src/main/java/net/thenextlvl/gopaint/brush/PlayerBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java similarity index 53% rename from src/main/java/net/thenextlvl/gopaint/brush/PlayerBrush.java rename to src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java index 9aa3fc60..f7a41f01 100644 --- a/src/main/java/net/thenextlvl/gopaint/brush/PlayerBrush.java +++ b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java @@ -16,19 +16,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.brush; +package net.thenextlvl.gopaint.brush.setting; import lombok.Getter; import lombok.Setter; -import lombok.experimental.Accessors; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.TextDecoration; import net.thenextlvl.gopaint.GoPaintPlugin; -import net.thenextlvl.gopaint.objects.brush.*; -import net.thenextlvl.gopaint.objects.other.SurfaceMode; -import net.thenextlvl.gopaint.utils.GUI; +import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; +import net.thenextlvl.gopaint.api.model.SurfaceMode; +import net.thenextlvl.gopaint.brush.*; +import net.thenextlvl.gopaint.util.GUI; import org.bukkit.Axis; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -37,21 +38,16 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; -import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.stream.Collectors; -/** - * The PlayerBrush class represents the brush settings of a player. - */ @Getter -@Accessors(fluent = true) -public final class PlayerBrush implements BrushSettings { +public final class CraftPlayerBrushSettings implements PlayerBrushSettings { + private static final Random random = new Random(); private final GoPaintPlugin plugin; - private final Random random = new SecureRandom(); private boolean maskEnabled; private boolean enabled; @@ -70,9 +66,9 @@ public final class PlayerBrush implements BrushSettings { private Material mask; private final List blocks = new ArrayList<>(); - private final Inventory gui; + private final Inventory inventory; - public PlayerBrush(GoPaintPlugin plugin) { + public CraftPlayerBrushSettings(GoPaintPlugin plugin) { this.plugin = plugin; surfaceMode = plugin.config().generic().surfaceMode(); @@ -90,64 +86,61 @@ public PlayerBrush(GoPaintPlugin plugin) { mask = plugin.config().generic().defaultMask(); brush = plugin.brushManager().cycleForward(null); blocks.add(Material.STONE); - gui = GUI.create(this); + inventory = GUI.create(this); + } + + @Override + public Random getRandom() { + return random; } - public Material randomBlock() { - return blocks().get(random.nextInt(blocks().size())); + public Material getRandomBlock() { + return getBlocks().get(random.nextInt(getBlocks().size())); } public void updateInventory() { - GUI.update(gui, this); + GUI.update(inventory, this); } public void increaseFalloffStrength() { - if (falloffStrength <= 90) { - falloffStrength += 10; - } + if (falloffStrength > 90) return; + falloffStrength += 10; updateInventory(); } public void decreaseFalloffStrength() { - if (falloffStrength >= 10) { - falloffStrength -= 10; - } + if (falloffStrength < 10) return; + falloffStrength -= 10; updateInventory(); } public void increaseMixingStrength() { - if (mixingStrength <= 90) { - mixingStrength += 10; - } + if (mixingStrength > 90) return; + mixingStrength += 10; updateInventory(); } public void decreaseMixingStrength() { - if (mixingStrength >= 10) { - mixingStrength -= 10; - } + if (mixingStrength < 10) return; + mixingStrength -= 10; updateInventory(); } - public void setMask(Material bt) { - mask = bt; + public void setMask(Material type) { + mask = type; updateInventory(); } - public void addBlock(Material bt, int slot) { - if (blocks.size() >= slot) { - blocks.set(slot - 1, bt); - } else { - blocks.add(bt); - } + public void addBlock(Material type, int slot) { + if (blocks.size() < slot) blocks.add(type); + else blocks.set(slot - 1, type); updateInventory(); } public void removeBlock(int slot) { - if (blocks.size() >= slot) { - blocks.remove(slot - 1); - updateInventory(); - } + if (blocks.size() < slot) return; + blocks.remove(slot - 1); + updateInventory(); } public void cycleBrushForward() { @@ -155,53 +148,23 @@ public void cycleBrushForward() { updateInventory(); } - public void cycleBrushBackwards() { - brush = plugin.brushManager().cycleBack(brush); + public void cycleBrushBackward() { + brush = plugin.brushManager().cycleBackward(brush); updateInventory(); } public void setSize(int size) { - if (size <= plugin.config().generic().maxSize() && size > 0) { - this.size = size; - } else if (size > plugin.config().generic().maxSize()) { - this.size = plugin.config().generic().maxSize(); - } else { - this.size = 1; - } + this.size = Math.clamp(size, 1, plugin.config().generic().maxSize()); updateInventory(); } - public Inventory getInventory() { - return gui; - } - - public void increaseBrushSize(boolean x10) { - if (x10) { - if (size + 10 <= plugin.config().generic().maxSize()) { - size += 10; - } else { - size = plugin.config().generic().maxSize(); - } - } else { - if (size < plugin.config().generic().maxSize()) { - size += 1; - } - } + public void increaseBrushSize(int amount) { + size = Math.min(plugin.config().generic().maxSize(), size + amount); updateInventory(); } - public void decreaseBrushSize(boolean x10) { - if (x10) { - if (size - 10 >= 1) { - size -= 10; - } else { - size = 1; - } - } else { - if (size > 1) { - size -= 1; - } - } + public void decreaseBrushSize(int amount) { + size = Math.max(1, size - amount); updateInventory(); } @@ -212,82 +175,62 @@ public boolean toggle() { } public void increaseChance() { - if (chance < 90) { - chance += 10; - } + if (chance >= 90) return; + chance += 10; updateInventory(); } public void decreaseChance() { - if (chance > 10) { - chance -= 10; - } + if (chance <= 10) return; + chance -= 10; updateInventory(); } public void increaseThickness() { - if (thickness < plugin.config().thickness().maxThickness()) { - thickness += 1; - } + if (thickness >= plugin.config().thickness().maxThickness()) return; + thickness += 1; updateInventory(); } public void decreaseThickness() { - if (thickness > 1) { - thickness -= 1; - } + if (thickness <= 1) return; + thickness -= 1; updateInventory(); } public void increaseAngleDistance() { - if (angleDistance < plugin.config().angle().maxAngleDistance()) { - angleDistance += 1; - } + if (angleDistance >= plugin.config().angle().maxAngleDistance()) return; + angleDistance += 1; updateInventory(); } public void decreaseAngleDistance() { - if (angleDistance > 1) { - angleDistance -= 1; - } + if (angleDistance <= 1) return; + angleDistance -= 1; updateInventory(); } public void increaseFractureDistance() { - if (this.fractureDistance < plugin.config().fracture().maxFractureDistance()) { - this.fractureDistance += 1; - } + if (this.fractureDistance >= plugin.config().fracture().maxFractureDistance()) return; + this.fractureDistance += 1; updateInventory(); } public void decreaseFractureDistance() { - if (this.fractureDistance > 1) { - this.fractureDistance -= 1; - } + if (this.fractureDistance <= 1) return; + this.fractureDistance -= 1; updateInventory(); } - public void increaseAngleHeightDifference(boolean d15) { - if (d15) { - angleHeightDifference += 15.0; - } else { - angleHeightDifference += 5.0; - } - if (angleHeightDifference > plugin.config().angle().maxAngleHeightDifference()) { - angleHeightDifference = plugin.config().angle().maxAngleHeightDifference(); - } + public void increaseAngleHeightDifference(int amount) { + var max = plugin.config().angle().maxAngleHeightDifference(); + angleHeightDifference = Math.min(max, angleHeightDifference + amount); updateInventory(); } - public void decreaseAngleHeightDifference(boolean d15) { - if (d15) { - angleHeightDifference -= 15.0; - } else { - angleHeightDifference -= 5.0; - } - if (angleHeightDifference < plugin.config().angle().minAngleHeightDifference()) { - angleHeightDifference = plugin.config().angle().minAngleHeightDifference(); - } + public void decreaseAngleHeightDifference(int amount) { + var min = plugin.config().angle().minAngleHeightDifference(); + angleHeightDifference = Math.max(min, angleHeightDifference - amount); updateInventory(); } @@ -318,37 +261,37 @@ public void export(ItemStack itemStack) { List lore = new ArrayList<>(); lore.add(""); lore.add("Size: " + size); - if (brush() instanceof SprayBrush) { - lore.add("Chance: " + chance() + "%"); - } else if (brush() instanceof OverlayBrush || brush() instanceof UnderlayBrush) { - lore.add("Thickness: " + thickness()); - } else if (brush() instanceof DiscBrush) { - lore.add("Axis: " + axis().name()); - } else if (brush() instanceof AngleBrush) { - lore.add("AngleDistance: " + angleDistance()); - lore.add("AngleHeightDifference: " + angleHeightDifference()); - } else if (brush() instanceof SplatterBrush) { - lore.add("Falloff: " + falloffStrength()); - } else if (brush() instanceof GradientBrush) { - lore.add("Mixing: " + mixingStrength()); - lore.add("Falloff: " + falloffStrength()); - } else if (brush() instanceof FractureBrush) { - lore.add("FractureDistance: " + fractureDistance()); + if (getBrush() instanceof SprayBrush) { + lore.add("Chance: " + getChance() + "%"); + } else if (getBrush() instanceof OverlayBrush || getBrush() instanceof UnderlayBrush) { + lore.add("Thickness: " + getThickness()); + } else if (getBrush() instanceof DiscBrush) { + lore.add("Axis: " + getAxis().name()); + } else if (getBrush() instanceof AngleBrush) { + lore.add("AngleDistance: " + getAngleDistance()); + lore.add("AngleHeightDifference: " + getAngleHeightDifference()); + } else if (getBrush() instanceof SplatterBrush) { + lore.add("Falloff: " + getFalloffStrength()); + } else if (getBrush() instanceof GradientBrush) { + lore.add("Mixing: " + getMixingStrength()); + lore.add("Falloff: " + getFalloffStrength()); + } else if (getBrush() instanceof FractureBrush) { + lore.add("FractureDistance: " + getFractureDistance()); } - lore.add("Blocks: " + (blocks().isEmpty() ? "none" : blocks().stream() + lore.add("Blocks: " + (getBlocks().isEmpty() ? "none" : getBlocks().stream() .map(Material::getKey) .map(NamespacedKey::asMinimalString) .collect(Collectors.joining(", ")))); - if (maskEnabled()) { - lore.add("Mask: " + mask().getKey().asMinimalString()); + if (isMaskEnabled()) { + lore.add("Mask: " + getMask().getKey().asMinimalString()); } - if (!surfaceMode().equals(SurfaceMode.DISABLED)) { + if (!getSurfaceMode().equals(SurfaceMode.DISABLED)) { lore.add("Surface Mode: " + surfaceMode.getName()); } itemStack.editMeta(itemMeta -> { - itemMeta.displayName(Component.text(" ♦ " + brush().getName() + " ♦ ", NamedTextColor.AQUA) + itemMeta.displayName(Component.text(" ♦ " + getBrush().getName() + " ♦ ", NamedTextColor.AQUA) .style(Style.style(TextDecoration.ITALIC.withState(false)))); itemMeta.lore(lore.stream().map(string -> Component.text(string).style(Style .style(TextDecoration.ITALIC.withState(false)) diff --git a/src/main/java/net/thenextlvl/gopaint/listeners/ConnectListener.java b/src/main/java/net/thenextlvl/gopaint/listener/ConnectListener.java similarity index 82% rename from src/main/java/net/thenextlvl/gopaint/listeners/ConnectListener.java rename to src/main/java/net/thenextlvl/gopaint/listener/ConnectListener.java index 5254bf6a..c5ab0a37 100644 --- a/src/main/java/net/thenextlvl/gopaint/listeners/ConnectListener.java +++ b/src/main/java/net/thenextlvl/gopaint/listener/ConnectListener.java @@ -16,10 +16,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.listeners; +package net.thenextlvl.gopaint.listener; import lombok.RequiredArgsConstructor; -import net.thenextlvl.gopaint.brush.PlayerBrushManager; +import net.thenextlvl.gopaint.GoPaintPlugin; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -27,10 +27,10 @@ @RequiredArgsConstructor public class ConnectListener implements Listener { - private final PlayerBrushManager brushManager; + private final GoPaintPlugin plugin; @EventHandler(priority = EventPriority.LOWEST) - public void onQuit(PlayerQuitEvent event) { - brushManager.removeBrush(event.getPlayer()); + public void onPlayerQuit(PlayerQuitEvent event) { + plugin.brushManager().removeBrush(event.getPlayer()); } } diff --git a/src/main/java/net/thenextlvl/gopaint/listeners/InteractListener.java b/src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java similarity index 77% rename from src/main/java/net/thenextlvl/gopaint/listeners/InteractListener.java rename to src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java index 0a80ecd0..f42e4983 100644 --- a/src/main/java/net/thenextlvl/gopaint/listeners/InteractListener.java +++ b/src/main/java/net/thenextlvl/gopaint/listener/InteractListener.java @@ -16,16 +16,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.listeners; +package net.thenextlvl.gopaint.listener; import com.sk89q.worldedit.bukkit.BukkitAdapter; import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.TextComponent; import net.thenextlvl.gopaint.GoPaintPlugin; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.brush.ExportedPlayerBrush; -import net.thenextlvl.gopaint.brush.PlayerBrush; -import net.thenextlvl.gopaint.objects.brush.Brush; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; +import net.thenextlvl.gopaint.brush.setting.CraftItemBrushSettings; import org.bukkit.FluidCollisionMode; import org.bukkit.Location; import org.bukkit.block.Block; @@ -38,8 +37,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.Optional; - @RequiredArgsConstructor public final class InteractListener implements Listener { private final GoPaintPlugin plugin; @@ -58,7 +55,7 @@ public void onClick(PlayerInteractEvent event) { } if (event.getAction().isLeftClick() && item.getType().equals(plugin.config().generic().defaultBrush())) { - PlayerBrush brush = plugin.brushManager().getBrush(player); + var brush = plugin.brushManager().getBrush(player); player.openInventory(brush.getInventory()); event.setCancelled(true); return; @@ -86,34 +83,32 @@ public void onClick(PlayerInteractEvent event) { return; } - BrushSettings brushSettings; + BrushSettings settings; ItemMeta itemMeta = item.getItemMeta(); if (itemMeta != null && itemMeta.hasLore() && itemMeta.displayName() instanceof TextComponent name) { - Optional brush = plugin.brushManager().getBrushHandler(name.content()); + var brush = plugin.brushManager().getBrushHandler(name.content()); //noinspection removal - brushSettings = brush.map(current -> ExportedPlayerBrush.parse(current, itemMeta)).orElse(null); + settings = brush.map(current -> CraftItemBrushSettings.parse(current, itemMeta)).orElse(null); } else if (item.getType().equals(plugin.config().generic().defaultBrush())) { - brushSettings = plugin.brushManager().getBrush(player); + settings = plugin.brushManager().getBrush(player); } else { return; } event.setCancelled(true); - if (brushSettings == null || brushSettings.blocks().isEmpty()) { + if (settings == null || settings.getBlocks().isEmpty()) { return; } - if (brushSettings.enabled()) { + if (!(settings instanceof PlayerBrushSettings playerSettings) || playerSettings.isEnabled()) { BukkitAdapter.adapt(player).runAction( - () -> brushSettings.brush().paint(location, player, brushSettings), false, true + () -> settings.getBrush().paint(location, player, settings), false, true ); - } else { - plugin.bundle().sendMessage(player, "brush.disabled"); - } + } else plugin.bundle().sendMessage(player, "brush.disabled"); } } diff --git a/src/main/java/net/thenextlvl/gopaint/listeners/InventoryListener.java b/src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java similarity index 89% rename from src/main/java/net/thenextlvl/gopaint/listeners/InventoryListener.java rename to src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java index e59ed653..61a5e46f 100644 --- a/src/main/java/net/thenextlvl/gopaint/listeners/InventoryListener.java +++ b/src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java @@ -16,14 +16,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.listeners; +package net.thenextlvl.gopaint.listener; import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.TextComponent; import net.thenextlvl.gopaint.GoPaintPlugin; -import net.thenextlvl.gopaint.brush.PlayerBrush; -import net.thenextlvl.gopaint.objects.brush.*; -import net.thenextlvl.gopaint.utils.GUI; +import net.thenextlvl.gopaint.brush.*; +import net.thenextlvl.gopaint.util.GUI; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -52,7 +51,7 @@ public void menuClick(InventoryClickEvent event) { } return; } - PlayerBrush playerBrush = plugin.brushManager().getBrush(player); + var playerBrush = plugin.brushManager().getBrush(player); if (event.getRawSlot() == 10 || event.getRawSlot() == 1 || event.getRawSlot() == 19) { if (event.getClick().equals(ClickType.LEFT)) { if (!event.getCursor().getType().isBlock()) { @@ -68,13 +67,13 @@ public void menuClick(InventoryClickEvent event) { if (event.getClick().equals(ClickType.LEFT)) { playerBrush.cycleBrushForward(); } else if (event.getClick().equals(ClickType.RIGHT)) { - playerBrush.cycleBrushBackwards(); + playerBrush.cycleBrushBackward(); } else if (event.getClick().isShiftClick()) { player.openInventory(GUI.generateBrushes()); } event.setCancelled(true); } else if (event.getRawSlot() == 12 || event.getRawSlot() == 3 || event.getRawSlot() == 21) { - Brush brush = playerBrush.brush(); + var brush = playerBrush.getBrush(); if (brush instanceof SprayBrush) { if (event.getClick().equals(ClickType.LEFT)) { playerBrush.increaseChance(); @@ -111,18 +110,18 @@ public void menuClick(InventoryClickEvent event) { } event.setCancelled(true); } else if (event.getRawSlot() == 13 || event.getRawSlot() == 4 || event.getRawSlot() == 22) { - Brush b = playerBrush.brush(); - if (b instanceof AngleBrush) { + var brush = playerBrush.getBrush(); + if (brush instanceof AngleBrush) { if (event.getClick().equals(ClickType.LEFT)) { - playerBrush.increaseAngleHeightDifference(false); + playerBrush.increaseAngleHeightDifference(5); } else if (event.getClick().equals(ClickType.RIGHT)) { - playerBrush.decreaseAngleHeightDifference(false); + playerBrush.decreaseAngleHeightDifference(5); } else if (event.getClick().equals(ClickType.SHIFT_LEFT)) { - playerBrush.increaseAngleHeightDifference(true); + playerBrush.increaseAngleHeightDifference(15); } else if (event.getClick().equals(ClickType.SHIFT_RIGHT)) { - playerBrush.decreaseAngleHeightDifference(true); + playerBrush.decreaseAngleHeightDifference(15); } - } else if (b instanceof GradientBrush) { + } else if (brush instanceof GradientBrush) { if (event.getClick().equals(ClickType.LEFT)) { playerBrush.increaseMixingStrength(); } else if (event.getClick().equals(ClickType.RIGHT)) { @@ -132,13 +131,13 @@ public void menuClick(InventoryClickEvent event) { event.setCancelled(true); } else if (event.getRawSlot() == 14 || event.getRawSlot() == 5 || event.getRawSlot() == 23) { if (event.getClick().equals(ClickType.LEFT)) { - playerBrush.increaseBrushSize(false); + playerBrush.increaseBrushSize(1); } else if (event.getClick().equals(ClickType.RIGHT)) { - playerBrush.decreaseBrushSize(false); + playerBrush.decreaseBrushSize(1); } else if (event.getClick().equals(ClickType.SHIFT_LEFT)) { - playerBrush.increaseBrushSize(true); + playerBrush.increaseBrushSize(10); } else if (event.getClick().equals(ClickType.SHIFT_RIGHT)) { - playerBrush.decreaseBrushSize(true); + playerBrush.decreaseBrushSize(10); } event.setCancelled(true); } else if (event.getRawSlot() == 15 || event.getRawSlot() == 6 || event.getRawSlot() == 24) { @@ -197,7 +196,7 @@ public void menuBrushClick(InventoryClickEvent event) { return; } - PlayerBrush playerBrush = plugin.brushManager().getBrush(player); + var playerBrush = plugin.brushManager().getBrush(player); ItemMeta itemMeta = event.getCurrentItem().getItemMeta(); @@ -208,7 +207,7 @@ public void menuBrushClick(InventoryClickEvent event) { //noinspection deprecation String name = itemMeta.getDisplayName().replace("§6", ""); plugin.brushManager().getBrushHandler(name).ifPresent(brush -> { - playerBrush.brush(brush); + playerBrush.setBrush(brush); playerBrush.updateInventory(); player.openInventory(playerBrush.getInventory()); }); diff --git a/src/main/java/net/thenextlvl/gopaint/objects/other/package-info.java b/src/main/java/net/thenextlvl/gopaint/listener/package-info.java similarity index 87% rename from src/main/java/net/thenextlvl/gopaint/objects/other/package-info.java rename to src/main/java/net/thenextlvl/gopaint/listener/package-info.java index c79226a8..e75c0067 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/other/package-info.java +++ b/src/main/java/net/thenextlvl/gopaint/listener/package-info.java @@ -2,7 +2,7 @@ @FieldsAreNotNullByDefault @MethodsReturnNotNullByDefault @ParametersAreNotNullByDefault -package net.thenextlvl.gopaint.objects.other; +package net.thenextlvl.gopaint.listener; import core.annotation.FieldsAreNotNullByDefault; import core.annotation.MethodsReturnNotNullByDefault; diff --git a/src/main/java/net/thenextlvl/gopaint/objects/other/PluginConfig.java b/src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java similarity index 95% rename from src/main/java/net/thenextlvl/gopaint/objects/other/PluginConfig.java rename to src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java index 1787af5d..2239d97e 100644 --- a/src/main/java/net/thenextlvl/gopaint/objects/other/PluginConfig.java +++ b/src/main/java/net/thenextlvl/gopaint/model/PluginConfig.java @@ -1,6 +1,7 @@ -package net.thenextlvl.gopaint.objects.other; +package net.thenextlvl.gopaint.model; import com.google.gson.annotations.SerializedName; +import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bukkit.Axis; import org.bukkit.Material; diff --git a/src/main/java/net/thenextlvl/gopaint/utils/package-info.java b/src/main/java/net/thenextlvl/gopaint/model/package-info.java similarity index 89% rename from src/main/java/net/thenextlvl/gopaint/utils/package-info.java rename to src/main/java/net/thenextlvl/gopaint/model/package-info.java index e1414ce4..e25b7156 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/package-info.java +++ b/src/main/java/net/thenextlvl/gopaint/model/package-info.java @@ -2,7 +2,7 @@ @FieldsAreNotNullByDefault @MethodsReturnNotNullByDefault @ParametersAreNotNullByDefault -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.model; import core.annotation.FieldsAreNotNullByDefault; import core.annotation.MethodsReturnNotNullByDefault; diff --git a/src/main/java/net/thenextlvl/gopaint/objects/brush/Brush.java b/src/main/java/net/thenextlvl/gopaint/objects/brush/Brush.java deleted file mode 100644 index 21d07d62..00000000 --- a/src/main/java/net/thenextlvl/gopaint/objects/brush/Brush.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * goPaint is designed to simplify painting inside of Minecraft. - * Copyright (C) Arcaniax-Development - * Copyright (C) Arcaniax team and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.thenextlvl.gopaint.objects.brush; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitPlayer; -import com.sk89q.worldedit.math.BlockVector3; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import net.thenextlvl.gopaint.brush.BrushSettings; -import net.thenextlvl.gopaint.utils.Surface; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import java.util.function.Consumer; - -@Getter -@RequiredArgsConstructor -public abstract class Brush { - - private final String name, description, head; - - /** - * Performs a painting action using the provided location, player, and brush settings. - * - * @param location The location the painting action is performed. - * @param player The player who is performing the paint action. - * @param brushSettings The brush settings to be applied while painting. - */ - public abstract void paint(Location location, Player player, BrushSettings brushSettings); - - /** - * Sets the material of a block in an EditSession. - * - * @param session The EditSession to perform the block update in. - * @param block The block to update. - * @param material The material to set the block to. - * @throws MaxChangedBlocksException If the maximum number of changed blocks is exceeded. - */ - protected void setBlock(EditSession session, Block block, Material material) throws MaxChangedBlocksException { - BlockVector3 vector = BlockVector3.at(block.getX(), block.getY(), block.getZ()); - if (session.getMask() == null || session.getMask().test(vector)) { - session.setBlock(vector, BukkitAdapter.asBlockType(material)); - } - } - - /** - * Performs an edit using WorldEdit's EditSession. - * This method wraps the edit session in a try-with-resources block to ensure proper cleanup of resources. - * - * @param player The player performing the edit. - * @param edit A Consumer functional interface that defines the actions to be taken within the edit session. - */ - protected void performEdit(Player player, Consumer edit) { - BukkitPlayer wrapped = BukkitAdapter.adapt(player); - LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(wrapped); - try (EditSession editsession = localSession.createEditSession(wrapped)) { - try { - edit.accept(editsession); - } finally { - localSession.remember(editsession); - } - } - } - - /** - * Checks if a given block passes the default checks defined by the brush settings. - * - * @param brushSettings The brush settings to be checked against. - * @param player The player using the brush. - * @param block The block being checked. - * @return true if the block passes all the default checks, false otherwise. - */ - protected boolean passesDefaultChecks(BrushSettings brushSettings, Player player, Block block) { - return passesMaskCheck(brushSettings, block) && passesSurfaceCheck(brushSettings, player, block); - } - - /** - * Checks if a given block passes the surface check defined by the brush settings. - * - * @param brushSettings The brush settings to be checked against. - * @param player The player using the brush. - * @param block The block being checked. - * @return true if the block passes the surface check, false otherwise. - */ - protected boolean passesSurfaceCheck(BrushSettings brushSettings, Player player, Block block) { - return Surface.isOnSurface(block, brushSettings.surfaceMode(), player.getLocation()); - } - - /** - * Checks if a given block passes the mask check defined by the brush settings. - * - * @param brushSettings The brush settings to be checked against. - * @param block The block being checked. - * @return true if the block passes the mask check, false otherwise. - */ - protected boolean passesMaskCheck(BrushSettings brushSettings, Block block) { - return !brushSettings.maskEnabled() || block.getType().equals(brushSettings.mask()); - } - -} diff --git a/src/main/java/net/thenextlvl/gopaint/utils/GUI.java b/src/main/java/net/thenextlvl/gopaint/util/GUI.java similarity index 82% rename from src/main/java/net/thenextlvl/gopaint/utils/GUI.java rename to src/main/java/net/thenextlvl/gopaint/util/GUI.java index f4065fdd..1fe8ec26 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/GUI.java +++ b/src/main/java/net/thenextlvl/gopaint/util/GUI.java @@ -16,13 +16,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.util; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.thenextlvl.gopaint.GoPaintPlugin; -import net.thenextlvl.gopaint.brush.PlayerBrush; -import net.thenextlvl.gopaint.objects.brush.*; +import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; +import net.thenextlvl.gopaint.brush.*; +import net.thenextlvl.gopaint.brush.setting.CraftPlayerBrushSettings; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.Inventory; @@ -32,7 +33,7 @@ public class GUI { private static final GoPaintPlugin plugin = JavaPlugin.getPlugin(GoPaintPlugin.class); - public static Inventory create(PlayerBrush pb) { + public static Inventory create(CraftPlayerBrushSettings pb) { Inventory inv = Bukkit.createInventory(null, 54, Component.text("goPaint Menu", NamedTextColor.DARK_BLUE)); update(inv, pb); return inv; @@ -43,8 +44,8 @@ public static Inventory generateBrushes() { // FILLER formatDefault(inv); for (int index = 0; index < plugin.brushManager().getBrushes().size(); index++) { - Brush brush = plugin.brushManager().getBrushes().get(index); - inv.setItem(index, Items.createHead(brush.getHead(), 1, "§6" + brush.getName(), + var brush = plugin.brushManager().getBrushes().get(index); + inv.setItem(index, Items.createHead(brush.getHeadValue(), 1, "§6" + brush.getName(), "\n§7Click to select\n\n§8" + brush.getDescription() )); } @@ -57,14 +58,14 @@ private static void formatDefault(Inventory inventory) { } } - public static void update(Inventory inventory, PlayerBrush playerBrush) { - Brush brush = playerBrush.brush(); + public static void update(Inventory inventory, PlayerBrushSettings settings) { + var brush = settings.getBrush(); // FILLER formatDefault(inventory); // goPaint toggle - if (playerBrush.enabled()) { + if (settings.isEnabled()) { inventory.setItem(1, Items.create(Material.LIME_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(10, Items.create(plugin.config().generic().defaultBrush(), 1, "§6goPaint Brush", "§a§lEnabled\n\n§7Left click with item to export\n§7Right click to toggle" @@ -84,7 +85,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { String clicks = "\n§7Shift click to select\n§7Click to cycle brush\n\n"; - inventory.setItem(11, Items.createHead(brush.getHead(), 1, "§6Selected Brush type", + inventory.setItem(11, Items.createHead(brush.getHeadValue(), 1, "§6Selected Brush type", clicks + plugin.brushManager().getBrushLore(brush) )); inventory.setItem(20, Items.create(Material.ORANGE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -93,7 +94,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof SprayBrush) { inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(12, Items.create(Material.GOLD_NUGGET, 1, - "§6Place chance: §e" + playerBrush.chance() + "%", + "§6Place chance: §e" + settings.getChance() + "%", "\n§7Left click to increase\n§7Right click to decrease" )); inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -103,7 +104,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof DiscBrush) { inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(12, Items.create(Material.COMPASS, 1, - "§6Axis: §e" + playerBrush.axis(), "\n§7Click to change" + "§6Axis: §e" + settings.getAxis(), "\n§7Click to change" )); inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); } @@ -113,7 +114,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof OverlayBrush || brush instanceof UnderlayBrush) { inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(12, Items.create(Material.BOOK, 1, - "§6Layer Thickness: §e" + playerBrush.thickness(), + "§6Layer Thickness: §e" + settings.getThickness(), "\n§7Left click to increase\n§7Right click to decrease" )); inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -123,14 +124,14 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof AngleBrush) { inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(12, Items.create(Material.DAYLIGHT_DETECTOR, 1, - "§6Angle Check Distance: §e" + playerBrush.angleDistance(), + "§6Angle Check Distance: §e" + settings.getAngleDistance(), "\n§7Left click to increase\n§7Right click to decrease" )); inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(4, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(13, Items.create(Material.BLAZE_ROD, 1, - "§6Maximum Angle: §e" + playerBrush.angleHeightDifference() + "°", + "§6Maximum Angle: §e" + settings.getAngleHeightDifference() + "°", "\n§7Left click to increase\n§7Right click to decrease\n§7Shift click to change by 15" )); inventory.setItem(22, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -140,7 +141,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof FractureBrush) { inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(12, Items.create(Material.DAYLIGHT_DETECTOR, 1, - "§6Fracture Check Distance: §e" + playerBrush.fractureDistance(), + "§6Fracture Check Distance: §e" + settings.getFractureDistance(), "\n§7Left click to increase\n§7Right click to decrease" )); inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -150,7 +151,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof GradientBrush) { inventory.setItem(4, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(13, Items.create(Material.MAGMA_CREAM, 1, - "§6Mixing Strength: §e" + playerBrush.mixingStrength() + "%", + "§6Mixing Strength: §e" + settings.getMixingStrength() + "%", "\n§7Left click to increase\n§7Right click to decrease" )); inventory.setItem(22, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -159,7 +160,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { if (brush instanceof SplatterBrush || brush instanceof PaintBrush || brush instanceof GradientBrush) { inventory.setItem(3, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(12, Items.create(Material.BLAZE_POWDER, 1, - "§6Falloff Strength: §e" + playerBrush.falloffStrength() + "%", + "§6Falloff Strength: §e" + settings.getFalloffStrength() + "%", "\n§7Left click to increase\n§7Right click to decrease" )); inventory.setItem(21, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); @@ -169,13 +170,13 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { // Size inventory.setItem(5, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(14, Items.create(Material.BROWN_MUSHROOM, 1, - "§6Brush Size: §e" + playerBrush.size(), + "§6Brush Size: §e" + settings.getSize(), "\n§7Left click to increase\n§7Right click to decrease\n§7Shift click to change by 10" )); inventory.setItem(23, Items.create(Material.WHITE_STAINED_GLASS_PANE, 1, "§7", "")); // Mask toggle - if (playerBrush.maskEnabled()) { + if (settings.isMaskEnabled()) { inventory.setItem(6, Items.create(Material.LIME_STAINED_GLASS_PANE, 1, "§7", "")); inventory.setItem(15, Items.create(Material.JACK_O_LANTERN, 1, "§6Mask", @@ -189,7 +190,7 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { } // Surface Mode toggle - addSurfaceModeSwitch(inventory, playerBrush); + addSurfaceModeSwitch(inventory, settings); // Place Block for (int x = 37; x <= 41; x++) { @@ -199,9 +200,9 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { inventory.setItem(x, Items.create(Material.BARRIER, 1, "§cEmpty Slot", "\n§7Click with a block to set")); } int x = 46; - int size = playerBrush.blocks().size(); + int size = settings.getBlocks().size(); int chance = size == 0 ? 0 : 100 / size; - for (Material material : playerBrush.blocks()) { + for (Material material : settings.getBlocks()) { if (chance > 64) { inventory.setItem(x, Items.create(material, 1, "§aSlot " + (x - 45) + " §7" + chance + "%", @@ -218,27 +219,27 @@ public static void update(Inventory inventory, PlayerBrush playerBrush) { // Mask Block inventory.setItem(43, Items.create(Material.YELLOW_STAINED_GLASS_PANE, 1, "§7", "")); - inventory.setItem(52, Items.create(playerBrush.mask(), 1, "§6Current Mask", "\n§7Left click with a block to change")); + inventory.setItem(52, Items.create(settings.getMask(), 1, "§6Current Mask", "\n§7Left click with a block to change")); } - private static void addSurfaceModeSwitch(Inventory inv, PlayerBrush playerBrush) { - Material pane = switch (playerBrush.surfaceMode()) { + private static void addSurfaceModeSwitch(Inventory inventory, PlayerBrushSettings settings) { + Material pane = switch (settings.getSurfaceMode()) { case DIRECT -> Material.LIME_STAINED_GLASS_PANE; case DISABLED -> Material.RED_STAINED_GLASS_PANE; case RELATIVE -> Material.ORANGE_STAINED_GLASS_PANE; }; - String color = switch (playerBrush.surfaceMode()) { + String color = switch (settings.getSurfaceMode()) { case DIRECT -> "§a"; case DISABLED -> "§c"; case RELATIVE -> "§6"; }; - inv.setItem(7, Items.create(pane, 1, "§7", "")); - inv.setItem(16, Items.create(Material.LIGHT_WEIGHTED_PRESSURE_PLATE, 1, + inventory.setItem(7, Items.create(pane, 1, "§7", "")); + inventory.setItem(16, Items.create(Material.LIGHT_WEIGHTED_PRESSURE_PLATE, 1, "§6Surface Mode", - color + "§l" + playerBrush.surfaceMode().getName() + "\n\n§7Click to toggle" + color + "§l" + settings.getSurfaceMode().getName() + "\n\n§7Click to toggle" )); - inv.setItem(25, Items.create(pane, 1, "§7", "")); + inventory.setItem(25, Items.create(pane, 1, "§7", "")); } } diff --git a/src/main/java/net/thenextlvl/gopaint/utils/Items.java b/src/main/java/net/thenextlvl/gopaint/util/Items.java similarity index 98% rename from src/main/java/net/thenextlvl/gopaint/utils/Items.java rename to src/main/java/net/thenextlvl/gopaint/util/Items.java index a9942464..9b407ef7 100644 --- a/src/main/java/net/thenextlvl/gopaint/utils/Items.java +++ b/src/main/java/net/thenextlvl/gopaint/util/Items.java @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package net.thenextlvl.gopaint.utils; +package net.thenextlvl.gopaint.util; import com.destroystokyo.paper.profile.ProfileProperty; import net.kyori.adventure.text.Component; diff --git a/src/main/java/net/thenextlvl/gopaint/util/package-info.java b/src/main/java/net/thenextlvl/gopaint/util/package-info.java new file mode 100644 index 00000000..44f318f1 --- /dev/null +++ b/src/main/java/net/thenextlvl/gopaint/util/package-info.java @@ -0,0 +1,10 @@ +@TypesAreNotNullByDefault +@FieldsAreNotNullByDefault +@MethodsReturnNotNullByDefault +@ParametersAreNotNullByDefault +package net.thenextlvl.gopaint.util; + +import core.annotation.FieldsAreNotNullByDefault; +import core.annotation.MethodsReturnNotNullByDefault; +import core.annotation.ParametersAreNotNullByDefault; +import core.annotation.TypesAreNotNullByDefault; \ No newline at end of file From af2063f6b23c9a797fcbcc18e9143de4065be442 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:03:22 +0200 Subject: [PATCH 3/8] added api module --- api/build.gradle.kts | 24 ++ .../thenextlvl/gopaint/api/brush/Brush.java | 94 +++++++ .../gopaint/api/brush/BrushManager.java | 69 +++++ .../api/brush/setting/ItemBrushSettings.java | 4 + .../brush/setting/PlayerBrushSettings.java | 250 ++++++++++++++++++ .../api/brush/setting/package-info.java | 10 + .../gopaint/api/model/package-info.java | 10 + build.gradle.kts | 2 + settings.gradle.kts | 1 + 9 files changed, 464 insertions(+) create mode 100644 api/build.gradle.kts create mode 100644 api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java create mode 100644 api/src/main/java/net/thenextlvl/gopaint/api/brush/BrushManager.java create mode 100644 api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/ItemBrushSettings.java create mode 100644 api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java create mode 100644 api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/package-info.java create mode 100644 api/src/main/java/net/thenextlvl/gopaint/api/model/package-info.java diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 00000000..c137748d --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("java") + id("java-library") +} + +group = "net.thenextlvl.gopaint" +version = "1.1.1" + +repositories { + mavenCentral() + maven("https://repo.thenextlvl.net/releases") + maven("https://papermc.io/repo/repository/maven-public/") +} + +dependencies { + compileOnly("org.projectlombok:lombok:1.18.32") + compileOnly("net.thenextlvl.core:annotations:2.0.1") + compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") + + implementation(platform("com.intellectualsites.bom:bom-newest:1.27")) + compileOnlyApi("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit") + + annotationProcessor("org.projectlombok:lombok:1.18.32") +} diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java new file mode 100644 index 00000000..63c00395 --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java @@ -0,0 +1,94 @@ +package net.thenextlvl.gopaint.api.brush; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.function.Consumer; + +/** + * This interface represents a brush used for painting blocks in a world. + */ +public interface Brush { + /** + * Retrieves the name of the brush. + * + * @return The name of the brush. + */ + String getName(); + + /** + * Retrieves the description of the brush. + * + * @return The description of the brush. + */ + String getDescription(); + + /** + * Retrieves the base64 head value. + * + * @return The base64 head value. + */ + String getHeadValue(); + + /** + * Performs a painting action using the provided location, player, and brush settings. + * + * @param location The location the painting action is performed. + * @param player The player who is performing the paint action. + * @param brushSettings The brush settings to be applied while painting. + */ + void paint(Location location, Player player, BrushSettings brushSettings); + + /** + * Sets the material of a block in an EditSession. + * + * @param session The EditSession to perform the block update in. + * @param block The block to update. + * @param material The material to set the block to. + * @throws MaxChangedBlocksException If the maximum number of changed blocks is exceeded. + */ + void setBlock(EditSession session, Block block, Material material) throws MaxChangedBlocksException; + + /** + * Performs an edit using WorldEdit's EditSession. + * This method wraps the edit session in a try-with-resources block to ensure proper cleanup of resources. + * + * @param player The player performing the edit. + * @param edit A Consumer functional interface that defines the actions to be taken within the edit session. + */ + void performEdit(Player player, Consumer edit); + + /** + * Checks if a given block passes the default checks defined by the brush settings. + * + * @param brushSettings The brush settings to be checked against. + * @param player The player using the brush. + * @param block The block being checked. + * @return true if the block passes all the default checks, false otherwise. + */ + boolean passesDefaultChecks(BrushSettings brushSettings, Player player, Block block); + + /** + * Checks if a given block passes the surface check defined by the brush settings. + * + * @param brushSettings The brush settings to be checked against. + * @param player The player using the brush. + * @param block The block being checked. + * @return true if the block passes the surface check, false otherwise. + */ + boolean passesSurfaceCheck(BrushSettings brushSettings, Player player, Block block); + + /** + * Checks if a given block passes the mask check defined by the brush settings. + * + * @param brushSettings The brush settings to be checked against. + * @param block The block being checked. + * @return true if the block passes the mask check, false otherwise. + */ + boolean passesMaskCheck(BrushSettings brushSettings, Block block); +} diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/BrushManager.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/BrushManager.java new file mode 100644 index 00000000..41c7173f --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/BrushManager.java @@ -0,0 +1,69 @@ +package net.thenextlvl.gopaint.api.brush; + +import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Optional; + +/** + * This interface manages the brush selection for each player. + */ +public interface BrushManager { + + /** + * Retrieves the list of brushes available in the BrushManager. + * + * @return The list of brushes. + */ + List getBrushes(); + + /** + * Retrieves the brush settings for a specific player. + * + * @param player The player whose brush settings are being retrieved. + * @return The brush settings for the specified player. + */ + PlayerBrushSettings getBrush(Player player); + + /** + * Retrieves the lore for a specific brush. Each brush name is preceded by a color code + * indicating whether it is the currently selected brush or not. + * + * @param brush The brush for which to retrieve the lore. + * @return The lore for the specified brush. + */ + String getBrushLore(Brush brush); + + /** + * Retrieves the brush handler for the given name. + * + * @param name The name of the brush to look for. + * @return An optional containing the brush handler, or empty if not found. + */ + Optional getBrushHandler(String name); + + /** + * Removes the brush settings for a specific player. + * + * @param player The player whose brush settings are being removed. + */ + void removeBrush(Player player); + + /** + * Retrieves the next brush in the list of available brushes. + * + * @param brush The current brush, if null returns the first brush in the list. + * @return The next brush in the list, or the first brush if the current brush is null. + */ + Brush cycleForward(@Nullable Brush brush); + + /** + * Retrieves the previous brush in the list of available brushes. + * + * @param brush The current brush. + * @return The previous brush in the list, or the first brush if the current brush is null. + */ + Brush cycleBackward(@Nullable Brush brush); +} diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/ItemBrushSettings.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/ItemBrushSettings.java new file mode 100644 index 00000000..3b2cb003 --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/ItemBrushSettings.java @@ -0,0 +1,4 @@ +package net.thenextlvl.gopaint.api.brush.setting; + +public interface ItemBrushSettings extends BrushSettings { +} diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java new file mode 100644 index 00000000..0a128c50 --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/PlayerBrushSettings.java @@ -0,0 +1,250 @@ +package net.thenextlvl.gopaint.api.brush.setting; + +import net.thenextlvl.gopaint.api.brush.Brush; +import org.bukkit.Material; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.ApiStatus; + +/** + * The PlayerBrushSettings interface extends the BrushSettings interface and the InventoryHolder interface. + * It represents the configuration settings for a brush specifically used by a player. + */ +public interface PlayerBrushSettings extends BrushSettings, InventoryHolder { + /** + * Checks whether the brush is enabled. + * + * @return true if the brush is enabled, false if it is disabled + */ + boolean isEnabled(); + + /** + * Enables or disables the brush. + * + * @return true if the brush is enabled, false if it is disabled + */ + boolean toggle(); + + /** + * Adds a block to the block palette. + * + * @param type The Material type of the block to add. + * @param slot The slot index in the block palette where the block should be added. + */ + void addBlock(Material type, int slot); + + /** + * Cycle the axis of the brush. + */ + void cycleAxis(); + + /** + * Cycle the selected brush backward. + */ + void cycleBrushBackward(); + + /** + * Cycle the selected brush forward. + */ + void cycleBrushForward(); + + /** + * Cycle the surface mode of the brush. + */ + void cycleSurfaceMode(); + + /** + * Decreases the angle distance of the brush. + *

+ * The angle distance determines the angular range in which the brush will affect blocks. + * A smaller angle distance will result in a more focused application of the brush. + */ + void decreaseAngleDistance(); + + /** + * Decreases the height difference between angles. + *

+ * The angle height difference determines the vertical range in which the brush will affect blocks. + * A smaller angle height difference will result in a more focused application of the brush. + * + * @param amount The amount by which to decrease the angle height difference. + */ + void decreaseAngleHeightDifference(int amount); + + /** + * Decreases the brush size by the given amount. + * + * @param amount The amount by which to decrease the brush size. + */ + void decreaseBrushSize(int amount); + + /** + * Decreases the chance of the brush. + *

+ * This method decreases the likelihood that the brush will affect blocks within its range when applied. + */ + void decreaseChance(); + + /** + * Decreases the falloff strength of the brush. + *

+ * The falloff strength determines the rate at which the brush's effect diminishes + * as it moves away from the center point. A lower falloff strength will result in + * a more gradual diminishing of the brush's effect. + */ + void decreaseFalloffStrength(); + + /** + * Decreases the fracture distance of the brush. + * + *

+ * The fracture distance determines the distance between fractured block replicas when the brush is applied. + * A smaller fracture distance will result in more closely spaced replicas, resulting in a more dense pattern. + */ + void decreaseFractureDistance(); + + /** + * Decreases the mixing strength of the brush. + *

+ * The mixing strength determines the intensity of the brush's effect when applied. + * A lower mixing strength will result in a less prominent effect. + */ + void decreaseMixingStrength(); + + /** + * Decreases the thickness of the brush. + *

+ * This method decreases the thickness of the brush, allowing it to cover a smaller area when applied. + */ + void decreaseThickness(); + + /** + * Exports the brush settings visually onto the given ItemStack. + * + * @param itemStack The ItemStack to export the brush settings to. + */ + void export(ItemStack itemStack); + + /** + * Increases the angle distance of the brush. + * + *

+ * The angle distance determines the angular range in which the brush will affect blocks. + * A larger angle distance will result in a broader application of the brush. + */ + void increaseAngleDistance(); + + /** + * Increases the height difference between angles in the brush. + * + *

+ * The angle height difference determines the vertical range in which the brush will affect blocks. + * A larger angle height difference will result in a broader application of the brush vertically. + * + * @param amount The amount by which to increase the angle height difference. + */ + void increaseAngleHeightDifference(int amount); + + /** + * Increases the size of the brush. + * + *

The size determines the area the brush will cover when applied. + * This method increases the size of the brush by the specified amount. + * + * @param amount The amount by which to increase the brush size. + */ + void increaseBrushSize(int amount); + + /** + * Increases the chance of the brush. + *

+ * This method increases the likelihood that the brush will affect blocks within its range when applied. + */ + void increaseChance(); + + /** + * Increases the falloff strength of the brush. + * + *

+ * The falloff strength determines the rate at which the brush's effect diminishes + * as it moves away from the center point. A lower falloff strength will result in + * a more gradual diminishing of the brush's effect. + */ + void increaseFalloffStrength(); + + /** + * Increases the fracture distance of the brush. + *

+ * The fracture distance determines the distance between fractured block replicas when the brush is applied. + * A larger fracture distance will result in more widely spaced replicas, resulting in a less dense pattern. + */ + void increaseFractureDistance(); + + /** + * Increases the mixing strength of the brush. + *

+ * The mixing strength determines the intensity of the brush's effect when applied. + * A higher mixing strength will result in a more prominent effect. + */ + void increaseMixingStrength(); + + /** + * Increases the thickness of the brush. + *

+ * This method increases the thickness of the brush, allowing it to cover a larger area when applied. + */ + void increaseThickness(); + + /** + * Removes a block from the block palette at the specified slot index. + * + * @param slot The slot index in the block palette from which the block should be removed. + */ + void removeBlock(int slot); + + /** + * Sets the brush for the player's brush settings. + * + * @param brush The brush to set. + */ + void setBrush(Brush brush); + + /** + * Sets the mask for the brush. + *

+ * The mask determines whether the brush applies its effect only to blocks matching the material specified + * + * @param type The Material type to set as the mask. + * @deprecated the mask-material is going to be replaced with a WorldEdit Mask + */ + @Deprecated(since = "1.1.1") + @ApiStatus.ScheduledForRemoval(inVersion = "1.2.0") + void setMask(Material type); + + /** + * Sets the size of the brush. + *

+ * The size determines the area the brush will cover when applied. + * + * @param size The size of the brush. Must be a positive integer. + */ + void setSize(int size); + + /** + * Toggles the mask state of the brush. + *

+ * The mask state determines whether the brush applies its effect only to blocks + * matching the material specified by {@link PlayerBrushSettings#setMask(Material)}. + * If the mask is enabled, the brush will only affect blocks of the specified material. + * If the mask is disabled, the brush will affect blocks of any material. + */ + void toggleMask(); + + /** + * Updates the inventory of the player brush settings. + *

+ * This method should be called whenever there is a change + * in the brush settings that requires updating the inventory display. + */ + void updateInventory(); +} diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/package-info.java b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/package-info.java new file mode 100644 index 00000000..4d524921 --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/brush/setting/package-info.java @@ -0,0 +1,10 @@ +@TypesAreNotNullByDefault +@FieldsAreNotNullByDefault +@MethodsReturnNotNullByDefault +@ParametersAreNotNullByDefault +package net.thenextlvl.gopaint.api.brush.setting; + +import core.annotation.FieldsAreNotNullByDefault; +import core.annotation.MethodsReturnNotNullByDefault; +import core.annotation.ParametersAreNotNullByDefault; +import core.annotation.TypesAreNotNullByDefault; \ No newline at end of file diff --git a/api/src/main/java/net/thenextlvl/gopaint/api/model/package-info.java b/api/src/main/java/net/thenextlvl/gopaint/api/model/package-info.java new file mode 100644 index 00000000..2ebbdec5 --- /dev/null +++ b/api/src/main/java/net/thenextlvl/gopaint/api/model/package-info.java @@ -0,0 +1,10 @@ +@TypesAreNotNullByDefault +@FieldsAreNotNullByDefault +@MethodsReturnNotNullByDefault +@ParametersAreNotNullByDefault +package net.thenextlvl.gopaint.api.model; + +import core.annotation.FieldsAreNotNullByDefault; +import core.annotation.MethodsReturnNotNullByDefault; +import core.annotation.ParametersAreNotNullByDefault; +import core.annotation.TypesAreNotNullByDefault; \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index a9d97199..b5b27535 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,6 +35,8 @@ dependencies { implementation("net.thenextlvl.core:i18n:1.0.18") implementation("net.thenextlvl.core:adapters:1.0.9") + api(project(":api")) + annotationProcessor("org.projectlombok:lombok:1.18.32") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 19cc1a34..c98d7ffa 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,2 @@ rootProject.name = "goPaintAdvanced" +include("api") From 9c6e09a9c7dc9bbe0701474485f02c1cf2d90870 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:03:43 +0200 Subject: [PATCH 4/8] renamed exported player brush --- .../brush/setting/CraftItemBrushSettings.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java diff --git a/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java new file mode 100644 index 00000000..b0ac9bfc --- /dev/null +++ b/src/main/java/net/thenextlvl/gopaint/brush/setting/CraftItemBrushSettings.java @@ -0,0 +1,105 @@ +/* + * goPaint is designed to simplify painting inside of Minecraft. + * Copyright (C) Arcaniax-Development + * Copyright (C) Arcaniax team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.thenextlvl.gopaint.brush.setting; + +import lombok.Builder; +import lombok.Getter; +import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.brush.setting.ItemBrushSettings; +import net.thenextlvl.gopaint.api.model.SurfaceMode; +import org.bukkit.Axis; +import org.bukkit.Material; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +@Getter +@Builder(builderClassName = "Builder") +public final class CraftItemBrushSettings implements ItemBrushSettings { + private final Brush brush; + private final @Nullable Material mask; + private final List blocks; + private final Axis axis; + private final SurfaceMode surfaceMode; + private final int size; + private final int chance; + private final int thickness; + private final int angleDistance; + private final int fractureDistance; + private final int falloffStrength; + private final int mixingStrength; + private final double angleHeightDifference; + + private static final Random random = new Random(); + + @Override + public boolean isMaskEnabled() { + return getMask() != null; + } + + @Override + public Material getRandomBlock() { + return getBlocks().get(getRandom().nextInt(getBlocks().size())); + } + + @Override + public Random getRandom() { + return random; + } + + @Deprecated(forRemoval = true) + public static ItemBrushSettings parse(Brush brush, ItemMeta itemMeta) { + var builder = builder().brush(brush); + Optional.ofNullable(itemMeta.getLore()).ifPresent(lore -> lore.stream() + .map(line -> line.replace("§8", "")) + .forEach(line -> { + if (line.startsWith("Size: ")) { + builder.size(Integer.parseInt(line.substring(6))); + } else if (line.startsWith("Chance: ")) { + builder.chance(Integer.parseInt(line.substring(8, line.length() - 1))); + } else if (line.startsWith("Thickness: ")) { + builder.thickness(Integer.parseInt(line.substring(11))); + } else if (line.startsWith("Axis: ")) { + builder.axis(Axis.valueOf(line.substring(6).toUpperCase())); + } else if (line.startsWith("FractureDistance: ")) { + builder.fractureDistance(Integer.parseInt(line.substring(18))); + } else if (line.startsWith("AngleDistance: ")) { + builder.angleDistance(Integer.parseInt(line.substring(15))); + } else if (line.startsWith("AngleHeightDifference: ")) { + builder.angleHeightDifference(Double.parseDouble(line.substring(23))); + } else if (line.startsWith("Mixing: ")) { + builder.mixingStrength(Integer.parseInt(line.substring(8))); + } else if (line.startsWith("Falloff: ")) { + builder.falloffStrength(Integer.parseInt(line.substring(9))); + } else if (line.startsWith("Blocks: ")) { + builder.blocks(Arrays.stream(line.substring(8).split(", ")) + .map(Material::matchMaterial) + .filter(Objects::nonNull) + .toList()); + } else if (line.startsWith("Mask: ")) { + builder.mask(Material.matchMaterial(line.substring(6))); + } else if (line.startsWith("Surface Mode: ")) { + SurfaceMode.byName(line.substring(14)).ifPresent(builder::surfaceMode); + } + })); + return builder.build(); + } + +} From a4f4ff28a2e4e1925d2f136f2411b63c24bc3b7b Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:03:50 +0200 Subject: [PATCH 5/8] added package info --- .../thenextlvl/gopaint/brush/setting/package-info.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/net/thenextlvl/gopaint/brush/setting/package-info.java diff --git a/src/main/java/net/thenextlvl/gopaint/brush/setting/package-info.java b/src/main/java/net/thenextlvl/gopaint/brush/setting/package-info.java new file mode 100644 index 00000000..af289c6c --- /dev/null +++ b/src/main/java/net/thenextlvl/gopaint/brush/setting/package-info.java @@ -0,0 +1,10 @@ +@TypesAreNotNullByDefault +@FieldsAreNotNullByDefault +@MethodsReturnNotNullByDefault +@ParametersAreNotNullByDefault +package net.thenextlvl.gopaint.brush.setting; + +import core.annotation.FieldsAreNotNullByDefault; +import core.annotation.MethodsReturnNotNullByDefault; +import core.annotation.ParametersAreNotNullByDefault; +import core.annotation.TypesAreNotNullByDefault; \ No newline at end of file From 68625b933fddf5679567b02652a48a92804426e3 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:04:54 +0200 Subject: [PATCH 6/8] added abstract CraftBrush --- .../thenextlvl/gopaint/brush/CraftBrush.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/net/thenextlvl/gopaint/brush/CraftBrush.java diff --git a/src/main/java/net/thenextlvl/gopaint/brush/CraftBrush.java b/src/main/java/net/thenextlvl/gopaint/brush/CraftBrush.java new file mode 100644 index 00000000..10033e5e --- /dev/null +++ b/src/main/java/net/thenextlvl/gopaint/brush/CraftBrush.java @@ -0,0 +1,56 @@ +package net.thenextlvl.gopaint.brush; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldedit.math.BlockVector3; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import net.thenextlvl.gopaint.api.brush.Brush; +import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; +import net.thenextlvl.gopaint.api.math.Surface; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.function.Consumer; + +@Getter +@RequiredArgsConstructor +abstract class CraftBrush implements Brush { + private final String name, description, headValue; + + public void setBlock(EditSession session, Block block, Material material) throws MaxChangedBlocksException { + BlockVector3 vector = BlockVector3.at(block.getX(), block.getY(), block.getZ()); + if (session.getMask() == null || session.getMask().test(vector)) { + session.setBlock(vector, BukkitAdapter.asBlockType(material)); + } + } + + public void performEdit(Player player, Consumer edit) { + BukkitPlayer wrapped = BukkitAdapter.adapt(player); + LocalSession localSession = WorldEdit.getInstance().getSessionManager().get(wrapped); + try (EditSession editsession = localSession.createEditSession(wrapped)) { + try { + edit.accept(editsession); + } finally { + localSession.remember(editsession); + } + } + } + + public boolean passesDefaultChecks(BrushSettings brushSettings, Player player, Block block) { + return passesMaskCheck(brushSettings, block) && passesSurfaceCheck(brushSettings, player, block); + } + + public boolean passesSurfaceCheck(BrushSettings brushSettings, Player player, Block block) { + return Surface.isOnSurface(block, brushSettings.getSurfaceMode(), player.getLocation()); + } + + public boolean passesMaskCheck(BrushSettings brushSettings, Block block) { + return !brushSettings.isMaskEnabled() || block.getType().equals(brushSettings.getMask()); + } +} From aed4f37f6c28a83fc512185033e8cb019e9a916f Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:05:06 +0200 Subject: [PATCH 7/8] renamed getter --- .../java/net/thenextlvl/gopaint/command/GoPaintCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/thenextlvl/gopaint/command/GoPaintCommand.java b/src/main/java/net/thenextlvl/gopaint/command/GoPaintCommand.java index 1a8e9705..1aba55e6 100644 --- a/src/main/java/net/thenextlvl/gopaint/command/GoPaintCommand.java +++ b/src/main/java/net/thenextlvl/gopaint/command/GoPaintCommand.java @@ -41,7 +41,7 @@ private int size(CommandContext context) { var brush = plugin.brushManager().getBrush(player); brush.setSize(context.getArgument("size", int.class)); plugin.bundle().sendMessage(player, "command.gopaint.brush.size", - Placeholder.parsed("size", String.valueOf(brush.size()))); + Placeholder.parsed("size", String.valueOf(brush.getSize()))); return Command.SINGLE_SUCCESS; } From e8fce1171d536eca56d4cb6845128e1b54eb53e4 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 16 Jun 2024 15:05:14 +0200 Subject: [PATCH 8/8] adapted changes --- .../net/thenextlvl/gopaint/GoPaintPlugin.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java b/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java index a8362b76..37746746 100644 --- a/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java +++ b/src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java @@ -11,13 +11,14 @@ import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import net.thenextlvl.gopaint.brush.PlayerBrushManager; +import net.thenextlvl.gopaint.api.brush.BrushManager; +import net.thenextlvl.gopaint.brush.CraftBrushManager; import net.thenextlvl.gopaint.command.GoPaintCommand; -import net.thenextlvl.gopaint.objects.other.PluginConfig; -import net.thenextlvl.gopaint.listeners.ConnectListener; -import net.thenextlvl.gopaint.listeners.InteractListener; -import net.thenextlvl.gopaint.listeners.InventoryListener; -import net.thenextlvl.gopaint.objects.other.SurfaceMode; +import net.thenextlvl.gopaint.model.PluginConfig; +import net.thenextlvl.gopaint.listener.ConnectListener; +import net.thenextlvl.gopaint.listener.InteractListener; +import net.thenextlvl.gopaint.listener.InventoryListener; +import net.thenextlvl.gopaint.api.model.SurfaceMode; import org.bstats.bukkit.Metrics; import org.bukkit.Axis; import org.bukkit.Bukkit; @@ -57,7 +58,7 @@ public class GoPaintPlugin extends JavaPlugin implements Listener { .create() ).validate().save(); - private final @Getter PlayerBrushManager brushManager = new PlayerBrushManager(this); + private final @Getter BrushManager brushManager = new CraftBrushManager(this); private final Metrics metrics = new Metrics(this, 22279); @Override @@ -76,18 +77,14 @@ public void reloadConfig() { configFile.reload(); } - private void registerCommands() { - new GoPaintCommand(this).register(); - } - private void registerListeners() { Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this); Bukkit.getPluginManager().registerEvents(new InteractListener(this), this); - Bukkit.getPluginManager().registerEvents(new ConnectListener(brushManager()), this); + Bukkit.getPluginManager().registerEvents(new ConnectListener(this), this); } - private boolean hasOriginalGoPaint() { - return Bukkit.getPluginManager().getPlugin("goPaint") != this; + private void registerCommands() { + new GoPaintCommand(this).register(); } public PluginConfig config() {