Archived
0

добавлен ImmutableEntityLocation

This commit is contained in:
2018-09-08 14:54:29 +03:00
parent 27c40e86e6
commit ad31a90455
3 changed files with 99 additions and 4 deletions

View File

@@ -0,0 +1,57 @@
package mc.core;
public class ImmutableEntityLocation extends EntityLocation {
public ImmutableEntityLocation(double x, double y, double z, float yaw, float pitch) {
super(x, y, z, yaw, pitch);
}
public ImmutableEntityLocation(EntityLocation location) {
this(
location.getX(),
location.getY(),
location.getZ(),
location.getYaw(),
location.getPitch()
);
}
@Override
public void setX(double x) {
throw new UnsupportedOperationException();
}
@Override
public void setY(double y) {
throw new UnsupportedOperationException();
}
@Override
public void setZ(double z) {
throw new UnsupportedOperationException();
}
@Override
public void setYaw(float yaw) {
throw new UnsupportedOperationException();
}
@Override
public void setPitch(float pitch) {
throw new UnsupportedOperationException();
}
@Override
public void set(EntityLocation location) {
throw new UnsupportedOperationException();
}
@Override
public void setXYZ(double x, double y, double z) {
throw new UnsupportedOperationException();
}
@Override
public void setYawPitch(float yaw, float pitch) {
throw new UnsupportedOperationException();
}
}

View File

@@ -5,20 +5,23 @@
package mc.core.eventbus.events;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import mc.core.EntityLocation;
import mc.core.ImmutableEntityLocation;
import mc.core.eventbus.EventBase;
import mc.core.player.Player;
@RequiredArgsConstructor
@Getter
public class CS_PlayerMoveEvent extends EventBase {
private final Player player;
private final EntityLocation oldLocation; // TODO сомнительное решение
// вообще нужно будет создать реализацию "иммутабл локейшен" для подобных ситуаций
private final ImmutableEntityLocation oldLocation;
@Setter
private EntityLocation newLocation;
@Setter
private boolean recalcChunk = false;
public CS_PlayerMoveEvent(Player player, EntityLocation oldLocation) {
this.player = player;
this.oldLocation = new ImmutableEntityLocation(oldLocation);
}
}

View File

@@ -0,0 +1,35 @@
package mc.core;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
public class TestImmutableEntityLocation {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testSetValue() {
EntityLocation location = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
thrown.expect(UnsupportedOperationException.class);
location.setX(1);
location.setY(1);
location.setZ(1);
location.setYaw(1);
location.setPitch(1);
location.setXYZ(1, 2, 3);
location.setYawPitch(1, 2);
location.set(EntityLocation.ZERO());
}
@Test
public void testClone() {
EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
EntityLocation locClone = locOrig.clone();
assertEquals(locOrig, locClone);
}
}