Skip to content

Commit 83f43f2

Browse files
committed
Refactor xp gain message code a bit to prepare for adding entity name in message
1 parent c7f6a39 commit 83f43f2

4 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/main/java/com/azuredoom/levelingcore/compat/party/PartyPluginCompat.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.UUID;
1212

1313
import com.azuredoom.levelingcore.config.GUIConfig;
14-
import com.azuredoom.levelingcore.lang.CommandLang;
1514
import com.azuredoom.levelingcore.level.LevelServiceImpl;
1615
import com.azuredoom.levelingcore.ui.hud.XPBarHud;
1716
import com.azuredoom.levelingcore.utils.NotificationsUtil;
@@ -32,7 +31,7 @@ public static void onXPGain(
3231
var party = PartyManager.getInstance().getPartyDataById(playerUuid);
3332
if (party == null || !cfg.isEnablePartyPluginXPShareCompat()) {
3433
if (!cfg.isDisableXPGainNotification()) {
35-
NotificationsUtil.sendNotification(playerRef, CommandLang.GAINED.param("xp", xp));
34+
NotificationsUtil.sendXPGainNotification(playerRef, xp);
3635
}
3736
levelService.addXp(playerUuid, xp);
3837
XPBarHud.updateHud(playerRef);
@@ -103,9 +102,15 @@ public static void onXPGain(
103102

104103
if (!cfg.isDisableXPGainNotification()) {
105104
if (player != null) {
106-
NotificationsUtil.sendNotification(player, CommandLang.GAINED.param("xp", award));
105+
NotificationsUtil.sendXPGainNotification(
106+
player,
107+
award
108+
);
107109
} else if (uuid.equals(playerUuid)) {
108-
NotificationsUtil.sendNotification(playerRef, CommandLang.GAINED.param("xp", award));
110+
NotificationsUtil.sendXPGainNotification(
111+
playerRef,
112+
award
113+
);
109114
}
110115
}
111116

src/main/java/com/azuredoom/levelingcore/compat/party/PartyProCompat.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.UUID;
1212

1313
import com.azuredoom.levelingcore.config.GUIConfig;
14-
import com.azuredoom.levelingcore.lang.CommandLang;
1514
import com.azuredoom.levelingcore.level.LevelServiceImpl;
1615
import com.azuredoom.levelingcore.ui.hud.XPBarHud;
1716
import com.azuredoom.levelingcore.utils.NotificationsUtil;
@@ -32,7 +31,7 @@ public static void onXPGain(
3231
var party = PartyProAPI.getInstance().getPartyByPlayer(playerUuid);
3332
if (party == null || !cfg.isEnablePartyPluginXPShareCompat()) {
3433
if (!cfg.isDisableXPGainNotification()) {
35-
NotificationsUtil.sendNotification(playerRef, CommandLang.GAINED.param("xp", xp));
34+
NotificationsUtil.sendXPGainNotification(playerRef, xp);
3635
}
3736
levelService.addXp(playerUuid, xp);
3837
XPBarHud.updateHud(playerRef);
@@ -103,9 +102,15 @@ public static void onXPGain(
103102

104103
if (!cfg.isDisableXPGainNotification()) {
105104
if (player != null) {
106-
NotificationsUtil.sendNotification(player, CommandLang.GAINED.param("xp", award));
105+
NotificationsUtil.sendXPGainNotification(
106+
player,
107+
award
108+
);
107109
} else if (uuid.equals(playerUuid)) {
108-
NotificationsUtil.sendNotification(playerRef, CommandLang.GAINED.param("xp", award));
110+
NotificationsUtil.sendXPGainNotification(
111+
playerRef,
112+
award
113+
);
109114
}
110115
}
111116

src/main/java/com/azuredoom/levelingcore/systems/xp/GainXPEventSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ public void onComponentAdded(
139139
} else {
140140
// Fallback to default XP gain if supported Party mods are not installed
141141
if (!config.get().isDisableXPGainNotification())
142-
NotificationsUtil.sendNotification(
142+
NotificationsUtil.sendXPGainNotification(
143143
playerRef,
144-
CommandLang.GAINED.param("xp", xpAmount)
144+
xpAmount
145145
);
146146
levelService.addXp(player.getUuid(), xpAmount);
147147
XPBarHud.updateHud(playerRef);

src/main/java/com/azuredoom/levelingcore/utils/NotificationsUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
import com.hypixel.hytale.server.core.universe.PlayerRef;
66
import com.hypixel.hytale.server.core.util.NotificationUtil;
77

8+
import com.azuredoom.levelingcore.lang.CommandLang;
9+
810
/**
911
* Utility class for sending notifications to players. Provides a method to send success notifications with a given
1012
* message to a specified player reference.
1113
*/
1214
public class NotificationsUtil {
1315

16+
private NotificationsUtil() {}
17+
1418
/**
1519
* Sends a success notification to a specific player.
1620
*
@@ -24,4 +28,11 @@ public static void sendNotification(PlayerRef playerRef, Message message) {
2428
NotificationStyle.Success
2529
);
2630
}
31+
32+
public static void sendXPGainNotification(PlayerRef playerRef, long xpAmount) {
33+
sendNotification(
34+
playerRef,
35+
CommandLang.GAINED.param("xp", xpAmount)
36+
);
37+
}
2738
}

0 commit comments

Comments
 (0)