mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-28 12:07:46 +01:00
Add transientRegion property to ProtectedRegion as a flag to only be stored in memory and not saved (#355)
This commit is contained in:
parent
e0df194ff2
commit
db70e6f346
@ -105,7 +105,7 @@ public void load() throws StorageException {
|
|||||||
*/
|
*/
|
||||||
public void save() throws StorageException {
|
public void save() throws StorageException {
|
||||||
index.setDirty(false);
|
index.setDirty(false);
|
||||||
store.saveAll(new HashSet<ProtectedRegion>(getValuesCopy()));
|
store.saveAll(new HashSet<ProtectedRegion>(getFilteredValuesCopy()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -422,12 +422,18 @@ public boolean apply(ProtectedRegion test) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an {@link ArrayList} copy of regions in the index.
|
* Get an {@link ArrayList} copy of regions in the index with transient regions filtered.
|
||||||
*
|
*
|
||||||
* @return a list
|
* @return a list
|
||||||
*/
|
*/
|
||||||
private List<ProtectedRegion> getValuesCopy() {
|
private List<ProtectedRegion> getFilteredValuesCopy() {
|
||||||
return new ArrayList<ProtectedRegion>(index.values());
|
List<ProtectedRegion> filteredValues = new ArrayList<ProtectedRegion>();
|
||||||
|
for (ProtectedRegion region : index.values()) {
|
||||||
|
if (!region.isTransient()) {
|
||||||
|
filteredValues.add(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== HELPER METHODS ===============
|
// =============== HELPER METHODS ===============
|
||||||
|
@ -39,12 +39,24 @@
|
|||||||
public class GlobalProtectedRegion extends ProtectedRegion {
|
public class GlobalProtectedRegion extends ProtectedRegion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.<br>
|
||||||
|
* Equivalent to {@link #GlobalProtectedRegion(String, boolean) GlobalProtectedRegion(id, false)}<br>
|
||||||
|
* <code>transientRegion</code> will be set to false, and this region can be saved.
|
||||||
*
|
*
|
||||||
* @param id the ID
|
* @param id the ID
|
||||||
*/
|
*/
|
||||||
public GlobalProtectedRegion(String id) {
|
public GlobalProtectedRegion(String id) {
|
||||||
super(id);
|
this(id, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param id the ID
|
||||||
|
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||||
|
*/
|
||||||
|
public GlobalProtectedRegion(String id, boolean transientRegion) {
|
||||||
|
super(id, transientRegion);
|
||||||
min = new BlockVector(0, 0, 0);
|
min = new BlockVector(0, 0, 0);
|
||||||
max = new BlockVector(0, 0, 0);
|
max = new BlockVector(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -39,14 +39,29 @@
|
|||||||
public class ProtectedCuboidRegion extends ProtectedRegion {
|
public class ProtectedCuboidRegion extends ProtectedRegion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new instance of this cuboid region.
|
* Construct a new instance of this cuboid region.<br>
|
||||||
|
* Equivalent to {@link #ProtectedCuboidRegion(String, boolean, BlockVector, BlockVector)
|
||||||
|
* ProtectedCuboidRegion(id, false, pt1, pt2)}<br>
|
||||||
|
* <code>transientRegion</code> will be set to false, and this region can be saved.
|
||||||
*
|
*
|
||||||
* @param id the region id
|
* @param id the region id
|
||||||
* @param pt1 the first point of this region
|
* @param pt1 the first point of this region
|
||||||
* @param pt2 the second point of this region
|
* @param pt2 the second point of this region
|
||||||
*/
|
*/
|
||||||
public ProtectedCuboidRegion(String id, BlockVector pt1, BlockVector pt2) {
|
public ProtectedCuboidRegion(String id, BlockVector pt1, BlockVector pt2) {
|
||||||
super(id);
|
this(id, false, pt1, pt2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new instance of this cuboid region.
|
||||||
|
*
|
||||||
|
* @param id the region id
|
||||||
|
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||||
|
* @param pt1 the first point of this region
|
||||||
|
* @param pt2 the second point of this region
|
||||||
|
*/
|
||||||
|
public ProtectedCuboidRegion(String id, boolean transientRegion, BlockVector pt1, BlockVector pt2) {
|
||||||
|
super(id, transientRegion);
|
||||||
setMinMaxPoints(pt1, pt2);
|
setMinMaxPoints(pt1, pt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,32 @@ public class ProtectedPolygonalRegion extends ProtectedRegion {
|
|||||||
private final int minY;
|
private final int minY;
|
||||||
private final int maxY;
|
private final int maxY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new instance of this polygonal region.<br>
|
||||||
|
* Equivalent to {@link #ProtectedPolygonalRegion(String, boolean, List, int, int)
|
||||||
|
* ProtectedPolygonalRegion(id, false, points, minY, maxY)}<br>
|
||||||
|
* <code>transientRegion</code> will be set to false, and this region can be saved.
|
||||||
|
*
|
||||||
|
* @param id the region id
|
||||||
|
* @param points a {@link List} of points that this region should contain
|
||||||
|
* @param minY the minimum y coordinate
|
||||||
|
* @param maxY the maximum y coordinate
|
||||||
|
*/
|
||||||
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
|
public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY, int maxY) {
|
||||||
super(id);
|
this(id, false, points, minY, maxY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new instance of this polygonal region.
|
||||||
|
*
|
||||||
|
* @param id the region id
|
||||||
|
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||||
|
* @param points a {@link List} of points that this region should contain
|
||||||
|
* @param minY the minimum y coordinate
|
||||||
|
* @param maxY the maximum y coordinate
|
||||||
|
*/
|
||||||
|
public ProtectedPolygonalRegion(String id, boolean transientRegion, List<BlockVector2D> points, int minY, int maxY) {
|
||||||
|
super(id, transientRegion);
|
||||||
ImmutableList<BlockVector2D> immutablePoints = ImmutableList.copyOf(points);
|
ImmutableList<BlockVector2D> immutablePoints = ImmutableList.copyOf(points);
|
||||||
setMinMaxPoints(immutablePoints, minY, maxY);
|
setMinMaxPoints(immutablePoints, minY, maxY);
|
||||||
this.points = immutablePoints;
|
this.points = immutablePoints;
|
||||||
|
@ -56,6 +56,7 @@ public abstract class ProtectedRegion implements ChangeTracked, Comparable<Prote
|
|||||||
protected BlockVector max;
|
protected BlockVector max;
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private final boolean transientRegion;
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
private ProtectedRegion parent;
|
private ProtectedRegion parent;
|
||||||
private DefaultDomain owners = new DefaultDomain();
|
private DefaultDomain owners = new DefaultDomain();
|
||||||
@ -67,9 +68,10 @@ public abstract class ProtectedRegion implements ChangeTracked, Comparable<Prote
|
|||||||
* Construct a new instance of this region.
|
* Construct a new instance of this region.
|
||||||
*
|
*
|
||||||
* @param id the name of this region
|
* @param id the name of this region
|
||||||
|
* @param transientRegion whether this region should only be kept in memory and not be saved
|
||||||
* @throws IllegalArgumentException thrown if the ID is invalid (see {@link #isValidId(String)}
|
* @throws IllegalArgumentException thrown if the ID is invalid (see {@link #isValidId(String)}
|
||||||
*/
|
*/
|
||||||
ProtectedRegion(String id) { // Package private because we can't have people creating their own region types
|
ProtectedRegion(String id, boolean transientRegion) { // Package private because we can't have people creating their own region types
|
||||||
checkNotNull(id);
|
checkNotNull(id);
|
||||||
|
|
||||||
if (!isValidId(id)) {
|
if (!isValidId(id)) {
|
||||||
@ -77,6 +79,7 @@ public abstract class ProtectedRegion implements ChangeTracked, Comparable<Prote
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.id = Normal.normalize(id);
|
this.id = Normal.normalize(id);
|
||||||
|
this.transientRegion = transientRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -680,8 +683,21 @@ protected boolean intersectsEdges(ProtectedRegion region) {
|
|||||||
*/
|
*/
|
||||||
abstract Area toArea();
|
abstract Area toArea();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <code>true</code> if this region should only be kept in memory and not be saved
|
||||||
|
*/
|
||||||
|
public boolean isTransient() {
|
||||||
|
return transientRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <code>true</code> if this region is not transient and changes have been made.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isDirty() {
|
public boolean isDirty() {
|
||||||
|
if (isTransient()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return dirty || owners.isDirty() || members.isDirty();
|
return dirty || owners.isDirty() || members.isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user