Skip to content

Commit

Permalink
Refactored code for JaCoCo coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 15, 2024
1 parent 8c1aa30 commit cb4d7e2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions demo/src/main/groovy/it/angrybear/yagl/YAGL.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,21 @@ class YAGL extends JavaPlugin {
* Unloads all the commands loaded in {@link #commands}.
*/
void unloadCommands() {
commandMap().ifPresent { map ->
commandMap().ifPresent(map -> {
Map<String, Command> commands = new Refl<>(map).getFieldObject('knownCommands')
if (commands == null) getLogger().warning('Could not find \'knownCommands\' field in CommandMap')
else commands.keySet().collect().each { key ->
Command value = commands.get(key)
if (this.commands.contains(value)) commands.remove(key, value)
}
}
})
}

private static Optional<CommandMap> commandMap() {
def pluginManager = Bukkit.getPluginManager()
if (pluginManager == null) Optional.empty()
else {
def refl = new Refl<>(pluginManager)
Optional.ofNullable(refl.getFieldObject('commandMap'))
}
// Terrible line, but necessary for JaCoCo coverage report to 100%
pluginManager == null ? Optional.empty() : Optional.ofNullable((CommandMap) new Refl<>(pluginManager)
.getFieldObject('commandMap'))
}

/**
Expand Down

0 comments on commit cb4d7e2

Please sign in to comment.