Skip to content

Commit f034d58

Browse files
authored
Merge pull request #31 from CyR1en/development
SignUI change and Command rework
2 parents 3828d52 + 88194f8 commit f034d58

30 files changed

Lines changed: 418 additions & 474 deletions

build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ java {
3939

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

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

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

@@ -102,19 +102,18 @@ shadowJar {
102102

103103
relocate 'com.github.stefvanschie.inventoryframework', 'com.cyr1en.inventoryframework'
104104
relocate 'net.wesjd.anvilgui', 'com.cyr1en.anvilgui'
105-
relocate 'me.lucko.commodore', 'com.cyr1en.commodore'
105+
relocate 'io.github.rapha149.signgui', 'com.cyr1en.signgui'
106+
relocate 'dev.jorel.commandapi', 'com.cyr1en.commandapi'
106107
relocate 'org.fusesource.jansi', 'com.cyr1en.jansi'
107108
relocate 'org.bstats', 'com.cyr1en.bstats'
108109

109-
110110
manifest {
111111
attributes "Bundled": true
112112
}
113113
}
114114

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

117-
118117
tasks.register("lightJar", ShadowJar) {
119118
archiveClassifier.set(pluginManifest.version.classifier)
120119
from sourceSets.main.output
@@ -125,17 +124,18 @@ tasks.register("lightJar", ShadowJar) {
125124
exclude(dependency('com.mojang:brigadier'))
126125
exclude(dependency('com.github.stefvanschie.inventoryframework:IF'))
127126
exclude(dependency('me.lucko:jar-relocator'))
128-
exclude(dependency('me.lucko:commodore'))
129-
exclude(dependency('me.lucko:commodore-file'))
130127
exclude(dependency('org.ow2.asm:asm'))
131128
exclude(dependency('org.ow2.asm:asm-commons'))
132129
exclude(dependency('org.ow2.asm:asm-tree'))
133130
exclude(dependency('org.ow2.asm:asm-analysis'))
131+
exclude(dependency('io.github.rapha149.signgui:signgui'))
132+
exclude(dependency('dev.jorel:commandapi-bukkit-shade'))
134133
}
135134
relocate 'com.github.stefvanschie.inventoryframework', 'com.cyr1en.inventoryframework'
136135
relocate 'net.wesjd.anvilgui', 'com.cyr1en.anvilgui'
137-
relocate 'me.lucko.commodore', 'com.cyr1en.commodore'
136+
relocate 'io.github.rapha149.signgui', 'com.cyr1en.signgui'
138137
relocate 'org.fusesource.jansi', 'com.cyr1en.jansi'
138+
relocate 'dev.jorel.commandapi', 'com.cyr1en.commandapi'
139139
relocate 'org.bstats', 'com.cyr1en.bstats'
140140
}
141141

src/main/java/com/cyr1en/commandprompter/CommandPrompter.java

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424

2525
package com.cyr1en.commandprompter;
2626

27-
import com.cyr1en.commandprompter.command.CommodoreRegistry;
28-
import com.cyr1en.commandprompter.commands.Cancel;
29-
import com.cyr1en.commandprompter.commands.ConsoleDelegate;
30-
import com.cyr1en.commandprompter.commands.Reload;
27+
import com.cyr1en.commandprompter.commands.CommandAPIWrapper;
3128
import com.cyr1en.commandprompter.config.CommandPrompterConfig;
3229
import com.cyr1en.commandprompter.config.ConfigurationManager;
3330
import com.cyr1en.commandprompter.config.PromptConfig;
@@ -47,11 +44,10 @@
4744
import com.cyr1en.commandprompter.util.Util.ServerType;
4845
import com.cyr1en.kiso.mc.I18N;
4946
import com.cyr1en.kiso.mc.UpdateChecker;
50-
import com.cyr1en.kiso.mc.command.CommandManager;
5147
import com.cyr1en.kiso.utils.SRegex;
48+
5249
import org.bstats.bukkit.Metrics;
5350
import org.bukkit.Bukkit;
54-
import org.bukkit.command.PluginCommand;
5551
import org.bukkit.entity.Player;
5652
import org.bukkit.event.HandlerList;
5753
import org.bukkit.plugin.java.JavaPlugin;
@@ -68,16 +64,17 @@ public class CommandPrompter extends JavaPlugin {
6864
private HookContainer hookContainer;
6965

7066
private PluginLogger logger;
71-
private CommandManager commandManager;
7267
private CommandListener commandListener;
7368
private I18N i18n;
7469
private UpdateChecker updateChecker;
7570
private PromptManager promptManager;
7671
private PluginMessenger messenger;
7772
private HeadCache headCache;
73+
private CommandAPIWrapper commandAPIWrapper;
7874

7975
@Override
8076
public void onEnable() {
77+
8178
new Metrics(this, 5359);
8279
setupConfig();
8380
logger = new PluginLogger(this, "CommandPrompter");
@@ -89,6 +86,11 @@ public void onEnable() {
8986
return;
9087

9188
i18n = new I18N(this, "CommandPrompter");
89+
90+
commandAPIWrapper = new CommandAPIWrapper(this);
91+
commandAPIWrapper.load();
92+
commandAPIWrapper.onEnable();
93+
9294
messenger = new PluginMessenger(config.promptPrefix());
9395

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

108110
@Override
109111
public void onDisable() {
112+
commandAPIWrapper.onDisable();
110113
if (promptManager != null)
111114
promptManager.clearPromptRegistry();
112115

@@ -198,32 +201,7 @@ private void setupConfig() {
198201
}
199202

200203
private void setupCommands() {
201-
setupCommandManager();
202-
commandManager.registerCommand(Reload.class);
203-
commandManager.registerCommand(Cancel.class);
204-
PluginCommand command = getCommand("commandprompter");
205-
PluginCommand delegate = getCommand("consoledelegate");
206-
delegate.setExecutor(new ConsoleDelegate(this));
207-
Objects.requireNonNull(command).setExecutor(commandManager);
208-
CommodoreRegistry.register(this, command);
209-
}
210-
211-
private void setupCommandManager() {
212-
var cmgBuilder = new CommandManager.Builder();
213-
cmgBuilder.plugin(this);
214-
cmgBuilder.setPrefix(getConfig().getString("Prompt-Prefix"));
215-
cmgBuilder.setPlayerOnlyMessage(getI18N().getProperty("CommandPlayerOnly"));
216-
cmgBuilder.setCommandInvalidMessage(getI18N().getProperty("CommandInvalid"));
217-
cmgBuilder.setNoPermMessage(getI18N().getFormattedProperty("CommandNoPerm"));
218-
cmgBuilder.setFallBack(context -> {
219-
getCommandManager().getMessenger().sendMessage(context.getSender(),
220-
getI18N().getFormattedProperty("PluginVersion", getDescription().getVersion()));
221-
UpdateChecker uC = getUpdateChecker();
222-
if (!uC.isDisabled() && uC.newVersionAvailable())
223-
uC.sendUpdateAvailableMessage(context.getSender());
224-
return false;
225-
});
226-
commandManager = cmgBuilder.build();
204+
commandAPIWrapper.registerCommands();
227205
}
228206

229207
private void setupUpdater() {
@@ -244,10 +222,6 @@ public I18N getI18N() {
244222
return i18n;
245223
}
246224

247-
public CommandManager getCommandManager() {
248-
return commandManager;
249-
}
250-
251225
public HookContainer getHookContainer() {
252226
return this.hookContainer;
253227
}
@@ -274,7 +248,6 @@ public void reload(boolean clean) {
274248
messenger.setPrefix(config.promptPrefix());
275249
logger = new PluginLogger(this, "CommandPrompter");
276250
i18n = new I18N(this, "CommandPrompter");
277-
commandManager.getMessenger().setPrefix(config.promptPrefix());
278251
promptManager.getParser().initRegex();
279252
ChatPrompt.DefaultListener.setPriority(this);
280253
setupUpdater();

src/main/java/com/cyr1en/commandprompter/api/Dispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void run() {
6666
* @param command command that would be dispatched.
6767
*/
6868
public static void dispatchConsole(final String command) {
69-
final String checked = command.codePointAt(0) == 0x2F ? command.replace("/", "") : command;
69+
final String checked = command.codePointAt(0) == 0x2F ? command.substring(1) : command;
7070
new BukkitRunnable() {
7171
public void run() {
7272
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), checked);

src/main/java/com/cyr1en/commandprompter/command/CommodoreRegistry.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/main/java/com/cyr1en/commandprompter/commands/Cancel.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.cyr1en.commandprompter.commands;
2+
3+
import com.cyr1en.commandprompter.CommandPrompter;
4+
import com.cyr1en.commandprompter.util.Util;
5+
6+
import dev.jorel.commandapi.CommandAPI;
7+
import dev.jorel.commandapi.CommandAPIBukkitConfig;
8+
9+
/**
10+
* Wrapper for CommandAPI.
11+
*
12+
* <p>
13+
* Since CommandPrompter loads CommandAPI dynamically, we need a wrapper to
14+
* prevent
15+
* CommandAPI imports on the main class.
16+
*/
17+
public class CommandAPIWrapper {
18+
19+
private final CommandPrompter plugin;
20+
21+
public CommandAPIWrapper(CommandPrompter plugin) {
22+
this.plugin = plugin;
23+
}
24+
25+
public void load() {
26+
var config = new CommandAPIBukkitConfig(plugin);
27+
config = plugin.getConfiguration().debugMode() ? config.silentLogs(false).verboseOutput(true)
28+
: config.silentLogs(true).verboseOutput(false);
29+
30+
var msg = plugin.getI18N().getProperty("DelegateConsoleOnly");
31+
config.missingExecutorImplementationMessage(Util.color(msg));
32+
CommandAPI.onLoad(config);
33+
}
34+
35+
public void onEnable() {
36+
CommandAPI.onEnable();
37+
}
38+
39+
public void onDisable() {
40+
CommandAPI.onDisable();
41+
}
42+
43+
public void registerCommands() {
44+
new MainCommand(plugin).register();
45+
new ConsoleDelegate(plugin).register();
46+
}
47+
}

0 commit comments

Comments
 (0)