9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-30 20:39:18 +00:00

competition

This commit is contained in:
XiaoMoMi
2023-09-29 17:17:33 +08:00
parent 018592923f
commit 89efe4fa15
4 changed files with 96 additions and 22 deletions

View File

@@ -50,6 +50,7 @@ import net.momirealms.customfishing.setting.CFConfig;
import net.momirealms.customfishing.setting.CFLocale;
import net.momirealms.customfishing.storage.StorageManagerImpl;
import net.momirealms.customfishing.version.VersionManagerImpl;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.HandlerList;
@@ -103,6 +104,8 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
this.totemManager = new TotemManagerImpl(this);
this.hookManager = new HookManagerImpl(this);
this.reload();
if (CFConfig.metrics) new Metrics(this, 16648);
if (CFConfig.updateChecker)
this.versionManager.checkUpdate().thenAccept(result -> {
if (!result) this.getAdventure().sendConsoleMessage("[CustomFishing] You are using the latest version.");

View File

@@ -664,32 +664,37 @@ public class FishingManagerImpl implements Listener, FishingManager {
private void doSuccessActions(Loot loot, Effect effect, FishingPreparation fishingPreparation, Player player) {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (competition != null) {
switch (competition.getGoal()) {
case CATCH_AMOUNT -> {
fishingPreparation.insertArg("{score}", "1");
competition.refreshData(player, 1);
}
case MAX_SIZE, TOTAL_SIZE -> {
String size = fishingPreparation.getArg("{size}");
if (size != null) {
fishingPreparation.insertArg("{score}", size);
competition.refreshData(player, Double.parseDouble(size));
} else {
fishingPreparation.insertArg("{score}", "0");
String scoreStr = fishingPreparation.getArg("{SCORE}");
if (scoreStr != null) {
competition.refreshData(player, Double.parseDouble(scoreStr));
} else {
switch (competition.getGoal()) {
case CATCH_AMOUNT -> {
double score = effect.getScoreMultiplier();
fishingPreparation.insertArg("{score}", String.format("%.2f", score));
competition.refreshData(player, score);
}
}
case TOTAL_SCORE -> {
double score = loot.getScore();
if (score != 0) {
fishingPreparation.insertArg("{score}", String.format("%.2f", score * effect.getScoreMultiplier()));
competition.refreshData(player, score * effect.getScoreMultiplier());
} else {
fishingPreparation.insertArg("{score}", "0");
case MAX_SIZE, TOTAL_SIZE -> {
String size = fishingPreparation.getArg("{size}");
if (size != null) {
double score = Double.parseDouble(size) * effect.getScoreMultiplier();
fishingPreparation.insertArg("{score}", String.format("%.2f", score));
competition.refreshData(player, score);
} else {
fishingPreparation.insertArg("{score}", "0");
}
}
case TOTAL_SCORE -> {
double score = loot.getScore();
if (score != 0) {
fishingPreparation.insertArg("{score}", String.format("%.2f", score * effect.getScoreMultiplier()));
competition.refreshData(player, score * effect.getScoreMultiplier());
} else {
fishingPreparation.insertArg("{score}", "0");
}
}
}
}
} else {
fishingPreparation.insertArg("{score}","-1");
}
// events and actions

View File

@@ -24,6 +24,7 @@ import net.momirealms.customfishing.api.integration.LevelInterface;
import net.momirealms.customfishing.api.integration.SeasonInterface;
import net.momirealms.customfishing.api.manager.RequirementManager;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
@@ -195,6 +196,7 @@ public class RequirementManagerImpl implements RequirementManager {
this.registerMoneyRequirement();
this.registerInBagRequirement();
this.registerHookRequirement();
this.registerCompetitionRequirement();
}
public HashMap<String, Double> getLootWithWeight(Condition condition) {
@@ -1049,6 +1051,40 @@ public class RequirementManagerImpl implements RequirementManager {
});
}
private void registerCompetitionRequirement() {
registerRequirement("competition", (args, actions, advanced) -> {
if (args instanceof ConfigurationSection section) {
boolean onCompetition = section.getBoolean("ongoing", true);
List<String> ids = ConfigUtils.stringListArgs(section.get("id"));
return condition -> {
if (ids.size() == 0) {
if (plugin.getCompetitionManager().getOnGoingCompetition() != null == onCompetition) {
return true;
}
} else {
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
if (onCompetition) {
if (competition != null) {
if (ids.contains(competition.getConfig().getKey())) {
return true;
}
}
} else {
if (competition == null) {
return true;
}
}
}
if (advanced) triggerActions(actions, condition);
return false;
};
} else {
LogUtils.warn("Wrong value format found at competition requirement.");
return null;
}
});
}
private void registerPluginLevelRequirement() {
registerRequirement("plugin-level", (args, actions, advanced) -> {
if (args instanceof ConfigurationSection section) {