добавлен ImmutableEntityLocation
This commit is contained in:
57
core/src/main/java/mc/core/ImmutableEntityLocation.java
Normal file
57
core/src/main/java/mc/core/ImmutableEntityLocation.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,20 +5,23 @@
|
|||||||
package mc.core.eventbus.events;
|
package mc.core.eventbus.events;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import mc.core.EntityLocation;
|
import mc.core.EntityLocation;
|
||||||
|
import mc.core.ImmutableEntityLocation;
|
||||||
import mc.core.eventbus.EventBase;
|
import mc.core.eventbus.EventBase;
|
||||||
import mc.core.player.Player;
|
import mc.core.player.Player;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
@Getter
|
||||||
public class CS_PlayerMoveEvent extends EventBase {
|
public class CS_PlayerMoveEvent extends EventBase {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final EntityLocation oldLocation; // TODO сомнительное решение
|
private final ImmutableEntityLocation oldLocation;
|
||||||
// вообще нужно будет создать реализацию "иммутабл локейшен" для подобных ситуаций
|
|
||||||
@Setter
|
@Setter
|
||||||
private EntityLocation newLocation;
|
private EntityLocation newLocation;
|
||||||
@Setter
|
@Setter
|
||||||
private boolean recalcChunk = false;
|
private boolean recalcChunk = false;
|
||||||
|
|
||||||
|
public CS_PlayerMoveEvent(Player player, EntityLocation oldLocation) {
|
||||||
|
this.player = player;
|
||||||
|
this.oldLocation = new ImmutableEntityLocation(oldLocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
core/src/test/java/mc/core/TestImmutableEntityLocation.java
Normal file
35
core/src/test/java/mc/core/TestImmutableEntityLocation.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user