Archived
0

Sonar: [squid:S2975] Remove this "clone" implementation; use a copy constructor or copy factory instead

This commit is contained in:
2019-02-11 14:33:33 +03:00
parent 667ea373b8
commit d4a3a49b47
8 changed files with 14 additions and 27 deletions

View File

@@ -10,7 +10,7 @@ import mc.core.world.block.BlockLocation;
@NoArgsConstructor
@AllArgsConstructor
@Data
public class EntityLocation implements Cloneable {
public class EntityLocation {
private double x, y, z;
private float yaw, pitch;
@@ -50,13 +50,7 @@ public class EntityLocation implements Cloneable {
return new BlockLocation(getBlockX(), getBlockY(), getBlockZ());
}
@Override
public EntityLocation clone() {
try {
return (EntityLocation) super.clone();
} catch (CloneNotSupportedException e) {
log.error("", e);
return ZERO();
}
public EntityLocation copy() {
return new EntityLocation(x, y, z, yaw, pitch);
}
}

View File

@@ -9,7 +9,7 @@ import lombok.extern.slf4j.Slf4j;
@NoArgsConstructor
@AllArgsConstructor
@Data
public class BlockLocation implements Cloneable {
public class BlockLocation {
private int x, y, z;
public static BlockLocation ZERO() {
@@ -22,13 +22,7 @@ public class BlockLocation implements Cloneable {
this.z = z;
}
@Override
public BlockLocation clone() {
try {
return (BlockLocation) super.clone();
} catch (CloneNotSupportedException e) {
log.error("", e);
return ZERO();
}
public BlockLocation copy() {
return new BlockLocation(x, y, z);
}
}

View File

@@ -37,9 +37,9 @@ class EntityLocationTest {
}
@Test
void clone_() {
void copy() {
EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch);
EntityLocation locClone = locOrig.clone();
EntityLocation locClone = locOrig.copy();
assertEquals(locOrig, locClone);
assertNotSame(locOrig, locClone);
}

View File

@@ -26,7 +26,7 @@ class ImmutableEntityLocationTest {
@Test
void clone_() {
EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
EntityLocation locClone = locOrig.clone();
EntityLocation locClone = locOrig.copy();
assertEquals(locOrig, locClone);
}

View File

@@ -31,9 +31,9 @@ class BlockLocationTest {
}
@Test
void clone_() {
void copy() {
BlockLocation locOrig = new BlockLocation(x, y, z);
BlockLocation locClone = locOrig.clone();
BlockLocation locClone = locOrig.copy();
assertEquals(locOrig, locClone);
}
}

View File

@@ -12,7 +12,6 @@ import mc.core.player.PlayerManager;
import mc.core.player.PlayerSettings;
import mc.core.world.World;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.util.*;
@@ -30,7 +29,7 @@ public class H2PlayerManager implements PlayerManager {
H2Player h2Player = new H2Player();
h2Player.setName(name);
h2Player.setUuid(UUID.randomUUID());
h2Player.setLocation(location.clone());
h2Player.setLocation(location.copy());
h2Player.setLoadedChunks(new ArrayList<>());
h2Player.setWorld(world);
h2Player.setSettings(new PlayerSettings());

View File

@@ -34,7 +34,7 @@ public class TeleportManager {
teleportId = RAND.nextInt(9999);
} while (teleportMap.containsKey(teleportId));
teleportMap.put(teleportId, new TpData(player, location.clone()));
teleportMap.put(teleportId, new TpData(player, location.copy()));
return teleportId;
}

View File

@@ -74,7 +74,7 @@ public class PlayHandler extends AbstractStateHandler implements PlayStateHandle
return;
}
CS_PlayerMoveEvent event = new CS_PlayerMoveEvent(player, player.getLocation().clone());
CS_PlayerMoveEvent event = new CS_PlayerMoveEvent(player, player.getLocation().copy());
event.setNewLocation(new EntityLocation(
packet.getX(), packet.getY(), packet.getZ(),
player.getLocation().getYaw(),