Skip to content

Commit 2f048c3

Browse files
committed
Add the ability to set per-rule block messages
1 parent 288d805 commit 2f048c3

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/main/java/net/jadedmc/commandblockerpro/listeners/PlayerCommandPreprocessListener.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ public void onCommandSend(PlayerCommandPreprocessEvent event) {
7171

7272
// Otherwise, block the command.
7373
event.setCancelled(true);
74-
ChatUtils.chat(player, plugin.settingsManager().getConfig().getString("blockMessage"));
74+
if(rule.hasBlockMessage()) {
75+
ChatUtils.chat(player, rule.blockMessage());
76+
}
77+
else {
78+
ChatUtils.chat(player, plugin.settingsManager().getConfig().getString("blockMessage"));
79+
}
7580
}
7681
}
7782
}

src/main/java/net/jadedmc/commandblockerpro/rules/Rule.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class Rule {
4747
private final List<String> commands = new ArrayList<>();
4848
private final List<String> contains = new ArrayList<>();
4949
private final List<String> regex = new ArrayList<>();
50+
private final boolean hasBlockMessage;
51+
private final String blockMessage;
5052

5153
/**
5254
* Creates the rule using a configuration section.
@@ -80,6 +82,25 @@ public Rule(final ConfigurationSection config) {
8082
if(config.isSet("regex")) {
8183
regex.addAll(config.getStringList("regex"));
8284
}
85+
86+
// Look for block message.
87+
if(config.isSet("blockMessage")) {
88+
hasBlockMessage = true;
89+
blockMessage = config.getString("blockMessage");
90+
}
91+
else {
92+
hasBlockMessage = false;
93+
blockMessage = "";
94+
}
95+
}
96+
97+
/**
98+
* Get the block message of the rule.
99+
* Returns an empty String if one isn't set.
100+
* @return Block Message of the rule.
101+
*/
102+
public String blockMessage() {
103+
return blockMessage;
83104
}
84105

85106
/**
@@ -98,6 +119,14 @@ public Collection<String> commands() {
98119
return commands;
99120
}
100121

122+
/**
123+
* Get if the rule has a block message set in its config.
124+
* @return Whether the rule has a block message configured.
125+
*/
126+
public boolean hasBlockMessage() {
127+
return hasBlockMessage;
128+
}
129+
101130
/**
102131
* Determine if a rule blocks a given player from using a given command.
103132
* @param player Player trying to use the command.

0 commit comments

Comments
 (0)