mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
I guess I'm bad at git
This commit is contained in:
@ -67,7 +67,7 @@ public class ScoreboardManager {
|
||||
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
* Stylizes the scoreboard in a Rainbow Pattern
|
||||
* Stylizes the targetBoard in a Rainbow Pattern
|
||||
* This is off by default
|
||||
*/
|
||||
if (Config.getInstance().getScoreboardRainbows()) {
|
||||
@ -109,7 +109,7 @@ public class ScoreboardManager {
|
||||
}
|
||||
/*
|
||||
* Builds the labels for our ScoreBoards
|
||||
* Stylizes the scoreboard using our normal color scheme
|
||||
* Stylizes the targetBoard using our normal color scheme
|
||||
*/
|
||||
else {
|
||||
for (PrimarySkill type : PrimarySkill.values()) {
|
||||
@ -379,12 +379,12 @@ public class ScoreboardManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or creates the power level objective on the main scoreboard.
|
||||
* Gets or creates the power level objective on the main targetBoard.
|
||||
* <p/>
|
||||
* If power levels are disabled, the objective is deleted and null is
|
||||
* returned.
|
||||
*
|
||||
* @return the main scoreboard objective, or null if disabled
|
||||
* @return the main targetBoard objective, or null if disabled
|
||||
*/
|
||||
public static Objective getPowerLevelObjective() {
|
||||
if (!Config.getInstance().getPowerLevelTagsEnabled()) {
|
||||
@ -392,7 +392,7 @@ public class ScoreboardManager {
|
||||
|
||||
if (objective != null) {
|
||||
objective.unregister();
|
||||
mcMMO.p.debug("Removed leftover scoreboard objects from Power Level Tags.");
|
||||
mcMMO.p.debug("Removed leftover targetBoard objects from Power Level Tags.");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -3,6 +3,7 @@ package com.gmail.nossr50.util.scoreboards;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.gmail.nossr50.events.scoreboard.*;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -30,6 +31,7 @@ import org.apache.commons.lang.Validate;
|
||||
public class ScoreboardWrapper {
|
||||
// Initialization variables
|
||||
public final String playerName;
|
||||
public final Player player;
|
||||
private final Scoreboard scoreboard;
|
||||
private boolean tippedKeep = false;
|
||||
private boolean tippedClear = false;
|
||||
@ -46,8 +48,9 @@ public class ScoreboardWrapper {
|
||||
private PlayerProfile targetProfile = null;
|
||||
public int leaderboardPage = -1;
|
||||
|
||||
private ScoreboardWrapper(String playerName, Scoreboard scoreboard) {
|
||||
this.playerName = playerName;
|
||||
private 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");
|
||||
@ -64,7 +67,11 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
|
||||
public static ScoreboardWrapper create(Player player) {
|
||||
return new ScoreboardWrapper(player.getName(), mcMMO.p.getServer().getScoreboardManager().getNewScoreboard());
|
||||
//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;
|
||||
@ -143,7 +150,7 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the old scoreboard, for use in reverting.
|
||||
* Set the old targetBoard, for use in reverting.
|
||||
*/
|
||||
public void setOldScoreboard() {
|
||||
Player player = mcMMO.p.getServer().getPlayerExact(playerName);
|
||||
@ -227,11 +234,17 @@ public class ScoreboardWrapper {
|
||||
|
||||
if (oldBoard != null) {
|
||||
if (player.getScoreboard() == scoreboard) {
|
||||
player.setScoreboard(oldBoard);
|
||||
/**
|
||||
* Call the revert scoreboard custom event
|
||||
*/
|
||||
McMMOScoreboardRevertEvent event = new McMMOScoreboardRevertEvent(oldBoard, player.getScoreboard(), player, ScoreboardEventReason.REVERTING_BOARD);
|
||||
player.getServer().getPluginManager().callEvent(event);
|
||||
//Modify the player based on the event
|
||||
event.getTargetPlayer().setScoreboard(event.getTargetBoard());
|
||||
oldBoard = null;
|
||||
}
|
||||
else {
|
||||
mcMMO.p.debug("Not reverting scoreboard for " + playerName + " - scoreboard was changed by another plugin (Consider disabling the mcMMO scoreboards if you don't want them!)");
|
||||
mcMMO.p.debug("Not reverting targetBoard for " + playerName + " - targetBoard was changed by another plugin (Consider disabling the mcMMO scoreboards if you don't want them!)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,8 +384,16 @@ public class ScoreboardWrapper {
|
||||
|
||||
// Setup for after a board type change
|
||||
protected void loadObjective(String displayName) {
|
||||
sidebarObjective.unregister();
|
||||
sidebarObjective = scoreboard.registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy");
|
||||
//Unregister objective
|
||||
McMMOScoreboardObjectiveEvent unregisterEvent = callObjectiveEvent(ScoreboardObjectiveEventReason.UNREGISTER_THIS_OBJECTIVE);
|
||||
if(!unregisterEvent.isCancelled()) {
|
||||
sidebarObjective.unregister();
|
||||
}
|
||||
|
||||
//Register objective
|
||||
McMMOScoreboardObjectiveEvent registerEvent = callObjectiveEvent(ScoreboardObjectiveEventReason.REGISTER_NEW_OBJECTIVE);
|
||||
if(!registerEvent.isCancelled())
|
||||
sidebarObjective = registerEvent.getTargetBoard().registerNewObjective(ScoreboardManager.SIDEBAR_OBJECTIVE, "dummy");
|
||||
|
||||
if (displayName.length() > 32) {
|
||||
displayName = displayName.substring(0, 32);
|
||||
@ -385,6 +406,12 @@ public class ScoreboardWrapper {
|
||||
sidebarObjective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
}
|
||||
|
||||
private McMMOScoreboardObjectiveEvent callObjectiveEvent(ScoreboardObjectiveEventReason reason) {
|
||||
McMMOScoreboardObjectiveEvent event = new McMMOScoreboardObjectiveEvent(sidebarObjective, reason, scoreboard, scoreboard, player, ScoreboardEventReason.OBJECTIVE);
|
||||
player.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load new values into the sidebar.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user