From 82107d0bc8b7fe52501ef2fae5c53d0aed695bde Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 13 Jun 2019 16:03:38 +0200 Subject: [PATCH] Disable BetterBrushes BetterBrushes is a neat addition for builders, unfortunately it's outdated, therefore the few features have been migrated into FAVS. --- .../thevoxelbox/voxelsniper/VoxelSniper.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java index 0a80f6174..1af02afad 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniper.java @@ -1,5 +1,6 @@ package com.thevoxelbox.voxelsniper; +import com.boydti.fawe.Fawe; import com.boydti.fawe.bukkit.BukkitCommand; import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FawePlayer; @@ -8,9 +9,17 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + /** * Bukkit extension point. */ @@ -55,7 +64,42 @@ public class VoxelSniper extends JavaPlugin { return sniperManager; } - @Override + private static Map lookupNames; + static { + { // Disable BetterBrushes - FAVS includes the features and BetterBrushes is outdated + PluginManager manager = Bukkit.getPluginManager(); + try { + Field pluginsField = manager.getClass().getDeclaredField("plugins"); + Field lookupNamesField = manager.getClass().getDeclaredField("lookupNames"); + pluginsField.setAccessible(true); + lookupNamesField.setAccessible(true); + List plugins = (List) pluginsField.get(manager); + lookupNames = (Map) lookupNamesField.get(manager); + pluginsField.set(manager, new ArrayList(plugins) { + @Override + public boolean add(Plugin plugin) { + if (plugin.getName().startsWith("BetterBrushes")) { + Fawe.debug("Disabling `" + plugin.getName() + "`. FastAsyncVoxelSniper includes all the features."); + } else { + return super.add(plugin); + } + return false; + } + }); + lookupNamesField.set(manager, lookupNames = new ConcurrentHashMap(lookupNames) { + @Override + public Plugin put(@NotNull String key, @NotNull Plugin plugin) { + if (plugin.getName().startsWith("BetterBrushes")) { + return null; + } + return super.put(key, plugin); + } + }); + } catch (Throwable ignore) {} + } + } + + @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, String commandLabel, @NotNull String[] args) { if (sender instanceof Player) {