9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-31 04:46:36 +00:00
This commit is contained in:
XiaoMoMi
2023-12-26 02:54:24 +08:00
parent e1082af01a
commit db722484af
12 changed files with 81 additions and 27 deletions

View File

@@ -1,3 +1,9 @@
/*
* This file is part of InvUI, licensed under the MIT License.
*
* Copyright (c) 2021 NichtStudioCode
*/
package net.momirealms.customfishing.adventure.component;
import com.google.gson.stream.JsonReader;

View File

@@ -1,3 +1,9 @@
/*
* This file is part of InvUI, licensed under the MIT License.
*
* Copyright (c) 2021 NichtStudioCode
*/
package net.momirealms.customfishing.adventure.component;
import net.kyori.adventure.text.Component;

View File

@@ -1,3 +1,9 @@
/*
* This file is part of InvUI, licensed under the MIT License.
*
* Copyright (c) 2021 NichtStudioCode
*/
package net.momirealms.customfishing.adventure.component;
import net.kyori.adventure.text.Component;

View File

@@ -1,3 +1,9 @@
/*
* This file is part of InvUI, licensed under the MIT License.
*
* Copyright (c) 2021 NichtStudioCode
*/
package net.momirealms.customfishing.adventure.component;
import net.kyori.adventure.text.*;

View File

@@ -1,3 +1,9 @@
/*
* This file is part of InvUI, licensed under the MIT License.
*
* Copyright (c) 2021 NichtStudioCode
*/
package net.momirealms.customfishing.adventure.component;
import java.util.ArrayList;

View File

@@ -35,7 +35,6 @@ public class CompetitionCommand {
public CommandAPICommand getCompetitionCommand() {
return new CommandAPICommand("competition")
.withPermission("customfishing.command.competition")
.withSubcommands(
getCompetitionStartCommand(),
getCompetitionEndCommand(),

View File

@@ -51,7 +51,6 @@ public class ItemCommand {
public CommandAPICommand getItemCommand() {
return new CommandAPICommand("items")
.withPermission("customfishing.command.items")
.withSubcommands(
getSubCommand("item"),
getSubCommand("util"),

View File

@@ -678,7 +678,7 @@ 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) {
String scoreStr = fishingPreparation.getArg("{SCORE}");
String scoreStr = fishingPreparation.getArg("{CUSTOM_SCORE}");
if (scoreStr != null) {
competition.refreshData(player, Double.parseDouble(scoreStr));
} else {
@@ -686,15 +686,18 @@ public class FishingManagerImpl implements Listener, FishingManager {
case CATCH_AMOUNT -> {
fishingPreparation.insertArg("{score}", "1.00");
competition.refreshData(player, 1);
fishingPreparation.insertArg("{SCORE}", "1");
}
case MAX_SIZE, TOTAL_SIZE -> {
String size = fishingPreparation.getArg("{size}");
String size = fishingPreparation.getArg("{SIZE}");
if (size != null) {
double score = Double.parseDouble(size);
fishingPreparation.insertArg("{score}", String.format("%.2f", score));
competition.refreshData(player, score);
fishingPreparation.insertArg("{SCORE}", size);
} else {
fishingPreparation.insertArg("{score}", "0.00");
fishingPreparation.insertArg("{score}", String.format("%.2f", 0.00));
fishingPreparation.insertArg("{SCORE}", "0");
}
}
case TOTAL_SCORE -> {
@@ -703,8 +706,10 @@ public class FishingManagerImpl implements Listener, FishingManager {
double finalScore = score * effect.getScoreMultiplier() + effect.getScore();
fishingPreparation.insertArg("{score}", String.format("%.2f", finalScore));
competition.refreshData(player, finalScore);
fishingPreparation.insertArg("{SCORE}", String.valueOf(finalScore));
} else {
fishingPreparation.insertArg("{score}", "0.00");
fishingPreparation.insertArg("{SCORE}", "0");
}
}
}

View File

@@ -122,6 +122,7 @@ public class ItemManagerImpl implements ItemManager, Listener {
}
public void disable() {
HandlerList.unregisterAll(this);
this.buildableItemMap.clear();
this.itemLibraryMap.clear();
}
@@ -587,14 +588,14 @@ public class ItemManagerImpl implements ItemManager, Listener {
@Override
public ItemBuilder nbt(Map<String, Object> nbt) {
if (nbt.size() == 0) return this;
editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(nbtItem, nbt));
editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(player, placeholders, nbtItem, nbt));
return this;
}
@Override
public ItemBuilder nbt(ConfigurationSection section) {
if (section == null) return this;
editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(nbtItem, section.getValues(false)));
editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(player, placeholders, nbtItem, section.getValues(false)));
return this;
}

View File

@@ -20,7 +20,10 @@ package net.momirealms.customfishing.util;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTListCompound;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import net.momirealms.customfishing.api.util.LogUtils;
import net.momirealms.customfishing.compatibility.papi.PlaceholderManagerImpl;
import org.bukkit.configuration.MemorySection;
import org.bukkit.entity.Player;
import java.util.*;
@@ -51,7 +54,7 @@ public class NBTUtils {
* @param map The source map from Bukkit YAML
*/
@SuppressWarnings("unchecked")
public static void setTagsFromBukkitYAML(NBTCompound nbtCompound, Map<String, Object> map) {
public static void setTagsFromBukkitYAML(Player player, Map<String, String> placeholders, NBTCompound nbtCompound, Map<String, Object> map) {
Deque<StackElement> stack = new ArrayDeque<>();
stack.push(new StackElement(map, nbtCompound));
@@ -70,31 +73,31 @@ public class NBTUtils {
} else if (value instanceof List<?> list) {
for (Object o : list) {
if (o instanceof String stringValue) {
setListValue(key, stringValue, currentNbtCompound);
setListValue(player, placeholders, key, stringValue, currentNbtCompound);
} else if (o instanceof Map<?, ?> mapValue) {
NBTListCompound nbtListCompound = currentNbtCompound.getCompoundList(key).addCompound();
stack.push(new StackElement((Map<String, Object>) mapValue, nbtListCompound));
}
}
} else if (value instanceof String stringValue) {
setSingleValue(key, stringValue, currentNbtCompound);
setSingleValue(player, placeholders, key, stringValue, currentNbtCompound);
}
}
}
}
// Private helper method
private static void setListValue(String key, String value, NBTCompound nbtCompound) {
private static void setListValue(Player player, Map<String, String> placeholders, String key, String value, NBTCompound nbtCompound) {
String[] parts = getTypeAndData(value);
String type = parts[0];
String data = parts[1];
String data = getParsedData(player, placeholders, parts[1]);
switch (type) {
case "String" -> nbtCompound.getStringList(key).add(data);
case "UUID" -> nbtCompound.getUUIDList(key).add(UUID.fromString(data));
case "Double" -> nbtCompound.getDoubleList(key).add(Double.valueOf(data));
case "Long" -> nbtCompound.getLongList(key).add(Long.valueOf(data));
case "Float" -> nbtCompound.getFloatList(key).add(Float.valueOf(data));
case "Int" -> nbtCompound.getIntegerList(key).add(Integer.valueOf(data));
case "Double" -> nbtCompound.getDoubleList(key).add(Double.parseDouble(data));
case "Long" -> nbtCompound.getLongList(key).add(Long.parseLong(data));
case "Float" -> nbtCompound.getFloatList(key).add(Float.parseFloat(data));
case "Int" -> nbtCompound.getIntegerList(key).add(Integer.parseInt(data));
case "IntArray" -> {
String[] split = data.replace("[", "").replace("]", "").replaceAll("\\s", "").split(",");
int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();
@@ -105,20 +108,20 @@ public class NBTUtils {
}
// Private helper method
private static void setSingleValue(String key, String value, NBTCompound nbtCompound) {
private static void setSingleValue(Player player, Map<String, String> placeholders, String key, String value, NBTCompound nbtCompound) {
String[] parts = getTypeAndData(value);
String type = parts[0];
String data = parts[1];
String data = getParsedData(player, placeholders, parts[1]);
switch (type) {
case "Int" -> nbtCompound.setInteger(key, Integer.valueOf(data));
case "Int" -> nbtCompound.setInteger(key, Integer.parseInt(data));
case "String" -> nbtCompound.setString(key, data);
case "Long" -> nbtCompound.setLong(key, Long.valueOf(data));
case "Float" -> nbtCompound.setFloat(key, Float.valueOf(data));
case "Double" -> nbtCompound.setDouble(key, Double.valueOf(data));
case "Short" -> nbtCompound.setShort(key, Short.valueOf(data));
case "Boolean" -> nbtCompound.setBoolean(key, Boolean.valueOf(data));
case "Long" -> nbtCompound.setLong(key, Long.parseLong(data));
case "Float" -> nbtCompound.setFloat(key, Float.parseFloat(data));
case "Double" -> nbtCompound.setDouble(key, Double.parseDouble(data));
case "Short" -> nbtCompound.setShort(key, Short.parseShort(data));
case "Boolean" -> nbtCompound.setBoolean(key, Boolean.parseBoolean(data));
case "UUID" -> nbtCompound.setUUID(key, UUID.nameUUIDFromBytes(data.getBytes()));
case "Byte" -> nbtCompound.setByte(key, Byte.valueOf(data));
case "Byte" -> nbtCompound.setByte(key, Byte.parseByte(data));
case "ByteArray" -> {
String[] split = splitValue(value);
byte[] bytes = new byte[split.length];
@@ -136,6 +139,23 @@ public class NBTUtils {
}
}
public static String getParsedData(Player player, Map<String, String> placeholders, String data) {
if (data.length() >= 3)
switch (data.substring(0,3)) {
case "-P:" -> data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
case "-E:" -> {
data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders);
double value = ConfigUtils.getExpressionValue(player, data, new HashMap<>());
if (value % 1 == 0) {
data = Long.toString((long) value);
} else {
data = Double.toString(value);
}
}
}
return data;
}
/**
* Converts an NBT compound to a map of key-value pairs.
*

View File

@@ -130,7 +130,7 @@ mechanics:
# Fishing wait time
# This section would take effect if you set "override-vanilla" to true
# That also means vanilla mechanics for example lure enchantment
# would not longer take effect, so you have to configurate its effect
# would no longer take effect, so you have to configurate its effect
# in enchantment effects.
fishing-wait-time:
# override vanilla mechanic