Skip to content

Commit

Permalink
Merge pull request #78 from LinoxGH/v1.15
Browse files Browse the repository at this point in the history
Added the velocity methods for EntityMock and BlockDataMock.
  • Loading branch information
seeseemelk committed Jun 28, 2020
2 parents 2129b74 + e9a406a commit cbeebad
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 14 deletions.
16 changes: 11 additions & 5 deletions src/main/java/be/seeseemelk/mockbukkit/block/BlockMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.Collection;
import java.util.List;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.block.data.BlockDataMock;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FluidCollisionMode;
import org.bukkit.Location;
Expand All @@ -26,13 +29,16 @@

import be.seeseemelk.mockbukkit.UnimplementedOperationException;
import junit.framework.AssertionFailedError;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;

public class BlockMock implements org.bukkit.block.Block
{
private final Location location;
private BlockState state;
private Material material;
private byte data;
private BlockData blockData;

/**
* Creates a basic block made of air.
Expand Down Expand Up @@ -73,6 +79,7 @@ public BlockMock(Material material, Location location)
this.material = material;
this.location = location;
state = new BlockStateMock();
this.blockData = new BlockDataMock(material);
}

@Override
Expand Down Expand Up @@ -219,6 +226,7 @@ public Chunk getChunk()
public void setType(Material type)
{
material = type;
blockData = new BlockDataMock(type);
}

@Override
Expand Down Expand Up @@ -363,15 +371,13 @@ public Collection<ItemStack> getDrops(ItemStack tool)
@Override
public BlockData getBlockData()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
return blockData;
}

@Override
public void setBlockData(BlockData data)
public void setBlockData(@NotNull BlockData data)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
this.blockData = data;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package be.seeseemelk.mockbukkit.block.data;

import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import be.seeseemelk.mockbukkit.UnimplementedOperationException;

public class BlockDataMock implements BlockData
{
private final Material type;

public BlockDataMock(Material type)
{
this.type = type;
}

@Override
public @NotNull Material getMaterial()
{
return type;
}

@Override
public @NotNull String getAsString()
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public @NotNull String getAsString(boolean hideUnspecified)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public @NotNull BlockData merge(@NotNull BlockData data)
{
// TODO Auto-generated method stub
throw new UnimplementedOperationException();
}

@Override
public boolean matches(@Nullable BlockData data)
{
if (data == null) return false;
return data.getMaterial() == type;
}

@Override
public @NotNull BlockData clone()
{
try {
return (BlockData) super.clone();
} catch (CloneNotSupportedException e) {
return new BlockDataMock(type);
}
}
}
9 changes: 4 additions & 5 deletions src/main/java/be/seeseemelk/mockbukkit/entity/EntityMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public abstract class EntityMock implements Entity, MessageTarget
private String name = "entity";
private final Queue<String> messages = new LinkedTransferQueue<>();
private final Set<PermissionAttachment> permissionAttachments = new HashSet<>();
private Vector velocity = new Vector(0, 0, 0);

public EntityMock(ServerMock server, UUID uuid)
{
Expand Down Expand Up @@ -391,17 +392,15 @@ public void setCustomName(String name)
}

@Override
public void setVelocity(Vector velocity)
public void setVelocity(@NotNull Vector velocity)
{
// TODO Auto-generated constructor stub
throw new UnimplementedOperationException();
this.velocity = velocity;
}

@Override
public Vector getVelocity()
{
// TODO Auto-generated constructor stub
throw new UnimplementedOperationException();
return velocity;
}

@Override
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/be/seeseemelk/mockbukkit/block/BlockMockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import be.seeseemelk.mockbukkit.WorldMock;
import be.seeseemelk.mockbukkit.block.data.BlockDataMock;

public class BlockMockTest
{
Expand Down Expand Up @@ -119,4 +121,20 @@ public void testGetRelativeCordinates()
assertEquals(block.getZ(), relative.getZ());
}

@Test
public void testGetBlockData()
{
Assert.assertEquals(block.getType(), block.getBlockData().getMaterial());
}

@Test
public void testSetBlockData()
{
BlockDataMock blockData = new BlockDataMock(Material.DIRT);
Material oldType = block.getType();

block.setBlockData(blockData);
Assert.assertEquals(blockData, block.getBlockData());
block.setType(oldType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package be.seeseemelk.mockbukkit.block.data;

import org.bukkit.Material;
import org.junit.Assert;
import org.junit.Test;

public class BlockDataTest {

@Test
public void testMatches()
{
BlockDataMock blockData1 = new BlockDataMock(Material.STONE);
BlockDataMock blockData2 = new BlockDataMock(Material.STONE);
Assert.assertTrue(blockData1.matches(blockData2));
}
}
19 changes: 15 additions & 4 deletions src/test/java/be/seeseemelk/mockbukkit/entity/EntityMockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.util.Vector;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -290,8 +291,8 @@ public void addPermission_String_PermissionAdded()
}

@Test
public void entityDamage_By_Player(){

public void entityDamage_By_Player()
{
World world = new WorldMock(Material.GRASS_BLOCK, 10);
LivingEntity zombie = (LivingEntity) world.spawnEntity(new Location(world,10,10,10), EntityType.ZOMBIE);
PlayerMock player1 = server.addPlayer();
Expand All @@ -302,14 +303,24 @@ public void entityDamage_By_Player(){
}

@Test
public void entityDamage_Event_Triggered(){
public void entityDamage_Event_Triggered()
{
World world = new WorldMock(Material.GRASS_BLOCK, 10);
LivingEntity zombie = (LivingEntity) world.spawnEntity(new Location(world,10,10,10), EntityType.ZOMBIE);
PlayerMock player1 = server.addPlayer();
zombie.damage(4, player1);
server.getPluginManager().assertEventFired(EntityDamageByEntityEvent.class);
}


@Test
public void setVelocity()
{
PlayerMock player1 = server.addPlayer();
Vector velocity = player1.getVelocity();
velocity.setY(velocity.getY() + 2);
player1.setVelocity(velocity);
assertEquals(player1.getVelocity(), velocity);
}
}


Expand Down

0 comments on commit cbeebad

Please sign in to comment.