-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix command permissions and reward correctors; Add mythic_stat reward
- Loading branch information
Showing
7 changed files
with
198 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/gg/auroramc/quests/hooks/mythicmobs/MythicHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
package gg.auroramc.quests.hooks.mythicmobs; | ||
|
||
import gg.auroramc.aurora.api.util.NamespacedId; | ||
import gg.auroramc.quests.AuroraQuests; | ||
import gg.auroramc.quests.hooks.Hook; | ||
import gg.auroramc.quests.hooks.mythicmobs.reward.MythicStatCorrector; | ||
import gg.auroramc.quests.hooks.mythicmobs.reward.MythicStatReward; | ||
import org.bukkit.Bukkit; | ||
|
||
public class MythicHook implements Hook { | ||
@Override | ||
public void hook(AuroraQuests plugin) { | ||
Bukkit.getPluginManager().registerEvents(new MythicMobListener(), plugin); | ||
|
||
plugin.getQuestManager().getRewardFactory() | ||
.registerRewardType(NamespacedId.fromDefault("mythic_stat"), MythicStatReward.class); | ||
|
||
plugin.getQuestManager().getRewardAutoCorrector() | ||
.registerCorrector(NamespacedId.fromDefault("mythic_stat"), new MythicStatCorrector()); | ||
|
||
AuroraQuests.logger().info("Hooked into MythicMobs for KILL_MYTHIC_MOB task type"); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/gg/auroramc/quests/hooks/mythicmobs/reward/AuroraQuestsStatSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package gg.auroramc.quests.hooks.mythicmobs.reward; | ||
|
||
import io.lumine.mythic.core.skills.stats.StatSource; | ||
|
||
public class AuroraQuestsStatSource implements StatSource { | ||
@Override | ||
public boolean removeOnReload() { | ||
return false; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/gg/auroramc/quests/hooks/mythicmobs/reward/MythicStatCorrector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package gg.auroramc.quests.hooks.mythicmobs.reward; | ||
|
||
import com.google.common.collect.Maps; | ||
import gg.auroramc.aurora.api.reward.RewardCorrector; | ||
import gg.auroramc.quests.AuroraQuests; | ||
import io.lumine.mythic.bukkit.MythicBukkit; | ||
import io.lumine.mythic.core.skills.stats.StatModifierType; | ||
import io.lumine.mythic.core.skills.stats.StatType; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Map; | ||
|
||
public class MythicStatCorrector implements RewardCorrector { | ||
|
||
@Override | ||
public void correctRewards(Player player) { | ||
var plugin = AuroraQuests.getInstance(); | ||
var manager = plugin.getQuestManager(); | ||
var mythic = MythicBukkit.inst(); | ||
var registry = mythic.getPlayerManager().getProfile(player).getStatRegistry(); | ||
|
||
Map<StatType, Map<StatModifierType, Double>> statMap = Maps.newHashMap(); | ||
|
||
mythic.getStatManager().getStats().values() | ||
.forEach(statType -> { | ||
if (!statType.isEnabled()) return; | ||
registry.removeValue(statType, MythicStatReward.getSource()); | ||
}); | ||
|
||
// Gather new stat modifiers | ||
for (var pool : manager.getQuestPools()) { | ||
// Correct global quests | ||
if (pool.isGlobal()) { | ||
for (var quest : pool.getQuests()) { | ||
if (!quest.isCompleted(player)) continue; | ||
|
||
for (var reward : quest.getRewards().values()) { | ||
if (reward instanceof MythicStatReward statReward && statReward.isValid()) { | ||
statMap.computeIfAbsent(statReward.getStatType(), (key) -> Maps.newHashMap()) | ||
.merge(statReward.getModifierType(), statReward.getValue(quest.getPlaceholders(player)), Double::sum); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Correct quest pool leveling | ||
if (!pool.hasLeveling()) continue; | ||
var level = pool.getPlayerLevel(player); | ||
|
||
for (int i = 1; i < level + 1; i++) { | ||
var matcher = pool.getMatcherManager().getBestMatcher(i); | ||
if (matcher == null) continue; | ||
var placeholders = pool.getLevelPlaceholders(player, i); | ||
for (var reward : matcher.computeRewards(i)) { | ||
if (reward instanceof MythicStatReward statReward && statReward.isValid()) { | ||
statMap.computeIfAbsent(statReward.getStatType(), (key) -> Maps.newHashMap()) | ||
.merge(statReward.getModifierType(), statReward.getValue(placeholders), Double::sum); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Apply the new stat modifiers | ||
for (var entry : statMap.entrySet()) { | ||
var statType = entry.getKey(); | ||
for (var modifierEntry : entry.getValue().entrySet()) { | ||
var modifierType = modifierEntry.getKey(); | ||
var value = modifierEntry.getValue(); | ||
AuroraQuests.logger().debug("Adding stat " + statType.getKey() + " with value " + value + " to player " + player.getName()); | ||
registry.putValue(statType, MythicStatReward.getSource(), modifierType, value); | ||
} | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/gg/auroramc/quests/hooks/mythicmobs/reward/MythicStatReward.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package gg.auroramc.quests.hooks.mythicmobs.reward; | ||
|
||
import gg.auroramc.aurora.api.message.Placeholder; | ||
import gg.auroramc.aurora.api.reward.NumberReward; | ||
import gg.auroramc.quests.AuroraQuests; | ||
import io.lumine.mythic.bukkit.MythicBukkit; | ||
import io.lumine.mythic.core.skills.stats.StatModifierType; | ||
import io.lumine.mythic.core.skills.stats.StatRegistry; | ||
import io.lumine.mythic.core.skills.stats.StatSource; | ||
import io.lumine.mythic.core.skills.stats.StatType; | ||
import lombok.Getter; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class MythicStatReward extends NumberReward { | ||
@Getter | ||
private static final StatSource source = new AuroraQuestsStatSource(); | ||
|
||
private StatType statType; | ||
private StatModifierType modifierType; | ||
private boolean valid = true; | ||
|
||
@Override | ||
public void execute(Player player, long level, List<Placeholder<?>> placeholders) { | ||
if (!valid) return; | ||
|
||
StatRegistry registry = MythicBukkit.inst().getPlayerManager().getProfile(player).getStatRegistry(); | ||
|
||
if (registry.getStatData(statType).isPresent()) { | ||
|
||
StatRegistry.StatMap data = registry.getStatData(statType).get(); | ||
double current = 0; | ||
|
||
switch (modifierType) { | ||
case ADDITIVE -> current = data.getAdditives().getOrDefault(source, 0.0); | ||
case ADDITIVE_MULTIPLIER -> current = data.getAdditiveMultipliers().getOrDefault(source, 0.0); | ||
case COMPOUND_MULTIPLIER -> current = data.getCompoundMultipliers().getOrDefault(source, 0.0); | ||
case SETTER -> current = data.getSetters().getOrDefault(source, 0.0); | ||
} | ||
|
||
registry.putValue(statType, source, modifierType, current + getValue(placeholders)); | ||
} else { | ||
registry.putValue(statType, source, modifierType, getValue(placeholders)); | ||
} | ||
} | ||
|
||
@Override | ||
public void init(ConfigurationSection args) { | ||
super.init(args); | ||
var stat = args.getString("stat"); | ||
|
||
if (stat == null) { | ||
this.valid = false; | ||
AuroraQuests.logger().warning("Stat is not defined in MythicStatReward"); | ||
return; | ||
} | ||
|
||
this.statType = MythicBukkit.inst().getStatManager().getStats().get(stat); | ||
|
||
if (statType == null) { | ||
this.valid = false; | ||
AuroraQuests.logger().warning("Invalid stat: " + stat + " in MythicStatReward"); | ||
return; | ||
} | ||
|
||
if (!statType.isEnabled()) { | ||
this.valid = false; | ||
AuroraQuests.logger().warning("Stat: " + stat + " is not enabled in MythicMobs. Cannot create MythicStatReward."); | ||
return; | ||
} | ||
|
||
var modifier = args.getString("modifier", "additive"); | ||
|
||
try { | ||
this.modifierType = StatModifierType.valueOf(modifier.toUpperCase()); | ||
} catch (IllegalArgumentException e) { | ||
this.valid = false; | ||
AuroraQuests.logger().warning("Invalid modifier type: " + modifier + " in MythicStatReward"); | ||
} | ||
} | ||
|
||
@Override | ||
public String getDisplay(Player player, List<Placeholder<?>> placeholders) { | ||
var display = super.getDisplay(player, placeholders); | ||
|
||
if (!valid) { | ||
return display; | ||
} | ||
|
||
var value = getValue(placeholders); | ||
|
||
return Placeholder.execute(display, | ||
Placeholder.of("{stat}", statType.getDisplay()), | ||
Placeholder.of("{stat_display}", statType.getFormattedValue(modifierType, value)) | ||
); | ||
} | ||
} |