From 4e90c27872f558eacdc2a9884dbc57b8208af353 Mon Sep 17 00:00:00 2001 From: nezd53 Date: Wed, 23 Dec 2020 18:13:22 -0800 Subject: [PATCH] Add nausea effect --- .../java/nezd53/sneakfart/FartHandler.java | 39 +++++++++++++------ src/main/java/nezd53/sneakfart/SneakFart.java | 24 ++++++------ src/main/resources/config.yml | 14 +++++-- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/main/java/nezd53/sneakfart/FartHandler.java b/src/main/java/nezd53/sneakfart/FartHandler.java index 2fa3f94..eee3700 100644 --- a/src/main/java/nezd53/sneakfart/FartHandler.java +++ b/src/main/java/nezd53/sneakfart/FartHandler.java @@ -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.*; @@ -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 players = l.getWorld().getPlayers(); + for (Player p : players) + if (p.getLocation().distance(l) <= nauseaDistance) + p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 5 * 20, 5)); } } diff --git a/src/main/java/nezd53/sneakfart/SneakFart.java b/src/main/java/nezd53/sneakfart/SneakFart.java index 3886995..9bbfc20 100644 --- a/src/main/java/nezd53/sneakfart/SneakFart.java +++ b/src/main/java/nezd53/sneakfart/SneakFart.java @@ -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); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2ce81d0..47019e8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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 @@ -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 @@ -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 \ No newline at end of file