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

Code cleanup and performance improvements #17

Merged
merged 100 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
ae0f869
Merge branch 'code-cleanup' of /home/david/IdeaProjects/BetterGoPaint…
NonSwag Jun 7, 2024
15720e8
Merge remote-tracking branch 'origin/code-cleanup' into code-cleanup
NonSwag Jun 8, 2024
afdac5a
removed XMaterials
NonSwag Jun 9, 2024
5d42b76
added brush settings interface
NonSwag Jun 9, 2024
b523947
removed static plugin access
NonSwag Jun 9, 2024
5074c10
renamed reload method for clarity
NonSwag Jun 9, 2024
8aaad5c
removed static plugin access
NonSwag Jun 9, 2024
673f166
removed xmaterials
NonSwag Jun 9, 2024
1cacea9
optimized brushes
NonSwag Jun 9, 2024
07015fe
optimized algorithms
NonSwag Jun 9, 2024
ffe9c56
removed unused and redundant code
NonSwag Jun 9, 2024
a7eaacd
added new underlay brush
NonSwag Jun 9, 2024
fa9ec9e
organized file
NonSwag Jun 9, 2024
d138af3
properly handle file loading errors
NonSwag Jun 9, 2024
d5c92f2
only replace solid blocks
NonSwag Jun 9, 2024
a834651
spotless apply
NonSwag Jun 9, 2024
bdd6620
don't use anonymous class for initialization
NonSwag Jun 9, 2024
c494382
removed excessive line breaks
NonSwag Jun 9, 2024
afe059f
reformat
NonSwag Jun 9, 2024
6beca47
added isEnabled to brush settings interface
NonSwag Jun 9, 2024
e4f207f
remove duplicate code
NonSwag Jun 9, 2024
46112a1
split up checks
NonSwag Jun 9, 2024
bec9641
let surface check only test for non-solid blocks
NonSwag Jun 9, 2024
1e33a39
fixed division by 0
NonSwag Jun 9, 2024
6ecce1f
made exported player brushes work again
NonSwag Jun 9, 2024
c2bcfb9
fixed interaction point
NonSwag Jun 9, 2024
0248e9d
use sendRichMessage instead of manually accessing minimessage
NonSwag Jun 9, 2024
9c2d9e1
moved logging from condition to effect
NonSwag Jun 9, 2024
0ee6bf8
removed suggestPaper as we are a paper-plugin
NonSwag Jun 9, 2024
8bead5f
replaced pumpkin with original one
NonSwag Jun 9, 2024
d94818b
cleanup
NonSwag Jun 9, 2024
6d69aa1
renamed constants to match conventions
NonSwag Jun 9, 2024
cbdd868
removed redundant concatenation
NonSwag Jun 9, 2024
ce89303
changed visibility
NonSwag Jun 9, 2024
2d0a97c
use sendRichMessage
NonSwag Jun 9, 2024
ce4a1f3
removed unused import
NonSwag Jun 9, 2024
e0de0c8
recovered original paint brush functionality
NonSwag Jun 9, 2024
813b787
removed unused parameter
NonSwag Jun 9, 2024
dd92dcd
renamed parameter
NonSwag Jun 10, 2024
dcf9dc4
renamed method for clarity
NonSwag Jun 10, 2024
40ff821
removed nonsense comment
NonSwag Jun 10, 2024
b46fad3
renamed parameters for clarity
NonSwag Jun 10, 2024
2d222fd
made class final
NonSwag Jun 10, 2024
6a09cd4
added nullability information
NonSwag Jun 12, 2024
77098d9
moved head values to respective brush classes
NonSwag Jun 12, 2024
2764f16
use builder pattern
NonSwag Jun 12, 2024
af54ecb
return constant name
NonSwag Jun 12, 2024
7864611
adapted pattern changes
NonSwag Jun 12, 2024
66cde49
added description getter
NonSwag Jun 12, 2024
4a083e2
overall code improvements
NonSwag Jun 12, 2024
1487583
added nullability information
NonSwag Jun 12, 2024
bdb3889
reverted unintended changes
NonSwag Jun 12, 2024
ca0c2f6
use primitives instead of wrapper
NonSwag Jun 12, 2024
a0a0bac
re-added missing color removal
NonSwag Jun 12, 2024
4603e0b
re-added missing check
NonSwag Jun 12, 2024
3a4fe84
added surface mode enum
NonSwag Jun 12, 2024
0a65b53
added documentation
NonSwag Jun 12, 2024
8455047
added missing settings
NonSwag Jun 12, 2024
68db083
append action instead of ignoring
NonSwag Jun 12, 2024
cd8d6c2
dont pass optional as parameter
NonSwag Jun 12, 2024
e39c773
change Vector3 to BlockVector3
NonSwag Jun 12, 2024
fd3d77f
removed unused code
NonSwag Jun 12, 2024
e9e949e
utilize stream api
NonSwag Jun 12, 2024
453380e
add missing condition
NonSwag Jun 12, 2024
2f4f9e5
directly pass surface mode
NonSwag Jun 12, 2024
7331020
added documentation
NonSwag Jun 12, 2024
c4ad179
revert back to isSolid checks
NonSwag Jun 12, 2024
6dc5dc0
adapt surface mode changes
NonSwag Jun 12, 2024
4e98600
spotlessApply
NonSwag Jun 12, 2024
4bc9758
added more docs
NonSwag Jun 12, 2024
53014b7
merge methods
NonSwag Jun 12, 2024
8d51569
fixed fracture brush to reflect original behaviour
NonSwag Jun 12, 2024
fb02a5c
dont replace and strip
NonSwag Jun 12, 2024
9683f81
use substring instead of replace
NonSwag Jun 12, 2024
69a25c7
contains not equal
NonSwag Jun 12, 2024
c66307f
remove disabled blocks as isSolid covers them all
NonSwag Jun 12, 2024
b140d96
drop negligible check
NonSwag Jun 12, 2024
82140f6
renamed method for clarity
NonSwag Jun 12, 2024
6d8cba4
removed stupid try catch and renamed variables and parameters for cla…
NonSwag Jun 12, 2024
5da996e
replace ampersand with paragraph
NonSwag Jun 12, 2024
51b0d96
move parse method to exported player brush class
NonSwag Jun 12, 2024
d661ebf
re-added line break
NonSwag Jun 12, 2024
4e1a1a2
move parse method to exported player brush class
NonSwag Jun 12, 2024
9d90b8d
started fixing gradient brush
NonSwag Jun 12, 2024
a9dbe94
fix import
NonSwag Jun 12, 2024
b31d584
added constructor to shorten duplicated code
NonSwag Jun 12, 2024
e16f7d1
just to satisfy sonar
NonSwag Jun 12, 2024
7544a37
added nullability information
NonSwag Jun 12, 2024
6599fd9
renamed parameter name for clarity
NonSwag Jun 12, 2024
0cb1d8f
added more docs
NonSwag Jun 12, 2024
55f33fe
added more nullability information
NonSwag Jun 12, 2024
6294692
recovered original functionality
NonSwag Jun 12, 2024
12a67a4
fixed file not found
NonSwag Jun 12, 2024
b0f3bab
added default brush item setting
NonSwag Jun 12, 2024
1960162
inverted condition
NonSwag Jun 12, 2024
864bd24
added permission constants
NonSwag Jun 12, 2024
d92552d
Replace enum equals with equals operator
TheMeinerLP Jun 12, 2024
5a695fa
Improve readability for world bypass permission
TheMeinerLP Jun 12, 2024
65880e1
pass player brush manager directly
NonSwag Jun 13, 2024
1d6e72b
re-added removed code
NonSwag Jun 14, 2024
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
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ dependencies {
// Utils
implementation(libs.serverlib)
implementation(libs.paperlib)
// Material Utils
implementation(libs.xseries) { isTransitive = false }
// Stats
implementation(libs.bstats)
// Commands
Expand Down Expand Up @@ -105,7 +103,6 @@ paper {
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER.txt"))
targetExclude("**/XMaterial.java")
target("**/*.java")
}
}
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[versions]
minecraft = "1.20.6-R0.1-SNAPSHOT"
intellectualsites = "1.27"
xseries = "9.4.0"
bstats = "3.0.2"
cloud-minecraft = "2.0.0-beta.8"
cloud-annotations = "2.0.0-rc.2"
Expand All @@ -12,7 +11,6 @@ fawe-bom = { group = "com.intellectualsites.bom", name = "bom-newest", version.r
fawe-bukkit = { group = "com.fastasyncworldedit", name = "FastAsyncWorldEdit-Bukkit" }
serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib" }
paperlib = { group = "io.papermc", name = "paperlib" }
xseries = { group = "com.github.cryptomorin", name = "XSeries", version.ref = "xseries" }
bstats = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
cloud-annotations = { group = "org.incendo", name = "cloud-annotations", version.ref = "cloud-annotations" }
cloud-minecraft-extras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloud-minecraft" }
Expand Down
104 changes: 44 additions & 60 deletions src/main/java/net/onelitefeather/bettergopaint/BetterGoPaint.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
package net.onelitefeather.bettergopaint;

import com.fastasyncworldedit.core.Fawe;
import io.papermc.lib.PaperLib;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.onelitefeather.bettergopaint.brush.PlayerBrushManager;
import net.onelitefeather.bettergopaint.command.GoPaintCommand;
import net.onelitefeather.bettergopaint.command.ReloadCommand;
import net.onelitefeather.bettergopaint.listeners.ConnectListener;
import net.onelitefeather.bettergopaint.listeners.InteractListener;
import net.onelitefeather.bettergopaint.listeners.InventoryListener;
import net.onelitefeather.bettergopaint.objects.other.Settings;
import net.onelitefeather.bettergopaint.objects.player.PlayerBrushManager;
import net.onelitefeather.bettergopaint.utils.Constants;
import net.onelitefeather.bettergopaint.utils.DisabledBlocks;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
Expand All @@ -42,70 +40,71 @@
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.LegacyPaperCommandManager;
import org.incendo.serverlib.ServerLib;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Objects;
import java.util.logging.Level;


public class BetterGoPaint extends JavaPlugin implements Listener {

public static boolean plotSquaredEnabled;
private static PlayerBrushManager manager;
private static BetterGoPaint betterGoPaint;
public static final @NotNull String PAPER_DOCS = "https://jd.papermc.io/paper/1.20.6/org/bukkit/Material.html#enum-constant-summary";

public static BetterGoPaint getGoPaintPlugin() {
return betterGoPaint;
}
public static final @NotNull String USE_PERMISSION = "bettergopaint.use";
public static final @NotNull String ADMIN_PERMISSION = "bettergopaint.admin";
public static final @NotNull String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
public static final @NotNull String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";

public static PlayerBrushManager getBrushManager() {
return manager;
}
private final @NotNull PlayerBrushManager brushManager = new PlayerBrushManager();
private final @NotNull Metrics metrics = new Metrics(this, 18734);

public static boolean isPlotSquaredEnabled() {
return plotSquaredEnabled;
}

public void reload() {
BetterGoPaint.getGoPaintPlugin().reloadConfig();
manager = new PlayerBrushManager();
Settings.settings().reload(new File(getDataFolder(), "config.yml"));
@Override
public void onLoad() {
metrics.addCustomChart(new SimplePie(
"faweVersion",
() -> Objects.requireNonNull(Fawe.instance().getVersion()).toString()
));
}

@Override
public void onEnable() {
// Check if we are in a safe environment
ServerLib.checkUnsafeForks();
PaperLib.suggestPaper(this);

// disable if goPaint and BetterGoPaint are installed simultaneously
if (hasOriginalGoPaint()) {
this.getServer().getPluginManager().disablePlugin(this);
getComponentLogger().error("BetterGoPaint is a replacement for goPaint. Please use one instead of both");
getComponentLogger().error("This plugin is now disabling to prevent future errors");
getServer().getPluginManager().disablePlugin(this);
return;
}

reloadConfig();

Material brush = Settings.settings().GENERIC.DEFAULT_BRUSH;
if (!brush.isItem()) {
getComponentLogger().error("{} is not a valid default brush, it has to be an item", brush.name());
getComponentLogger().error("For more information visit {}", PAPER_DOCS);
getServer().getPluginManager().disablePlugin(this);
}

//noinspection UnnecessaryUnicodeEscape
getComponentLogger().info(MiniMessage.miniMessage().deserialize(
"<white>Made with <red>\u2665</red> <white>in <gradient:black:red:gold>Germany</gradient>"
));

betterGoPaint = this;
if (!Files.exists(getDataFolder().toPath())) {
try {
Files.createDirectories(getDataFolder().toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Settings.settings().reload(new File(getDataFolder(), "config.yml"));
enableBStats();

manager = new PlayerBrushManager();

registerListeners();
registerCommands();
DisabledBlocks.addBlocks();
}

@Override
public void onDisable() {
metrics.shutdown();
}

public void reloadConfig() {
Settings.settings().reload(this, new File(getDataFolder(), "config.yml"));
}

@SuppressWarnings("UnstableApiUsage")
Expand All @@ -121,23 +120,13 @@ private void registerCommands() {

private void registerListeners() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new ConnectListener(this), this);
pm.registerEvents(new InventoryListener(getBrushManager()), this);
pm.registerEvents(new InteractListener(this), this);
pm.registerEvents(new InventoryListener(this), this);
pm.registerEvents(new ConnectListener(getBrushManager()), this);
}

private boolean hasOriginalGoPaint() {
if (getServer().getPluginManager().getPlugin("goPaint") == this) {
return false;
}
getComponentLogger().error(MiniMessage.miniMessage().deserialize(
"<red>BetterGoPaint is a replacement for goPaint. Please use one instead of both"
));
getComponentLogger().error(MiniMessage.miniMessage().deserialize(
"<red>This plugin is now disabling to prevent future errors"
));

return true;
return getServer().getPluginManager().getPlugin("goPaint") != this;
}

private @Nullable AnnotationParser<CommandSender> enableCommandSystem() {
Expand All @@ -158,13 +147,8 @@ private boolean hasOriginalGoPaint() {
}
}

private void enableBStats() {
Metrics metrics = new Metrics(this, Constants.BSTATS_ID);

metrics.addCustomChart(new SimplePie(
"faweVersion",
() -> Fawe.instance().getVersion().toString()
));
public @NotNull PlayerBrushManager getBrushManager() {
return brushManager;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* 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.onelitefeather.bettergopaint.brush;

import net.onelitefeather.bettergopaint.objects.brush.Brush;
import net.onelitefeather.bettergopaint.objects.other.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;

/**
* The BrushSettings interface defines the configuration settings for a brush. It provides methods to retrieve information
* about the brush's axis, brush type, list of blocks, mask material, enabled status, surface mode, angle-height
* 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();

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

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

/**
* 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();

/**
* Checks if the mask is enabled.
*
* @return true if the mask is enabled, false otherwise.
*/
boolean maskEnabled();

/**
* Returns the surface mode used by the brush settings.
*
* @return The surface mode used by the brush settings.
*/
SurfaceMode surfaceMode();

/**
* Returns the angle-height difference used by the brush settings.
*
* @return The angle-height difference used by the brush settings.
*/
double angleHeightDifference();

/**
* Returns the angle distance used by the brush settings.
*
* @return The angle distance used by the brush settings.
*/
int angleDistance();

/**
* Returns the chance of the brush being applied to a block.
*
* @return The chance of the brush being applied to a block.
*/
int chance();

/**
* Returns the falloff strength used by the brush settings.
*
* @return The falloff strength used by the brush settings.
*/
int falloffStrength();

/**
* Returns the fracture distance used by the brush settings.
*
* @return The fracture distance used by the brush settings.
*/
int fractureDistance();

/**
* Returns the mixing strength used by the brush settings.
*
* @return The mixing strength used by the brush settings.
*/
int mixingStrength();

/**
* Returns the size of the brush settings.
*
* @return The size of the brush settings.
*/
int size();

/**
* Returns the thickness used by the brush settings.
*
* @return The thickness used by the brush settings.
*/
int thickness();

/**
* Picks a random block material from {@link #blocks()}.
*
* @return The randomly picked block material.
*/
@NotNull
Material randomBlock();

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

}
Loading
Loading