Skip to content

Commit

Permalink
Some testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ale32bit committed Dec 17, 2024
1 parent 83acabc commit 6e65ef4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
8 changes: 0 additions & 8 deletions src/main/java/me/alexdevs/solstice/api/module/ModCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ public ModCommand(T module) {
this.module = module;
}

public static <T extends ModuleBase> ModCommand<T> init(Class<? extends ModCommand<T>> commandClass, T module) {
try {
return commandClass.getDeclaredConstructor(module.getClass()).newInstance(module);
} catch (Exception e) {
throw new RuntimeException("Failed to initialize ModCommand: " + commandClass.getSimpleName(), e);
}
}

public void register() {
this.register(dispatcher, commandRegistry, environment);
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/me/alexdevs/solstice/api/module/ModuleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import me.alexdevs.solstice.Solstice;

import java.util.Collection;

public abstract class ModuleBase {
public final String id;
protected final String id;

public ModuleBase(String id) {
this.id = id;
}

public abstract Collection<? extends ModCommand<?>> getCommands();

public String getId() {
return id;
}

public String getPermissionNode() {
return Solstice.MOD_ID + "." + id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import me.alexdevs.solstice.modules.admin.commands.*;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;

public class AdminModule extends ModuleBase {
public class AdminModule {
public static final String ID = "admin";
public AdminModule() {
super(ID);
//super(ID);

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
new BroadcastCommand(this);
new DoAsCommand(dispatcher, registryAccess, environment);
new ExtinguishCommand(dispatcher, registryAccess, environment);
new FeedCommand(dispatcher, registryAccess, environment);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.alexdevs.solstice.modules.broadcast;

import me.alexdevs.solstice.api.module.ModCommand;
import me.alexdevs.solstice.api.module.ModuleBase;
import me.alexdevs.solstice.modules.broadcast.commands.BroadcastCommand;

import java.util.Collection;
import java.util.List;

public class BroadcastModule extends ModuleBase {
private final Collection<? extends ModCommand<BroadcastModule>> commands;

public BroadcastModule() {
super("broadcast");

commands = List.of(new BroadcastCommand(this));
}

@Override
public Collection<? extends ModCommand<?>> getCommands() {
return commands;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package me.alexdevs.solstice.modules.admin.commands;
package me.alexdevs.solstice.modules.broadcast.commands;

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import eu.pb4.placeholders.api.PlaceholderContext;
import me.alexdevs.solstice.Solstice;
import me.alexdevs.solstice.api.module.ModCommand;
import me.alexdevs.solstice.modules.admin.AdminModule;
import me.alexdevs.solstice.modules.broadcast.BroadcastModule;
import me.alexdevs.solstice.util.Format;
import com.mojang.brigadier.arguments.StringArgumentType;
import eu.pb4.placeholders.api.PlaceholderContext;
import net.minecraft.server.command.ServerCommandSource;

import java.util.List;

import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;

public class BroadcastCommand extends ModCommand<AdminModule> {
public class BroadcastCommand extends ModCommand<BroadcastModule> {

public BroadcastCommand(AdminModule module) {
public BroadcastCommand(BroadcastModule module) {
super(module);
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/me/alexdevs/solstice/modules/sudo/SudoModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.alexdevs.solstice.modules.sudo;

import me.alexdevs.solstice.api.module.ModCommand;
import me.alexdevs.solstice.api.module.ModuleBase;

import java.util.Collection;
import java.util.List;

public class SudoModule extends ModuleBase {
public SudoModule(String id) {
super("sudo");
}

@Override
public Collection<? extends ModCommand<?>> getCommands() {
return List.of();
}
}

0 comments on commit 6e65ef4

Please sign in to comment.