mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-27 10:59:13 +00:00
fix temp fishing state
This commit is contained in:
@@ -46,6 +46,6 @@ public class MMOItemsItemImpl implements ItemLibrary {
|
||||
public String getItemID(ItemStack itemStack) {
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
if (!nbtItem.hasTag("MMOITEMS_ITEM_ID")) return null;
|
||||
return nbtItem.getString("MMOITEMS_ITEM_ID");
|
||||
return nbtItem.getString("MMOITEMS_ITEM_ID").toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,10 +56,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FishingManagerImpl implements Listener, FishingManager {
|
||||
@@ -286,6 +284,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
if (!RequirementManager.isRequirementMet(
|
||||
fishingPreparation, RequirementManagerImpl.mechanicRequirements
|
||||
)) {
|
||||
removeTempFishingState(player);
|
||||
return;
|
||||
}
|
||||
// Merge rod/bait/util effects
|
||||
@@ -387,20 +386,20 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
private void onCaughtFish(PlayerFishEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final UUID uuid = player.getUniqueId();
|
||||
if (!(event.getCaught() instanceof Item item)) return;
|
||||
if (!(event.getCaught() instanceof Item item))
|
||||
return;
|
||||
|
||||
// If player is playing the game
|
||||
GamingPlayer gamingPlayer = gamingPlayerMap.get(uuid);
|
||||
if (gamingPlayer != null) {
|
||||
if (gamingPlayer.onRightClick()) {
|
||||
if (gamingPlayer.onRightClick())
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If player is not playing the game
|
||||
var temp = this.tempFishingStateMap.get(uuid);
|
||||
if (temp != null ) {
|
||||
var temp = this.getTempFishingState(uuid);
|
||||
if (temp != null) {
|
||||
var loot = temp.getLoot();
|
||||
if (loot.getID().equals("vanilla")) {
|
||||
// put vanilla loot in map
|
||||
@@ -421,11 +420,6 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CFConfig.vanillaMechanicIfNoLoot) {
|
||||
event.setCancelled(true);
|
||||
event.getHook().remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -439,13 +433,13 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
|
||||
// If player is already in game
|
||||
// then ignore the event
|
||||
GamingPlayer gamingPlayer = gamingPlayerMap.get(uuid);
|
||||
GamingPlayer gamingPlayer = getGamingPlayer(uuid);
|
||||
if (gamingPlayer != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the loot's game is instant
|
||||
TempFishingState temp = tempFishingStateMap.get(uuid);
|
||||
TempFishingState temp = getTempFishingState(uuid);
|
||||
if (temp != null) {
|
||||
var loot = temp.getLoot();
|
||||
|
||||
@@ -470,7 +464,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
final UUID uuid = player.getUniqueId();
|
||||
|
||||
// If player is in game
|
||||
GamingPlayer gamingPlayer = gamingPlayerMap.get(uuid);
|
||||
GamingPlayer gamingPlayer = getGamingPlayer(uuid);
|
||||
if (gamingPlayer != null) {
|
||||
if (gamingPlayer.onRightClick())
|
||||
event.setCancelled(true);
|
||||
@@ -487,7 +481,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
return;
|
||||
}
|
||||
|
||||
var temp = this.tempFishingStateMap.get(uuid);
|
||||
var temp = getTempFishingState(uuid);
|
||||
if (temp != null ) {
|
||||
Loot loot = temp.getLoot();
|
||||
loot.triggerActions(ActionTrigger.HOOK, temp.getPreparation());
|
||||
@@ -603,7 +597,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
var effect = state.getEffect();
|
||||
var fishingPreparation = state.getPreparation();
|
||||
var player = fishingPreparation.getPlayer();
|
||||
fishingPreparation.insertArg("{size-multiplier}", String.format("%.2f", effect.getSizeMultiplier()));
|
||||
fishingPreparation.insertArg("{size-multiplier}", String.valueOf(effect.getSizeMultiplier()));
|
||||
int amount;
|
||||
if (loot.getType() == LootType.ITEM) {
|
||||
amount = (int) effect.getMultipleLootChance();
|
||||
|
||||
@@ -627,7 +627,7 @@ public class ItemManagerImpl implements ItemManager, Listener {
|
||||
if (bonus != 0) {
|
||||
placeholders.put("{bonus}", String.format("%.2f", bonus));
|
||||
}
|
||||
float size = Float.parseFloat(placeholders.getOrDefault("{size}", "0"));
|
||||
float size = Float.parseFloat(placeholders.getOrDefault("{size}", "0").replace(",", "."));
|
||||
double price = CustomFishingPlugin.get().getMarketManager().getFishPrice(
|
||||
base,
|
||||
bonus,
|
||||
|
||||
@@ -199,9 +199,13 @@ public class LootManagerImpl implements LootManager {
|
||||
@Nullable
|
||||
public Loot getNextLoot(Effect initialEffect, Condition condition) {
|
||||
String key = WeightUtils.getRandom(getPossibleLootKeysWithWeight(initialEffect, condition));
|
||||
if (key == null) {
|
||||
LogUtils.warn("No loot available at " + condition.getLocation() + " for player: " + condition.getPlayer().getName());
|
||||
return null;
|
||||
}
|
||||
Loot loot = getLoot(key);
|
||||
if (loot == null) {
|
||||
LogUtils.warn(String.format("Loot %s doesn't exist.", key));
|
||||
LogUtils.warn(String.format("Loot %s doesn't exist in any of the subfolders[item/entity/block].", key));
|
||||
return null;
|
||||
}
|
||||
return loot;
|
||||
|
||||
@@ -20,6 +20,7 @@ package net.momirealms.customfishing.scheduler;
|
||||
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customfishing.api.scheduler.Scheduler;
|
||||
import net.momirealms.customfishing.api.util.LogUtils;
|
||||
import net.momirealms.customfishing.setting.CFConfig;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -44,16 +45,20 @@ public class SchedulerImpl implements Scheduler {
|
||||
this.schedule = new ScheduledThreadPoolExecutor(1);
|
||||
this.schedule.setMaximumPoolSize(1);
|
||||
this.schedule.setKeepAliveTime(30, TimeUnit.SECONDS);
|
||||
this.schedule.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
this.schedule.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the scheduler configuration based on CustomFishingPlugin settings.
|
||||
*/
|
||||
public void reload() {
|
||||
this.schedule.setCorePoolSize(CFConfig.corePoolSize);
|
||||
this.schedule.setKeepAliveTime(CFConfig.keepAliveTime, TimeUnit.SECONDS);
|
||||
this.schedule.setMaximumPoolSize(CFConfig.maximumPoolSize);
|
||||
try {
|
||||
this.schedule.setCorePoolSize(CFConfig.corePoolSize);
|
||||
this.schedule.setKeepAliveTime(CFConfig.keepAliveTime, TimeUnit.SECONDS);
|
||||
this.schedule.setMaximumPoolSize(CFConfig.maximumPoolSize);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogUtils.warn("Failed to create thread pool. Please lower the corePoolSize in config.yml.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,8 @@ public class CFConfig {
|
||||
|
||||
// config version
|
||||
public static String configVersion = "27";
|
||||
|
||||
// Debug mode
|
||||
public static boolean debug;
|
||||
// language
|
||||
public static String language;
|
||||
|
||||
@@ -73,11 +74,6 @@ public class CFConfig {
|
||||
public static int lavaMinTime;
|
||||
public static int lavaMaxTime;
|
||||
|
||||
// Exception
|
||||
public static boolean vanillaMechanicIfNoLoot;
|
||||
public static Action[] noLootActions;
|
||||
public static boolean debug;
|
||||
|
||||
// Competition
|
||||
public static boolean redisRanking;
|
||||
public static int placeholderLimit;
|
||||
@@ -139,9 +135,6 @@ public class CFConfig {
|
||||
lavaMinTime = config.getInt("mechanics.lava-fishing.min-wait-time", 100);
|
||||
lavaMaxTime = config.getInt("mechanics.lava-fishing.max-wait-time", 600);
|
||||
|
||||
vanillaMechanicIfNoLoot = config.getBoolean("mechanics.vanilla-mechanic-if-no-loot.enable", false);
|
||||
noLootActions = CustomFishingPlugin.get().getActionManager().getActions(config.getConfigurationSection("mechanics.vanilla-mechanic-if-no-loot.actions"));
|
||||
|
||||
redisRanking = config.getBoolean("mechanics.competition.redis-ranking", false);
|
||||
placeholderLimit = config.getInt("mechanics.competition.placeholder-limit", 3);
|
||||
|
||||
|
||||
@@ -112,6 +112,11 @@ public class ConfigUtils {
|
||||
public static Pair<Float, Float> getSizePair(String size) {
|
||||
if (size == null) return null;
|
||||
String[] split = size.split("~", 2);
|
||||
if (split.length != 2) {
|
||||
LogUtils.warn("Illegal size argument: " + size);
|
||||
LogUtils.warn("Correct usage example: 10.5~25.6");
|
||||
return null;
|
||||
}
|
||||
return Pair.of(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
|
||||
}
|
||||
|
||||
|
||||
@@ -117,16 +117,6 @@ mechanics:
|
||||
# Increase this value would allow you to use more placeholders like {4_player} {5_score} in sacrifice of some performance
|
||||
placeholder-limit: 3
|
||||
|
||||
# Enable vanilla fishing mechanic if there's no loot available
|
||||
vanilla-mechanic-if-no-loot:
|
||||
enable: false
|
||||
# actions to trigger if vanilla mechanic not allowed
|
||||
actions:
|
||||
message_action:
|
||||
type: message
|
||||
value:
|
||||
- 'There''s no loot here. Try to find another place for fishing.'
|
||||
|
||||
# Other settings
|
||||
other-settings:
|
||||
# It's recommended to use MiniMessage format. If you insist on using legacy color code "&", enable the support below.
|
||||
|
||||
Reference in New Issue
Block a user