Don't resave cells on stopping creation, fixes #74

We was saving everything again when the players stop creating anything,
this was causing issues with duplicate cells when using any storage with
SQL (due to insert and no primary key).

Also, added a hasChanged to the cell class which will prevent resaving
things in sql if it hasn't changed.
This commit is contained in:
graywolf336
2015-05-26 14:57:38 -05:00
parent fd52be6972
commit 12f35a01bf
7 changed files with 75 additions and 12 deletions

View File

@ -71,4 +71,12 @@ public class AnyCell implements ICell {
public boolean hasChest() {
throw new UnsupportedOperationException();
}
public boolean setChanged(boolean changed) {
throw new UnsupportedOperationException();
}
public boolean hasChanged() {
throw new UnsupportedOperationException();
}
}

View File

@ -20,6 +20,7 @@ public class Cell implements ICell {
private Prisoner p;
private HashSet<SimpleLocation> signs;
private SimpleLocation teleport, chest;
private boolean changed;
/** Creates a new Cell with the given name
*
@ -28,6 +29,7 @@ public class Cell implements ICell {
public Cell(String name) {
this.name = name;
this.signs = new HashSet<SimpleLocation>();
this.changed = false;
}
public String getName() {
@ -36,6 +38,7 @@ public class Cell implements ICell {
public void setPrisoner(Prisoner prisoner) {
this.p = prisoner;
this.changed = true;
}
public Prisoner getPrisoner() {
@ -44,6 +47,7 @@ public class Cell implements ICell {
public void removePrisoner() {
this.p = null;
this.changed = true;
}
public boolean hasPrisoner() {
@ -52,10 +56,12 @@ public class Cell implements ICell {
public void addAllSigns(HashSet<SimpleLocation> signs) {
this.signs.addAll(signs);
this.changed = true;
}
public void addSign(SimpleLocation sign) {
this.signs.add(sign);
this.changed = true;
}
public HashSet<SimpleLocation> getSigns() {
@ -82,6 +88,7 @@ public class Cell implements ICell {
public void setTeleport(SimpleLocation location) {
this.teleport = location;
this.changed = true;
}
public Location getTeleport() {
@ -90,6 +97,7 @@ public class Cell implements ICell {
public void setChestLocation(SimpleLocation simpleLocation) {
this.chest = simpleLocation;
this.changed = true;
}
public Location getChestLocation() {
@ -115,4 +123,12 @@ public class Cell implements ICell {
}else
return false;
}
public boolean setChanged(boolean changed) {
return this.changed = changed;
}
public boolean hasChanged() {
return this.changed;
}
}

View File

@ -160,9 +160,13 @@ public class Jail {
}
/** Adds a cell to the Jail. */
public void addCell(Cell cell, boolean save) {
public boolean addCell(Cell cell, boolean save) {
if(save) plugin.getJailIO().saveCell(this, cell);
this.cells.put(cell.getName(), cell);
//Check if it already exists or not
if(this.cells.containsKey(cell.getName())) return false;
else this.cells.put(cell.getName(), cell);
return true;
}
/** Gets the cell with the given name. */

View File

@ -71,4 +71,12 @@ public class NoCell implements ICell {
public boolean hasChest() {
throw new UnsupportedOperationException();
}
public boolean setChanged(boolean changed) {
throw new UnsupportedOperationException();
}
public boolean hasChanged() {
throw new UnsupportedOperationException();
}
}