Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit exception and documentation for when types are valid #16

Merged
merged 1 commit into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)