diff --git a/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfire.java b/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfire.java index 54e89f8..9621e12 100644 --- a/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfire.java +++ b/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfire.java @@ -6,7 +6,8 @@ public final class MagicalCampfire extends JavaPlugin { @Override public void onEnable() { - getServer().getPluginManager().registerEvents(new MagicalCampfireListener(), this); + saveDefaultConfig(); + getServer().getPluginManager().registerEvents(new MagicalCampfireListener(this), this); getLogger().info("MagicalCampfire Plugin Enabled!"); } @@ -14,5 +15,4 @@ public final class MagicalCampfire extends JavaPlugin { public void onDisable() { getLogger().info("MagicalCampfire Plugin Disabled!"); } -} - +} \ No newline at end of file diff --git a/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfireListener.java b/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfireListener.java index 50b2e66..187c047 100644 --- a/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfireListener.java +++ b/src/main/java/org/twipnetwork/magicalCampfire/MagicalCampfireListener.java @@ -3,6 +3,7 @@ package org.twipnetwork.magicalCampfire; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.type.Campfire; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.scheduler.BukkitRunnable; @@ -11,9 +12,14 @@ import org.bukkit.Location; public class MagicalCampfireListener implements Listener { private final Plugin plugin; + private final int regenInterval; + private final boolean worksWithSoul; - public MagicalCampfireListener() { - this.plugin = Bukkit.getPluginManager().getPlugin("MagicalCampfire"); + public MagicalCampfireListener(Plugin plugin) { + this.plugin = plugin; + FileConfiguration config = plugin.getConfig(); + this.regenInterval = config.getInt("regenInterval", 40); + this.worksWithSoul = config.getBoolean("worksWithSoul", false); startRegenTask(); } @@ -28,7 +34,7 @@ public class MagicalCampfireListener implements Listener { } } } - }.runTaskTimer(plugin, 0L, 40L); + }.runTaskTimer(plugin, 0L, regenInterval); } private boolean isNearLitCampfire(Player player) { @@ -37,7 +43,7 @@ public class MagicalCampfireListener implements Listener { for (int y = -2; y <= 2; y++) { for (int z = -2; z <= 2; z++) { Location loc = playerLoc.clone().add(x, y, z); - if (loc.getBlock().getType() == Material.CAMPFIRE) { + if (loc.getBlock().getType() == Material.CAMPFIRE || (worksWithSoul && loc.getBlock().getType() == Material.SOUL_CAMPFIRE)) { Campfire campfire = (Campfire) loc.getBlock().getBlockData(); if (campfire.isLit()) { return true; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..d21609c --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,8 @@ +# config.yml + +# regenInterval sets how often the regen task should run (in ticks, 20 ticks = 1 second) +# everytime the task runs it regenerates half a heart. (default: 40) +regenInterval: 40 + +# worksWithSoul defines whether soul campfires regen as well. (default: false) +worksWithSoul: false \ No newline at end of file