Skip to content

Commit

Permalink
Add nausea effect
Browse files Browse the repository at this point in the history
  • Loading branch information
mfletcher2 committed Dec 24, 2020
1 parent 017828d commit 4e90c27
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
39 changes: 28 additions & 11 deletions src/main/java/nezd53/sneakfart/FartHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;

import java.util.List;

import static java.lang.Math.*;
import static nezd53.sneakfart.SneakFart.*;

Expand All @@ -23,21 +27,34 @@ static void handleSneak(Player player) {
}

static void fart(Player player) {
Particle.DustOptions options = new Particle.DustOptions(Color.fromRGB(139, 69, 19), (float)fartParticleSize);
Particle.DustOptions options = new Particle.DustOptions(Color.fromRGB(139, 69, 19), (float) fartParticleSize);
float yaw = player.getLocation().getYaw();
Vector offset = new Vector(sin(toRadians(yaw)) * fartDistance, 0.25, -cos(toRadians(yaw)) * fartDistance);
Location l = player.getLocation().add(offset);
player.spawnParticle(Particle.REDSTONE, l,
25, fartOffset, fartOffset, fartOffset, options);
player.playSound(l, Sound.BLOCK_WET_GRASS_PLACE, (float)fartVolume, 0.005f);

if (random() <= poopChance) {
Item item = player.getWorld().dropItem(l, new ItemStack(Material.BROWN_DYE));
item.setPickupDelay(32767);
item.setTicksLived(5900);
item.setCustomName(player.getName() + "'s Poop");
item.setCustomNameVisible(true);
item.setVelocity(offset.divide(new Vector(10,1,10)));
}
player.playSound(l, Sound.BLOCK_WET_GRASS_PLACE, (float) fartVolume, 0.005f);

if (random() < poopChance)
poop(player, offset, l);

if (random() < nauseaChance)
inflictNausea(l);
}

private static void poop(Player player, Vector offset, Location l) {
Item item = player.getWorld().dropItem(l, new ItemStack(Material.BROWN_DYE));
item.setPickupDelay(32767);
item.setTicksLived(5900);
item.setCustomName(player.getName() + "'s Poop");
item.setCustomNameVisible(true);
item.setVelocity(offset.clone().divide(new Vector(10, 1, 10)));
}

private static void inflictNausea(Location l) {
List<Player> players = l.getWorld().getPlayers();
for (Player p : players)
if (p.getLocation().distance(l) <= nauseaDistance)
p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 5 * 20, 5));
}
}
24 changes: 13 additions & 11 deletions src/main/java/nezd53/sneakfart/SneakFart.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ public final class SneakFart extends JavaPlugin {

static boolean enableFarts;
static double fartDistance, fartTimeStart, fartTimeEnd,
fartOffset, fartParticleSize, fartVolume, poopChance;
fartOffset, fartParticleSize, fartVolume, poopChance, nauseaChance, nauseaDistance;
static int fartParticleCount;

@Override
public void onEnable() {
saveDefaultConfig();
enableFarts = getConfig().getBoolean("EnableFarts");
fartDistance = getConfig().getDouble("FartDistance");
fartTimeStart = getConfig().getDouble("FartTimeStart");
fartTimeEnd = getConfig().getDouble("FartTimeEnd");
fartOffset = getConfig().getDouble("FartOffset");
fartParticleCount = getConfig().getInt("FartParticleCount");
fartParticleSize = getConfig().getDouble("FartParticleSize");
fartVolume = getConfig().getDouble("FartVolume");
poopChance = getConfig().getDouble("PoopChance");
enableFarts = getConfig().getBoolean("EnableFarts", true);
fartDistance = getConfig().getDouble("FartDistance", 0.8);
fartTimeStart = getConfig().getDouble("FartTimeStart", 15);
fartTimeEnd = getConfig().getDouble("FartTimeEnd", 30);
fartOffset = getConfig().getDouble("FartOffset", 0.25);
fartParticleCount = getConfig().getInt("FartParticleCount", 25);
fartParticleSize = getConfig().getDouble("FartParticleSize", 1);
fartVolume = getConfig().getDouble("FartVolume", 1);
poopChance = getConfig().getDouble("PoopChance", 0.05);
nauseaChance = getConfig().getDouble("NauseaChance", 0.3);
nauseaDistance = getConfig().getDouble("NauseaDistance", 2);

if(enableFarts)
if (enableFarts)
getServer().getPluginManager().registerEvents(new FartListener(), this);

}
Expand Down
14 changes: 11 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
# Whether or not to enable this plugin (true or false)
EnableFarts: true

# Percent chance that poop will spawn with fart from 0 to 1
# Set to 0 to disable
PoopChance: 0.05

# Percent chance that the fart will inflict nausea from 0 to 1
# Set to 0 to disable
NauseaChance: 0.3

# Distance from the player in blocks that the fart should come out
FartDistance: 0.8

Expand All @@ -11,6 +19,9 @@ FartDistance: 0.8
FartTimeStart: 15
FartTimeEnd: 30

# How far players must be from the fart to be inflicted with nausea in blocks
NauseaDistance: 2

# How spread apart the fart particles should be in blocks
FartOffset: 0.25

Expand All @@ -22,6 +33,3 @@ FartParticleSize: 1

# Volume level of fart sound
FartVolume: 1

# Percent chance that poop will spawn with fart from 0 to 1
PoopChance: 0.05

0 comments on commit 4e90c27

Please sign in to comment.