Skip to content

Commit ff47bac

Browse files
Merge pull request #113 from ParallelMC/datapacks-suck
Cozy campfires
2 parents a0c66bc + 7a9bb78 commit ff47bac

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

modules/src/main/java/parallelmc/parallelutils/modules/bitsandbobs/BitsAndBobs.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class BitsAndBobs extends ParallelModule {
2222

2323
private TogglePvpManager pvpManager;
2424

25+
private CozyCampfires cozyCampfires;
26+
2527
public BitsAndBobs(ParallelClassLoader classLoader, List<String> dependents) {
2628
super(classLoader, dependents);
2729
}
@@ -78,6 +80,11 @@ public void onEnable() {
7880
manager.registerEvents(new PreventSpawnerMining(), plugin);
7981
}
8082

83+
cozyCampfires = new CozyCampfires();
84+
if (config.getBoolean("enable-cozy-campfires", false)) {
85+
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> cozyCampfires.checkForCampfires(), 0, 80);
86+
}
87+
8188
if (config.getBoolean("enable-ziprails", true)) {
8289
manager.registerEvents(new Ziprails(), plugin);
8390
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package parallelmc.parallelutils.modules.bitsandbobs.minimodules;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.Location;
5+
import org.bukkit.Material;
6+
import org.bukkit.World;
7+
import org.bukkit.block.Block;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.potion.PotionEffect;
10+
import org.bukkit.potion.PotionEffectType;
11+
12+
public class CozyCampfires {
13+
14+
private static final int RADIUS = 3;
15+
private static final PotionEffect ABSORPTION = new PotionEffect(PotionEffectType.ABSORPTION, 14400, 1, true, false);
16+
17+
public void checkForCampfires() {
18+
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
19+
if (isCampfireNearby(p.getLocation())) {
20+
p.addPotionEffect(ABSORPTION);
21+
}
22+
}
23+
}
24+
25+
private boolean isCampfireNearby(Location location) {
26+
World world = location.getWorld();
27+
for (int x = -RADIUS; x <= RADIUS; x++) {
28+
for (int y = -RADIUS; y <= RADIUS; y++) {
29+
for (int z = -RADIUS; z <= RADIUS; z++) {
30+
Block block = world.getBlockAt(add(location, x, y ,z));
31+
if (block.getType() == Material.CAMPFIRE || block.getType() == Material.SOUL_CAMPFIRE) {
32+
return true;
33+
}
34+
}
35+
}
36+
}
37+
return false;
38+
}
39+
40+
// spigot add no make copy
41+
// this function make copy
42+
// :)
43+
private Location add(Location old, double x, double y, double z) {
44+
return old.clone().add(x, y ,z);
45+
}
46+
}

0 commit comments

Comments
 (0)