Add AdvancementEvent to forgeToSpongeEventMapping
Add some documentation explaining the purpose of this map
import net.minecraftforge.event.entity.living.ZombieEvent;
import net.minecraftforge.event.entity.minecart.MinecartCollisionEvent;
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
+import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import org.spongepowered.api.event.world.chunk.LoadChunkEvent;
import org.spongepowered.api.plugin.PluginManager;
import org.spongepowered.common.event.RegisteredListener;
+import org.spongepowered.common.event.ShouldFire;
import org.spongepowered.common.event.SpongeEventManager;
import org.spongepowered.mod.SpongeMod;
import org.spongepowered.mod.interfaces.IMixinASMEventHandler;
Class<? extends Event>[] spawnEntityEvent = new Class[] {SpawnEntityEvent.ChunkLoad.class, SpawnEntityEvent.Spawner.class};
@SuppressWarnings("unchecked")
+ /**
+ * A mapping from Forge events to corresponding Sponge events.
+ *
+ * This mapping is used to keep the {@link ShouldFire} flags up-to-date.
+ * If a Forge mod registers an event listener for any of the Forge evnt
+ * classes in this map, the {@link ShouldFire} flags for the corresponding Sponge
+ * event will be enabled.
+ *
+ * For example, a mod listener for Forge's {@link ItemExpireEvent} will,
+ * for the purposes of {@link ShouldFire}, be treated as though a plugin
+ * has registered a listener for Sponge's {@link DestructEntityEvent.Death}.
+ * THis ensures that any Sponge code firing a {@link DestructEntityEvent.Death} and
+ * checking {@link ShouldFire} will continue to do so, even if only Forge listeners
+ * are registered.
+ *
+ * Forge events should be mapped to the most specific Sponge events that they correspond
+ * to. For example, {@link LivingEntityUseItemEvent} is mapped to all of the subinterfaces
+ * of Sponge's {@link UseItemStackEvent}, even though not all of them may actually cause a Forge
+ * event to be fired.
+ *
+ * Overall, the goal is to avoid any false negatives. False positives - mapping a Forge event
+ * to a Sponge event that doesn't actually cause it to be fired - will simply cause some
+ * {@link ShouldFire} flags to be unecessaryily <code>true</code>, making the server slightly less efficient
+ * than it could otherwise be. False negatives, on the other hand, mean that events won't be fired even
+ * though a mod is listening for them.
+ */
public final ImmutableMultimap<Class<? extends net.minecraftforge.fml.common.eventhandler.Event>, Class<? extends Event>>
forgeToSpongeEventMapping =
new ImmutableMultimap.Builder<Class<? extends net.minecraftforge.fml.common.eventhandler.Event>, Class<? extends Event>>()
.putAll(PlayerEvent.PlayerLoggedInEvent.class, ClientConnectionEvent.Auth.class, ClientConnectionEvent.Login.class, ClientConnectionEvent.Join.class)
.put(PlayerEvent.PlayerLoggedOutEvent.class, ClientConnectionEvent.Disconnect.class)
.put(PlayerEvent.PlayerChangedDimensionEvent.class, MoveEntityEvent.Teleport.Portal.class)
+ .put(AdvancementEvent.class, org.spongepowered.api.event.advancement.AdvancementEvent.Grant.class)
.build();
