Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructured the entire project #12

Merged
merged 8 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
94 changes: 94 additions & 0 deletions api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java
Original file line number Diff line number Diff line change
@@ -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<EditSession> 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);
}
Original file line number Diff line number Diff line change
@@ -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<Brush> 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<Brush> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
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;
Expand All @@ -34,133 +15,118 @@
* 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<Material> blocks();
List<Material> getBlocks();

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

/**
* 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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.thenextlvl.gopaint.api.brush.setting;

public interface ItemBrushSettings extends BrushSettings {
}
Loading
Loading