3636import java .util .ArrayList ;
3737import java .util .Collection ;
3838import java .util .Collections ;
39- import java .util .HashSet ;
4039import java .util .Iterator ;
4140import java .util .List ;
4241import java .util .Map ;
4342import java .util .Set ;
4443import java .util .UUID ;
44+ import java .util .concurrent .ConcurrentHashMap ;
4545
4646import static com .google .common .base .Preconditions .checkNotNull ;
4747
@@ -53,7 +53,7 @@ public class DefaultDomain implements Domain, ChangeTracked {
5353 private PlayerDomain playerDomain = new PlayerDomain ();
5454 private GroupDomain groupDomain = new GroupDomain ();
5555
56- private Set < CustomDomain > customDomains = new HashSet <>();
56+ private final Map < String , CustomDomain > customDomains = new ConcurrentHashMap <>();
5757 private boolean customDomainsChanged = false ;
5858
5959 /**
@@ -70,7 +70,7 @@ public DefaultDomain() {
7070 public DefaultDomain (DefaultDomain existing ) {
7171 setPlayerDomain (existing .getPlayerDomain ());
7272 setGroupDomain (existing .getGroupDomain ());
73- setCustomDomains (existing .getCustomDomains () );
73+ setCustomDomains (existing .customDomains );
7474 }
7575
7676 /**
@@ -118,9 +118,8 @@ public void setGroupDomain(GroupDomain groupDomain) {
118118 */
119119 public void addCustomDomain (CustomDomain customDomain ) {
120120 checkNotNull (customDomain );
121- removeCustomDomain (customDomain .getName ());
122- this .customDomains .add (customDomain );
123- customDomainsChanged = true ;
121+ this .customDomains .put (customDomain .getName (), customDomain );
122+ this .customDomainsChanged = true ;
124123 }
125124
126125 /**
@@ -130,8 +129,8 @@ public void addCustomDomain(CustomDomain customDomain) {
130129 */
131130 public void removeCustomDomain (String name ) {
132131 checkNotNull (name );
133- if (this .customDomains .removeIf ( d -> d . getName (). equalsIgnoreCase ( name )) ) {
134- customDomainsChanged = true ;
132+ if (this .customDomains .remove ( name ) != null ) {
133+ this . customDomainsChanged = true ;
135134 }
136135 }
137136
@@ -142,8 +141,8 @@ public void removeCustomDomain(String name) {
142141 */
143142 public void removeCustomDomain (CustomDomain customDomain ) {
144143 checkNotNull (customDomain );
145- if (this .customDomains .remove (customDomain ) ) {
146- customDomainsChanged = true ;
144+ if (this .customDomains .remove (customDomain . getName ()) != null ) {
145+ this . customDomainsChanged = true ;
147146 }
148147 }
149148
@@ -152,19 +151,30 @@ public void removeCustomDomain(CustomDomain customDomain) {
152151 *
153152 * @param customDomains the domains
154153 */
155- public void setCustomDomains (Collection < CustomDomain > customDomains ) {
154+ public void setCustomDomains (Map < String , CustomDomain > customDomains ) {
156155 checkNotNull (customDomains );
157- this .customDomains = new HashSet <>(customDomains );
158- customDomainsChanged = true ;
156+ this .customDomains .clear ();
157+ this .customDomains .putAll (customDomains );
158+ this .customDomainsChanged = true ;
159159 }
160160
161161 /**
162162 * Get all api domains
163163 *
164164 * @return a unmodifiable copy of the domains
165165 */
166- public Set <CustomDomain > getCustomDomains () {
167- return Collections .unmodifiableSet (this .customDomains );
166+ public Collection <CustomDomain > getCustomDomains () {
167+ return Collections .unmodifiableCollection (this .customDomains .values ());
168+ }
169+
170+ /**
171+ * Get the api domain specified by its name
172+ *
173+ * @param name the name of the domain
174+ * @return the custom domain
175+ */
176+ public @ Nullable CustomDomain getCustomDomain (String name ) {
177+ return this .customDomains .get (name );
168178 }
169179
170180 /**
@@ -311,12 +321,12 @@ public Set<String> getGroups() {
311321
312322 @ Override
313323 public boolean contains (LocalPlayer player ) {
314- return playerDomain .contains (player ) || groupDomain .contains (player ) || customDomains .stream ().anyMatch (d -> d .contains (player ));
324+ return playerDomain .contains (player ) || groupDomain .contains (player ) || customDomains .values (). stream ().anyMatch (d -> d .contains (player ));
315325 }
316326
317327 @ Override
318328 public boolean contains (UUID uniqueId ) {
319- return playerDomain .contains (uniqueId ) || customDomains .stream ().anyMatch (d -> d .contains (uniqueId ));
329+ return playerDomain .contains (uniqueId ) || customDomains .values (). stream ().anyMatch (d -> d .contains (uniqueId ));
320330 }
321331
322332 @ Override
@@ -384,7 +394,7 @@ public String toGroupsString() {
384394
385395 public String toCustomDomainsString () {
386396 List <String > output = new ArrayList <>();
387- for (CustomDomain customDomain : customDomains ) {
397+ for (CustomDomain customDomain : customDomains . values () ) {
388398 output .add (customDomain .getName () + ":" + customDomain .toString ());
389399 }
390400 output .sort (String .CASE_INSENSITIVE_ORDER );
@@ -513,7 +523,7 @@ private Component toPlayersComponent(ProfileCache cache) {
513523
514524 private Component toCustomDomainsComponent () {
515525 final TextComponent .Builder builder = TextComponent .builder ("" );
516- for (Iterator <CustomDomain > it = customDomains .iterator (); it .hasNext (); ) {
526+ for (Iterator <CustomDomain > it = customDomains .values (). iterator (); it .hasNext (); ) {
517527 CustomDomain domain = it .next ();
518528 builder .append (TextComponent .of (domain .getName () + ":" , TextColor .LIGHT_PURPLE ))
519529 .append (TextComponent .of (domain .toString (), TextColor .GOLD ));
@@ -528,15 +538,15 @@ private Component toCustomDomainsComponent() {
528538 @ Override
529539 public boolean isDirty () {
530540 return playerDomain .isDirty () || groupDomain .isDirty () ||
531- customDomainsChanged || customDomains .stream ().anyMatch (ChangeTracked ::isDirty );
541+ customDomainsChanged || customDomains .values (). stream ().anyMatch (ChangeTracked ::isDirty );
532542 }
533543
534544 @ Override
535545 public void setDirty (boolean dirty ) {
536546 playerDomain .setDirty (dirty );
537547 groupDomain .setDirty (dirty );
538548 customDomainsChanged = dirty ;
539- customDomains .forEach (d -> d .setDirty (dirty ));
549+ customDomains .values (). forEach (d -> d .setDirty (dirty ));
540550 }
541551
542552 @ Override
0 commit comments