mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
4 days of work and I'm still not done ;_;
This commit is contained in:
@ -3,18 +3,16 @@ package com.gmail.nossr50.util;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbility;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelChangeEvent;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelDownEvent;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
|
||||
import com.gmail.nossr50.events.fake.*;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerPreDeathPenaltyEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerStatLossEvent;
|
||||
import com.gmail.nossr50.events.hardcore.McMMOPlayerVampirismEvent;
|
||||
@ -32,10 +30,15 @@ import com.gmail.nossr50.events.skills.salvage.McMMOPlayerSalvageCheckEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -43,7 +46,100 @@ import org.bukkit.plugin.PluginManager;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is meant to help make event related code less boilerplate
|
||||
*/
|
||||
public class EventUtils {
|
||||
/*
|
||||
* Quality of Life methods
|
||||
*/
|
||||
/**
|
||||
* Checks to see if damage is from natural sources
|
||||
* This cannot be used to determine if damage is from vanilla MC, it just checks to see if the damage is from a complex behaviour in mcMMO such as bleed.
|
||||
*
|
||||
* @param event this event
|
||||
* @return true if damage is NOT from an unnatural mcMMO skill (such as bleed DOTs)
|
||||
*/
|
||||
public static boolean isDamageFromMcMMOComplexBehaviour(Event event) {
|
||||
if (event instanceof FakeEntityDamageEvent) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This little method is just to make the code more readable
|
||||
* @param entity target entity
|
||||
* @return the associated McMMOPlayer for this entity
|
||||
*/
|
||||
public static McMMOPlayer getMcMMOPlayer(Entity entity)
|
||||
{
|
||||
return UserManager.getPlayer((Player)entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a Player was damaged in this EntityDamageEvent
|
||||
*
|
||||
* This method checks for the following things and if they are all true it returns true
|
||||
*
|
||||
* 1) The player is real and not an NPC
|
||||
* 2) The player is not in god mode
|
||||
* 3) The damage dealt is above 0
|
||||
* 4) The player is loaded into our mcMMO user profiles
|
||||
*
|
||||
* @param entityDamageEvent
|
||||
* @return
|
||||
*/
|
||||
public static boolean isRealPlayerDamaged(EntityDamageEvent entityDamageEvent)
|
||||
{
|
||||
//Make sure the damage is above 0
|
||||
double damage = entityDamageEvent.getFinalDamage();
|
||||
|
||||
if (damage <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = entityDamageEvent.getEntity();
|
||||
|
||||
//Check to make sure the entity is not an NPC
|
||||
if(Misc.isNPCEntity(entity))
|
||||
return false;
|
||||
|
||||
if (!entity.isValid() || !(entity instanceof LivingEntity)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
|
||||
if (CombatUtils.isInvincible(livingEntity, damage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
/* Check for invincibility */
|
||||
if (mcMMOPlayer.getGodMode()) {
|
||||
entityDamageEvent.setCancelled(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Others
|
||||
*/
|
||||
|
||||
public static McMMOPlayerAbilityActivateEvent callPlayerAbilityActivateEvent(Player player, PrimarySkill skill) {
|
||||
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, skill);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
@ -51,8 +147,28 @@ public class EventUtils {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static SubSkillEvent callSubSkillEvent(Player player, SubSkill subSkill) {
|
||||
SubSkillEvent event = new SubSkillEvent(player, subSkill);
|
||||
/**
|
||||
* Calls a new SubSkillEvent for this SubSkill and then returns it
|
||||
* @param player target player
|
||||
* @param subSkillType target subskill
|
||||
* @return the event after it has been fired
|
||||
*/
|
||||
@Deprecated
|
||||
public static SubSkillEvent callSubSkillEvent(Player player, SubSkillType subSkillType) {
|
||||
SubSkillEvent event = new SubSkillEvent(player, subSkillType);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a new SubSkillEvent for this SubSkill and then returns it
|
||||
* @param player target player
|
||||
* @param abstractSubSkill target subskill
|
||||
* @return the event after it has been fired
|
||||
*/
|
||||
public static SubSkillEvent callSubSkillEvent(Player player, AbstractSubSkill abstractSubSkill) {
|
||||
SubSkillEvent event = new SubSkillEvent(player, abstractSubSkill);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return event;
|
||||
@ -286,4 +402,6 @@ public class EventUtils {
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
@ -14,7 +15,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.commands.party.PartySubcommandType;
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
|
||||
public final class Permissions {
|
||||
private Permissions() {}
|
||||
@ -22,7 +23,6 @@ public final class Permissions {
|
||||
/*
|
||||
* GENERAL
|
||||
*/
|
||||
|
||||
public static boolean motd(Permissible permissible) { return permissible.hasPermission("mcmmo.motd"); }
|
||||
public static boolean mobHealthDisplay(Permissible permissible) { return permissible.hasPermission("mcmmo.mobhealthdisplay"); }
|
||||
public static boolean updateNotifications(Permissible permissible) {return permissible.hasPermission("mcmmo.tools.updatecheck"); }
|
||||
@ -133,7 +133,8 @@ public final class Permissions {
|
||||
|
||||
public static boolean skillEnabled(Permissible permissible, PrimarySkill skill) {return permissible.hasPermission("mcmmo.skills." + skill.toString().toLowerCase()); }
|
||||
public static boolean vanillaXpBoost(Permissible permissible, PrimarySkill skill) { return permissible.hasPermission("mcmmo.ability." + skill.toString().toLowerCase() + ".vanillaxpboost"); }
|
||||
public static boolean isSubSkillEnabled(Permissible permissible, SubSkill subSkill) { return permissible.hasPermission(subSkill.getPermissionNodeAddress()); }
|
||||
public static boolean isSubSkillEnabled(Permissible permissible, SubSkillType subSkillType) { return permissible.hasPermission(subSkillType.getPermissionNodeAddress()); }
|
||||
public static boolean isSubSkillEnabled(Permissible permissible, AbstractSubSkill abstractSubSkill) { return permissible.hasPermission(abstractSubSkill.getPermissionNode()); }
|
||||
public static boolean bonusDamage(Permissible permissible, PrimarySkill skill) { return permissible.hasPermission("mcmmo.ability." + skill.toString().toLowerCase() + ".bonusdamage"); }
|
||||
|
||||
/* ACROBATICS */
|
||||
|
@ -1,200 +0,0 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillFlags;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class SkillTextComponentFactory {
|
||||
public static HashMap<SubSkill, TextComponent> subSkillTextComponents;
|
||||
|
||||
//Yeah there's probably a better way to do this
|
||||
public static HashMap<SubSkill, BaseComponent[]> lockedComponentMap;
|
||||
|
||||
//This is a nested map because each JSON component for a different rank is going to be a bit different.
|
||||
public static HashMap<Integer, HashMap<SubSkill, BaseComponent[]>> hoverComponentOuterMap;
|
||||
|
||||
public static TextComponent getSubSkillTextComponent(Player player, SubSkill subSkill)
|
||||
{
|
||||
//Init our maps
|
||||
if (subSkillTextComponents == null)
|
||||
{
|
||||
subSkillTextComponents = new HashMap<>();
|
||||
lockedComponentMap = new HashMap<>();
|
||||
hoverComponentOuterMap = new HashMap<>();
|
||||
}
|
||||
|
||||
//The skill milestone holds relevant information about the ranks of a skill
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
||||
|
||||
//Get skill name & description from our locale file
|
||||
String skillName = subSkill.getLocaleName();
|
||||
|
||||
if(subSkillTextComponents.get(subSkill) == null)
|
||||
{
|
||||
//Setup Text Component
|
||||
TextComponent textComponent = new TextComponent(skillName);
|
||||
textComponent.setColor(ChatColor.DARK_AQUA);
|
||||
|
||||
//Hover Event
|
||||
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getBaseComponent(player, subSkill)));
|
||||
|
||||
//Insertion
|
||||
textComponent.setInsertion(skillName);
|
||||
|
||||
subSkillTextComponents.put(subSkill, textComponent);
|
||||
return subSkillTextComponents.get(subSkill);
|
||||
} else {
|
||||
return subSkillTextComponents.get(subSkill);
|
||||
}
|
||||
}
|
||||
|
||||
private static BaseComponent[] getBaseComponent(Player player, SubSkill subSkill)
|
||||
{
|
||||
//If the player hasn't unlocked this skill yet we use a different JSON template
|
||||
if(subSkill.getNumRanks() > 0 && RankUtils.getRank(player, subSkill) == 0)
|
||||
{
|
||||
//If the JSON component already exists
|
||||
if(lockedComponentMap.get(subSkill) != null)
|
||||
return lockedComponentMap.get(subSkill);
|
||||
|
||||
BaseComponent[] newComponents = getSubSkillHoverEventJSON(subSkill, player);
|
||||
lockedComponentMap.put(subSkill, newComponents);
|
||||
return lockedComponentMap.get(subSkill);
|
||||
}
|
||||
|
||||
int curRank = RankUtils.getRank(player, subSkill);
|
||||
|
||||
//If the inner hashmap for this rank isn't made yet
|
||||
if(hoverComponentOuterMap.get(curRank) == null)
|
||||
hoverComponentOuterMap.put(curRank, new HashMap<>());
|
||||
|
||||
//Inner Hashmap for current rank
|
||||
HashMap<SubSkill, BaseComponent[]> innerMap = hoverComponentOuterMap.get(curRank);
|
||||
|
||||
if(innerMap.get(subSkill) == null)
|
||||
innerMap.put(subSkill, getSubSkillHoverEventJSON(subSkill, player));
|
||||
|
||||
return innerMap.get(subSkill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a bit is flagged in the subskill
|
||||
* @param flag1 The flag to check for
|
||||
* @param subSkill The target subskill
|
||||
* @return returns true if the bit is flagged in the subskill
|
||||
*/
|
||||
private static boolean checkFlags(int flag1, SubSkill subSkill)
|
||||
{
|
||||
return (flag1 & subSkill.getFlags()) == flag1;
|
||||
}
|
||||
|
||||
private static BaseComponent[] getSubSkillHoverEventJSON(SubSkill subSkill, Player player)
|
||||
{
|
||||
String skillName = subSkill.getLocaleName();
|
||||
String skillDescription = subSkill.getLocaleDescription();
|
||||
|
||||
/*
|
||||
* Hover Event BaseComponent color table
|
||||
*/
|
||||
ChatColor ccSubSkillHeader = ChatColor.GOLD;
|
||||
ChatColor ccRank = ChatColor.BLUE;
|
||||
ChatColor ccCurRank = ChatColor.GREEN;
|
||||
ChatColor ccPossessive = ChatColor.WHITE;
|
||||
ChatColor ccNumRanks = ccCurRank;
|
||||
ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
|
||||
ChatColor ccDescription = ChatColor.WHITE;
|
||||
ChatColor ccLocked = ChatColor.DARK_GRAY;
|
||||
ChatColor ccLevelRequirement = ChatColor.BLUE;
|
||||
ChatColor ccLevelRequired = ChatColor.RED;
|
||||
|
||||
//SubSkill Name
|
||||
ComponentBuilder componentBuilder = new ComponentBuilder(skillName);
|
||||
componentBuilder.bold(true).color(ccSubSkillHeader);
|
||||
componentBuilder.append("\n");
|
||||
|
||||
if(RankUtils.getRank(player, subSkill) == 0)
|
||||
{
|
||||
//Skill is not unlocked yet
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Locked")).color(ccLocked).bold(true);
|
||||
componentBuilder.append("\n").append("\n").bold(false);
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.LevelRequirement") +": ").color(ccLevelRequirement);
|
||||
componentBuilder.append(String.valueOf(AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, 1))).color(ccLevelRequired);
|
||||
|
||||
} else {
|
||||
addSubSkillTypeToHoverEventJSON(subSkill, componentBuilder);
|
||||
|
||||
//RANK
|
||||
if(subSkill.getNumRanks() > 0)
|
||||
{
|
||||
//Rank
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Rank") + ": ").bold(false).color(ccRank);
|
||||
|
||||
//x of y
|
||||
componentBuilder.append(String.valueOf(RankUtils.getRank(player, subSkill))).color(ccCurRank);
|
||||
componentBuilder.append(" "+LocaleLoader.getString("JSON.RankPossesive")+" ").color(ccPossessive);
|
||||
componentBuilder.append(String.valueOf(subSkill.getNumRanks())).color(ccNumRanks);
|
||||
}
|
||||
|
||||
//Empty line
|
||||
componentBuilder.append("\n").bold(false);
|
||||
componentBuilder.append("\n");
|
||||
|
||||
//Description Header
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader")).bold(false).color(ccDescriptionHeader);
|
||||
componentBuilder.append("\n").bold(false);
|
||||
|
||||
//Description
|
||||
componentBuilder.append(skillDescription).color(ccDescription);
|
||||
//componentBuilder.append("\n");
|
||||
}
|
||||
|
||||
return componentBuilder.create();
|
||||
}
|
||||
|
||||
private static void addSubSkillTypeToHoverEventJSON(SubSkill subSkill, ComponentBuilder componentBuilder)
|
||||
{
|
||||
if(checkFlags(SubSkillFlags.SUPERABILITY, subSkill))
|
||||
{
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Type.SuperAbility")).color(ChatColor.LIGHT_PURPLE);
|
||||
componentBuilder.bold(true);
|
||||
} else if(checkFlags(SubSkillFlags.ACTIVE, subSkill))
|
||||
{
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Type.Active")).color(ChatColor.DARK_RED);
|
||||
componentBuilder.bold(true);
|
||||
} else {
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Type.Passive")).color(ChatColor.GREEN);
|
||||
componentBuilder.bold(true);
|
||||
}
|
||||
|
||||
componentBuilder.append("\n");
|
||||
}
|
||||
|
||||
public static void getSubSkillTextComponents(Player player, List<TextComponent> textComponents, PrimarySkill parentSkill) {
|
||||
for(SubSkill subSkill : SubSkill.values())
|
||||
{
|
||||
if(subSkill.getParentSkill() == parentSkill)
|
||||
{
|
||||
if(Permissions.isSubSkillEnabled(player, subSkill))
|
||||
{
|
||||
textComponents.add(SkillTextComponentFactory.getSubSkillTextComponent(player, subSkill));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbility;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
|
531
src/main/java/com/gmail/nossr50/util/TextComponentFactory.java
Normal file
531
src/main/java/com/gmail/nossr50/util/TextComponentFactory.java
Normal file
@ -0,0 +1,531 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.commands.skills.McMMOWebLinks;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.json.McMMOUrl;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class TextComponentFactory {
|
||||
public static HashMap<String, TextComponent> subSkillTextComponents;
|
||||
|
||||
//Yeah there's probably a better way to do this
|
||||
public static HashMap<String, BaseComponent[]> lockedComponentMap;
|
||||
|
||||
public static BaseComponent[] webComponents;
|
||||
|
||||
public static TextComponent getNotificationTextComponent(String localeKey, NotificationType notificationType)
|
||||
{
|
||||
TextComponent textComponent = new TextComponent(LocaleLoader.getString(localeKey));
|
||||
return textComponent;
|
||||
}
|
||||
|
||||
public static void sendPlayerUrlHeader(Player player) {
|
||||
Player.Spigot spigotPlayer = player.spigot();
|
||||
|
||||
if(webComponents != null)
|
||||
{
|
||||
player.spigot().sendMessage(webComponents);
|
||||
return;
|
||||
}
|
||||
|
||||
TextComponent prefix = new TextComponent("[| ");
|
||||
prefix.setColor(ChatColor.DARK_AQUA);
|
||||
TextComponent suffix = new TextComponent(" |]");
|
||||
suffix.setColor(ChatColor.DARK_AQUA);
|
||||
|
||||
TextComponent emptySpace = new TextComponent(" ");
|
||||
|
||||
BaseComponent[] baseComponents = {new TextComponent(prefix),
|
||||
getWebLinkTextComponent(McMMOWebLinks.WEBSITE),
|
||||
emptySpace,
|
||||
getWebLinkTextComponent(McMMOWebLinks.DISCORD),
|
||||
emptySpace,
|
||||
getWebLinkTextComponent(McMMOWebLinks.PATREON),
|
||||
emptySpace,
|
||||
getWebLinkTextComponent(McMMOWebLinks.WIKI),
|
||||
emptySpace,
|
||||
getWebLinkTextComponent(McMMOWebLinks.SPIGOT),
|
||||
emptySpace,
|
||||
getWebLinkTextComponent(McMMOWebLinks.HELP_TRANSLATE),
|
||||
new TextComponent(suffix)};
|
||||
|
||||
//Cache into memory since the links wont change
|
||||
webComponents = baseComponents;
|
||||
spigotPlayer.sendMessage(webComponents);
|
||||
}
|
||||
|
||||
public static void sendPlayerSubSkillList(Player player, List<TextComponent> textComponents)
|
||||
{
|
||||
TextComponent emptySpace = new TextComponent(" ");
|
||||
//TextComponent atSymbolText = new TextComponent(atSymbol);
|
||||
|
||||
ArrayList<BaseComponent> bulkMessage = new ArrayList<>();
|
||||
int newLineCount = 0; //Hacky solution to wordwrap problems
|
||||
|
||||
for (TextComponent textComponent : textComponents) {
|
||||
//Don't send more than 3 subskills per line to avoid MOST wordwrap problems
|
||||
if(newLineCount > 2)
|
||||
{
|
||||
TextComponent[] bulkArray = new TextComponent[bulkMessage.size()];
|
||||
bulkArray = bulkMessage.toArray(bulkArray);
|
||||
|
||||
player.spigot().sendMessage(bulkArray);
|
||||
bulkMessage = new ArrayList<>();
|
||||
newLineCount = 0;
|
||||
}
|
||||
//Style the skills into @links
|
||||
final String originalTxt = textComponent.getText();
|
||||
|
||||
TextComponent stylizedText = new TextComponent("@");
|
||||
stylizedText.setColor(ChatColor.YELLOW);
|
||||
addChild(stylizedText, originalTxt);
|
||||
|
||||
if(textComponent.getHoverEvent() != null)
|
||||
stylizedText.setHoverEvent(textComponent.getHoverEvent());
|
||||
|
||||
if(textComponent.getClickEvent() != null)
|
||||
stylizedText.setClickEvent(textComponent.getClickEvent());
|
||||
|
||||
bulkMessage.add(stylizedText);
|
||||
bulkMessage.add(emptySpace);
|
||||
|
||||
newLineCount++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert our list into an array
|
||||
*/
|
||||
TextComponent[] bulkArray = new TextComponent[bulkMessage.size()];
|
||||
bulkArray = bulkMessage.toArray(bulkArray);
|
||||
|
||||
player.spigot().sendMessage(bulkArray);
|
||||
}
|
||||
|
||||
public static TextComponent getWebLinkTextComponent(McMMOWebLinks webLinks)
|
||||
{
|
||||
TextComponent webTextComponent;
|
||||
|
||||
switch(webLinks)
|
||||
{
|
||||
case WEBSITE:
|
||||
webTextComponent = new TextComponent("@");
|
||||
webTextComponent.setColor(ChatColor.YELLOW);
|
||||
addChild(webTextComponent, "Web");
|
||||
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWebsite));
|
||||
break;
|
||||
case SPIGOT:
|
||||
webTextComponent = new TextComponent("@");
|
||||
webTextComponent.setColor(ChatColor.YELLOW);
|
||||
addChild(webTextComponent, "Spigot");
|
||||
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlSpigot));
|
||||
break;
|
||||
case DISCORD:
|
||||
webTextComponent = new TextComponent("@");
|
||||
webTextComponent.setColor(ChatColor.YELLOW);
|
||||
addChild(webTextComponent, "Discord");
|
||||
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlDiscord));
|
||||
break;
|
||||
case PATREON:
|
||||
webTextComponent = new TextComponent("@");
|
||||
webTextComponent.setColor(ChatColor.YELLOW);
|
||||
addChild(webTextComponent, "Patreon");
|
||||
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlPatreon));
|
||||
break;
|
||||
case WIKI:
|
||||
webTextComponent = new TextComponent("@");
|
||||
webTextComponent.setColor(ChatColor.YELLOW);
|
||||
addChild(webTextComponent, "Wiki");
|
||||
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlWiki));
|
||||
break;
|
||||
case HELP_TRANSLATE:
|
||||
webTextComponent = new TextComponent("@");
|
||||
webTextComponent.setColor(ChatColor.YELLOW);
|
||||
addChild(webTextComponent, "Lang");
|
||||
webTextComponent.setClickEvent(getUrlClickEvent(McMMOUrl.urlTranslate));
|
||||
break;
|
||||
default:
|
||||
webTextComponent = new TextComponent("NOT DEFINED");
|
||||
}
|
||||
|
||||
webTextComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getUrlHoverEvent(webLinks)));
|
||||
webTextComponent.setInsertion(webLinks.getUrl());
|
||||
|
||||
return webTextComponent;
|
||||
}
|
||||
|
||||
private static void addChild(TextComponent webTextComponent, String childName) {
|
||||
TextComponent childComponent = new TextComponent(childName);
|
||||
childComponent.setColor(ChatColor.BLUE);
|
||||
webTextComponent.addExtra(childComponent);
|
||||
}
|
||||
|
||||
private static BaseComponent[] getUrlHoverEvent(McMMOWebLinks webLinks)
|
||||
{
|
||||
ComponentBuilder componentBuilder = new ComponentBuilder(webLinks.getNiceTitle());
|
||||
|
||||
switch(webLinks)
|
||||
{
|
||||
case WEBSITE:
|
||||
addUrlHeaderHover(webLinks, componentBuilder);
|
||||
componentBuilder.append("\n\n").italic(false);
|
||||
componentBuilder.append("The official mcMMO Website!").color(ChatColor.GREEN);
|
||||
break;
|
||||
case SPIGOT:
|
||||
addUrlHeaderHover(webLinks, componentBuilder);
|
||||
componentBuilder.append("\n\n").italic(false);
|
||||
componentBuilder.append("The official mcMMO Spigot Resource Page!").color(ChatColor.GREEN);
|
||||
componentBuilder.append("\nI post regularly in the discussion thread here!").color(ChatColor.GRAY);
|
||||
break;
|
||||
case PATREON:
|
||||
addUrlHeaderHover(webLinks, componentBuilder);
|
||||
componentBuilder.append("\n\n").italic(false);
|
||||
componentBuilder.append("Support nossr50 and development of mcMMO on Patreon!").color(ChatColor.GREEN);
|
||||
break;
|
||||
case WIKI:
|
||||
addUrlHeaderHover(webLinks, componentBuilder);
|
||||
componentBuilder.append("\n\n").italic(false);
|
||||
componentBuilder.append("The official mcMMO wiki!").color(ChatColor.GREEN);
|
||||
componentBuilder.append("\n");
|
||||
componentBuilder.append("I'm looking for more wiki staff, contact me on our discord!").italic(false).color(ChatColor.DARK_GRAY);
|
||||
break;
|
||||
case DISCORD:
|
||||
addUrlHeaderHover(webLinks, componentBuilder);
|
||||
componentBuilder.append("\n\n").italic(false);
|
||||
componentBuilder.append("The official mcMMO Discord server!").color(ChatColor.GREEN);
|
||||
break;
|
||||
case HELP_TRANSLATE:
|
||||
addUrlHeaderHover(webLinks, componentBuilder);
|
||||
componentBuilder.append("\n\n").italic(false);
|
||||
componentBuilder.append("mcMMO's translation service!").color(ChatColor.GREEN);
|
||||
componentBuilder.append("\n");
|
||||
componentBuilder.append("You can use this website to help translate mcMMO into your language!" +
|
||||
"\nIf you want to know more contact me in discord.").italic(false).color(ChatColor.DARK_GRAY);
|
||||
}
|
||||
|
||||
return componentBuilder.create();
|
||||
}
|
||||
|
||||
private static void addUrlHeaderHover(McMMOWebLinks webLinks, ComponentBuilder componentBuilder) {
|
||||
componentBuilder.append("\n");
|
||||
componentBuilder.append(webLinks.getUrl()).color(ChatColor.GRAY).italic(true);
|
||||
}
|
||||
|
||||
private static ClickEvent getUrlClickEvent(String url)
|
||||
{
|
||||
return new ClickEvent(ClickEvent.Action.OPEN_URL, url);
|
||||
}
|
||||
|
||||
public static TextComponent getSubSkillTextComponent(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
//Init our maps
|
||||
if (subSkillTextComponents == null)
|
||||
{
|
||||
subSkillTextComponents = new HashMap<>();
|
||||
lockedComponentMap = new HashMap<>();
|
||||
//hoverComponentOuterMap = new HashMap<>();
|
||||
}
|
||||
|
||||
//Get skill name & description from our locale file
|
||||
String key = subSkillType.toString();
|
||||
String skillName = subSkillType.getLocaleName();
|
||||
|
||||
if(subSkillTextComponents.get(key) == null)
|
||||
{
|
||||
//Setup Text Component
|
||||
TextComponent textComponent = new TextComponent(skillName);
|
||||
//textComponent.setColor(ChatColor.DARK_AQUA);
|
||||
|
||||
//Hover Event
|
||||
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getBaseComponent(player, subSkillType)));
|
||||
|
||||
//Insertion
|
||||
textComponent.setInsertion(skillName);
|
||||
|
||||
subSkillTextComponents.put(key, textComponent);
|
||||
return subSkillTextComponents.get(key);
|
||||
} else {
|
||||
return subSkillTextComponents.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static TextComponent getSubSkillTextComponent(Player player, AbstractSubSkill abstractSubSkill)
|
||||
{
|
||||
//Init our maps
|
||||
if (subSkillTextComponents == null)
|
||||
{
|
||||
subSkillTextComponents = new HashMap<>();
|
||||
lockedComponentMap = new HashMap<>();
|
||||
//hoverComponentOuterMap = new HashMap<>();
|
||||
}
|
||||
|
||||
//Get skill name & description from our locale file
|
||||
String key = abstractSubSkill.getConfigKeyName();
|
||||
String skillName = abstractSubSkill.getNiceName();
|
||||
|
||||
if(subSkillTextComponents.get(key) == null)
|
||||
{
|
||||
//Setup Text Component
|
||||
TextComponent textComponent = new TextComponent(skillName);
|
||||
textComponent.setColor(ChatColor.DARK_AQUA);
|
||||
|
||||
//Hover Event
|
||||
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getBaseComponent(player, abstractSubSkill)));
|
||||
|
||||
//Insertion
|
||||
textComponent.setInsertion(skillName);
|
||||
|
||||
subSkillTextComponents.put(key, textComponent);
|
||||
return subSkillTextComponents.get(key);
|
||||
} else {
|
||||
return subSkillTextComponents.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static BaseComponent[] getBaseComponent(Player player, AbstractSubSkill abstractSubSkill)
|
||||
{
|
||||
|
||||
int curRank = RankUtils.getRank(player, abstractSubSkill);
|
||||
String key = abstractSubSkill.getConfigKeyName();
|
||||
|
||||
//If the player hasn't unlocked this skill yet we use a different JSON template
|
||||
if(abstractSubSkill.getNumRanks() > 0 && curRank == 0)
|
||||
{
|
||||
//If the JSON component already exists
|
||||
if(lockedComponentMap.get(key) != null)
|
||||
return lockedComponentMap.get(key);
|
||||
|
||||
BaseComponent[] newComponents = getSubSkillHoverEventJSON(abstractSubSkill, player, curRank);
|
||||
lockedComponentMap.put(key, newComponents);
|
||||
return lockedComponentMap.get(key);
|
||||
}
|
||||
|
||||
//If the inner hashmap for this rank isn't made yet
|
||||
/*if(hoverComponentOuterMap.get(curRank) == null)
|
||||
hoverComponentOuterMap.put(curRank, new HashMap<>());*/
|
||||
|
||||
//Inner Hashmap for current rank
|
||||
//HashMap<String, BaseComponent[]> innerMap = hoverComponentOuterMap.get(curRank);
|
||||
|
||||
/*if(innerMap.get(key) == null)
|
||||
innerMap.put(key, getSubSkillHoverEventJSON(abstractSubSkill, player, curRank));*/
|
||||
|
||||
return getSubSkillHoverEventJSON(abstractSubSkill, player, curRank);
|
||||
}
|
||||
|
||||
private static BaseComponent[] getBaseComponent(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
int curRank = RankUtils.getRank(player, subSkillType);
|
||||
String key = subSkillType.toString();
|
||||
|
||||
//If the player hasn't unlocked this skill yet we use a different JSON template
|
||||
if(subSkillType.getNumRanks() > 0 && curRank == 0)
|
||||
{
|
||||
//If the JSON component already exists
|
||||
if(lockedComponentMap.get(key) != null)
|
||||
return lockedComponentMap.get(key);
|
||||
|
||||
BaseComponent[] newComponents = getSubSkillHoverEventJSON(subSkillType, player, curRank);
|
||||
lockedComponentMap.put(key, newComponents);
|
||||
return lockedComponentMap.get(key);
|
||||
}
|
||||
|
||||
//If the inner hashmap for this rank isn't made yet
|
||||
/*if(hoverComponentOuterMap.get(curRank) == null)
|
||||
hoverComponentOuterMap.put(curRank, new HashMap<>());
|
||||
|
||||
//Inner Hashmap for current rank
|
||||
HashMap<String, BaseComponent[]> innerMap = hoverComponentOuterMap.get(curRank);*/
|
||||
|
||||
/*if(innerMap.get(key) == null)
|
||||
innerMap.put(key, getSubSkillHoverEventJSON(subSkillType, player, curRank));
|
||||
|
||||
return innerMap.get(key);*/
|
||||
|
||||
return getSubSkillHoverEventJSON(subSkillType, player, curRank);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for the skill in the new skill system (Deriving from AbstractSubSkill)
|
||||
* @param abstractSubSkill this subskill
|
||||
* @param player
|
||||
* @param curRank
|
||||
* @return
|
||||
*/
|
||||
private static BaseComponent[] getSubSkillHoverEventJSON(AbstractSubSkill abstractSubSkill, Player player, int curRank)
|
||||
{
|
||||
String skillName = abstractSubSkill.getNiceName();
|
||||
|
||||
/*
|
||||
* Hover Event BaseComponent color table
|
||||
*/
|
||||
ChatColor ccSubSkillHeader = ChatColor.GOLD;
|
||||
ChatColor ccRank = ChatColor.BLUE;
|
||||
ChatColor ccCurRank = ChatColor.GREEN;
|
||||
ChatColor ccPossessive = ChatColor.WHITE;
|
||||
ChatColor ccNumRanks = ccCurRank;
|
||||
//ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
|
||||
//ChatColor ccDescription = ChatColor.WHITE;
|
||||
ChatColor ccLocked = ChatColor.DARK_GRAY;
|
||||
ChatColor ccLevelRequirement = ChatColor.BLUE;
|
||||
ChatColor ccLevelRequired = ChatColor.RED;
|
||||
|
||||
//SubSkillType Name
|
||||
ComponentBuilder componentBuilder = getNewComponentBuilder(skillName, ccSubSkillHeader);
|
||||
|
||||
if(RankUtils.getRank(player, abstractSubSkill) == 0)
|
||||
{
|
||||
//Skill is not unlocked yet
|
||||
addLocked(abstractSubSkill, ccLocked, ccLevelRequirement, ccLevelRequired, componentBuilder);
|
||||
} else {
|
||||
addSubSkillTypeToHoverEventJSON(abstractSubSkill, componentBuilder);
|
||||
|
||||
//RANK
|
||||
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, abstractSubSkill.getNumRanks(), RankUtils.getRank(player, abstractSubSkill));
|
||||
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader"));
|
||||
componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n");
|
||||
|
||||
//Empty line
|
||||
componentBuilder.append("\n").bold(false);
|
||||
componentBuilder.append("\n");
|
||||
|
||||
//Finally, add details to the tooltip
|
||||
abstractSubSkill.addStats(componentBuilder, player);
|
||||
}
|
||||
|
||||
return componentBuilder.create();
|
||||
}
|
||||
|
||||
private static ComponentBuilder getNewComponentBuilder(String skillName, ChatColor ccSubSkillHeader) {
|
||||
ComponentBuilder componentBuilder = new ComponentBuilder(skillName);
|
||||
componentBuilder.bold(true).color(ccSubSkillHeader);
|
||||
componentBuilder.append("\n");
|
||||
return componentBuilder;
|
||||
}
|
||||
|
||||
private static void addRanked(ChatColor ccRank, ChatColor ccCurRank, ChatColor ccPossessive, ChatColor ccNumRanks, ComponentBuilder componentBuilder, int numRanks, int rank) {
|
||||
if (numRanks > 0) {
|
||||
//Rank
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Rank") + ": ").bold(false).color(ccRank);
|
||||
|
||||
//x of y
|
||||
componentBuilder.append(String.valueOf(rank)).color(ccCurRank);
|
||||
componentBuilder.append(" " + LocaleLoader.getString("JSON.RankPossesive") + " ").color(ccPossessive);
|
||||
componentBuilder.append(String.valueOf(numRanks)).color(ccNumRanks);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Locked")).color(ccLocked).bold(true);
|
||||
componentBuilder.append("\n").append("\n").bold(false);
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.LevelRequirement") +": ").color(ccLevelRequirement);
|
||||
componentBuilder.append(String.valueOf(AdvancedConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static BaseComponent[] getSubSkillHoverEventJSON(SubSkillType subSkillType, Player player, int curRank)
|
||||
{
|
||||
String skillName = subSkillType.getLocaleName();
|
||||
|
||||
/*
|
||||
* Hover Event BaseComponent color table
|
||||
*/
|
||||
ChatColor ccSubSkillHeader = ChatColor.GOLD;
|
||||
ChatColor ccRank = ChatColor.BLUE;
|
||||
ChatColor ccCurRank = ChatColor.GREEN;
|
||||
ChatColor ccPossessive = ChatColor.WHITE;
|
||||
ChatColor ccNumRanks = ccCurRank;
|
||||
ChatColor ccDescriptionHeader = ChatColor.DARK_PURPLE;
|
||||
ChatColor ccDescription = ChatColor.DARK_GRAY;
|
||||
ChatColor ccLocked = ChatColor.DARK_GRAY;
|
||||
ChatColor ccLevelRequirement = ChatColor.BLUE;
|
||||
ChatColor ccLevelRequired = ChatColor.RED;
|
||||
|
||||
//SubSkillType Name
|
||||
ComponentBuilder componentBuilder = getNewComponentBuilder(skillName, ccSubSkillHeader);
|
||||
|
||||
if(RankUtils.getRank(player, subSkillType) == 0)
|
||||
{
|
||||
//Skill is not unlocked yet
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Locked")).color(ccLocked).bold(true);
|
||||
componentBuilder.append("\n").append("\n").bold(false);
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.LevelRequirement") +": ").color(ccLevelRequirement);
|
||||
componentBuilder.append(String.valueOf(AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired);
|
||||
|
||||
} else {
|
||||
//addSubSkillTypeToHoverEventJSON(subSkillType, componentBuilder);
|
||||
|
||||
//RANK
|
||||
if(subSkillType.getNumRanks() > 0)
|
||||
{
|
||||
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, subSkillType.getNumRanks(), RankUtils.getRank(player, subSkillType));
|
||||
|
||||
//Empty line
|
||||
componentBuilder.append("\n").bold(false);
|
||||
}
|
||||
}
|
||||
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.DescriptionHeader"));
|
||||
componentBuilder.color(ccDescriptionHeader);
|
||||
componentBuilder.append("\n");
|
||||
componentBuilder.append(subSkillType.getLocaleDescription());
|
||||
componentBuilder.color(ccDescription);
|
||||
|
||||
return componentBuilder.create();
|
||||
}
|
||||
|
||||
private static void addSubSkillTypeToHoverEventJSON(AbstractSubSkill abstractSubSkill, ComponentBuilder componentBuilder)
|
||||
{
|
||||
if(abstractSubSkill.isSuperAbility())
|
||||
{
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Type.SuperAbility")).color(ChatColor.LIGHT_PURPLE);
|
||||
componentBuilder.bold(true);
|
||||
} else if(abstractSubSkill.isActiveUse())
|
||||
{
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Type.Active")).color(ChatColor.DARK_RED);
|
||||
componentBuilder.bold(true);
|
||||
} else {
|
||||
componentBuilder.append(LocaleLoader.getString("JSON.Type.Passive")).color(ChatColor.GREEN);
|
||||
componentBuilder.bold(true);
|
||||
}
|
||||
|
||||
componentBuilder.append("\n");
|
||||
}
|
||||
|
||||
public static void getSubSkillTextComponents(Player player, List<TextComponent> textComponents, PrimarySkill parentSkill) {
|
||||
for(SubSkillType subSkillType : SubSkillType.values())
|
||||
{
|
||||
if(subSkillType.getParentSkill() == parentSkill)
|
||||
{
|
||||
if(Permissions.isSubSkillEnabled(player, subSkillType))
|
||||
{
|
||||
textComponents.add(TextComponentFactory.getSubSkillTextComponent(player, subSkillType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* NEW SKILL SYSTEM */
|
||||
for(AbstractSubSkill abstractSubSkill : InteractionManager.getSubSkillList())
|
||||
{
|
||||
if(abstractSubSkill.getPrimarySkill() == parentSkill)
|
||||
{
|
||||
if(Permissions.isSubSkillEnabled(player, abstractSubSkill))
|
||||
textComponents.add(TextComponentFactory.getSubSkillTextComponent(player, abstractSubSkill));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
package com.gmail.nossr50.util.player;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* This class will manage all types of feedback for a player done through mcMMO
|
||||
* Including
|
||||
* 1) Audio Feedback
|
||||
* 2) Visual Feedback (Anything on the screen that we use to convey information)
|
||||
*/
|
||||
public class FeedbackManager {
|
||||
|
||||
/**
|
||||
* Used for sending specific sound cues to a player
|
||||
* @param player The player who will be receiving the sound cues
|
||||
*/
|
||||
public void sendAudioFeedback(Player player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for sending specific visual aides to a player
|
||||
* @param player The player who will be receiving the visual feedback
|
||||
*/
|
||||
public void sendVisualFeedback(Player player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.gmail.nossr50.util.player;
|
||||
|
||||
public enum VisualFeedbackType {
|
||||
ADVANCEMENT,
|
||||
CHAT_MESSAGE,
|
||||
CUSTOM_SCOREBOARD
|
||||
}
|
@ -1,66 +1,118 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RankUtils {
|
||||
public static HashMap<SubSkill, HashMap<Integer, Integer>> subSkillRanks;
|
||||
|
||||
/**
|
||||
* Adds ranks to subSkillRanks for target SubSkill
|
||||
* @param subSkill Target SubSkill
|
||||
*/
|
||||
private static void addRanks(SubSkill subSkill) {
|
||||
int numRanks = subSkill.getNumRanks();
|
||||
public static HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
|
||||
|
||||
/* NEW SYSTEM */
|
||||
private static void addRanks(AbstractSubSkill abstractSubSkill)
|
||||
{
|
||||
//Fill out the rank array
|
||||
for(int i = 0; i < numRanks; i++)
|
||||
for(int i = 0; i < abstractSubSkill.getNumRanks(); i++)
|
||||
{
|
||||
//This adds the highest ranks first
|
||||
addRank(subSkill, numRanks-i);
|
||||
addRank(abstractSubSkill, abstractSubSkill.getNumRanks()-i);
|
||||
|
||||
//TODO: Remove debug code
|
||||
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkill.toString());*/
|
||||
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkillType.toString());*/
|
||||
}
|
||||
}
|
||||
|
||||
private static void addRanks(SubSkillType subSkillType)
|
||||
{
|
||||
//Fill out the rank array
|
||||
for(int i = 0; i < subSkillType.getNumRanks(); i++)
|
||||
{
|
||||
//This adds the highest ranks first
|
||||
addRank(subSkillType, subSkillType.getNumRanks()-i);
|
||||
|
||||
//TODO: Remove debug code
|
||||
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkillType.toString());*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current rank of the subskill for the player
|
||||
* @param player The player in question
|
||||
* @param subSkill Target subskill
|
||||
* @param subSkillType Target subskill
|
||||
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
||||
*/
|
||||
public static int getRank(Player player, SubSkill subSkill)
|
||||
public static int getRank(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
String skillName = subSkillType.toString();
|
||||
int numRanks = subSkillType.getNumRanks();
|
||||
|
||||
if(subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
|
||||
if(subSkill.getNumRanks() == 0)
|
||||
if(numRanks == 0)
|
||||
return -1; //-1 Means the skill doesn't have ranks
|
||||
|
||||
if(subSkillRanks.get(subSkill) == null && subSkill.getNumRanks() > 0)
|
||||
addRanks(subSkill);
|
||||
if(subSkillRanks.get(skillName) == null && numRanks > 0)
|
||||
addRanks(subSkillType);
|
||||
|
||||
//Get our rank map
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
|
||||
|
||||
//Skill level of parent skill
|
||||
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkill.getParentSkill());
|
||||
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkillType.getParentSkill());
|
||||
|
||||
for(int i = 0; i < subSkill.getNumRanks(); i++)
|
||||
for(int i = 0; i < numRanks; i++)
|
||||
{
|
||||
//Compare against the highest to lowest rank in that order
|
||||
int rank = subSkill.getNumRanks()-i;
|
||||
int unlockLevel = getUnlockLevel(subSkill, rank);
|
||||
int rank = numRanks-i;
|
||||
int unlockLevel = getUnlockLevel(subSkillType, rank);
|
||||
|
||||
//TODO: Remove this debug code
|
||||
/*System.out.println("[DEBUG RANKCHECK] Checking rank "+rank+" of "+subSkill.getNumRanks());
|
||||
System.out.println("[DEBUG RANKCHECK] Rank "+rank+" -- Unlock level: "+unlockLevel);
|
||||
System.out.println("[DEBUG RANKCHECK] Rank" +rank+" -- Player Skill Level: "+currentSkillLevel);*/
|
||||
//If we check all ranks and still cannot unlock the skill, we return rank 0
|
||||
if(rank == 0)
|
||||
return 0;
|
||||
|
||||
//True if our skill level can unlock the current rank
|
||||
if(currentSkillLevel >= unlockLevel)
|
||||
return rank;
|
||||
}
|
||||
|
||||
return 0; //We should never reach this
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current rank of the subskill for the player
|
||||
* @param player The player in question
|
||||
* @param abstractSubSkill Target subskill
|
||||
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
||||
*/
|
||||
public static int getRank(Player player, AbstractSubSkill abstractSubSkill)
|
||||
{
|
||||
String skillName = abstractSubSkill.getConfigKeyName();
|
||||
int numRanks = abstractSubSkill.getNumRanks();
|
||||
|
||||
if(subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
|
||||
if(numRanks == 0)
|
||||
return -1; //-1 Means the skill doesn't have ranks
|
||||
|
||||
if(subSkillRanks.get(skillName) == null && numRanks > 0)
|
||||
addRanks(abstractSubSkill);
|
||||
|
||||
//Get our rank map
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
|
||||
|
||||
//Skill level of parent skill
|
||||
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
|
||||
|
||||
for(int i = 0; i < numRanks; i++)
|
||||
{
|
||||
//Compare against the highest to lowest rank in that order
|
||||
int rank = numRanks-i;
|
||||
int unlockLevel = getUnlockLevel(abstractSubSkill, rank);
|
||||
|
||||
//If we check all ranks and still cannot unlock the skill, we return rank 0
|
||||
if(rank == 0)
|
||||
@ -76,32 +128,54 @@ public class RankUtils {
|
||||
|
||||
/**
|
||||
* Adds ranks to our map
|
||||
* @param subSkill The subskill to add ranks for
|
||||
* @param abstractSubSkill The subskill to add ranks for
|
||||
* @param rank The rank to add
|
||||
*/
|
||||
private static void addRank(SubSkill subSkill, int rank)
|
||||
private static void addRank(AbstractSubSkill abstractSubSkill, int rank)
|
||||
{
|
||||
if(subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
initMaps(abstractSubSkill.getConfigKeyName());
|
||||
|
||||
if(subSkillRanks.get(subSkill) == null)
|
||||
subSkillRanks.put(subSkill, new HashMap<>());
|
||||
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(abstractSubSkill.getConfigKeyName());
|
||||
|
||||
//TODO: Remove this debug code
|
||||
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkill.toString()+" requires skill level "+getUnlockLevel(subSkill, rank));
|
||||
rankMap.put(rank, getUnlockLevel(subSkill, rank));
|
||||
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getUnlockLevel(subSkillType, rank));
|
||||
rankMap.put(rank, getUnlockLevel(abstractSubSkill, rank));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void addRank(SubSkillType subSkillType, int rank)
|
||||
{
|
||||
initMaps(subSkillType.toString());
|
||||
|
||||
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 "+getUnlockLevel(subSkillType, rank));
|
||||
rankMap.put(rank, getUnlockLevel(subSkillType, rank));
|
||||
}
|
||||
|
||||
private static void initMaps(String s) {
|
||||
if (subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
|
||||
if (subSkillRanks.get(s) == null)
|
||||
subSkillRanks.put(s, new HashMap<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unlock level for a specific rank in a subskill
|
||||
* @param subSkill The target subskill
|
||||
* @param subSkillType The target subskill
|
||||
* @param rank The target rank
|
||||
* @return The level at which this rank unlocks
|
||||
*/
|
||||
private static int getUnlockLevel(SubSkill subSkill, int rank)
|
||||
@Deprecated
|
||||
private static int getUnlockLevel(SubSkillType subSkillType, int rank)
|
||||
{
|
||||
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, rank);
|
||||
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkillType, rank);
|
||||
}
|
||||
|
||||
private static int getUnlockLevel(AbstractSubSkill abstractSubSkill, int rank)
|
||||
{
|
||||
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, rank);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.gmail.nossr50.util.skills;
|
||||
/**
|
||||
* Defines the type of random calculations to use with a given skill
|
||||
*/
|
||||
public enum SubSkillActivationType {
|
||||
public enum SkillActivationType {
|
||||
RANDOM_LINEAR_100_SCALE_NO_CAP, //A skill level of 100 would guarantee the proc with this
|
||||
RANDOM_LINEAR_100_SCALE_WITH_CAP, //This one is based on a scale of 1-100 but with a specified cap for max bonus
|
||||
RANDOM_STATIC_CHANCE, //The skill always has a SPECIFIC chance to succeed
|
@ -4,9 +4,12 @@ import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.HiddenConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbility;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.interfaces.RandomChance;
|
||||
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
|
||||
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillWeightedActivationCheckEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -28,10 +31,54 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SkillUtils {
|
||||
|
||||
public static final DecimalFormat percent = new DecimalFormat("##0.00%");
|
||||
public static final DecimalFormat decimal = new DecimalFormat("##0.00");
|
||||
|
||||
public static void applyXpGain(McMMOPlayer mcMMOPlayer, PrimarySkill skill, float xp, XPGainReason xpGainReason) {
|
||||
mcMMOPlayer.beginXpGain(skill, xp, xpGainReason);
|
||||
}
|
||||
|
||||
/*
|
||||
* Skill Stat Calculations
|
||||
*/
|
||||
|
||||
public static String[] calculateAbilityDisplayValues(double chance, boolean isLucky) {
|
||||
String[] displayValues = new String[2];
|
||||
|
||||
displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.0D);
|
||||
displayValues[1] = isLucky ? percent.format(Math.min(chance * 1.3333D, 100.0D) / 100.0D) : null;
|
||||
|
||||
return displayValues;
|
||||
}
|
||||
|
||||
public static String[] calculateAbilityDisplayValues(float skillValue, SubSkillType subSkillType, boolean isLucky) {
|
||||
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
|
||||
|
||||
return calculateAbilityDisplayValues((AdvancedConfig.getInstance().getMaxChance(subSkillType) / maxBonusLevel) * Math.min(skillValue, maxBonusLevel), isLucky);
|
||||
}
|
||||
|
||||
public static String[] calculateLengthDisplayValues(Player player, float skillValue, PrimarySkill skill) {
|
||||
int maxLength = skill.getAbility().getMaxLength();
|
||||
int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength());
|
||||
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
|
||||
|
||||
if (maxLength != 0) {
|
||||
length = Math.min(length, maxLength);
|
||||
}
|
||||
|
||||
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
|
||||
}
|
||||
|
||||
/*
|
||||
* Others
|
||||
*/
|
||||
|
||||
public static int handleFoodSkills(Player player, PrimarySkill skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
|
||||
int skillLevel = UserManager.getPlayer(player).getSkillLevel(skill);
|
||||
|
||||
@ -199,7 +246,7 @@ public class SkillUtils {
|
||||
|
||||
/**
|
||||
* Checks whether or not the given skill succeeds
|
||||
* @param subSkill The ability corresponding to this check
|
||||
* @param subSkillType The ability corresponding to this check
|
||||
* @param player The player whose skill levels we are checking against
|
||||
* @param skillLevel The skill level of the corresponding skill
|
||||
* @param activationChance used to determine activation chance
|
||||
@ -207,9 +254,15 @@ public class SkillUtils {
|
||||
* @param maxLevel maximum skill level bonus
|
||||
* @return true if random chance succeeds and the event isn't cancelled
|
||||
*/
|
||||
private static boolean performRandomSkillCheck(SubSkill subSkill, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
|
||||
private static boolean performRandomSkillCheck(SubSkillType subSkillType, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
|
||||
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
|
||||
return performRandomSkillCheckStatic(subSkill, player, activationChance, chance);
|
||||
return performRandomSkillCheckStatic(subSkillType, player, activationChance, chance);
|
||||
}
|
||||
|
||||
/* NEW VERSION */
|
||||
private static boolean performRandomSkillCheck(AbstractSubSkill abstractSubSkill, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
|
||||
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
|
||||
return performRandomSkillCheckStatic(abstractSubSkill, player, activationChance, chance);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,48 +277,107 @@ public class SkillUtils {
|
||||
* Random skills check for success based on numbers and then fire a cancellable event, if that event is not cancelled they succeed
|
||||
* All other skills just fire the cancellable event and succeed if it is not cancelled
|
||||
*
|
||||
* @param subSkill The identifier for this specific sub-skill
|
||||
* @param subSkillType The identifier for this specific sub-skill
|
||||
* @param player The owner of this sub-skill
|
||||
* @param skill The identifier for the parent of our sub-skill
|
||||
* @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
|
||||
* @param subskillActivationType this value represents what kind of activation procedures this sub-skill uses
|
||||
* @return returns true if all conditions are met and they event is not cancelled
|
||||
*/
|
||||
public static boolean isActivationSuccessful(SubSkillActivationType subskillActivationType, SubSkill subSkill, Player player,
|
||||
public static boolean isActivationSuccessful(SkillActivationType subskillActivationType, SubSkillType subSkillType, Player player,
|
||||
PrimarySkill skill, int skillLevel, int activationChance)
|
||||
{
|
||||
//Maximum chance to succeed
|
||||
double maxChance = AdvancedConfig.getInstance().getMaxChance(subSkill);
|
||||
double maxChance = AdvancedConfig.getInstance().getMaxChance(subSkillType);
|
||||
//Maximum roll we can make
|
||||
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkill);
|
||||
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
|
||||
|
||||
switch(subskillActivationType)
|
||||
{
|
||||
//100 Skill = Guaranteed
|
||||
case RANDOM_LINEAR_100_SCALE_NO_CAP:
|
||||
return performRandomSkillCheck(subSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
|
||||
return performRandomSkillCheck(subSkillType, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
|
||||
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
|
||||
return performRandomSkillCheck(subSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), AdvancedConfig.getInstance().getMaxChance(subSkill), AdvancedConfig.getInstance().getMaxBonusLevel(subSkill));
|
||||
return performRandomSkillCheck(subSkillType, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), maxChance, maxBonusLevel);
|
||||
case RANDOM_STATIC_CHANCE:
|
||||
//Grab the static activation chance of this skill
|
||||
double staticRoll = getSecondaryAbilityStaticChance(subSkill) / activationChance;
|
||||
return performRandomSkillCheckStatic(subSkill, player, activationChance, staticRoll);
|
||||
double staticRoll = getSecondaryAbilityStaticChance(subSkillType) / activationChance;
|
||||
return performRandomSkillCheckStatic(subSkillType, player, activationChance, staticRoll);
|
||||
case ALWAYS_FIRES:
|
||||
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkill);
|
||||
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkillType);
|
||||
return !event.isCancelled();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* NEW VERSION */
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player, double maxChance, int maxBonusLevel)
|
||||
{
|
||||
int skillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
|
||||
PrimarySkill skill = abstractSubSkill.getPrimarySkill();
|
||||
|
||||
switch(skillActivationType)
|
||||
{
|
||||
//100 Skill = Guaranteed
|
||||
case RANDOM_LINEAR_100_SCALE_NO_CAP:
|
||||
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
|
||||
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
|
||||
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), maxChance, maxBonusLevel);
|
||||
case RANDOM_STATIC_CHANCE:
|
||||
//TODO: Add this in for the new system
|
||||
//Grab the static activation chance of this skill
|
||||
//double staticRoll = getSecondaryAbilityStaticChance(subSkillType) / activationChance;
|
||||
//return performRandomSkillCheckStatic(subSkillType, player, activationChance, staticRoll);
|
||||
return false;
|
||||
case ALWAYS_FIRES:
|
||||
SubSkillEvent event = EventUtils.callSubSkillEvent(player, abstractSubSkill);
|
||||
return !event.isCancelled();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player)
|
||||
{
|
||||
//Maximum chance to succeed
|
||||
RandomChance randomChance = (RandomChance) abstractSubSkill;
|
||||
double maxChance = randomChance.getRandomChanceMaxChance();
|
||||
|
||||
//Maximum roll we can make
|
||||
int maxBonusLevel = randomChance.getRandomChanceMaxBonus();
|
||||
int skillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
|
||||
PrimarySkill skill = abstractSubSkill.getPrimarySkill();
|
||||
|
||||
switch(skillActivationType)
|
||||
{
|
||||
//100 Skill = Guaranteed
|
||||
case RANDOM_LINEAR_100_SCALE_NO_CAP:
|
||||
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
|
||||
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
|
||||
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), maxChance, maxBonusLevel);
|
||||
case RANDOM_STATIC_CHANCE:
|
||||
//TODO: Add this in for the new system
|
||||
//Grab the static activation chance of this skill
|
||||
//double staticRoll = getSecondaryAbilityStaticChance(subSkillType) / activationChance;
|
||||
//return performRandomSkillCheckStatic(subSkillType, player, activationChance, staticRoll);
|
||||
return false;
|
||||
case ALWAYS_FIRES:
|
||||
SubSkillEvent event = EventUtils.callSubSkillEvent(player, abstractSubSkill);
|
||||
return !event.isCancelled();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs static activation rolls for Secondary Abilities
|
||||
* @param subSkill The secondary ability to grab properties of
|
||||
* @param subSkillType The secondary ability to grab properties of
|
||||
* @return The static activation roll involved in the RNG calculation
|
||||
*/
|
||||
public static double getSecondaryAbilityStaticChance(SubSkill subSkill)
|
||||
public static double getSecondaryAbilityStaticChance(SubSkillType subSkillType)
|
||||
{
|
||||
switch(subSkill)
|
||||
switch(subSkillType)
|
||||
{
|
||||
case AXES_ARMOR_IMPACT:
|
||||
return AdvancedConfig.getInstance().getImpactChance();
|
||||
@ -280,20 +392,27 @@ public class SkillUtils {
|
||||
|
||||
/**
|
||||
* Used to determine whether or not a sub-skill activates from random chance (using static values)
|
||||
* @param subSkill The identifier for this specific sub-skill
|
||||
* @param subSkillType The identifier for this specific sub-skill
|
||||
* @param player The owner of this sub-skill
|
||||
* @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
|
||||
* @param chance This is the static modifier for our random calculations
|
||||
* @return true if random chance was successful and the event wasn't cancelled
|
||||
*/
|
||||
private static boolean performRandomSkillCheckStatic(SubSkill subSkill, Player player, int activationChance, double chance) {
|
||||
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, subSkill, chance);
|
||||
private static boolean performRandomSkillCheckStatic(SubSkillType subSkillType, Player player, int activationChance, double chance) {
|
||||
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, subSkillType, chance);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
|
||||
}
|
||||
|
||||
/* NEW VERSION */
|
||||
private static boolean performRandomSkillCheckStatic(AbstractSubSkill abstractSubSkill, Player player, int activationChance, double chance) {
|
||||
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, abstractSubSkill, chance);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
|
||||
}
|
||||
|
||||
public static boolean treasureDropSuccessful(Player player, double dropChance, int activationChance) {
|
||||
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, SubSkill.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
|
||||
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, SubSkillType.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance) && !event.isCancelled();
|
||||
}
|
||||
|
Reference in New Issue
Block a user