-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Several platform-related improvements
* Use Sponge register listener with lookup API if possible. Leverage SpongePowered/SpongeAPI#2441 if available. Otherwise fallback to method scanning and warn user. * Implement AlwaysAvailableMuteCache#clearCachedMuteIf for faster unmute resolution * Add fast-path for user lookups when running on Folia
- Loading branch information
Showing
9 changed files
with
123 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...src/main/java/space/arim/libertybans/env/sponge/listener/RegisterListenersWithLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* LibertyBans | ||
* Copyright © 2023 Anand Beh | ||
* | ||
* LibertyBans is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* LibertyBans is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with LibertyBans. If not, see <https://www.gnu.org/licenses/> | ||
* and navigate to version 3 of the GNU Affero General Public License. | ||
*/ | ||
|
||
package space.arim.libertybans.env.sponge.listener; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import org.spongepowered.api.Game; | ||
import org.spongepowered.api.event.EventManager; | ||
import org.spongepowered.plugin.PluginContainer; | ||
import space.arim.libertybans.core.env.PlatformListener; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
@Singleton | ||
public final class RegisterListenersWithLookup implements RegisterListeners { | ||
|
||
private final PluginContainer plugin; | ||
private final Game game; | ||
|
||
@Inject | ||
public RegisterListenersWithLookup(PluginContainer plugin, Game game) { | ||
this.plugin = plugin; | ||
this.game = game; | ||
} | ||
|
||
public static boolean detectIfUsable() { | ||
try { | ||
EventManager.class.getMethod("registerListeners", PluginContainer.class, Object.class, MethodHandles.Lookup.class); | ||
return true; | ||
} catch (NoSuchMethodException ex) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void register(PlatformListener listener) { | ||
game.eventManager().registerListeners(plugin, listener, MethodHandles.lookup()); | ||
} | ||
|
||
@Override | ||
public void unregister(PlatformListener listener) { | ||
game.eventManager().unregisterListeners(listener); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters