9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-28 19:39:06 +00:00
This commit is contained in:
Xiao-MoMi
2023-03-21 17:15:26 +08:00
parent 1bbe22bb65
commit 06583e3e8f
44 changed files with 502 additions and 358 deletions

View File

@@ -20,7 +20,6 @@ package net.momirealms.customfishing.data;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.action.Action;
import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.manager.LootManager;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

View File

@@ -17,6 +17,7 @@
package net.momirealms.customfishing.fishing;
import net.momirealms.customfishing.fishing.requirements.RequirementInterface;
import net.momirealms.customfishing.manager.ConfigManager;
import java.util.HashMap;
@@ -34,6 +35,7 @@ public class Effect {
private double doubleLootChance;
private boolean canLavaFishing;
private boolean hasSpecialRod;
private RequirementInterface[] requirements;
public void setSizeMultiplier(double sizeMultiplier) {
this.sizeMultiplier = sizeMultiplier;
@@ -91,7 +93,22 @@ public class Effect {
this.canLavaFishing = canLavaFishing;
}
public void addEffect(Effect anotherEffect) {
public RequirementInterface[] getRequirements() {
return requirements;
}
public void setRequirements(RequirementInterface[] requirements) {
this.requirements = requirements;
}
public boolean addEffect(Effect anotherEffect, FishingCondition fishingCondition) {
if (anotherEffect.getRequirements() != null) {
for (RequirementInterface requirement : anotherEffect.getRequirements()) {
if (!requirement.isConditionMet(fishingCondition)) {
return false;
}
}
}
HashMap<String, Integer> weightAS = anotherEffect.getWeightAS();
if (weightAS != null) {
for (Map.Entry<String, Integer> en : weightAS.entrySet()) {
@@ -112,6 +129,7 @@ public class Effect {
if (anotherEffect.getScoreMultiplier() != 0) this.scoreMultiplier += (anotherEffect.getScoreMultiplier() - 1);
if (anotherEffect.getSizeMultiplier() != 0) this.sizeMultiplier += (anotherEffect.getSizeMultiplier() - 1);
if (anotherEffect.canLavaFishing()) this.canLavaFishing = true;
return true;
}
public double getScoreMultiplier() {

View File

@@ -57,8 +57,6 @@ public class ModeOneBar extends FishingBar {
return totalWidth;
}
public String getPointerImage() {
return pointerImage;
}

View File

@@ -24,6 +24,7 @@ import net.momirealms.customfishing.manager.MessageManager;
import net.momirealms.customfishing.manager.OffsetManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Material;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffectType;
@@ -38,6 +39,7 @@ public abstract class FishingGame extends BukkitRunnable {
protected Player player;
protected int difficulty;
protected String title;
protected FishHook fishHook;
public FishingGame(CustomFishing plugin, FishingManager fishingManager, long deadline, Player player, int difficulty, FishingBar fishingBar) {
this.offsetManager = plugin.getOffsetManager();
@@ -46,11 +48,14 @@ public abstract class FishingGame extends BukkitRunnable {
this.deadline = deadline;
this.difficulty = difficulty;
this.title = fishingBar.getRandomTitle();
this.fishHook = fishingManager.getBobber(player);
}
@Override
public void run() {
timeOutCheck();
switchItemCheck();
invalidHookCheck();
}
public void showBar() {
@@ -61,26 +66,30 @@ public abstract class FishingGame extends BukkitRunnable {
return false;
}
protected boolean timeOut() {
protected void timeOutCheck() {
if (System.currentTimeMillis() > deadline) {
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.escape);
cancel();
fishingManager.removeFishingPlayer(player);
fishingManager.removeBobber(player);
fishingManager.fail(player, null, true);
return true;
}
return false;
}
protected boolean switchItem() {
protected void switchItemCheck() {
PlayerInventory playerInventory = player.getInventory();
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD) {
cancel();
fishingManager.removeFishingPlayer(player);
player.removePotionEffect(PotionEffectType.SLOW);
return true;
}
return false;
}
protected void invalidHookCheck() {
if (fishHook == null || !fishHook.isValid()) {
cancel();
fishingManager.removeFishingPlayer(player);
player.removePotionEffect(PotionEffectType.SLOW);
}
}
}

View File

@@ -21,6 +21,7 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.bar.ModeOneBar;
import net.momirealms.customfishing.manager.FishingManager;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
public class ModeOneGame extends FishingGame {
@@ -37,7 +38,7 @@ public class ModeOneGame extends FishingGame {
@Override
public void run() {
if (timeOut() || switchItem()) return;
super.run();
if (face) progress += difficulty;
else progress -= difficulty;
if (progress > modeOneBar.getTotalWidth()) {

View File

@@ -44,7 +44,7 @@ public class ModeThreeGame extends FishingGame {
@Override
public void run() {
if (timeOut() || switchItem()) return;
super.run();
timer++;
if (timer >= timer_max) {
timer = 0;

View File

@@ -48,7 +48,7 @@ public class ModeTwoGame extends FishingGame {
@Override
public void run() {
if (timeOut() || switchItem()) return;
super.run();
if (player.isSneaking()) addV();
else reduceV();
if (timer < 20) {

View File

@@ -19,10 +19,18 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.biomeapi.BiomeAPI;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public record BiomeImpl(List<String> biomes) implements RequirementInterface {
public class BiomeImpl extends Requirement implements RequirementInterface {
private final List<String> biomes;
public BiomeImpl(@Nullable String[] msg, List<String> biomes) {
super(msg);
this.biomes = biomes;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
@@ -32,6 +40,7 @@ public record BiomeImpl(List<String> biomes) implements RequirementInterface {
return true;
}
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -26,12 +26,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
public class CustomPapi implements RequirementInterface {
public class CustomPapi extends Requirement implements RequirementInterface {
public static HashSet<String> allPapi = new HashSet<>();
private PapiRequirement papiRequirement;
public CustomPapi(Map<String, Object> expressions){
public CustomPapi(String[] msg, Map<String, Object> expressions){
super(msg);
expressions.keySet().forEach(key -> {
if (key.startsWith("&&")){
List<PapiRequirement> papiRequirements = new ArrayList<>();

View File

@@ -3,13 +3,25 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.integration.JobInterface;
import org.jetbrains.annotations.Nullable;
public record JobLevelImpl(int level) implements RequirementInterface {
public class JobLevelImpl extends Requirement implements RequirementInterface {
private final int level;
public JobLevelImpl(@Nullable String[] msg, int level) {
super(msg);
this.level = level;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
JobInterface jobInterface = CustomFishing.getInstance().getIntegrationManager().getJobInterface();
if (jobInterface == null) return true;
return jobInterface.getLevel(fishingCondition.getPlayer()) >= level;
if (jobInterface.getLevel(fishingCondition.getPlayer()) >= level) {
return true;
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -18,8 +18,16 @@
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.jetbrains.annotations.Nullable;
public record PermissionImpl(String permission) implements RequirementInterface {
public class PermissionImpl extends Requirement implements RequirementInterface {
private final String permission;
public PermissionImpl(@Nullable String[] msg, String permission) {
super(msg);
this.permission = permission;
}
public String getPermission() {
return this.permission;
@@ -27,6 +35,10 @@ public record PermissionImpl(String permission) implements RequirementInterface
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
return fishingCondition.getPlayer().hasPermission(permission);
if (fishingCondition.getPlayer().hasPermission(permission)) {
return true;
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.fishing.requirements;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public abstract class Requirement {
protected String[] msg;
protected Requirement(@Nullable String[] msg) {
this.msg = msg;
}
public void notMetMessage(Player player) {
if (msg != null) {
for (String str : msg) {
AdventureUtil.playerMessage(player, str);
}
}
}
}

View File

@@ -20,10 +20,18 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.integration.SeasonInterface;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public record SeasonImpl(List<String> seasons) implements RequirementInterface {
public class SeasonImpl extends Requirement implements RequirementInterface {
private final List<String> seasons;
public SeasonImpl(@Nullable String[] msg, List<String> seasons) {
super(msg);
this.seasons = seasons;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
@@ -35,6 +43,7 @@ public record SeasonImpl(List<String> seasons) implements RequirementInterface {
return true;
}
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -3,13 +3,25 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.FishingCondition;
import net.momirealms.customfishing.integration.SkillInterface;
import org.jetbrains.annotations.Nullable;
public record SkillLevelImpl(int level) implements RequirementInterface {
public class SkillLevelImpl extends Requirement implements RequirementInterface {
private final int level;
public SkillLevelImpl(@Nullable String[] msg, int level) {
super(msg);
this.level = level;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
SkillInterface skillInterface = CustomFishing.getInstance().getIntegrationManager().getSkillInterface();
if (skillInterface == null) return true;
return skillInterface.getLevel(fishingCondition.getPlayer()) >= level;
if (skillInterface.getLevel(fishingCondition.getPlayer()) >= level) {
return true;
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -19,10 +19,18 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public record TimeImpl(List<String> times) implements RequirementInterface {
public class TimeImpl extends Requirement implements RequirementInterface {
private final List<String> times;
public TimeImpl(@Nullable String[] msg, List<String> times) {
super(msg);
this.times = times;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
@@ -33,6 +41,7 @@ public record TimeImpl(List<String> times) implements RequirementInterface {
return true;
}
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -19,26 +19,32 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public record WeatherImpl(List<String> weathers) implements RequirementInterface {
public class WeatherImpl extends Requirement implements RequirementInterface {
private final List<String> weathers;
public WeatherImpl(@Nullable String[] msg, List<String> weathers) {
super(msg);
this.weathers = weathers;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
World world = fishingCondition.getLocation().getWorld();
if (world != null) {
String currentWeather;
if (world.isThundering()) currentWeather = "thunder";
else if (world.isClearWeather()) currentWeather = "clear";
else currentWeather = "rain";
for (String weather : weathers) {
if (weather.equalsIgnoreCase(currentWeather)) {
return true;
}
String currentWeather;
if (world.isThundering()) currentWeather = "thunder";
else if (world.isClearWeather()) currentWeather = "clear";
else currentWeather = "rain";
for (String weather : weathers) {
if (weather.equalsIgnoreCase(currentWeather)) {
return true;
}
return false;
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -18,17 +18,27 @@
package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.bukkit.World;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public record WorldImpl(List<String> worlds) implements RequirementInterface {
public class WorldImpl extends Requirement implements RequirementInterface {
private final List<String> worlds;
public WorldImpl(@Nullable String[] msg, List<String> worlds) {
super(msg);
this.worlds = worlds;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
org.bukkit.World world = fishingCondition.getLocation().getWorld();
if (world != null) {
return worlds.contains(world.getName());
World world = fishingCondition.getLocation().getWorld();
if (worlds.contains(world.getName())) {
return true;
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -19,10 +19,18 @@ package net.momirealms.customfishing.fishing.requirements;
import net.momirealms.customfishing.fishing.FishingCondition;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public record YPosImpl(List<String> yPos) implements RequirementInterface {
public class YPosImpl extends Requirement implements RequirementInterface {
private final List<String> yPos;
public YPosImpl(@Nullable String[] msg, List<String> yPos) {
super(msg);
this.yPos = yPos;
}
@Override
public boolean isConditionMet(FishingCondition fishingCondition) {
@@ -33,6 +41,7 @@ public record YPosImpl(List<String> yPos) implements RequirementInterface {
return true;
}
}
notMetMessage(fishingCondition.getPlayer());
return false;
}
}

View File

@@ -32,7 +32,7 @@ import java.util.Set;
public class ActivatedTotem extends BukkitRunnable {
public static int id = 127616121;
public static int id = 121616121;
private int timer;
private final TotemConfig totem;
private final Location bottomLoc;
@@ -43,8 +43,9 @@ public class ActivatedTotem extends BukkitRunnable {
private final BukkitRunnable particleTimerTask;
private final FishingManager fishingManager;
private final int direction;
private final String activator;
public ActivatedTotem(Location coreLoc, TotemConfig totem, FishingManager fishingManager, int direction) {
public ActivatedTotem(Location coreLoc, TotemConfig totem, FishingManager fishingManager, int direction, String activator) {
this.fishingManager = fishingManager;
this.totem = totem;
this.coreLoc = coreLoc;
@@ -58,6 +59,7 @@ public class ActivatedTotem extends BukkitRunnable {
this.particleTimerTask = new TotemParticle(bottomLoc, totem.getRadius(), totem.getParticle());
this.particleTimerTask.runTaskTimerAsynchronously(CustomFishing.getInstance(), 0, 4);
this.direction = direction;
this.activator = activator;
}
@Override
@@ -77,8 +79,10 @@ public class ActivatedTotem extends BukkitRunnable {
if (hasHolo) {
for (int i = 0; i < entityID.length; i++) {
CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getMetaPacket(entityID[i],
totem.getHoloText()[entityID.length - 1 - i].replace("{time}", String.valueOf(totem.getDuration() - timer))
totem.getHoloText()[entityID.length - 1 - i]
.replace("{time}", String.valueOf(totem.getDuration() - timer))
.replace("{max_time}", String.valueOf(totem.getDuration()))
.replace("{player}", activator)
));
}
addPotionEffect(player);
@@ -99,8 +103,10 @@ public class ActivatedTotem extends BukkitRunnable {
for (int i = 0; i < entityID.length; i++) {
CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtil.getSpawnPacket(entityID[i], bottomLoc.clone().add(0.5, totem.getHoloOffset() + i * 0.4, 0.5)));
CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtil.getMetaPacket(entityID[i],
totem.getHoloText()[entityID.length - 1 - i].replace("{time}", String.valueOf(totem.getDuration() - timer))
.replace("{max_time}", String.valueOf(totem.getDuration()))
totem.getHoloText()[entityID.length - 1 - i]
.replace("{time}", String.valueOf(totem.getDuration() - timer))
.replace("{max_time}", String.valueOf(totem.getDuration()))
.replace("{player}", activator)
));
}
addPotionEffect(newComer);

View File

@@ -1,126 +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.fishing.totem;
import net.momirealms.customfishing.fishing.Effect;
import net.momirealms.customfishing.fishing.action.Action;
import net.momirealms.customfishing.fishing.requirements.RequirementInterface;
import org.bukkit.Particle;
import org.bukkit.potion.PotionEffect;
public class Totem {
private final OriginalModel originalModel;
private FinalModel finalModel;
private RequirementInterface[] requirements;
private final int radius;
private final Particle particle;
private final int duration;
private final Effect effect;
private Action[] activatorActions;
private Action[] nearbyActions;
private double holoOffset;
private String[] holoText;
private PotionEffect[] potionEffects;
public Totem(OriginalModel originalModel, FinalModel finalModel, int radius, int duration, Particle particle, Effect effect) {
this.originalModel = originalModel;
this.finalModel = finalModel;
this.radius = radius;
this.duration = duration;
this.particle = particle;
this.effect = effect;
}
public RequirementInterface[] getRequirements() {
return requirements;
}
public void setRequirements(RequirementInterface[] requirements) {
this.requirements = requirements;
}
public OriginalModel getOriginalModel() {
return originalModel;
}
public FinalModel getFinalModel() {
return finalModel;
}
public void setFinalModel(FinalModel finalModel) {
this.finalModel = finalModel;
}
public int getRadius() {
return radius;
}
public Particle getParticle() {
return particle;
}
public int getDuration() {
return duration;
}
public Effect getBonus() {
return effect;
}
public Action[] getActivatorActions() {
return activatorActions;
}
public void setActivatorActions(Action[] activatorActions) {
this.activatorActions = activatorActions;
}
public Action[] getNearbyActions() {
return nearbyActions;
}
public void setNearbyActions(Action[] nearbyActions) {
this.nearbyActions = nearbyActions;
}
public double getHoloOffset() {
return holoOffset;
}
public void setHoloOffset(double holoOffset) {
this.holoOffset = holoOffset;
}
public String[] getHoloText() {
return holoText;
}
public void setHoloText(String[] holoText) {
this.holoText = holoText;
}
public PotionEffect[] getPotionEffects() {
return potionEffects;
}
public void setPotionEffects(PotionEffect[] potionEffects) {
this.potionEffects = potionEffects;
}
}

View File

@@ -59,7 +59,6 @@ public class TotemConfig {
return originalModel;
}
public FinalModel getFinalModel() {
return finalModel;
}

View File

@@ -43,8 +43,7 @@ public class CustomFishingItemImpl implements ItemInterface {
@Override
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
Damageable damageable = (Damageable) itemStack.getItemMeta();
Enchantment enchantment = Enchantment.DURABILITY;
if (Math.random() < (1 / (double) (damageable.getEnchantLevel(enchantment) + 1))){
if (Math.random() < (1 / (double) (damageable.getEnchantLevel(Enchantment.DURABILITY) + 1))) {
damageable.setDamage(damageable.getDamage() + 1);
itemStack.setItemMeta(damageable);
}

View File

@@ -24,7 +24,6 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.loot.Item;
import net.momirealms.customfishing.util.ItemStackUtil;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import java.util.Map;

View File

@@ -19,6 +19,7 @@ package net.momirealms.customfishing.integration.item;
import dev.lone.itemsadder.api.CustomStack;
import net.momirealms.customfishing.integration.ItemInterface;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -39,7 +40,9 @@ public class ItemsAdderItemImpl implements ItemInterface {
CustomStack customStack = CustomStack.byItemStack(itemStack);
if (customStack == null) return false;
if (customStack.hasCustomDurability()) {
customStack.setDurability(customStack.getDurability() - 1);
if (Math.random() < (1 / (double) (itemStack.getEnchantmentLevel(Enchantment.DURABILITY) + 1))) {
customStack.setDurability(customStack.getDurability() - 1);
}
return true;
}
return false;

View File

@@ -23,6 +23,7 @@ import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.momirealms.customfishing.integration.ItemInterface;
import org.apache.commons.lang.StringUtils;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -42,10 +43,12 @@ public class MMOItemsItemImpl implements ItemInterface {
@Override
public boolean loseCustomDurability(ItemStack itemStack, Player player) {
DurabilityItem durabilityItem = new DurabilityItem(player, itemStack);
durabilityItem.decreaseDurability(1);
final ItemStack newVersion = durabilityItem.toItem();
if (newVersion == null) return false;
itemStack.setItemMeta(newVersion.getItemMeta());
if (Math.random() < (1 / (double) (itemStack.getEnchantmentLevel(Enchantment.DURABILITY) + 1))) {
durabilityItem.decreaseDurability(1);
final ItemStack newVersion = durabilityItem.toItem();
if (newVersion == null) return false;
itemStack.setItemMeta(newVersion.getItemMeta());
}
return true;
}
}

View File

@@ -49,7 +49,7 @@ public class McMMOTreasure {
FishingTreasure treasure = getFishingTreasure(player, fishingManager.getLootTier());
ItemStack treasureDrop;
if (treasure != null) {
if(treasure instanceof FishingTreasureBook) {
if (treasure instanceof FishingTreasureBook) {
treasureDrop = ItemUtils.createEnchantBook((FishingTreasureBook) treasure);
} else {
treasureDrop = treasure.getDrop().clone();

View File

@@ -18,7 +18,6 @@
package net.momirealms.customfishing.integration.item;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.core.items.ItemExecutor;
import net.momirealms.customfishing.integration.ItemInterface;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@@ -17,13 +17,12 @@
package net.momirealms.customfishing.integration.item;
import io.th0rgal.oraxen.OraxenPlugin;
import io.th0rgal.oraxen.api.OraxenFurniture;
import io.th0rgal.oraxen.api.OraxenItems;
import io.th0rgal.oraxen.items.ItemBuilder;
import io.th0rgal.oraxen.mechanics.provided.gameplay.durability.DurabilityMechanic;
import io.th0rgal.oraxen.mechanics.provided.gameplay.durability.DurabilityMechanicFactory;
import net.momirealms.customfishing.integration.ItemInterface;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
@@ -45,7 +44,9 @@ public class OraxenItemImpl implements ItemInterface {
if (mechanic == null) {
return false;
}
mechanic.changeDurability(itemStack, -1);
if (Math.random() < (1 / (double) (itemStack.getEnchantmentLevel(Enchantment.DURABILITY) + 1))) {
mechanic.changeDurability(itemStack, -1);
}
return true;
}
}

View File

@@ -17,7 +17,6 @@
package net.momirealms.customfishing.integration.job;
import com.willfp.ecojobs.EcoJobsPlugin;
import com.willfp.ecojobs.api.EcoJobsAPI;
import com.willfp.ecojobs.jobs.Job;
import com.willfp.ecojobs.jobs.Jobs;

View File

@@ -19,7 +19,6 @@ package net.momirealms.customfishing.integration.mob;
import io.lumine.mythic.api.adapters.AbstractLocation;
import io.lumine.mythic.api.adapters.AbstractVector;
import io.lumine.mythic.api.mobs.MobManager;
import io.lumine.mythic.api.mobs.MythicMob;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.bukkit.utils.serialize.Position;

View File

@@ -102,7 +102,7 @@ public class BagDataManager extends DataFunction {
Inventory inventory = plugin.getDataManager().getDataStorageInterface().loadBagData(ownerOffline.getUniqueId(), force);
if (inventory == null) {
AdventureUtil.playerMessage(viewer, "<red>[CustomFishing] Failed to load bag data for player " + ownerOffline.getName());
AdventureUtil.playerMessage(viewer, "<red>This might be caused when the target player is online but on another server");
AdventureUtil.playerMessage(viewer, "<red>This might be caused by the target player is online but on another server");
AdventureUtil.playerMessage(viewer, "<red>Use /fishingbag open [Player] --force to ignore this warning");
return;
}

View File

@@ -22,10 +22,9 @@ import net.momirealms.customfishing.fishing.Effect;
import net.momirealms.customfishing.fishing.loot.Item;
import net.momirealms.customfishing.object.Function;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ItemStackUtil;
import net.momirealms.customfishing.util.ConfigUtil;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -96,9 +95,11 @@ public class EffectManager extends Function {
Item item = new Item(utilSection, key);
item.setCfTag(new String[] {"util", key});
utilItems.put(key, item);
if (utilSection.contains("effect")) {
utilEffects.put(key, getEffect(utilSection.getConfigurationSection("effect")));
Effect effect = ConfigUtil.getEffect(utilSection.getConfigurationSection("effect"));
if (utilSection.contains("requirements")) {
effect.setRequirements(ConfigUtil.getRequirements(utilSection.getConfigurationSection("requirements")));
}
utilEffects.put(key, effect);
}
}
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + utilItems.size() + " <gray>util(s)");
@@ -120,7 +121,11 @@ public class EffectManager extends Function {
ConfigurationSection levelSection = config.getConfigurationSection(key);
if (levelSection == null) continue;
for (String level : levelSection.getKeys(false)) {
enchantEffects.put((key.startsWith("eco") ? "minecraft" + key.substring(3) : key) + ":" + level, getEffect(levelSection.getConfigurationSection(key)));
Effect effect = ConfigUtil.getEffect(levelSection.getConfigurationSection(level + ".effect"));
if (levelSection.contains(level + ".requirements")) {
effect.setRequirements(ConfigUtil.getRequirements(levelSection.getConfigurationSection(level + ".requirements")));
}
enchantEffects.put((key.startsWith("eco") ? "minecraft" + key.substring(3) : key) + ":" + level, effect);
}
amount++;
}
@@ -146,9 +151,11 @@ public class EffectManager extends Function {
Item item = new Item(baitSection, key);
item.setCfTag(new String[] {"bait", key});
baitItems.put(key, item);
if (baitSection.contains("effect")) {
baitEffects.put(key, getEffect(baitSection.getConfigurationSection("effect")));
Effect effect = ConfigUtil.getEffect(baitSection.getConfigurationSection("effect"));
if (baitSection.contains("requirements")) {
effect.setRequirements(ConfigUtil.getRequirements(baitSection.getConfigurationSection("requirements")));
}
baitEffects.put(key, effect);
}
}
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + baitItems.size() + " <gray>bait(s)");
@@ -173,40 +180,16 @@ public class EffectManager extends Function {
Item item = new Item(rodSection, key);
item.setCfTag(new String[] {"rod", key});
rodItems.put(key, item);
if (rodSection.contains("effect")) {
rodEffects.put(key, getEffect(rodSection.getConfigurationSection("effect")));
Effect effect = ConfigUtil.getEffect(rodSection.getConfigurationSection("effect"));
if (rodSection.contains("requirements")) {
effect.setRequirements(ConfigUtil.getRequirementsWithMsg(rodSection.getConfigurationSection("requirements")));
}
rodEffects.put(key, effect);
}
}
AdventureUtil.consoleMessage("[CustomFishing] Loaded <green>" + rodItems.size() + " <gray>rod(s)");
}
public static Effect getEffect(ConfigurationSection section) {
Effect effect = new Effect();
if (section == null) return effect;
for (String modifier : section.getKeys(false)) {
switch (modifier) {
case "weight-add" -> {
HashMap<String, Integer> as = new HashMap<>();
Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> as.put(group, (Integer) value));
effect.setWeightAS(as);
}
case "weight-multiply" -> {
HashMap<String, Double> md = new HashMap<>();
Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> md.put(group, Double.parseDouble(String.valueOf(value))-1));
effect.setWeightMD(md);
}
case "time" -> effect.setTimeModifier(section.getDouble(modifier));
case "difficulty" -> effect.setDifficulty(section.getInt(modifier));
case "double-loot" -> effect.setDoubleLootChance(section.getDouble(modifier));
case "score" -> effect.setScoreMultiplier(section.getDouble(modifier));
case "size-multiply" -> effect.setSizeMultiplier(section.getDouble(modifier));
case "lava-fishing" -> effect.setCanLavaFishing(section.getBoolean(modifier, false));
}
}
return effect;
}
@Nullable
public Item getBaitItem(String key) {
return baitItems.get(key);

View File

@@ -155,18 +155,15 @@ public class FishingManager extends Function {
}
public void onFishing(PlayerFishEvent event) {
final Player player = event.getPlayer();
final FishHook fishHook = event.getHook();
hooks.put(player, fishHook);
if (isCoolDown(player, 500)) return;
PlayerInventory inventory = player.getInventory();
boolean noSpecialRod = true;
boolean noRod = true;
boolean noBait = true;
boolean baitOnMainHand = false;
int lureLevel = 0;
ItemStack baitItem = null;
@@ -179,12 +176,14 @@ public class FishingManager extends Function {
initialEffect.setWeightMD(new HashMap<>());
initialEffect.setWeightAS(new HashMap<>());
FishingCondition fishingCondition = new FishingCondition(player.getLocation(), player);
ItemStack mainHandItem = inventory.getItemInMainHand();
Material mainHandItemType = mainHandItem.getType();
if (mainHandItemType != Material.AIR) {
if (mainHandItemType == Material.FISHING_ROD) {
noRod = false;
addEnchantEffect(initialEffect, mainHandItem);
addEnchantEffect(initialEffect, mainHandItem, fishingCondition);
lureLevel = mainHandItem.getEnchantmentLevel(Enchantment.LURE);
}
NBTItem mainHandNBTItem = new NBTItem(mainHandItem);
@@ -195,16 +194,18 @@ public class FishingManager extends Function {
if (type.equals("rod")) {
Effect rodEffect = plugin.getEffectManager().getRodEffect(id);
if (rodEffect != null){
initialEffect.addEffect(rodEffect);
if (!initialEffect.addEffect(rodEffect, fishingCondition)) {
event.setCancelled(true);
return;
}
noSpecialRod = false;
}
}
else if (type.equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(id);
if (baitEffect != null) {
initialEffect.addEffect(baitEffect);
if (baitEffect != null && initialEffect.addEffect(baitEffect, fishingCondition)) {
baitItem = mainHandItem.clone();
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
baitOnMainHand = true;
noBait = false;
}
}
@@ -215,7 +216,7 @@ public class FishingManager extends Function {
Material offHandItemType = offHandItem.getType();
if (offHandItemType != Material.AIR){
if (noRod && offHandItemType == Material.FISHING_ROD) {
addEnchantEffect(initialEffect, offHandItem);
addEnchantEffect(initialEffect, offHandItem, fishingCondition);
lureLevel = offHandItem.getEnchantmentLevel(Enchantment.LURE);
}
NBTItem offHandNBTItem = new NBTItem(offHandItem);
@@ -225,26 +226,33 @@ public class FishingManager extends Function {
String id = nbtCompound.getString("id");
if (noBait && type.equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(id);
if (baitEffect != null){
initialEffect.addEffect(baitEffect);
if (baitEffect != null && initialEffect.addEffect(baitEffect, fishingCondition)) {
baitItem = offHandItem.clone();
offHandItem.setAmount(offHandItem.getAmount() - 1);
noBait = false;
}
}
else if (noSpecialRod && type.equals("rod")) {
Effect rodEffect = plugin.getEffectManager().getRodEffect(id);
if (rodEffect != null) {
initialEffect.addEffect(rodEffect);
if (!initialEffect.addEffect(rodEffect, fishingCondition)) {
event.setCancelled(true);
return;
}
noSpecialRod = false;
}
}
}
}
// To prevent bait is consumed if the player can't use the rod
if (!noBait) {
if (baitOnMainHand) mainHandItem.setAmount(mainHandItem.getAmount() - 1);
else offHandItem.setAmount(offHandItem.getAmount() - 1);
}
for (ActivatedTotem activatedTotem : activeTotemMap.values()) {
if (activatedTotem.getNearbyPlayerSet().contains(player)) {
initialEffect.addEffect(activatedTotem.getTotem().getBonus());
initialEffect.addEffect(activatedTotem.getTotem().getBonus(), fishingCondition);
break;
}
}
@@ -263,9 +271,8 @@ public class FishingManager extends Function {
String id = cfCompound.getString("id");
if (noBait && type.equals("bait")) {
Effect baitEffect = plugin.getEffectManager().getBaitEffect(id);
if (baitEffect != null && itemStack.getAmount() > 0) {
if (baitEffect != null && itemStack.getAmount() > 0 && initialEffect.addEffect(baitEffect, fishingCondition)) {
noBait = false;
initialEffect.addEffect(baitEffect);
baitItem = itemStack.clone();
itemStack.setAmount(itemStack.getAmount() - 1);
}
@@ -273,7 +280,7 @@ public class FishingManager extends Function {
else if (type.equals("util")) {
Effect utilEffect = plugin.getEffectManager().getUtilEffect(id);
if (utilEffect != null && !uniqueUtils.contains(id)) {
initialEffect.addEffect(utilEffect);
initialEffect.addEffect(utilEffect, fishingCondition);
uniqueUtils.add(id);
}
}
@@ -281,6 +288,7 @@ public class FishingManager extends Function {
}
}
initialEffect.setHasSpecialRod(!noSpecialRod);
RodCastEvent rodCastEvent = new RodCastEvent(player, initialEffect);
Bukkit.getPluginManager().callEvent(rodCastEvent);
if (rodCastEvent.isCancelled()) {
@@ -292,14 +300,11 @@ public class FishingManager extends Function {
fishHook.setMinWaitTime((int) (fishHook.getMinWaitTime() * initialEffect.getTimeModifier()));
nextEffect.put(player, initialEffect);
if (ConfigManager.needRodToFish && noSpecialRod) {
if (ConfigManager.needRodToFish && !initialEffect.hasSpecialRod()) {
nextLoot.put(player, Loot.EMPTY);
return;
}
initialEffect.setHasSpecialRod(!noSpecialRod);
int entityID = 0;
if (baitItem != null) {
baitItem.setAmount(1);
@@ -574,8 +579,9 @@ public class FishingManager extends Function {
Competition.currentCompetition.tryAddBossBarToPlayer(player);
}
for (Action action : droppedItem.getSuccessActions())
action.doOn(player, null);
if (droppedItem.getSuccessActions() != null)
for (Action action : droppedItem.getSuccessActions())
action.doOn(player, null);
dropItem(player, location, fishResultEvent.isDouble(), drop);
addStats(player.getUniqueId(), droppedItem, isDouble ? 2 : 1);
@@ -643,10 +649,9 @@ public class FishingManager extends Function {
Loot vanilla = plugin.getLootManager().getVanilla_loot();
addStats(player.getUniqueId(), vanilla, isDouble ? 2 : 1);
if (vanilla.getSuccessActions() != null) {
if (vanilla.getSuccessActions() != null)
for (Action action : vanilla.getSuccessActions())
action.doOn(player, null);
}
AdventureUtil.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1);
dropItem(player, location, isDouble, itemStack);
@@ -686,8 +691,9 @@ public class FishingManager extends Function {
Competition.currentCompetition.tryAddBossBarToPlayer(player);
}
for (Action action : loot.getSuccessActions())
action.doOn(player, null);
if (loot.getSuccessActions() != null)
for (Action action : loot.getSuccessActions())
action.doOn(player, null);
mobInterface.summon(player.getLocation(), location, mob);
addStats(player.getUniqueId(), mob, 1);
@@ -823,11 +829,11 @@ public class FishingManager extends Function {
return coolDown.computeIfAbsent(player, k -> time - delay) + delay > time;
}
private void addEnchantEffect(Effect initialEffect, ItemStack itemStack) {
private void addEnchantEffect(Effect initialEffect, ItemStack itemStack, FishingCondition fishingCondition) {
for (String key : plugin.getIntegrationManager().getEnchantmentInterface().getEnchants(itemStack)) {
Effect enchantEffect = plugin.getEffectManager().getEnchantEffect(key);
if (enchantEffect != null) {
initialEffect.addEffect(enchantEffect);
initialEffect.addEffect(enchantEffect, fishingCondition);
}
}
}
@@ -878,11 +884,12 @@ public class FishingManager extends Function {
if (totemList == null || !totemList.contains(totem)) return;
FishingCondition fishingCondition = new FishingCondition(block.getLocation(), player);
for (RequirementInterface requirement : totem.getRequirements()) {
if (!requirement.isConditionMet(fishingCondition)) {
return;
if (totem.getRequirements() != null)
for (RequirementInterface requirement : totem.getRequirements()) {
if (!requirement.isConditionMet(fishingCondition)) {
return;
}
}
}
Location coreLoc = block.getLocation();
int direction = plugin.getTotemManager().checkLocationModel(totem.getOriginalModel(), coreLoc);
@@ -900,17 +907,18 @@ public class FishingManager extends Function {
plugin.getTotemManager().removeModel(totem.getFinalModel(), coreLoc, direction);
if (player.getGameMode() != GameMode.CREATIVE) itemStack.setAmount(itemStack.getAmount() - 1);
for (Action action : totem.getActivatorActions()) {
action.doOn(player, null);
}
for (Action action : totem.getNearbyActions()) {
for (Player nearby : coreLoc.getNearbyPlayers(totem.getRadius())) {
action.doOn(nearby, player);
if (totem.getActivatorActions() != null)
for (Action action : totem.getActivatorActions()) {
action.doOn(player, null);
}
if (totem.getNearbyActions() != null)
for (Action action : totem.getNearbyActions()) {
for (Player nearby : coreLoc.getNearbyPlayers(totem.getRadius())) {
action.doOn(nearby, player);
}
}
}
ActivatedTotem activatedTotem = new ActivatedTotem(coreLoc, totem, this, direction);
ActivatedTotem activatedTotem = new ActivatedTotem(coreLoc, totem, this, direction, player.getName());
activatedTotem.runTaskTimer(plugin, 10, 20);
activeTotemMap.put(LocationUtils.getSimpleLocation(coreLoc), activatedTotem);
}
@@ -959,8 +967,10 @@ public class FishingManager extends Function {
fishingGame.runTaskTimer(plugin, 0, 1);
fishingPlayerMap.put(player, fishingGame);
}
for (Action action : loot.getHookActions()) {
action.doOn(player, null);
if (loot.getHookActions() != null) {
for (Action action : loot.getHookActions()) {
action.doOn(player, null);
}
}
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, game.getTime() * 20,3));
}

View File

@@ -25,6 +25,7 @@ import net.momirealms.customfishing.fishing.requirements.*;
import net.momirealms.customfishing.object.Function;
import net.momirealms.customfishing.object.LeveledEnchantment;
import net.momirealms.customfishing.util.AdventureUtil;
import net.momirealms.customfishing.util.ConfigUtil;
import net.momirealms.customfishing.util.ItemStackUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
@@ -254,10 +255,10 @@ public class LootManager extends Function {
}
private void setActions(ConfigurationSection section, Loot loot) {
loot.setSuccessActions(getActions(section.getConfigurationSection("action.success"), loot.getNick()));
loot.setFailureActions(getActions(section.getConfigurationSection("action.failure"), loot.getNick()));
loot.setHookActions(getActions(section.getConfigurationSection("action.hook"), loot.getNick()));
loot.setConsumeActions(getActions(section.getConfigurationSection("action.consume"), loot.getNick()));
loot.setSuccessActions(ConfigUtil.getActions(section.getConfigurationSection("action.success"), loot.getNick()));
loot.setFailureActions(ConfigUtil.getActions(section.getConfigurationSection("action.failure"), loot.getNick()));
loot.setHookActions(ConfigUtil.getActions(section.getConfigurationSection("action.hook"), loot.getNick()));
loot.setConsumeActions(ConfigUtil.getActions(section.getConfigurationSection("action.consume"), loot.getNick()));
setSuccessAmountAction(section.getConfigurationSection("action.success-times"), loot);
}
@@ -265,72 +266,17 @@ public class LootManager extends Function {
if (section != null) {
HashMap<Integer, Action[]> actionMap = new HashMap<>();
for (String amount : section.getKeys(false)) {
actionMap.put(Integer.parseInt(amount), getActions(section.getConfigurationSection(amount), loot.getNick()));
actionMap.put(Integer.parseInt(amount), ConfigUtil.getActions(section.getConfigurationSection(amount), loot.getNick()));
}
loot.setSuccessTimesActions(actionMap);
}
}
private void setRequirements(ConfigurationSection section, Loot loot) {
loot.setRequirements(getRequirements(section));
loot.setRequirements(ConfigUtil.getRequirements(section));
}
public Action[] getActions(ConfigurationSection section, String nick) {
List<Action> actions = new ArrayList<>();
if (section != null) {
for (String action : section.getKeys(false)) {
switch (action) {
case "message" -> actions.add(new MessageActionImpl(section.getStringList(action).toArray(new String[0]), nick));
case "command" -> actions.add(new CommandActionImpl(section.getStringList(action).toArray(new String[0]), nick));
case "exp" -> actions.add(new VanillaXPImpl(section.getInt(action), false));
case "mending" -> actions.add(new VanillaXPImpl(section.getInt(action), true));
case "skill-xp" -> actions.add(new SkillXPImpl(section.getDouble(action)));
case "job-xp" -> actions.add(new JobXPImpl(section.getDouble(action)));
case "sound" -> actions.add(new SoundActionImpl(
section.getString(action + ".source"),
section.getString(action + ".key"),
(float) section.getDouble(action + ".volume"),
(float) section.getDouble(action + ".pitch")
));
case "potion-effect" -> {
List<PotionEffect> potionEffectList = new ArrayList<>();
for (String key : section.getConfigurationSection(action).getKeys(false)) {
PotionEffectType type = PotionEffectType.getByName(section.getString(action + "." + key + ".type", "BLINDNESS").toUpperCase());
if (type == null) AdventureUtil.consoleMessage("<red>[CustomFishing] Potion effect " + section.getString(action + "." + key + ".type", "BLINDNESS") + " doesn't exists");
potionEffectList.add(new PotionEffect(
type == null ? PotionEffectType.LUCK : type,
section.getInt(action + "." + key + ".duration"),
section.getInt(action + "." + key + ".amplifier")
));
}
actions.add(new PotionEffectImpl(potionEffectList.toArray(new PotionEffect[0])));
}
}
}
}
return actions.toArray(new Action[0]);
}
public RequirementInterface[] getRequirements(ConfigurationSection section) {
List<RequirementInterface> requirements = new ArrayList<>();
if (section != null) {
for (String type : section.getKeys(false)) {
switch (type) {
case "biome" -> requirements.add(new BiomeImpl(section.getStringList(type)));
case "weather" -> requirements.add(new WeatherImpl(section.getStringList(type)));
case "ypos" -> requirements.add(new YPosImpl(section.getStringList(type)));
case "season" -> requirements.add(new SeasonImpl(section.getStringList(type)));
case "world" -> requirements.add(new WorldImpl(section.getStringList(type)));
case "permission" -> requirements.add(new PermissionImpl(section.getString(type)));
case "time" -> requirements.add(new TimeImpl(section.getStringList(type)));
case "skill-level" -> requirements.add(new SkillLevelImpl(section.getInt(type)));
case "job-level" -> requirements.add(new JobLevelImpl(section.getInt(type)));
case "papi-condition" -> requirements.add(new CustomPapi(Objects.requireNonNull(section.getConfigurationSection(type)).getValues(false)));
}
}
}
return requirements.toArray(new RequirementInterface[0]);
}
private MiniGameConfig[] getMiniGames(ConfigurationSection section) {
String[] games = section.getStringList("mini-game").size() == 0 ? new String[]{section.getString("mini-game", null)} : section.getStringList("mini-game").toArray(new String[0]);

View File

@@ -180,7 +180,7 @@ public class TotemManager extends Function {
config.getInt(key + ".radius", 16),
config.getInt(key + ".duration", 300),
Particle.valueOf(config.getString(key + ".particle", "SPELL_MOB").toUpperCase()),
EffectManager.getEffect(config.getConfigurationSection(key + ".effect"))
ConfigUtil.getEffect(config.getConfigurationSection(key + ".effect"))
);
List<Action> actionList = new ArrayList<>();
@@ -198,7 +198,7 @@ public class TotemManager extends Function {
totem.setActivatorActions(actionList.toArray(new Action[0]));
totem.setNearbyActions(nearActionList.toArray(new Action[0]));
totem.setRequirements(plugin.getLootManager().getRequirements(config.getConfigurationSection(key + ".requirements")));
totem.setRequirements(ConfigUtil.getRequirementsWithMsg(config.getConfigurationSection(key + ".requirements")));
if (config.getBoolean(key + ".hologram.enable", false)) {
totem.setHoloText(config.getStringList(key + ".hologram.text").toArray(new String[0]));

View File

@@ -42,6 +42,7 @@ public class AdventureUtil {
* @param s message
*/
public static void sendMessage(CommandSender sender, String s) {
if (s == null) return;
if (sender instanceof Player player) playerMessage(player, s);
else consoleMessage(s);
}
@@ -51,6 +52,7 @@ public class AdventureUtil {
* @param s message
*/
public static void consoleMessage(String s) {
if (s == null) return;
Audience au = CustomFishing.getAdventure().sender(Bukkit.getConsoleSender());
MiniMessage mm = MiniMessage.miniMessage();
Component parsed = mm.deserialize(replaceLegacy(s));
@@ -63,6 +65,7 @@ public class AdventureUtil {
* @param s message
*/
public static void playerMessage(Player player, String s) {
if (s == null) return;
Audience au = CustomFishing.getAdventure().player(player);
MiniMessage mm = MiniMessage.miniMessage();
Component parsed = mm.deserialize(replaceLegacy(s));
@@ -134,7 +137,7 @@ public class AdventureUtil {
*/
public static String replaceLegacy(String s) {
StringBuilder stringBuilder = new StringBuilder();
char[] chars = s.replaceAll("&","§").toCharArray();
char[] chars = s.replace("&","§").toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '§') {
if (i + 1 < chars.length) {

View File

@@ -24,11 +24,20 @@ import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.Effect;
import net.momirealms.customfishing.fishing.action.*;
import net.momirealms.customfishing.fishing.requirements.*;
import net.momirealms.customfishing.helper.Log;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
public class ConfigUtil {
@@ -73,4 +82,116 @@ public class ConfigUtil {
}
return YamlConfiguration.loadConfiguration(file);
}
public static RequirementInterface[] getRequirements(ConfigurationSection section) {
if (section != null) {
List<RequirementInterface> requirements = new ArrayList<>();
for (String type : section.getKeys(false)) {
switch (type) {
case "biome" -> requirements.add(new BiomeImpl(null, section.getStringList(type)));
case "weather" -> requirements.add(new WeatherImpl(null, section.getStringList(type)));
case "ypos" -> requirements.add(new YPosImpl(null, section.getStringList(type)));
case "season" -> requirements.add(new SeasonImpl(null, section.getStringList(type)));
case "world" -> requirements.add(new WorldImpl(null, section.getStringList(type)));
case "permission" -> requirements.add(new PermissionImpl(null, section.getString(type)));
case "time" -> requirements.add(new TimeImpl(null, section.getStringList(type)));
case "skill-level" -> requirements.add(new SkillLevelImpl(null, section.getInt(type)));
case "job-level" -> requirements.add(new JobLevelImpl(null, section.getInt(type)));
case "papi-condition" -> requirements.add(new CustomPapi(null, Objects.requireNonNull(section.getConfigurationSection(type)).getValues(false)));
}
}
return requirements.toArray(new RequirementInterface[0]);
}
return null;
}
public static RequirementInterface[] getRequirementsWithMsg(ConfigurationSection section) {
if (section != null) {
List<RequirementInterface> requirements = new ArrayList<>();
for (String id : section.getKeys(false)) {
ConfigurationSection innerSec = section.getConfigurationSection(id);
if (innerSec == null) continue;
String type = innerSec.getString("type");
if (type == null) continue;
String[] msg = innerSec.getStringList("message").size() == 0 ? (innerSec.getString("message") == null ? null : new String[]{innerSec.getString("message")}) : innerSec.getStringList("message").toArray(new String[0]);
switch (type) {
case "biome" -> requirements.add(new BiomeImpl(msg, innerSec.getStringList("value")));
case "weather" -> requirements.add(new WeatherImpl(msg, innerSec.getStringList("value")));
case "ypos" -> requirements.add(new YPosImpl(msg, innerSec.getStringList("value")));
case "season" -> requirements.add(new SeasonImpl(msg, innerSec.getStringList("value")));
case "world" -> requirements.add(new WorldImpl(msg, innerSec.getStringList("value")));
case "permission" -> requirements.add(new PermissionImpl(msg, innerSec.getString("value")));
case "time" -> requirements.add(new TimeImpl(msg, innerSec.getStringList("value")));
case "skill-level" -> requirements.add(new SkillLevelImpl(msg, innerSec.getInt("value")));
case "job-level" -> requirements.add(new JobLevelImpl(msg, innerSec.getInt("value")));
case "papi-condition" -> requirements.add(new CustomPapi(msg, Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false)));
}
}
return requirements.toArray(new RequirementInterface[0]);
}
return null;
}
public static Action[] getActions(ConfigurationSection section, String nick) {
if (section != null) {
List<Action> actions = new ArrayList<>();
for (String action : section.getKeys(false)) {
switch (action) {
case "message" -> actions.add(new MessageActionImpl(section.getStringList(action).toArray(new String[0]), nick));
case "command" -> actions.add(new CommandActionImpl(section.getStringList(action).toArray(new String[0]), nick));
case "exp" -> actions.add(new VanillaXPImpl(section.getInt(action), false));
case "mending" -> actions.add(new VanillaXPImpl(section.getInt(action), true));
case "skill-xp" -> actions.add(new SkillXPImpl(section.getDouble(action)));
case "job-xp" -> actions.add(new JobXPImpl(section.getDouble(action)));
case "sound" -> actions.add(new SoundActionImpl(
section.getString(action + ".source"),
section.getString(action + ".key"),
(float) section.getDouble(action + ".volume"),
(float) section.getDouble(action + ".pitch")
));
case "potion-effect" -> {
List<PotionEffect> potionEffectList = new ArrayList<>();
for (String key : section.getConfigurationSection(action).getKeys(false)) {
PotionEffectType type = PotionEffectType.getByName(section.getString(action + "." + key + ".type", "BLINDNESS").toUpperCase());
if (type == null) AdventureUtil.consoleMessage("<red>[CustomFishing] Potion effect " + section.getString(action + "." + key + ".type", "BLINDNESS") + " doesn't exists");
potionEffectList.add(new PotionEffect(
type == null ? PotionEffectType.LUCK : type,
section.getInt(action + "." + key + ".duration"),
section.getInt(action + "." + key + ".amplifier")
));
}
actions.add(new PotionEffectImpl(potionEffectList.toArray(new PotionEffect[0])));
}
}
}
return actions.toArray(new Action[0]);
}
return null;
}
public static Effect getEffect(ConfigurationSection section) {
Effect effect = new Effect();
if (section == null) return effect;
for (String modifier : section.getKeys(false)) {
switch (modifier) {
case "weight-add" -> {
HashMap<String, Integer> as = new HashMap<>();
Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> as.put(group, (Integer) value));
effect.setWeightAS(as);
}
case "weight-multiply" -> {
HashMap<String, Double> md = new HashMap<>();
Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> md.put(group, Double.parseDouble(String.valueOf(value))-1));
effect.setWeightMD(md);
}
case "time" -> effect.setTimeModifier(section.getDouble(modifier));
case "difficulty" -> effect.setDifficulty(section.getInt(modifier));
case "double-loot" -> effect.setDoubleLootChance(section.getDouble(modifier));
case "score" -> effect.setScoreMultiplier(section.getDouble(modifier));
case "size-multiply" -> effect.setSizeMultiplier(section.getDouble(modifier));
case "lava-fishing" -> effect.setCanLavaFishing(section.getBoolean(modifier, false));
}
}
return effect;
}
}

View File

@@ -27,7 +27,6 @@ import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.fishing.loot.DroppedItem;
import net.momirealms.customfishing.fishing.loot.Item;
import net.momirealms.customfishing.fishing.loot.Loot;
import net.momirealms.customfishing.manager.ConfigManager;
import net.momirealms.customfishing.object.LeveledEnchantment;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;

View File

@@ -30,4 +30,7 @@ magnet_bait:
effect:
weight-multiply:
silver: 1.15
gold: 1.15
gold: 1.15
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/requirements
requirements:
permission: magnet_bait.use

View File

@@ -3,40 +3,59 @@
minecraft:luck_of_the_sea:
#levels
1:
weight-add:
silver: 2
gold: 1
effect:
weight-add:
silver: 2
gold: 1
2:
weight-add:
silver: 3
gold: 2
effect:
weight-add:
silver: 3
gold: 2
3:
weight-add:
silver: 4
gold: 3
effect:
weight-add:
silver: 4
gold: 3
4:
effect:
weight-add:
silver: 6
gold: 5
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/requirements
requirements:
permission: luck_of_the_sea.admin
# lucky_catch from EcoEnchants
eco:lucky_catch:
1:
double-loot: 0.1
effect:
double-loot: 0.1
2:
double-loot: 0.2
effect:
double-loot: 0.2
3:
double-loot: 0.3
effect:
double-loot: 0.3
# You can register an enchantment in EcoEnchants called "easy_catch"
# And then create its effects in CustomFishing!
eco:easy_catch:
1:
difficulty: -1
effect:
difficulty: -1
2:
difficulty: -2
effect:
difficulty: -2
# AdvancedEnchantments support
AE:lucky:
1:
double-loot: 0.1
effect:
double-loot: 0.1
2:
double-loot: 0.2
effect:
double-loot: 0.2
3:
double-loot: 0.3
effect:
double-loot: 0.3

View File

@@ -1,3 +1,7 @@
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/item-library
vanilla:
disable-stats: false
disable-bar-mechanic: false
rubbish:
material: cod
show-in-fishfinder: false

View File

@@ -158,7 +158,7 @@ rainbow_fish:
item_flags:
- HIDE_ENCHANTS
# Optional
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/requirements
requirements:
#Biome

View File

@@ -50,4 +50,15 @@ star_fishing_rod:
weight-add:
silver: 20
gold: 10
lava-fishing: true
lava-fishing: true
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/requirements
requirements:
requirement_1:
type: permission
message: '<red>You don''t have permission to use this rod!'
value: star_fishing_rod.use
requirement_2:
type: world
message: '<red>You can only use this rod in Nether.'
value:
- world_nether

View File

@@ -11,7 +11,7 @@ double_loot_fishing_totem:
hologram:
enable: true
text:
- '<#87CEFA>Fishing Totem'
- '<#87CEFA>{player}''s Fishing Totem'
- '<white>{time}s <gray>/ <white>{max_time}s'
y-offset: 3.8
@@ -27,12 +27,23 @@ double_loot_fishing_totem:
action:
#commands-activator: []
messages-activator:
- You activated a double loot totem!
- '<gold>[CustomFishing] You activated a double loot totem!'
#commands-nearby-players: []
messages-nearby-players:
- '{activator} activated a fishing totem!'
- 'Players inside of the effective range would get fishing buffs!'
- '<blue>[!] {activator} activated a fishing totem!'
- '<blue>[!] Players inside of the effective range would get fishing buffs!'
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/requirements
requirements:
requirement_1:
type: permission
message: '<red>You don''t have permission to activate this totem!'
value: double_loot_fishing_totem.activate
requirement_2:
type: world
message: '<red>You can only activate this totem in Nether.'
value:
- world_nether
# The layout of the totem
# 图腾的摆放放