Skip to content

Commit

Permalink
2.1.225
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Oct 15, 2023
1 parent 06160c6 commit a545905
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 197 deletions.
5 changes: 5 additions & 0 deletions Changelog.txt
@@ -1,3 +1,8 @@
Version 2.1.225
Fixed various bugs with ability text
Updated Adventure dependencies
Added new API McMMOPlayerNotificationEvent.getPlayer

Version 2.1.224
Updated to a new build of ACF to fix NoSuchFieldException locale
Improved Folia Support (Thanks HSGamer)
Expand Down
57 changes: 40 additions & 17 deletions pom.xml
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.225-SNAPSHOT</version>
<version>2.1.225</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand Down Expand Up @@ -150,21 +150,20 @@
<include>net.kyori:examination-api</include>
<include>net.kyori:examination-string</include>
<include>net.kyori:adventure-text-serializer-legacy</include>
<include>net.kyori:adventure-text-serializer-gson</include>
<include>net.kyori:adventure-text-serializer-json</include>
<include>net.kyori:adventure-text-serializer-bungeecord</include>
<include>net.kyori:adventure-text-serializer-craftbukkit</include>
<include>net.kyori:adventure-text-serializer-gson-legacy-impl</include>
<include>net.kyori:adventure-text-serializer-json-legacy-impl</include>
<include>co.aikar:acf-bukkit</include>
<include>com.tcoded:FoliaLib</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>net.kyori.examination</pattern>
<shadedPattern>com.gmail.nossr50.mcmmo.kyori.examination</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori.adventure</pattern>
<shadedPattern>com.gmail.nossr50.mcmmo.kyori.adventure</shadedPattern>
<pattern>net.kyori</pattern>
<shadedPattern>com.gmail.nossr50.mcmmo.kyori</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.commands</pattern>
Expand Down Expand Up @@ -269,41 +268,65 @@
<artifactId>acf-bukkit</artifactId> <!-- Don't forget to replace this -->
<version>0.5.1-SNAPSHOT</version> <!-- Replace this as well -->
</dependency>
<!-- adventure-api, adventure-text-serializer-gson, adventure-platform-bukkit-->
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-bungeecord</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson-legacy-impl</artifactId>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-json</artifactId>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-json-legacy-impl</artifactId>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-nbt</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-key</artifactId>
<version>4.13.0</version>
<version>4.14.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson-legacy-impl</artifactId>
<version>4.13.0</version>
<artifactId>adventure-platform-api</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.0</version>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-api</artifactId>
<version>4.3.0</version>
<artifactId>adventure-platform-facet</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-viaversion</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
Expand Down
Expand Up @@ -27,8 +27,13 @@ public class McMMOPlayerNotificationEvent extends Event implements Cancellable {
protected Component notificationTextComponent;
protected final NotificationType notificationType;

public McMMOPlayerNotificationEvent(Player who, NotificationType notificationType, Component notificationTextComponent, McMMOMessageType chatMessageType, boolean isMessageAlsoBeingSentToChat) {
protected final Player player;

public McMMOPlayerNotificationEvent(Player player, NotificationType notificationType,
Component notificationTextComponent, McMMOMessageType chatMessageType,
boolean isMessageAlsoBeingSentToChat) {
super(false);
this.player = player;
this.notificationType = notificationType;
this.notificationTextComponent = notificationTextComponent;
this.chatMessageType = chatMessageType;
Expand All @@ -48,6 +53,10 @@ public void setMessageAlsoBeingSentToChat(boolean messageAlsoBeingSentToChat) {
isMessageAlsoBeingSentToChat = messageAlsoBeingSentToChat;
}

public Player getPlayer() {
return player;
}

public Component getNotificationTextComponent() {
return notificationTextComponent;
}
Expand Down
Expand Up @@ -16,7 +16,6 @@
import com.gmail.nossr50.util.text.McMMOMessageType;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
Expand Down Expand Up @@ -49,7 +48,9 @@ public static void sendPlayerInformation(Player player, NotificationType notific
if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
return;

McMMOMessageType destination = mcMMO.p.getAdvancedConfig().doesNotificationUseActionBar(notificationType) ? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM;
McMMOMessageType destination
= mcMMO.p.getAdvancedConfig().doesNotificationUseActionBar(notificationType)
? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM;

Component message = TextComponentFactory.getNotificationTextComponentFromLocale(key);
McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message);
Expand All @@ -75,7 +76,8 @@ public static boolean doesPlayerUseNotifications(Player player)
* @param key Locale Key for the string to use with this event
* @param values values to be injected into the locale string
*/
public static void sendNearbyPlayersInformation(Player targetPlayer, NotificationType notificationType, String key, String... values)
public static void sendNearbyPlayersInformation(Player targetPlayer, NotificationType notificationType, String key,
String... values)
{
sendPlayerInformation(targetPlayer, notificationType, key, values);
}
Expand All @@ -99,7 +101,8 @@ public static void sendPlayerInformationChatOnlyPrefixed(Player player, String k
player.sendMessage(prefixFormattedMessage);
}

public static void sendPlayerInformation(Player player, NotificationType notificationType, String key, String... values)
public static void sendPlayerInformation(Player player, NotificationType notificationType, String key,
String... values)
{
if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
return;
Expand All @@ -119,24 +122,28 @@ private static void sendNotification(Player player, McMMOPlayerNotificationEvent
final Audience audience = mcMMO.getAudiences().player(player);

//If the message is being sent to the action bar we need to check if the copy if a copy is sent to the chat system
Component notificationTextComponent = customEvent.getNotificationTextComponent();
if(customEvent.getChatMessageType() == McMMOMessageType.ACTION_BAR)
{
audience.sendActionBar(customEvent.getNotificationTextComponent());
audience.sendActionBar(notificationTextComponent);

if(customEvent.isMessageAlsoBeingSentToChat())
{
//Send copy to chat system
audience.sendMessage(Identity.nil(), customEvent.getNotificationTextComponent(), MessageType.SYSTEM);
audience.sendMessage(notificationTextComponent);
}
} else {
audience.sendMessage(Identity.nil(), customEvent.getNotificationTextComponent(), MessageType.SYSTEM);
audience.sendMessage(notificationTextComponent);
}
}

private static McMMOPlayerNotificationEvent checkNotificationEvent(Player player, NotificationType notificationType, McMMOMessageType destination, Component message) {
private static McMMOPlayerNotificationEvent checkNotificationEvent(Player player, NotificationType notificationType,
McMMOMessageType destination,
Component message) {
//Init event
McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(player,
notificationType, message, destination, mcMMO.p.getAdvancedConfig().doesNotificationSendCopyToChat(notificationType));
notificationType, message, destination,
mcMMO.p.getAdvancedConfig().doesNotificationSendCopyToChat(notificationType));

//Call event
Bukkit.getServer().getPluginManager().callEvent(customEvent);
Expand All @@ -149,15 +156,23 @@ private static McMMOPlayerNotificationEvent checkNotificationEvent(Player player
* @param skillName skill that leveled up
* @param newLevel new level of that skill
*/
public static void sendPlayerLevelUpNotification(McMMOPlayer mcMMOPlayer, PrimarySkillType skillName, int levelsGained, int newLevel)
public static void sendPlayerLevelUpNotification(McMMOPlayer mcMMOPlayer, PrimarySkillType skillName,
int levelsGained, int newLevel)
{
if(!mcMMOPlayer.useChatNotifications())
return;

McMMOMessageType destination = mcMMO.p.getAdvancedConfig().doesNotificationUseActionBar(NotificationType.LEVEL_UP_MESSAGE) ? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM;
McMMOMessageType destination
= mcMMO.p.getAdvancedConfig().doesNotificationUseActionBar(NotificationType.LEVEL_UP_MESSAGE)
? McMMOMessageType.ACTION_BAR : McMMOMessageType.SYSTEM;

Component levelUpTextComponent = TextComponentFactory.getNotificationLevelUpTextComponent(skillName, levelsGained, newLevel);
McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(mcMMOPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, destination, levelUpTextComponent);
Component levelUpTextComponent = TextComponentFactory.getNotificationLevelUpTextComponent(
skillName, levelsGained, newLevel);
McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(
mcMMOPlayer.getPlayer(),
NotificationType.LEVEL_UP_MESSAGE,
destination,
levelUpTextComponent);

sendNotification(mcMMOPlayer.getPlayer(), customEvent);
}
Expand All @@ -176,17 +191,12 @@ public static void sendPlayerUnlockNotification(McMMOPlayer mcMMOPlayer, SubSkil
return;

//CHAT MESSAGE
mcMMO.getAudiences().player(mcMMOPlayer.getPlayer()).sendMessage(Identity.nil(), TextComponentFactory.getSubSkillUnlockedNotificationComponents(mcMMOPlayer.getPlayer(), subSkillType));
mcMMO.getAudiences().player(mcMMOPlayer.getPlayer()).sendMessage(Identity.nil(),
TextComponentFactory.getSubSkillUnlockedNotificationComponents(mcMMOPlayer.getPlayer(), subSkillType));

//Unlock Sound Effect
SoundManager.sendCategorizedSound(mcMMOPlayer.getPlayer(), mcMMOPlayer.getPlayer().getLocation(), SoundType.SKILL_UNLOCKED, SoundCategory.MASTER);

//ACTION BAR MESSAGE
/*if(mcMMO.p.getAdvancedConfig().doesNotificationUseActionBar(NotificationType.SUBSKILL_UNLOCKED))
mcMMOPlayer.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(LocaleLoader.getString("JSON.SkillUnlockMessage",
subSkillType.getLocaleName(),
String.valueOf(RankUtils.getRank(mcMMOPlayer.getPlayer(),
subSkillType)))));*/
SoundManager.sendCategorizedSound(mcMMOPlayer.getPlayer(), mcMMOPlayer.getPlayer().getLocation(),
SoundType.SKILL_UNLOCKED, SoundCategory.MASTER);
}

/**
Expand Down Expand Up @@ -225,27 +235,35 @@ private static void sendAdminCommandConfirmation(CommandSender commandSender, St
* @param commandSender the command user
* @param sensitiveCommandType type of command issued
*/
public static void processSensitiveCommandNotification(CommandSender commandSender, SensitiveCommandType sensitiveCommandType, String... args) {
public static void processSensitiveCommandNotification(CommandSender commandSender,
SensitiveCommandType sensitiveCommandType, String... args) {
/*
* Determine the 'identity' of the one who executed the command to pass as a parameters
*/
String senderName = LocaleLoader.getString("Server.ConsoleName");

if(commandSender instanceof Player)
{
senderName = ((Player) commandSender).getDisplayName() + ChatColor.RESET + "-" + ((Player) commandSender).getUniqueId();
senderName = ((Player) commandSender).getDisplayName()
+ ChatColor.RESET + "-" + ((Player) commandSender).getUniqueId();
}

//Send the notification
switch(sensitiveCommandType)
{
case XPRATE_MODIFY:
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Others", addItemToFirstPositionOfArray(senderName, args)));
sendAdminCommandConfirmation(commandSender, LocaleLoader.getString("Notifications.Admin.XPRate.Start.Self", args));
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.Start.Others",
addItemToFirstPositionOfArray(senderName, args)));
sendAdminCommandConfirmation(
commandSender, LocaleLoader.getString("Notifications.Admin.XPRate.Start.Self", args));
break;
case XPRATE_END:
sendAdminNotification(LocaleLoader.getString("Notifications.Admin.XPRate.End.Others", addItemToFirstPositionOfArray(senderName, args)));
sendAdminCommandConfirmation(commandSender, LocaleLoader.getString("Notifications.Admin.XPRate.End.Self", args));
sendAdminNotification(
LocaleLoader.getString(
"Notifications.Admin.XPRate.End.Others",
addItemToFirstPositionOfArray(senderName, args)));
sendAdminCommandConfirmation(commandSender,
LocaleLoader.getString("Notifications.Admin.XPRate.End.Self", args));
break;
}
}
Expand All @@ -266,8 +284,6 @@ public static String[] addItemToFirstPositionOfArray(String itemToAdd, String...
return newArray;
}

//TODO: Remove the code duplication, am lazy atm
//TODO: Fix broadcasts being skipped for situations where a player skips over the milestone like with the addlevels command
public static void processLevelUpBroadcasting(@NotNull McMMOPlayer mmoPlayer, @NotNull PrimarySkillType primarySkillType, int level) {
if(level <= 0)
return;
Expand All @@ -290,13 +306,22 @@ public static void processLevelUpBroadcasting(@NotNull McMMOPlayer mmoPlayer, @N
.append(Component.newline())
.append(Component.text(LocalDate.now().toString()))
.append(Component.newline())
.append(Component.text(mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType)+" reached level "+level)).color(TextColor.fromHexString(HEX_BEIGE_COLOR))
.append(Component.text(
mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType)
+ " reached level "+level)).color(TextColor.fromHexString(HEX_BEIGE_COLOR))
.asHoverEvent();

String localeMessage = LocaleLoader.getString("Broadcasts.LevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), level, mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
Component message = LegacyComponentSerializer.legacySection().deserialize(localeMessage).hoverEvent(levelMilestoneHover);

mcMMO.p.getFoliaLib().getImpl().runNextTick(t -> audience.sendMessage(Identity.nil(), message));
String localeMessage = LocaleLoader.getString(
"Broadcasts.LevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), level,
mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
Component component = LegacyComponentSerializer
.legacySection()
.deserialize(localeMessage)
.hoverEvent(levelMilestoneHover);

// TODO: Update system msg API
mcMMO.p.getFoliaLib().getImpl().runNextTick(
t -> audience.sendMessage(component));
}
}
}
Expand Down Expand Up @@ -331,7 +356,7 @@ public static void processPowerLevelUpBroadcasting(@NotNull McMMOPlayer mmoPlaye
String localeMessage = LocaleLoader.getString("Broadcasts.PowerLevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), powerLevel);
Component message = LegacyComponentSerializer.legacySection().deserialize(localeMessage).hoverEvent(levelMilestoneHover);

mcMMO.p.getFoliaLib().getImpl().runNextTick(t -> audience.sendMessage(Identity.nil(), message));
mcMMO.p.getFoliaLib().getImpl().runNextTick(t -> audience.sendMessage(message));
}
}
}
Expand Down

0 comments on commit a545905

Please sign in to comment.