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

Command cleanup #82

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@

# Gradle
.gradle/
run/
31 changes: 24 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ plugins {
id("com.gradleup.shadow") version "8.3.5"
id("io.papermc.hangar-publish-plugin") version "0.1.2"
id("com.modrinth.minotaur") version "2.8.7"
id("xyz.jpenilla.run-paper") version "2.3.1"
}

group = "com.dre.brewery"
version = "3.4.7"
version = "3.4.7-SNAPSHOT"
val langVersion: Int = 17
val encoding: String = "UTF-8"

Expand All @@ -58,6 +59,7 @@ repositories {
maven("https://repo.oraxen.com/releases") // Oraxen
maven("https://storehouse.okaeri.eu/repository/maven-public/") // Okaeri Config
maven("https://papermc.io/repo/repository/maven-public/") // PaperLib
maven("https://repo.panda-lang.org/releases") // LiteCommands
}

dependencies {
Expand All @@ -74,18 +76,20 @@ dependencies {
// For proper scheduling between Bukkit-Folia like servers, https://github.com/Anon8281/UniversalScheduler
implementation("com.github.Anon8281:UniversalScheduler:0.1.3-dev")
// Nice annotations, I prefer these to Lombok's, https://www.jetbrains.com/help/idea/annotating-source-code.html
implementation("org.jetbrains:annotations:16.0.2")
implementation("org.jetbrains:annotations:26.0.1")
// MongoDB & log4j to suppress MongoDB's logger
implementation("org.mongodb:mongodb-driver-sync:5.3.0-beta0")
compileOnly("org.apache.logging.log4j:log4j-core:2.23.1")
compileOnly("org.apache.logging.log4j:log4j-core:2.24.3")
// Lombok
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
// Okaeri configuration
compileOnly("org.projectlombok:lombok:1.18.36")
annotationProcessor("org.projectlombok:lombok:1.18.36")
// LiteCommands
implementation("dev.rollczi:litecommands-bukkit:3.9.6")
// Okaeri configuration
implementation("eu.okaeri:okaeri-configs-yaml-snakeyaml:5.0.5") {
exclude("org.yaml", "snakeyaml")
}
constraints {
constraints {
implementation("org.yaml:snakeyaml") {
version {
require("2.3")
Expand Down Expand Up @@ -133,6 +137,7 @@ tasks {
}
withType<JavaCompile>().configureEach {
options.encoding = encoding
options.compilerArgs.add("-parameters") // required by LiteCommands, see https://docs.rollczi.dev/documentation/litecommands/getting-started/dependencies.html#parameters-compile-flag
}
test {
useJUnitPlatform()
Expand All @@ -156,6 +161,7 @@ tasks {
relocate("com.mongodb", "$pack.mongodb")
relocate("org.bson", "$pack.bson")
relocate("io.papermc.lib", "$pack.paperlib")
relocate("dev.rollczi.litecommands", "$pack.litecommands")

archiveClassifier.set("")
}
Expand All @@ -178,6 +184,17 @@ tasks {
}
}

runServer {
minecraftVersion("1.21.4")
}

}

tasks.withType(xyz.jpenilla.runtask.task.AbstractRun::class) {
javaLauncher = javaToolchains.launcherFor {
vendor = JvmVendorSpec.ADOPTIUM
languageVersion = JavaLanguageVersion.of(21)
}
}

java {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 1 addition & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
rootProject.name = "BreweryX"

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
}
25 changes: 5 additions & 20 deletions src/main/java/com/dre/brewery/BreweryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandMap;
import org.bukkit.command.PluginCommand;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -84,6 +81,7 @@ public final class BreweryPlugin extends JavaPlugin {


private final Map<String, Function<ItemLoader, Ingredient>> ingredientLoaders = new HashMap<>(); // Registrations
private CommandManager commandManager;
private BreweryStats breweryStats; // Metrics

{
Expand Down Expand Up @@ -122,6 +120,8 @@ public void onEnable() {
TranslationManager.getInstance().updateTranslationFiles();
ConfigManager.newInstance(Lang.class, false);

this.commandManager = new CommandManager();

BSealer.registerRecipe(); // Sealing table recipe
ConfigManager.registerDefaultPluginItems(); // Register plugin items

Expand Down Expand Up @@ -179,23 +179,6 @@ public void onEnable() {
this.breweryStats.setupBStats();
new BreweryXStats().setupBStats();

// Register command and aliases
PluginCommand defaultCommand = getCommand("breweryx");
defaultCommand.setExecutor(new CommandManager());
try {
// This has to be done reflectively because Spigot doesn't expose the CommandMap through the API
Field bukkitCommandMap = getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);

CommandMap commandMap = (CommandMap) bukkitCommandMap.get(getServer());

for (String alias : config.getCommandAliases()) {
commandMap.register(alias, "breweryx", defaultCommand);
}
} catch (Exception e) {
Logging.errorLog("Failed to register command aliases!", e);
}

// Register Listeners
getServer().getPluginManager().registerEvents(new BlockListener(), this);
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
Expand Down Expand Up @@ -242,6 +225,8 @@ public void onEnable() {
public void onDisable() {
if (addonManager != null) addonManager.unloadAddons();

this.commandManager.disable();

// Disable listeners
HandlerList.unregisterAll(this);

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/dre/brewery/api/addons/AddonCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@

package com.dre.brewery.api.addons;

import com.dre.brewery.commands.SubCommand;

/**
* Interface for a command that is part of an addon. Really just a SubCommand, but with a different name/package.
*
* @see BreweryAddon#registerCommand(String, AddonCommand)
* @see BreweryAddon#unregisterCommand(String)
*/
public interface AddonCommand extends SubCommand {
public interface AddonCommand { // TODO
}
7 changes: 3 additions & 4 deletions src/main/java/com/dre/brewery/api/addons/BreweryAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.dre.brewery.api.addons;

import com.dre.brewery.BreweryPlugin;
import com.dre.brewery.commands.CommandManager;
import com.dre.brewery.storage.DataManager;
import com.dre.brewery.utility.MinecraftVersion;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
Expand Down Expand Up @@ -185,7 +184,7 @@ public void unregisterListener(Listener listener) {
* @param command The command to register
*/
public void registerCommand(String name, AddonCommand command) {
CommandManager.addSubCommand(name, command);
// CommandManager.addSubCommand(name, command); // TODO
commands.add(name);
}

Expand All @@ -195,7 +194,7 @@ public void registerCommand(String name, AddonCommand command) {
* @param name The name of the command
*/
public void unregisterCommand(String name) {
CommandManager.removeSubCommand(name);
// CommandManager.removeSubCommand(name); // TODO
commands.remove(name);
}

Expand All @@ -214,7 +213,7 @@ public void unregisterListeners() {
*/
public void unregisterCommands() {
for (String command : commands) {
CommandManager.removeSubCommand(command);
// CommandManager.removeSubCommand(command); // TODO
}
commands.clear();
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/dre/brewery/commands/BreweryCommandEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* BreweryX Bukkit-Plugin for an alternate brewing process
* Copyright (C) 2024-2025 The Brewery Team
*
* This file is part of BreweryX.
*
* BreweryX 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.
*
* BreweryX 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 BreweryX. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.dre.brewery.commands;

import com.dre.brewery.configuration.ConfigManager;
import com.dre.brewery.configuration.files.Config;
import dev.rollczi.litecommands.command.builder.CommandBuilder;
import dev.rollczi.litecommands.editor.Editor;
import org.bukkit.command.CommandSender;

/**
* LiteCommands Editor that puts commands under "/breweryx" route, as well as aliases specified in the config
*
* @see com.dre.brewery.commands.annotation.BreweryCommand
* @see CommandManager#CommandManager()
*/
class BreweryCommandEditor implements Editor<CommandSender> {
@Override
public CommandBuilder<CommandSender> edit(CommandBuilder<CommandSender> context) {
Config config = ConfigManager.getConfig(Config.class);

return context
.routeName("breweryx " + context.name())
.routeAliases(
config.getCommandAliases().stream()
.map(alias -> alias + " " + context.name())
.toList()
);
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/dre/brewery/commands/BreweryCommandScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* BreweryX Bukkit-Plugin for an alternate brewing process
* Copyright (C) 2024-2025 The Brewery Team
*
* This file is part of BreweryX.
*
* BreweryX 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.
*
* BreweryX 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 BreweryX. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.dre.brewery.commands;

import com.dre.brewery.commands.annotation.BreweryCommand;
import dev.rollczi.litecommands.meta.Meta;
import dev.rollczi.litecommands.scope.Scope;
import dev.rollczi.litecommands.scope.Scopeable;

/**
* LiteCommands Scope resolving commands annotated with {@link BreweryCommand}
*
* @see BreweryCommandEditor
* @see CommandManager
*/
class BreweryCommandScope implements Scope {
@Override
public boolean isApplicable(Scopeable scopeable) {
return scopeable.meta().get(Meta.COMMAND_ORIGIN_TYPE).stream()
.anyMatch(clazz -> clazz.isAnnotationPresent(BreweryCommand.class));
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/dre/brewery/commands/CommandBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* BreweryX Bukkit-Plugin for an alternate brewing process
* Copyright (C) 2024-2025 The Brewery Team
*
* This file is part of BreweryX.
*
* BreweryX 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.
*
* BreweryX 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 BreweryX. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.dre.brewery.commands;

import com.dre.brewery.configuration.files.Lang;

/**
* A class that all BreweryX command should extend, used for easier access
*/
public abstract class CommandBase {
protected final CommandManager commandManager;
protected final Lang lang;

public CommandBase(CommandManager commandManager) {
this.commandManager = commandManager;
this.lang = commandManager.getLang();
}
}
Loading
Loading