9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-28 03:19:12 +00:00
This commit is contained in:
Xiao-MoMi
2023-01-16 00:03:01 +08:00
parent 515e2d13b5
commit bac4b0ea40
4 changed files with 133 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '1.2.18'
version = '1.2.18.2'
repositories {
mavenCentral()

View File

@@ -0,0 +1,116 @@
/*
* 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.integration.quest;
import net.momirealms.customfishing.api.event.FishResultEvent;
import net.momirealms.customfishing.object.fishing.FishResult;
import net.momirealms.customfishing.util.AdventureUtil;
import org.betonquest.betonquest.BetonQuest;
import org.betonquest.betonquest.Instruction;
import org.betonquest.betonquest.VariableNumber;
import org.betonquest.betonquest.api.CountingObjective;
import org.betonquest.betonquest.api.profiles.OnlineProfile;
import org.betonquest.betonquest.api.profiles.Profile;
import org.betonquest.betonquest.exceptions.InstructionParseException;
import org.betonquest.betonquest.utils.PlayerConverter;
import org.betonquest.betonquest.utils.location.CompoundLocation;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import java.util.Collections;
import java.util.HashSet;
public class NewBetonQuestCFQuest extends CountingObjective implements Listener {
private final CompoundLocation playerLocation;
private final VariableNumber rangeVar;
private final HashSet<String> loot_ids;
public NewBetonQuestCFQuest(Instruction instruction) throws InstructionParseException {
super(instruction, "loot_to_fish");
loot_ids = new HashSet<>();
Collections.addAll(loot_ids, instruction.getArray());
targetAmount = instruction.getInt();
final String pack = instruction.getPackage().getQuestPath();
final String loc = instruction.getOptional("playerLocation");
final String range = instruction.getOptional("range");
if (loc != null && range != null) {
playerLocation = new CompoundLocation(pack, loc);
rangeVar = new VariableNumber(pack, range);
} else {
playerLocation = null;
rangeVar = null;
}
if (targetAmount <= 0) {
throw new InstructionParseException("Fish amount cannot be less than 0");
}
}
public static void register() {
BetonQuest.getInstance().registerObjectives("customfishing", NewBetonQuestCFQuest.class);
}
@EventHandler
public void onFish(FishResultEvent event) {
if (event.getResult() != FishResult.FAILURE) {
OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer());
if (!containsPlayer(onlineProfile)) {
return;
}
if (isInvalidLocation(event, onlineProfile)) {
return;
}
if (this.loot_ids.contains(event.getLoot_id()) && this.checkConditions(onlineProfile)) {
getCountingData(onlineProfile).progress(event.isDouble() ? 1 : 2);
completeIfDoneOrNotify(onlineProfile);
}
}
}
private boolean isInvalidLocation(FishResultEvent event, final Profile profile) {
if (playerLocation == null || rangeVar == null) {
return false;
}
final Location targetLocation;
try {
targetLocation = playerLocation.getLocation(profile);
} catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) {
AdventureUtil.consoleMessage(e.getMessage());
return true;
}
final int range = rangeVar.getInt(profile);
final Location playerLoc = event.getPlayer().getLocation();
return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range;
}
@Override
public void start() {
Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance());
}
@Override
public void stop() {
HandlerList.unregisterAll(this);
}
}

View File

@@ -19,6 +19,7 @@ package net.momirealms.customfishing.integration.quest;
import net.momirealms.customfishing.api.event.FishResultEvent;
import net.momirealms.customfishing.object.fishing.FishResult;
import net.momirealms.customfishing.util.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -39,14 +40,14 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.logging.Level;
public class BetonQuestCFQuest extends Objective implements Listener {
public class OldBetonQuestCFQuest extends Objective implements Listener {
private final HashSet<String> loot_ids = new HashSet<>();
private final int amount;
private final boolean notify;
private final int notifyInterval;
public BetonQuestCFQuest(Instruction instruction) throws InstructionParseException {
public OldBetonQuestCFQuest(Instruction instruction) throws InstructionParseException {
super(instruction);
this.template = FishData.class;
this.notifyInterval = instruction.getInt(instruction.getOptional("notify"), 1);
@@ -56,7 +57,7 @@ public class BetonQuestCFQuest extends Objective implements Listener {
}
public static void register() {
BetonQuest.getInstance().registerObjectives("customfishing", BetonQuestCFQuest.class);
BetonQuest.getInstance().registerObjectives("customfishing", OldBetonQuestCFQuest.class);
}
@Override
@@ -71,7 +72,7 @@ public class BetonQuestCFQuest extends Objective implements Listener {
@Override
public String getDefaultDataInstruction() {
return null;
return Integer.toString(this.amount);
}
@Override
@@ -130,7 +131,13 @@ public class BetonQuestCFQuest extends Objective implements Listener {
public FishData(String instruction, String playerID, String objID) {
super(instruction, playerID, objID);
this.amount = Integer.parseInt(instruction);
try {
this.amount = Integer.parseInt(instruction);
}
catch (NumberFormatException e) {
AdventureUtil.consoleMessage("<>");
this.amount = 1;
}
}
public void catchFish(int caughtAmount) {

View File

@@ -28,7 +28,8 @@ import net.momirealms.customfishing.integration.item.*;
import net.momirealms.customfishing.integration.mob.MythicMobsMobImpl;
import net.momirealms.customfishing.integration.papi.PlaceholderManager;
import net.momirealms.customfishing.integration.quest.BattlePassCFQuest;
import net.momirealms.customfishing.integration.quest.BetonQuestCFQuest;
import net.momirealms.customfishing.integration.quest.NewBetonQuestCFQuest;
import net.momirealms.customfishing.integration.quest.OldBetonQuestCFQuest;
import net.momirealms.customfishing.integration.quest.ClueScrollCFQuest;
import net.momirealms.customfishing.integration.season.CustomCropsSeasonImpl;
import net.momirealms.customfishing.integration.season.RealisticSeasonsImpl;
@@ -212,14 +213,14 @@ public class IntegrationManager extends Function {
}
public void registerQuests() {
if (Bukkit.getPluginManager().isPluginEnabled("ClueScrolls")) {
ClueScrollCFQuest clueScrollCFQuest = new ClueScrollCFQuest();
Bukkit.getPluginManager().registerEvents(clueScrollCFQuest, CustomFishing.plugin);
hookMessage("ClueScrolls");
}
if (Bukkit.getPluginManager().isPluginEnabled("BetonQuest")) {
BetonQuestCFQuest.register();
if (Bukkit.getPluginManager().getPlugin("BetonQuest").getDescription().getVersion().startsWith("2.")) NewBetonQuestCFQuest.register();
else OldBetonQuestCFQuest.register();
hookMessage("BetonQuest");
}
if (Bukkit.getPluginManager().isPluginEnabled("BattlePass")) {