Skip to content

Commit 9424341

Browse files
author
NonSwag
authored
Merge pull request #17 from NonSwag/code-cleanup
Code cleanup and performance improvements
2 parents b867c7d + 1d6e72b commit 9424341

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2117
-2972
lines changed

build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ dependencies {
5858
// Utils
5959
implementation(libs.serverlib)
6060
implementation(libs.paperlib)
61-
// Material Utils
62-
implementation(libs.xseries) { isTransitive = false }
6361
// Stats
6462
implementation(libs.bstats)
6563
// Commands
@@ -105,7 +103,6 @@ paper {
105103
spotless {
106104
java {
107105
licenseHeaderFile(rootProject.file("HEADER.txt"))
108-
targetExclude("**/XMaterial.java")
109106
target("**/*.java")
110107
}
111108
}

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[versions]
22
minecraft = "1.20.6-R0.1-SNAPSHOT"
33
intellectualsites = "1.27"
4-
xseries = "9.4.0"
54
bstats = "3.0.2"
65
cloud-minecraft = "2.0.0-beta.8"
76
cloud-annotations = "2.0.0-rc.2"
@@ -12,7 +11,6 @@ fawe-bom = { group = "com.intellectualsites.bom", name = "bom-newest", version.r
1211
fawe-bukkit = { group = "com.fastasyncworldedit", name = "FastAsyncWorldEdit-Bukkit" }
1312
serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib" }
1413
paperlib = { group = "io.papermc", name = "paperlib" }
15-
xseries = { group = "com.github.cryptomorin", name = "XSeries", version.ref = "xseries" }
1614
bstats = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats" }
1715
cloud-annotations = { group = "org.incendo", name = "cloud-annotations", version.ref = "cloud-annotations" }
1816
cloud-minecraft-extras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloud-minecraft" }

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

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@
1919
package net.onelitefeather.bettergopaint;
2020

2121
import com.fastasyncworldedit.core.Fawe;
22-
import io.papermc.lib.PaperLib;
2322
import net.kyori.adventure.text.minimessage.MiniMessage;
23+
import net.onelitefeather.bettergopaint.brush.PlayerBrushManager;
2424
import net.onelitefeather.bettergopaint.command.GoPaintCommand;
2525
import net.onelitefeather.bettergopaint.command.ReloadCommand;
2626
import net.onelitefeather.bettergopaint.listeners.ConnectListener;
2727
import net.onelitefeather.bettergopaint.listeners.InteractListener;
2828
import net.onelitefeather.bettergopaint.listeners.InventoryListener;
2929
import net.onelitefeather.bettergopaint.objects.other.Settings;
30-
import net.onelitefeather.bettergopaint.objects.player.PlayerBrushManager;
31-
import net.onelitefeather.bettergopaint.utils.Constants;
32-
import net.onelitefeather.bettergopaint.utils.DisabledBlocks;
3330
import org.bstats.bukkit.Metrics;
3431
import org.bstats.charts.SimplePie;
3532
import org.bukkit.Bukkit;
33+
import org.bukkit.Material;
3634
import org.bukkit.command.CommandSender;
3735
import org.bukkit.event.Listener;
3836
import org.bukkit.plugin.PluginManager;
@@ -42,70 +40,71 @@
4240
import org.incendo.cloud.execution.ExecutionCoordinator;
4341
import org.incendo.cloud.paper.LegacyPaperCommandManager;
4442
import org.incendo.serverlib.ServerLib;
43+
import org.jetbrains.annotations.NotNull;
4544
import org.jetbrains.annotations.Nullable;
4645

4746
import java.io.File;
48-
import java.io.IOException;
49-
import java.nio.file.Files;
47+
import java.util.Objects;
5048
import java.util.logging.Level;
5149

52-
5350
public class BetterGoPaint extends JavaPlugin implements Listener {
5451

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

59-
public static BetterGoPaint getGoPaintPlugin() {
60-
return betterGoPaint;
61-
}
54+
public static final @NotNull String USE_PERMISSION = "bettergopaint.use";
55+
public static final @NotNull String ADMIN_PERMISSION = "bettergopaint.admin";
56+
public static final @NotNull String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
57+
public static final @NotNull String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";
6258

63-
public static PlayerBrushManager getBrushManager() {
64-
return manager;
65-
}
59+
private final @NotNull PlayerBrushManager brushManager = new PlayerBrushManager();
60+
private final @NotNull Metrics metrics = new Metrics(this, 18734);
6661

67-
public static boolean isPlotSquaredEnabled() {
68-
return plotSquaredEnabled;
69-
}
70-
71-
public void reload() {
72-
BetterGoPaint.getGoPaintPlugin().reloadConfig();
73-
manager = new PlayerBrushManager();
74-
Settings.settings().reload(new File(getDataFolder(), "config.yml"));
62+
@Override
63+
public void onLoad() {
64+
metrics.addCustomChart(new SimplePie(
65+
"faweVersion",
66+
() -> Objects.requireNonNull(Fawe.instance().getVersion()).toString()
67+
));
7568
}
7669

70+
@Override
7771
public void onEnable() {
7872
// Check if we are in a safe environment
7973
ServerLib.checkUnsafeForks();
80-
PaperLib.suggestPaper(this);
8174

8275
// disable if goPaint and BetterGoPaint are installed simultaneously
8376
if (hasOriginalGoPaint()) {
84-
this.getServer().getPluginManager().disablePlugin(this);
77+
getComponentLogger().error("BetterGoPaint is a replacement for goPaint. Please use one instead of both");
78+
getComponentLogger().error("This plugin is now disabling to prevent future errors");
79+
getServer().getPluginManager().disablePlugin(this);
8580
return;
8681
}
8782

83+
reloadConfig();
84+
85+
Material brush = Settings.settings().GENERIC.DEFAULT_BRUSH;
86+
if (!brush.isItem()) {
87+
getComponentLogger().error("{} is not a valid default brush, it has to be an item", brush.name());
88+
getComponentLogger().error("For more information visit {}", PAPER_DOCS);
89+
getServer().getPluginManager().disablePlugin(this);
90+
}
91+
8892
//noinspection UnnecessaryUnicodeEscape
8993
getComponentLogger().info(MiniMessage.miniMessage().deserialize(
9094
"<white>Made with <red>\u2665</red> <white>in <gradient:black:red:gold>Germany</gradient>"
9195
));
9296

93-
betterGoPaint = this;
94-
if (!Files.exists(getDataFolder().toPath())) {
95-
try {
96-
Files.createDirectories(getDataFolder().toPath());
97-
} catch (IOException e) {
98-
throw new RuntimeException(e);
99-
}
100-
}
101-
Settings.settings().reload(new File(getDataFolder(), "config.yml"));
102-
enableBStats();
103-
104-
manager = new PlayerBrushManager();
105-
10697
registerListeners();
10798
registerCommands();
108-
DisabledBlocks.addBlocks();
99+
}
100+
101+
@Override
102+
public void onDisable() {
103+
metrics.shutdown();
104+
}
105+
106+
public void reloadConfig() {
107+
Settings.settings().reload(this, new File(getDataFolder(), "config.yml"));
109108
}
110109

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

122121
private void registerListeners() {
123122
PluginManager pm = getServer().getPluginManager();
124-
pm.registerEvents(new ConnectListener(this), this);
123+
pm.registerEvents(new InventoryListener(getBrushManager()), this);
125124
pm.registerEvents(new InteractListener(this), this);
126-
pm.registerEvents(new InventoryListener(this), this);
125+
pm.registerEvents(new ConnectListener(getBrushManager()), this);
127126
}
128127

129128
private boolean hasOriginalGoPaint() {
130-
if (getServer().getPluginManager().getPlugin("goPaint") == this) {
131-
return false;
132-
}
133-
getComponentLogger().error(MiniMessage.miniMessage().deserialize(
134-
"<red>BetterGoPaint is a replacement for goPaint. Please use one instead of both"
135-
));
136-
getComponentLogger().error(MiniMessage.miniMessage().deserialize(
137-
"<red>This plugin is now disabling to prevent future errors"
138-
));
139-
140-
return true;
129+
return getServer().getPluginManager().getPlugin("goPaint") != this;
141130
}
142131

143132
private @Nullable AnnotationParser<CommandSender> enableCommandSystem() {
@@ -158,13 +147,8 @@ private boolean hasOriginalGoPaint() {
158147
}
159148
}
160149

161-
private void enableBStats() {
162-
Metrics metrics = new Metrics(this, Constants.BSTATS_ID);
163-
164-
metrics.addCustomChart(new SimplePie(
165-
"faweVersion",
166-
() -> Fawe.instance().getVersion().toString()
167-
));
150+
public @NotNull PlayerBrushManager getBrushManager() {
151+
return brushManager;
168152
}
169153

170154
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* goPaint is designed to simplify painting inside of Minecraft.
3+
* Copyright (C) Arcaniax-Development
4+
* Copyright (C) Arcaniax team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package net.onelitefeather.bettergopaint.brush;
20+
21+
import net.onelitefeather.bettergopaint.objects.brush.Brush;
22+
import net.onelitefeather.bettergopaint.objects.other.SurfaceMode;
23+
import org.bukkit.Axis;
24+
import org.bukkit.Material;
25+
import org.jetbrains.annotations.ApiStatus;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
import java.util.List;
29+
import java.util.Random;
30+
31+
/**
32+
* The BrushSettings interface defines the configuration settings for a brush. It provides methods to retrieve information
33+
* about the brush's axis, brush type, list of blocks, mask material, enabled status, surface mode, angle-height
34+
* difference, angle distance, chance, falloff strength, fracture distance, mixing strength, size and thickness.
35+
*/
36+
public interface BrushSettings {
37+
38+
/**
39+
* Returns the axis used by the brush settings.
40+
*
41+
* @return the axis used by the brush settings
42+
*/
43+
@NotNull
44+
Axis axis();
45+
46+
/**
47+
* Returns the brush used by the brush settings.
48+
*
49+
* @return The brush used by the brush settings.
50+
*/
51+
@NotNull
52+
Brush brush();
53+
54+
/**
55+
* Returns the list of blocks used by the brush settings.
56+
*
57+
* @return the list of blocks used by the brush settings
58+
*/
59+
@NotNull
60+
List<Material> blocks();
61+
62+
/**
63+
* Retrieves the mask material used by the brush settings.
64+
*
65+
* @return The mask material.
66+
* @deprecated the mask-material is going to be replaced with a WorldEdit Mask
67+
*/
68+
@NotNull
69+
@Deprecated(since = "1.1.0-SNAPSHOT")
70+
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
71+
Material mask();
72+
73+
/**
74+
* Checks if the brush is enabled.
75+
*
76+
* @return true if the brush is enabled, false otherwise
77+
*/
78+
boolean enabled();
79+
80+
/**
81+
* Checks if the mask is enabled.
82+
*
83+
* @return true if the mask is enabled, false otherwise.
84+
*/
85+
boolean maskEnabled();
86+
87+
/**
88+
* Returns the surface mode used by the brush settings.
89+
*
90+
* @return The surface mode used by the brush settings.
91+
*/
92+
SurfaceMode surfaceMode();
93+
94+
/**
95+
* Returns the angle-height difference used by the brush settings.
96+
*
97+
* @return The angle-height difference used by the brush settings.
98+
*/
99+
double angleHeightDifference();
100+
101+
/**
102+
* Returns the angle distance used by the brush settings.
103+
*
104+
* @return The angle distance used by the brush settings.
105+
*/
106+
int angleDistance();
107+
108+
/**
109+
* Returns the chance of the brush being applied to a block.
110+
*
111+
* @return The chance of the brush being applied to a block.
112+
*/
113+
int chance();
114+
115+
/**
116+
* Returns the falloff strength used by the brush settings.
117+
*
118+
* @return The falloff strength used by the brush settings.
119+
*/
120+
int falloffStrength();
121+
122+
/**
123+
* Returns the fracture distance used by the brush settings.
124+
*
125+
* @return The fracture distance used by the brush settings.
126+
*/
127+
int fractureDistance();
128+
129+
/**
130+
* Returns the mixing strength used by the brush settings.
131+
*
132+
* @return The mixing strength used by the brush settings.
133+
*/
134+
int mixingStrength();
135+
136+
/**
137+
* Returns the size of the brush settings.
138+
*
139+
* @return The size of the brush settings.
140+
*/
141+
int size();
142+
143+
/**
144+
* Returns the thickness used by the brush settings.
145+
*
146+
* @return The thickness used by the brush settings.
147+
*/
148+
int thickness();
149+
150+
/**
151+
* Picks a random block material from {@link #blocks()}.
152+
*
153+
* @return The randomly picked block material.
154+
*/
155+
@NotNull
156+
Material randomBlock();
157+
158+
/**
159+
* The random number generator instance.
160+
*
161+
* @return a Random instance
162+
*/
163+
@NotNull
164+
Random random();
165+
166+
}

0 commit comments

Comments
 (0)