Skip to content

Commit 2e2cf3e

Browse files
authored
Merge pull request #64 from CyR1en/development
Version 2.14.0
2 parents d4761a8 + a8a450a commit 2e2cf3e

20 files changed

+267
-113
lines changed

build.gradle

Lines changed: 9 additions & 6 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: 13, patch: 0, fix: 0, classifier: 'SNAPSHOT'),
42+
version : new Version(major: 2, minor: 14, patch: 0, fix: 0, classifier: 'SNAPSHOT'),
4343
author : 'CyR1en',
4444
description: 'Making Commands More Interactive!',
4545
entry : 'com.cyr1en.commandprompter.CommandPrompter'
@@ -66,20 +66,23 @@ repositories {
6666
dependencies {
6767
implementation 'com.cyr1en:kiso-utils:1.8-SNAPSHOT'
6868
implementation 'com.cyr1en:kiso-mc:1.8-SNAPSHOT'
69-
implementation 'net.wesjd:anvilgui:1.10.5-SNAPSHOT'
7069
implementation 'org.bstats:bstats-bukkit:3.0.2'
7170
implementation group: 'org.fusesource.jansi', name: 'jansi', version: '2.4.0'
72-
implementation 'com.github.stefvanschie.inventoryframework:IF:0.11.0'
7371
implementation "net.kyori:adventure-text-minimessage:4.21.0"
74-
implementation "dev.jorel:commandapi-bukkit-shade:10.0.1"
75-
implementation 'de.rapha149.signgui:signgui:2.5.1'
7672
implementation 'org.openjdk.nashorn:nashorn-core:15.4'
7773

74+
implementation "dev.jorel:commandapi-bukkit-shade:10.1.1"
75+
76+
// UI libs
77+
implementation 'net.wesjd:anvilgui:1.10.6-SNAPSHOT'
78+
implementation 'com.github.stefvanschie.inventoryframework:IF:0.11.2'
79+
implementation 'de.rapha149.signgui:signgui:2.5.2'
80+
7881
compileOnly "net.kyori:adventure-text-serializer-legacy:4.21.0"
7982
compileOnly "net.kyori:adventure-text-serializer-plain:4.21.0"
8083
compileOnly 'me.clip:placeholderapi:2.11.6'
8184
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.3.0'
82-
compileOnly "org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT"
85+
compileOnly "org.spigotmc:spigot-api:1.21.6-R0.1-SNAPSHOT"
8386
compileOnly 'com.github.LeonMangler:SuperVanish:6.2.18-3'
8487
compileOnly 'de.hexaoxi:carbonchat-api:3.0.0-beta.26'
8588
compileOnly 'com.github.mbax:VanishNoPacket:3.22'

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.cyr1en.commandprompter;
22

3+
import com.cyr1en.commandprompter.util.FormatUtil;
34
import org.bukkit.Bukkit;
45
import org.fusesource.jansi.Ansi;
56

67
import java.awt.*;
78
import java.util.Objects;
8-
import java.util.UnknownFormatConversionException;
99
import java.util.logging.Level;
1010

1111
public class PluginLogger {
@@ -24,7 +24,7 @@ public PluginLogger(CommandPrompter plugin, String prefix) {
2424
this.debugMode = plugin.getConfiguration().debugMode();
2525

2626
// Spread love not war <3
27-
normalGrad = new ColorGradient(new Color(1, 88, 181), new Color(246, 206, 0));
27+
normalGrad = new ColorGradient(new Color(101, 78, 163), new Color(234, 175, 200));
2828

2929
debugGrad = new ColorGradient(new Color(255, 96, 109), new Color(255, 195, 113));
3030

@@ -50,11 +50,7 @@ private String makeGradient(String prefix, ColorGradient grad) {
5050

5151
public void log(String prefix, Level level, String msg, Object... args) {
5252
String pre = prefix == null ? getPrefix() : prefix;
53-
try {
54-
if (msg.matches("%s"))
55-
msg = String.format(msg, args);
56-
} catch (UnknownFormatConversionException ignore) {
57-
}
53+
msg = FormatUtil.safeFormat(msg, args);
5854
Bukkit.getLogger().log(level, pre + msg);
5955
}
6056

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void run() {
8585
* @param perms Permissions to set to the PermissionAttachment
8686
*/
8787
public static void dispatchWithAttachment(Plugin plugin, Player sender, String command, int ticks,
88-
@NotNull String[] perms) {
88+
@NotNull String[] perms) {
8989
var commandPrompter = (CommandPrompter) plugin;
9090
var logger = commandPrompter.getPluginLogger();
9191

@@ -108,4 +108,40 @@ public static void dispatchWithAttachment(Plugin plugin, Player sender, String c
108108
sender.removeAttachment(attachment);
109109
}
110110

111+
/**
112+
* A helper enum to determine to easily determine which dispatcher to use. This will be used to override
113+
* the context of a CommandExecutor.
114+
*
115+
* <p>
116+
* PASSTHROUGH is a default type that indicates that we are not overriding the execution context.
117+
*/
118+
public enum Type {
119+
PLAYER("p"),
120+
CONSOLE("c"),
121+
PASSTHROUGH;
122+
123+
private String key;
124+
125+
Type() {
126+
this.key = "";
127+
}
128+
129+
Type(String key) {
130+
this.key = key;
131+
}
132+
133+
/**
134+
* Get the key for this type.
135+
*
136+
* @param typeStr the type string to parse
137+
* @return the key for this type
138+
*/
139+
public static Type parse(String typeStr) {
140+
typeStr = typeStr == null ? "" : typeStr.trim().toLowerCase();
141+
for (Type value : Type.values())
142+
if (value.key.equals(typeStr))
143+
return value;
144+
return PASSTHROUGH;
145+
}
146+
}
111147
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public CommandAPIWrapper(CommandPrompter plugin) {
2323

2424
public void load() {
2525
var config = new CommandAPIBukkitConfig(plugin);
26+
config.beLenientForMinorVersions(true);
2627
config.skipReloadDatapacks(true);
2728
config.useLatestNMSVersion(false);
2829
config = plugin.getConfiguration().debugMode() ? config.silentLogs(false).verboseOutput(true)

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private DelegateCommand(JavaPlugin plugin) {
3535

3636
public abstract void register();
3737

38-
public abstract void doCommand(Player targetPlayer, String command, CommandArguments args);
38+
public abstract void doCommand(CommandSender sender, Player targetPlayer, String command, CommandArguments args);
3939

4040
protected void exec(CommandSender sender, CommandArguments args) {
4141
logger.debug("Command Arguments: " + args.fullInput());
@@ -65,7 +65,7 @@ protected void exec(CommandSender sender, CommandArguments args) {
6565
if (delegatedCommand.contains("%target_player%"))
6666
delegatedCommand = delegatedCommand.replace("%target_player%", targetPlayer.getName());
6767

68-
doCommand(targetPlayer, delegatedCommand, args);
68+
doCommand(sender, targetPlayer, delegatedCommand, args);
6969
}
7070

7171
public static class ConsoleDelegate extends DelegateCommand {
@@ -83,9 +83,10 @@ public void register() {
8383
.register();
8484
}
8585

86-
public void doCommand(Player targetPlayer, String command, CommandArguments args) {
86+
public void doCommand(CommandSender sender, Player targetPlayer, String command, CommandArguments args) {
8787
var context = new PromptContext.Builder()
88-
.setSender(targetPlayer)
88+
.setCommandSender(targetPlayer)
89+
.setPromptedPlayer(targetPlayer)
8990
.setContent(command)
9091
.setConsoleDelegate(true)
9192
.build();
@@ -117,9 +118,10 @@ public void register() {
117118
}
118119

119120
@Override
120-
public void doCommand(Player targetPlayer, String command, CommandArguments args) {
121+
public void doCommand(CommandSender sender, Player targetPlayer, String command, CommandArguments args) {
121122
var context = new PromptContext.Builder()
122-
.setSender(targetPlayer)
123+
.setCommandSender(targetPlayer)
124+
.setPromptedPlayer(targetPlayer)
123125
.setContent(command)
124126
.setPaKey(args.getRaw("permission"))
125127
.build();

src/main/java/com/cyr1en/commandprompter/hook/hooks/CarbonChatHook.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public void handle(CarbonChatEvent event) {
6060
var ds = LegacyComponentSerializer.legacyAmpersand().serialize(event.message());
6161
serializedMsg = prompt.sanitizeInput() ? ds : serializedMsg;
6262
}
63-
var ctx = new PromptContext.Builder().setSender(player).setContent(serializedMsg).build();
63+
var ctx = new PromptContext.Builder()
64+
.setCommandSender(player)
65+
.setPromptedPlayer(player)
66+
.setContent(serializedMsg).build();
6467
Bukkit.getScheduler().runTask(getPlugin(), () -> promptManager.processPrompt(ctx));
6568
}
6669
}

src/main/java/com/cyr1en/commandprompter/listener/VanillaListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
4242
var content = event.getMessage().replaceFirst("/", "");
4343
var context = new PromptContext.Builder()
4444
.setCancellable(event)
45-
.setSender(event.getPlayer())
45+
.setCommandSender(event.getPlayer())
46+
.setPromptedPlayer(event.getPlayer())
4647
.setContent(content)
4748
.build();
4849
this.process(context);

src/main/java/com/cyr1en/commandprompter/prompt/ContextProcessor.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ protected void process(PromptContext context) {
3232
if (context.getContent().matches(Cancel.commandPattern.toString()))
3333
return;
3434

35-
if (!context.getSender().hasPermission("commandprompter.use") &&
35+
if (!context.getPromptedPlayer().hasPermission("commandprompter.use") &&
3636
plugin.getConfiguration().enablePermission()) {
37-
plugin.getMessenger().sendMessage(context.getSender(),
37+
plugin.getMessenger().sendMessage(context.getPromptedPlayer(),
3838
plugin.getI18N().getProperty("PromptNoPerm"));
3939
return;
4040
}
4141
if (shouldBlock(context)) {
42-
plugin.getMessenger().sendMessage(context.getSender(),
42+
plugin.getMessenger().sendMessage(context.getPromptedPlayer(),
4343
plugin.getI18N().getFormattedProperty("PromptInProgress",
4444
plugin.getConfiguration().cancelKeyword()));
4545
if (context.getCancellable() != null)
@@ -48,22 +48,23 @@ protected void process(PromptContext context) {
4848
}
4949

5050
if (!promptManager.getParser().isParsable(context)) return;
51-
if (!(context.getSender() instanceof Player)) {
52-
plugin.getMessenger().sendMessage(context.getSender(),
53-
plugin.getI18N().getProperty("PromptPlayerOnly"));
54-
return;
55-
}
51+
52+
// if (!(context.getPromptedPlayer() instanceof Player)) {
53+
// plugin.getMessenger().sendMessage(context.getSender(),
54+
// plugin.getI18N().getProperty("PromptPlayerOnly"));
55+
// return;
56+
// }
5657

5758
if (context.getCancellable() != null)
5859
context.getCancellable().setCancelled(true);
5960

6061
plugin.getPluginLogger().debug("Ctx Before Parse: " + context);
6162
promptManager.parse(context);
62-
promptManager.sendPrompt(context.getSender());
63+
promptManager.sendPrompt(context.getPromptedPlayer());
6364
}
6465

6566
private boolean shouldBlock(PromptContext context) {
66-
var fulfilling = promptManager.getPromptRegistry().inCommandProcess(context.getSender());
67+
var fulfilling = promptManager.getPromptRegistry().inCommandProcess(context.getPromptedPlayer());
6768
var cmd = extractCommand(context.getContent());
6869
var cmds = plugin.getConfiguration().allowedWhileInPrompt();
6970
return fulfilling && (!cmds.contains(cmd) && promptManager.getParser().isParsable(context));

src/main/java/com/cyr1en/commandprompter/prompt/PromptContext.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,42 @@
4141
*/
4242
public class PromptContext {
4343
private final Cancellable cancellable;
44-
private final CommandSender sender;
44+
private final CommandSender sender; // Command sender that initiated the prompt (usually a player or console).
45+
private final Player promptedPlayer; // Player that we're going to send the prompt to.
4546
private String content;
4647
private String promptKey;
4748
private boolean isConsoleDelegate;
4849

4950
private final String paKey;
5051

5152
public PromptContext(PlayerCommandPreprocessEvent e) {
52-
this(e, e.getPlayer(), e.getMessage(), null, null, false);
53+
this(e, e.getPlayer(), e.getPlayer(), e.getMessage(), null, null, false);
5354
}
5455

5556
public PromptContext(@Nullable Cancellable callable,
56-
Player sender,
57+
CommandSender sender,
58+
Player promptedPlayer,
5759
String content,
5860
@Nullable String promptKey,
5961
@Nullable String paKey,
6062
boolean isConsoleDelegate) {
6163
this.cancellable = callable;
6264
this.sender = sender;
65+
this.promptedPlayer = promptedPlayer;
6366
this.content = content;
6467
this.promptKey = promptKey;
6568
this.paKey = paKey;
6669
this.isConsoleDelegate = isConsoleDelegate;
6770
}
6871

69-
public CommandSender getSender() {
72+
public CommandSender getCommandSender() {
7073
return sender;
7174
}
7275

76+
public Player getPromptedPlayer() {
77+
return promptedPlayer;
78+
}
79+
7380
public Cancellable getCancellable() {
7481
return cancellable;
7582
}
@@ -118,6 +125,7 @@ public String toString() {
118125
public static class Builder {
119126
private Cancellable cancellable;
120127
private CommandSender sender;
128+
private Player promptedPlayer;
121129
private String content;
122130

123131
private String promptKey;
@@ -139,11 +147,16 @@ public Builder setCancellable(Cancellable cancellable) {
139147
return this;
140148
}
141149

142-
public Builder setSender(CommandSender sender) {
150+
public Builder setCommandSender(CommandSender sender) {
143151
this.sender = sender;
144152
return this;
145153
}
146154

155+
public Builder setPromptedPlayer(Player promptedPlayer) {
156+
this.promptedPlayer = promptedPlayer;
157+
return this;
158+
}
159+
147160
public Builder setContent(String content) {
148161
this.content = content;
149162
return this;
@@ -165,11 +178,9 @@ public Builder setPaKey(String paKey) {
165178
}
166179

167180
public PromptContext build() {
168-
// check if sender and content is null.
169181
if (sender == null || content == null)
170-
throw new IllegalStateException("Sender and content must not be null!");
171-
return new PromptContext(cancellable, (Player) sender,
172-
content, promptKey, paKey, isConsoleDelegate);
182+
throw new IllegalStateException("Must provide non-null CommandSender, Player, and String!");
183+
return new PromptContext(cancellable, sender, promptedPlayer, content, promptKey, paKey, isConsoleDelegate);
173184
}
174185
}
175186
}

0 commit comments

Comments
 (0)