-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LP prefix and suffix as pre-process placeholders in name formats
- Loading branch information
Showing
5 changed files
with
86 additions
and
6 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
53 changes: 53 additions & 0 deletions
53
src/main/java/me/alexdevs/solstice/integrations/LuckPermsIntegration.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,53 @@ | ||
package me.alexdevs.solstice.integrations; | ||
|
||
import me.alexdevs.solstice.Solstice; | ||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.luckperms.api.LuckPerms; | ||
import net.luckperms.api.LuckPermsProvider; | ||
import net.luckperms.api.event.user.UserDataRecalculateEvent; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class LuckPermsIntegration { | ||
|
||
private static LuckPerms luckPerms; | ||
private static boolean available = false; | ||
|
||
public static void register() { | ||
|
||
var container = FabricLoader.getInstance().getModContainer(Solstice.MOD_ID).get(); | ||
|
||
ServerLifecycleEvents.SERVER_STARTED.register(server -> { | ||
luckPerms = LuckPermsProvider.get(); | ||
available = true; | ||
var eventBus = luckPerms.getEventBus(); | ||
|
||
eventBus.subscribe(container, UserDataRecalculateEvent.class, Listeners::onDataRecalculate); | ||
}); | ||
|
||
} | ||
|
||
public static @Nullable String getPrefix(ServerPlayerEntity player) { | ||
if(!available) { | ||
return null; | ||
} | ||
var playerMeta = luckPerms.getPlayerAdapter(ServerPlayerEntity.class).getMetaData(player); | ||
return playerMeta.getPrefix(); | ||
} | ||
|
||
public static @Nullable String getSuffix(ServerPlayerEntity player) { | ||
if(!available) { | ||
return null; | ||
} | ||
var playerMeta = luckPerms.getPlayerAdapter(ServerPlayerEntity.class).getMetaData(player); | ||
return playerMeta.getSuffix(); | ||
} | ||
|
||
public static class Listeners { | ||
|
||
public static void onDataRecalculate(UserDataRecalculateEvent event) { | ||
Solstice.modules.customName.refreshNames(); | ||
} | ||
} | ||
} |
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