Skip to content

Commit c5d36eb

Browse files
committed
Add error checks to ensure regionshow setup/cleanup/loop shows exist, and to ensure that a region is not specified twice
GitOrigin-RevId: 7c7f78aa34bf9cc96d7e92af9457d917d62c3678
1 parent 866dade commit c5d36eb

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/us/mcparks/showscript/RegionShowListener.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,48 @@ private boolean loadRegionShow(File f, CommandSender sender, boolean alertIfIgno
123123
}
124124

125125
TimecodeShowConfig setupShow = main.timecodeExecutor.getShowConfig(yaml.isConfigurationSection("setup") ? yaml.getString("setup.name") : yaml.getString("setup"), placeholderArgs);
126+
127+
if (setupShow == null) {
128+
throw new IllegalArgumentException("Setup show `" + yaml.getString("setup.name") + "` not found");
129+
}
130+
126131
Long setupDelay = yaml.isConfigurationSection("setup") ? (yaml.contains("setup.delay") ? yaml.getLong("setup.delay") : 0) : 0;
127132
TimecodeShowConfig cleanupShow = main.timecodeExecutor.getShowConfig(yaml.getString("cleanup"), placeholderArgs);
128-
133+
134+
if (cleanupShow == null) {
135+
throw new IllegalArgumentException("Cleanup show `" + yaml.getString("cleanup.name") + "` not found");
136+
}
137+
129138
List<TimecodeShowConfig> loopShows = new ArrayList<>();
130139
List<Long> loopShowDelays = new ArrayList<>();
131140

132141
if (yaml.isString("loop")) {
133-
loopShows.add(main.timecodeExecutor.getShowConfig(yaml.getString("loop"), placeholderArgs));
142+
TimecodeShowConfig show = main.timecodeExecutor.getShowConfig(yaml.getString("loop"), placeholderArgs);
143+
if (show == null) {
144+
throw new IllegalArgumentException("Loop show `" + yaml.getString("loop.name") + "` not found");
145+
}
146+
loopShows.add(show);
134147
loopShowDelays.add(0L);
135148
} else if (yaml.isConfigurationSection("loop")) {
136-
loopShows.add(main.timecodeExecutor.getShowConfig(yaml.getString("loop.name"), placeholderArgs));
149+
TimecodeShowConfig show = main.timecodeExecutor.getShowConfig(yaml.getString("loop.name"), placeholderArgs);
150+
if (show == null) {
151+
throw new IllegalArgumentException("Loop show `" + yaml.getString("loop.name") + "` not found");
152+
}
153+
loopShows.add(show);
137154
loopShowDelays.add(yaml.contains("loop.delay") ? yaml.getLong("loop.delay") : 0);
138155
} else {
139156
for (Map<?,?> loop : yaml.getMapList("loop")) {
140-
loopShows.add(
141-
main.timecodeExecutor.getShowConfig((String) loop.get("name"), placeholderArgs));
157+
TimecodeShowConfig show = main.timecodeExecutor.getShowConfig((String) loop.get("name"), placeholderArgs);
158+
if (show == null) {
159+
throw new IllegalArgumentException("Loop show `" + loop.get("name") + "` not found");
160+
}
161+
loopShows.add(show);
142162
loopShowDelays.add(loop.containsKey("delay") ? ((Number) loop.get("delay")).longValue() : 0);
143163
}
144164
}
145165

166+
167+
146168
String filepath = f.getAbsolutePath();
147169
boolean isIgnored = yaml.contains("ignore") && yaml.getBoolean("ignore") == true;
148170

@@ -190,12 +212,18 @@ private boolean loadRegionShow(File f, CommandSender sender, boolean alertIfIgno
190212
}
191213
}
192214

215+
Set<String> loadedRegions = new HashSet<>();
216+
193217
for (String region : regions) {
194218
if (!region.toLowerCase().equals(region)) {
195219
throw new IllegalArgumentException("Region names are always lowercase, but you entered " + region);
196220
}
197-
loadRegionShow(filepath, region, setupShow, loopShows, cleanupShow, setupDelay, loopShowDelays, isIgnored, true);
221+
if (loadedRegions.contains(region)) {
222+
throw new IllegalArgumentException("Duplicate region in schema: " + region);
223+
}
198224

225+
loadRegionShow(filepath, region, setupShow, loopShows, cleanupShow, setupDelay, loopShowDelays, isIgnored, true);
226+
loadedRegions.add(region);
199227
if (!isIgnored && sender != null) sender.sendMessage("Loaded " + f.getName() + " in region " + region);
200228
}
201229
}

0 commit comments

Comments
 (0)