Skip to content

Commit 44f7380

Browse files
committed
Cleanup DomainRegistry
1 parent b3ae14b commit 44f7380

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

worldguard-core/src/main/java/com/sk89q/worldguard/commands/region/MemberCommands.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
2727
import com.sk89q.worldedit.extension.platform.Actor;
2828
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
29-
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
3029
import com.sk89q.worldedit.util.formatting.text.Component;
3130
import com.sk89q.worldedit.util.formatting.text.TextComponent;
3231
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
@@ -35,11 +34,9 @@
3534
import com.sk89q.worldedit.world.World;
3635
import com.sk89q.worldguard.LocalPlayer;
3736
import com.sk89q.worldguard.WorldGuard;
38-
import com.sk89q.worldguard.domains.CustomDomain;
3937
import com.sk89q.worldguard.domains.DefaultDomain;
4038
import com.sk89q.worldguard.domains.registry.DomainFactory;
4139
import com.sk89q.worldguard.domains.registry.DomainRegistry;
42-
import com.sk89q.worldguard.domains.registry.InvalidDomainFormat;
4340
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
4441
import com.sk89q.worldguard.protection.managers.RegionManager;
4542
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public interface DomainRegistry extends Iterable<DomainFactory<?>> {
6262
@Nullable
6363
DomainFactory<?> get(String name);
6464

65+
/**
66+
* Try to get a domain by its name
67+
*/
68+
@Nullable
69+
CustomDomain createDomain(String name);
70+
6571
/**
6672
* Get all domains keyed by the registered name
6773
*

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,31 +100,37 @@ public DomainFactory<?> get(String name) {
100100
return domains.get(name.toLowerCase());
101101
}
102102

103+
@Nullable
104+
@Override
105+
public CustomDomain createDomain(String name) {
106+
DomainFactory<?> factory = get(name);
107+
if (factory == null) return null;
108+
return factory.create(name);
109+
}
110+
103111
@Override
104112
public Map<String, DomainFactory<?>> getAll() {
105113
return ImmutableMap.copyOf(domains);
106114
}
107115

108116
private CustomDomain getOrCreate(String name, Object value, boolean createUnknown) {
109-
DomainFactory<? extends CustomDomain> domainFactory = get(name);
117+
CustomDomain customDomain = createDomain(name);
110118

111-
if (domainFactory != null) {
112-
CustomDomain customDomain = domainFactory.create(name);
113-
if (customDomain != null) customDomain.unmarshal(value);
119+
if (customDomain != null) {
120+
customDomain.unmarshal(value);
114121
return customDomain;
115122
}
116123

117124
synchronized (lock) {
118-
domainFactory = get(name); // Load again because the previous load was not synchronized
119-
if (domainFactory != null) {
120-
CustomDomain customDomain = domainFactory.create(name);
121-
if (customDomain != null) customDomain.unmarshal(value);
125+
customDomain = createDomain(name); // Load again because the previous load was not synchronized
126+
if (customDomain != null) {
127+
customDomain.unmarshal(value);
122128
return customDomain;
123129
}
124130
if (createUnknown) {
125131
DomainFactory<UnknownDomain> unknownFactory = forceRegister(name, UnknownDomain.FACTORY);
126132
if (unknownFactory != null) {
127-
CustomDomain customDomain = unknownFactory.create(name);
133+
customDomain = unknownFactory.create(name);
128134
if (customDomain != null) customDomain.unmarshal(value);
129135
return customDomain;
130136
}

worldguard-core/src/main/java/com/sk89q/worldguard/protection/util/DomainInputResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ public DefaultDomain call() throws UnresolvedNamesException, InvalidDomainFormat
135135
domain.addGroup(groupMatcher.group(1));
136136
} else if (customMatcher.matches()) {
137137
String domainName = customMatcher.group(1);
138-
DomainFactory<?> domainFactory = WorldGuard.getInstance().getDomainRegistry().get(domainName);
139-
if (domainFactory == null) {
138+
CustomDomain customDomain = WorldGuard.getInstance().getDomainRegistry().createDomain(domainName);
139+
if (customDomain == null) {
140140
throw new InvalidDomainFormat("No domain named '" + domainName + "' found.");
141141
}
142-
CustomDomain customDomain = domainFactory.create(domainName);
143142
customDomain.parseInput(CustomDomainContext.create()
144143
.setSender(actor).setInput(customMatcher.group(2)).setObject("region", region).build());
145144
} else {

0 commit comments

Comments
 (0)