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 @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Data @Data
public class EntityLocation implements Cloneable { public class EntityLocation {
private double x, y, z; private double x, y, z;
private float yaw, pitch; private float yaw, pitch;
@@ -50,13 +50,7 @@ public class EntityLocation implements Cloneable {
return new BlockLocation(getBlockX(), getBlockY(), getBlockZ()); return new BlockLocation(getBlockX(), getBlockY(), getBlockZ());
} }
@Override public EntityLocation copy() {
public EntityLocation clone() { return new EntityLocation(x, y, z, yaw, pitch);
try {
return (EntityLocation) super.clone();
} catch (CloneNotSupportedException e) {
log.error("", e);
return ZERO();
}
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -74,7 +74,7 @@ public class PlayHandler extends AbstractStateHandler implements PlayStateHandle
return; 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( event.setNewLocation(new EntityLocation(
packet.getX(), packet.getY(), packet.getZ(), packet.getX(), packet.getY(), packet.getZ(),
player.getLocation().getYaw(), player.getLocation().getYaw(),