Skip to content

Commit

Permalink
fix: server null issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Senior-S committed Sep 22, 2024
1 parent afd41b5 commit 6c5aa97
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.3
1.1.4
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ repositories {
name 'Xander Maven'
url 'https://maven.isxander.dev/releases'
}
// Tetra, PointBlank, Tac:Zero, MrCrayfish's Gun Mod & ScorchedGuns 2
// Tetra, PointBlank, Tac:Zero, MrCrayfish's Gun Mod, ScorchedGuns 2 & JEI
maven {
url "https://cursemaven.com"
content {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ kubejs_version=2001.6.5-build.14
rhino_version=2001.2.2-build.17
architectury_version=9.1.12

# JEI
jei_version=15.19.0.89

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=justlevelingfork
Expand All @@ -47,7 +50,7 @@ mod_name=JustLevelingFork
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=APACHE
# The mod version. See https://semver.org/
mod_version=1.1.3
mod_version=1.1.4
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.seniors.justlevelingfork.registry;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.client.core.Aptitudes;
import com.seniors.justlevelingfork.common.capability.AptitudeCapability;
import com.seniors.justlevelingfork.handler.HandlerAptitude;
import com.seniors.justlevelingfork.handler.HandlerCommonConfig;
import com.seniors.justlevelingfork.integration.TetraIntegration;
import com.seniors.justlevelingfork.registry.aptitude.Aptitude;
import com.seniors.justlevelingfork.registry.title.Title;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
Expand All @@ -29,24 +24,6 @@
* registry CLIENT events into the forge mod bus.
*/
public class RegistryClientEvents {

@SubscribeEvent
public void onClientChatReceivedEvent(ClientChatReceivedEvent event){
if (JustLevelingFork.server != null && HandlerCommonConfig.HANDLER.instance().displayTitlesAsPrefix) {
ServerPlayer serverPlayer = JustLevelingFork.server.getPlayerList().getPlayer(event.getSender());
if(serverPlayer == null) return;
AptitudeCapability capability = AptitudeCapability.get(serverPlayer);
if(capability == null) return;
Title titleKey = RegistryTitles.getTitle(capability.getPlayerTitle());
String title = (titleKey != null) ? Component.translatable(RegistryTitles.getTitle(AptitudeCapability.get().getPlayerTitle()).getKey()).getString() : "";

if(!title.isEmpty()){
String originalMessage = event.getMessage().getString();
event.setMessage(Component.literal(String.format("[%s] %s", title, originalMessage)));
}
}
}

@SubscribeEvent
public void onTooltipDisplay(ItemTooltipEvent event) {
if ((Minecraft.getInstance()).player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.seniors.justlevelingfork.network.packet.common.CounterAttackSP;
import com.seniors.justlevelingfork.registry.skills.ConvergenceSkill;
import com.seniors.justlevelingfork.registry.skills.TreasureHunterSkill;
import com.seniors.justlevelingfork.registry.title.Title;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -62,6 +63,24 @@
*/
@Mod.EventBusSubscriber(modid = JustLevelingFork.MOD_ID)
public class RegistryCommonEvents {

@SubscribeEvent
public void onPlayerNameFormat(PlayerEvent.NameFormat event) {
if (JustLevelingFork.server != null && HandlerCommonConfig.HANDLER.instance().displayTitlesAsPrefix) {
ServerPlayer serverPlayer = JustLevelingFork.server.getPlayerList().getPlayer(event.getEntity().getUUID());
if(serverPlayer == null) return;
AptitudeCapability capability = AptitudeCapability.get(serverPlayer);
if(capability == null) return;
Title titleKey = RegistryTitles.getTitle(capability.getPlayerTitle());
String title = (titleKey != null) ? Component.translatable(RegistryTitles.getTitle(capability.getPlayerTitle()).getKey()).getString() : "";

event.setDisplayname(Component.literal(String.format("[%s] %s",
title.isEmpty()
? Component.translatable(RegistryTitles.TITLELESS.get().getKey()).getString()
: title,
event.getDisplayname().getString())));
}
}
@SubscribeEvent
public void onPlayerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event) {
Player player = event.getEntity();
Expand All @@ -76,6 +95,8 @@ public void onPlayerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event) {

@SubscribeEvent
public void onServerStarting(final ServerStartingEvent event) { // Let's migrate the config on server start to it runs on client and server.
JustLevelingFork.server = event.getServer();

File oldConfigFile = FMLPaths.CONFIGDIR.get().resolve("just_leveling-common.toml").toFile();
if (!HandlerCommonConfig.HANDLER.instance().usingNewConfig && oldConfigFile.exists()) {
JustLevelingFork.getLOGGER().info("Configuration not migrated yet, starting migration...");
Expand All @@ -84,8 +105,6 @@ public void onServerStarting(final ServerStartingEvent event) { // Let's migrate
HandlerCommonConfig.HANDLER.instance().usingNewConfig = true;
HandlerCommonConfig.HANDLER.save();
}

JustLevelingFork.server = event.getServer();
}

@SubscribeEvent
Expand Down Expand Up @@ -143,8 +162,6 @@ public static void onPlayerJoinWorld(EntityJoinLevelEvent event) {
if (!event.getLevel().isClientSide()) {
Entity entity = event.getEntity();
if (entity instanceof ServerPlayer serverPlayer) {
JustLevelingFork.server = serverPlayer.server;

SyncAptitudeCapabilityCP.send(serverPlayer);
RegistryAttributes.modifierAttributes(serverPlayer);
RegistryTitles.syncTitles(serverPlayer);
Expand Down

0 comments on commit 6c5aa97

Please sign in to comment.