Skip to content
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
21 changes: 11 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io.papermc.hangarpublishplugin.model.Platforms
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
import net.minecrell.pluginyml.paper.PaperPluginDescription
import xyz.jpenilla.runpaper.task.RunServer
import kotlin.system.exitProcess

Expand All @@ -13,7 +14,7 @@ plugins {
alias(libs.plugins.minotaur)
alias(libs.plugins.shadow)
alias(libs.plugins.hangar.publish.plugin)
alias(libs.plugins.plugin.yml.bukkit)
alias(libs.plugins.plugin.yml.paper)
alias(libs.plugins.run.paper)
}

Expand Down Expand Up @@ -68,22 +69,22 @@ dependencies {
annotationProcessor(libs.cloud.annotations)
}

bukkit {
paper {
name = "BetterGoPaint"
main = "net.onelitefeather.bettergopaint.BetterGoPaint"
authors = listOf("Arcaniax", "TheMeinerLP")
apiVersion = "1.13"
depend = listOf("FastAsyncWorldEdit")
website = "https://github.com/OneLiteFeatherNET/BetterGoPaint"
softDepend = listOf("goPaint")
apiVersion = "1.20"

commands {
register("gopaint") {
description = "goPaint command"
aliases = listOf("gp")
serverDependencies {
register("FastAsyncWorldEdit") {
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
required = true
}
}

website = "https://github.com/OneLiteFeatherNET/BetterGoPaint"
provides = listOf("goPaint")

permissions {
register("bettergopaint.command.admin.reload") {
default = BukkitPluginDescription.Permission.Default.OP
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ spotless = { id = "com.diffplug.spotless", version = "6.18.0" }
minotaur = { id = "com.modrinth.minotaur", version = "2.+" }
shadow = { id = "io.github.goooler.shadow", version = "8.1.7" }
hangar-publish-plugin = { id = "io.papermc.hangar-publish-plugin", version = "0.1.2" }
plugin-yml-bukkit = { id = "net.minecrell.plugin-yml.bukkit", version = "0.5.3" }
plugin-yml-paper = { id = "net.minecrell.plugin-yml.paper", version = "0.6.0" }
run-paper = { id = "xyz.jpenilla.run-paper", version = "2.1.0" }
100 changes: 41 additions & 59 deletions src/main/java/net/onelitefeather/bettergopaint/BetterGoPaint.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.fastasyncworldedit.core.Fawe;
import io.papermc.lib.PaperLib;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.onelitefeather.bettergopaint.command.Handler;
import net.onelitefeather.bettergopaint.command.GoPaintCommand;
import net.onelitefeather.bettergopaint.command.ReloadCommand;
import net.onelitefeather.bettergopaint.listeners.ConnectListener;
import net.onelitefeather.bettergopaint.listeners.InteractListener;
Expand All @@ -32,6 +32,7 @@
import net.onelitefeather.bettergopaint.utils.DisabledBlocks;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
Expand All @@ -41,6 +42,7 @@
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.LegacyPaperCommandManager;
import org.incendo.serverlib.ServerLib;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand All @@ -53,11 +55,6 @@ public class BetterGoPaint extends JavaPlugin implements Listener {
public static boolean plotSquaredEnabled;
private static PlayerBrushManager manager;
private static BetterGoPaint betterGoPaint;
public ConnectListener connectListener;
public InteractListener interactListener;
public InventoryListener inventoryListener;
public Handler cmdHandler;
private AnnotationParser<CommandSender> annotationParser;

public static BetterGoPaint getGoPaintPlugin() {
return betterGoPaint;
Expand All @@ -80,32 +77,18 @@ public void reload() {
public void onEnable() {
// Check if we are in a safe environment
ServerLib.checkUnsafeForks();
ServerLib.isJavaSixteen();
PaperLib.suggestPaper(this);

if (PaperLib.getMinecraftVersion() < 16) {
getSLF4JLogger().error("We support only Minecraft 1.16.5 upwards");
getSLF4JLogger().error("Disabling plugin to prevent errors");
this.getServer().getPluginManager().disablePlugin(this);
return;
}
if (PaperLib.getMinecraftVersion() == 16 && PaperLib.getMinecraftPatchVersion() < 5) {
getSLF4JLogger().error("We support only Minecraft 1.16.5 upwards");
getSLF4JLogger().error("Disabling plugin to prevent errors");
// disable if goPaint and BetterGoPaint are installed simultaneously
if (hasOriginalGoPaint()) {
this.getServer().getPluginManager().disablePlugin(this);
return;
}

if (PaperLib.getMinecraftVersion() > 17) {
getComponentLogger().info(MiniMessage
.miniMessage()
.deserialize("<white>Made with <red>\u2665</red> <white>in <gradient:black:red:gold>Germany</gradient>"));
} else {
getLogger().info("Made with \u2665 in Germany");
}
if (checkIfGoPaintActive()) {
return;
}
//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())) {
Expand All @@ -117,48 +100,47 @@ public void onEnable() {
}
Settings.settings().reload(new File(getDataFolder(), "config.yml"));
enableBStats();
enableCommandSystem();
if (this.annotationParser != null) {
annotationParser.parse(new ReloadCommand(this));
}


manager = new PlayerBrushManager();

connectListener = new ConnectListener(betterGoPaint);
interactListener = new InteractListener(betterGoPaint);
inventoryListener = new InventoryListener(betterGoPaint);
cmdHandler = new Handler(betterGoPaint);
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(connectListener, this);
pm.registerEvents(interactListener, this);
pm.registerEvents(inventoryListener, this);
pm.registerEvents(cmdHandler, this);
getCommand("gopaint").setExecutor(cmdHandler);
registerListeners();
registerCommands();
DisabledBlocks.addBlocks();
}

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

var annotationParser = enableCommandSystem();
if (annotationParser != null) {
annotationParser.parse(new ReloadCommand(this));
annotationParser.parse(new GoPaintCommand(this));
}
}

private boolean checkIfGoPaintActive() {
if (getServer().getPluginManager().isPluginEnabled("goPaint")) {
if (PaperLib.getMinecraftVersion() > 17) {
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"));
} else {
getSLF4JLogger().error("BetterGoPaint is a replacement for goPaint. Please use one instead of both");
getSLF4JLogger().error("This plugin is now disabling to prevent future errors");
}
this.getServer().getPluginManager().disablePlugin(this);
return true;
private void registerListeners() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new ConnectListener(this), this);
pm.registerEvents(new InteractListener(this), this);
pm.registerEvents(new InventoryListener(this), this);
}

private boolean hasOriginalGoPaint() {
if (getServer().getPluginManager().getPlugin("goPaint") == this) {
return false;
}
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;
}

private void enableCommandSystem() {
private @Nullable AnnotationParser<CommandSender> enableCommandSystem() {
try {
LegacyPaperCommandManager<CommandSender> commandManager = LegacyPaperCommandManager.createNative(
this,
Expand All @@ -168,12 +150,12 @@ private void enableCommandSystem() {
commandManager.registerBrigadier();
getLogger().info("Brigadier support enabled");
}
this.annotationParser = new AnnotationParser<>(commandManager, CommandSender.class);
return new AnnotationParser<>(commandManager, CommandSender.class);

} catch (Exception e) {
getLogger().log(Level.SEVERE, "Cannot init command manager");
return null;
}

}

private void enableBStats() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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.command;

import net.kyori.adventure.text.minimessage.MiniMessage;
import net.onelitefeather.bettergopaint.BetterGoPaint;
import net.onelitefeather.bettergopaint.objects.other.Settings;
import net.onelitefeather.bettergopaint.objects.player.PlayerBrush;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class GoPaintCommand extends Command implements PluginIdentifiableCommand {

public static BetterGoPaint plugin;

public GoPaintCommand(BetterGoPaint main) {
super("gopaint", "goPaint command", "/gp size|toggle|info|reload", List.of("gp"));
plugin = main;
}

@Override
public boolean execute(
@NotNull final CommandSender sender,
@NotNull final String commandLabel,
final @NotNull String[] args
) {
if (!(sender instanceof final Player p)) {
return false;
}
PlayerBrush pb = BetterGoPaint.getBrushManager().getPlayerBrush(p);
String prefix = Settings.settings().GENERIC.PREFIX;
if (!p.hasPermission("bettergopaint.use")) {
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>You are lacking the permission bettergopaint" +
".use"));
return true;
}
if (args.length == 0) {
if (p.hasPermission("bettergopaint.admin")) {
p.sendMessage(MiniMessage
.miniMessage()
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload"));
return true;
}
p.sendMessage(MiniMessage
.miniMessage()
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>"));
return true;
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("size")) {
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gp size [number]"));
return true;
} else if (args[0].equalsIgnoreCase("toggle")) {
if (pb.isEnabled()) {
pb.toggleEnabled();
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>Disabled brush"));
} else {
pb.toggleEnabled();
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<green>Enabled brush"));
}
return true;
} else if ((args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("r")) && p.hasPermission(
"bettergopaint.admin")) {
plugin.reload();
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<green>Reloaded"));
return true;
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("i")) {
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<aqua>Created by: <gold>TheMeinerLP"));
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<aqua>Links: <gold><click:open_url:https" +
"://twitter.com/themeinerlp'><u>Twitter</u></click>"));
return true;
}
if (p.hasPermission("bettergopaint.admin")) {
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray" +
">|<red>info" +
"<gray>" +
"|<red>reload"));
return true;
}
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info"));
return true;
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("size") || args[0].equalsIgnoreCase("s")) {
try {
int sizeAmount = Integer.parseInt(args[1]);
pb.setBrushSize(sizeAmount);
p.sendMessage(MiniMessage
.miniMessage()
.deserialize(prefix + "<gold>Size set to: <yellow>" + pb.getBrushSize()));
return true;
} catch (Exception e) {
p.sendMessage(MiniMessage.miniMessage().deserialize(prefix + "<red>/gb size [number]"));
return true;
}
}
if (p.hasPermission("bettergopaint.admin")) {
p.sendMessage(MiniMessage
.miniMessage()
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload"));
return true;
}
p.sendMessage(MiniMessage
.miniMessage()
.deserialize(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>"));
return true;
}
return false;
}

@Override
public @NotNull Plugin getPlugin() {
return plugin;
}

}
Loading