mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-31 04:46:36 +00:00
checkpoint - 30
This commit is contained in:
@@ -46,6 +46,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
@@ -329,9 +330,9 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
|
||||
|
||||
@Override
|
||||
public YamlDocument loadConfig(String filePath, char routeSeparator) {
|
||||
try {
|
||||
try (InputStream inputStream = new FileInputStream(resolveConfig(filePath).toFile())) {
|
||||
return YamlDocument.create(
|
||||
resolveConfig(filePath).toFile(),
|
||||
inputStream,
|
||||
plugin.getResourceStream(filePath),
|
||||
GeneralSettings.builder().setRouteSeparator(routeSeparator).build(),
|
||||
LoaderSettings
|
||||
@@ -352,8 +353,8 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
|
||||
|
||||
@Override
|
||||
public YamlDocument loadData(File file) {
|
||||
try {
|
||||
return YamlDocument.create(file);
|
||||
try (InputStream inputStream = new FileInputStream(file)) {
|
||||
return YamlDocument.create(inputStream);
|
||||
} catch (IOException e) {
|
||||
plugin.getPluginLogger().severe("Failed to load config " + file, e);
|
||||
throw new RuntimeException(e);
|
||||
@@ -362,8 +363,8 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
|
||||
|
||||
@Override
|
||||
public YamlDocument loadData(File file, char routeSeparator) {
|
||||
try {
|
||||
return YamlDocument.create(file, GeneralSettings.builder().setRouteSeparator(routeSeparator).build());
|
||||
try (InputStream inputStream = new FileInputStream(file)) {
|
||||
return YamlDocument.create(inputStream, GeneralSettings.builder().setRouteSeparator(routeSeparator).build());
|
||||
} catch (IOException e) {
|
||||
plugin.getPluginLogger().severe("Failed to load config " + file, e);
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -50,6 +50,11 @@ public class ItemConfigParser {
|
||||
this.id = id;
|
||||
this.material = section.getString("material");
|
||||
if (!section.contains("tag")) section.set("tag", true);
|
||||
if (!section.contains("nick")) {
|
||||
if (section.contains("display.name")) {
|
||||
section.set("nick", section.getString("display.name"));
|
||||
}
|
||||
}
|
||||
analyze(section, functionMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,9 @@ public interface Context<T> {
|
||||
@Nullable
|
||||
<C> C arg(ContextKeys<C> key);
|
||||
|
||||
@Nullable
|
||||
<C> C remove(ContextKeys<C> key);
|
||||
|
||||
/**
|
||||
* Gets the holder of this context.
|
||||
*
|
||||
|
||||
@@ -54,10 +54,10 @@ public class ContextKeys<T> {
|
||||
public static final ContextKeys<Double> SCORE = of("score", Double.class);
|
||||
public static final ContextKeys<Double> CUSTOM_SCORE = of("custom_score", Double.class);
|
||||
public static final ContextKeys<String> RANK = of("rank", String.class);
|
||||
public static final ContextKeys<Location> HOOK_LOCATION = of("hook_location", Location.class);
|
||||
public static final ContextKeys<Integer> HOOK_X = of("hook_x", Integer.class);
|
||||
public static final ContextKeys<Integer> HOOK_Y = of("hook_y", Integer.class);
|
||||
public static final ContextKeys<Integer> HOOK_Z = of("hook_z", Integer.class);
|
||||
public static final ContextKeys<Location> OTHER_LOCATION = of("other_location", Location.class);
|
||||
public static final ContextKeys<Integer> OTHER_X = of("other_x", Integer.class);
|
||||
public static final ContextKeys<Integer> OTHER_Y = of("other_y", Integer.class);
|
||||
public static final ContextKeys<Integer> OTHER_Z = of("other_z", Integer.class);
|
||||
public static final ContextKeys<String> MONEY = of("money", String.class);
|
||||
public static final ContextKeys<String> MONEY_FORMATTED = of("money_formatted", String.class);
|
||||
public static final ContextKeys<String> REST = of("rest", String.class);
|
||||
|
||||
@@ -86,6 +86,14 @@ public final class PlayerContextImpl implements Context<Player> {
|
||||
return (C) args.get(key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <C> C remove(ContextKeys<C> key) {
|
||||
placeholderMap.remove("{" + key.key() + "}");
|
||||
return (C) args.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getHolder() {
|
||||
return player;
|
||||
|
||||
@@ -134,10 +134,10 @@ public class CustomFishingHook {
|
||||
}
|
||||
}
|
||||
|
||||
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.HOOK_X, hook.getLocation().getBlockX());
|
||||
context.arg(ContextKeys.HOOK_Y, hook.getLocation().getBlockY());
|
||||
context.arg(ContextKeys.HOOK_Z, hook.getLocation().getBlockZ());
|
||||
context.arg(ContextKeys.OTHER_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX());
|
||||
context.arg(ContextKeys.OTHER_Y, hook.getLocation().getBlockY());
|
||||
context.arg(ContextKeys.OTHER_Z, hook.getLocation().getBlockZ());
|
||||
|
||||
// get the next loot
|
||||
Loot loot = plugin.getLootManager().getNextLoot(effect, context);
|
||||
@@ -226,7 +226,7 @@ public class CustomFishingHook {
|
||||
|
||||
public void onBite() {
|
||||
if (isPlayingGame()) return;
|
||||
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.BITE);
|
||||
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.BITE);
|
||||
gears.trigger(ActionTrigger.BITE, context);
|
||||
if (RequirementManager.isSatisfied(context, ConfigManager.autoFishingRequirements())) {
|
||||
handleSuccessfulFishing();
|
||||
@@ -306,10 +306,10 @@ public class CustomFishingHook {
|
||||
public void handleFailedFishing() {
|
||||
|
||||
// update the hook location
|
||||
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.HOOK_X, hook.getLocation().getBlockX());
|
||||
context.arg(ContextKeys.HOOK_Y, hook.getLocation().getBlockY());
|
||||
context.arg(ContextKeys.HOOK_Z, hook.getLocation().getBlockZ());
|
||||
context.arg(ContextKeys.OTHER_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX());
|
||||
context.arg(ContextKeys.OTHER_Y, hook.getLocation().getBlockY());
|
||||
context.arg(ContextKeys.OTHER_Z, hook.getLocation().getBlockZ());
|
||||
|
||||
gears.trigger(ActionTrigger.FAILURE, context);
|
||||
plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.LOOT, ActionTrigger.FAILURE);
|
||||
@@ -318,10 +318,10 @@ public class CustomFishingHook {
|
||||
public void handleSuccessfulFishing() {
|
||||
|
||||
// update the hook location
|
||||
context.arg(ContextKeys.HOOK_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.HOOK_X, hook.getLocation().getBlockX());
|
||||
context.arg(ContextKeys.HOOK_Y, hook.getLocation().getBlockY());
|
||||
context.arg(ContextKeys.HOOK_Z, hook.getLocation().getBlockZ());
|
||||
context.arg(ContextKeys.OTHER_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX());
|
||||
context.arg(ContextKeys.OTHER_Y, hook.getLocation().getBlockY());
|
||||
context.arg(ContextKeys.OTHER_Z, hook.getLocation().getBlockZ());
|
||||
|
||||
LootType lootType = context.arg(ContextKeys.LOOT);
|
||||
Objects.requireNonNull(lootType, "Missing loot type");
|
||||
@@ -429,7 +429,6 @@ public class CustomFishingHook {
|
||||
|
||||
String id = context.arg(ContextKeys.ID);
|
||||
Player player = context.getHolder();
|
||||
MechanicType type = MechanicType.getTypeByID(id);
|
||||
|
||||
if (!nextLoot.disableStats()) {
|
||||
plugin.getStorageManager().getOnlineUser(player.getUniqueId()).ifPresent(
|
||||
@@ -441,14 +440,14 @@ public class CustomFishingHook {
|
||||
context.arg(ContextKeys.RECORD, max);
|
||||
context.arg(ContextKeys.RECORD_FORMATTED, String.format("%.2f", max));
|
||||
if (userData.statistics().updateSize(nextLoot.statisticKey().sizeKey(), size)) {
|
||||
plugin.getEventManager().trigger(context, id, type, ActionTrigger.NEW_SIZE_RECORD);
|
||||
plugin.getEventManager().trigger(context, id, MechanicType.LOOT, ActionTrigger.NEW_SIZE_RECORD);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
plugin.getEventManager().trigger(context, id, type, ActionTrigger.SUCCESS);
|
||||
plugin.getEventManager().trigger(context, id, MechanicType.LOOT, ActionTrigger.SUCCESS);
|
||||
player.setStatistic(Statistic.FISH_CAUGHT, player.getStatistic(Statistic.FISH_CAUGHT) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ public class FishingGears {
|
||||
// set bait if it is
|
||||
boolean hasBait = false;
|
||||
String anotherItemID = BukkitCustomFishingPlugin.getInstance().getItemManager().getItemID(rodOnMainHand ? offHandItem : mainHandItem);
|
||||
MechanicType type = MechanicType.getTypeByID(anotherItemID);
|
||||
if (type == MechanicType.BAIT) {
|
||||
List<MechanicType> type = MechanicType.getTypeByID(anotherItemID);
|
||||
if (type != null && type.contains(MechanicType.BAIT)) {
|
||||
fishingGears.gears.put(GearType.BAIT, List.of(Pair.of(anotherItemID, rodOnMainHand ? offHandItem : mainHandItem)));
|
||||
context.arg(ContextKeys.BAIT, anotherItemID);
|
||||
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(anotherItemID, MechanicType.BAIT).ifPresent(fishingGears.modifiers::add);
|
||||
@@ -140,15 +140,17 @@ public class FishingGears {
|
||||
ItemStack itemInBag = bag.getItem(i);
|
||||
if (itemInBag == null) continue;
|
||||
String bagItemID = BukkitCustomFishingPlugin.getInstance().getItemManager().getItemID(itemInBag);
|
||||
MechanicType bagItemType = MechanicType.getTypeByID(bagItemID);
|
||||
if (!hasBait && bagItemType == MechanicType.BAIT) {
|
||||
fishingGears.gears.put(GearType.BAIT, List.of(Pair.of(bagItemID, itemInBag)));
|
||||
context.arg(ContextKeys.BAIT, bagItemID);
|
||||
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(bagItemID, MechanicType.BAIT).ifPresent(fishingGears.modifiers::add);
|
||||
hasBait = true;
|
||||
}
|
||||
if (bagItemType == MechanicType.UTIL) {
|
||||
uniqueUtils.put(bagItemID, itemInBag);
|
||||
List<MechanicType> bagItemType = MechanicType.getTypeByID(bagItemID);
|
||||
if (bagItemType != null) {
|
||||
if (!hasBait && bagItemType.contains(MechanicType.BAIT)) {
|
||||
fishingGears.gears.put(GearType.BAIT, List.of(Pair.of(bagItemID, itemInBag)));
|
||||
context.arg(ContextKeys.BAIT, bagItemID);
|
||||
BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(bagItemID, MechanicType.BAIT).ifPresent(fishingGears.modifiers::add);
|
||||
hasBait = true;
|
||||
}
|
||||
if (bagItemType.contains(MechanicType.UTIL)) {
|
||||
uniqueUtils.put(bagItemID, itemInBag);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!uniqueUtils.isEmpty()) {
|
||||
|
||||
@@ -50,12 +50,6 @@ public interface ItemManager extends Reloadable {
|
||||
@Nullable
|
||||
String getCustomFishingItemID(@NotNull ItemStack itemStack);
|
||||
|
||||
@Nullable
|
||||
MechanicType getItemType(@NotNull ItemStack itemStack);
|
||||
|
||||
@Nullable
|
||||
MechanicType getItemType(@NotNull String id);
|
||||
|
||||
@Nullable
|
||||
Item dropItemLoot(@NotNull Context<Player> context, ItemStack rod, FishHook hook);
|
||||
|
||||
|
||||
@@ -22,12 +22,14 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MechanicType {
|
||||
|
||||
private static final HashMap<String, MechanicType> types = new HashMap<>();
|
||||
private static final HashMap<String, List<MechanicType>> types = new HashMap<>();
|
||||
|
||||
public static final MechanicType LOOT = of("loot");
|
||||
public static final MechanicType ROD = of("rod");
|
||||
@@ -65,18 +67,13 @@ public class MechanicType {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void register(String id, MechanicType type) {
|
||||
MechanicType previous = types.put(id, type);
|
||||
if (previous != null) {
|
||||
BukkitCustomFishingPlugin.getInstance().getPluginLogger().warn(
|
||||
"Attempted to register item type " + id + " twice, this is not a safe behavior. ["
|
||||
+ type.getType() + "," + previous.getType() + "]"
|
||||
);
|
||||
}
|
||||
List<MechanicType> previous = types.computeIfAbsent(id, k -> new ArrayList<>());
|
||||
previous.add(type);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ApiStatus.Internal
|
||||
public static MechanicType getTypeByID(String id) {
|
||||
public static List<MechanicType> getTypeByID(String id) {
|
||||
return types.get(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.momirealms.customfishing.api.mechanic.item.tag;
|
||||
|
||||
public enum TagListType {
|
||||
TAG,
|
||||
VALUE
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.customfishing.api.mechanic.item.tag;
|
||||
|
||||
import net.momirealms.customfishing.api.mechanic.context.Context;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface TagMap {
|
||||
|
||||
Map<String, Object> apply(Context<Player> context);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.customfishing.api.mechanic.item.tag;
|
||||
|
||||
public enum TagValueType {
|
||||
BYTE,
|
||||
INT,
|
||||
DOUBLE,
|
||||
LONG,
|
||||
FLOAT,
|
||||
SHORT,
|
||||
STRING,
|
||||
BYTEARRAY,
|
||||
INTARRAY
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public interface Loot {
|
||||
public static boolean DEFAULT_INSTANT_GAME = false;
|
||||
public static boolean DEFAULT_DISABLE_GAME = false;
|
||||
public static boolean DEFAULT_DISABLE_STATS = false;
|
||||
public static boolean DEFAULT_SHOW_IN_FINDER = false;
|
||||
public static boolean DEFAULT_SHOW_IN_FINDER = true;
|
||||
}
|
||||
|
||||
LootType DEFAULT_TYPE = LootType.ITEM;
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface LootManager extends Reloadable {
|
||||
@NotNull
|
||||
Optional<Loot> getLoot(String key);
|
||||
|
||||
Map<String, Double> getWeightedLoots(Context<Player> context);
|
||||
Map<String, Double> getWeightedLoots(Effect effect, Context<Player> context);
|
||||
|
||||
@Nullable
|
||||
Loot getNextLoot(Effect effect, Context<Player> context);
|
||||
|
||||
Reference in New Issue
Block a user