mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-22 18:45:22 +01:00
Added potion effects for acid rain
Implemented https://github.com/BentoBoxWorld/AcidIsland/issues/24 Also improved some config comments
This commit is contained in:
parent
838868b1c9
commit
f2b53bb2f8
@ -69,7 +69,7 @@ public class AISettings implements WorldSettings {
|
||||
@ConfigEntry(path = "acid.damage.acid.item")
|
||||
private long acidDestroyItemTime = 0;
|
||||
|
||||
@ConfigComment("Damage from acid rain")
|
||||
@ConfigComment("Damage from acid rain (and snow, if toggled on).")
|
||||
@ConfigEntry(path = "acid.damage.rain")
|
||||
private int acidRainDamage = 1;
|
||||
|
||||
@ -82,12 +82,18 @@ public class AISettings implements WorldSettings {
|
||||
@ConfigEntry(path = "acid.damage.delay")
|
||||
private long acidDamageDelay = 2;
|
||||
|
||||
@ConfigComment("Portion effects from going into acid water")
|
||||
@ConfigComment("Potion effects from going into acid water")
|
||||
@ConfigComment("You can list multiple effects")
|
||||
@ConfigEntry(path = "acid.damage.effects")
|
||||
@Adapter(PotionEffectListAdapter.class)
|
||||
private List<PotionEffectType> acidEffects = new ArrayList<>();
|
||||
|
||||
@ConfigComment("Potion effects from going into acid rain and snow")
|
||||
@ConfigComment("You can list multiple effects.")
|
||||
@ConfigEntry(path = "acid.damage.rain-effects", since = "1.9.1")
|
||||
@Adapter(PotionEffectListAdapter.class)
|
||||
private List<PotionEffectType> acidRainEffects = new ArrayList<>();
|
||||
|
||||
@ConfigComment("If player wears a helmet then they will not suffer from acid rain")
|
||||
@ConfigEntry(path = "acid.damage.protection.helmet")
|
||||
private boolean helmetProtection;
|
||||
@ -1507,4 +1513,22 @@ public class AISettings implements WorldSettings {
|
||||
{
|
||||
this.createIslandOnFirstLoginAbortOnLogout = createIslandOnFirstLoginAbortOnLogout;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* @since 1.9.1
|
||||
*/
|
||||
public List<PotionEffectType> getAcidRainEffects() {
|
||||
return acidRainEffects;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param acidRainEffects
|
||||
* @since 1.9.1
|
||||
*/
|
||||
public void setAcidRainEffects(List<PotionEffectType> acidRainEffects) {
|
||||
this.acidRainEffects = acidRainEffects;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class AcidEvent extends Event implements Cancellable {
|
||||
private Player player;
|
||||
private double totalDamage;
|
||||
private final double protection;
|
||||
private List<PotionEffectType> potionEffects = new ArrayList<>();
|
||||
private List<PotionEffectType> potionEffects;
|
||||
|
||||
/**
|
||||
* @param player - player
|
||||
|
@ -4,6 +4,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This event is fired when a player is going to be burned by acid rain
|
||||
@ -17,6 +20,10 @@ public class AcidRainEvent extends Event implements Cancellable {
|
||||
private Player player;
|
||||
private double rainDamage;
|
||||
private final double protection;
|
||||
/**
|
||||
* @since 1.9.1
|
||||
*/
|
||||
private List<PotionEffectType> potionEffects;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
@ -26,10 +33,11 @@ public class AcidRainEvent extends Event implements Cancellable {
|
||||
* @param rainDamage
|
||||
* @param protection
|
||||
*/
|
||||
public AcidRainEvent(Player player, double rainDamage, double protection) {
|
||||
public AcidRainEvent(Player player, double rainDamage, double protection, List<PotionEffectType> potionEffects) {
|
||||
this.player = player;
|
||||
this.rainDamage = rainDamage;
|
||||
this.protection = protection;
|
||||
this.potionEffects = potionEffects;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,6 +77,25 @@ public class AcidRainEvent extends Event implements Cancellable {
|
||||
this.rainDamage = rainDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the potion effects that will be applied to the player.
|
||||
* @return
|
||||
* @since 1.9.1
|
||||
*/
|
||||
public List<PotionEffectType> getPotionEffects() {
|
||||
return potionEffects;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param potionEffects the potionEffects to set
|
||||
* @return
|
||||
* @since 1.9.1
|
||||
*/
|
||||
public void setPotionEffects(List<PotionEffectType> potionEffects) {
|
||||
this.potionEffects = potionEffects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
@ -116,11 +116,16 @@ public class AcidEffect implements Listener {
|
||||
} else if (wetPlayers.containsKey(player) && wetPlayers.get(player) < System.currentTimeMillis()) {
|
||||
double protection = addon.getSettings().getAcidRainDamage() * getDamageReduced(player);
|
||||
double totalDamage = Math.max(0, addon.getSettings().getAcidRainDamage() - protection);
|
||||
AcidRainEvent e = new AcidRainEvent(player, totalDamage, protection);
|
||||
addon.getServer().getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled()) {
|
||||
player.damage(e.getRainDamage());
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
AcidRainEvent event = new AcidRainEvent(player, totalDamage, protection, addon.getSettings().getAcidRainEffects());
|
||||
addon.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
event.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, 600, 1)));
|
||||
event.getPotionEffects().stream().filter(e -> e.equals(PotionEffectType.POISON)).forEach(t -> player.addPotionEffect(new PotionEffect(t, 200, 1)));
|
||||
// Apply damage if there is any
|
||||
if (event.getRainDamage() > 0D) {
|
||||
player.damage(event.getRainDamage());
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,27 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AcidRainEventTest {
|
||||
|
||||
@Mock
|
||||
private Player player;
|
||||
private List<PotionEffectType> effects;
|
||||
private AcidRainEvent e;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
e = new AcidRainEvent(player, 10, 5);
|
||||
effects = Arrays.asList(PotionEffectType.values());
|
||||
e = new AcidRainEvent(player, 10, 5, effects);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -55,6 +63,17 @@ public class AcidRainEventTest {
|
||||
assertTrue(e.getRainDamage() == 50D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPotionEffects() {
|
||||
Assert.assertArrayEquals(PotionEffectType.values(), e.getPotionEffects().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPotionEffects() {
|
||||
e.setPotionEffects(new ArrayList<>());
|
||||
assertTrue(e.getPotionEffects().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsCancelled() {
|
||||
assertFalse(e.isCancelled());
|
||||
|
Loading…
Reference in New Issue
Block a user