Skip to content

Commit 4f1be02

Browse files
committed
Fixed dirty flags for CustomDomain, added UnitTest
1 parent 8736185 commit 4f1be02

6 files changed

Lines changed: 94 additions & 6 deletions

File tree

worldguard-core/src/main/java/com/sk89q/worldguard/commands/CommandInputContext.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
package com.sk89q.worldguard.commands;
2121

22-
import com.google.common.collect.Maps;
2322
import com.sk89q.worldedit.extension.platform.Actor;
2423
import com.sk89q.worldguard.LocalPlayer;
25-
import com.sk89q.worldguard.protection.flags.FlagContext;
2624
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
2725

2826
import javax.annotation.Nullable;

worldguard-core/src/main/java/com/sk89q/worldguard/domains/CustomDomain.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class CustomDomain implements Domain, ChangeTracked {
3232
private static final Pattern VALID_NAME = Pattern.compile("^[A-Za-z0-9\\-]{1,40}$");
3333

3434
private final String name;
35+
private boolean dirty;
3536

3637
public CustomDomain(String name) {
3738
if (name == null ||!isValidName(name)) {
@@ -93,4 +94,14 @@ public boolean contains(LocalPlayer player) {
9394
public int size() {
9495
return 1;
9596
}
97+
98+
@Override
99+
public boolean isDirty() {
100+
return dirty;
101+
}
102+
103+
@Override
104+
public void setDirty(boolean dirty) {
105+
this.dirty = dirty;
106+
}
96107
}

worldguard-core/src/main/java/com/sk89q/worldguard/domains/DefaultDomain.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class DefaultDomain implements Domain, ChangeTracked {
5454
private GroupDomain groupDomain = new GroupDomain();
5555

5656
private Set<CustomDomain> customDomains = new HashSet<>();
57+
private boolean customDomainsChanged = false;
5758

5859
/**
5960
* Create a new domain.
@@ -119,6 +120,7 @@ public void addCustomDomain(CustomDomain customDomain) {
119120
checkNotNull(customDomain);
120121
removeCustomDomain(customDomain.getName());
121122
this.customDomains.add(customDomain);
123+
customDomainsChanged = true;
122124
}
123125

124126
/**
@@ -128,7 +130,9 @@ public void addCustomDomain(CustomDomain customDomain) {
128130
*/
129131
public void removeCustomDomain(String name) {
130132
checkNotNull(name);
131-
this.customDomains.removeIf(d -> d.getName().equalsIgnoreCase(name));
133+
if (this.customDomains.removeIf(d -> d.getName().equalsIgnoreCase(name))) {
134+
customDomainsChanged = true;
135+
}
132136
}
133137

134138
/**
@@ -138,7 +142,9 @@ public void removeCustomDomain(String name) {
138142
*/
139143
public void removeCustomDomain(CustomDomain customDomain) {
140144
checkNotNull(customDomain);
141-
this.customDomains.remove(customDomain);
145+
if (this.customDomains.remove(customDomain)) {
146+
customDomainsChanged = true;
147+
}
142148
}
143149

144150
/**
@@ -149,6 +155,7 @@ public void removeCustomDomain(CustomDomain customDomain) {
149155
public void setCustomDomains(Collection<CustomDomain> customDomains) {
150156
checkNotNull(customDomains);
151157
this.customDomains = new HashSet<>(customDomains);
158+
customDomainsChanged = true;
152159
}
153160

154161
/**
@@ -534,13 +541,15 @@ private Component toCustomDomainsComponent() {
534541

535542
@Override
536543
public boolean isDirty() {
537-
return playerDomain.isDirty() || groupDomain.isDirty() || customDomains.stream().anyMatch(ChangeTracked::isDirty);
544+
return playerDomain.isDirty() || groupDomain.isDirty() ||
545+
customDomainsChanged || customDomains.stream().anyMatch(ChangeTracked::isDirty);
538546
}
539547

540548
@Override
541549
public void setDirty(boolean dirty) {
542550
playerDomain.setDirty(dirty);
543551
groupDomain.setDirty(dirty);
552+
customDomainsChanged = true;
544553
customDomains.forEach(d -> d.setDirty(dirty));
545554
}
546555

worldguard-core/src/main/java/com/sk89q/worldguard/domains/registry/UnknownDomain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public UnknownDomain(String name) {
3434
}
3535

3636
@Override
37-
public void parseInput(CustomDomainContext c) throws InvalidDomainFormat {
37+
public void parseInput(CustomDomainContext context) throws InvalidDomainFormat {
3838
throw new InvalidDomainFormat("The plugin that registered this flag is not currently installed");
3939
}
4040

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* WorldGuard, a suite of tools for Minecraft
3+
* Copyright (C) sk89q <http://www.sk89q.com>
4+
* Copyright (C) WorldGuard team and contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License as published by the
8+
* Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package com.sk89q.worldguard.domains;
21+
22+
import com.sk89q.worldguard.domains.registry.CustomDomainContext;
23+
import com.sk89q.worldguard.domains.registry.InvalidDomainFormat;
24+
25+
import java.util.Objects;
26+
import java.util.UUID;
27+
28+
public class CustomUUIDDomain extends CustomDomain {
29+
private UUID test;
30+
31+
public CustomUUIDDomain(String name, UUID test) {
32+
super(name);
33+
this.test = test;
34+
}
35+
36+
@Override
37+
public void parseInput(CustomDomainContext context) throws InvalidDomainFormat {
38+
throw new InvalidDomainFormat("not supported");
39+
}
40+
41+
@Override
42+
public void unmarshal(Object o) {
43+
}
44+
45+
@Override
46+
public Object marshal() {
47+
return null;
48+
}
49+
50+
@Override
51+
public boolean contains(UUID uniqueId) {
52+
return Objects.equals(test, uniqueId);
53+
}
54+
55+
@Override
56+
public boolean contains(String playerName) {
57+
return false;
58+
}
59+
60+
@Override
61+
public void clear() {
62+
test = null;
63+
}
64+
}

worldguard-core/src/test/java/com/sk89q/worldguard/domains/DefaultDomainTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,11 @@ public void testContains() throws Exception {
112112
assertFalse(domain.contains(player1));
113113
assertTrue(domain.contains(player2));
114114
assertTrue(domain.contains(player3));
115+
116+
domain = new DefaultDomain();
117+
domain.addCustomDomain(new CustomUUIDDomain("test", player2.getUniqueId()));
118+
assertTrue(domain.contains(player2));
119+
assertFalse(domain.contains(player2.getName()));
120+
assertFalse(domain.contains(player3));
115121
}
116122
}

0 commit comments

Comments
 (0)