Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into tridentsxbows

This commit is contained in:
nossr50 2020-08-08 19:37:04 -07:00
commit 9038abac8f
4 changed files with 233 additions and 113 deletions

View File

@ -48,13 +48,19 @@ Version 2.2.000
Notes:
These are the first new skills that I've written for mcMMO in about 9 years, I'll be listening closely to feedback and tweaking them often.
Version 2.1.140
Deployed a few fixes to scoreboards code
Updated polish locale
NOTES:
Scoreboards code is a mess and most of it is ancient, I plan to rewrite it in a future update. The way scoreboards API works in general is just difficult to deal with.
Version 2.1.139
Code used to fetch UUIDs was reworked to avoid a scenario where it failed (thanks t00thpick1)
Added 'Netherite_Gold_Ore' to Smelting XP tables (thanks Quavelen)
Added 'Gilded_Blackstone' and 'Nether_Gold_Ore' to code used to determine what can activate Super Breaker in certain situations (thanks Quavelen)
MMOinfo for Roll was corrected (thanks emanondev)
>>>>>>> 8df15a4e55b27af7ac0fc72d587acc2bdf5b966a
Version 2.1.138
Fixed a bug where Netherite weapons/tools/armor weren't applying correct values in some skill calculations

View File

@ -33,39 +33,40 @@ public class SelfListener implements Listener {
public void onPlayerLevelUp(McMMOPlayerLevelUpEvent event) {
Player player = event.getPlayer();
PrimarySkillType skill = event.getSkill();
if(player.isOnline()) {
//Players can gain multiple levels especially during xprate events
for(int i = 0; i < event.getLevelsGained(); i++)
{
int previousLevelGained = event.getSkillLevel() - i;
//Send player skill unlock notifications
UserManager.getPlayer(player).processUnlockNotifications(plugin, event.getSkill(), previousLevelGained);
}
//Players can gain multiple levels especially during xprate events
for(int i = 0; i < event.getLevelsGained(); i++)
{
int previousLevelGained = event.getSkillLevel() - i;
//Send player skill unlock notifications
UserManager.getPlayer(player).processUnlockNotifications(plugin, event.getSkill(), previousLevelGained);
//Reset the delay timer
RankUtils.resetUnlockDelayTimer();
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.handleLevelUp(player, skill);
}
//Reset the delay timer
RankUtils.resetUnlockDelayTimer();
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.handleLevelUp(player, skill);
if (!Config.getInstance().getLevelUpEffectsEnabled()) {
}
/*if ((event.getSkillLevel() % Config.getInstance().getLevelUpEffectsTier()) == 0) {
skill.celebrateLevelUp(player);
}*/
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerXp(McMMOPlayerXpGainEvent event) {
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.handleXp(event.getPlayer(), event.getSkill());
Player player = event.getPlayer();
if(player.isOnline()) {
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.handleXp(player, event.getSkill());
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAbility(McMMOPlayerAbilityActivateEvent event) {
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.cooldownUpdate(event.getPlayer(), event.getSkill());
Player player = event.getPlayer();
if(player.isOnline()) {
if(Config.getInstance().getScoreboardsEnabled())
ScoreboardManager.cooldownUpdate(event.getPlayer(), event.getSkill());
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)

View File

@ -6,6 +6,8 @@ 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.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
@ -18,6 +20,8 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@ -42,13 +46,15 @@ public class ScoreboardManager {
static final String LABEL_LEVEL = LocaleLoader.getString("Scoreboard.Misc.Level");
static final String LABEL_CURRENT_XP = LocaleLoader.getString("Scoreboard.Misc.CurrentXP");
static final String LABEL_REMAINING_XP = LocaleLoader.getString("Scoreboard.Misc.RemainingXP");
static final String LABEL_ABILITY_COOLDOWN = LocaleLoader.getString("Scoreboard.Misc.Cooldown");
static final String LABEL_OVERALL = LocaleLoader.getString("Scoreboard.Misc.Overall");
// static final String LABEL_ABILITY_COOLDOWN = LocaleLoader.getString("Scoreboard.Misc.Cooldown");
// static final String LABEL_OVERALL = LocaleLoader.getString("Scoreboard.Misc.Overall");
static final Map<PrimarySkillType, String> skillLabels;
static final Map<SuperAbilityType, String> abilityLabelsColored;
static final Map<SuperAbilityType, String> abilityLabelsSkill;
public static final String DISPLAY_NAME = "powerLevel";
/*
* Initializes the static properties of this class
*/
@ -170,21 +176,28 @@ public class ScoreboardManager {
// Called by PlayerJoinEvent listener
public static void setupPlayer(Player player) {
PLAYER_SCOREBOARDS.put(player.getName(), ScoreboardWrapper.create(player));
teardownPlayer(player);
PLAYER_SCOREBOARDS.put(player.getName(), makeNewScoreboard(player));
dirtyPowerLevels.add(player.getName());
}
// Called by PlayerQuitEvent listener and OnPlayerTeleport under certain circumstances
public static void teardownPlayer(Player player) {
if(player == null)
return;
//Hacky world blacklist fix
if(player.isOnline() && player.isValid())
if(player.isOnline() && player.isValid()) {
if(Bukkit.getServer().getScoreboardManager() != null)
player.setScoreboard(Bukkit.getServer().getScoreboardManager().getMainScoreboard());
}
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.remove(player.getName());
if (wrapper != null && wrapper.revertTask != null) {
wrapper.revertTask.cancel();
if(getWrapper(player) != null) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.remove(player.getName());
if(wrapper.revertTask != null) {
wrapper.revertTask.cancel();
}
}
}
@ -209,34 +222,42 @@ public class ScoreboardManager {
// Called by internal level-up event listener
public static void handleLevelUp(Player player, PrimarySkillType skill) {
// Selfboards
ScoreboardWrapper selfboardWrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
if ((selfboardWrapper.isSkillScoreboard() && selfboardWrapper.targetSkill == skill) || (selfboardWrapper.isStatsScoreboard()) && selfboardWrapper.isBoardShown()) {
selfboardWrapper.doSidebarUpdateSoon();
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
// Otherboards
String playerName = player.getName();
for (ScoreboardWrapper wrapper : PLAYER_SCOREBOARDS.values()) {
if (wrapper.isStatsScoreboard() && playerName.equals(wrapper.targetPlayer) && selfboardWrapper.isBoardShown()) {
selfboardWrapper.doSidebarUpdateSoon();
if(wrapper != null) {
if ((wrapper.isSkillScoreboard() && wrapper.targetSkill == skill) || (wrapper.isStatsScoreboard()) && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon();
}
}
if (Config.getInstance().getPowerLevelTagsEnabled() && !dirtyPowerLevels.contains(playerName)) {
dirtyPowerLevels.add(playerName);
}
// Otherboards
String playerName = player.getName();
for (ScoreboardWrapper iWrapper : PLAYER_SCOREBOARDS.values()) {
if (iWrapper.isStatsScoreboard() && playerName.equals(iWrapper.targetPlayer) && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon();
}
}
if (Config.getInstance().getPowerLevelTagsEnabled() && !dirtyPowerLevels.contains(playerName)) {
dirtyPowerLevels.add(playerName);
}
if (Config.getInstance().getSkillLevelUpBoard()) {
enablePlayerSkillLevelUpScoreboard(player, skill);
}
if (Config.getInstance().getSkillLevelUpBoard()) {
enablePlayerSkillLevelUpScoreboard(player, skill);
}
}
// Called by internal xp event listener
public static void handleXp(Player player, PrimarySkillType skill) {
// Selfboards
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
if (wrapper != null && wrapper.isSkillScoreboard() && wrapper.targetSkill == skill && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon();
@ -246,40 +267,59 @@ public class ScoreboardManager {
// Called by internal ability event listeners
public static void cooldownUpdate(Player player, PrimarySkillType skill) {
// Selfboards
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
if (wrapper != null && (wrapper.isCooldownScoreboard() || wrapper.isSkillScoreboard() && wrapper.targetSkill == skill) && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon();
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
if ((wrapper.isCooldownScoreboard() || wrapper.isSkillScoreboard() && wrapper.targetSkill == skill) && wrapper.isBoardShown()) {
wrapper.doSidebarUpdateSoon();
}
}
}
// **** Setup methods **** //
public static void enablePlayerSkillScoreboard(Player player, PrimarySkillType skill) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
wrapper.setOldScoreboard();
wrapper.setTypeSkill(skill);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
changeScoreboard(wrapper, Config.getInstance().getSkillScoreboardTime());
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeSkill(skill);
changeScoreboard(wrapper, Config.getInstance().getSkillScoreboardTime());
}
}
public static void enablePlayerSkillLevelUpScoreboard(Player player, PrimarySkillType skill) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
// Do NOT run if already shown
if (wrapper.isBoardShown()) {
return;
if (wrapper != null && wrapper.isBoardShown()) {
if(wrapper.isBoardShown())
return;
wrapper.setOldScoreboard();
wrapper.setTypeSkill(skill);
changeScoreboard(wrapper, Config.getInstance().getSkillLevelUpTime());
}
wrapper.setOldScoreboard();
wrapper.setTypeSkill(skill);
changeScoreboard(wrapper, Config.getInstance().getSkillLevelUpTime());
}
public static void enablePlayerStatsScoreboard(Player player) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null)
return;
wrapper.setOldScoreboard();
wrapper.setTypeSelfStats();
@ -288,61 +328,112 @@ public class ScoreboardManager {
}
public static void enablePlayerInspectScoreboard(Player player, PlayerProfile targetProfile) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
wrapper.setOldScoreboard();
wrapper.setTypeInspectStats(targetProfile);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
changeScoreboard(wrapper, Config.getInstance().getInspectScoreboardTime());
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeInspectStats(targetProfile);
changeScoreboard(wrapper, Config.getInstance().getInspectScoreboardTime());
}
}
public static void enablePlayerCooldownScoreboard(Player player) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
wrapper.setOldScoreboard();
wrapper.setTypeCooldowns();
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
changeScoreboard(wrapper, Config.getInstance().getCooldownScoreboardTime());
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeCooldowns();
changeScoreboard(wrapper, Config.getInstance().getCooldownScoreboardTime());
}
}
public static void showPlayerRankScoreboard(Player player, Map<PrimarySkillType, Integer> rank) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
wrapper.setOldScoreboard();
wrapper.setTypeSelfRank();
wrapper.acceptRankData(rank);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime());
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeSelfRank();
wrapper.acceptRankData(rank);
changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime());
}
}
public static void showPlayerRankScoreboardOthers(Player player, String targetName, Map<PrimarySkillType, Integer> rank) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
wrapper.setOldScoreboard();
wrapper.setTypeInspectRank(targetName);
wrapper.acceptRankData(rank);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime());
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeInspectRank(targetName);
wrapper.acceptRankData(rank);
changeScoreboard(wrapper, Config.getInstance().getRankScoreboardTime());
}
}
public static void showTopScoreboard(Player player, PrimarySkillType skill, int pageNumber, List<PlayerStat> stats) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
wrapper.setOldScoreboard();
wrapper.setTypeTop(skill, pageNumber);
wrapper.acceptLeaderboardData(stats);
ScoreboardWrapper wrapper = getWrapper(player);
changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime());
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeTop(skill, pageNumber);
wrapper.acceptLeaderboardData(stats);
changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime());
}
}
public static void showTopPowerScoreboard(Player player, int pageNumber, List<PlayerStat> stats) {
ScoreboardWrapper wrapper = PLAYER_SCOREBOARDS.get(player.getName());
ScoreboardWrapper wrapper = getWrapper(player);
wrapper.setOldScoreboard();
wrapper.setTypeTopPower(pageNumber);
wrapper.acceptLeaderboardData(stats);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime());
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeTopPower(pageNumber);
wrapper.acceptLeaderboardData(stats);
changeScoreboard(wrapper, Config.getInstance().getTopScoreboardTime());
}
}
public static @Nullable ScoreboardWrapper getWrapper(Player player) {
if(PLAYER_SCOREBOARDS.get(player.getName()) == null) {
makeNewScoreboard(player);
}
return PLAYER_SCOREBOARDS.get(player.getName());
}
// **** Helper methods **** //
@ -386,9 +477,12 @@ public class ScoreboardManager {
*
* @return the main targetBoard objective, or null if disabled
*/
public static Objective getPowerLevelObjective() {
public static @Nullable Objective getPowerLevelObjective() {
if (!Config.getInstance().getPowerLevelTagsEnabled()) {
Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if(getScoreboardManager() == null)
return null;
Objective objective = getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if (objective != null) {
objective.unregister();
@ -398,10 +492,14 @@ public class ScoreboardManager {
return null;
}
Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if(getScoreboardManager() == null)
return null;
Objective powerObjective = getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if (powerObjective == null) {
powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy");
powerObjective = getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy", DISPLAY_NAME);
powerObjective.setDisplayName(TAG_POWER_LEVEL);
powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
}
@ -409,6 +507,11 @@ public class ScoreboardManager {
return powerObjective;
}
public @Nullable static org.bukkit.scoreboard.ScoreboardManager getScoreboardManager() {
return mcMMO.p.getServer().getScoreboardManager();
}
private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) {
if (displayTime == -1) {
wrapper.showBoardWithNoRevert();
@ -433,4 +536,16 @@ public class ScoreboardManager {
public static void setRevertTimer(String playerName, int seconds) {
PLAYER_SCOREBOARDS.get(playerName).showBoardAndScheduleRevert(seconds * Misc.TICK_CONVERSION_FACTOR);
}
public static @Nullable ScoreboardWrapper makeNewScoreboard(Player player) {
if(getScoreboardManager() == null)
return null;
//Call our custom event
Scoreboard scoreboard = getScoreboardManager().getNewScoreboard();
McMMOScoreboardMakeboardEvent event = new McMMOScoreboardMakeboardEvent(scoreboard, 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());
}
}

View File

@ -6,7 +6,10 @@ 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.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.child.FamilyTree;
@ -27,6 +30,8 @@ import java.util.List;
import java.util.Map;
public class ScoreboardWrapper {
public static final String SIDE_OBJECTIVE = "mcMMO_sideObjective";
public static final String POWER_OBJECTIVE = "mcMMO_powerObjective";
// Initialization variables
public final String playerName;
public final Player player;
@ -46,13 +51,13 @@ public class ScoreboardWrapper {
private PlayerProfile targetProfile = null;
public int leaderboardPage = -1;
private ScoreboardWrapper(Player player, Scoreboard scoreboard) {
public ScoreboardWrapper(Player player, Scoreboard scoreboard) {
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(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy", SIDE_OBJECTIVE);
powerObjective = this.scoreboard.registerNewObjective(ScoreboardManager.POWER_OBJECTIVE, "dummy", POWER_OBJECTIVE);
if (Config.getInstance().getPowerLevelTagsEnabled()) {
powerObjective.setDisplayName(ScoreboardManager.TAG_POWER_LEVEL);
@ -64,14 +69,6 @@ public class ScoreboardWrapper {
}
}
public static ScoreboardWrapper create(Player player) {
//Call our custom event
McMMOScoreboardMakeboardEvent event = new McMMOScoreboardMakeboardEvent(mcMMO.p.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 BukkitTask updateTask = null;
private class ScoreboardQuickUpdate extends BukkitRunnable {
@ -158,16 +155,17 @@ public class ScoreboardWrapper {
return;
}
Scoreboard oldBoard = player.getScoreboard();
Scoreboard previousBoard = player.getScoreboard();
if (oldBoard == scoreboard) { // Already displaying it
if (previousBoard == scoreboard) { // Already displaying it
if (this.oldBoard == null) {
// (Shouldn't happen) Use failsafe value - we're already displaying our board, but we don't have the one we should revert to
this.oldBoard = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard();
if(mcMMO.p.getServer().getScoreboardManager() != null)
this.oldBoard = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard();
}
}
else {
this.oldBoard = oldBoard;
this.oldBoard = previousBoard;
}
}
@ -394,7 +392,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(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy", SIDE_OBJECTIVE);
if (displayName.length() > 32) {
displayName = displayName.substring(0, 32);