mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-29 11:59:11 +00:00
fix lava fishing & add event
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.event;
|
||||
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FishingResultEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
private boolean isCancelled;
|
||||
private final Result result;
|
||||
private final Loot loot;
|
||||
private final Map<String, String> args;
|
||||
|
||||
public FishingResultEvent(@NotNull Player who, Result result, Loot loot, Map<String, String> args) {
|
||||
super(who);
|
||||
this.result = result;
|
||||
this.loot = loot;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
isCancelled = cancel;
|
||||
}
|
||||
|
||||
public String getArg(String key) {
|
||||
return args.get("{" + key + "}");
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Loot getLoot() {
|
||||
return loot;
|
||||
}
|
||||
|
||||
public enum Result {
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,16 @@ package net.momirealms.customfishing.api.manager;
|
||||
|
||||
import net.momirealms.customfishing.api.common.Key;
|
||||
import net.momirealms.customfishing.api.mechanic.effect.Effect;
|
||||
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface EffectManager {
|
||||
boolean registerEffect(Key key, Effect effect);
|
||||
|
||||
boolean unregisterEffect(Key key);
|
||||
boolean registerEffectItem(Key key, EffectCarrier effect);
|
||||
|
||||
@Nullable Effect getEffect(String namespace, String id);
|
||||
boolean unregisterEffectItem(Key key);
|
||||
|
||||
@Nullable EffectCarrier getEffect(String namespace, String id);
|
||||
|
||||
Effect getInitialEffect();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* 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.action;
|
||||
|
||||
public abstract class ActionExpansion {
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.momirealms.customfishing.api.mechanic.condition;
|
||||
|
||||
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.effect.Effect;
|
||||
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@@ -36,11 +37,11 @@ public class FishingPreparation extends Condition {
|
||||
private final boolean rodOnMainHand;
|
||||
private final @NotNull ItemStack rodItemStack;
|
||||
private final @NotNull String rodItemID;
|
||||
private final @Nullable Effect rodEffect;
|
||||
private final @Nullable EffectCarrier rodEffect;
|
||||
private @Nullable ItemStack baitItemStack;
|
||||
private @Nullable String baitItemID;
|
||||
private @Nullable Effect baitEffect;
|
||||
private final List<Effect> utilEffects;
|
||||
private @Nullable EffectCarrier baitEffect;
|
||||
private final List<EffectCarrier> utilEffects;
|
||||
private boolean canFish = true;
|
||||
|
||||
public FishingPreparation(Player player, CustomFishingPlugin plugin) {
|
||||
@@ -55,15 +56,18 @@ public class FishingPreparation extends Condition {
|
||||
this.rodItemStack = this.rodOnMainHand ? mainHandItem : offHandItem;
|
||||
this.rodItemID = plugin.getItemManager().getAnyItemID(this.rodItemStack);
|
||||
this.rodEffect = plugin.getEffectManager().getEffect("rod", this.rodItemID);
|
||||
super.insertArg("rod", this.rodItemID);
|
||||
super.insertArg("{rod}", this.rodItemID);
|
||||
|
||||
String baitItemID = plugin.getItemManager().getAnyItemID(this.rodOnMainHand ? offHandItem : mainHandItem);
|
||||
Effect baitEffect = plugin.getEffectManager().getEffect("bait", baitItemID);
|
||||
EffectCarrier baitEffect = plugin.getEffectManager().getEffect("bait", baitItemID);
|
||||
|
||||
if (baitEffect != null) {
|
||||
this.baitItemID = baitItemID;
|
||||
this.baitItemStack = this.rodOnMainHand ? offHandItem : mainHandItem;
|
||||
this.baitEffect = baitEffect;
|
||||
} else if (plugin.getBagManager().isBagEnabled()) {
|
||||
}
|
||||
|
||||
if (plugin.getBagManager().isBagEnabled()) {
|
||||
Inventory fishingBag = plugin.getBagManager().getOnlineBagInventory(player.getUniqueId());
|
||||
HashSet<String> uniqueUtils = new HashSet<>(4);
|
||||
if (fishingBag != null) {
|
||||
@@ -71,8 +75,8 @@ public class FishingPreparation extends Condition {
|
||||
ItemStack itemInBag = fishingBag.getItem(i);
|
||||
String bagItemID = plugin.getItemManager().getItemID(itemInBag);
|
||||
if (bagItemID == null) continue;
|
||||
if (this.baitEffect == null) {
|
||||
Effect effect = plugin.getEffectManager().getEffect("bait", bagItemID);
|
||||
if (this.baitItemID == null) {
|
||||
EffectCarrier effect = plugin.getEffectManager().getEffect("bait", bagItemID);
|
||||
if (effect != null) {
|
||||
this.baitItemID = bagItemID;
|
||||
this.baitItemStack = itemInBag;
|
||||
@@ -80,32 +84,27 @@ public class FishingPreparation extends Condition {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Effect utilEffect = plugin.getEffectManager().getEffect("util", bagItemID);
|
||||
if (utilEffect != null
|
||||
&& !uniqueUtils.contains(bagItemID)
|
||||
&& utilEffect.canMerge(this)) {
|
||||
EffectCarrier utilEffect = plugin.getEffectManager().getEffect("util", bagItemID);
|
||||
if (utilEffect != null && !uniqueUtils.contains(bagItemID) && utilEffect.isConditionMet(this)) {
|
||||
utilEffects.add(utilEffect);
|
||||
uniqueUtils.add(bagItemID);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.baitItemID = null;
|
||||
this.baitItemStack = null;
|
||||
this.baitEffect = null;
|
||||
}
|
||||
|
||||
if (this.baitEffect != null) {
|
||||
if (!this.baitEffect.canMerge(this)) {
|
||||
if (!this.baitEffect.isConditionMet(this)) {
|
||||
this.canFish = false;
|
||||
return;
|
||||
}
|
||||
super.insertArg("bait", this.baitItemID);
|
||||
super.insertArg("{bait}", this.baitItemID);
|
||||
}
|
||||
|
||||
if (this.rodEffect != null) {
|
||||
if (!this.rodEffect.canMerge(this)) {
|
||||
if (!this.rodEffect.isConditionMet(this)) {
|
||||
this.canFish = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,27 +133,24 @@ public class FishingPreparation extends Condition {
|
||||
return baitItemID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Effect getRodEffect() {
|
||||
return rodEffect;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Effect getBaitEffect() {
|
||||
return baitEffect;
|
||||
}
|
||||
|
||||
public boolean canFish() {
|
||||
return this.canFish;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public @NotNull Player getPlayer() {
|
||||
assert super.player != null;
|
||||
public Player getPlayer() {
|
||||
return super.player;
|
||||
}
|
||||
|
||||
public List<Effect> getUtilEffects() {
|
||||
return utilEffects;
|
||||
public Effect mergeEffect(Effect effect) {
|
||||
if (this.rodEffect != null)
|
||||
effect.merge(this.rodEffect.getEffect());
|
||||
if (this.baitEffect != null)
|
||||
effect.merge(this.baitEffect.getEffect());
|
||||
for (EffectCarrier util : utilEffects) {
|
||||
effect.merge(util.getEffect());
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,19 +34,8 @@ public class AbstractEffect implements Effect {
|
||||
protected double timeModifier = 1;
|
||||
protected double difficultyModifier = 0;
|
||||
protected double gameTimeModifier = 0;
|
||||
protected Requirement[] requirements;
|
||||
protected List<Pair<String, Modifier>> lootWeightModifier = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Requirement[] getRequirements() {
|
||||
return requirements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canLavaFishing() {
|
||||
return lavaFishing;
|
||||
@@ -99,15 +88,4 @@ public class AbstractEffect implements Effect {
|
||||
public List<Pair<String, Modifier>> getLootWeightModifier() {
|
||||
return lootWeightModifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMerge(Condition condition) {
|
||||
if (this.requirements == null) return true;
|
||||
for (Requirement requirement : requirements) {
|
||||
if (!requirement.isConditionMet(condition)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,6 @@ import java.util.List;
|
||||
|
||||
public interface Effect {
|
||||
|
||||
boolean persist();
|
||||
|
||||
Requirement[] getRequirements();
|
||||
|
||||
boolean canLavaFishing();
|
||||
|
||||
double getMultipleLootChance();
|
||||
@@ -47,6 +43,4 @@ public interface Effect {
|
||||
Effect merge(Effect another);
|
||||
|
||||
List<Pair<String, Modifier>> getLootWeightModifier();
|
||||
|
||||
boolean canMerge(Condition condition);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package net.momirealms.customfishing.api.mechanic.effect;
|
||||
|
||||
import net.momirealms.customfishing.api.common.Key;
|
||||
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.requirement.Requirement;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EffectCarrier {
|
||||
|
||||
private Key key;
|
||||
private Requirement[] requirements;
|
||||
private Effect effect;
|
||||
private Map<ActionTrigger, Action[]> actionMap;
|
||||
private boolean persist;
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final EffectCarrier item;
|
||||
|
||||
public Builder() {
|
||||
this.item = new EffectCarrier();
|
||||
}
|
||||
|
||||
public Builder persist(boolean persist) {
|
||||
item.persist = persist;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder key(Key key) {
|
||||
item.key = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder requirements(Requirement[] requirements) {
|
||||
item.requirements = requirements;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder effect(Effect effect) {
|
||||
item.effect = effect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder actionMap(Map<ActionTrigger, Action[]> actionMap) {
|
||||
item.actionMap = actionMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EffectCarrier build() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public Key getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Requirement[] getRequirements() {
|
||||
return requirements;
|
||||
}
|
||||
|
||||
public Effect getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public Map<ActionTrigger, Action[]> getActionMap() {
|
||||
return actionMap;
|
||||
}
|
||||
|
||||
public boolean isPersist() {
|
||||
return persist;
|
||||
}
|
||||
|
||||
public boolean isConditionMet(Condition condition) {
|
||||
if (requirements == null) return true;
|
||||
for (Requirement requirement : requirements) {
|
||||
if (!requirement.isConditionMet(condition)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -73,11 +73,6 @@ public class FishingEffect extends AbstractEffect {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder requirements(Requirement[] requirements) {
|
||||
effect.requirements = requirements;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FishingEffect build() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public abstract class GameExpansion {
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* 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 org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* 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.requirement;
|
||||
|
||||
public abstract class RequirementExpansion {
|
||||
|
||||
Reference in New Issue
Block a user