Cleaned up AnvilGUI integration

This commit is contained in:
Auxilor 2020-12-11 18:21:50 +00:00
parent 7c72d388e6
commit 2d11d614ab
5 changed files with 4 additions and 80 deletions

View File

@ -2,7 +2,7 @@ package com.willfp.ecoenchants.enchantments.support.merging.anvil;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.integrations.anvilgui.AnvilGUIManager;
import com.willfp.ecoenchants.nms.OpenInventory;
import com.willfp.ecoenchants.nms.RepairCost;
import com.willfp.ecoenchants.util.NumberUtils;
import com.willfp.ecoenchants.util.tuplets.Pair;
@ -21,6 +21,7 @@ import java.util.UUID;
public class AnvilListeners implements Listener {
private static final HashMap<UUID, Integer> noIncreaseXpMap = new HashMap<>();
private static final String ANVIL_GUI_CLASS = "net.wesjd.anvilgui.version.Wrapper" + EcoEnchantsPlugin.NMS_VERSION.substring(1) + "$AnvilContainer";
@EventHandler(priority = EventPriority.HIGHEST)
public void onAnvilPrepare(PrepareAnvilEvent event) {
@ -35,7 +36,8 @@ public class AnvilListeners implements Listener {
if(event.getViewers().isEmpty()) return; // Prevent ArrayIndexOutOfBoundsException when using AnvilGUI
Player player = (Player) event.getViewers().get(0);
if(AnvilGUIManager.hasAnvilGUIOpen(player)) return;
if(OpenInventory.getOpenInventory(player).getClass().toString().equals(ANVIL_GUI_CLASS))
return;
Pair<ItemStack, Integer> newOut = AnvilMerge.doMerge(left, right, out, name, player);

View File

@ -1,17 +0,0 @@
package com.willfp.ecoenchants.integrations.anvilgui;
import com.willfp.ecoenchants.integrations.Integration;
/**
* Interface for AnvilGUI integrations
*/
public interface AnvilGUIIntegration extends Integration {
/**
* Get if the NMS inventory is an instance of an AnvilGUI
*
* @param object The NMS inventory to check
* @return If the object is an AnvilGUI
* @see com.willfp.ecoenchants.nms.OpenInventory
*/
boolean isInstance(Object object);
}

View File

@ -1,35 +0,0 @@
package com.willfp.ecoenchants.integrations.anvilgui;
import com.willfp.ecoenchants.nms.OpenInventory;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
/**
* Utility class for interfacing with plugins that use WesJD's AnvilGUI library
*/
public class AnvilGUIManager {
private static final Set<AnvilGUIIntegration> integrations = new HashSet<>();
/**
* Register a new AnvilGUI integration
*
* @param integration The integration to register
*/
public static void registerIntegration(AnvilGUIIntegration integration) {
integrations.add(integration);
}
/**
* Get if a player's open inventory is an AnvilGUI
*
* @param player The player to check
* @return If the player's open inventory is an AnvilGUI
*/
public static boolean hasAnvilGUIOpen(Player player) {
if (integrations.isEmpty())
return false;
return integrations.stream().anyMatch(integration -> integration.isInstance(OpenInventory.getOpenInventory(player)));
}
}

View File

@ -1,21 +0,0 @@
package com.willfp.ecoenchants.integrations.anvilgui.plugins;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.integrations.anvilgui.AnvilGUIIntegration;
/**
* Concrete implementation of {@link AnvilGUIIntegration}
*/
public class AnvilGUIImpl implements AnvilGUIIntegration {
private static final String ANVIL_GUI_CLASS = "net.wesjd.anvilgui.version.Wrapper" + EcoEnchantsPlugin.NMS_VERSION.substring(1) + "$AnvilContainer";
@Override
public boolean isInstance(Object object) {
return object.getClass().toString().equals(ANVIL_GUI_CLASS);
}
@Override
public String getPluginName() {
return "AnvilGUI";
}
}

View File

@ -39,8 +39,6 @@ import com.willfp.ecoenchants.integrations.antigrief.plugins.AntigriefKingdoms;
import com.willfp.ecoenchants.integrations.antigrief.plugins.AntigriefLands;
import com.willfp.ecoenchants.integrations.antigrief.plugins.AntigriefTowny;
import com.willfp.ecoenchants.integrations.antigrief.plugins.AntigriefWorldGuard;
import com.willfp.ecoenchants.integrations.anvilgui.AnvilGUIManager;
import com.willfp.ecoenchants.integrations.anvilgui.plugins.AnvilGUIImpl;
import com.willfp.ecoenchants.integrations.essentials.EssentialsManager;
import com.willfp.ecoenchants.integrations.essentials.plugins.IntegrationEssentials;
import com.willfp.ecoenchants.integrations.mcmmo.McmmoManager;
@ -226,9 +224,6 @@ public class Loader {
}));
Prerequisite.update();
AnvilGUIManager.registerIntegration(new AnvilGUIImpl()); // No direct lib, can always register
Logger.info("");
/*