mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +02:00
I guess I'm bad at git
This commit is contained in:
@ -1,4 +1,90 @@
|
||||
package com.gmail.nossr50.events.scoreboard;
|
||||
|
||||
public class McMMOScoreboardEvent {
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
/**
|
||||
* The parent class of all mcMMO scoreboard events
|
||||
* All scoreboard events will extend from this
|
||||
*/
|
||||
abstract public class McMMOScoreboardEvent extends Event {
|
||||
|
||||
protected Scoreboard targetBoard; //Scoreboard involved in this event
|
||||
final Scoreboard currentBoard; //Can be null
|
||||
protected Player targetPlayer;
|
||||
|
||||
private final ScoreboardEventReason scoreboardEventReason;
|
||||
|
||||
public McMMOScoreboardEvent(Scoreboard targetBoard, Scoreboard currentBoard, Player targetPlayer, ScoreboardEventReason scoreboardEventReason)
|
||||
{
|
||||
this.scoreboardEventReason = scoreboardEventReason;
|
||||
this.targetBoard = targetBoard;
|
||||
this.currentBoard = currentBoard;
|
||||
this.targetPlayer = targetPlayer;
|
||||
}
|
||||
|
||||
/** GETTER & SETTER BOILERPLATE **/
|
||||
|
||||
/**
|
||||
* This is the scoreboard the player will be assigned to after this event
|
||||
* @return the target board to assign the player after this event fires
|
||||
*/
|
||||
public Scoreboard getTargetBoard() {
|
||||
return targetBoard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the scoreboard that the player will be assigned to after this event fires
|
||||
* @param targetBoard the new board to assign the player to
|
||||
*/
|
||||
public void setTargetBoard(Scoreboard targetBoard) {
|
||||
this.targetBoard = targetBoard;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player involved in this event (this can be changed)
|
||||
* @return the player involved in this event
|
||||
*/
|
||||
public Player getTargetPlayer() {
|
||||
return targetPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the scoreboard the player is currently assigned to at the time the event was fired
|
||||
* Grabbed via player.getScoreboard()
|
||||
* @return players current scoreboard
|
||||
*/
|
||||
public Scoreboard getCurrentBoard() {
|
||||
return currentBoard;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ENUM defining the reason for this event
|
||||
* @return the reason for this event
|
||||
*/
|
||||
public ScoreboardEventReason getScoreboardEventReason() {
|
||||
return scoreboardEventReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the target player for this event
|
||||
* @param targetPlayer the new target for this event
|
||||
*/
|
||||
public void setTargetPlayer(Player targetPlayer) {
|
||||
this.targetPlayer = targetPlayer;
|
||||
}
|
||||
|
||||
/** Rest of file is required boilerplate for custom events **/
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,15 @@
|
||||
package com.gmail.nossr50.events.scoreboard;
|
||||
|
||||
public class McMMOScoreboardMakeboardEvent {
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
/**
|
||||
* This event is called when mcMMO creates its custom boards
|
||||
* You should not interfere with this event unless you understand our board code thoroughly
|
||||
* mcMMO relies on using new scoreboards to show players individually catered boards with stats specific to them
|
||||
*/
|
||||
public class McMMOScoreboardMakeboardEvent extends McMMOScoreboardEvent {
|
||||
public McMMOScoreboardMakeboardEvent(Scoreboard targetBoard, Scoreboard currentBoard, Player targetPlayer, ScoreboardEventReason scoreboardEventReason) {
|
||||
super(targetBoard, currentBoard, targetPlayer, scoreboardEventReason);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,52 @@
|
||||
package com.gmail.nossr50.events.scoreboard;
|
||||
|
||||
public class McMMOScoreboardObjectiveEvent {
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
public class McMMOScoreboardObjectiveEvent extends McMMOScoreboardEvent implements Cancellable {
|
||||
protected boolean cancelled;
|
||||
|
||||
protected Objective targetObjective;
|
||||
protected final ScoreboardObjectiveEventReason objectiveEventReason;
|
||||
|
||||
public McMMOScoreboardObjectiveEvent(Objective targetObjective, ScoreboardObjectiveEventReason objectiveEventReason, Scoreboard scoreboard, Scoreboard oldboard, Player targetPlayer, ScoreboardEventReason scoreboardEventReason) {
|
||||
super(scoreboard, oldboard, targetPlayer, scoreboardEventReason);
|
||||
this.objectiveEventReason = objectiveEventReason;
|
||||
this.targetObjective = targetObjective;
|
||||
cancelled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The objective that will be modified by this event
|
||||
* @return
|
||||
*/
|
||||
public Objective getTargetObjective() {
|
||||
return targetObjective;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the target objective for this event
|
||||
* @param newObjective new target objective
|
||||
*/
|
||||
public void setTargetObjective(Objective newObjective) {
|
||||
this.targetObjective = newObjective;
|
||||
}
|
||||
|
||||
public ScoreboardObjectiveEventReason getObjectiveEventReason() {
|
||||
return objectiveEventReason;
|
||||
}
|
||||
|
||||
/* BOILERPLATE FROM INTERFACES */
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
cancelled = b;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,14 @@
|
||||
package com.gmail.nossr50.events.scoreboard;
|
||||
|
||||
public class McMMOScoreboardRevertEvent {
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
/**
|
||||
* This event is called when mcMMO is attempting to change a players targetBoard back to their previous board
|
||||
* This is used when an mcMMO board is cleared (removed from the screen), changing back from a temporary board (usually from a delayed scheduled task or our mcscoreboard time command)
|
||||
*/
|
||||
public class McMMOScoreboardRevertEvent extends McMMOScoreboardEvent {
|
||||
public McMMOScoreboardRevertEvent(Scoreboard targetBoard, Scoreboard currentBoard, Player targetPlayer, ScoreboardEventReason scoreboardEventReason) {
|
||||
super(targetBoard, currentBoard, targetPlayer, scoreboardEventReason);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
package com.gmail.nossr50.events.scoreboard;
|
||||
|
||||
public enum ScoreboardObjectiveEventReason {
|
||||
UNREGISTER_THIS_OBJECTIVE,
|
||||
REGISTER_NEW_OBJECTIVE,
|
||||
}
|
||||
|
@ -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