Skip to content

Commit

Permalink
Add explicit exception and documentation for when types are valid (#16)
Browse files Browse the repository at this point in the history
References #15
  • Loading branch information
tajobe authored Feb 16, 2020
1 parent 8fdb047 commit 4901dbf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased]
### Changed
- Updated README for clarity around types and styles valid for a specific configuration

### Fixed
- Add explicit exception when healthbar `type` is invalid for a specific bar configuration

## [0.1.3] - 2020-02-11
### Changed
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Simple, easy-to-use healthbar plugin with optional player and mob healthbars

```yaml
player-bar:
type: SCOREBOARD
style: ABSOLUTE
type: SCOREBOARD # healthbar type (AKA location, can be SCOREBOARD or ACTION)
style: ABSOLUTE # style of healthbar (ABSOLUTE, PERCENT, or BAR)

mob-bar:
type: NAME # healthbar type (AKA location, can be SCOREBOARD, NAME, or ACTION)
Expand All @@ -23,12 +23,12 @@ mob-bar:
### Available `type`s

- `SCOREBOARD` - Below-name healthbar using the scoreboard API
- `NAME` - Updates entity's custom name to include health
- `ACTION` - Uses a player's action bar to display recently-damaged entity's health
- `SCOREBOARD` - Below-name healthbar using the scoreboard API (valid for: `player-bar`)
- `NAME` - Updates entity's custom name to include health (valid for: `mob-bar`)
- `ACTION` - Uses a player's action bar to display recently-damaged entity's health (valid for: `player-bar`, `mob-bar`)

### Available `style`s

- `ABSOLUTE` - Health is displayed as actual health value (hearts)
- `PERCENT` - Health is displayed as a percentage of max health
- `BAR` - Health is displayed as a portion of a bar, configured by `length` and `char` properties
- `BAR` - Health is displayed as a portion of a bar, configured by `length` and `char` properties (not valid for `SCOREBOARD` type bar)
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ class SimpleHealthbars2 : JavaPlugin() {

listener = DamageListener(
this,
config.getConfigurationSection("player-bar")?.let { loadBar(it) } as PlayerHealthbar?,
config.getConfigurationSection("mob-bar")?.let { loadBar(it) } as MobHealthbar?
config.getConfigurationSection("player-bar")?.let {
loadBar(it)?.let { bar ->
checkNotNull(bar as? PlayerHealthbar) { "Invalid player healthbar type! Must be one of: SCOREBOARD, ACTION" }
}
},
config.getConfigurationSection("mob-bar")?.let {
loadBar(it)?.let { bar ->
checkNotNull(bar as? MobHealthbar) { "Invalid mob healthbar type! Must be one of: NAME, ACTION" }
}
}
)

server.pluginManager.registerEvents(
Expand Down
15 changes: 7 additions & 8 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

player-bar:
type: SCOREBOARD
style: ABSOLUTE
type: SCOREBOARD # healthbar type (AKA location, can be SCOREBOARD or ACTION)
style: ABSOLUTE # style of healthbar (ABSOLUTE, PERCENT, or BAR)

mob-bar:
type: NAME
style: BAR
length: 20
char: 0x25ae
showMobNames: true
type: NAME # healthbar type (AKA location, can be NAME or ACTION)
style: BAR # style of healthbar (ABSOLUTE, PERCENT, or BAR)
length: 20 # length of the bar (number of characters)
char: 0x25ae # character to use for the bar
showMobNames: true # if the mob's name should show alongside the healthbar (for NAME or ACTION type)

0 comments on commit 4901dbf

Please sign in to comment.