public LegacyJavaFixer() { @SuppressWarnings("unchecked") ListIterator<ITweaker> itr = ((List<ITweaker>)Launch.blackboard.get("Tweaks")).listIterator(); ITweaker replacement = new SortReplacement(); while (itr.hasNext()) { ITweaker t = itr.next(); FMLRelaunchLog.log.info("[LegacyJavaFixer] Tweaker: " + t); if (t instanceof FMLInjectionAndSortingTweaker) { itr.set(replacement); FMLRelaunchLog.info("[LegacyJavaFixer] Replacing tweaker %s with %s", t, replacement); } } }
@Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { if (!hasRun) { FMLRelaunchLog.log.info("[LegacyJavaFixer] Replacing sort"); sort(); URL is = FMLInjectionAndSortingTweaker.class.getResource("/cpw/mods/fml/common/launcher/TerminalTweaker.class"); if (is != null) { FMLRelaunchLog.log.info("[LegacyJavaFixer] Detected TerminalTweaker"); @SuppressWarnings("unchecked") List<String> newTweaks = (List<String>) Launch.blackboard.get("TweakClasses"); newTweaks.add("cpw.mods.fml.common.launcher.TerminalTweaker"); } } hasRun = true; }
public static void injectCoreModTweaks(FMLInjectionAndSortingTweaker fmlInjectionAndSortingTweaker) { @SuppressWarnings("unchecked") List<ITweaker> tweakers = (List<ITweaker>) Launch.blackboard.get("Tweaks"); // Add the sorting tweaker first- it'll appear twice in the list tweakers.add(0, fmlInjectionAndSortingTweaker); for (FMLPluginWrapper wrapper : loadPlugins) { tweakers.add(wrapper); } }
public static void injectCoreModTweaks(FMLInjectionAndSortingTweaker fmlInjectionAndSortingTweaker) { List<ITweaker> tweakers = (List<ITweaker>) Launch.blackboard.get("Tweaks"); // Add the sorting tweaker first- it'll appear twice in the list tweakers.add(0, fmlInjectionAndSortingTweaker); for (FMLPluginWrapper wrapper : loadPlugins) { tweakers.add(wrapper); } }
public static void sortTweakList() { @SuppressWarnings("unchecked") List<ITweaker> tweakers = (List<ITweaker>) Launch.blackboard.get("Tweaks"); // Basically a copy of Collections.sort pre 8u20, optimized as we know we're an array list. // Thanks unhelpful fixer of http://bugs.java.com/view_bug.do?bug_id=8032636 ITweaker[] toSort = tweakers.toArray(new ITweaker[tweakers.size()]); Arrays.sort(toSort, new Comparator<ITweaker>() { @Override public int compare(ITweaker o1, ITweaker o2) { Integer first = null; Integer second = null; if (o1 instanceof FMLInjectionAndSortingTweaker) { first = Integer.MIN_VALUE; } if (o2 instanceof FMLInjectionAndSortingTweaker) { second = Integer.MIN_VALUE; } if (o1 instanceof FMLPluginWrapper) { first = ((FMLPluginWrapper) o1).sortIndex; } else if (first == null) { first = tweakSorting.get(o1.getClass().getName()); } if (o2 instanceof FMLPluginWrapper) { second = ((FMLPluginWrapper) o2).sortIndex; } else if (second == null) { second = tweakSorting.get(o2.getClass().getName()); } if (first == null) { first = 0; } if (second == null) { second = 0; } return Ints.saturatedCast((long)first - (long)second); } }); // Basically a copy of Collections.sort, optimized as we know we're an array list. // Thanks unhelpful fixer of http://bugs.java.com/view_bug.do?bug_id=8032636 for (int j = 0; j < toSort.length; j++) { tweakers.set(j, toSort[j]); } }
public static void sortTweakList() { @SuppressWarnings("unchecked") List<ITweaker> tweakers = (List<ITweaker>) Launch.blackboard.get("Tweaks"); Collections.sort(tweakers, new Comparator<ITweaker>() { @Override public int compare(ITweaker o1, ITweaker o2) { Integer first = null; Integer second = null; if (o1 instanceof FMLInjectionAndSortingTweaker) { first = Integer.MIN_VALUE; } if (o2 instanceof FMLInjectionAndSortingTweaker) { second = Integer.MIN_VALUE; } if (o1 instanceof FMLPluginWrapper) { first = ((FMLPluginWrapper) o1).sortIndex; } else if (first == null) { first = tweakSorting.get(o1.getClass().getName()); } if (o2 instanceof FMLPluginWrapper) { second = ((FMLPluginWrapper) o2).sortIndex; } else if (second == null) { second = tweakSorting.get(o2.getClass().getName()); } if (first == null) { first = 0; } if (second == null) { second = 0; } return Ints.saturatedCast((long)first - (long)second); } }); }
public static void sortTweakList() { List<ITweaker> tweakers = (List<ITweaker>) Launch.blackboard.get("Tweaks"); Collections.sort(tweakers, new Comparator<ITweaker>() { @Override public int compare(ITweaker o1, ITweaker o2) { Integer first = null; Integer second = null; if (o1 instanceof FMLInjectionAndSortingTweaker) { first = Integer.MIN_VALUE; } if (o2 instanceof FMLInjectionAndSortingTweaker) { second = Integer.MIN_VALUE; } if (o1 instanceof FMLPluginWrapper) { first = ((FMLPluginWrapper) o1).sortIndex; } else if (first == null) { first = tweakSorting.get(o1.getClass().getName()); } if (o2 instanceof FMLPluginWrapper) { second = ((FMLPluginWrapper) o2).sortIndex; } else if (second == null) { second = tweakSorting.get(o2.getClass().getName()); } if (first == null) { first = 0; } if (second == null) { second = 0; } return Ints.saturatedCast((long)first - (long)second); } }); }