|
61 | 61 | import com.laytonsmith.core.events.BoundEvent.ActiveEvent; |
62 | 62 | import com.laytonsmith.core.events.Driver; |
63 | 63 | import com.laytonsmith.core.events.EventBuilder; |
64 | | -import com.laytonsmith.core.events.EventUtils; |
65 | 64 | import com.laytonsmith.core.events.Prefilters; |
66 | 65 | import com.laytonsmith.core.events.Prefilters.PrefilterType; |
67 | 66 | import com.laytonsmith.core.events.drivers.EntityEvents.entity_death; |
|
78 | 77 | import java.util.ArrayList; |
79 | 78 | import java.util.Arrays; |
80 | 79 | import java.util.HashMap; |
81 | | -import java.util.HashSet; |
82 | 80 | import java.util.IllegalFormatConversionException; |
83 | 81 | import java.util.List; |
84 | 82 | import java.util.Map; |
@@ -1876,10 +1874,10 @@ public boolean modifyEvent(String key, Construct value, BindableEvent event) { |
1876 | 1874 |
|
1877 | 1875 | } |
1878 | 1876 |
|
1879 | | - private static final Set<Integer> THRESHOLD_LIST = new HashSet<>(); |
| 1877 | + private static final Map<Integer, Integer> THRESHOLD_LIST = new HashMap<>(); |
1880 | 1878 |
|
1881 | 1879 | public static Set<Integer> GetThresholdList() { |
1882 | | - return THRESHOLD_LIST; |
| 1880 | + return THRESHOLD_LIST.keySet(); |
1883 | 1881 | } |
1884 | 1882 |
|
1885 | 1883 | private static final Map<Integer, Map<String, MCLocation>> LAST_PLAYER_LOCATIONS = new HashMap<>(); |
@@ -1925,33 +1923,27 @@ public void hook() { |
1925 | 1923 |
|
1926 | 1924 | @Override |
1927 | 1925 | public void bind(BoundEvent event) { |
1928 | | - int threshold = 1; |
1929 | 1926 | Map<String, Construct> prefilters = event.getPrefilter(); |
1930 | | - if(prefilters.containsKey("threshold")) { |
1931 | | - threshold = Static.getInt32(prefilters.get("threshold"), Target.UNKNOWN); |
1932 | | - } |
1933 | | - THRESHOLD_LIST.add(threshold); |
| 1927 | + int threshold = (prefilters.containsKey("threshold") |
| 1928 | + ? Static.getInt32(prefilters.get("threshold"), Target.UNKNOWN) : 1); |
| 1929 | + Integer count = THRESHOLD_LIST.get(threshold); |
| 1930 | + THRESHOLD_LIST.put(threshold, (count != null ? count + 1 : 1)); |
1934 | 1931 | } |
1935 | 1932 |
|
1936 | 1933 | @Override |
1937 | 1934 | public void unbind(BoundEvent event) { |
1938 | | - int threshold = 1; |
1939 | 1935 | Map<String, Construct> prefilters = event.getPrefilter(); |
1940 | | - if(prefilters.containsKey("threshold")) { |
1941 | | - threshold = Static.getInt32(prefilters.get("threshold"), Target.UNKNOWN); |
1942 | | - } |
1943 | | - for(BoundEvent b : EventUtils.GetEvents(event.getDriver())) { |
1944 | | - if(b.getId().equals(event.getId())) { |
1945 | | - continue; |
1946 | | - } |
1947 | | - if(b.getPrefilter().containsKey("threshold")) { |
1948 | | - if(threshold == Static.getInt(b.getPrefilter().get("threshold"), Target.UNKNOWN)) { |
1949 | | - return; |
1950 | | - } |
| 1936 | + int threshold = (prefilters.containsKey("threshold") |
| 1937 | + ? Static.getInt32(prefilters.get("threshold"), Target.UNKNOWN) : 1); |
| 1938 | + Integer count = THRESHOLD_LIST.get(threshold); |
| 1939 | + if(count != null) { |
| 1940 | + if(count <= 1) { |
| 1941 | + THRESHOLD_LIST.remove(threshold); |
| 1942 | + LAST_PLAYER_LOCATIONS.remove(threshold); |
| 1943 | + } else { |
| 1944 | + THRESHOLD_LIST.put(threshold, count - 1); |
1951 | 1945 | } |
1952 | 1946 | } |
1953 | | - THRESHOLD_LIST.remove(threshold); |
1954 | | - LAST_PLAYER_LOCATIONS.remove(threshold); |
1955 | 1947 | } |
1956 | 1948 |
|
1957 | 1949 | @Override |
|
0 commit comments