nossr50 6 лет назад
Родитель
Сommit
b38c589125

+ 8 - 8
Changelog.txt

@@ -39,7 +39,7 @@ Version 2.1.0
  - (Locale) Removed localizations with the following codes for being almost empty: id, HR_hr, et_EE, lv, lt, no, pl_PL, pt_PT, tr_TR
  - (Config) Removed SkillShot's IncreaseLevel & IncreasePercentage (replaced by RankDamageMultiplier)
  - (Config) Removed AxeMastery's MaxBonus & MaxBonusLevel (replaced by RankDamageMultiplier)
- = (Plugin Compatibility) mcMMO now uses the main scoreboard instead of creating a new one, this improves plugin compatibility with other plugins (Citizens2, etc...)
+ = (Plugin Compatibility) mcMMO now fires new custom events relating to changes it makes to player scoreboards, plugin authors can listen to these events to improve compatibility
  = (Items) Chimaera Wing now tracks cooldowns between sessions for players (no more disconnect abuse)
  = (Skills) Added missing mushroom blocks to experience.yml defaults
  = (Skills) Tridents will no longer be considered unarmed
@@ -146,7 +146,7 @@ Version 1.5.01
  + Added SQL connection pooling and async loading!
  + Added the long awaited Diminished Returns feature
  + Added new feature to Herbalism. Instantly-regrown crops are protected from being broken for 1 second
- + Added option to config.yml to show the /mcstats scoreboard automatically after logging in
+ + Added option to config.yml to show the /mcstats targetBoard automatically after logging in
  + Added option to config.yml for Alchemy. Skills.Alchemy.Prevent_Hopper_Transfer_Bottles
  + Added option to config.yml for Scoreboards, display "Ability" instead of ability names on the scoreboards
  + Added options to experience.yml for Dirt and Sand variations
@@ -286,15 +286,15 @@ Version 1.4.07
  + Added Quartz and Name Tags to the default Excavation treasures
  + Added a warning message if the server is running NoCheatPlus without CompatNoCheatPlus
  + Added cooldown to commands with heavy database access to prevent denial of service
- + Added /mcscoreboard keep, to keep the scoreboard up forever
+ + Added /mcscoreboard keep, to keep the targetBoard up forever
  + Added Rainbow Mode to scoreboards
  + Added new /mccooldowns command to show all ability cooldowns
- + Commands may now both print text and display a scoreboard
+ + Commands may now both print text and display a targetBoard
  + Killing a custom entity will automatically add it to the custom entity config file with default values.
  = Fixed bug which allowed players to bypass fishing's exploit prevention
  = Fixed bug where FakeEntityDamageByEntityEvent wasn't being fired
  = Fixed bug with "Skull Splitter" not finding the locale string
- = Fixed issue where locale strings could cause the scoreboard header to be longer than 16 characters.
+ = Fixed issue where locale strings could cause the targetBoard header to be longer than 16 characters.
  = Fixed a bug with "Beast Lore" when the entity had no owner but was tamed.
  = Fixed a bug where AbilityDeactivateEvent would throw an error if the player logged out before his ability ran out.
  = Fixed a bug where LevelUpEvent would be called for an offline player.
@@ -331,8 +331,8 @@ Version 1.4.07
  ! Party item share category states are now saved when the server shuts down.
  ! When using "Super Breaker" or "Giga Driller" abilities extra tool durability is used (again)
  ! Mob healthbars are automatically disabled when the plugin "HealthBar" is found
- ! Massively improved scoreboard handling
- ! Reworked scoreboard configuration (config.yml) - **you will need to update**
+ ! Massively improved targetBoard handling
+ ! Reworked targetBoard configuration (config.yml) - **you will need to update**
  - The /mmoupdate command has been removed. It is replaced by /mcconvert database
  - Removed Abilities.Tools.Durability_Loss_Enabled, set Abilities.Tools.Durability_Loss to 0 to disable instead.
  - Removed Skills.Fishing.Shake_UnlockLevel from advanced.yml, now using Skills.Fishing.Rank_Levels.Rank_1 instead.
@@ -341,7 +341,7 @@ Version 1.4.07
 Version 1.4.06
  + Added "Ice Fishing" ability to Fishing
  + Added global scoreboards to track skill rankings (display using /mctop)
- + Added per-player scoreboard displays for the /inspect, /mcrank, /mcstats, and /<skillname> commands
+ + Added per-player targetBoard displays for the /inspect, /mcrank, /mcstats, and /<skillname> commands
  + Added tab-complete support for all commands
  + Added ability to configure drops from Shake in treasures.yml
  + Added "Master Angler" ability to Fishing.

+ 87 - 1
src/main/java/com/gmail/nossr50/events/scoreboard/McMMOScoreboardEvent.java

@@ -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;
+    }
 }

+ 12 - 1
src/main/java/com/gmail/nossr50/events/scoreboard/McMMOScoreboardMakeboardEvent.java

@@ -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);
+    }
 }

+ 49 - 1
src/main/java/com/gmail/nossr50/events/scoreboard/McMMOScoreboardObjectiveEvent.java

@@ -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;
+    }
 }

+ 11 - 1
src/main/java/com/gmail/nossr50/events/scoreboard/McMMOScoreboardRevertEvent.java

@@ -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);
+    }
 }

+ 2 - 0
src/main/java/com/gmail/nossr50/events/scoreboard/ScoreboardObjectiveEventReason.java

@@ -1,4 +1,6 @@
 package com.gmail.nossr50.events.scoreboard;
 
 public enum ScoreboardObjectiveEventReason {
+    UNREGISTER_THIS_OBJECTIVE,
+    REGISTER_NEW_OBJECTIVE,
 }

+ 5 - 5
src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java

@@ -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;

+ 35 - 8
src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java

@@ -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.
      */