mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-09-30 07:37:31 +02:00
Revert "Removed parents from regions."
Removal of parents will make upgrading extremely difficult and so consider them pending for the itme being.
This reverts commit df54d4de91
.
This commit is contained in:
parent
7acfb3586c
commit
4b15855b2f
@ -40,6 +40,7 @@ public class Region implements Comparable<Region> {
|
|||||||
private final String id;
|
private final String id;
|
||||||
private IndexableShape shape;
|
private IndexableShape shape;
|
||||||
private int priority = 0;
|
private int priority = 0;
|
||||||
|
private Region parent;
|
||||||
private Map<String, Attribute> attributes = new HashMap<String, Attribute>();
|
private Map<String, Attribute> attributes = new HashMap<String, Attribute>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,6 +107,46 @@ public void setPriority(int priority) {
|
|||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the parent of the region. Parents can determine how multiple overlapping
|
||||||
|
* regions are handled in regards to some flags, but it is dependent on the flag.
|
||||||
|
*
|
||||||
|
* @return parent region or null
|
||||||
|
*/
|
||||||
|
public Region getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the parent of this region.
|
||||||
|
*
|
||||||
|
* @see #getParent() for an explanation of parents
|
||||||
|
* @param parent the new parent, or null
|
||||||
|
* @throws IllegalArgumentException when circular inheritance is detected
|
||||||
|
*/
|
||||||
|
public synchronized void setParent(Region parent) throws IllegalArgumentException {
|
||||||
|
if (parent == null) {
|
||||||
|
this.parent = null;
|
||||||
|
} else {
|
||||||
|
if (parent == this) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Circular region inheritance detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
Region p = parent.getParent();
|
||||||
|
while (p != null) {
|
||||||
|
if (p == this) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Circular region inheritance detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
p = p.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an attribute to this region.
|
* Set an attribute to this region.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -60,6 +60,28 @@ public void testCompareTo() {
|
|||||||
assertEquals(regionB.compareTo(regionB), 0);
|
assertEquals(regionB.compareTo(regionB), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetParent() {
|
||||||
|
// Test self setting
|
||||||
|
Region regionA = new Region("A", mock(IndexableShape.class));
|
||||||
|
thrown.expect(IllegalArgumentException.class);
|
||||||
|
regionA.setParent(regionA);
|
||||||
|
|
||||||
|
// Test regular setting
|
||||||
|
Region child = new Region("A", mock(IndexableShape.class));
|
||||||
|
Region parent = new Region("B", mock(IndexableShape.class));
|
||||||
|
child.setParent(parent);
|
||||||
|
assertEquals(child.getParent(), parent);
|
||||||
|
assertEquals(parent.getParent(), null);
|
||||||
|
|
||||||
|
// Test circular
|
||||||
|
child = new Region("A", mock(IndexableShape.class));
|
||||||
|
parent = new Region("B", mock(IndexableShape.class));
|
||||||
|
child.setParent(parent);
|
||||||
|
thrown.expect(IllegalArgumentException.class);
|
||||||
|
parent.setParent(child);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPriority() {
|
public void testGetPriority() {
|
||||||
Region regionA = new Region("A", mock(IndexableShape.class));
|
Region regionA = new Region("A", mock(IndexableShape.class));
|
||||||
|
Loading…
Reference in New Issue
Block a user