Skip to content

Commit

Permalink
Version 1.2.0. Allow /df config to configure bar colour, subtitles …
Browse files Browse the repository at this point in the history
…and message for stage 11, too.
  • Loading branch information
totemo committed Aug 5, 2021
1 parent ded905c commit 236706f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 67 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>nu.nerd</groupId>
<artifactId>DragonFight</artifactId>
<version>1.1.4</version>
<version>1.2.0</version>

<description>Custom dragon fight.</description>
<url>https://github.com/NerdNu/${project.name}</url>
Expand Down
36 changes: 17 additions & 19 deletions src/main/java/nu/nerd/df/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Configuration {

/**
* Total boss maximum health.
*
*
* This needs to be preserved across restarts, since a stage fight may have
* a random number of bosses, some of which may have died. THere is no easy
* way to work infer the total maximum boss health points in the stage after
Expand All @@ -37,15 +37,15 @@ public class Configuration {
/**
* The UUID of the Player who placed the last end crystal to initiate the
* current fight.
*
*
* That player receives the drops.
*/
public UUID FIGHT_OWNER;

/**
* A map from Player UUID to the number of unclaimed dragon kill prizes for
* that player.
*
*
* The key will be absent if there are no prizes to claim.
*/
public HashMap<UUID, Integer> UNCLAIMED_PRIZES = new HashMap<>();
Expand All @@ -55,7 +55,7 @@ public class Configuration {
* Default constructor.
*/
public Configuration() {
for (int stageNumber = 1; stageNumber <= 10; ++stageNumber) {
for (int stageNumber = 1; stageNumber <= 11; ++stageNumber) {
_stages[stageNumber - 1] = new Stage(stageNumber);
}
}
Expand All @@ -64,7 +64,7 @@ public Configuration() {
/**
* Return the stored number of unclaimed prizes for the player with the
* specified UUID.
*
*
* @param playerUuid the player's UUID.
* @return the number of unclaimed prizes accrued to the player.
*/
Expand All @@ -76,10 +76,10 @@ public int getUnclaimedPrizes(UUID playerUuid) {
/**
* Increment the stored number of unclaimed prizes for the player with the
* specified UUID.
*
*
* @param playerUuid the player's UUID.
* @param amount the amount to increase the count of prizes (negative to
* decrement).
* @param amount the amount to increase the count of prizes (negative to
* decrement).
* @return the number of unclaimed prizes accrued to the player.
*/
public Integer incUnclaimedPrizes(UUID playerUuid, int amount) {
Expand All @@ -92,12 +92,12 @@ public Integer incUnclaimedPrizes(UUID playerUuid, int amount) {
// ------------------------------------------------------------------------
/**
* Return a reference to the Stage with the specified stage number.
*
* @param stageNumber the stage number, from 1 to 10.
*
* @param stageNumber the stage number, from 1 to 11.
* @return the Stage, or null if the stage number is out of range.
*/
public Stage getStage(int stageNumber) {
return (stageNumber < 1 || stageNumber > 10) ? null : _stages[stageNumber - 1];
return (stageNumber < 1 || stageNumber > 11) ? null : _stages[stageNumber - 1];
}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -132,7 +132,7 @@ public void reload() {
}
}

for (int stageNumber = 1; stageNumber <= 10; ++stageNumber) {
for (int stageNumber = 1; stageNumber <= 11; ++stageNumber) {
getStage(stageNumber).load(getStageSection(stageNumber));
}
}
Expand All @@ -155,7 +155,7 @@ public void save() {
unclaimedPrizes.set(entry.getKey().toString(), entry.getValue());
}

for (int stageNumber = 1; stageNumber <= 10; ++stageNumber) {
for (int stageNumber = 1; stageNumber <= 11; ++stageNumber) {
getStage(stageNumber).save(getStageSection(stageNumber));
}
DragonFight.PLUGIN.saveConfig();
Expand All @@ -164,8 +164,8 @@ public void save() {
// ------------------------------------------------------------------------
/**
* Return the ConfigurationSection that encodes the specified stage.
*
* @param stageNumber the stage number in [1,10].
*
* @param stageNumber the stage number in [1,11].
* @return the section.
*/
protected ConfigurationSection getStageSection(int stageNumber) {
Expand All @@ -175,10 +175,8 @@ protected ConfigurationSection getStageSection(int stageNumber) {

// ------------------------------------------------------------------------
/**
* {@link Stage}s 1 through 10, in indices 0 through 9, respectively.
*
* Stage 11, the dragon on its own, does not use a Stage instance.
* {@link Stage}s 1 through 11, in indices 0 through 10, respectively.
*/
protected Stage[] _stages = new Stage[10];
protected Stage[] _stages = new Stage[11];

} // class Configuration
61 changes: 30 additions & 31 deletions src/main/java/nu/nerd/df/FightState.java
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ protected void defineBeastMasterObjects() {
}
}

// Initialise stage loot tables.
// Initialise stage loot tables. Stage 11 has no loot table.
for (int stageNumber = 1; stageNumber <= 10; ++stageNumber) {
// Add the stage N boss mob loot tables, if not defined.
String dropSetId = Stage.getDropSetId(stageNumber);
Expand Down Expand Up @@ -1373,8 +1373,6 @@ protected void despawnPillarCrystals(int count) {
/**
* Begin the specified boss stage (1 to 11 only).
*
* Stage 0 is not supported.
*
* @param sender the command sender for messages, or null if
* unused.
* @param stageNumber the stage number from 1 to 10.
Expand All @@ -1385,23 +1383,28 @@ protected void startStage(CommandSender sender, int stageNumber, Location bossSp
sender.sendMessage(ChatColor.DARK_PURPLE + "Starting stage: " + ChatColor.LIGHT_PURPLE + stageNumber);
}
_stageNumber = stageNumber;
if (_stageNumber == 11) {
startStage11();
return;
}

// Stages 1 to 10:
Stage stage = DragonFight.CONFIG.getStage(_stageNumber);
log("Beginning stage: " + _stageNumber);

// Spawn boss or bosses.
DragonFight.CONFIG.TOTAL_BOSS_MAX_HEALTH = 0;
DropResults results = new DropResults();
DropSet dropSet = BeastMaster.LOOTS.getDropSet(stage.getDropSetId());
if (dropSet != null) {
dropSet.generateRandomDrops(results, "DragonFight stage " + stage, null, bossSpawnLocation, true);
// Spawn boss or bosses. Only valid in stages 1 to 10.
if (_stageNumber >= 1 && _stageNumber <= 10) {
DragonFight.CONFIG.TOTAL_BOSS_MAX_HEALTH = 0;
DropResults results = new DropResults();
DropSet dropSet = BeastMaster.LOOTS.getDropSet(stage.getDropSetId());
if (dropSet != null) {
dropSet.generateRandomDrops(results, "DragonFight stage " + stage, null, bossSpawnLocation, true);
}
log("Mobs are spawned.");
} else {
// Stage 11. The dragon was set invulnerable in stage 1.
DragonBattle battle = DragonUtil.getFightWorld().getEnderDragonBattle();
EnderDragon dragon = battle.getEnderDragon();
if (dragon != null) {
dragon.setInvulnerable(false);
}
log("Dragon is now vulnerable.");
}
log("Mobs are spawned.");

// Show the title.
Set<Player> nearby = getNearbyPlayers();
Expand All @@ -1414,19 +1417,7 @@ protected void startStage(CommandSender sender, int stageNumber, Location bossSp
* Show the stage 11 titles and set the dragon vulnerable again.
*/
protected void startStage11() {
log("Beginning stage 11.");
_stageNumber = 11;

// Show a fixed stage 11 title for the dragon.
getNearbyPlayers().forEach(p -> p.sendTitle(ChatColor.DARK_PURPLE + "Stage 11",
ChatColor.LIGHT_PURPLE + "Defeat the dragon.", 10, 70, 20));

// The dragon was set invulnerable in stage 1.
DragonBattle battle = DragonUtil.getFightWorld().getEnderDragonBattle();
EnderDragon dragon = battle.getEnderDragon();
if (dragon != null) {
dragon.setInvulnerable(false);
}
startStage(null, 11, null);
}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -1511,18 +1502,26 @@ protected Set<Player> getNearbyPlayers() {
/**
* Update the BossBar for the current stage.
*
* If we're not in stage 1-10, don't show a boss bar, even if we have some
* test bosses.
* If we're not in stage 1-10, don't show a custom boss bar, even if we have
* some test bosses.
*/
protected void updateBossBar() {
if (_stageNumber >= 1 && _stageNumber <= 11) {
// Vanilla/Bukkit code reuses the dragon boss bar across fights, so
// set its colour across all stages.
Stage stage = DragonFight.CONFIG.getStage(11);
DragonBattle battle = DragonUtil.getFightWorld().getEnderDragonBattle();
battle.getBossBar().setColor(stage.getBarColor());
}

if (_bosses.size() == 0 || _stageNumber < 1 || _stageNumber > 10) {
if (_bossBar != null) {
_bossBar.setVisible(false);
}
return;
}

// We have a non-zero number of bosses. Stage 1 to 10. Sow the bar.
// We have a non-zero number of bosses. Stage 1 to 10. Show the bar.
Stage stage = DragonFight.CONFIG.getStage(_stageNumber);
if (_bossBar == null) {
_bossBar = Bukkit.createBossBar("", BarColor.WHITE, BarStyle.SOLID, new BarFlag[0]);
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/nu/nerd/df/commands/DFExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

sender.sendMessage(ChatColor.DARK_PURPLE + "The following players have unclaimed prizes:");
String players = DragonFight.CONFIG.UNCLAIMED_PRIZES.entrySet().stream()
.map(entry -> {
// OfflinePlayer never null:
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(entry.getKey());
String playerName = (offlinePlayer.getName() == null) ? offlinePlayer.getUniqueId().toString()
: offlinePlayer.getName();
return ChatColor.LIGHT_PURPLE + playerName + ChatColor.DARK_PURPLE + ": " +
ChatColor.WHITE + Integer.toString(entry.getValue());
})
.sorted(String.CASE_INSENSITIVE_ORDER)
.collect(Collectors.joining(ChatColor.DARK_PURPLE + ", "));
.map(entry -> {
// OfflinePlayer never null:
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(entry.getKey());
String playerName = (offlinePlayer.getName() == null) ? offlinePlayer.getUniqueId().toString()
: offlinePlayer.getName();
return ChatColor.LIGHT_PURPLE + playerName + ChatColor.DARK_PURPLE + ": " +
ChatColor.WHITE + Integer.toString(entry.getValue());
})
.sorted(String.CASE_INSENSITIVE_ORDER)
.collect(Collectors.joining(ChatColor.DARK_PURPLE + ", "));
sender.sendMessage(players);
return true;
}

if (args.length == 1 && args[0].equalsIgnoreCase("list")) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Stages:");
for (int stageNumber = 1; stageNumber <= 10; ++stageNumber) {
for (int stageNumber = 1; stageNumber <= 11; ++stageNumber) {
Stage stage = DragonFight.CONFIG.getStage(stageNumber);
sender.sendMessage(ChatColor.DARK_PURPLE + "(" + stageNumber + ") " +
ChatColor.WHITE + stage.format(stage.getTitle()) +
Expand Down Expand Up @@ -234,7 +234,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St

Integer stageNumber = Commands.parseNumber(args[1],
Commands::parseInt,
n -> n >= 1 && n <= 10,
n -> n >= 1 && n <= 11,
() -> sender.sendMessage(ChatColor.RED + "The stage must be a number from 1 to 10."),
null);
if (stageNumber == null) {
Expand Down Expand Up @@ -276,8 +276,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (listColors) {
sender.sendMessage(ChatColor.RED + "Colors: " +
Stream.of(BarColor.values())
.map(c -> BAR_COLORS[c.ordinal()] + c.toString())
.collect(Collectors.joining(" ")));
.map(c -> BAR_COLORS[c.ordinal()] + c.toString())
.collect(Collectors.joining(" ")));
}

} else {
Expand Down Expand Up @@ -322,7 +322,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
// ------------------------------------------------------------------------
/**
* Show usage message.
*
*
* @param sender the message sender.
*/
protected void configUsage(CommandSender sender) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ stages:
title: '&5Stage {}'
subtitle: ''
message: ''
'11':
barcolor: PINK
title: '&5Stage {}'
subtitle: '&dDefeat the dragon.'
message: ''
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ commands:
§5/<command> list§f - List all 10 stage titles and subtitles.
§5/<command> swap <from> <to>§f - Swap two stages by stage number (1 to 10).
§5/<command> move <from> <to>§f - Move stage <from> to stage <to> and shift in-between stages into the gap.
§5/<command> config <stage>§f - Show the configuration of <stage> 1 to 10.
§5/<command> config <stage>§f - Show the configuration of <stage> 1 to 11.
§5/<command> config <stage> barcolor <color>§f - Configure stage bar color.
§5/<command> config <stage> title <text>§f - Configure stage title.
§5/<command> config <stage> subtitle <text>§f - Configure stage subtitle.
Expand Down

0 comments on commit 236706f

Please sign in to comment.