mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Cleaned up AnvilGUI integration
This commit is contained in:
parent
7c72d388e6
commit
2d11d614ab
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -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)));
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
@ -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("");
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user