1919package net .onelitefeather .bettergopaint ;
2020
2121import com .fastasyncworldedit .core .Fawe ;
22- import io .papermc .lib .PaperLib ;
2322import net .kyori .adventure .text .minimessage .MiniMessage ;
23+ import net .onelitefeather .bettergopaint .brush .PlayerBrushManager ;
2424import net .onelitefeather .bettergopaint .command .GoPaintCommand ;
2525import net .onelitefeather .bettergopaint .command .ReloadCommand ;
2626import net .onelitefeather .bettergopaint .listeners .ConnectListener ;
2727import net .onelitefeather .bettergopaint .listeners .InteractListener ;
2828import net .onelitefeather .bettergopaint .listeners .InventoryListener ;
2929import 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 ;
3330import org .bstats .bukkit .Metrics ;
3431import org .bstats .charts .SimplePie ;
3532import org .bukkit .Bukkit ;
33+ import org .bukkit .Material ;
3634import org .bukkit .command .CommandSender ;
3735import org .bukkit .event .Listener ;
3836import org .bukkit .plugin .PluginManager ;
4240import org .incendo .cloud .execution .ExecutionCoordinator ;
4341import org .incendo .cloud .paper .LegacyPaperCommandManager ;
4442import org .incendo .serverlib .ServerLib ;
43+ import org .jetbrains .annotations .NotNull ;
4544import org .jetbrains .annotations .Nullable ;
4645
4746import java .io .File ;
48- import java .io .IOException ;
49- import java .nio .file .Files ;
47+ import java .util .Objects ;
5048import java .util .logging .Level ;
5149
52-
5350public 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}
0 commit comments