mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
2.3.8
This commit is contained in:
@@ -20,6 +20,7 @@ package net.momirealms.customfishing.api.mechanic.competition;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BroadcastConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -125,6 +126,13 @@ public interface CompetitionConfig {
|
||||
*/
|
||||
ActionBarConfig actionBarConfig();
|
||||
|
||||
/**
|
||||
* Gets the configuration for the broadcast during the competition.
|
||||
*
|
||||
* @return the broadcast configuration
|
||||
*/
|
||||
BroadcastConfig broadcastConfig();
|
||||
|
||||
/**
|
||||
* Get the time to start competition
|
||||
*
|
||||
@@ -242,6 +250,14 @@ public interface CompetitionConfig {
|
||||
*/
|
||||
Builder actionBarConfig(ActionBarConfig actionBarConfig);
|
||||
|
||||
/**
|
||||
* Sets the configuration for the broadcast during the competition.
|
||||
*
|
||||
* @param broadcastConfig the broadcast configuration.
|
||||
* @return the builder instance.
|
||||
*/
|
||||
Builder broadcastConfig(BroadcastConfig broadcastConfig);
|
||||
|
||||
/**
|
||||
* Sets the configuration for schedules of the competition.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,8 @@ package net.momirealms.customfishing.api.mechanic.competition;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BroadcastConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BroadcastConfigImpl;
|
||||
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -41,9 +43,13 @@ public class CompetitionConfigImpl implements CompetitionConfig {
|
||||
private final HashMap<String, Action<Player>[]> rewards;
|
||||
private final BossBarConfig bossBarConfig;
|
||||
private final ActionBarConfig actionBarConfig;
|
||||
private final BroadcastConfig broadcastConfig;
|
||||
private final List<CompetitionSchedule> schedules;
|
||||
|
||||
public CompetitionConfigImpl(String key, CompetitionGoal goal, int duration, int minPlayers, Requirement<Player>[] joinRequirements, Action<Player>[] skipActions, Action<Player>[] startActions, Action<Player>[] endActions, Action<Player>[] joinActions, HashMap<String, Action<Player>[]> rewards, BossBarConfig bossBarConfig, ActionBarConfig actionBarConfig, List<CompetitionSchedule> schedules) {
|
||||
public CompetitionConfigImpl(String key, CompetitionGoal goal, int duration, int minPlayers, Requirement<Player>[] joinRequirements,
|
||||
Action<Player>[] skipActions, Action<Player>[] startActions, Action<Player>[] endActions, Action<Player>[] joinActions, HashMap<String, Action<Player>[]> rewards,
|
||||
BossBarConfig bossBarConfig, ActionBarConfig actionBarConfig, BroadcastConfig broadcastConfig,
|
||||
List<CompetitionSchedule> schedules) {
|
||||
this.key = key;
|
||||
this.goal = goal;
|
||||
this.duration = duration;
|
||||
@@ -56,6 +62,7 @@ public class CompetitionConfigImpl implements CompetitionConfig {
|
||||
this.rewards = rewards;
|
||||
this.bossBarConfig = bossBarConfig;
|
||||
this.actionBarConfig = actionBarConfig;
|
||||
this.broadcastConfig = broadcastConfig;
|
||||
this.schedules = schedules;
|
||||
}
|
||||
|
||||
@@ -119,6 +126,11 @@ public class CompetitionConfigImpl implements CompetitionConfig {
|
||||
return actionBarConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastConfig broadcastConfig() {
|
||||
return broadcastConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompetitionSchedule> schedules() {
|
||||
return schedules;
|
||||
@@ -137,6 +149,7 @@ public class CompetitionConfigImpl implements CompetitionConfig {
|
||||
private HashMap<String, Action<Player>[]> rewards = DEFAULT_REWARDS;
|
||||
private BossBarConfig bossBarConfig;
|
||||
private ActionBarConfig actionBarConfig;
|
||||
private BroadcastConfig broadcastConfig;
|
||||
private final List<CompetitionSchedule> schedules = new ArrayList<>();
|
||||
@Override
|
||||
public Builder id(String key) {
|
||||
@@ -199,13 +212,18 @@ public class CompetitionConfigImpl implements CompetitionConfig {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Builder broadcastConfig(BroadcastConfig broadcastConfig) {
|
||||
this.broadcastConfig = broadcastConfig;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Builder schedules(List<CompetitionSchedule> schedules) {
|
||||
this.schedules.addAll(schedules);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public CompetitionConfig build() {
|
||||
return new CompetitionConfigImpl(key, goal, duration, minPlayers, joinRequirements, skipActions, startActions, endActions, joinActions, rewards, bossBarConfig, actionBarConfig, schedules);
|
||||
return new CompetitionConfigImpl(key, goal, duration, minPlayers, joinRequirements, skipActions, startActions, endActions, joinActions, rewards, bossBarConfig, actionBarConfig, broadcastConfig, schedules);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package net.momirealms.customfishing.api.mechanic.competition.info;
|
||||
|
||||
public interface BroadcastConfig {
|
||||
int DEFAULT_INTERVAL = 200;
|
||||
boolean DEFAULT_SHOW_TO_ALL = true;
|
||||
String[] DEFAULT_TEXTS = new String[]{""};
|
||||
boolean DEFAULT_ENABLED = true;
|
||||
|
||||
/**
|
||||
* Get the interval for broadcasting competition information.
|
||||
*
|
||||
* @return The interval in ticks.
|
||||
*/
|
||||
int interval();
|
||||
|
||||
/**
|
||||
* Check if competition information should be shown to all players.
|
||||
*
|
||||
* @return True if information is shown to all players, otherwise only to participants.
|
||||
*/
|
||||
boolean showToAll();
|
||||
|
||||
/**
|
||||
* Get an array of competition information texts to be broadcasted.
|
||||
*
|
||||
* @return An array of broadcast texts.
|
||||
*/
|
||||
String[] texts();
|
||||
|
||||
/**
|
||||
* Check if the broadcast is enabled.
|
||||
*
|
||||
* @return True if the broadcast is enabled, false otherwise.
|
||||
*/
|
||||
boolean enabled();
|
||||
|
||||
/**
|
||||
* Creates a new builder instance for constructing {@link BroadcastConfig} objects.
|
||||
*
|
||||
* @return A new {@link Builder} instance.
|
||||
*/
|
||||
static Builder builder() {
|
||||
return new BroadcastConfigImpl.BuilderImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder interface for constructing {@link BroadcastConfig} objects.
|
||||
*/
|
||||
interface Builder {
|
||||
|
||||
/**
|
||||
* Sets the interval between broadcasting messages.
|
||||
*
|
||||
* @param interval The interval in ticks.
|
||||
* @return The current {@link Builder} instance.
|
||||
*/
|
||||
Builder interval(int interval);
|
||||
|
||||
/**
|
||||
* Sets whether the broadcast should be visible to all players.
|
||||
*
|
||||
* @param showToAll True to show to all players, false for participants only.
|
||||
* @return The current {@link Builder} instance.
|
||||
*/
|
||||
Builder showToAll(boolean showToAll);
|
||||
|
||||
/**
|
||||
* Sets the texts to be broadcasted during the competition.
|
||||
*
|
||||
* @param texts An array of broadcast texts.
|
||||
* @return The current {@link Builder} instance.
|
||||
*/
|
||||
Builder texts(String[] texts);
|
||||
|
||||
/**
|
||||
* Enables or disables the broadcast.
|
||||
*
|
||||
* @param enable True to enable the broadcast, false to disable.
|
||||
* @return The current {@link Builder} instance.
|
||||
*/
|
||||
Builder enable(boolean enable);
|
||||
|
||||
/**
|
||||
* Builds the {@link BroadcastConfig} object with the configured settings.
|
||||
*
|
||||
* @return The constructed {@link BroadcastConfig} object.
|
||||
*/
|
||||
BroadcastConfig build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.momirealms.customfishing.api.mechanic.competition.info;
|
||||
|
||||
public class BroadcastConfigImpl implements BroadcastConfig {
|
||||
private final String[] texts;
|
||||
private final boolean showToAll;
|
||||
private final boolean enabled;
|
||||
private final int interval;
|
||||
|
||||
public BroadcastConfigImpl(boolean enable, int interval, String[] texts, boolean showToAll) {
|
||||
this.texts = texts;
|
||||
this.showToAll = showToAll;
|
||||
this.enabled = enable;
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int interval() {
|
||||
return this.interval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showToAll() {
|
||||
return this.showToAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] texts() {
|
||||
return this.texts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public static class BuilderImpl implements BroadcastConfig.Builder {
|
||||
private int interval = DEFAULT_INTERVAL;
|
||||
private boolean showToAll = DEFAULT_SHOW_TO_ALL;
|
||||
private String[] texts = DEFAULT_TEXTS;
|
||||
private boolean enabled = DEFAULT_ENABLED;
|
||||
|
||||
@Override
|
||||
public Builder interval(int interval) {
|
||||
this.interval = interval;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder showToAll(boolean showToAll) {
|
||||
this.showToAll = showToAll;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder texts(String[] texts) {
|
||||
this.texts = texts;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder enable(boolean enable) {
|
||||
this.enabled = enable;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastConfig build() {
|
||||
return new BroadcastConfigImpl(enabled, interval, texts, showToAll);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.CompetitionSchedule;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.info.BroadcastConfig;
|
||||
import net.momirealms.customfishing.common.util.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -77,6 +78,16 @@ public class CompetitionConfigParser {
|
||||
.build()
|
||||
);
|
||||
}
|
||||
if (section.getBoolean("broadcast.enable", false)) {
|
||||
builder.broadcastConfig(
|
||||
BroadcastConfig.builder()
|
||||
.enable(true)
|
||||
.interval(section.getInt("broadcast.interval", 1200))
|
||||
.showToAll(!section.getBoolean("broadcast.only-show-to-participants", true))
|
||||
.texts(section.getStringList("broadcast.text").toArray(new String[0]))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
List<Pair<Integer, Integer>> timePairs = section.getStringList("start-time")
|
||||
.stream().map(it -> {
|
||||
String[] split = it.split(":");
|
||||
|
||||
@@ -44,6 +44,7 @@ public class ContextKeys<T> {
|
||||
public static final ContextKeys<LootType> LOOT = of("loot", LootType.class);
|
||||
public static final ContextKeys<String> NICK = of("nick", String.class);
|
||||
public static final ContextKeys<Boolean> OPEN_WATER = of("open_water", Boolean.class);
|
||||
public static final ContextKeys<Boolean> IS_NEW_SIZE_RECORD = of("is_new_size_record", Boolean.class);
|
||||
public static final ContextKeys<Float> SIZE = of("size", Float.class);
|
||||
public static final ContextKeys<Double> SIZE_MULTIPLIER = of("size_multiplier", Double.class);
|
||||
public static final ContextKeys<Double> SIZE_ADDER = of("size_adder", Double.class);
|
||||
|
||||
@@ -619,7 +619,7 @@ public class CustomFishingHook {
|
||||
userData -> {
|
||||
Pair<Integer, Integer> result = userData.statistics().addAmount(nextLoot.statisticKey().amountKey(), 1);
|
||||
context.arg(ContextKeys.TOTAL_AMOUNT, userData.statistics().getAmount(nextLoot.statisticKey().amountKey()));
|
||||
Optional.ofNullable(context.arg(ContextKeys.SIZE)).ifPresent(size -> {
|
||||
Optional.ofNullable(context.arg(ContextKeys.SIZE)).ifPresentOrElse(size -> {
|
||||
float currentRecord = userData.statistics().getMaxSize(nextLoot.statisticKey().sizeKey());
|
||||
float max = Math.max(size, currentRecord);
|
||||
context.arg(ContextKeys.RECORD, max);
|
||||
@@ -627,10 +627,11 @@ public class CustomFishingHook {
|
||||
context.arg(ContextKeys.RECORD_FORMATTED, String.format("%.2f", max));
|
||||
context.arg(ContextKeys.PREVIOUS_RECORD_FORMATTED, String.format("%.2f", currentRecord));
|
||||
if (userData.statistics().updateSize(nextLoot.statisticKey().sizeKey(), size)) {
|
||||
context.arg(ContextKeys.IS_NEW_SIZE_RECORD, true);
|
||||
plugin.getEventManager().trigger(context, id, MechanicType.LOOT, ActionTrigger.SUCCESS, result.left(), result.right());
|
||||
plugin.getEventManager().trigger(context, id, MechanicType.LOOT, ActionTrigger.NEW_SIZE_RECORD);
|
||||
}
|
||||
});
|
||||
plugin.getEventManager().trigger(context, id, MechanicType.LOOT, ActionTrigger.SUCCESS, result.left(), result.right());
|
||||
}, () -> plugin.getEventManager().trigger(context, id, MechanicType.LOOT, ActionTrigger.SUCCESS, result.left(), result.right()));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user