Skip to content

Commit

Permalink
idk
Browse files Browse the repository at this point in the history
Signed-off-by: Mineshafter61 <[email protected]>
  • Loading branch information
Mineshafter61 committed Jun 27, 2024
1 parent a7f156b commit 530d8fe
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 18 deletions.
Binary file added .gradle/7.4.2/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added .gradle/7.4.2/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/7.4.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file added .gradle/7.4.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/7.4.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Empty file added .gradle/7.4.2/gc.properties
Empty file.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
56 changes: 38 additions & 18 deletions src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
package mikeshafter.mikestcaddons;

import cloud.commandframework.CommandTree;
import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.arguments.parser.ParserParameters;
import cloud.commandframework.arguments.parser.StandardParameters;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.paper.PaperCommandManager;
import com.bergerkiller.bukkit.common.map.MapResourcePack;
import com.bergerkiller.bukkit.tc.signactions.SignAction;
import mikeshafter.mikestcaddons.attachments.SignActionAttachment;
import mikeshafter.mikestcaddons.signactions.SignActionRHStation;
import mikeshafter.mikestcaddons.signactions.SignActionSwap;
import mikeshafter.mikestcaddons.throttle.ThrottleManager;
import mikeshafter.mikestcaddons.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Objects;
import java.util.function.Function;
import java.util.logging.Level;


public final class MikesTCAddons extends JavaPlugin {

private final SignActionSwap signActionSwap = new SignActionSwap();
private final SignActionRHStation signActionRHStation = new SignActionRHStation();
private final SignActionAttachment signActionAttachment = new SignActionAttachment();

@Override
private void registerCommands(Commands commands) {
final Function<CommandTree<CommandSender>, CommandExecutionCoordinator<CommandSender>> executionCoordinatorFunction = CommandExecutionCoordinator.simpleCoordinator();
PaperCommandManager<CommandSender> manager;
try {
manager = new PaperCommandManager<>(this, executionCoordinatorFunction, Function.identity(), Function.identity());
} catch (Exception e) {
this.getLogger().log(Level.SEVERE, "Failed to create command manager:");
this.getLogger().warning(e.getLocalizedMessage());
return;
}
//if (manager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {manager.registerBrigadier();}
parseCommandAnnotations(commands, manager);
}

private void parseCommandAnnotations(Commands commands, PaperCommandManager<CommandSender> manager) {
final Function<ParserParameters, CommandMeta> commandMetaFunction = p -> CommandMeta.simple().with(CommandMeta.DESCRIPTION, p.get(StandardParameters.DESCRIPTION, "Description not specified.")).build();
AnnotationParser<CommandSender> annotationParser = new AnnotationParser<>(manager, CommandSender.class, commandMetaFunction);
annotationParser.parse(commands);
}


@Override
public void onDisable() {
// Plugin shutdown logic
SignAction.unregister(signActionSwap);
SignAction.unregister(signActionRHStation);
SignAction.unregister(signActionAttachment);
Util.gates.forEach((gate) -> gate.closeGate(true));
this.getLogger().log(Level.INFO, "Mike's TC Addons has been disabled!");
for (Player player : Bukkit.getOnlinePlayers()) ThrottleManager.removeThrottle(player);
Expand All @@ -39,21 +70,10 @@ public void onEnable() {
MapResourcePack.SERVER.load();

SignAction.register(signActionSwap);
SignAction.register(signActionRHStation);
Commands manager = new Commands();
Objects.requireNonNull(getCommand("throttle")).setExecutor(manager);
Objects.requireNonNull(getCommand("door")).setExecutor(manager);
Objects.requireNonNull(getCommand("swap")).setExecutor(manager);
Objects.requireNonNull(getCommand("decouple")).setExecutor(manager);
Objects.requireNonNull(getCommand("opengate")).setExecutor(manager);
Objects.requireNonNull(getCommand("reload")).setExecutor(manager);
this.getServer().getPluginManager().registerEvents(new ThrottleManager(), this);
Objects.requireNonNull(getCommand("throttle")).setTabCompleter(manager);
Objects.requireNonNull(getCommand("door")).setTabCompleter(manager);
Objects.requireNonNull(getCommand("swap")).setTabCompleter(manager);
Objects.requireNonNull(getCommand("decouple")).setTabCompleter(manager);
Objects.requireNonNull(getCommand("opengate")).setTabCompleter(manager);
Objects.requireNonNull(getCommand("reload")).setTabCompleter(manager);
SignAction.register(signActionAttachment);

registerCommands(new Commands());

this.getLogger().log(Level.INFO, "Mike's TC Addons has been enabled!");
}
}

0 comments on commit 530d8fe

Please sign in to comment.