Skip to content

Commit

Permalink
[1.9.5]修复paper端情况下会导致其他插件铁砧和切石机逻辑异常的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Jun 7, 2024
1 parent fa2ddde commit ae82a5a
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.9.4"
version = "1.9.5"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import com.github.yufiriamazenta.craftorithm.config.PluginConfigs;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.listener.ItemsAdderHandler;
import com.github.yufiriamazenta.craftorithm.listener.OtherPluginsListenerHandler;
import com.github.yufiriamazenta.craftorithm.listener.OtherPluginsListenerProxy;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.util.UpdateUtil;
import crypticlib.BukkitPlugin;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -34,7 +33,7 @@ public void enable() {
initArcenciel();
loadBStat();

Bukkit.getPluginManager().registerEvents(OtherPluginsListenerHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(OtherPluginsListenerProxy.INSTANCE, this);
PluginHookUtil.hookPlugins();
LangUtil.info(Languages.LOAD_FINISH);
}
Expand Down Expand Up @@ -78,7 +77,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
public void onServerLoad(ServerLoadEvent event) {
if (!PluginHookUtil.isItemsAdderLoaded()) {
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerHandler.INSTANCE.reloadOtherPluginsListener();
OtherPluginsListenerProxy.INSTANCE.reloadOtherPluginsListener();
return;
}
Bukkit.getPluginManager().registerEvents(ItemsAdderHandler.INSTANCE, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.github.yufiriamazenta.craftorithm.config.Languages;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.item.impl.CraftorithmItemProvider;
import com.github.yufiriamazenta.craftorithm.listener.OtherPluginsListenerHandler;
import com.github.yufiriamazenta.craftorithm.listener.OtherPluginsListenerProxy;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.util.ItemUtils;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
Expand Down Expand Up @@ -38,7 +38,7 @@ public static void reloadPlugin() {
CraftorithmItemProvider.INSTANCE.reloadItemProvider();
ItemManager.INSTANCE.reloadCustomCookingFuel();
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerHandler.INSTANCE.reloadOtherPluginsListener();
OtherPluginsListenerProxy.INSTANCE.reloadOtherPluginsListener();
}

public static void reloadConfigs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum ItemsAdderHandler implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onItemsAdderLoaded(ItemsAdderLoadDataEvent event) {
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerHandler.INSTANCE.reloadOtherPluginsListener();
OtherPluginsListenerProxy.INSTANCE.reloadOtherPluginsListener();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum OraxenHandler implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onOraxenLoaded(OraxenItemsLoadedEvent event) {
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerHandler.INSTANCE.reloadOtherPluginsListener();
OtherPluginsListenerProxy.INSTANCE.reloadOtherPluginsListener();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.github.yufiriamazenta.craftorithm.listener;

import crypticlib.CrypticLib;
import crypticlib.listener.BukkitListener;
import crypticlib.platform.IPlatform;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareGrindstoneEvent;
import org.bukkit.plugin.RegisteredListener;

import java.util.List;

/**
* 因为Grindstone在1.19才有,所以要独立出来
*/
@BukkitListener
public enum OtherPluginsGrindstoneListenerProxy implements Listener {

INSTANCE;

@EventHandler(priority = EventPriority.LOWEST)
public void proxyLowestPrepareGrindstone(PrepareGrindstoneEvent event) {
proxyPrepareGrindstone(event, EventPriority.LOWEST);
}

@EventHandler(priority = EventPriority.LOW)
public void proxyLowPrepareGrindstone(PrepareGrindstoneEvent event) {
proxyPrepareGrindstone(event, EventPriority.LOW);
}

@EventHandler(priority = EventPriority.NORMAL)
public void proxyNormalPrepareGrindstone(PrepareGrindstoneEvent event) {
proxyPrepareGrindstone(event, EventPriority.NORMAL);
}

@EventHandler(priority = EventPriority.HIGH)
public void proxyHighPrepareGrindstone(PrepareGrindstoneEvent event) {
proxyPrepareGrindstone(event, EventPriority.HIGH);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void proxyHighestPrepareGrindstone(PrepareGrindstoneEvent event) {
proxyPrepareGrindstone(event, EventPriority.HIGHEST);
}


@EventHandler(priority = EventPriority.MONITOR)
public void proxyMonitorPrepareGrindstone(PrepareGrindstoneEvent event) {
proxyPrepareGrindstone(event, EventPriority.MONITOR);
}

public void proxyPrepareGrindstone(PrepareGrindstoneEvent event, EventPriority priority) {
//因为只有paper及下游服务端才有这个问题,如果识别到是bukkit或者spigot,就不用处理
if (CrypticLib.platform().platform().equals(IPlatform.Platform.BUKKIT)) {
return;
}
OtherPluginsListenerProxy proxy = OtherPluginsListenerProxy.INSTANCE;
List<RegisteredListener> registeredListeners = proxy.getPrepareItemCraftEventListeners().get(priority);
if (registeredListeners == null || registeredListeners.isEmpty()) {
return;
}
proxy.executeListener(event, registeredListeners);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.yufiriamazenta.craftorithm.listener;

import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import crypticlib.CrypticLib;
import crypticlib.platform.IPlatform;
import crypticlib.util.ReflectUtil;
import org.bukkit.NamespacedKey;
import org.bukkit.event.*;
Expand All @@ -16,14 +18,14 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public enum OtherPluginsListenerHandler implements Listener {
public enum OtherPluginsListenerProxy implements Listener {

INSTANCE;
private final Field executorField = ReflectUtil.getDeclaredField(RegisteredListener.class, "executor");
private final Map<EventPriority, List<RegisteredListener>> prepareItemCraftEventListeners = new ConcurrentHashMap<>();
//因为CraftItemEvent与SmithItemEvent的handler list与InventoryClickEvent共享,所以只能放在一起
private final Map<EventPriority, List<RegisteredListener>> inventoryClickEventListeners = new ConcurrentHashMap<>();
private final Map<EventPriority, List<RegisteredListener>> prePareSmithingItemEventListeners = new ConcurrentHashMap<>();
private final Map<EventPriority, List<RegisteredListener>> prepareSmithingItemEventListeners = new ConcurrentHashMap<>();
private final Map<EventPriority, List<RegisteredListener>> furnaceSmeltListeners = new ConcurrentHashMap<>();
private final Map<EventPriority, List<RegisteredListener>> blockCookListeners = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -61,7 +63,7 @@ private void loadProxyInventoryClickEventListeners() {

private void loadProxyPrepareSmithingItemEventListeners() {
for (RegisteredListener registeredListener : PrepareSmithingEvent.getHandlerList().getRegisteredListeners()) {
if (addListenerCache(registeredListener, prePareSmithingItemEventListeners)) {
if (addListenerCache(registeredListener, prepareSmithingItemEventListeners)) {
PrepareSmithingEvent.getHandlerList().unregister(registeredListener);
}
}
Expand Down Expand Up @@ -226,7 +228,7 @@ public void proxyMonitorPrepareSmithing(PrepareSmithingEvent event) {
}

private void proxyPrepareSmithing(PrepareSmithingEvent event, EventPriority eventPriority) {
List<RegisteredListener> registeredListeners = prePareSmithingItemEventListeners.get(eventPriority);
List<RegisteredListener> registeredListeners = prepareSmithingItemEventListeners.get(eventPriority);
if (registeredListeners == null) {
return;
}
Expand All @@ -243,6 +245,52 @@ private void proxyPrepareSmithing(PrepareSmithingEvent event, EventPriority even
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void proxyLowestPrepareAnvil(PrepareAnvilEvent event) {
proxyPrepareAnvil(event, EventPriority.LOWEST);
}

@EventHandler(priority = EventPriority.LOW)
public void proxyLowPrepareAnvil(PrepareAnvilEvent event) {
proxyPrepareAnvil(event, EventPriority.LOW);
}

@EventHandler(priority = EventPriority.NORMAL)
public void proxyNormalPrepareAnvil(PrepareAnvilEvent event) {
proxyPrepareAnvil(event, EventPriority.NORMAL);
}

@EventHandler(priority = EventPriority.HIGH)
public void proxyHighPrepareAnvil(PrepareAnvilEvent event) {
proxyPrepareAnvil(event, EventPriority.HIGH);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void proxyHighestPrepareAnvil(PrepareAnvilEvent event) {
proxyPrepareAnvil(event, EventPriority.HIGHEST);
}

@EventHandler(priority = EventPriority.MONITOR)
public void proxyMonitorPrepareAnvil(PrepareAnvilEvent event) {
proxyPrepareAnvil(event, EventPriority.MONITOR);
}

private void proxyPrepareAnvil(PrepareAnvilEvent event, EventPriority eventPriority) {
//因为只有paper及下游服务端才有这个问题,如果识别到是bukkit或者spigot,就不用处理
if (CrypticLib.platform().platform().equals(IPlatform.Platform.BUKKIT)) {
return;
}
List<RegisteredListener> registeredListeners = prepareSmithingItemEventListeners.get(eventPriority);
if (registeredListeners == null) {
return;
}
if (registeredListeners.isEmpty()) {
return;
}
executeListener(event, registeredListeners);
}


@EventHandler(priority = EventPriority.LOWEST)
public void proxyLowestSmithItem(SmithItemEvent event) {
proxySmithItem(event, EventPriority.LOWEST);
Expand Down Expand Up @@ -440,4 +488,23 @@ public void executeListener(Event event, List<RegisteredListener> registeredList
}
}

public Map<EventPriority, List<RegisteredListener>> getPrepareItemCraftEventListeners() {
return prepareItemCraftEventListeners;
}

public Map<EventPriority, List<RegisteredListener>> getInventoryClickEventListeners() {
return inventoryClickEventListeners;
}

public Map<EventPriority, List<RegisteredListener>> getPrepareSmithingItemEventListeners() {
return prepareSmithingItemEventListeners;
}

public Map<EventPriority, List<RegisteredListener>> getFurnaceSmeltListeners() {
return furnaceSmeltListeners;
}

public Map<EventPriority, List<RegisteredListener>> getBlockCookListeners() {
return blockCookListeners;
}
}

0 comments on commit ae82a5a

Please sign in to comment.