9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
XiaoMoMi
2025-06-30 01:11:10 +08:00
parent f779f2c024
commit 531ce227b3
13 changed files with 128 additions and 154 deletions

View File

@@ -25,6 +25,7 @@ dependencies {
compileOnly("org.apache.logging.log4j:log4j-core:${rootProject.properties["log4j_version"]}")
compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}")
compileOnly("net.kyori:adventure-text-serializer-gson:${rootProject.properties["adventure_bundle_version"]}")
compileOnly("net.kyori:adventure-text-serializer-json-legacy-impl:${rootProject.properties["adventure_bundle_version"]}")
compileOnly("com.github.ben-manes.caffeine:caffeine:${rootProject.properties["caffeine_version"]}")
compileOnly("net.objecthunter:exp4j:${rootProject.properties["exp4j_version"]}")
compileOnly("com.google.guava:guava:${rootProject.properties["guava_version"]}")

View File

@@ -41,7 +41,7 @@ public class MechanicType {
public static final MechanicType HOOK = of("hook");
public static final MechanicType TOTEM = of("totem");
public static final MechanicType ENCHANT = of("enchant");
public static final MechanicType GEAR = of("gear");
public static final MechanicType EQUIPMENT = of("equipment");
private final String type;

View File

@@ -32,8 +32,8 @@ import java.util.function.Supplier;
* Configuration types for various mechanics.
*/
public class ConfigType {
public static final ConfigType GEAR = of(
"gear", //new
public static final ConfigType EQUIPMENT = of(
"equipment", //new
() -> {
HashMap<String, Node<ConfigParserFunction>> parsers = new HashMap<>();
parsers.putAll(BukkitCustomFishingPlugin.getInstance().getConfigManager().getItemFormatFunctions());
@@ -42,10 +42,10 @@ public class ConfigType {
return parsers;
},
(id, section, functions) -> {
MechanicType.register(id, MechanicType.GEAR);
MechanicType.register(id, MechanicType.EQUIPMENT);
GearConfigParser config = new GearConfigParser(id, section, functions);
BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem());
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.GEAR);
BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.EQUIPMENT);
BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier());
}
);
@@ -234,7 +234,7 @@ public class ConfigType {
}
);
private static final ConfigType[] values = new ConfigType[] {ITEM, ENTITY, BLOCK, HOOK, ROD, BAIT, UTIL, TOTEM, ENCHANT, MINI_GAME, COMPETITION, GEAR};
private static final ConfigType[] values = new ConfigType[] {ITEM, ENTITY, BLOCK, HOOK, ROD, BAIT, UTIL, TOTEM, ENCHANT, MINI_GAME, COMPETITION, EQUIPMENT};
/**
* Gets an array of all configuration types.

View File

@@ -80,7 +80,7 @@ public class GearConfigParser {
public EffectModifier getEffectModifier() {
EffectModifier.Builder builder = EffectModifier.builder()
.id(id)
.type(MechanicType.GEAR);
.type(MechanicType.EQUIPMENT);
for (Consumer<EffectModifier.Builder> consumer : effectBuilderConsumers) {
consumer.accept(builder);
}
@@ -90,7 +90,7 @@ public class GearConfigParser {
public EventCarrier getEventCarrier() {
EventCarrier.Builder builder = EventCarrier.builder()
.id(id)
.type(MechanicType.GEAR);
.type(MechanicType.EQUIPMENT);
for (Consumer<EventCarrier.Builder> consumer : eventBuilderConsumers) {
consumer.accept(builder);
}

View File

@@ -252,14 +252,14 @@ public class FishingGears {
if (armorPiece != null && armorPiece.getType() != Material.AIR) {
String gearID = BukkitCustomFishingPlugin.getInstance().getItemManager().getItemID(armorPiece);
List<MechanicType> itemTypes = MechanicType.getTypeByID(gearID);
if (itemTypes != null && itemTypes.contains(MechanicType.GEAR)) {
if (itemTypes != null && itemTypes.contains(MechanicType.EQUIPMENT)) {
gearItemsList.add(Pair.of(gearID, armorPiece));
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(gearID, MechanicType.GEAR).ifPresent(fishingGears.modifiers::add);
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(gearID, MechanicType.EQUIPMENT).ifPresent(fishingGears.modifiers::add);
}
}
}
if (!gearItemsList.isEmpty()) {
fishingGears.gears.put(GearType.GEAR, gearItemsList);
fishingGears.gears.put(GearType.EQUIPMENT, gearItemsList);
}
// check requirements before checking totems
@@ -305,7 +305,7 @@ public class FishingGears {
((context, itemStack) -> {}),
((context, itemStack) -> {})
);
public static final GearType GEAR = new GearType(MechanicType.GEAR,
public static final GearType EQUIPMENT = new GearType(MechanicType.EQUIPMENT,
((context, itemStack) -> {}), // castFunction
((context, itemStack) -> {}), // reelFunction
((context, itemStack) -> {}), // biteFunction

View File

@@ -25,6 +25,8 @@ import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.json.JSONOptions;
import net.kyori.adventure.text.serializer.json.legacyimpl.NBTLegacyHoverEventSerializer;
import net.kyori.adventure.title.Title;
import java.time.Duration;
@@ -44,7 +46,19 @@ public class AdventureHelper {
private AdventureHelper() {
this.miniMessage = MiniMessage.builder().build();
this.miniMessageStrict = MiniMessage.builder().strict(true).build();
this.gsonComponentSerializer = GsonComponentSerializer.builder().build();
GsonComponentSerializer.Builder builder = GsonComponentSerializer.builder();
if (!VersionHelper.isVersionNewerThan1_20_5()) {
builder.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get());
builder.editOptions((b) -> b.value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, false));
}
if (!VersionHelper.isVersionNewerThan1_21_5()) {
builder.editOptions((b) -> {
b.value(JSONOptions.EMIT_CLICK_EVENT_TYPE, JSONOptions.ClickEventValueMode.CAMEL_CASE);
b.value(JSONOptions.EMIT_HOVER_EVENT_TYPE, JSONOptions.HoverEventValueMode.CAMEL_CASE);
b.value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_KEY_AS_TYPE_AND_UUID_AS_ID, true);
});
}
this.gsonComponentSerializer = builder.build();
}
private static class SingletonHolder {
@@ -103,40 +117,6 @@ public class AdventureHelper {
return instance.miniMessageToJsonCache.get(miniMessage, (text) -> instance.gsonComponentSerializer.serialize(miniMessage(text)));
}
/**
* Sends a title to an audience.
*
* @param audience the audience to send the title to
* @param title the title component
* @param subtitle the subtitle component
* @param fadeIn the fade-in duration in ticks
* @param stay the stay duration in ticks
* @param fadeOut the fade-out duration in ticks
*/
public static void sendTitle(Audience audience, Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
audience.showTitle(Title.title(title, subtitle, Title.Times.times(Duration.ofMillis(fadeIn * 50L), Duration.ofMillis(stay * 50L), Duration.ofMillis(fadeOut * 50L))));
}
/**
* Sends an action bar message to an audience.
*
* @param audience the audience to send the action bar message to
* @param actionBar the action bar component
*/
public static void sendActionBar(Audience audience, Component actionBar) {
audience.sendActionBar(actionBar);
}
/**
* Sends a message to an audience.
*
* @param audience the audience to send the message to
* @param message the message component
*/
public static void sendMessage(Audience audience, Component message) {
audience.sendMessage(message);
}
/**
* Plays a sound for an audience.
*