Using copy on write set instead
@@ -2,7 +2,6 @@ package com.matt.forgehax.asm.utils;
import com.google.common.collect.Sets;
-import java.util.Collections;
import java.util.Set;
/**
@@ -12,7 +11,7 @@ public class MultiBoolean {
/**
* A list of unique string ids so that one mod cannot increment the level more than once.
*/
- private final Set<String> ids = Collections.synchronizedSet(Sets.newHashSet());
+ private final Set<String> ids = Sets.newCopyOnWriteArraySet();
private int level = 0;
private void clampLevel() {
@@ -24,37 +23,31 @@ public class MultiBoolean {
* @param uniqueId id used to identify this increment
*/
public void enable(String uniqueId) {
- synchronized (ids) {
if(ids.add(uniqueId)) {
++level;
clampLevel();
}
}
- }
/**
* Disables this object for the specific id
* @param uniqueId unique id
*/
public void disable(String uniqueId) {
- synchronized (ids) {
if(ids.remove(uniqueId)) {
--level;
clampLevel();
}
}
- }
/**
* Will clear the id list and set the level to zero, disabling this object
* Do not use this unless it's absolutely necessary
*/
public void forceDisable() {
- synchronized (ids) {
level = 0;
ids.clear();
}
- }
/**
* Check if the object is enabled
