mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-31 03:25:28 +02:00
Remove Static Abuse - Scoreboards... (Yuck)
This commit is contained in:
@@ -3,7 +3,6 @@ package com.gmail.nossr50.util;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
@@ -49,7 +48,7 @@ public final class ChimaeraWing {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMOPlayer = UserManager.getPlayer(player);
|
||||
mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
|
||||
//Not loaded
|
||||
if (mcMMOPlayer == null)
|
||||
|
@@ -31,7 +31,6 @@ import com.gmail.nossr50.events.skills.salvage.McMMOPlayerSalvageCheckEvent;
|
||||
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
|
||||
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -83,7 +82,7 @@ public class EventManager {
|
||||
* @return the associated McMMOPlayer for this entity
|
||||
*/
|
||||
public McMMOPlayer getMcMMOPlayer(Entity entity) {
|
||||
return UserManager.getPlayer((Player) entity);
|
||||
return pluginRef.getUserManager().getPlayer((Player) entity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,11 +140,11 @@ public class EventManager {
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player)) {
|
||||
if (!pluginRef.getUserManager().hasPlayerDataKey(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
return true;
|
||||
@@ -216,7 +215,7 @@ public class EventManager {
|
||||
boolean isCancelled = event.isCancelled();
|
||||
|
||||
if (isCancelled) {
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
PlayerProfile profile = pluginRef.getUserManager().getPlayer(player).getProfile();
|
||||
|
||||
profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : -levelsChanged));
|
||||
profile.addXp(skill, xpRemoved);
|
||||
@@ -232,7 +231,7 @@ public class EventManager {
|
||||
boolean isCancelled = event.isCancelled();
|
||||
|
||||
if (isCancelled) {
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
PlayerProfile profile = pluginRef.getUserManager().getPlayer(player).getProfile();
|
||||
|
||||
profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : -levelsChanged));
|
||||
profile.addXp(skill, xpRemoved);
|
||||
@@ -267,7 +266,7 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(teleportingPlayer);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(teleportingPlayer);
|
||||
|
||||
if (mcMMOPlayer == null)
|
||||
return;
|
||||
@@ -322,15 +321,15 @@ public class EventManager {
|
||||
boolean isCancelled = event.isCancelled();
|
||||
|
||||
if (!isCancelled) {
|
||||
UserManager.getPlayer(player).addXp(skill, event.getRawXpGained());
|
||||
UserManager.getPlayer(player).getProfile().registerXpGain(skill, event.getRawXpGained());
|
||||
pluginRef.getUserManager().getPlayer(player).addXp(skill, event.getRawXpGained());
|
||||
pluginRef.getUserManager().getPlayer(player).getProfile().registerXpGain(skill, event.getRawXpGained());
|
||||
}
|
||||
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public boolean handleStatsLossEvent(Player player, HashMap<String, Integer> levelChanged, HashMap<String, Double> experienceChanged) {
|
||||
if (UserManager.getPlayer(player) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(player) == null)
|
||||
return true;
|
||||
|
||||
McMMOPlayerStatLossEvent event = new McMMOPlayerStatLossEvent(player, levelChanged, experienceChanged);
|
||||
@@ -341,7 +340,7 @@ public class EventManager {
|
||||
if (!isCancelled) {
|
||||
levelChanged = event.getLevelChanged();
|
||||
experienceChanged = event.getExperienceChanged();
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
||||
PlayerProfile playerProfile = pluginRef.getUserManager().getPlayer(player).getProfile();
|
||||
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
|
||||
String skillName = primarySkillType.toString();
|
||||
@@ -378,17 +377,17 @@ public class EventManager {
|
||||
HashMap<String, Integer> levelChangedVictim = eventVictim.getLevelChanged();
|
||||
HashMap<String, Double> experienceChangedVictim = eventVictim.getExperienceChanged();
|
||||
|
||||
McMMOPlayer killerPlayer = UserManager.getPlayer(killer);
|
||||
McMMOPlayer killerPlayer = pluginRef.getUserManager().getPlayer(killer);
|
||||
|
||||
//Not loaded
|
||||
if (killerPlayer == null)
|
||||
return true;
|
||||
|
||||
//Not loaded
|
||||
if (UserManager.getPlayer(victim) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(victim) == null)
|
||||
return true;
|
||||
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
PlayerProfile victimProfile = pluginRef.getUserManager().getPlayer(victim).getProfile();
|
||||
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
|
||||
String skillName = primarySkillType.toString();
|
||||
|
@@ -3,7 +3,6 @@ package com.gmail.nossr50.util;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
||||
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -25,10 +24,10 @@ public final class HardcoreManager {
|
||||
double statLossPercentage = pluginRef.getConfigManager().getConfigHardcore().getDeathPenalty().getPenaltyPercentage();
|
||||
int levelThreshold = pluginRef.getConfigManager().getConfigHardcore().getDeathPenalty().getLevelThreshold();
|
||||
|
||||
if (UserManager.getPlayer(player) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(player) == null)
|
||||
return;
|
||||
|
||||
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
|
||||
PlayerProfile playerProfile = pluginRef.getUserManager().getPlayer(player).getProfile();
|
||||
int totalLevelsLost = 0;
|
||||
|
||||
HashMap<String, Integer> levelChanged = new HashMap<>();
|
||||
@@ -77,11 +76,11 @@ public final class HardcoreManager {
|
||||
double vampirismStatLeechPercentage = pluginRef.getConfigManager().getConfigHardcore().getVampirism().getPenaltyPercentage();
|
||||
int levelThreshold = pluginRef.getConfigManager().getConfigHardcore().getVampirism().getLevelThreshold();
|
||||
|
||||
if (UserManager.getPlayer(killer) == null || UserManager.getPlayer(victim) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(killer) == null || pluginRef.getUserManager().getPlayer(victim) == null)
|
||||
return;
|
||||
|
||||
PlayerProfile killerProfile = UserManager.getPlayer(killer).getProfile();
|
||||
PlayerProfile victimProfile = UserManager.getPlayer(victim).getProfile();
|
||||
PlayerProfile killerProfile = pluginRef.getUserManager().getPlayer(killer).getProfile();
|
||||
PlayerProfile victimProfile = pluginRef.getUserManager().getPlayer(victim).getProfile();
|
||||
int totalLevelsStolen = 0;
|
||||
|
||||
HashMap<String, Integer> levelChanged = new HashMap<>();
|
||||
|
@@ -2,7 +2,6 @@ package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
|
||||
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -176,7 +175,7 @@ public final class Misc {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player != null) {
|
||||
UserManager.remove(player);
|
||||
pluginRef.getUserManager().remove(player);
|
||||
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(pluginRef, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||
}
|
||||
}
|
||||
|
@@ -5,8 +5,8 @@ import com.gmail.nossr50.commands.admin.ReloadLocaleCommand;
|
||||
import com.gmail.nossr50.commands.chat.AdminChatCommand;
|
||||
import com.gmail.nossr50.commands.chat.ChatSpyCommand;
|
||||
import com.gmail.nossr50.commands.chat.PartyChatCommand;
|
||||
import com.gmail.nossr50.commands.database.PurgeCommand;
|
||||
import com.gmail.nossr50.commands.database.McremoveCommand;
|
||||
import com.gmail.nossr50.commands.database.PurgeCommand;
|
||||
import com.gmail.nossr50.commands.database.ShowDatabaseCommand;
|
||||
import com.gmail.nossr50.commands.experience.AddLevelsCommand;
|
||||
import com.gmail.nossr50.commands.experience.AddXPCommand;
|
||||
|
@@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -206,10 +205,10 @@ public final class CommandTools {
|
||||
}
|
||||
|
||||
private void printGroupedSkillData(Player inspect, CommandSender display, String header, List<PrimarySkillType> skillGroup) {
|
||||
if (UserManager.getPlayer(inspect) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(inspect) == null)
|
||||
return;
|
||||
|
||||
PlayerProfile profile = UserManager.getPlayer(inspect).getProfile();
|
||||
PlayerProfile profile = pluginRef.getUserManager().getPlayer(inspect).getProfile();
|
||||
|
||||
List<String> displayData = new ArrayList<>();
|
||||
displayData.add(header);
|
||||
|
@@ -62,7 +62,7 @@ public class NotificationManager {
|
||||
* @param key the locale key for the notifications defined message
|
||||
*/
|
||||
public void sendPlayerInformation(Player player, NotificationType notificationType, String key) {
|
||||
if (UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
|
||||
if (pluginRef.getUserManager().getPlayer(player) == null || !pluginRef.getUserManager().getPlayer(player).useChatNotifications())
|
||||
return;
|
||||
|
||||
TextComponent textComponent = TextComponentFactory.getNotificationTextComponentFromLocale(key);
|
||||
@@ -106,7 +106,7 @@ public class NotificationManager {
|
||||
|
||||
public void sendPlayerInformationChatOnly(Player player, String key, String... values)
|
||||
{
|
||||
if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
|
||||
if(pluginRef.getUserManager().getPlayer(player) == null || !pluginRef.getUserManager().getPlayer(player).useChatNotifications())
|
||||
return;
|
||||
|
||||
String preColoredString = pluginRef.getLocaleManager().getString(key, (Object[]) values);
|
||||
@@ -115,7 +115,7 @@ public class NotificationManager {
|
||||
|
||||
public void sendPlayerInformation(Player player, NotificationType notificationType, String key, String... values)
|
||||
{
|
||||
if(UserManager.getPlayer(player) == null || !UserManager.getPlayer(player).useChatNotifications())
|
||||
if(pluginRef.getUserManager().getPlayer(player) == null || !pluginRef.getUserManager().getPlayer(player).useChatNotifications())
|
||||
return;
|
||||
|
||||
TextComponent textComponent = buildTextComponent(key, values);
|
||||
@@ -263,9 +263,9 @@ public class NotificationManager {
|
||||
}
|
||||
|
||||
public boolean doesPlayerUseNotifications(Player player) {
|
||||
if (UserManager.getPlayer(player) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(player) == null)
|
||||
return false;
|
||||
else
|
||||
return UserManager.getPlayer(player).useChatNotifications();
|
||||
return pluginRef.getUserManager().getPlayer(player).useChatNotifications();
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.gmail.nossr50.util.player;
|
||||
|
||||
import com.gmail.nossr50.core.MetadataConstants;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -14,9 +15,13 @@ import java.util.HashSet;
|
||||
|
||||
public final class UserManager {
|
||||
|
||||
private UserManager() {
|
||||
private mcMMO pluginRef;
|
||||
|
||||
public UserManager(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
}
|
||||
private static HashSet<McMMOPlayer> playerDataSet; //Used to track players for sync saves on shutdown
|
||||
|
||||
private HashSet<McMMOPlayer> playerDataSet; //Used to track players for sync saves on shutdown
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,7 +29,7 @@ public final class UserManager {
|
||||
*
|
||||
* @param mcMMOPlayer the player profile to start tracking
|
||||
*/
|
||||
public static void track(McMMOPlayer mcMMOPlayer) {
|
||||
public void track(McMMOPlayer mcMMOPlayer) {
|
||||
mcMMOPlayer.getPlayer().setMetadata(MetadataConstants.PLAYER_DATA_METAKEY, new FixedMetadataValue(pluginRef, mcMMOPlayer));
|
||||
|
||||
if(playerDataSet == null)
|
||||
@@ -33,7 +38,7 @@ public final class UserManager {
|
||||
playerDataSet.add(mcMMOPlayer); //for sync saves on shutdown
|
||||
}
|
||||
|
||||
public static void cleanupPlayer(McMMOPlayer mcMMOPlayer) {
|
||||
public void cleanupPlayer(McMMOPlayer mcMMOPlayer) {
|
||||
if(playerDataSet != null && playerDataSet.contains(mcMMOPlayer))
|
||||
playerDataSet.remove(mcMMOPlayer);
|
||||
}
|
||||
@@ -43,7 +48,7 @@ public final class UserManager {
|
||||
*
|
||||
* @param player The Player object
|
||||
*/
|
||||
public static void remove(Player player) {
|
||||
public void remove(Player player) {
|
||||
McMMOPlayer mcMMOPlayer = getPlayer(player);
|
||||
player.removeMetadata(MetadataConstants.PLAYER_DATA_METAKEY, pluginRef);
|
||||
|
||||
@@ -54,7 +59,7 @@ public final class UserManager {
|
||||
/**
|
||||
* Clear all users.
|
||||
*/
|
||||
public static void clearAll() {
|
||||
public void clearAll() {
|
||||
for (Player player : pluginRef.getServer().getOnlinePlayers()) {
|
||||
remove(player);
|
||||
}
|
||||
@@ -66,7 +71,7 @@ public final class UserManager {
|
||||
/**
|
||||
* Save all users ON THIS THREAD.
|
||||
*/
|
||||
public static void saveAll() {
|
||||
public void saveAll() {
|
||||
if(playerDataSet == null)
|
||||
return;
|
||||
|
||||
@@ -89,7 +94,7 @@ public final class UserManager {
|
||||
pluginRef.getLogger().info("Finished save operation for "+trackedSyncData.size()+" players!");
|
||||
}
|
||||
|
||||
public static Collection<McMMOPlayer> getPlayers() {
|
||||
public Collection<McMMOPlayer> getPlayers() {
|
||||
Collection<McMMOPlayer> playerCollection = new ArrayList<>();
|
||||
|
||||
for (Player player : pluginRef.getServer().getOnlinePlayers()) {
|
||||
@@ -107,11 +112,11 @@ public final class UserManager {
|
||||
* @param playerName The name of the player whose McMMOPlayer to retrieve
|
||||
* @return the player's McMMOPlayer object
|
||||
*/
|
||||
public static McMMOPlayer getPlayer(String playerName) {
|
||||
public McMMOPlayer getPlayer(String playerName) {
|
||||
return retrieveMcMMOPlayer(playerName, false);
|
||||
}
|
||||
|
||||
public static McMMOPlayer getOfflinePlayer(OfflinePlayer player) {
|
||||
public McMMOPlayer getOfflinePlayer(OfflinePlayer player) {
|
||||
if (player instanceof Player) {
|
||||
return getPlayer((Player) player);
|
||||
}
|
||||
@@ -119,7 +124,7 @@ public final class UserManager {
|
||||
return retrieveMcMMOPlayer(player.getName(), true);
|
||||
}
|
||||
|
||||
public static McMMOPlayer getOfflinePlayer(String playerName) {
|
||||
public McMMOPlayer getOfflinePlayer(String playerName) {
|
||||
return retrieveMcMMOPlayer(playerName, true);
|
||||
}
|
||||
|
||||
@@ -129,7 +134,7 @@ public final class UserManager {
|
||||
* @param player target player
|
||||
* @return McMMOPlayer object for this player, null if Player has not been loaded
|
||||
*/
|
||||
public static McMMOPlayer getPlayer(Player player) {
|
||||
public McMMOPlayer getPlayer(Player player) {
|
||||
//Avoid Array Index out of bounds
|
||||
if (player != null && player.hasMetadata(MetadataConstants.PLAYER_DATA_METAKEY))
|
||||
return (McMMOPlayer) player.getMetadata(MetadataConstants.PLAYER_DATA_METAKEY).get(0).value();
|
||||
@@ -137,7 +142,7 @@ public final class UserManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static McMMOPlayer retrieveMcMMOPlayer(String playerName, boolean offlineValid) {
|
||||
private McMMOPlayer retrieveMcMMOPlayer(String playerName, boolean offlineValid) {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
@@ -151,7 +156,7 @@ public final class UserManager {
|
||||
return getPlayer(player);
|
||||
}
|
||||
|
||||
public static boolean hasPlayerDataKey(Entity entity) {
|
||||
public boolean hasPlayerDataKey(Entity entity) {
|
||||
return entity != null && entity.hasMetadata(MetadataConstants.PLAYER_DATA_METAKEY);
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package com.gmail.nossr50.util.random;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RandomChanceSkill implements RandomChanceExecution {
|
||||
@@ -20,7 +19,7 @@ public class RandomChanceSkill implements RandomChanceExecution {
|
||||
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
|
||||
|
||||
if (player != null)
|
||||
this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
|
||||
this.skillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(primarySkillType);
|
||||
else
|
||||
this.skillLevel = 0;
|
||||
|
||||
@@ -40,7 +39,7 @@ public class RandomChanceSkill implements RandomChanceExecution {
|
||||
this.subSkillType = subSkillType;
|
||||
|
||||
if (player != null)
|
||||
this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
|
||||
this.skillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(primarySkillType);
|
||||
else
|
||||
this.skillLevel = 0;
|
||||
|
||||
|
@@ -4,163 +4,61 @@ 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.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.events.scoreboard.McMMOScoreboardMakeboardEvent;
|
||||
import com.gmail.nossr50.events.scoreboard.ScoreboardEventReason;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manages the Scoreboards used to display a variety of mcMMO related information to the player
|
||||
*/
|
||||
public class ScoreboardManager {
|
||||
static final Map<String, ScoreboardWrapper> PLAYER_SCOREBOARDS = new HashMap<>();
|
||||
private final mcMMO pluginRef;
|
||||
private final Map<String, ScoreboardWrapper> PLAYER_SCOREBOARDS = new HashMap<>();
|
||||
|
||||
// do not localize; these are internal identifiers
|
||||
static final String SIDEBAR_OBJECTIVE = "mcmmo_sidebar";
|
||||
static final String POWER_OBJECTIVE = "mcmmo_pwrlvl";
|
||||
private final ScoreboardStrings scoreboardStrings;
|
||||
|
||||
static final String HEADER_STATS = pluginRef.getLocaleManager().getString("Scoreboard.Header.PlayerStats");
|
||||
static final String HEADER_COOLDOWNS = pluginRef.getLocaleManager().getString("Scoreboard.Header.PlayerCooldowns");
|
||||
static final String HEADER_RANK = pluginRef.getLocaleManager().getString("Scoreboard.Header.PlayerRank");
|
||||
static final String TAG_POWER_LEVEL = pluginRef.getLocaleManager().getString("Scoreboard.Header.PowerLevel");
|
||||
private List<String> dirtyPowerLevels = new ArrayList<>();
|
||||
|
||||
static final String POWER_LEVEL = pluginRef.getLocaleManager().getString("Scoreboard.Misc.PowerLevel");
|
||||
|
||||
static final String LABEL_POWER_LEVEL = POWER_LEVEL;
|
||||
static final String LABEL_LEVEL = pluginRef.getLocaleManager().getString("Scoreboard.Misc.Level");
|
||||
static final String LABEL_CURRENT_XP = pluginRef.getLocaleManager().getString("Scoreboard.Misc.CurrentXP");
|
||||
static final String LABEL_REMAINING_XP = pluginRef.getLocaleManager().getString("Scoreboard.Misc.RemainingXP");
|
||||
static final String LABEL_ABILITY_COOLDOWN = pluginRef.getLocaleManager().getString("Scoreboard.Misc.Cooldown");
|
||||
static final String LABEL_OVERALL = pluginRef.getLocaleManager().getString("Scoreboard.Misc.Overall");
|
||||
|
||||
static final Map<PrimarySkillType, String> skillLabels;
|
||||
static final Map<SuperAbilityType, String> abilityLabelsColored;
|
||||
static final Map<SuperAbilityType, String> abilityLabelsSkill;
|
||||
private static List<String> dirtyPowerLevels = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* Initializes the static properties of this class
|
||||
*/
|
||||
static {
|
||||
/*
|
||||
* We need immutable objects for our ConfigScoreboard's labels
|
||||
*/
|
||||
ImmutableMap.Builder<PrimarySkillType, String> skillLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbilityType, String> abilityLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbilityType, String> abilityLabelSkillBuilder = ImmutableMap.builder();
|
||||
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
* Stylizes the targetBoard in a Rainbow Pattern
|
||||
* This is off by default
|
||||
*/
|
||||
if (pluginRef.getScoreboardSettings().getUseRainbowSkillStyling()) {
|
||||
// Everything but black, gray, gold
|
||||
List<ChatColor> colors = Lists.newArrayList(
|
||||
ChatColor.WHITE,
|
||||
ChatColor.YELLOW,
|
||||
ChatColor.LIGHT_PURPLE,
|
||||
ChatColor.RED,
|
||||
ChatColor.AQUA,
|
||||
ChatColor.GREEN,
|
||||
ChatColor.DARK_GRAY,
|
||||
ChatColor.BLUE,
|
||||
ChatColor.DARK_PURPLE,
|
||||
ChatColor.DARK_RED,
|
||||
ChatColor.DARK_AQUA,
|
||||
ChatColor.DARK_GREEN,
|
||||
ChatColor.DARK_BLUE);
|
||||
|
||||
Collections.shuffle(colors, Misc.getRandom());
|
||||
|
||||
int i = 0;
|
||||
for (PrimarySkillType type : PrimarySkillType.values()) {
|
||||
// Include child skills
|
||||
skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false));
|
||||
|
||||
if (type.getSuperAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getSuperAbility(), getShortenedName(colors.get(i) + type.getSuperAbility().getName()));
|
||||
|
||||
if (type == PrimarySkillType.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
if (++i == colors.size()) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
* Stylizes the targetBoard using our normal color scheme
|
||||
*/
|
||||
else {
|
||||
for (PrimarySkillType type : PrimarySkillType.values()) {
|
||||
// Include child skills
|
||||
skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName()));
|
||||
|
||||
if (type.getSuperAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getSuperAbility(), formatAbility(type.getSuperAbility().getName()));
|
||||
|
||||
if (type == PrimarySkillType.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SuperAbilityType type : SuperAbilityType.values()) {
|
||||
abilityLabelSkillBuilder.put(type, formatAbility((type == SuperAbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA), type.getName()));
|
||||
}
|
||||
|
||||
skillLabels = skillLabelBuilder.build();
|
||||
abilityLabelsColored = abilityLabelBuilder.build();
|
||||
abilityLabelsSkill = abilityLabelSkillBuilder.build();
|
||||
}
|
||||
|
||||
private static String formatAbility(String abilityName) {
|
||||
return formatAbility(ChatColor.AQUA, abilityName);
|
||||
}
|
||||
|
||||
private static String formatAbility(ChatColor color, String abilityName) {
|
||||
if (pluginRef.getScoreboardSettings().getUseAbilityNamesOverGenerics()) {
|
||||
return getShortenedName(color + abilityName);
|
||||
} else {
|
||||
return color + pluginRef.getLocaleManager().getString("Scoreboard.Misc.Ability");
|
||||
}
|
||||
}
|
||||
|
||||
private static String getShortenedName(String name) {
|
||||
return getShortenedName(name, true);
|
||||
}
|
||||
|
||||
private static String getShortenedName(String name, boolean useDots) {
|
||||
if (name.length() > 16) {
|
||||
name = useDots ? name.substring(0, 14) + ".." : name.substring(0, 16);
|
||||
}
|
||||
|
||||
return name;
|
||||
public ScoreboardManager(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
this.scoreboardStrings = new ScoreboardStrings(pluginRef);
|
||||
}
|
||||
|
||||
// Called by PlayerJoinEvent listener
|
||||
public static void setupPlayer(Player player) {
|
||||
PLAYER_SCOREBOARDS.put(player.getName(), ScoreboardWrapper.create(player));
|
||||
public void setupPlayer(Player player) {
|
||||
PLAYER_SCOREBOARDS.put(player.getName(), create(player));
|
||||
dirtyPowerLevels.add(player.getName());
|
||||
}
|
||||
|
||||
public ScoreboardWrapper create(Player player) {
|
||||
//TODO: Christ...
|
||||
|
||||
//Call our custom event
|
||||
if(pluginRef.getServer().getScoreboardManager() != null) {
|
||||
McMMOScoreboardMakeboardEvent event = new McMMOScoreboardMakeboardEvent(pluginRef.getServer().getScoreboardManager().getNewScoreboard(), player.getScoreboard(), player, ScoreboardEventReason.CREATING_NEW_SCOREBOARD);
|
||||
player.getServer().getPluginManager().callEvent(event);
|
||||
return new ScoreboardWrapper(event.getTargetPlayer(), event.getTargetBoard(), scoreboardStrings, pluginRef);
|
||||
|
||||
}
|
||||
|
||||
//Use the values from the event
|
||||
return null;
|
||||
}
|
||||
|
||||
// **** Listener call-ins **** //
|
||||
|
||||
// Called by PlayerQuitEvent listener
|
||||
public static void teardownPlayer(Player player) {
|
||||
public void teardownPlayer(Player player) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.remove(player.getName());
|
||||
|
||||
if (wrapper != null && wrapper.revertTask != null) {
|
||||
@@ -169,7 +67,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
// Called in onDisable()
|
||||
public static void teardownAll() {
|
||||
public void teardownAll() {
|
||||
ImmutableList<Player> onlinePlayers = ImmutableList.copyOf(pluginRef.getServer().getOnlinePlayers());
|
||||
pluginRef.debug("Tearing down scoreboards... (" + onlinePlayers.size() + ")");
|
||||
for (Player player : onlinePlayers) {
|
||||
@@ -178,7 +76,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
// Called by ScoreboardWrapper when its Player logs off and an action tries to be performed
|
||||
public static void cleanup(ScoreboardWrapper wrapper) {
|
||||
public void cleanup(ScoreboardWrapper wrapper) {
|
||||
PLAYER_SCOREBOARDS.remove(wrapper.playerName);
|
||||
|
||||
if (wrapper.revertTask != null) {
|
||||
@@ -187,7 +85,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
// Called by internal level-up event listener
|
||||
public static void handleLevelUp(Player player, PrimarySkillType skill) {
|
||||
public void handleLevelUp(Player player, PrimarySkillType skill) {
|
||||
// Selfboards
|
||||
ScoreboardWrapper selfboardWrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
@@ -214,7 +112,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
// Called by internal xp event listener
|
||||
public static void handleXp(Player player, PrimarySkillType skill) {
|
||||
public void handleXp(Player player, PrimarySkillType skill) {
|
||||
// Selfboards
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
@@ -224,7 +122,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
// Called by internal ability event listeners
|
||||
public static void cooldownUpdate(Player player, PrimarySkillType skill) {
|
||||
public void cooldownUpdate(Player player, PrimarySkillType skill) {
|
||||
// Selfboards
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
@@ -233,7 +131,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void enablePlayerSkillScoreboard(Player player, PrimarySkillType skill) {
|
||||
public void enablePlayerSkillScoreboard(Player player, PrimarySkillType skill) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -244,7 +142,7 @@ public class ScoreboardManager {
|
||||
|
||||
// **** Setup methods **** //
|
||||
|
||||
public static void enablePlayerSkillLevelUpScoreboard(Player player, PrimarySkillType skill) {
|
||||
public void enablePlayerSkillLevelUpScoreboard(Player player, PrimarySkillType skill) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
// Do NOT run if already shown
|
||||
@@ -258,7 +156,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getConfigSectionScoreboardTypes().getConfigSectionSkillBoard().getShowBoardOnPlayerLevelUpTime());
|
||||
}
|
||||
|
||||
public static void enablePlayerStatsScoreboard(Player player) {
|
||||
public void enablePlayerStatsScoreboard(Player player) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -267,7 +165,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getScoreboardDisplayTime(SidebarType.STATS_BOARD));
|
||||
}
|
||||
|
||||
public static void enablePlayerInspectScoreboard(Player player, PlayerProfile targetProfile) {
|
||||
public void enablePlayerInspectScoreboard(Player player, PlayerProfile targetProfile) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -276,7 +174,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getConfigSectionScoreboardTypes().getConfigSectionInspectBoard().getDisplayTimeInSeconds());
|
||||
}
|
||||
|
||||
public static void enablePlayerCooldownScoreboard(Player player) {
|
||||
public void enablePlayerCooldownScoreboard(Player player) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -285,7 +183,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getScoreboardDisplayTime(SidebarType.COOLDOWNS_BOARD));
|
||||
}
|
||||
|
||||
public static void showPlayerRankScoreboard(Player player, Map<PrimarySkillType, Integer> rank) {
|
||||
public void showPlayerRankScoreboard(Player player, Map<PrimarySkillType, Integer> rank) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -295,7 +193,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getScoreboardDisplayTime(SidebarType.RANK_BOARD));
|
||||
}
|
||||
|
||||
public static void showPlayerRankScoreboardOthers(Player player, String targetName, Map<PrimarySkillType, Integer> rank) {
|
||||
public void showPlayerRankScoreboardOthers(Player player, String targetName, Map<PrimarySkillType, Integer> rank) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -305,7 +203,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getScoreboardDisplayTime(SidebarType.RANK_BOARD));
|
||||
}
|
||||
|
||||
public static void showTopScoreboard(Player player, PrimarySkillType skill, int pageNumber, List<PlayerStat> stats) {
|
||||
public void showTopScoreboard(Player player, PrimarySkillType skill, int pageNumber, List<PlayerStat> stats) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -315,7 +213,7 @@ public class ScoreboardManager {
|
||||
changeScoreboard(wrapper, pluginRef.getScoreboardSettings().getScoreboardDisplayTime(SidebarType.TOP_BOARD));
|
||||
}
|
||||
|
||||
public static void showTopPowerScoreboard(Player player, int pageNumber, List<PlayerStat> stats) {
|
||||
public void showTopPowerScoreboard(Player player, int pageNumber, List<PlayerStat> stats) {
|
||||
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
|
||||
|
||||
wrapper.setOldScoreboard();
|
||||
@@ -328,7 +226,7 @@ public class ScoreboardManager {
|
||||
/**
|
||||
* @return false if power levels are disabled
|
||||
*/
|
||||
public static boolean powerLevelHeartbeat() {
|
||||
public boolean powerLevelHeartbeat() {
|
||||
Objective mainObjective = getPowerLevelObjective();
|
||||
|
||||
if (mainObjective == null) {
|
||||
@@ -336,7 +234,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
for (String playerName : dirtyPowerLevels) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(playerName);
|
||||
|
||||
if (mcMMOPlayer == null) {
|
||||
continue;
|
||||
@@ -366,9 +264,9 @@ public class ScoreboardManager {
|
||||
*
|
||||
* @return the main targetBoard objective, or null if disabled
|
||||
*/
|
||||
public static Objective getPowerLevelObjective() {
|
||||
public Objective getPowerLevelObjective() {
|
||||
if (!pluginRef.getScoreboardSettings().getPowerLevelTagsEnabled()) {
|
||||
Objective objective = pluginRef.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
|
||||
Objective objective = pluginRef.getServer().getScoreboardManager().getMainScoreboard().getObjective(scoreboardStrings.POWER_OBJECTIVE);
|
||||
|
||||
if (objective != null) {
|
||||
objective.unregister();
|
||||
@@ -378,18 +276,18 @@ public class ScoreboardManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
Objective powerObjective = pluginRef.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
|
||||
Objective powerObjective = pluginRef.getServer().getScoreboardManager().getMainScoreboard().getObjective(scoreboardStrings.POWER_OBJECTIVE);
|
||||
|
||||
if (powerObjective == null) {
|
||||
powerObjective = pluginRef.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy");
|
||||
powerObjective.setDisplayName(TAG_POWER_LEVEL);
|
||||
powerObjective = pluginRef.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(scoreboardStrings.POWER_OBJECTIVE, "dummy");
|
||||
powerObjective.setDisplayName(scoreboardStrings.TAG_POWER_LEVEL);
|
||||
powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
|
||||
}
|
||||
|
||||
return powerObjective;
|
||||
}
|
||||
|
||||
private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) {
|
||||
private void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) {
|
||||
if (displayTime == -1) {
|
||||
wrapper.showBoardWithNoRevert();
|
||||
} else {
|
||||
@@ -397,28 +295,23 @@ public class ScoreboardManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBoardShown(String playerName) {
|
||||
public boolean isBoardShown(String playerName) {
|
||||
return PLAYER_SCOREBOARDS.get(playerName).isBoardShown();
|
||||
}
|
||||
|
||||
public static void clearBoard(String playerName) {
|
||||
public void clearBoard(String playerName) {
|
||||
PLAYER_SCOREBOARDS.get(playerName).tryRevertBoard();
|
||||
}
|
||||
|
||||
public static void keepBoard(String playerName) {
|
||||
public void keepBoard(String playerName) {
|
||||
PLAYER_SCOREBOARDS.get(playerName).cancelRevert();
|
||||
}
|
||||
|
||||
public static void setRevertTimer(String playerName, int seconds) {
|
||||
public void setRevertTimer(String playerName, int seconds) {
|
||||
PLAYER_SCOREBOARDS.get(playerName).showBoardAndScheduleRevert(seconds * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
public enum SidebarType {
|
||||
NONE,
|
||||
SKILL_BOARD,
|
||||
STATS_BOARD,
|
||||
COOLDOWNS_BOARD,
|
||||
RANK_BOARD,
|
||||
TOP_BOARD
|
||||
public List<String> getDirtyPowerLevels() {
|
||||
return dirtyPowerLevels;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,168 @@
|
||||
package com.gmail.nossr50.util.scoreboards;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Temporary class
|
||||
* Scoreboard code was a mess, in the process of unmaking it a static singleton cluster-@#$% I decided to hold off on rewriting that abomination and use this class a temporary band-aid fix
|
||||
*/
|
||||
//TODO: Rewrite scoreboard code so this thing doesn't need to exist
|
||||
public class ScoreboardStrings {
|
||||
private final mcMMO pluginRef;
|
||||
// do not localize; these are internal identifiers
|
||||
public final String SIDEBAR_OBJECTIVE = "mcmmo_sidebar";
|
||||
public final String POWER_OBJECTIVE = "mcmmo_pwrlvl";
|
||||
|
||||
public String HEADER_STATS;
|
||||
public final String HEADER_COOLDOWNS;
|
||||
public final String HEADER_RANK;
|
||||
public final String TAG_POWER_LEVEL;
|
||||
|
||||
public final String POWER_LEVEL;
|
||||
|
||||
public final String LABEL_POWER_LEVEL;
|
||||
public final String LABEL_LEVEL;
|
||||
public final String LABEL_CURRENT_XP;
|
||||
public final String LABEL_REMAINING_XP;
|
||||
public final String LABEL_ABILITY_COOLDOWN;
|
||||
public final String LABEL_OVERALL;
|
||||
|
||||
public Map<PrimarySkillType, String> skillLabels;
|
||||
public Map<SuperAbilityType, String> abilityLabelsColored;
|
||||
public Map<SuperAbilityType, String> abilityLabelsSkill;
|
||||
|
||||
public ScoreboardStrings(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
|
||||
HEADER_STATS = pluginRef.getLocaleManager().getString("Scoreboard.Header.PlayerStats");
|
||||
HEADER_COOLDOWNS = pluginRef.getLocaleManager().getString("Scoreboard.Header.PlayerCooldowns");
|
||||
HEADER_RANK = pluginRef.getLocaleManager().getString("Scoreboard.Header.PlayerRank");
|
||||
TAG_POWER_LEVEL = pluginRef.getLocaleManager().getString("Scoreboard.Header.PowerLevel");
|
||||
|
||||
POWER_LEVEL = pluginRef.getLocaleManager().getString("Scoreboard.Misc.PowerLevel");
|
||||
|
||||
LABEL_POWER_LEVEL = POWER_LEVEL;
|
||||
LABEL_LEVEL = pluginRef.getLocaleManager().getString("Scoreboard.Misc.Level");
|
||||
LABEL_CURRENT_XP = pluginRef.getLocaleManager().getString("Scoreboard.Misc.CurrentXP");
|
||||
LABEL_REMAINING_XP = pluginRef.getLocaleManager().getString("Scoreboard.Misc.RemainingXP");
|
||||
LABEL_ABILITY_COOLDOWN = pluginRef.getLocaleManager().getString("Scoreboard.Misc.Cooldown");
|
||||
LABEL_OVERALL = pluginRef.getLocaleManager().getString("Scoreboard.Misc.Overall");
|
||||
|
||||
init(pluginRef);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes the properties of this class
|
||||
*/
|
||||
private void init(mcMMO pluginRef) {
|
||||
/*
|
||||
* We need immutable objects for our ConfigScoreboard's labels
|
||||
*/
|
||||
ImmutableMap.Builder<PrimarySkillType, String> skillLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbilityType, String> abilityLabelBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<SuperAbilityType, String> abilityLabelSkillBuilder = ImmutableMap.builder();
|
||||
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
* Stylizes the targetBoard in a Rainbow Pattern
|
||||
* This is off by default
|
||||
*/
|
||||
if (pluginRef.getScoreboardSettings().getUseRainbowSkillStyling()) {
|
||||
// Everything but black, gray, gold
|
||||
List<ChatColor> colors = Lists.newArrayList(
|
||||
ChatColor.WHITE,
|
||||
ChatColor.YELLOW,
|
||||
ChatColor.LIGHT_PURPLE,
|
||||
ChatColor.RED,
|
||||
ChatColor.AQUA,
|
||||
ChatColor.GREEN,
|
||||
ChatColor.DARK_GRAY,
|
||||
ChatColor.BLUE,
|
||||
ChatColor.DARK_PURPLE,
|
||||
ChatColor.DARK_RED,
|
||||
ChatColor.DARK_AQUA,
|
||||
ChatColor.DARK_GREEN,
|
||||
ChatColor.DARK_BLUE);
|
||||
|
||||
Collections.shuffle(colors, Misc.getRandom());
|
||||
|
||||
int i = 0;
|
||||
for (PrimarySkillType type : PrimarySkillType.values()) {
|
||||
// Include child skills
|
||||
skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false));
|
||||
|
||||
if (type.getSuperAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getSuperAbility(), getShortenedName(colors.get(i) + type.getSuperAbility().getName()));
|
||||
|
||||
if (type == PrimarySkillType.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
if (++i == colors.size()) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
* Stylizes the targetBoard using our normal color scheme
|
||||
*/
|
||||
else {
|
||||
for (PrimarySkillType type : PrimarySkillType.values()) {
|
||||
// Include child skills
|
||||
skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName()));
|
||||
|
||||
if (type.getSuperAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getSuperAbility(), formatAbility(type.getSuperAbility().getName()));
|
||||
|
||||
if (type == PrimarySkillType.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SuperAbilityType type : SuperAbilityType.values()) {
|
||||
abilityLabelSkillBuilder.put(type, formatAbility((type == SuperAbilityType.BLAST_MINING ? ChatColor.BLUE : ChatColor.AQUA), type.getName()));
|
||||
}
|
||||
|
||||
skillLabels = skillLabelBuilder.build();
|
||||
abilityLabelsColored = abilityLabelBuilder.build();
|
||||
abilityLabelsSkill = abilityLabelSkillBuilder.build();
|
||||
}
|
||||
|
||||
private String formatAbility(String abilityName) {
|
||||
return formatAbility(ChatColor.AQUA, abilityName);
|
||||
}
|
||||
|
||||
private String formatAbility(ChatColor color, String abilityName) {
|
||||
if (pluginRef.getScoreboardSettings().getUseAbilityNamesOverGenerics()) {
|
||||
return getShortenedName(color + abilityName);
|
||||
} else {
|
||||
return color + pluginRef.getLocaleManager().getString("Scoreboard.Misc.Ability");
|
||||
}
|
||||
}
|
||||
|
||||
private String getShortenedName(String name) {
|
||||
return getShortenedName(name, true);
|
||||
}
|
||||
|
||||
private String getShortenedName(String name, boolean useDots) {
|
||||
if (name.length() > 16) {
|
||||
name = useDots ? name.substring(0, 14) + ".." : name.substring(0, 16);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -5,11 +5,13 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.events.scoreboard.*;
|
||||
import com.gmail.nossr50.events.scoreboard.McMMOScoreboardObjectiveEvent;
|
||||
import com.gmail.nossr50.events.scoreboard.McMMOScoreboardRevertEvent;
|
||||
import com.gmail.nossr50.events.scoreboard.ScoreboardEventReason;
|
||||
import com.gmail.nossr50.events.scoreboard.ScoreboardObjectiveEventReason;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -25,6 +27,9 @@ import java.util.Map;
|
||||
|
||||
public class ScoreboardWrapper {
|
||||
// Initialization variables
|
||||
public final mcMMO pluginRef;
|
||||
public final ScoreboardStrings scoreboardStrings;
|
||||
|
||||
public final String playerName;
|
||||
public final Player player;
|
||||
private final Scoreboard scoreboard;
|
||||
@@ -44,32 +49,28 @@ public class ScoreboardWrapper {
|
||||
private Scoreboard oldBoard = null;
|
||||
private PlayerProfile targetProfile = null;
|
||||
|
||||
private ScoreboardWrapper(Player player, Scoreboard scoreboard) {
|
||||
protected ScoreboardWrapper(Player player, Scoreboard scoreboard, ScoreboardStrings scoreboardStrings, mcMMO pluginRef) {
|
||||
this.scoreboardStrings = scoreboardStrings;
|
||||
this.pluginRef = pluginRef;
|
||||
|
||||
|
||||
this.player = player;
|
||||
this.playerName = player.getName();
|
||||
this.scoreboard = scoreboard;
|
||||
sidebarType = SidebarType.NONE;
|
||||
sidebarObjective = this.scoreboard.registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy");
|
||||
powerObjective = this.scoreboard.registerNewObjective(ScoreboardManager.POWER_OBJECTIVE, "dummy");
|
||||
sidebarObjective = this.scoreboard.registerNewObjective(scoreboardStrings.SIDEBAR_OBJECTIVE, "dummy");
|
||||
powerObjective = this.scoreboard.registerNewObjective(scoreboardStrings.POWER_OBJECTIVE, "dummy");
|
||||
|
||||
if (pluginRef.getScoreboardSettings().getPowerLevelTagsEnabled()) {
|
||||
powerObjective.setDisplayName(ScoreboardManager.TAG_POWER_LEVEL);
|
||||
powerObjective.setDisplayName(scoreboardStrings.TAG_POWER_LEVEL);
|
||||
powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
|
||||
|
||||
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) {
|
||||
for (McMMOPlayer mcMMOPlayer : pluginRef.getUserManager().getPlayers()) {
|
||||
powerObjective.getScore(mcMMOPlayer.getProfile().getPlayerName()).setScore(mcMMOPlayer.getPowerLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ScoreboardWrapper create(Player player) {
|
||||
//Call our custom event
|
||||
McMMOScoreboardMakeboardEvent event = new McMMOScoreboardMakeboardEvent(pluginRef.getServer().getScoreboardManager().getNewScoreboard(), player.getScoreboard(), player, ScoreboardEventReason.CREATING_NEW_SCOREBOARD);
|
||||
player.getServer().getPluginManager().callEvent(event);
|
||||
//Use the values from the event
|
||||
return new ScoreboardWrapper(event.getTargetPlayer(), event.getTargetBoard());
|
||||
}
|
||||
|
||||
public void doSidebarUpdateSoon() {
|
||||
if (updateTask == null) {
|
||||
// To avoid spamming the scheduler, store the instance and run 2 ticks later
|
||||
@@ -115,7 +116,7 @@ public class ScoreboardWrapper {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
ScoreboardManager.cleanup(this);
|
||||
pluginRef.getScoreboardManager().cleanup(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ public class ScoreboardWrapper {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
ScoreboardManager.cleanup(this);
|
||||
pluginRef.getScoreboardManager().cleanup(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ public class ScoreboardWrapper {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
ScoreboardManager.cleanup(this);
|
||||
pluginRef.getScoreboardManager().cleanup(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,10 +166,10 @@ public class ScoreboardWrapper {
|
||||
// TODO is there any way to do the time that looks acceptable?
|
||||
// player.sendMessage(pluginRef.getLocaleManager().getString("Commands.ConfigScoreboard.Timer", StringUtils.capitalize(sidebarType.toString().toLowerCase()), ticks / 20F));
|
||||
|
||||
if (UserManager.getPlayer(playerName) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(playerName) == null)
|
||||
return;
|
||||
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
PlayerProfile profile = pluginRef.getUserManager().getPlayer(player).getProfile();
|
||||
|
||||
if (profile.getScoreboardTipsShown() >= pluginRef.getScoreboardSettings().getTipsAmount()) {
|
||||
return;
|
||||
@@ -188,7 +189,7 @@ public class ScoreboardWrapper {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
ScoreboardManager.cleanup(this);
|
||||
pluginRef.getScoreboardManager().cleanup(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -220,7 +221,7 @@ public class ScoreboardWrapper {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
ScoreboardManager.cleanup(this);
|
||||
pluginRef.getScoreboardManager().cleanup(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -255,7 +256,7 @@ public class ScoreboardWrapper {
|
||||
targetProfile = null;
|
||||
leaderboardPage = -1;
|
||||
|
||||
loadObjective(ScoreboardManager.skillLabels.get(skill));
|
||||
loadObjective(scoreboardStrings.skillLabels.get(skill));
|
||||
}
|
||||
|
||||
public void setTypeSelfStats() {
|
||||
@@ -266,7 +267,7 @@ public class ScoreboardWrapper {
|
||||
targetProfile = null;
|
||||
leaderboardPage = -1;
|
||||
|
||||
loadObjective(ScoreboardManager.HEADER_STATS);
|
||||
loadObjective(scoreboardStrings.HEADER_STATS);
|
||||
}
|
||||
|
||||
// Board Type Changing 'API' methods
|
||||
@@ -290,7 +291,7 @@ public class ScoreboardWrapper {
|
||||
targetProfile = null;
|
||||
leaderboardPage = -1;
|
||||
|
||||
loadObjective(ScoreboardManager.HEADER_COOLDOWNS);
|
||||
loadObjective(scoreboardStrings.HEADER_COOLDOWNS);
|
||||
}
|
||||
|
||||
public void setTypeSelfRank() {
|
||||
@@ -301,7 +302,7 @@ public class ScoreboardWrapper {
|
||||
targetProfile = null;
|
||||
leaderboardPage = -1;
|
||||
|
||||
loadObjective(ScoreboardManager.HEADER_RANK);
|
||||
loadObjective(scoreboardStrings.HEADER_RANK);
|
||||
}
|
||||
|
||||
public void setTypeInspectRank(String otherPlayer) {
|
||||
@@ -312,7 +313,7 @@ public class ScoreboardWrapper {
|
||||
targetProfile = null;
|
||||
leaderboardPage = -1;
|
||||
|
||||
loadObjective(ScoreboardManager.HEADER_RANK);
|
||||
loadObjective(scoreboardStrings.HEADER_RANK);
|
||||
}
|
||||
|
||||
public void setTypeTopPower(int page) {
|
||||
@@ -325,7 +326,7 @@ public class ScoreboardWrapper {
|
||||
|
||||
int endPosition = page * 10;
|
||||
int startPosition = endPosition - 9;
|
||||
loadObjective(String.format("%s (%2d - %2d)", ScoreboardManager.POWER_LEVEL, startPosition, endPosition));
|
||||
loadObjective(String.format("%s (%2d - %2d)", scoreboardStrings.POWER_LEVEL, startPosition, endPosition));
|
||||
}
|
||||
|
||||
public void setTypeTop(PrimarySkillType skill, int page) {
|
||||
@@ -338,7 +339,7 @@ public class ScoreboardWrapper {
|
||||
|
||||
int endPosition = page * 10;
|
||||
int startPosition = endPosition - 9;
|
||||
loadObjective(String.format("%s (%2d - %2d)", ScoreboardManager.skillLabels.get(skill), startPosition, endPosition));
|
||||
loadObjective(String.format("%s (%2d - %2d)", scoreboardStrings.skillLabels.get(skill), startPosition, endPosition));
|
||||
}
|
||||
|
||||
// Setup for after a board type change
|
||||
@@ -352,7 +353,7 @@ public class ScoreboardWrapper {
|
||||
//Register objective
|
||||
McMMOScoreboardObjectiveEvent registerEvent = callObjectiveEvent(ScoreboardObjectiveEventReason.REGISTER_NEW_OBJECTIVE);
|
||||
if (!registerEvent.isCancelled())
|
||||
sidebarObjective = registerEvent.getTargetBoard().registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy");
|
||||
sidebarObjective = registerEvent.getTargetBoard().registerNewObjective(scoreboardStrings.SIDEBAR_OBJECTIVE, "dummy");
|
||||
|
||||
if (displayName.length() > 32) {
|
||||
displayName = displayName.substring(0, 32);
|
||||
@@ -389,11 +390,11 @@ public class ScoreboardWrapper {
|
||||
Player player = pluginRef.getServer().getPlayerExact(playerName);
|
||||
|
||||
if (player == null) {
|
||||
ScoreboardManager.cleanup(this);
|
||||
pluginRef.getScoreboardManager().cleanup(this);
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
|
||||
if (mcMMOPlayer == null)
|
||||
return;
|
||||
@@ -406,23 +407,23 @@ public class ScoreboardWrapper {
|
||||
if (!targetSkill.isChildSkill()) {
|
||||
int currentXP = mcMMOPlayer.getSkillXpLevel(targetSkill);
|
||||
|
||||
sidebarObjective.getScore(ScoreboardManager.LABEL_CURRENT_XP).setScore(currentXP);
|
||||
sidebarObjective.getScore(ScoreboardManager.LABEL_REMAINING_XP).setScore(mcMMOPlayer.getXpToLevel(targetSkill) - currentXP);
|
||||
sidebarObjective.getScore(scoreboardStrings.LABEL_CURRENT_XP).setScore(currentXP);
|
||||
sidebarObjective.getScore(scoreboardStrings.LABEL_REMAINING_XP).setScore(mcMMOPlayer.getXpToLevel(targetSkill) - currentXP);
|
||||
} else {
|
||||
for (PrimarySkillType parentSkill : FamilyTree.getParents(targetSkill)) {
|
||||
sidebarObjective.getScore(ScoreboardManager.skillLabels.get(parentSkill)).setScore(mcMMOPlayer.getSkillLevel(parentSkill));
|
||||
sidebarObjective.getScore(scoreboardStrings.skillLabels.get(parentSkill)).setScore(mcMMOPlayer.getSkillLevel(parentSkill));
|
||||
}
|
||||
}
|
||||
|
||||
sidebarObjective.getScore(ScoreboardManager.LABEL_LEVEL).setScore(mcMMOPlayer.getSkillLevel(targetSkill));
|
||||
sidebarObjective.getScore(scoreboardStrings.LABEL_LEVEL).setScore(mcMMOPlayer.getSkillLevel(targetSkill));
|
||||
|
||||
if (targetSkill.getSuperAbility() != null) {
|
||||
boolean stopUpdating;
|
||||
|
||||
if (targetSkill == PrimarySkillType.MINING) {
|
||||
// Special-Case: Mining has two abilities, both with cooldowns
|
||||
Score cooldownSB = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(SuperAbilityType.SUPER_BREAKER));
|
||||
Score cooldownBM = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(SuperAbilityType.BLAST_MINING));
|
||||
Score cooldownSB = sidebarObjective.getScore(scoreboardStrings.abilityLabelsSkill.get(SuperAbilityType.SUPER_BREAKER));
|
||||
Score cooldownBM = sidebarObjective.getScore(scoreboardStrings.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);
|
||||
|
||||
@@ -432,7 +433,7 @@ public class ScoreboardWrapper {
|
||||
stopUpdating = (secondsSB == 0 && secondsBM == 0);
|
||||
} else {
|
||||
SuperAbilityType ability = targetSkill.getSuperAbility();
|
||||
Score cooldown = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(ability));
|
||||
Score cooldown = sidebarObjective.getScore(scoreboardStrings.abilityLabelsSkill.get(ability));
|
||||
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
|
||||
|
||||
cooldown.setScore(seconds);
|
||||
@@ -458,7 +459,7 @@ public class ScoreboardWrapper {
|
||||
anyCooldownsActive = true;
|
||||
}
|
||||
|
||||
sidebarObjective.getScore(ScoreboardManager.abilityLabelsColored.get(ability)).setScore(seconds);
|
||||
sidebarObjective.getScore(scoreboardStrings.abilityLabelsColored.get(ability)).setScore(seconds);
|
||||
}
|
||||
|
||||
if (anyCooldownsActive) {
|
||||
@@ -477,7 +478,7 @@ public class ScoreboardWrapper {
|
||||
} else if (targetPlayer == null) {
|
||||
newProfile = mcMMOPlayer.getProfile(); // self
|
||||
} else {
|
||||
newProfile = UserManager.getPlayer(targetPlayer).getProfile(); // online
|
||||
newProfile = pluginRef.getUserManager().getPlayer(targetPlayer).getProfile(); // online
|
||||
}
|
||||
|
||||
// Calculate power level here
|
||||
@@ -492,10 +493,10 @@ public class ScoreboardWrapper {
|
||||
continue;
|
||||
}
|
||||
|
||||
sidebarObjective.getScore(ScoreboardManager.skillLabels.get(skill)).setScore(level);
|
||||
sidebarObjective.getScore(scoreboardStrings.skillLabels.get(skill)).setScore(level);
|
||||
}
|
||||
|
||||
sidebarObjective.getScore(ScoreboardManager.LABEL_POWER_LEVEL).setScore(powerLevel);
|
||||
sidebarObjective.getScore(scoreboardStrings.LABEL_POWER_LEVEL).setScore(powerLevel);
|
||||
break;
|
||||
|
||||
case RANK_BOARD:
|
||||
@@ -523,14 +524,14 @@ public class ScoreboardWrapper {
|
||||
rank = rankData.get(skill);
|
||||
|
||||
if (rank != null) {
|
||||
sidebarObjective.getScore(ScoreboardManager.skillLabels.get(skill)).setScore(rank);
|
||||
sidebarObjective.getScore(scoreboardStrings.skillLabels.get(skill)).setScore(rank);
|
||||
}
|
||||
}
|
||||
|
||||
rank = rankData.get(null);
|
||||
|
||||
if (rank != null) {
|
||||
sidebarObjective.getScore(ScoreboardManager.LABEL_POWER_LEVEL).setScore(rank);
|
||||
sidebarObjective.getScore(scoreboardStrings.LABEL_POWER_LEVEL).setScore(rank);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package com.gmail.nossr50.util.scoreboards;
|
||||
|
||||
public enum SidebarType {
|
||||
NONE,
|
||||
SKILL_BOARD,
|
||||
STATS_BOARD,
|
||||
COOLDOWNS_BOARD,
|
||||
RANK_BOARD,
|
||||
TOP_BOARD
|
||||
}
|
@@ -22,7 +22,6 @@ import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -49,7 +48,7 @@ public final class CombatUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
||||
double initialDamage = event.getDamage();
|
||||
double finalDamage = initialDamage;
|
||||
@@ -92,7 +91,7 @@ public final class CombatUtils {
|
||||
double finalDamage = initialDamage;
|
||||
Map<DamageModifier, Double> modifiers = getModifiers(event);
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
AxesManager axesManager = mcMMOPlayer.getAxesManager();
|
||||
|
||||
if (axesManager.canActivateAbility()) {
|
||||
@@ -133,7 +132,7 @@ public final class CombatUtils {
|
||||
double initialDamage = event.getDamage();
|
||||
double finalDamage = initialDamage;
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
||||
|
||||
if (unarmedManager.canActivateAbility()) {
|
||||
@@ -168,7 +167,7 @@ public final class CombatUtils {
|
||||
double initialDamage = event.getDamage();
|
||||
double finalDamage = initialDamage;
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(master);
|
||||
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
||||
|
||||
if (tamingManager.canUseFastFoodService()) {
|
||||
@@ -192,13 +191,13 @@ public final class CombatUtils {
|
||||
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) {
|
||||
double initialDamage = event.getDamage();
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
||||
|
||||
double finalDamage = event.getDamage();
|
||||
|
||||
if (target instanceof Player && PrimarySkillType.UNARMED.getPVPEnabled()) {
|
||||
UnarmedManager unarmedManager = UserManager.getPlayer((Player) target).getUnarmedManager();
|
||||
UnarmedManager unarmedManager = pluginRef.getUserManager().getPlayer((Player) target).getUnarmedManager();
|
||||
|
||||
if (unarmedManager.canDeflect()) {
|
||||
event.setCancelled(unarmedManager.deflectCheck());
|
||||
@@ -250,10 +249,10 @@ public final class CombatUtils {
|
||||
}
|
||||
|
||||
Player player = (Player) target;
|
||||
if (!UserManager.hasPlayerDataKey(player)) {
|
||||
if (!pluginRef.getUserManager().hasPlayerDataKey(player)) {
|
||||
return;
|
||||
}
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||
|
||||
if (acrobaticsManager.canDodge(target)) {
|
||||
@@ -276,7 +275,7 @@ public final class CombatUtils {
|
||||
if (attacker instanceof Player && entityType == EntityType.PLAYER) {
|
||||
Player player = (Player) attacker;
|
||||
|
||||
if (!UserManager.hasPlayerDataKey(player)) {
|
||||
if (!pluginRef.getUserManager().hasPlayerDataKey(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -284,7 +283,7 @@ public final class CombatUtils {
|
||||
|
||||
if (target instanceof Tameable) {
|
||||
if (heldItem.getType() == Material.BONE) {
|
||||
TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();
|
||||
TamingManager tamingManager = pluginRef.getUserManager().getPlayer(player).getTamingManager();
|
||||
|
||||
if (tamingManager.canUseBeastLore()) {
|
||||
tamingManager.beastLore(target);
|
||||
@@ -346,7 +345,7 @@ public final class CombatUtils {
|
||||
}
|
||||
|
||||
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && PrimarySkillType.TAMING.getPermissions(player)) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
||||
tamingManager.attackTarget(target);
|
||||
}
|
||||
@@ -497,7 +496,7 @@ public final class CombatUtils {
|
||||
pluginRef.getNotificationManager().sendPlayerInformation((Player) entity, NotificationType.SUBSKILL_MESSAGE, "Swords.Combat.SS.Struck");
|
||||
}
|
||||
|
||||
UserManager.getPlayer(attacker).getSwordsManager().ruptureCheck(target);
|
||||
pluginRef.getUserManager().getPlayer(attacker).getSwordsManager().ruptureCheck(target);
|
||||
break;
|
||||
|
||||
case AXES:
|
||||
@@ -601,10 +600,10 @@ public final class CombatUtils {
|
||||
Player defender = (Player) entity;
|
||||
|
||||
//TODO: NPC Interaction?
|
||||
if (UserManager.getPlayer(defender) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(defender) == null)
|
||||
return true;
|
||||
|
||||
if (!defender.getWorld().getPVP() || defender == player || UserManager.getPlayer(defender).getGodMode()) {
|
||||
if (!defender.getWorld().getPVP() || defender == player || pluginRef.getUserManager().getPlayer(defender).getGodMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,6 @@ 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.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
@@ -169,11 +168,11 @@ public class RankUtils {
|
||||
//Get our rank map
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
|
||||
|
||||
if (UserManager.getPlayer(player) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(player) == null)
|
||||
return 0;
|
||||
|
||||
//Skill level of parent skill
|
||||
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkillType.getParentSkill());
|
||||
int currentSkillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(subSkillType.getParentSkill());
|
||||
|
||||
for (int i = 0; i < numRanks; i++) {
|
||||
//Compare against the highest to lowest rank in that order
|
||||
@@ -215,11 +214,11 @@ public class RankUtils {
|
||||
//Get our rank map
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
|
||||
|
||||
if (UserManager.getPlayer(player) == null)
|
||||
if (pluginRef.getUserManager().getPlayer(player) == null)
|
||||
return 0;
|
||||
|
||||
//Skill level of parent skill
|
||||
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
|
||||
int currentSkillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
|
||||
|
||||
for (int i = 0; i < numRanks; i++) {
|
||||
//Compare against the highest to lowest rank in that order
|
||||
|
@@ -181,7 +181,7 @@ public class SkillUtils {
|
||||
}
|
||||
}
|
||||
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(player);
|
||||
|
||||
//Not Loaded
|
||||
if(mcMMOPlayer == null)
|
||||
|
Reference in New Issue
Block a user