-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature based off Stop Drop N Roll mod (#72)
* Add Stop Drop N Roll * Nearly forgot the chance * Fix * twerk-to-reduce-burn-time
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/org/purpurmc/purpurextras/modules/StopDropNRollModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |