Skip to content

Commit

Permalink
Add feature based off Stop Drop N Roll mod (#72)
Browse files Browse the repository at this point in the history
* Add Stop Drop N Roll

* Nearly forgot the chance

* Fix

* twerk-to-reduce-burn-time
  • Loading branch information
JustDoom authored Jun 1, 2024
1 parent 21bd46c commit caf338c
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.purpurmc.purpurextras.modules;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.purpurmc.purpurextras.PurpurExtras;

import java.util.HashMap;
import java.util.Map;

/**
* Allows the player to Stop Drop N Roll to get extinguished from any flames.
*/
public class StopDropNRollModule implements PurpurExtrasModule, Listener {

private final Map<Player, Boolean> playerLastSneakMap = new HashMap<>();
private double chance;
private double amount;

protected StopDropNRollModule() {}

@Override
public void enable() {
PurpurExtras plugin = PurpurExtras.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
chance = PurpurExtras.getPurpurConfig().getDouble("settings.twerk-to-reduce-burn-time.chance", 0);
amount = PurpurExtras.getPurpurConfig().getDouble("settings.twerk-to-reduce-burn-time.amount", 0.5);
}

@Override
public boolean shouldEnable() {
return PurpurExtras.getPurpurConfig().getDouble("settings.twerk-to-reduce-burn-time.chance", 0) != 0;
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerToggleSneak(PlayerToggleSneakEvent event){
Player player = event.getPlayer();
boolean isSneaking = event.isSneaking();

if (player.getFireTicks() > 0 && isSneaking && !playerLastSneakMap.get(player) && Math.random() < chance) {
player.setFireTicks((int) (player.getFireTicks() * (1f - amount)));
}

playerLastSneakMap.put(player, isSneaking);
}

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
playerLastSneakMap.put(event.getPlayer(), false);
}

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(PlayerQuitEvent event) {
playerLastSneakMap.remove(event.getPlayer());
}
}

0 comments on commit caf338c

Please sign in to comment.