Skip to content

Commit 42c7f7d

Browse files
authored
Merge pull request #16 from NonSwag/paper-plugin-migration
Paper plugin migration
2 parents 0687cf7 + ede916b commit 42c7f7d

File tree

5 files changed

+189
-186
lines changed

5 files changed

+189
-186
lines changed

build.gradle.kts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io.papermc.hangarpublishplugin.model.Platforms
22
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
3+
import net.minecrell.pluginyml.paper.PaperPluginDescription
34
import xyz.jpenilla.runpaper.task.RunServer
45
import kotlin.system.exitProcess
56

@@ -13,7 +14,7 @@ plugins {
1314
alias(libs.plugins.minotaur)
1415
alias(libs.plugins.shadow)
1516
alias(libs.plugins.hangar.publish.plugin)
16-
alias(libs.plugins.plugin.yml.bukkit)
17+
alias(libs.plugins.plugin.yml.paper)
1718
alias(libs.plugins.run.paper)
1819
}
1920

@@ -68,22 +69,22 @@ dependencies {
6869
annotationProcessor(libs.cloud.annotations)
6970
}
7071

71-
bukkit {
72+
paper {
7273
name = "BetterGoPaint"
7374
main = "net.onelitefeather.bettergopaint.BetterGoPaint"
7475
authors = listOf("Arcaniax", "TheMeinerLP")
75-
apiVersion = "1.13"
76-
depend = listOf("FastAsyncWorldEdit")
77-
website = "https://github.com/OneLiteFeatherNET/BetterGoPaint"
78-
softDepend = listOf("goPaint")
76+
apiVersion = "1.20"
7977

80-
commands {
81-
register("gopaint") {
82-
description = "goPaint command"
83-
aliases = listOf("gp")
78+
serverDependencies {
79+
register("FastAsyncWorldEdit") {
80+
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
81+
required = true
8482
}
8583
}
8684

85+
website = "https://github.com/OneLiteFeatherNET/BetterGoPaint"
86+
provides = listOf("goPaint")
87+
8788
permissions {
8889
register("bettergopaint.command.admin.reload") {
8990
default = BukkitPluginDescription.Permission.Default.OP

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ spotless = { id = "com.diffplug.spotless", version = "6.18.0" }
2323
minotaur = { id = "com.modrinth.minotaur", version = "2.+" }
2424
shadow = { id = "io.github.goooler.shadow", version = "8.1.7" }
2525
hangar-publish-plugin = { id = "io.papermc.hangar-publish-plugin", version = "0.1.2" }
26-
plugin-yml-bukkit = { id = "net.minecrell.plugin-yml.bukkit", version = "0.5.3" }
26+
plugin-yml-paper = { id = "net.minecrell.plugin-yml.paper", version = "0.6.0" }
2727
run-paper = { id = "xyz.jpenilla.run-paper", version = "2.1.0" }

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

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.fastasyncworldedit.core.Fawe;
2222
import io.papermc.lib.PaperLib;
2323
import net.kyori.adventure.text.minimessage.MiniMessage;
24-
import net.onelitefeather.bettergopaint.command.Handler;
24+
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;
@@ -32,6 +32,7 @@
3232
import net.onelitefeather.bettergopaint.utils.DisabledBlocks;
3333
import org.bstats.bukkit.Metrics;
3434
import org.bstats.charts.SimplePie;
35+
import org.bukkit.Bukkit;
3536
import org.bukkit.command.CommandSender;
3637
import org.bukkit.event.Listener;
3738
import org.bukkit.plugin.PluginManager;
@@ -41,6 +42,7 @@
4142
import org.incendo.cloud.execution.ExecutionCoordinator;
4243
import org.incendo.cloud.paper.LegacyPaperCommandManager;
4344
import org.incendo.serverlib.ServerLib;
45+
import org.jetbrains.annotations.Nullable;
4446

4547
import java.io.File;
4648
import java.io.IOException;
@@ -53,11 +55,6 @@ public class BetterGoPaint extends JavaPlugin implements Listener {
5355
public static boolean plotSquaredEnabled;
5456
private static PlayerBrushManager manager;
5557
private static BetterGoPaint betterGoPaint;
56-
public ConnectListener connectListener;
57-
public InteractListener interactListener;
58-
public InventoryListener inventoryListener;
59-
public Handler cmdHandler;
60-
private AnnotationParser<CommandSender> annotationParser;
6158

6259
public static BetterGoPaint getGoPaintPlugin() {
6360
return betterGoPaint;
@@ -80,32 +77,18 @@ public void reload() {
8077
public void onEnable() {
8178
// Check if we are in a safe environment
8279
ServerLib.checkUnsafeForks();
83-
ServerLib.isJavaSixteen();
8480
PaperLib.suggestPaper(this);
8581

86-
if (PaperLib.getMinecraftVersion() < 16) {
87-
getSLF4JLogger().error("We support only Minecraft 1.16.5 upwards");
88-
getSLF4JLogger().error("Disabling plugin to prevent errors");
89-
this.getServer().getPluginManager().disablePlugin(this);
90-
return;
91-
}
92-
if (PaperLib.getMinecraftVersion() == 16 && PaperLib.getMinecraftPatchVersion() < 5) {
93-
getSLF4JLogger().error("We support only Minecraft 1.16.5 upwards");
94-
getSLF4JLogger().error("Disabling plugin to prevent errors");
82+
// disable if goPaint and BetterGoPaint are installed simultaneously
83+
if (hasOriginalGoPaint()) {
9584
this.getServer().getPluginManager().disablePlugin(this);
9685
return;
9786
}
9887

99-
if (PaperLib.getMinecraftVersion() > 17) {
100-
getComponentLogger().info(MiniMessage
101-
.miniMessage()
102-
.deserialize("<white>Made with <red>\u2665</red> <white>in <gradient:black:red:gold>Germany</gradient>"));
103-
} else {
104-
getLogger().info("Made with \u2665 in Germany");
105-
}
106-
if (checkIfGoPaintActive()) {
107-
return;
108-
}
88+
//noinspection UnnecessaryUnicodeEscape
89+
getComponentLogger().info(MiniMessage.miniMessage().deserialize(
90+
"<white>Made with <red>\u2665</red> <white>in <gradient:black:red:gold>Germany</gradient>"
91+
));
10992

11093
betterGoPaint = this;
11194
if (!Files.exists(getDataFolder().toPath())) {
@@ -117,48 +100,47 @@ public void onEnable() {
117100
}
118101
Settings.settings().reload(new File(getDataFolder(), "config.yml"));
119102
enableBStats();
120-
enableCommandSystem();
121-
if (this.annotationParser != null) {
122-
annotationParser.parse(new ReloadCommand(this));
123-
}
124-
125103

126104
manager = new PlayerBrushManager();
127105

128-
connectListener = new ConnectListener(betterGoPaint);
129-
interactListener = new InteractListener(betterGoPaint);
130-
inventoryListener = new InventoryListener(betterGoPaint);
131-
cmdHandler = new Handler(betterGoPaint);
132-
PluginManager pm = getServer().getPluginManager();
133-
pm.registerEvents(connectListener, this);
134-
pm.registerEvents(interactListener, this);
135-
pm.registerEvents(inventoryListener, this);
136-
pm.registerEvents(cmdHandler, this);
137-
getCommand("gopaint").setExecutor(cmdHandler);
106+
registerListeners();
107+
registerCommands();
138108
DisabledBlocks.addBlocks();
109+
}
139110

111+
@SuppressWarnings("UnstableApiUsage")
112+
private void registerCommands() {
113+
Bukkit.getCommandMap().register("gopaint", getPluginMeta().getName(), new GoPaintCommand(this));
140114

115+
var annotationParser = enableCommandSystem();
116+
if (annotationParser != null) {
117+
annotationParser.parse(new ReloadCommand(this));
118+
annotationParser.parse(new GoPaintCommand(this));
119+
}
141120
}
142121

143-
private boolean checkIfGoPaintActive() {
144-
if (getServer().getPluginManager().isPluginEnabled("goPaint")) {
145-
if (PaperLib.getMinecraftVersion() > 17) {
146-
getComponentLogger().error(MiniMessage.miniMessage().deserialize("<red>BetterGoPaint is a replacement for goPaint. " +
147-
"Please use one instead of both"));
148-
getComponentLogger().error(MiniMessage.miniMessage().deserialize("<red>This plugin is now disabling to prevent " +
149-
"future " +
150-
"errors"));
151-
} else {
152-
getSLF4JLogger().error("BetterGoPaint is a replacement for goPaint. Please use one instead of both");
153-
getSLF4JLogger().error("This plugin is now disabling to prevent future errors");
154-
}
155-
this.getServer().getPluginManager().disablePlugin(this);
156-
return true;
122+
private void registerListeners() {
123+
PluginManager pm = getServer().getPluginManager();
124+
pm.registerEvents(new ConnectListener(this), this);
125+
pm.registerEvents(new InteractListener(this), this);
126+
pm.registerEvents(new InventoryListener(this), this);
127+
}
128+
129+
private boolean hasOriginalGoPaint() {
130+
if (getServer().getPluginManager().getPlugin("goPaint") == this) {
131+
return false;
157132
}
158-
return false;
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;
159141
}
160142

161-
private void enableCommandSystem() {
143+
private @Nullable AnnotationParser<CommandSender> enableCommandSystem() {
162144
try {
163145
LegacyPaperCommandManager<CommandSender> commandManager = LegacyPaperCommandManager.createNative(
164146
this,
@@ -168,12 +150,12 @@ private void enableCommandSystem() {
168150
commandManager.registerBrigadier();
169151
getLogger().info("Brigadier support enabled");
170152
}
171-
this.annotationParser = new AnnotationParser<>(commandManager, CommandSender.class);
153+
return new AnnotationParser<>(commandManager, CommandSender.class);
172154

173155
} catch (Exception e) {
174156
getLogger().log(Level.SEVERE, "Cannot init command manager");
157+
return null;
175158
}
176-
177159
}
178160

179161
private void enableBStats() {
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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.command;
20+
21+
import net.kyori.adventure.text.minimessage.MiniMessage;
22+
import net.onelitefeather.bettergopaint.BetterGoPaint;
23+
import net.onelitefeather.bettergopaint.objects.other.Settings;
24+
import net.onelitefeather.bettergopaint.objects.player.PlayerBrush;
25+
import org.bukkit.command.Command;
26+
import org.bukkit.command.CommandSender;
27+
import org.bukkit.command.PluginIdentifiableCommand;
28+
import org.bukkit.entity.Player;
29+
import org.bukkit.plugin.Plugin;
30+
import org.jetbrains.annotations.NotNull;
31+
32+
import java.util.List;
33+
34+
public class GoPaintCommand extends Command implements PluginIdentifiableCommand {
35+
36+
public static BetterGoPaint plugin;
37+
38+
public GoPaintCommand(BetterGoPaint main) {
39+
super("gopaint", "goPaint command", "/gp size|toggle|info|reload", List.of("gp"));
40+
plugin = main;
41+
}
42+
43+
@Override
44+
public boolean execute(
45+
@NotNull final CommandSender sender,
46+
@NotNull final String commandLabel,
47+
final @NotNull String[] args
48+
) {
49+
if (!(sender instanceof final Player p)) {
50+
return false;
51+
}
52+
PlayerBrush pb = BetterGoPaint.getBrushManager().getPlayerBrush(p);
53+
String prefix = Settings.settings().GENERIC.PREFIX;
54+
if (!p.hasPermission("bettergopaint.use")) {
55+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>You are lacking the permission bettergopaint" +
56+
".use"));
57+
return true;
58+
}
59+
if (args.length == 0) {
60+
if (p.hasPermission("bettergopaint.admin")) {
61+
p.sendMessage(MiniMessage
62+
.miniMessage()
63+
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload"));
64+
return true;
65+
}
66+
p.sendMessage(MiniMessage
67+
.miniMessage()
68+
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>"));
69+
return true;
70+
} else if (args.length == 1) {
71+
if (args[0].equalsIgnoreCase("size")) {
72+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gp size [number]"));
73+
return true;
74+
} else if (args[0].equalsIgnoreCase("toggle")) {
75+
if (pb.isEnabled()) {
76+
pb.toggleEnabled();
77+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>Disabled brush"));
78+
} else {
79+
pb.toggleEnabled();
80+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<green>Enabled brush"));
81+
}
82+
return true;
83+
} else if ((args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("r")) && p.hasPermission(
84+
"bettergopaint.admin")) {
85+
plugin.reload();
86+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<green>Reloaded"));
87+
return true;
88+
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("i")) {
89+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<aqua>Created by: <gold>TheMeinerLP"));
90+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<aqua>Links: <gold><click:open_url:https" +
91+
"://twitter.com/themeinerlp'><u>Twitter</u></click>"));
92+
return true;
93+
}
94+
if (p.hasPermission("bettergopaint.admin")) {
95+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray" +
96+
">|<red>info" +
97+
"<gray>" +
98+
"|<red>reload"));
99+
return true;
100+
}
101+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info"));
102+
return true;
103+
} else if (args.length == 2) {
104+
if (args[0].equalsIgnoreCase("size") || args[0].equalsIgnoreCase("s")) {
105+
try {
106+
int sizeAmount = Integer.parseInt(args[1]);
107+
pb.setBrushSize(sizeAmount);
108+
p.sendMessage(MiniMessage
109+
.miniMessage()
110+
.deserialize(prefix + "<gold>Size set to: <yellow>" + pb.getBrushSize()));
111+
return true;
112+
} catch (Exception e) {
113+
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gb size [number]"));
114+
return true;
115+
}
116+
}
117+
if (p.hasPermission("bettergopaint.admin")) {
118+
p.sendMessage(MiniMessage
119+
.miniMessage()
120+
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload"));
121+
return true;
122+
}
123+
p.sendMessage(MiniMessage
124+
.miniMessage()
125+
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>"));
126+
return true;
127+
}
128+
return false;
129+
}
130+
131+
@Override
132+
public @NotNull Plugin getPlugin() {
133+
return plugin;
134+
}
135+
136+
}

0 commit comments

Comments
 (0)