mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-30 04:19:30 +00:00
2.0.9
This commit is contained in:
@@ -99,4 +99,8 @@ public class PlayerData {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return this == LOCKED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,23 @@ import java.util.Map;
|
||||
|
||||
public class StatisticData {
|
||||
|
||||
@SerializedName("map")
|
||||
public Map<String, Integer> statisticMap;
|
||||
@SerializedName(value="amount", alternate={"map"})
|
||||
public Map<String, Integer> amountMap;
|
||||
|
||||
public StatisticData(@NotNull Map<String, Integer> data) {
|
||||
this.statisticMap = data;
|
||||
@SerializedName("size")
|
||||
public Map<String, Float> sizeMap;
|
||||
|
||||
public StatisticData() {
|
||||
this.sizeMap = new HashMap<>();
|
||||
this.amountMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public StatisticData(@NotNull Map<String, Integer> amount, @NotNull Map<String, Float> size) {
|
||||
this.amountMap = amount;
|
||||
this.sizeMap = size;
|
||||
}
|
||||
|
||||
public static StatisticData empty() {
|
||||
return new StatisticData(new HashMap<>());
|
||||
return new StatisticData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ package net.momirealms.customfishing.api.manager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface MarketManager {
|
||||
|
||||
/**
|
||||
@@ -56,12 +58,9 @@ public interface MarketManager {
|
||||
/**
|
||||
* Calculates the price based on a formula with provided variables.
|
||||
*
|
||||
* @param base The base value for the formula.
|
||||
* @param bonus The bonus value for the formula.
|
||||
* @param size The size value for the formula.
|
||||
* @return The calculated price based on the formula and provided variables.
|
||||
*/
|
||||
double getFishPrice(float base, float bonus, float size);
|
||||
double getFishPrice(Player player, Map<String, String> vars);
|
||||
|
||||
/**
|
||||
* Gets the character representing the item slot in the MarketGUI.
|
||||
|
||||
@@ -28,5 +28,6 @@ public enum ActionTrigger {
|
||||
LAND,
|
||||
ACTIVATE,
|
||||
TIMER,
|
||||
INTERACT
|
||||
INTERACT,
|
||||
NEW_SIZE_RECORD
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ 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.statistic.StatisticsKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -38,6 +39,7 @@ public class CFLoot implements Loot {
|
||||
private double score;
|
||||
private String[] lootGroup;
|
||||
private String filePath;
|
||||
private StatisticsKey statisticsKey;
|
||||
|
||||
public CFLoot(String id, LootType type) {
|
||||
this.id = id;
|
||||
@@ -149,6 +151,17 @@ public class CFLoot implements Loot {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the statistics key for this loot
|
||||
*
|
||||
* @param statisticsKey statistics key
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder statsKey(StatisticsKey statisticsKey) {
|
||||
this.loot.statisticsKey = statisticsKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add actions triggered by a specific trigger.
|
||||
*
|
||||
@@ -245,6 +258,11 @@ public class CFLoot implements Loot {
|
||||
return this.nick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatisticsKey getStatisticKey() {
|
||||
return this.statisticsKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this loot should be shown in the finder.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,7 @@ 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.statistic.StatisticsKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -55,6 +56,8 @@ public interface Loot {
|
||||
@NotNull
|
||||
String getNick();
|
||||
|
||||
StatisticsKey getStatisticKey();
|
||||
|
||||
/**
|
||||
* Check if this loot should be shown in the finder.
|
||||
*
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class Statistics {
|
||||
|
||||
private final ConcurrentHashMap<String, Integer> statisticMap;
|
||||
private final ConcurrentHashMap<String, Float> sizeMap;
|
||||
private int total;
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,8 @@ public class Statistics {
|
||||
* @param statisticData The initial statistic data.
|
||||
*/
|
||||
public Statistics(StatisticData statisticData) {
|
||||
this.statisticMap = new ConcurrentHashMap<>(statisticData.statisticMap);
|
||||
this.statisticMap = new ConcurrentHashMap<>(statisticData.amountMap);
|
||||
this.sizeMap = new ConcurrentHashMap<>(statisticData.sizeMap);
|
||||
this.total = statisticMap.values().stream().mapToInt(Integer::intValue).sum();
|
||||
}
|
||||
|
||||
@@ -52,14 +54,17 @@ public class Statistics {
|
||||
* @param amount The amount of loot to add.
|
||||
*/
|
||||
public synchronized void addLootAmount(Loot loot, Condition condition, int amount) {
|
||||
if (amount < 1) {
|
||||
return;
|
||||
}
|
||||
if (amount == 1) {
|
||||
addSingleLootAmount(loot, condition);
|
||||
return;
|
||||
}
|
||||
Integer previous = statisticMap.get(loot.getID());
|
||||
Integer previous = statisticMap.get(loot.getStatisticKey().getAmountKey());
|
||||
if (previous == null) previous = 0;
|
||||
int after = previous + amount;
|
||||
statisticMap.put(loot.getID(), after);
|
||||
statisticMap.put(loot.getStatisticKey().getAmountKey(), after);
|
||||
total += amount;
|
||||
doSuccessTimesAction(previous, after, condition, loot);
|
||||
}
|
||||
@@ -85,6 +90,13 @@ public class Statistics {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setSizeIfHigher(String loot, float size) {
|
||||
float previous = sizeMap.getOrDefault(loot, 0f);
|
||||
if (previous >= size) return false;
|
||||
sizeMap.put(loot, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single loot amount to the statistics.
|
||||
*
|
||||
@@ -111,8 +123,11 @@ public class Statistics {
|
||||
* @return The amount of the specified loot item.
|
||||
*/
|
||||
public int getLootAmount(String key) {
|
||||
Integer amount = statisticMap.get(key);
|
||||
return amount == null ? 0 : amount;
|
||||
return statisticMap.getOrDefault(key, 0);
|
||||
}
|
||||
|
||||
public float getSizeRecord(String key) {
|
||||
return sizeMap.getOrDefault(key, 0f);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,6 +147,10 @@ public class Statistics {
|
||||
return statisticMap;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, Float> getSizeMap() {
|
||||
return sizeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets data for a specific key in the statistics.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.momirealms.customfishing.api.mechanic.statistic;
|
||||
|
||||
public class StatisticsKey {
|
||||
|
||||
private final String amountKey;
|
||||
private final String sizeKey;
|
||||
|
||||
public StatisticsKey(String amountKey, String sizeKey) {
|
||||
this.amountKey = amountKey;
|
||||
this.sizeKey = sizeKey;
|
||||
}
|
||||
|
||||
public String getAmountKey() {
|
||||
return amountKey;
|
||||
}
|
||||
|
||||
public String getSizeKey() {
|
||||
return sizeKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user