diff --git a/src/main/java/ch/njol/skript/registrations/EventValues.java b/src/main/java/ch/njol/skript/registrations/EventValues.java index d6956f32ee1..47b784d3ac2 100644 --- a/src/main/java/ch/njol/skript/registrations/EventValues.java +++ b/src/main/java/ch/njol/skript/registrations/EventValues.java @@ -82,7 +82,6 @@ public Class getValueClass() { * @return The classes of the Excludes associated with this event value */ @Nullable - @SuppressWarnings("null") public Class[] getExcludes() { if (excludes != null) return Arrays.copyOf(excludes, excludes.length); @@ -98,26 +97,26 @@ public String getExcludeErrorMessage() { return excludeErrorMessage; } } - + private final static List> defaultEventValues = new ArrayList<>(30); private final static List> futureEventValues = new ArrayList<>(); private final static List> pastEventValues = new ArrayList<>(); - + /** * The past time of an event value. Represented by "past" or "former". */ public static final int TIME_PAST = -1; - + /** * The current time of an event value. */ public static final int TIME_NOW = 0; - + /** * The future time of an event value. */ public static final int TIME_FUTURE = 1; - + /** * Get Event Values list for the specified time * @param time The time of the event values. One of @@ -127,7 +126,7 @@ public String getExcludeErrorMessage() { public static List> getEventValuesListForTime(int time) { return ImmutableList.copyOf(getEventValuesList(time)); } - + private static List> getEventValuesList(int time) { if (time == -1) return pastEventValues; @@ -242,7 +241,7 @@ public static T getEventValue(E e, Class c, int time) { * @return true or false if the event and type have multiple getters. */ public static Kleenean hasMultipleGetters(Class event, Class type, int time) { - List> getters = getEventValueGetters(event, type, time, true); + List> getters = getEventValueGetters(event, type, time, true, false); if (getters == null) return Kleenean.UNKNOWN; return Kleenean.get(getters.size() > 1); @@ -273,13 +272,18 @@ public static Kleenean hasMultipleGetters(Class event, C return list.get(0); } + @Nullable + private static List> getEventValueGetters(Class event, Class type, int time, boolean allowDefault) { + return getEventValueGetters(event, type, time, allowDefault, true); + } + /* * We need to be able to collect all possible event-values to a list for determining problematic collisions. * Always return after the loop check if the list is not empty. */ @Nullable @SuppressWarnings("unchecked") - private static List> getEventValueGetters(Class event, Class type, int time, boolean allowDefault) { + private static List> getEventValueGetters(Class event, Class type, int time, boolean allowDefault, boolean allowConverting) { List> eventValues = getEventValuesList(time); List> list = new ArrayList<>(); // First check for exact classes matching the parameters. @@ -313,6 +317,8 @@ public T get(E event) { } if (!list.isEmpty()) return list; + if (!allowConverting) + return null; // Most checks have returned before this below is called, but Skript will attempt to convert or find an alternative. // Third check is if the returned object matches the class. for (EventValueInfo eventValueInfo : eventValues) { @@ -361,11 +367,11 @@ public T get(E event) { // The requesting event must be assignable to the event value's event. Otherwise it'll throw an error. if (!event.isAssignableFrom(eventValueInfo.event)) continue; - + Getter getter = (Getter) getConvertedGetter(eventValueInfo, type, true); if (getter == null) continue; - + if (!checkExcludes(eventValueInfo, event)) return null; list.add(getter);