Got rid of cancerous Cloneable interface and fixed possible NPE when cloning a Position Keyframe

This commit is contained in:
CrushedPixel
2015-06-12 23:27:43 +02:00
parent b1864424d9
commit 8ef7e768d6
5 changed files with 14 additions and 15 deletions

View File

@@ -50,7 +50,7 @@ public class GuiEditKeyframe extends GuiScreen {
public GuiEditKeyframe(Keyframe keyframe) { public GuiEditKeyframe(Keyframe keyframe) {
this.keyframe = keyframe; this.keyframe = keyframe;
this.keyframeBackup = (Keyframe)keyframe.clone(); this.keyframeBackup = keyframe.clone();
this.posKeyframe = keyframe instanceof PositionKeyframe; this.posKeyframe = keyframe instanceof PositionKeyframe;
this.timeKeyframe = keyframe instanceof TimeKeyframe; this.timeKeyframe = keyframe instanceof TimeKeyframe;
this.markerKeyframe = keyframe instanceof MarkerKeyframe; this.markerKeyframe = keyframe instanceof MarkerKeyframe;
@@ -119,7 +119,7 @@ public class GuiEditKeyframe extends GuiScreen {
inputs.addAll(posInputs); inputs.addAll(posInputs);
} else if(markerKeyframe) { } else if(markerKeyframe) {
markerNameInput = new GuiTextField(GuiConstants.KEYFRAME_REPOSTORY_NAME_INPUT, fontRendererObj, 0, 0, 300, 20); markerNameInput = new GuiTextField(GuiConstants.KEYFRAME_REPOSTORY_NAME_INPUT, fontRendererObj, 0, 0, 300, 20);
markerNameInput.setText(((MarkerKeyframe)keyframe).getName()); markerNameInput.setText(((MarkerKeyframe)keyframe).getName() == null ? "" : ((MarkerKeyframe)keyframe).getName());
inputs.add(markerNameInput); inputs.add(markerNameInput);
} }
} }

View File

@@ -1,11 +1,10 @@
package eu.crushedpixel.replaymod.holders; package eu.crushedpixel.replaymod.holders;
public class Keyframe implements Cloneable { public class Keyframe {
private int realTimestamp; private int realTimestamp;
@Override public Keyframe clone() {
public Object clone() {
return new Keyframe(realTimestamp); return new Keyframe(realTimestamp);
} }

View File

@@ -8,7 +8,7 @@ public class MarkerKeyframe extends Keyframe {
private String name; private String name;
@Override @Override
public Object clone() { public Keyframe clone() {
return new MarkerKeyframe(this.getPosition(), this.getRealTimestamp(), this.getName()); return new MarkerKeyframe(this.getPosition(), this.getRealTimestamp(), this.getName());
} }

View File

@@ -8,8 +8,8 @@ public class PositionKeyframe extends Keyframe {
private Integer spectatedEntityID = null; private Integer spectatedEntityID = null;
@Override @Override
public Object clone() { public Keyframe clone() {
return new PositionKeyframe(this.getRealTimestamp(), this.getPosition(), this.getSpectatedEntityID()); return new PositionKeyframe(getRealTimestamp(), position, spectatedEntityID);
} }
public PositionKeyframe(int realTime, Position position) { public PositionKeyframe(int realTime, Position position) {
@@ -17,7 +17,7 @@ public class PositionKeyframe extends Keyframe {
this.position = position; this.position = position;
} }
public PositionKeyframe(int realTime, Position position, int spectatedEntityID) { public PositionKeyframe(int realTime, Position position, Integer spectatedEntityID) {
super(realTime); super(realTime);
this.position = position; this.position = position;
this.spectatedEntityID = spectatedEntityID; this.spectatedEntityID = spectatedEntityID;

View File

@@ -7,7 +7,7 @@ public class TimeKeyframe extends Keyframe {
private final int timestamp; private final int timestamp;
@Override @Override
public Object clone() { public Keyframe clone() {
return new TimeKeyframe(this.getRealTimestamp(), this.getTimestamp()); return new TimeKeyframe(this.getRealTimestamp(), this.getTimestamp());
} }