Skip to content

Commit

Permalink
✨ Added config
Browse files Browse the repository at this point in the history
  • Loading branch information
szpolny committed Oct 29, 2020
1 parent bc184ed commit d2e4f01
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HealthBar ![v1.1](https://img.shields.io/badge/version-1.1-brightgreen)
# HealthBar ![v1.2](https://img.shields.io/badge/version-1.2-brightgreen)
HealthBar is Spigot plugin which shows the health of the player under his nickname
## Download
You can find the download in the [releases page](https://github.com/sellectuwa/HealthBar/releases).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.sellect</groupId>
<artifactId>HealthBar</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>

<name>HealthBar</name>
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/me/sellect/healthbar/ConfigLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.sellect.healthbar;

import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;

import java.io.File;

public class ConfigLoader {
private final Plugin plugin;

public ConfigLoader(Plugin plugin){
this.plugin = plugin;
}

public void configSetup(){
File configFile = new File("plugins/HealthBar/config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
plugin.getConfig().options().header("HealthBar\n" +
"How to format text: https://pastebin.com/raw/4kjcQGrh");
plugin.getConfig().addDefault("suffix", "&c❤");
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
}
}
14 changes: 13 additions & 1 deletion src/main/java/me/sellect/healthbar/HealthBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

import java.util.Objects;

public final class HealthBar extends JavaPlugin {

private Scoreboard scoreboard;
Expand All @@ -24,6 +26,9 @@ public void onEnable() {
// Metrics
Metrics metrics = new Metrics(this, 9217);

// Config
new ConfigLoader(this).configSetup();

scoreboard = getServer().getScoreboardManager().getMainScoreboard();
registerHealthBar();
}
Expand All @@ -33,7 +38,14 @@ public void registerHealthBar() {
scoreboard.getObjective("health").unregister();
}
Objective objective = scoreboard.registerNewObjective("health", "health");
objective.setDisplayName(ChatColor.RED + "❤");

String suffix = ChatColor.RED + "❤";

if(getConfig().getString("suffix") != null) {
suffix = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(getConfig().getString("suffix")));
}

objective.setDisplayName(suffix);
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
}
}

0 comments on commit d2e4f01

Please sign in to comment.