9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2026-01-04 15:41:35 +00:00

checkpoint - 31

This commit is contained in:
XiaoMoMi
2024-07-09 03:04:01 +08:00
parent a3191bc693
commit 12782164c8
51 changed files with 665 additions and 134 deletions

View File

@@ -15,10 +15,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.item;
package net.momirealms.customfishing.api.mechanic;
import net.kyori.adventure.util.Index;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

View File

@@ -18,13 +18,13 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -18,11 +18,11 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.block.BlockConfig;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -94,6 +94,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
protected Requirement<Player>[] skipGameRequirements;
protected Requirement<Player>[] autoFishingRequirements;
protected boolean enableBag;
protected boolean baitAnimation;
protected List<TriConsumer<Effect, Context<Player>, Integer>> globalEffects;
protected ConfigManager(BukkitCustomFishingPlugin plugin) {
@@ -201,6 +202,10 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
return instance.enableBag;
}
public static boolean baitAnimation() {
return instance.baitAnimation;
}
public static List<String> durabilityLore() {
return instance.durabilityLore;
}

View File

@@ -19,8 +19,8 @@ package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.common.config.node.Node;
import org.apache.logging.log4j.util.TriConsumer;

View File

@@ -18,12 +18,12 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EffectModifierParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EventParserFunction;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.common.config.node.Node;
import java.util.ArrayList;

View File

@@ -18,11 +18,11 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.entity.EntityConfig;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -18,6 +18,7 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
@@ -25,7 +26,6 @@ import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.hook.HookConfig;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -18,12 +18,12 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -18,13 +18,13 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -18,13 +18,13 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.ConfigParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EffectModifierParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.EventParserFunction;
import net.momirealms.customfishing.api.mechanic.config.function.TotemParserFunction;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.totem.TotemConfig;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -18,13 +18,13 @@
package net.momirealms.customfishing.api.mechanic.config;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.function.*;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffect;
import net.momirealms.customfishing.api.mechanic.event.EventCarrier;
import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.common.config.node.Node;

View File

@@ -17,7 +17,7 @@
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import java.util.Optional;

View File

@@ -1,7 +1,7 @@
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import net.momirealms.customfishing.common.util.TriConsumer;
import org.bukkit.entity.Player;

View File

@@ -17,8 +17,8 @@
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.requirement.Requirement;
import net.momirealms.customfishing.common.util.TriConsumer;
import org.bukkit.entity.Player;

View File

@@ -17,10 +17,10 @@
package net.momirealms.customfishing.api.mechanic.event;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import org.bukkit.entity.Player;
import java.util.HashMap;

View File

@@ -17,11 +17,11 @@
package net.momirealms.customfishing.api.mechanic.event;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionManager;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import org.bukkit.entity.Player;
import java.util.HashMap;

View File

@@ -1,10 +1,10 @@
package net.momirealms.customfishing.api.mechanic.event;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionManager;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.common.plugin.feature.Reloadable;
import org.bukkit.entity.Player;

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.fishing;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask;
import net.momirealms.sparrow.heart.SparrowHeart;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.concurrent.TimeUnit;
public class BaitAnimationTask implements Runnable {
private final SchedulerTask task;
private final int entityID;
private final Player player;
private final FishHook fishHook;
public BaitAnimationTask(BukkitCustomFishingPlugin plugin, Player player, FishHook fishHook, ItemStack baitItem) {
this.player = player;
this.fishHook = fishHook;
this.task = plugin.getScheduler().asyncRepeating(this, 50, 50, TimeUnit.MILLISECONDS);
ItemStack itemStack = baitItem.clone();
itemStack.setAmount(1);
this.entityID = SparrowHeart.getInstance().dropFakeItem(player, itemStack, fishHook.getLocation().clone().subtract(0,0.6,0));
}
@Override
public void run() {
SparrowHeart.getInstance().sendClientSideEntityMotion(player, fishHook.getVelocity(), entityID);
SparrowHeart.getInstance().sendClientSideTeleportEntity(player, fishHook.getLocation().clone().subtract(0,0.6,0), false, entityID);
}
public void cancel() {
task.cancel();
SparrowHeart.getInstance().removeClientSideEntity(player, entityID);
}
}

View File

@@ -20,6 +20,7 @@ package net.momirealms.customfishing.api.mechanic.fishing;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.event.FishingLootSpawnEvent;
import net.momirealms.customfishing.api.event.FishingResultEvent;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal;
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
@@ -34,7 +35,6 @@ import net.momirealms.customfishing.api.mechanic.fishing.hook.VanillaMechanic;
import net.momirealms.customfishing.api.mechanic.fishing.hook.VoidFishingMechanic;
import net.momirealms.customfishing.api.mechanic.game.Game;
import net.momirealms.customfishing.api.mechanic.game.GamingPlayer;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.loot.LootType;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
@@ -72,6 +72,7 @@ public class CustomFishingHook {
private HookMechanic hookMechanic;
private Loot nextLoot;
private GamingPlayer gamingPlayer;
private BaitAnimationTask baitAnimationTask;
private static TriFunction<FishHook, Context<Player>, Effect, List<HookMechanic>> mechanicProviders = defaultMechanicProviders();
@@ -103,6 +104,11 @@ public class CustomFishingHook {
consumer.accept(effect, context, 0);
}
}
// enable bait animation
if (ConfigManager.baitAnimation() && !gears.getItem(FishingGears.GearType.BAIT).isEmpty()) {
this.baitAnimationTask = new BaitAnimationTask(plugin, context.getHolder(), hook, gears.getItem(FishingGears.GearType.BAIT).stream().findAny().get().right());
}
List<HookMechanic> enabledMechanics = mechanicProviders.apply(hook, context, effect);
this.task = plugin.getScheduler().sync().runRepeating(() -> {
// destroy if hook is invalid
@@ -125,6 +131,13 @@ public class CustomFishingHook {
if (this.hookMechanic != mechanic) {
if (this.hookMechanic != null) this.hookMechanic.destroy();
this.hookMechanic = mechanic;
// remove bait animation if there exists
if (this.baitAnimationTask != null) {
this.baitAnimationTask.cancel();
this.baitAnimationTask = null;
}
// to update some properties
mechanic.preStart();
Effect tempEffect = effect.copy();
@@ -179,6 +192,10 @@ public class CustomFishingHook {
if (hook.isValid()) hook.remove();
if (hookMechanic != null) hookMechanic.destroy();
if (gamingPlayer != null) gamingPlayer.destroy();
if (this.baitAnimationTask != null) {
this.baitAnimationTask.cancel();
this.baitAnimationTask = null;
}
}
public Context<Player> getContext() {

View File

@@ -18,12 +18,12 @@
package net.momirealms.customfishing.api.mechanic.fishing;
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.config.ConfigManager;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.item.MechanicType;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
import net.momirealms.customfishing.api.storage.user.UserData;
import net.momirealms.customfishing.common.util.Pair;

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.item;
import com.saicone.rtag.RtagItem;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface ItemEditor {
void apply(RtagItem item, Context<Player> context);
}

View File

@@ -1,10 +0,0 @@
package net.momirealms.customfishing.api.mechanic.item.component;
import com.saicone.rtag.RtagItem;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.entity.Player;
public interface ComponentEditor {
void apply(RtagItem item, Context<Player> context);
}

View File

@@ -1,11 +0,0 @@
package net.momirealms.customfishing.api.mechanic.item.tag;
import com.saicone.rtag.RtagItem;
import net.momirealms.customfishing.api.mechanic.context.Context;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface TagEditor {
void apply(RtagItem item, Context<Player> context);
}

View File

@@ -1,6 +0,0 @@
package net.momirealms.customfishing.api.mechanic.item.tag;
public enum TagListType {
TAG,
VALUE
}

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.item.tag;
import net.momirealms.customfishing.api.mechanic.context.Context;
@@ -8,4 +25,8 @@ import java.util.Map;
public interface TagMap {
Map<String, Object> apply(Context<Player> context);
static TagMap of(Map<String, Object> inputMap) {
return new TagMapImpl(inputMap);
}
}

View File

@@ -0,0 +1,191 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.item.tag;
import net.momirealms.customfishing.api.mechanic.context.Context;
import net.momirealms.customfishing.api.mechanic.misc.value.MathValue;
import net.momirealms.customfishing.api.mechanic.misc.value.TextValue;
import net.momirealms.customfishing.common.util.Pair;
import org.bukkit.entity.Player;
import java.util.*;
import static net.momirealms.customfishing.api.util.TagUtils.toTypeAndData;
import static net.momirealms.customfishing.common.util.ArrayUtils.splitValue;
public class TagMapImpl implements TagMap {
private final Map<String, Object> convertedMap = new HashMap<>();
public TagMapImpl(Map<String, Object> inputMap) {
this.analyze(inputMap, convertedMap);
}
private void analyze(Map<String, Object> inputMap, Map<String, Object> outPutMap) {
for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map<?, ?> inner) {
Map<String, Object> inputInnerMap = (Map<String, Object>) inner;
HashMap<String, Object> outputInnerMap = new HashMap<>();
outPutMap.put(key, outputInnerMap);
analyze(inputInnerMap, outputInnerMap);
} else if (value instanceof List<?> list) {
Object first = list.get(0);
ArrayList<Object> outputList = new ArrayList<>();
if (first instanceof Map<?, ?>) {
for (Object o : list) {
Map<String, Object> inputListMap = (Map<String, Object>) o;
outputList.add(TagMap.of(inputListMap));
}
} else if (first instanceof String) {
for (Object o : list) {
String str = (String) o;
Pair<TagValueType, String> pair = toTypeAndData(str);
switch (pair.left()) {
case STRING -> {
TextValue<Player> textValue = TextValue.auto(pair.right());
outputList.add((ValueProvider) textValue::render);
}
case BYTE -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outputList.add((ValueProvider) context -> (byte) mathValue.evaluate(context));
}
case SHORT -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outputList.add((ValueProvider) context -> (short) mathValue.evaluate(context));
}
case INT -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outputList.add((ValueProvider) context -> (int) mathValue.evaluate(context));
}
case LONG -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outputList.add((ValueProvider) context -> (long) mathValue.evaluate(context));
}
case FLOAT -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outputList.add((ValueProvider) context -> (float) mathValue.evaluate(context));
}
case DOUBLE -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outputList.add((ValueProvider) context -> (double) mathValue.evaluate(context));
}
}
}
} else {
outputList.addAll(list);
}
outPutMap.put(key, outputList);
} else if (value instanceof String str) {
Pair<TagValueType, String> pair = toTypeAndData(str);
switch (pair.left()) {
case INTARRAY -> {
String[] split = splitValue(str);
int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();
outPutMap.put(pair.right(), array);
}
case BYTEARRAY -> {
String[] split = splitValue(str);
byte[] bytes = new byte[split.length];
for (int i = 0; i < split.length; i++){
bytes[i] = Byte.parseByte(split[i]);
}
outPutMap.put(pair.right(), bytes);
}
case STRING -> {
TextValue<Player> textValue = TextValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) textValue::render);
}
case BYTE -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) context -> (byte) mathValue.evaluate(context));
}
case SHORT -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) context -> (short) mathValue.evaluate(context));
}
case INT -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) context -> (int) mathValue.evaluate(context));
}
case LONG -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) context -> (long) mathValue.evaluate(context));
}
case FLOAT -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) context -> (float) mathValue.evaluate(context));
}
case DOUBLE -> {
MathValue<Player> mathValue = MathValue.auto(pair.right());
outPutMap.put(key, (ValueProvider) context -> (double) mathValue.evaluate(context));
}
}
} else {
outPutMap.put(key, value);
}
}
}
@Override
public Map<String, Object> apply(Context<Player> context) {
HashMap<String, Object> output = new HashMap<>();
setMapValue(convertedMap, output, context);
return output;
}
private void setMapValue(Map<String, Object> inputMap, Map<String, Object> outPutMap, Context<Player> context) {
for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map<?, ?> inner) {
Map<String, Object> inputInnerMap = (Map<String, Object>) inner;
HashMap<String, Object> outputInnerMap = new HashMap<>();
outPutMap.put(key, outputInnerMap);
setMapValue(inputInnerMap, outputInnerMap, context);
} else if (value instanceof List<?> list) {
ArrayList<Object> convertedList = new ArrayList<>();
Object first = list.get(0);
if (first instanceof TagMap) {
for (Object o : list) {
TagMap map = (TagMap) o;
convertedList.add(map.apply(context));
}
} else if (first instanceof ValueProvider) {
for (Object o : list) {
ValueProvider pd = (ValueProvider) o;
convertedList.add(pd.apply(context));
}
} else {
convertedList.addAll(list);
}
outPutMap.put(key, convertedList);
} else if (value instanceof ValueProvider provider) {
outPutMap.put(key, provider.apply(context));
} else {
outPutMap.put(key, value);
}
}
}
@FunctionalInterface
public interface ValueProvider {
Object apply(Context<Player> context);
}
}

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.item.tag;
public enum TagValueType {

View File

@@ -85,7 +85,6 @@ public class FishingStatisticsImpl implements FishingStatistics {
float previous = sizeMap.getOrDefault(id, 0f);
if (previous >= newSize) return false;
sizeMap.put(id, newSize);
System.out.println(sizeMap);
return true;
}

View File

@@ -0,0 +1,22 @@
package net.momirealms.customfishing.api.util;
import net.momirealms.customfishing.api.mechanic.item.tag.TagValueType;
import net.momirealms.customfishing.common.util.Pair;
import java.util.Locale;
public class TagUtils {
public static Pair<TagValueType, String> toTypeAndData(String str) {
String[] parts = str.split("\\s+", 2);
if (parts.length == 1) {
return Pair.of(TagValueType.STRING, parts[0]);
}
if (parts.length != 2) {
throw new IllegalArgumentException("Invalid value format: " + str);
}
TagValueType type = TagValueType.valueOf(parts[0].substring(1, parts[0].length() - 1).toUpperCase(Locale.ENGLISH));
String data = parts[1];
return Pair.of(type, data);
}
}