Skip to content

Commit

Permalink
Merge pull request #31 from CyR1en/development
Browse files Browse the repository at this point in the history
SignUI change and Command rework
  • Loading branch information
CyR1en authored Nov 30, 2023
2 parents 3828d52 + 88194f8 commit f034d58
Show file tree
Hide file tree
Showing 30 changed files with 418 additions and 474 deletions.
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ java {

PluginManifest pluginManifest = [
name : 'CommandPrompter',
version : new Version(major: 2, minor: 5, patch: 0, fix: 0, classifier: 'SNAPSHOT'),
version : new Version(major: 2, minor: 6, patch: 0, fix: 0, classifier: 'RELEASE'),
author : 'CyR1en',
description: 'Perfect companion plugin for inventory UI menu.',
entry : 'com.cyr1en.commandprompter.CommandPrompter'
Expand All @@ -64,11 +64,12 @@ dependencies {
implementation 'com.cyr1en:kiso-utils:1.8-SNAPSHOT'
implementation 'com.cyr1en:kiso-mc:1.8-SNAPSHOT'
implementation 'net.wesjd:anvilgui:1.9.0-SNAPSHOT'
implementation 'io.github.rapha149.signgui:signgui:2.2.1'
implementation 'org.bstats:bstats-bukkit:3.0.0'
implementation "dev.jorel:commandapi-bukkit-shade:9.2.0"
implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0'

// Exclude these
implementation 'me.lucko:commodore:2.2'
implementation 'me.lucko:jar-relocator:1.7'
implementation 'com.github.stefvanschie.inventoryframework:IF:0.10.11'

Expand All @@ -77,7 +78,6 @@ dependencies {
compileOnly "net.kyori:adventure-text-serializer-plain:4.13.1"
compileOnly "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT"
compileOnly 'com.github.LeonMangler:SuperVanish:6.2.17'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
compileOnly 'com.github.mbax:VanishNoPacket:3.22'
compileOnly 'org.jetbrains:annotations:23.0.0'

Expand All @@ -102,19 +102,18 @@ shadowJar {

relocate 'com.github.stefvanschie.inventoryframework', 'com.cyr1en.inventoryframework'
relocate 'net.wesjd.anvilgui', 'com.cyr1en.anvilgui'
relocate 'me.lucko.commodore', 'com.cyr1en.commodore'
relocate 'io.github.rapha149.signgui', 'com.cyr1en.signgui'
relocate 'dev.jorel.commandapi', 'com.cyr1en.commandapi'
relocate 'org.fusesource.jansi', 'com.cyr1en.jansi'
relocate 'org.bstats', 'com.cyr1en.bstats'


manifest {
attributes "Bundled": true
}
}

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar


tasks.register("lightJar", ShadowJar) {
archiveClassifier.set(pluginManifest.version.classifier)
from sourceSets.main.output
Expand All @@ -125,17 +124,18 @@ tasks.register("lightJar", ShadowJar) {
exclude(dependency('com.mojang:brigadier'))
exclude(dependency('com.github.stefvanschie.inventoryframework:IF'))
exclude(dependency('me.lucko:jar-relocator'))
exclude(dependency('me.lucko:commodore'))
exclude(dependency('me.lucko:commodore-file'))
exclude(dependency('org.ow2.asm:asm'))
exclude(dependency('org.ow2.asm:asm-commons'))
exclude(dependency('org.ow2.asm:asm-tree'))
exclude(dependency('org.ow2.asm:asm-analysis'))
exclude(dependency('io.github.rapha149.signgui:signgui'))
exclude(dependency('dev.jorel:commandapi-bukkit-shade'))
}
relocate 'com.github.stefvanschie.inventoryframework', 'com.cyr1en.inventoryframework'
relocate 'net.wesjd.anvilgui', 'com.cyr1en.anvilgui'
relocate 'me.lucko.commodore', 'com.cyr1en.commodore'
relocate 'io.github.rapha149.signgui', 'com.cyr1en.signgui'
relocate 'org.fusesource.jansi', 'com.cyr1en.jansi'
relocate 'dev.jorel.commandapi', 'com.cyr1en.commandapi'
relocate 'org.bstats', 'com.cyr1en.bstats'
}

Expand Down
49 changes: 11 additions & 38 deletions src/main/java/com/cyr1en/commandprompter/CommandPrompter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

package com.cyr1en.commandprompter;

import com.cyr1en.commandprompter.command.CommodoreRegistry;
import com.cyr1en.commandprompter.commands.Cancel;
import com.cyr1en.commandprompter.commands.ConsoleDelegate;
import com.cyr1en.commandprompter.commands.Reload;
import com.cyr1en.commandprompter.commands.CommandAPIWrapper;
import com.cyr1en.commandprompter.config.CommandPrompterConfig;
import com.cyr1en.commandprompter.config.ConfigurationManager;
import com.cyr1en.commandprompter.config.PromptConfig;
Expand All @@ -47,11 +44,10 @@
import com.cyr1en.commandprompter.util.Util.ServerType;
import com.cyr1en.kiso.mc.I18N;
import com.cyr1en.kiso.mc.UpdateChecker;
import com.cyr1en.kiso.mc.command.CommandManager;
import com.cyr1en.kiso.utils.SRegex;

import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -68,16 +64,17 @@ public class CommandPrompter extends JavaPlugin {
private HookContainer hookContainer;

private PluginLogger logger;
private CommandManager commandManager;
private CommandListener commandListener;
private I18N i18n;
private UpdateChecker updateChecker;
private PromptManager promptManager;
private PluginMessenger messenger;
private HeadCache headCache;
private CommandAPIWrapper commandAPIWrapper;

@Override
public void onEnable() {

new Metrics(this, 5359);
setupConfig();
logger = new PluginLogger(this, "CommandPrompter");
Expand All @@ -89,6 +86,11 @@ public void onEnable() {
return;

i18n = new I18N(this, "CommandPrompter");

commandAPIWrapper = new CommandAPIWrapper(this);
commandAPIWrapper.load();
commandAPIWrapper.onEnable();

messenger = new PluginMessenger(config.promptPrefix());

setupUpdater();
Expand All @@ -107,6 +109,7 @@ public void onEnable() {

@Override
public void onDisable() {
commandAPIWrapper.onDisable();
if (promptManager != null)
promptManager.clearPromptRegistry();

Expand Down Expand Up @@ -198,32 +201,7 @@ private void setupConfig() {
}

private void setupCommands() {
setupCommandManager();
commandManager.registerCommand(Reload.class);
commandManager.registerCommand(Cancel.class);
PluginCommand command = getCommand("commandprompter");
PluginCommand delegate = getCommand("consoledelegate");
delegate.setExecutor(new ConsoleDelegate(this));
Objects.requireNonNull(command).setExecutor(commandManager);
CommodoreRegistry.register(this, command);
}

private void setupCommandManager() {
var cmgBuilder = new CommandManager.Builder();
cmgBuilder.plugin(this);
cmgBuilder.setPrefix(getConfig().getString("Prompt-Prefix"));
cmgBuilder.setPlayerOnlyMessage(getI18N().getProperty("CommandPlayerOnly"));
cmgBuilder.setCommandInvalidMessage(getI18N().getProperty("CommandInvalid"));
cmgBuilder.setNoPermMessage(getI18N().getFormattedProperty("CommandNoPerm"));
cmgBuilder.setFallBack(context -> {
getCommandManager().getMessenger().sendMessage(context.getSender(),
getI18N().getFormattedProperty("PluginVersion", getDescription().getVersion()));
UpdateChecker uC = getUpdateChecker();
if (!uC.isDisabled() && uC.newVersionAvailable())
uC.sendUpdateAvailableMessage(context.getSender());
return false;
});
commandManager = cmgBuilder.build();
commandAPIWrapper.registerCommands();
}

private void setupUpdater() {
Expand All @@ -244,10 +222,6 @@ public I18N getI18N() {
return i18n;
}

public CommandManager getCommandManager() {
return commandManager;
}

public HookContainer getHookContainer() {
return this.hookContainer;
}
Expand All @@ -274,7 +248,6 @@ public void reload(boolean clean) {
messenger.setPrefix(config.promptPrefix());
logger = new PluginLogger(this, "CommandPrompter");
i18n = new I18N(this, "CommandPrompter");
commandManager.getMessenger().setPrefix(config.promptPrefix());
promptManager.getParser().initRegex();
ChatPrompt.DefaultListener.setPriority(this);
setupUpdater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void run() {
* @param command command that would be dispatched.
*/
public static void dispatchConsole(final String command) {
final String checked = command.codePointAt(0) == 0x2F ? command.replace("/", "") : command;
final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command;
new BukkitRunnable() {
public void run() {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked);
Expand Down

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/com/cyr1en/commandprompter/commands/Cancel.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.cyr1en.commandprompter.commands;

import com.cyr1en.commandprompter.CommandPrompter;
import com.cyr1en.commandprompter.util.Util;

import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig;

/**
* Wrapper for CommandAPI.
*
* <p>
* Since CommandPrompter loads CommandAPI dynamically, we need a wrapper to
* prevent
* CommandAPI imports on the main class.
*/
public class CommandAPIWrapper {

private final CommandPrompter plugin;

public CommandAPIWrapper(CommandPrompter plugin) {
this.plugin = plugin;
}

public void load() {
var config = new CommandAPIBukkitConfig(plugin);
config = plugin.getConfiguration().debugMode() ? config.silentLogs(false).verboseOutput(true)
: config.silentLogs(true).verboseOutput(false);

var msg = plugin.getI18N().getProperty("DelegateConsoleOnly");
config.missingExecutorImplementationMessage(Util.color(msg));
CommandAPI.onLoad(config);
}

public void onEnable() {
CommandAPI.onEnable();
}

public void onDisable() {
CommandAPI.onDisable();
}

public void registerCommands() {
new MainCommand(plugin).register();
new ConsoleDelegate(plugin).register();
}
}
Loading

0 comments on commit f034d58

Please sign in to comment.