Skip to content

Commit ccffaa9

Browse files
committed
BugFix: Fix unbinding player_move to unbind multiple player_move events if no threshold prefilter is supplied
When binding multiple player_move events without threshold prefilter and then unbinding one of those events, all events would not trigger anymore until another event with the default treshold prefilter would be bound. This bug is caused by the unbind code removing the default threshold without checking whether more events still use it.
1 parent 1fecd28 commit ccffaa9

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import com.laytonsmith.core.events.BoundEvent.ActiveEvent;
6262
import com.laytonsmith.core.events.Driver;
6363
import com.laytonsmith.core.events.EventBuilder;
64-
import com.laytonsmith.core.events.EventUtils;
6564
import com.laytonsmith.core.events.Prefilters;
6665
import com.laytonsmith.core.events.Prefilters.PrefilterType;
6766
import com.laytonsmith.core.events.drivers.EntityEvents.entity_death;
@@ -78,7 +77,6 @@
7877
import java.util.ArrayList;
7978
import java.util.Arrays;
8079
import java.util.HashMap;
81-
import java.util.HashSet;
8280
import java.util.IllegalFormatConversionException;
8381
import java.util.List;
8482
import java.util.Map;
@@ -1876,10 +1874,10 @@ public boolean modifyEvent(String key, Construct value, BindableEvent event) {
18761874

18771875
}
18781876

1879-
private static final Set<Integer> THRESHOLD_LIST = new HashSet<>();
1877+
private static final Map<Integer, Integer> THRESHOLD_LIST = new HashMap<>();
18801878

18811879
public static Set<Integer> GetThresholdList() {
1882-
return THRESHOLD_LIST;
1880+
return THRESHOLD_LIST.keySet();
18831881
}
18841882

18851883
private static final Map<Integer, Map<String, MCLocation>> LAST_PLAYER_LOCATIONS = new HashMap<>();
@@ -1925,33 +1923,27 @@ public void hook() {
19251923

19261924
@Override
19271925
public void bind(BoundEvent event) {
1928-
int threshold = 1;
19291926
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));
19341931
}
19351932

19361933
@Override
19371934
public void unbind(BoundEvent event) {
1938-
int threshold = 1;
19391935
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);
19511945
}
19521946
}
1953-
THRESHOLD_LIST.remove(threshold);
1954-
LAST_PLAYER_LOCATIONS.remove(threshold);
19551947
}
19561948

19571949
@Override

0 commit comments

Comments
 (0)