mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-05 00:43:15 +01:00
Improves some things
Makes sure to save the arena after editing allowed or loss trigger damage causes Makes sure to save and restore player saturation Adds damage animation and damage sound when faking damage for allowed damage causes Plays a sound when a player loses
This commit is contained in:
parent
2ec15c69c7
commit
901b052b25
@ -37,6 +37,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
private final boolean originalIsSwimming;
|
||||
private final boolean originalCollideAble;
|
||||
private final double originalHealth;
|
||||
private final float originalSaturation;
|
||||
private final Collection<PotionEffect> originalPotionEffects;
|
||||
|
||||
/**
|
||||
@ -54,6 +55,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
this.originalIsSwimming = player.isSwimming();
|
||||
this.originalCollideAble = player.isCollidable();
|
||||
this.originalHealth = player.getHealth();
|
||||
this.originalSaturation = player.getSaturation();
|
||||
|
||||
// Store and clear potion effects
|
||||
this.originalPotionEffects = getPlayer().getActivePotionEffects();
|
||||
@ -75,12 +77,13 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
* @param originalPotionEffects <p>The potion effects applied to the player when joining</p>
|
||||
* @param originalHealth <p>The health of the player when joining the arena</p>
|
||||
* @param originalSaturation <p>The saturation of the player when joining the arena</p>
|
||||
*/
|
||||
public AbstractPlayerEntryState(@NotNull UUID playerId, @NotNull Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble, @NotNull Collection<PotionEffect> originalPotionEffects,
|
||||
double originalHealth) {
|
||||
double originalHealth, float originalSaturation) {
|
||||
this.playerId = playerId;
|
||||
this.entryLocation = entryLocation;
|
||||
this.originalIsFlying = originalIsFlying;
|
||||
@ -91,6 +94,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
this.originalCollideAble = originalCollideAble;
|
||||
this.originalPotionEffects = originalPotionEffects;
|
||||
this.originalHealth = originalHealth;
|
||||
this.originalSaturation = originalSaturation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,6 +125,8 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
}
|
||||
removeMenuItem(player);
|
||||
player.setHealth(originalHealth);
|
||||
player.setSaturation(originalSaturation);
|
||||
player.setFallDistance(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,6 +162,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState {
|
||||
data.put("originalCollideAble", this.originalCollideAble);
|
||||
data.put("originalPotionEffects", this.originalPotionEffects);
|
||||
data.put("originalHealth", this.originalHealth);
|
||||
data.put("originalSaturation", this.originalSaturation);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -243,12 +243,14 @@ public class DropperArena implements Arena {
|
||||
@Override
|
||||
public boolean setAllowedDamageCauses(@NotNull Set<EntityDamageEvent.DamageCause> causes) {
|
||||
this.allowedDamageCauses = causes;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setLossTriggerDamageCauses(@NotNull Set<EntityDamageEvent.DamageCause> causes) {
|
||||
this.lossTriggerDamageCauses = causes;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import net.knarcraft.minigames.gui.DropperGUIBedrock;
|
||||
import net.knarcraft.minigames.util.GeyserHelper;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import net.knarcraft.minigames.util.RewardHelper;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -116,6 +117,7 @@ public class DropperArenaSession extends AbstractArenaSession {
|
||||
this.deaths++;
|
||||
//Teleport the player back to the top
|
||||
PlayerTeleporter.teleportPlayer(this.player, this.arena.getSpawnLocation(), true, false);
|
||||
this.player.playSound(this.player, Sound.ENTITY_CHICKEN_EGG, 5f, 0.5f);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
|
@ -50,15 +50,18 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
* @param originalPotionEffects <p>The potion effects applied to the player when joining</p>
|
||||
* @param originalHealth <p>The health of the player when joining the arena</p>
|
||||
* @param originalSaturation <p>The saturation of the player when joining the arena</p>
|
||||
*/
|
||||
public DropperPlayerEntryState(@NotNull UUID playerId, @NotNull Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
float originalFlySpeed, float horizontalVelocity,
|
||||
@NotNull DropperArenaGameMode arenaGameMode, boolean originalCollideAble,
|
||||
@NotNull Collection<PotionEffect> originalPotionEffects, double originalHealth) {
|
||||
@NotNull Collection<PotionEffect> originalPotionEffects, double originalHealth,
|
||||
float originalSaturation) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth);
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth,
|
||||
originalSaturation);
|
||||
this.originalFlySpeed = originalFlySpeed;
|
||||
this.horizontalVelocity = horizontalVelocity;
|
||||
this.arenaGameMode = arenaGameMode;
|
||||
@ -130,11 +133,12 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState {
|
||||
Collection<PotionEffect> originalPotionEffect =
|
||||
(Collection<PotionEffect>) data.getOrDefault("originalPotionEffects", new ArrayList<>());
|
||||
double originalHealth = ((Number) data.get("originalHealth")).doubleValue();
|
||||
float originalSaturation = ((Number) data.get("originalSaturation")).floatValue();
|
||||
|
||||
return new DropperPlayerEntryState(playerId, entryLocation, originalIsFlying,
|
||||
originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming,
|
||||
originalFlySpeed, horizontalVelocity, arenaGameMode, originalCollideAble, originalPotionEffect,
|
||||
originalHealth);
|
||||
originalHealth, originalSaturation);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -273,12 +273,14 @@ public class ParkourArena implements Arena {
|
||||
@Override
|
||||
public boolean setAllowedDamageCauses(@NotNull Set<EntityDamageEvent.DamageCause> causes) {
|
||||
this.allowedDamageCauses = causes;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setLossTriggerDamageCauses(@NotNull Set<EntityDamageEvent.DamageCause> causes) {
|
||||
this.lossTriggerDamageCauses = causes;
|
||||
this.saveArena();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import net.knarcraft.minigames.util.GeyserHelper;
|
||||
import net.knarcraft.minigames.util.PlayerTeleporter;
|
||||
import net.knarcraft.minigames.util.RewardHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
@ -135,6 +136,7 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
//Teleport the player back to the top
|
||||
Location spawnLocation = this.reachedCheckpoint != null ? this.reachedCheckpoint : this.arena.getSpawnLocation();
|
||||
PlayerTeleporter.teleportPlayer(this.player, spawnLocation, true, false);
|
||||
this.player.playSound(this.player, Sound.ENTITY_CHICKEN_EGG, 5f, 0.5f);
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
|
@ -40,14 +40,16 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
* @param originalCollideAble <p>Whether the player was collide-able before entering the arena</p>
|
||||
* @param originalPotionEffects <p>The potion effects applied to the player when joining</p>
|
||||
* @param originalHealth <p>The health of the player when joining the arena</p>
|
||||
* @param originalSaturation <p>The saturation of the player when joining the arena</p>
|
||||
*/
|
||||
public ParkourPlayerEntryState(@NotNull UUID playerId, Location entryLocation,
|
||||
boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight,
|
||||
boolean originalInvulnerable, boolean originalIsSwimming,
|
||||
boolean originalCollideAble, Collection<PotionEffect> originalPotionEffects,
|
||||
double originalHealth) {
|
||||
double originalHealth, float originalSaturation) {
|
||||
super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight,
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth);
|
||||
originalInvulnerable, originalIsSwimming, originalCollideAble, originalPotionEffects, originalHealth,
|
||||
originalSaturation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,10 +82,11 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState {
|
||||
Collection<PotionEffect> originalPotionEffect =
|
||||
(Collection<PotionEffect>) data.getOrDefault("originalPotionEffects", new ArrayList<>());
|
||||
double originalHealth = ((Number) data.get("originalHealth")).doubleValue();
|
||||
float originalSaturation = ((Number) data.get("originalSaturation")).floatValue();
|
||||
|
||||
return new ParkourPlayerEntryState(playerId, entryLocation, originalIsFlying, originalGameMode,
|
||||
originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble,
|
||||
originalPotionEffect, originalHealth);
|
||||
originalPotionEffect, originalHealth, originalSaturation);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package net.knarcraft.minigames.listener;
|
||||
|
||||
import net.knarcraft.knarlib.lib.annotations.NotNull;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -18,7 +20,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
public class DamageListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDamage(EntityDamageEvent event) {
|
||||
public void onPlayerDamage(@NotNull EntityDamageEvent event) {
|
||||
// Only player damage matters
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
@ -42,15 +44,7 @@ public class DamageListener implements Listener {
|
||||
|
||||
// If set as allowed damage, do nothing, except if the damage is fatal
|
||||
if (arenaSession.getArena().getAllowedDamageCauses().contains(event.getCause())) {
|
||||
if (event.getFinalDamage() >= player.getHealth()) {
|
||||
AttributeInstance health = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
if (health != null) {
|
||||
player.setHealth(health.getValue());
|
||||
}
|
||||
arenaSession.triggerLoss();
|
||||
} else {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
applyFakeDamage(player, event.getDamage(), arenaSession);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,8 +54,31 @@ public class DamageListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fakes the damaging of a player
|
||||
*
|
||||
* @param player <p>The player to damage</p>
|
||||
* @param damage <p>The raw damage to apply</p>
|
||||
* @param arenaSession <p>The arena session to trigger a loss for, if the player reaches 0 damage</p>
|
||||
*/
|
||||
private void applyFakeDamage(@NotNull Player player, double damage, @NotNull ArenaSession arenaSession) {
|
||||
double newHealth = player.getHealth() - damage;
|
||||
player.sendHurtAnimation(180);
|
||||
if (newHealth <= 0) {
|
||||
AttributeInstance health = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
if (health != null) {
|
||||
player.setHealth(health.getValue());
|
||||
}
|
||||
arenaSession.triggerLoss();
|
||||
} else {
|
||||
player.setHealth(newHealth);
|
||||
player.setNoDamageTicks(10);
|
||||
player.playSound(player, Sound.ENTITY_PLAYER_HURT, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerCombustion(EntityCombustEvent event) {
|
||||
public void onPlayerCombustion(@NotNull EntityCombustEvent event) {
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user