Skip to content

Commit a786a55

Browse files
committed
fix getURL function (loophole fixed)
1 parent 7aa397f commit a786a55

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

src/main/java/me/isoham/imageframe/mde/config/MessageConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public enum Message {
5151
URL_NOT_WHITELISTED(
5252
"messages.moderation.not_whitelisted",
5353
"&cYour url type isn't whitelisted. Use a discord url."
54+
),
55+
56+
INVALID_USAGE(
57+
"messages.request.invalid_usage",
58+
"&cInvalid Usage"
5459
);
5560

5661
public final String path;

src/main/java/me/isoham/imageframe/mde/listeners/CommandInterceptor.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
5555
return;
5656
}
5757

58-
String url = getUrl(args);
58+
String url = getURL(args);
5959
if (url == null) {
60+
event.setCancelled(true);
61+
player.sendMessage(config.getMessages().get(MessageConfig.Message.INVALID_USAGE));
6062
return;
6163
}
6264

@@ -137,35 +139,32 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
137139
}
138140
}
139141

140-
private static @Nullable String getUrl(String[] args) {
141-
String sub = args[1].toLowerCase();
142+
// Gets the url and also validates command partially
143+
private static @Nullable String getURL(String[] args) {
144+
if (args.length < 4) {
145+
return null;
146+
}
142147

143-
String url = null;
148+
String sub = args[1].toLowerCase();
144149

145-
switch (sub) {
150+
return switch (sub) {
146151
case "create" -> {
147-
if (args.length == 6 || args.length == 7) {
148-
url = args[3];
149-
} else if (args.length == 5 && args[4].equalsIgnoreCase("selection")) {
150-
url = args[3];
152+
// /imageframe create <name> <url> selection
153+
if (args.length == 5 && args[4].equalsIgnoreCase("selection")) {
154+
yield args[3];
151155
}
152-
}
153156

154-
case "overlay" -> {
155-
if (args.length == 4) {
156-
url = args[3];
157-
} else if (args.length == 5 && args[4].equalsIgnoreCase("selection")) {
158-
url = args[3];
157+
// /imageframe create <name> <url> <width> <height> [options]
158+
if (args.length >= 6) {
159+
yield args[3];
159160
}
160-
}
161161

162-
case "refresh" -> {
163-
if (args.length >= 4) {
164-
url = args[3];
165-
}
162+
yield null;
166163
}
167-
}
168-
return url;
164+
165+
case "overlay", "refresh" -> args[3];
166+
default -> null;
167+
};
169168
}
170169

171170
private String hash(String input) {

0 commit comments

Comments
 (0)