mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
mcMMO now alerts you when you progress in a skill
This commit is contained in:
@ -516,6 +516,15 @@ public class TextComponentFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TextComponent getSubSkillUnlockedNotificationComponents(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
TextComponent unlockMessage = new TextComponent("");
|
||||
unlockMessage.setText(LocaleLoader.getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType)));
|
||||
unlockMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getSubSkillHoverComponent(player, subSkillType)));
|
||||
unlockMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/"+subSkillType.getParentSkill().toString().toLowerCase()));
|
||||
return unlockMessage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,9 +4,12 @@ import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -115,4 +118,17 @@ public class NotificationManager {
|
||||
player.sendTitle(title, subtitle, i1, i2, i3);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPlayerUnlockNotification(McMMOPlayer mcMMOPlayer, SubSkillType subSkillType)
|
||||
{
|
||||
//CHAT MESSAGE
|
||||
mcMMOPlayer.getPlayer().spigot().sendMessage(TextComponentFactory.getSubSkillUnlockedNotificationComponents(mcMMOPlayer.getPlayer(), subSkillType));
|
||||
|
||||
//ACTION BAR MESSAGE
|
||||
/*if(AdvancedConfig.getInstance().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)))));*/
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,55 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import com.gmail.nossr50.config.RankConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.runnables.skills.SkillUnlockNotificationTask;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RankUtils {
|
||||
public static HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
|
||||
private static HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin plugin instance ref
|
||||
* @param mcMMOPlayer target player
|
||||
* @param primarySkillType
|
||||
* @param newLevel the new level of this skill
|
||||
*/
|
||||
public static void executeSkillUnlockNotifications(Plugin plugin, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for(SubSkillType subSkillType : primarySkillType.getSkillAbilities())
|
||||
{
|
||||
int playerRankInSkill = getRank(mcMMOPlayer.getPlayer(), subSkillType);
|
||||
|
||||
HashMap<Integer, Integer> innerMap = subSkillRanks.get(subSkillType.toString());
|
||||
|
||||
//If the skill doesn't have registered ranks gtfo
|
||||
if(innerMap == null || innerMap.get(playerRankInSkill) == null)
|
||||
return;
|
||||
|
||||
//The players level is the exact level requirement for this skill
|
||||
if(newLevel == innerMap.get(playerRankInSkill))
|
||||
{
|
||||
SkillUnlockNotificationTask skillUnlockNotificationTask = new SkillUnlockNotificationTask(mcMMOPlayer, subSkillType, newLevel);
|
||||
|
||||
skillUnlockNotificationTask.runTaskLater(plugin, ((count * 5) + 1) * 20);
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* NEW SYSTEM */
|
||||
private static void addRanks(AbstractSubSkill abstractSubSkill)
|
||||
@ -39,6 +78,22 @@ public class RankUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the ranks for every skill we know about
|
||||
*/
|
||||
public static void populateRanks()
|
||||
{
|
||||
for(SubSkillType subSkillType : SubSkillType.values())
|
||||
{
|
||||
addRanks(subSkillType);
|
||||
}
|
||||
|
||||
for(AbstractSubSkill abstractSubSkill : InteractionManager.getSubSkillList())
|
||||
{
|
||||
addRanks(abstractSubSkill);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the player has unlocked the first rank in target subskill
|
||||
* @param player the player
|
||||
@ -190,8 +245,6 @@ public class RankUtils {
|
||||
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(abstractSubSkill.getConfigKeyName());
|
||||
|
||||
//TODO: Remove this debug code
|
||||
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getRankUnlockLevel(subSkillType, rank));
|
||||
rankMap.put(rank, getRankUnlockLevel(abstractSubSkill, rank));
|
||||
}
|
||||
|
||||
@ -202,8 +255,6 @@ public class RankUtils {
|
||||
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkillType.toString());
|
||||
|
||||
//TODO: Remove this debug code
|
||||
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getRankUnlockLevel(subSkillType, rank));
|
||||
rankMap.put(rank, getRankUnlockLevel(subSkillType, rank));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user