Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class BitsAndBobs extends ParallelModule {

private TogglePvpManager pvpManager;

private CozyCampfires cozyCampfires;

public BitsAndBobs(ParallelClassLoader classLoader, List<String> dependents) {
super(classLoader, dependents);
}
Expand Down Expand Up @@ -78,6 +80,11 @@ public void onEnable() {
manager.registerEvents(new PreventSpawnerMining(), plugin);
}

cozyCampfires = new CozyCampfires();
if (config.getBoolean("enable-cozy-campfires", false)) {
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> cozyCampfires.checkForCampfires(), 0, 80);
}

if (config.getBoolean("enable-ziprails", true)) {
manager.registerEvents(new Ziprails(), plugin);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package parallelmc.parallelutils.modules.bitsandbobs.minimodules;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class CozyCampfires {

private static final int RADIUS = 3;
private static final PotionEffect ABSORPTION = new PotionEffect(PotionEffectType.ABSORPTION, 14400, 1, true, false);

public void checkForCampfires() {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (isCampfireNearby(p.getLocation())) {
p.addPotionEffect(ABSORPTION);
}
}
}

private boolean isCampfireNearby(Location location) {
World world = location.getWorld();
for (int x = -RADIUS; x <= RADIUS; x++) {
for (int y = -RADIUS; y <= RADIUS; y++) {
for (int z = -RADIUS; z <= RADIUS; z++) {
Block block = world.getBlockAt(add(location, x, y ,z));
if (block.getType() == Material.CAMPFIRE || block.getType() == Material.SOUL_CAMPFIRE) {
return true;
}
}
}
}
return false;
}

// spigot add no make copy
// this function make copy
// :)
private Location add(Location old, double x, double y, double z) {
return old.clone().add(x, y ,z);
}
}
Loading