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

redo effect system

This commit is contained in:
XiaoMoMi
2023-11-05 17:10:53 +08:00
parent 4640e9007e
commit b82c74ca08
20 changed files with 304 additions and 207 deletions

View File

@@ -23,6 +23,7 @@ import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
import net.momirealms.customfishing.adventure.AdventureManagerImpl;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.event.CustomFishingReloadEvent;
import net.momirealms.customfishing.api.util.LogUtils;
import net.momirealms.customfishing.api.util.ReflectionUtils;
import net.momirealms.customfishing.command.CommandManagerImpl;
@@ -107,6 +108,7 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
this.hookManager = new HookManagerImpl(this);
this.chatCatcherManager = new ChatCatcherManager(this);
this.reload();
super.initialized = true;
if (CFConfig.metrics) new Metrics(this, 16648);
if (CFConfig.updateChecker)
@@ -191,6 +193,9 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin {
this.coolDownManager.load();
this.chatCatcherManager.unload();
this.chatCatcherManager.load();
CustomFishingReloadEvent event = new CustomFishingReloadEvent(this);
Bukkit.getPluginManager().callEvent(event);
}
/**

View File

@@ -18,10 +18,7 @@
package net.momirealms.customfishing.command.sub;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.IStringTooltip;
import dev.jorel.commandapi.StringTooltip;
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.BooleanArgument;
import dev.jorel.commandapi.arguments.StringArgument;
import net.momirealms.customfishing.adventure.AdventureManagerImpl;
import net.momirealms.customfishing.api.CustomFishingPlugin;

View File

@@ -20,16 +20,12 @@ package net.momirealms.customfishing.compatibility.papi;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.data.user.OnlineUser;
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
import net.momirealms.customfishing.setting.CFLocale;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
public class CFPapi extends PlaceholderExpansion {
private final CustomFishingPlugin plugin;

View File

@@ -24,14 +24,12 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

View File

@@ -27,6 +27,7 @@ package net.momirealms.customfishing.libraries.libraryloader;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import net.momirealms.customfishing.CustomFishingPluginImpl;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.util.LogUtils;
@@ -46,7 +47,7 @@ import java.util.StringJoiner;
public final class LibraryLoader {
@SuppressWarnings("Guava")
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) CustomFishingPlugin.getInstance().getClass().getClassLoader()));
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) CustomFishingPluginImpl.getInstance().getClass().getClassLoader()));
/**
* Resolves all {@link MavenLibrary} annotations on the given object.

View File

@@ -42,7 +42,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
public class BagManagerImpl implements BagManager, Listener {

View File

@@ -25,7 +25,6 @@ import net.momirealms.customfishing.api.mechanic.competition.*;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.scheduler.CancellableTask;
import net.momirealms.customfishing.api.util.LogUtils;
import net.momirealms.customfishing.setting.CFConfig;
import net.momirealms.customfishing.setting.CFLocale;
import net.momirealms.customfishing.storage.method.database.nosql.RedisManager;
import net.momirealms.customfishing.util.ConfigUtils;

View File

@@ -187,7 +187,7 @@ public class EffectManagerImpl implements EffectManager {
@NotNull
@Override
public FishingEffect getInitialEffect() {
return new FishingEffect.Builder().build();
return new FishingEffect();
}
/**
@@ -270,16 +270,28 @@ public class EffectManagerImpl implements EffectManager {
effect.addWeightModifierIgnored(modList);
});
}
case "hook-time" -> {
case "wait-time" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setHookTimeModifier(effect.getHookTimeModifier() + value.get(condition.getPlayer()) - 1);
effect.setWaitTime(effect.getWaitTime() + value.get(condition.getPlayer()));
});
}
case "hook-time", "wait-time-multiplier" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setWaitTimeMultiplier(effect.getWaitTimeMultiplier() + value.get(condition.getPlayer()) - 1);
});
}
case "difficulty" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setDifficultyModifier(effect.getDifficultyModifier() + value.get(condition.getPlayer()));
effect.setDifficulty(effect.getDifficulty() + value.get(condition.getPlayer()));
});
}
case "difficulty-multiplier", "difficulty-bonus" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setDifficultyMultiplier(effect.getDifficultyMultiplier() + value.get(condition.getPlayer()) - 1);
});
}
case "multiple-loot" -> {
@@ -288,13 +300,25 @@ public class EffectManagerImpl implements EffectManager {
effect.setMultipleLootChance(effect.getMultipleLootChance() + value.get(condition.getPlayer()));
});
}
case "score-bonus" -> {
case "score" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setScore(effect.getScore() + value.get(condition.getPlayer()));
});
}
case "score-bonus", "score-multiplier" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setScoreMultiplier(effect.getScoreMultiplier() + value.get(condition.getPlayer()) - 1);
});
}
case "size-bonus" -> {
case "size" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setSize(effect.getSize() + value.get(condition.getPlayer()));
});
}
case "size-bonus", "size-multiplier" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setSizeMultiplier(effect.getSizeMultiplier() + value.get(condition.getPlayer()) - 1);
@@ -303,7 +327,13 @@ public class EffectManagerImpl implements EffectManager {
case "game-time" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setGameTimeModifier(effect.getGameTimeModifier() + value.get(condition.getPlayer()));
effect.setGameTime(effect.getGameTime() + value.get(condition.getPlayer()));
});
}
case "game-time-bonus", "game-time-multiplier" -> {
var value = ConfigUtils.getValue(section.get("value"));
return ((effect, condition) -> {
effect.setGameTimeMultiplier(effect.getGameTimeMultiplier() + value.get(condition.getPlayer()) - 1);
});
}
case "lava-fishing" -> {

View File

@@ -302,8 +302,9 @@ public class FishingManagerImpl implements Listener, FishingManager {
// Store fishhook entity and apply the effects
final FishHook fishHook = event.getHook();
this.hookCacheMap.put(player.getUniqueId(), fishHook);
fishHook.setMaxWaitTime((int) (fishHook.getMaxWaitTime() * initialEffect.getHookTimeModifier()));
fishHook.setMinWaitTime((int) (fishHook.getMinWaitTime() * initialEffect.getHookTimeModifier()));
// fishHook.setMaxWaitTime(Math.max(100, (int) (fishHook.getMaxWaitTime() * initialEffect.getHookTimeModifier())));
// fishHook.setMinWaitTime(Math.max(100, (int) (fishHook.getMinWaitTime() * initialEffect.getHookTimeModifier())));
fishHook.setWaitTime(Math.max(1, (int) (fishHook.getWaitTime() * initialEffect.getWaitTimeMultiplier() + initialEffect.getWaitTime())));
// Reduce amount & Send animation
var baitItem = fishingPreparation.getBaitItemStack();
if (baitItem != null) {
@@ -594,6 +595,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
var fishingPreparation = state.getPreparation();
var player = fishingPreparation.getPlayer();
fishingPreparation.insertArg("{size-multiplier}", String.valueOf(effect.getSizeMultiplier()));
fishingPreparation.insertArg("{size-fixed}", String.valueOf(effect.getSize()));
int amount;
if (loot.getType() == LootType.ITEM) {
amount = (int) effect.getMultipleLootChance();
@@ -668,27 +670,27 @@ public class FishingManagerImpl implements Listener, FishingManager {
} else {
switch (competition.getGoal()) {
case CATCH_AMOUNT -> {
double score = effect.getScoreMultiplier();
fishingPreparation.insertArg("{score}", String.format("%.2f", score));
competition.refreshData(player, score);
fishingPreparation.insertArg("{score}", "1.00");
competition.refreshData(player, 1);
}
case MAX_SIZE, TOTAL_SIZE -> {
String size = fishingPreparation.getArg("{size}");
if (size != null) {
double score = Double.parseDouble(size) * effect.getScoreMultiplier();
double score = Double.parseDouble(size);
fishingPreparation.insertArg("{score}", String.format("%.2f", score));
competition.refreshData(player, score);
} else {
fishingPreparation.insertArg("{score}", "0");
fishingPreparation.insertArg("{score}", "0.00");
}
}
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());
double finalScore = score * effect.getScoreMultiplier() + effect.getScore();
fishingPreparation.insertArg("{score}", String.format("%.2f", finalScore));
competition.refreshData(player, finalScore);
} else {
fishingPreparation.insertArg("{score}", "0");
fishingPreparation.insertArg("{score}", "0.00");
}
}
}

View File

@@ -206,7 +206,7 @@ public class HookCheckTimerTask implements Runnable {
// get random time
int random = ThreadLocalRandom.current().nextInt(CFConfig.lavaMinTime, CFConfig.lavaMaxTime);
random -= lureLevel * 100;
random *= initialEffect.getHookTimeModifier();
random *= initialEffect.getWaitTimeMultiplier();
random = Math.max(CFConfig.lavaMinTime, random);
// lava effect task (Three seconds in advance)

View File

@@ -670,7 +670,9 @@ public class ItemManagerImpl implements ItemManager, Listener {
NBTCompound cfCompound = nbtItem.getOrCreateCompound("CustomFishing");
float random = size.left() + ThreadLocalRandom.current().nextFloat(size.right() - size.left());
float bonus = Float.parseFloat(placeholders.getOrDefault("{size-multiplier}", "1.0"));
double fixed = Double.parseDouble(placeholders.getOrDefault("{size-fixed}", "0.0"));
random *= bonus;
random += fixed;
cfCompound.setFloat("size", random);
placeholders.put("{size}", String.format("%.2f", random));
});

View File

@@ -25,7 +25,6 @@ import net.momirealms.customfishing.compatibility.papi.PlaceholderManagerImpl;
import net.momirealms.customfishing.mechanic.misc.value.ExpressionValue;
import net.momirealms.customfishing.mechanic.misc.value.PlainValue;
import net.momirealms.customfishing.mechanic.misc.value.Value;
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;

View File

@@ -54,13 +54,13 @@ magnetic_bait:
- '<gray>can''t help but investigate.'
- ''
- '<#FFD700>Effects:'
- '<gray> - Reduce hook time'
- '<gray> - Reduce wait time'
- '<gray> - More time for fishing'
- ''
custom-model-data: 50002
effects:
hooktime:
type: hook-time
type: wait-time-multiplier
value: 0.9
gametime:
type: game-time
@@ -86,9 +86,9 @@ wild_bait:
effects:
difficulty:
type: difficulty
value: 20
value: +20
size:
type: size-bonus
type: size-multiplier
value: 1.5
gametime:
type: game-time

View File

@@ -10,7 +10,7 @@ FISHING_ROD:
material: fishing_rod
effects:
time_effect:
type: hook-time
type: wait-time-multiplier
value: 1.5
# Custom rods
@@ -32,7 +32,7 @@ beginner_rod:
max-durability: 64
effects:
time_effect:
type: hook-time
type: wait-time-multiplier
value: 1.8
difficulty:
type: difficulty
@@ -176,7 +176,7 @@ magical_rod:
value:
- enchantments:+10
time_effect:
type: hook-time
type: wait-time-multiplier
value: 3
master_rod:
@@ -200,7 +200,7 @@ master_rod:
max-durability: 128
effects:
time_effect:
type: hook-time
type: wait-time-multiplier
value: 0.95
difficulty:
type: difficulty