mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Some refactoring
This commit is contained in:
@ -4,7 +4,7 @@ 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.SuperAbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
@ -354,7 +354,7 @@ public class EventUtils {
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, SuperAbility ability) {
|
||||
public static McMMOPlayerAbilityDeactivateEvent callAbilityDeactivateEvent(Player player, SuperAbilityType ability) {
|
||||
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, PrimarySkill.byAbility(ability));
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
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.SuperAbilityType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -29,7 +28,7 @@ public class StringUtils {
|
||||
return createPrettyString(entity.toString());
|
||||
}
|
||||
|
||||
public static String getPrettyAbilityString(SuperAbility ability) {
|
||||
public static String getPrettyAbilityString(SuperAbilityType ability) {
|
||||
return createPrettyString(ability.toString());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,88 @@
|
||||
package com.gmail.nossr50.util.player;
|
||||
|
||||
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.PrimarySkill;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NotificationManager {
|
||||
/**
|
||||
* Sends players notifications from mcMMO
|
||||
* This does this by sending out an event so other plugins can cancel it
|
||||
* @param player target player
|
||||
* @param notificationType notifications defined type
|
||||
* @param key the locale key for the notifications defined message
|
||||
*/
|
||||
public static void sendPlayerInformation(Player player, NotificationType notificationType, String key)
|
||||
{
|
||||
|
||||
ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM;
|
||||
|
||||
TextComponent message = TextComponentFactory.getNotificationTextComponentFromLocale(key, notificationType);
|
||||
McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message);
|
||||
|
||||
sendNotification(player, customEvent);
|
||||
}
|
||||
|
||||
public static void sendOtherPlayersSkillInfo(Player source, NotificationType notificationType, String key, String... values)
|
||||
{
|
||||
Location location = source.getLocation();
|
||||
for (Player otherPlayer : source.getWorld().getPlayers()) {
|
||||
if (otherPlayer != source && Misc.isNear(location, otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {
|
||||
sendPlayerInformation(otherPlayer, notificationType, key, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPlayerInformation(Player player, NotificationType notificationType, String key, String... values)
|
||||
{
|
||||
ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(notificationType) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM;
|
||||
|
||||
|
||||
TextComponent message = TextComponentFactory.getNotificationMultipleValues(key, notificationType, values);
|
||||
McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(player, notificationType, destination, message);
|
||||
|
||||
sendNotification(player, customEvent);
|
||||
}
|
||||
|
||||
private static void sendNotification(Player player, McMMOPlayerNotificationEvent customEvent) {
|
||||
if (customEvent.isCancelled())
|
||||
return;
|
||||
|
||||
player.spigot().sendMessage(customEvent.getChatMessageType(), customEvent.getNotificationTextComponent());
|
||||
}
|
||||
|
||||
private static McMMOPlayerNotificationEvent checkNotificationEvent(Player player, NotificationType notificationType, ChatMessageType destination, TextComponent message) {
|
||||
//Init event
|
||||
McMMOPlayerNotificationEvent customEvent = new McMMOPlayerNotificationEvent(player,
|
||||
notificationType, message, destination);
|
||||
|
||||
//Call event
|
||||
Bukkit.getServer().getPluginManager().callEvent(customEvent);
|
||||
return customEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles sending level up notifications to a mcMMOPlayer
|
||||
* @param mcMMOPlayer target mcMMOPlayer
|
||||
* @param skillName skill that leveled up
|
||||
* @param newLevel new level of that skill
|
||||
*/
|
||||
public static void sendPlayerLevelUpNotification(McMMOPlayer mcMMOPlayer, PrimarySkill skillName, int newLevel)
|
||||
{
|
||||
ChatMessageType destination = AdvancedConfig.getInstance().doesNotificationUseActionBar(NotificationType.LEVEL_UP_MESSAGE) ? ChatMessageType.ACTION_BAR : ChatMessageType.SYSTEM;
|
||||
|
||||
TextComponent levelUpTextComponent = TextComponentFactory.getNotificationLevelUpTextComponent(mcMMOPlayer, skillName, newLevel);
|
||||
McMMOPlayerNotificationEvent customEvent = checkNotificationEvent(mcMMOPlayer.getPlayer(), NotificationType.LEVEL_UP_MESSAGE, destination, levelUpTextComponent);
|
||||
|
||||
sendNotification(mcMMOPlayer.getPlayer(), customEvent);
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbility;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
@ -51,8 +51,8 @@ public class ScoreboardManager {
|
||||
static final String LABEL_OVERALL = LocaleLoader.getString("Scoreboard.Misc.Overall");
|
||||
|
||||
static final Map<PrimarySkill, String> skillLabels;
|
||||
static final Map<SuperAbility, String> abilityLabelsColored;
|
||||
static final Map<SuperAbility, String> abilityLabelsSkill;
|
||||
static final Map<SuperAbilityType, String> abilityLabelsColored;
|
||||
static final Map<SuperAbilityType, String> abilityLabelsSkill;
|
||||
|
||||
/*
|
||||
* Initializes the static properties of this class
|
||||
@ -62,8 +62,8 @@ public class ScoreboardManager {
|
||||
* We need immutable objects for our Scoreboard's labels
|
||||
*/
|
||||
ImmutableMap.Builder<PrimarySkill, String> skillLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbility, String> abilityLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbility, String> abilityLabelSkillBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbilityType, String> abilityLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbilityType, String> abilityLabelSkillBuilder = ImmutableMap.builder();
|
||||
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
@ -98,7 +98,7 @@ public class ScoreboardManager {
|
||||
abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getName()));
|
||||
|
||||
if (type == PrimarySkill.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbility.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbility.BLAST_MINING.getName()));
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,14 +120,14 @@ public class ScoreboardManager {
|
||||
abilityLabelBuilder.put(type.getAbility(), formatAbility(type.getAbility().getName()));
|
||||
|
||||
if (type == PrimarySkill.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbility.BLAST_MINING, formatAbility(SuperAbility.BLAST_MINING.getName()));
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SuperAbility type : SuperAbility.values()) {
|
||||
abilityLabelSkillBuilder.put(type, formatAbility((type == SuperAbility.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA), type.getName()));
|
||||
for (SuperAbilityType type : SuperAbilityType.values()) {
|
||||
abilityLabelSkillBuilder.put(type, formatAbility((type == SuperAbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA), type.getName()));
|
||||
}
|
||||
|
||||
skillLabels = skillLabelBuilder.build();
|
||||
|
@ -3,6 +3,7 @@ package com.gmail.nossr50.util.scoreboards;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.events.scoreboard.*;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -18,7 +19,6 @@ import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbility;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
@ -463,10 +463,10 @@ public class ScoreboardWrapper {
|
||||
|
||||
if (targetSkill == PrimarySkill.MINING) {
|
||||
// Special-Case: Mining has two abilities, both with cooldowns
|
||||
Score cooldownSB = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(SuperAbility.SUPER_BREAKER));
|
||||
Score cooldownBM = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(SuperAbility.BLAST_MINING));
|
||||
int secondsSB = Math.max(mcMMOPlayer.calculateTimeRemaining(SuperAbility.SUPER_BREAKER), 0);
|
||||
int secondsBM = Math.max(mcMMOPlayer.calculateTimeRemaining(SuperAbility.BLAST_MINING), 0);
|
||||
Score cooldownSB = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(SuperAbilityType.SUPER_BREAKER));
|
||||
Score cooldownBM = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(SuperAbilityType.BLAST_MINING));
|
||||
int secondsSB = Math.max(mcMMOPlayer.calculateTimeRemaining(SuperAbilityType.SUPER_BREAKER), 0);
|
||||
int secondsBM = Math.max(mcMMOPlayer.calculateTimeRemaining(SuperAbilityType.BLAST_MINING), 0);
|
||||
|
||||
cooldownSB.setScore(secondsSB);
|
||||
cooldownBM.setScore(secondsBM);
|
||||
@ -474,7 +474,7 @@ public class ScoreboardWrapper {
|
||||
stopUpdating = (secondsSB == 0 && secondsBM == 0);
|
||||
}
|
||||
else {
|
||||
SuperAbility ability = targetSkill.getAbility();
|
||||
SuperAbilityType ability = targetSkill.getAbility();
|
||||
Score cooldown = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(ability));
|
||||
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
|
||||
|
||||
@ -495,7 +495,7 @@ public class ScoreboardWrapper {
|
||||
case COOLDOWNS_BOARD:
|
||||
boolean anyCooldownsActive = false;
|
||||
|
||||
for (SuperAbility ability : SuperAbility.values()) {
|
||||
for (SuperAbilityType ability : SuperAbilityType.values()) {
|
||||
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
|
||||
|
||||
if (seconds != 0) {
|
||||
|
@ -6,20 +6,20 @@ import com.gmail.nossr50.config.HiddenConfig;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
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.SuperAbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
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.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.EventUtils;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.player.NotificationManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -33,7 +33,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -138,7 +137,7 @@ public class SkillUtils {
|
||||
|
||||
for (Player otherPlayer : player.getWorld().getPlayers()) {
|
||||
if (otherPlayer != player && Misc.isNear(location, otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {
|
||||
InteractionManager.sendOtherPlayersSkillInfo(player, notificationType, key);
|
||||
NotificationManager.sendOtherPlayersSkillInfo(player, notificationType, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,7 +179,7 @@ public class SkillUtils {
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
PrimarySkill skill = mcMMOPlayer.getAbilityMode(SuperAbility.SUPER_BREAKER) ? PrimarySkill.MINING : PrimarySkill.EXCAVATION;
|
||||
PrimarySkill skill = mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) ? PrimarySkill.MINING : PrimarySkill.EXCAVATION;
|
||||
int ticks = PerksUtils.handleActivationPerks(player, 2 + (mcMMOPlayer.getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), skill.getAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
|
||||
|
||||
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
|
||||
|
Reference in New Issue
Block a user