Added events and tests.
This commit is contained in:
parent
3053305bf1
commit
0bc55d2cf6
22
pom.xml
22
pom.xml
|
@ -7,7 +7,11 @@
|
|||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<powermock.version>1.7.4</powermock.version>
|
||||
</properties>
|
||||
<build>
|
||||
<defaultGoal>clean package install</defaultGoal>
|
||||
|
@ -61,6 +65,24 @@
|
|||
<artifactId>bskyblock</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.10.19</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
|
|
@ -22,6 +22,7 @@ public class AcidIsland extends Addon {
|
|||
private static AcidIsland addon;
|
||||
private AISettings settings;
|
||||
private AcidIslandWorld aiw;
|
||||
private AcidTask acidTask;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
@ -46,11 +47,12 @@ public class AcidIsland extends Addon {
|
|||
new AcidCommand(this);
|
||||
new AiCommand(this);
|
||||
// Burn everything
|
||||
new AcidTask(this);
|
||||
acidTask = new AcidTask(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
acidTask.cancelTasks();
|
||||
}
|
||||
|
||||
public AISettings getSettings() {
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package bskyblock.addon.acidisland.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* This event is fired when a player is going to be burned by acid (not rain)
|
||||
*
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AcidEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private double totalDamage;
|
||||
private final double protection;
|
||||
private List<PotionEffectType> potionEffects = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param totalDamage
|
||||
* @param protection
|
||||
* @param potionEffects
|
||||
* @param cancelled
|
||||
*/
|
||||
public AcidEvent(Player player, double totalDamage, double protection, List<PotionEffectType> potionEffects) {
|
||||
this.player = player;
|
||||
this.totalDamage = totalDamage;
|
||||
this.protection = protection;
|
||||
this.potionEffects = potionEffects;
|
||||
}
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* @return the player being damaged by acid rain
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to set
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of damage caused
|
||||
* @return the totalDamage
|
||||
*/
|
||||
public double getTotalDamage() {
|
||||
return totalDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount the damage was reduced for this player due to armor, etc.
|
||||
* @return the protection
|
||||
*/
|
||||
public double getProtection() {
|
||||
return protection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param acidDamage the rainDamage to set
|
||||
*/
|
||||
public void setTotalDamage(double totalDamage) {
|
||||
this.totalDamage = totalDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the potionEffects
|
||||
*/
|
||||
public List<PotionEffectType> getPotionEffects() {
|
||||
return potionEffects;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param potionEffects the potionEffects to set
|
||||
*/
|
||||
public void setPotionEffects(List<PotionEffectType> potionEffects) {
|
||||
this.potionEffects = potionEffects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package bskyblock.addon.acidisland.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* This event is fired when a player is going to be burned by acid rain
|
||||
*
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AcidRainEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private double rainDamage;
|
||||
private final double protection;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param rainDamage
|
||||
* @param protection
|
||||
*/
|
||||
public AcidRainEvent(Player player, double rainDamage, double protection) {
|
||||
this.player = player;
|
||||
this.rainDamage = rainDamage;
|
||||
this.protection = protection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player being damaged by acid rain
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to set
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of damage caused
|
||||
* @return the rainDamage
|
||||
*/
|
||||
public double getRainDamage() {
|
||||
return rainDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount the damage was reduced for this player due to armor, etc.
|
||||
* @return the protection
|
||||
*/
|
||||
public double getProtection() {
|
||||
return protection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rainDamage the rainDamage to set
|
||||
*/
|
||||
public void setRainDamage(double rainDamage) {
|
||||
this.rainDamage = rainDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
import org.bukkit.util.Vector;
|
||||
|
||||
import bskyblock.addon.acidisland.AcidIsland;
|
||||
import bskyblock.addon.acidisland.events.AcidEvent;
|
||||
import bskyblock.addon.acidisland.events.AcidRainEvent;
|
||||
import bskyblock.addon.acidisland.world.AcidTask;
|
||||
|
||||
/**
|
||||
|
@ -112,8 +114,14 @@ public class AcidEffect implements Listener {
|
|||
this.cancel();
|
||||
// Check they are still in this world
|
||||
} else {
|
||||
player.damage((addon.getSettings().getAcidRainDamage() - addon.getSettings().getAcidRainDamage() * getDamageReduced(player)));
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
double protection = addon.getSettings().getAcidRainDamage() * getDamageReduced(player);
|
||||
double totalDamage = (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(addon.getBSkyBlock(), 0L, 20L);
|
||||
|
@ -141,14 +149,19 @@ public class AcidEffect implements Listener {
|
|||
burningPlayers.remove(player);
|
||||
this.cancel();
|
||||
} else {
|
||||
addon.getSettings().getAcidEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, 600, 1)));
|
||||
addon.getSettings().getAcidEffects().stream().filter(e -> e.equals(PotionEffectType.POISON)).forEach(t -> player.addPotionEffect(new PotionEffect(t, 200, 1)));
|
||||
// Apply damage if there is any
|
||||
if (addon.getSettings().getAcidDamage() > 0D) {
|
||||
player.damage((addon.getSettings().getAcidDamage() - addon.getSettings().getAcidDamage() * getDamageReduced(player)));
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
double protection = addon.getSettings().getAcidDamage() * getDamageReduced(player);
|
||||
double totalDamage = addon.getSettings().getAcidDamage() - protection;
|
||||
AcidEvent acidEvent = new AcidEvent(player, totalDamage, protection, addon.getSettings().getAcidEffects());
|
||||
addon.getServer().getPluginManager().callEvent(acidEvent);
|
||||
if (!acidEvent.isCancelled()) {
|
||||
acidEvent.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, 600, 1)));
|
||||
acidEvent.getPotionEffects().stream().filter(e -> e.equals(PotionEffectType.POISON)).forEach(t -> player.addPotionEffect(new PotionEffect(t, 200, 1)));
|
||||
// Apply damage if there is any
|
||||
if (acidEvent.getTotalDamage() > 0D) {
|
||||
player.damage(acidEvent.getTotalDamage());
|
||||
player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(addon.getBSkyBlock(), 0L, 20L);
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Animals;
|
||||
|
@ -18,7 +19,7 @@ import bskyblock.addon.acidisland.AcidIsland;
|
|||
|
||||
public class AcidTask {
|
||||
private final AcidIsland addon;
|
||||
private Set<Entity> itemsInWater = Collections.newSetFromMap(new WeakHashMap<Entity, Boolean>());
|
||||
private Set<Entity> itemsInWater = Collections.newSetFromMap(new WeakHashMap<Entity, Boolean>());
|
||||
private int entityBurnTask = -1;
|
||||
private int itemBurnTask = -1;
|
||||
|
||||
|
@ -36,38 +37,32 @@ public class AcidTask {
|
|||
* Start the entity buring task
|
||||
*/
|
||||
private void burnEntities() {
|
||||
if (entityBurnTask >= 0) {
|
||||
addon.getServer().getScheduler().cancelTask(entityBurnTask);
|
||||
}
|
||||
// This part will kill monsters if they fall into the water because it is acid
|
||||
entityBurnTask = addon.getServer().getScheduler().scheduleSyncRepeatingTask(addon.getBSkyBlock(), () -> addon.getIslandWorld().getEntities().stream()
|
||||
.filter(e -> !(e instanceof Guardian || e instanceof Squid))
|
||||
.filter(w -> w.getLocation().getBlock().getType().equals(Material.WATER) || w.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER))
|
||||
.forEach(e -> {
|
||||
if ((e instanceof Monster) && addon.getSettings().getAcidDamageMonster() > 0D) {
|
||||
((Monster) e).damage(addon.getSettings().getAcidDamageMonster());
|
||||
} else if ((e instanceof Animals) && addon.getSettings().getAcidDamageAnimal() > 0D
|
||||
&& (!e.getType().equals(EntityType.CHICKEN) || addon.getSettings().isAcidDamageChickens())) {
|
||||
((Animals) e).damage(addon.getSettings().getAcidDamageMonster());
|
||||
}
|
||||
}), 0L, 20L);
|
||||
entityBurnTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getBSkyBlock(), () -> addon.getIslandWorld().getEntities().stream()
|
||||
.filter(e -> !(e instanceof Guardian || e instanceof Squid))
|
||||
.filter(w -> w.getLocation().getBlock().getType().equals(Material.WATER) || w.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER))
|
||||
.forEach(e -> {
|
||||
if ((e instanceof Monster) && addon.getSettings().getAcidDamageMonster() > 0D) {
|
||||
((Monster) e).damage(addon.getSettings().getAcidDamageMonster());
|
||||
} else if ((e instanceof Animals) && addon.getSettings().getAcidDamageAnimal() > 0D
|
||||
&& (!e.getType().equals(EntityType.CHICKEN) || addon.getSettings().isAcidDamageChickens())) {
|
||||
((Animals) e).damage(addon.getSettings().getAcidDamageMonster());
|
||||
}
|
||||
}), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the item removal in acid task
|
||||
*/
|
||||
private void runAcidItemRemovalTask() {
|
||||
if (itemBurnTask >= 0) {
|
||||
addon.getServer().getScheduler().cancelTask(itemBurnTask);
|
||||
}
|
||||
if (addon.getSettings().getAcidDestroyItemTime() <= 0) {
|
||||
return;
|
||||
}
|
||||
itemBurnTask = addon.getServer().getScheduler().scheduleSyncRepeatingTask(addon.getBSkyBlock(), () -> {
|
||||
itemBurnTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getBSkyBlock(), () -> {
|
||||
Set<Entity> newItemsInWater = new HashSet<>();
|
||||
addon.getIslandWorld().getEntities().stream()
|
||||
.filter(e -> e.getType().equals(EntityType.DROPPED_ITEM)
|
||||
&& (e.getLocation().getBlock().getType().equals(Material.WATER)
|
||||
&& (e.getLocation().getBlock().getType().equals(Material.WATER)
|
||||
|| e.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER))
|
||||
)
|
||||
.forEach(e -> {
|
||||
|
@ -78,7 +73,19 @@ public class AcidTask {
|
|||
newItemsInWater.add(e);
|
||||
}
|
||||
});
|
||||
itemsInWater = newItemsInWater;
|
||||
itemsInWater = newItemsInWater;
|
||||
}, addon.getSettings().getAcidDestroyItemTime() * 20L, addon.getSettings().getAcidDestroyItemTime() * 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel tasks running
|
||||
*/
|
||||
public void cancelTasks() {
|
||||
if (entityBurnTask >= 0) {
|
||||
Bukkit.getScheduler().cancelTask(entityBurnTask);
|
||||
}
|
||||
if (itemBurnTask >= 0) {
|
||||
Bukkit.getScheduler().cancelTask(itemBurnTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package bskyblock.addon.acidisland.events;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AcidEventTest {
|
||||
|
||||
private Player player;
|
||||
private List<PotionEffectType> effects;
|
||||
private AcidEvent e;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
player = mock(Player.class);
|
||||
effects = Arrays.asList(PotionEffectType.values());
|
||||
e = new AcidEvent(player, 10, 5, effects);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcidEvent() {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayer() {
|
||||
assertEquals(player, e.getPlayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPlayer() {
|
||||
Player player2 = mock(Player.class);
|
||||
e.setPlayer(player2);
|
||||
assertEquals(player2, e.getPlayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTotalDamage() {
|
||||
assertTrue(e.getTotalDamage() == 10D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProtection() {
|
||||
assertTrue(e.getProtection() == 5D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetTotalDamage() {
|
||||
e.setTotalDamage(50);
|
||||
assertTrue(e.getTotalDamage() == 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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCancelled() {
|
||||
e.setCancelled(true);
|
||||
assertTrue(e.isCancelled());
|
||||
e.setCancelled(false);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package bskyblock.addon.acidisland.events;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AcidRainEventTest {
|
||||
|
||||
private Player player;
|
||||
private AcidRainEvent e;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
player = mock(Player.class);
|
||||
e = new AcidRainEvent(player, 10, 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcidEvent() {
|
||||
assertNotNull(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayer() {
|
||||
assertEquals(player, e.getPlayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPlayer() {
|
||||
Player player2 = mock(Player.class);
|
||||
e.setPlayer(player2);
|
||||
assertEquals(player2, e.getPlayer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTotalDamage() {
|
||||
assertTrue(e.getRainDamage() == 10D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProtection() {
|
||||
assertTrue(e.getProtection() == 5D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetTotalDamage() {
|
||||
e.setRainDamage(50);
|
||||
assertTrue(e.getRainDamage() == 50D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsCancelled() {
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCancelled() {
|
||||
e.setCancelled(true);
|
||||
assertTrue(e.isCancelled());
|
||||
e.setCancelled(false);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package bskyblock.addon.acidisland.world;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import bskyblock.addon.acidisland.AISettings;
|
||||
import bskyblock.addon.acidisland.AcidIsland;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class})
|
||||
public class AcidTaskTest {
|
||||
|
||||
private BukkitScheduler scheduler;
|
||||
private AISettings settings;
|
||||
private AcidIsland addon;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
scheduler = mock(BukkitScheduler.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||
addon = mock(AcidIsland.class);
|
||||
settings = mock(AISettings.class);
|
||||
when(settings.getAcidDestroyItemTime()).thenReturn(0L);
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcidTaskDoNotDestroyItems() {
|
||||
new AcidTask(addon);
|
||||
Mockito.verify(scheduler).scheduleSyncRepeatingTask(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(20L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcidTaskDestroyItems() {
|
||||
when(settings.getAcidDestroyItemTime()).thenReturn(5L);
|
||||
new AcidTask(addon);
|
||||
Mockito.verify(scheduler).scheduleSyncRepeatingTask(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(20L));
|
||||
Mockito.verify(scheduler).scheduleSyncRepeatingTask(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(100L), Mockito.eq(100L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcidTaskCancelTasks() {
|
||||
AcidTask task = new AcidTask(addon);
|
||||
task.cancelTasks();
|
||||
Mockito.verify(scheduler).cancelTask(Mockito.anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcidTaskCancelBothTasks() {
|
||||
when(settings.getAcidDestroyItemTime()).thenReturn(5L);
|
||||
AcidTask task = new AcidTask(addon);
|
||||
task.cancelTasks();
|
||||
Mockito.verify(scheduler, Mockito.times(2)).cancelTask(Mockito.anyInt());
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue