Skip to content

Commit

Permalink
GH-38 Add give and take options (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrdzn committed May 29, 2022
1 parent b5e02df commit 19855ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public class PluginConfig {

public boolean takeHealthFromVictim;
public boolean giveHealthToKiller;
public int defaultHealth;
public int healthChange;
public Entry<Integer, Integer> healthRange;
Expand All @@ -31,6 +33,10 @@ public void parseAndLoad(ConfigurationSection section) throws InvalidConfigurati
throw new InvalidConfigurationException("Configuration section cannot be null.");
}

this.takeHealthFromVictim = section.getBoolean("takeHealthFromVictim");

this.giveHealthToKiller = section.getBoolean("giveHealthToKiller");

int defaultHealth = section.getInt("defaultHealth");
if (defaultHealth < 1) {
throw new InvalidConfigurationException("Property 'defaultHealth' cannot be lower than 1.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void changePlayerHearts(PlayerDeathEvent event) {

int healthChange = this.config.healthChange;

if (this.config.killByPlayerOnly) {
if (this.config.giveHealthToKiller && this.config.killByPlayerOnly) {
if (killer == null) {
return;
}
Expand All @@ -81,7 +81,7 @@ public void changePlayerHearts(PlayerDeathEvent event) {
double victimMaxHealth = this.adapter.getMaxHealth(victim);

double victimNewHealth = victimMaxHealth - healthChange;
if (victimNewHealth >= healthRange.getKey()) {
if (this.config.takeHealthFromVictim && victimNewHealth >= healthRange.getKey()) {
this.adapter.setMaxHealth(victim, victimNewHealth);
}

Expand Down
6 changes: 6 additions & 0 deletions plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# A section for the plugin operation.
# 1 heart = 2 health points.
baseSettings:
# If health points should be decreased from a player who is killed.
takeHealthFromVictim: true

# If health points should be increased for a player who killed somebody.
giveHealthToKiller: true

# Amount of maximum health points that will be given to the new player that did not play before.
defaultHealth: 20

Expand Down

0 comments on commit 19855ab

Please sign in to comment.