9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 03:49:07 +00:00

remake default configs

This commit is contained in:
XiaoMoMi
2023-09-12 04:25:24 +08:00
parent 2068a3b178
commit 908fd59016
34 changed files with 1717 additions and 411 deletions

View File

@@ -17,8 +17,8 @@
package net.momirealms.customfishing.api.manager;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import net.momirealms.customfishing.api.mechanic.entity.EntityLibrary;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.bukkit.Location;
public interface EntityManager {

View File

@@ -52,7 +52,7 @@ public interface FishingManager {
Loot getNextLoot(Effect initialEffect, Condition condition);
void startFishingGame(Player player, Loot loot, Effect effect);
void startFishingGame(Player player, Condition condition, Effect effect);
void startFishingGame(Player player, GameSettings settings, GameInstance gameInstance);
}

View File

@@ -17,11 +17,16 @@
package net.momirealms.customfishing.api.manager;
import net.momirealms.customfishing.api.mechanic.game.GameConfig;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.game.BasicGameConfig;
import net.momirealms.customfishing.api.mechanic.game.GameFactory;
import net.momirealms.customfishing.api.mechanic.game.GameInstance;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Optional;
public interface GameManager {
@@ -29,15 +34,9 @@ public interface GameManager {
boolean unregisterGameType(String type);
@Nullable GameFactory getGameCreator(String type);
@Nullable GameInstance getGame(String key);
@Nullable GameConfig getGameConfig(String key);
GameInstance getRandomGame();
GameConfig getRandomGameConfig();
@Nullable GameFactory getGameFactory(String type);
Optional<Pair<BasicGameConfig, GameInstance>> getGame(String key);
HashMap<String, Double> getGameWithWeight(Condition condition);
}

View File

@@ -17,10 +17,12 @@
package net.momirealms.customfishing.api.manager;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.loot.Loot;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public interface LootManager {
@@ -32,4 +34,6 @@ public interface LootManager {
Collection<String> getAllLootKeys();
Collection<Loot> getAllLoots();
HashMap<String, Double> getLootWithWeight(Condition condition);
}

View File

@@ -33,6 +33,8 @@ public interface RequirementManager {
HashMap<String, Double> getLootWithWeight(Condition condition);
HashMap<String, Double> getGameWithWeight(Condition condition);
@Nullable Requirement[] getRequirements(ConfigurationSection section, boolean advanced);
Requirement getRequirement(ConfigurationSection section, boolean checkAction);

View File

@@ -11,7 +11,7 @@ import java.util.Map;
public class GlobalSettings {
public static HashMap<ActionTrigger, Action[]> itemActions = new HashMap<>();
public static HashMap<ActionTrigger, Action[]> lootActions = new HashMap<>();
public static HashMap<ActionTrigger, Action[]> rodActions = new HashMap<>();
public static HashMap<ActionTrigger, Action[]> baitActions = new HashMap<>();
@@ -21,7 +21,7 @@ public class GlobalSettings {
if (entry.getValue() instanceof ConfigurationSection inner) {
HashMap<ActionTrigger, Action[]> map = CustomFishingPlugin.get().getActionManager().getActionMap(inner);
switch (entry.getKey()) {
case "item" -> itemActions = map;
case "loot" -> lootActions = map;
case "rod" -> rodActions = map;
case "bait" -> baitActions = map;
}
@@ -30,13 +30,13 @@ public class GlobalSettings {
}
public static void unload() {
itemActions.clear();
lootActions.clear();
rodActions.clear();
baitActions.clear();
}
public static void triggerItemActions(ActionTrigger trigger, Condition condition) {
Action[] actions = itemActions.get(trigger);
public static void triggerLootActions(ActionTrigger trigger, Condition condition) {
Action[] actions = lootActions.get(trigger);
if (actions != null) {
for (Action action : actions) {
action.trigger(condition);

View File

@@ -113,9 +113,7 @@ public class FishingPreparation extends Condition {
}
}
for (String enchant : plugin.getIntegrationManager().getEnchantments(rodItemStack)) {
System.out.println(enchant);
EffectCarrier enchantEffect = plugin.getEffectManager().getEffect("enchant", enchant);
if (enchantEffect != null) {
if (!enchantEffect.isConditionMet(this)) {

View File

@@ -0,0 +1,57 @@
package net.momirealms.customfishing.api.mechanic.game;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import org.jetbrains.annotations.Nullable;
import java.util.concurrent.ThreadLocalRandom;
public class BasicGameConfig {
private int minTime;
private int maxTime;
private int minDifficulty;
private int maxDifficulty;
public static class Builder {
private final BasicGameConfig basicGameConfig;
public Builder() {
basicGameConfig = new BasicGameConfig();
}
public Builder difficulty(int value) {
basicGameConfig.minDifficulty = (basicGameConfig.maxDifficulty = value);
return this;
}
public Builder difficulty(int min, int max) {
basicGameConfig.minDifficulty = min;
basicGameConfig.maxDifficulty = max;
return this;
}
public Builder time(int value) {
basicGameConfig.minTime = (basicGameConfig.maxTime = value);
return this;
}
public Builder time(int min, int max) {
basicGameConfig.minTime = min;
basicGameConfig.maxTime = max;
return this;
}
public BasicGameConfig build() {
return basicGameConfig;
}
}
@Nullable
public GameSettings getGameSetting(Effect effect) {
return new GameSettings(
ThreadLocalRandom.current().nextInt(minTime, maxTime + 1),
(int) Math.min(100, Math.max(1, ThreadLocalRandom.current().nextInt(minDifficulty, maxDifficulty + 1) + effect.getDifficultyModifier()))
);
}
}

View File

@@ -1,28 +0,0 @@
/*
* 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.game;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import org.jetbrains.annotations.Nullable;
public interface GameConfig {
@Nullable
Pair<GameInstance, GameSettings> getRandomGame(Effect effect);
}

View File

@@ -1,78 +0,0 @@
/*
* 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.game;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.util.WeightUtils;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class GameGroup implements GameConfig {
private final List<Pair<String, Double>> gamePairs;
private int minTime;
private int maxTime;
private int minDifficulty;
private int maxDifficulty;
public GameGroup(List<Pair<String, Double>> gamePairs) {
this.gamePairs = gamePairs;
}
public GameGroup difficulty(int value) {
minDifficulty = (maxDifficulty = value);
return this;
}
public GameGroup time(int value) {
minTime = (maxTime = value);
return this;
}
public GameGroup difficulty(int min, int max) {
minDifficulty = min;
maxDifficulty = max;
return this;
}
public GameGroup time(int min, int max) {
minTime = min;
maxTime = max;
return this;
}
@Override
@Nullable
public Pair<GameInstance, GameSettings> getRandomGame(Effect effect) {
String key = WeightUtils.getRandom(gamePairs);
GameInstance gameInstance = CustomFishingPlugin.get().getGameManager().getGame(key);
if (gameInstance == null) {
CustomFishingPlugin.get().getLogger().warning(String.format("Game %s doesn't exist!", key));
return null;
}
GameSettings settings = new GameSettings(
ThreadLocalRandom.current().nextInt(minTime, maxTime + 1),
(int) Math.min(100, Math.max(1, ThreadLocalRandom.current().nextInt(minDifficulty, maxDifficulty + 1) + effect.getDifficultyModifier()))
);
return Pair.of(gameInstance, settings);
}
}

View File

@@ -1,50 +0,0 @@
/*
* 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.game;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.util.WeightUtils;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class GameGroups implements GameConfig {
private final List<Pair<String, Double>> gamesWithWeight;
public GameGroups(List<Pair<String, Double>> gamesWithWeight) {
this.gamesWithWeight = gamesWithWeight;
}
@Override
public @Nullable Pair<GameInstance, GameSettings> getRandomGame(Effect effect) {
String group = WeightUtils.getRandom(gamesWithWeight);
GameConfig gameConfig = CustomFishingPlugin.get().getGameManager().getGameConfig(group);
if (gameConfig == null) {
CustomFishingPlugin.get().getLogger().warning(String.format("Game config %s doesn't exist!", group));
return null;
}
if (!(gameConfig instanceof GameGroup gameGroup)) {
CustomFishingPlugin.get().getLogger().warning(String.format("%s is not a game group!", group));
return null;
}
return gameGroup.getRandomGame(effect);
}
}

View File

@@ -1,10 +1,8 @@
package net.momirealms.customfishing.api.mechanic.loot;
import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.game.GameConfig;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@@ -153,16 +151,6 @@ public class CFLoot implements Loot {
return lootGroup;
}
@Override
public GameConfig getGameConfig() {
return CustomFishingPlugin.get().getGameManager().getGameConfig(this.gameConfig);
}
@Override
public String getGameConfigKey() {
return this.gameConfig;
}
@Override
public Action[] getActions(ActionTrigger actionTrigger) {
return actionMap.get(actionTrigger);

View File

@@ -20,7 +20,6 @@ package net.momirealms.customfishing.api.mechanic.loot;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
import net.momirealms.customfishing.api.mechanic.game.GameConfig;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@@ -74,14 +73,6 @@ public interface Loot {
String[] getLootGroup();
/**
* Get the game config
* @return game config
*/
GameConfig getGameConfig();
String getGameConfigKey();
/**
* get actions triggered by certain events
* @return actions