9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-25 18:09:28 +00:00
This commit is contained in:
Xiao-MoMi
2023-03-21 19:16:52 +08:00
parent dc12da325b
commit 3fabbdbe33
15 changed files with 387 additions and 30 deletions

View File

@@ -19,7 +19,6 @@ package net.momirealms.customcrops;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.momirealms.customcrops.commands.PluginCommand;
@@ -30,9 +29,14 @@ import net.momirealms.customcrops.helper.VersionHelper;
import net.momirealms.customcrops.integrations.papi.PlaceholderManager;
import net.momirealms.customcrops.integrations.protection.WorldGuardHook;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.integrations.quest.BattlePassCCQuest;
import net.momirealms.customcrops.integrations.quest.ClueScrollCCQuest;
import net.momirealms.customcrops.integrations.quest.NewBetonQuestCCQuest;
import net.momirealms.customcrops.integrations.quest.OldBetonQuestCCQuest;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
@@ -99,6 +103,7 @@ public final class CustomCrops extends JavaPlugin {
}
ConfigUtil.reloadConfigs();
this.registerQuests();
PluginCommand pluginCommand = new PluginCommand();
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(pluginCommand);
@@ -145,4 +150,19 @@ public final class CustomCrops extends JavaPlugin {
public VersionHelper getVersionHelper() {
return versionHelper;
}
private void registerQuests() {
PluginManager pluginManager = Bukkit.getPluginManager();
if (pluginManager.isPluginEnabled("ClueScrolls")) {
ClueScrollCCQuest quest = new ClueScrollCCQuest();
Bukkit.getPluginManager().registerEvents(quest, plugin);
}
if (pluginManager.isPluginEnabled("BetonQuest")) {
if (Bukkit.getPluginManager().getPlugin("BetonQuest").getDescription().getVersion().startsWith("2")) NewBetonQuestCCQuest.register();
else OldBetonQuestCCQuest.register();
}
if (pluginManager.isPluginEnabled("BattlePass")) {
BattlePassCCQuest.register();
}
}
}

View File

@@ -19,11 +19,8 @@
package net.momirealms.customcrops.api.utils;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.config.MainConfig;
import org.bukkit.World;
import java.util.List;
public class WorldUtils {
/**

View File

@@ -20,7 +20,6 @@ package net.momirealms.customcrops.commands;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.MessageConfig;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;

View File

@@ -24,7 +24,10 @@ import net.momirealms.customcrops.integrations.SkillInterface;
import net.momirealms.customcrops.integrations.job.EcoJobsHook;
import net.momirealms.customcrops.integrations.job.JobsRebornHook;
import net.momirealms.customcrops.integrations.protection.*;
import net.momirealms.customcrops.integrations.skill.*;
import net.momirealms.customcrops.integrations.skill.AureliumsHook;
import net.momirealms.customcrops.integrations.skill.EcoSkillsHook;
import net.momirealms.customcrops.integrations.skill.MMOCoreHook;
import net.momirealms.customcrops.integrations.skill.mcMMOHook;
import net.momirealms.customcrops.objects.QualityRatio;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.apache.commons.lang.StringUtils;

View File

@@ -3,7 +3,6 @@ package net.momirealms.customcrops.helper;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
import net.momirealms.customcrops.CustomCrops;
import org.bukkit.Bukkit;
import java.lang.reflect.Field;

View File

@@ -37,7 +37,6 @@ import net.momirealms.customcrops.objects.Sprinkler;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.FurnitureUtil;
import net.momirealms.customcrops.utils.MiscUtils;
import org.bukkit.BanList;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@@ -22,7 +22,6 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import net.momirealms.customcrops.integrations.JobInterface;
import net.momirealms.customcrops.integrations.SkillInterface;
import org.bukkit.entity.Player;
import java.util.List;

View File

@@ -18,16 +18,12 @@
package net.momirealms.customcrops.integrations.protection;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import net.momirealms.customcrops.integrations.CCAntiGrief;
import org.bukkit.Location;

View File

@@ -0,0 +1,45 @@
/*
* 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.customcrops.integrations.quest;
import io.github.battlepass.BattlePlugin;
import io.github.battlepass.quests.quests.external.executor.ExternalQuestExecutor;
import io.github.battlepass.registry.quest.QuestRegistry;
import net.momirealms.customcrops.api.event.CropHarvestEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class BattlePassCCQuest extends ExternalQuestExecutor implements Listener {
public static void register() {
QuestRegistry questRegistry = BattlePlugin.getApi().getQuestRegistry();
questRegistry.hook("customcrops", BattlePassCCQuest::new);
}
public BattlePassCCQuest(BattlePlugin battlePlugin) {
super(battlePlugin, "customcrops");
}
@EventHandler
public void onHarvest(CropHarvestEvent event) {
if (event.isCancelled()) return;
Player player = event.getPlayer();
this.execute("harvest", player, (var1x) -> var1x.root(event.getCrop().getKey()));
}
}

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.customcrops.integrations.quest;
import com.electro2560.dev.cluescrolls.api.*;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.api.event.CropHarvestEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ClueScrollCCQuest implements Listener {
private final CustomClue commonClue;
public ClueScrollCCQuest() {
commonClue = ClueScrollsAPI.getInstance().registerCustomClue(CustomCrops.plugin, "harvest", new ClueConfigData("crop_id", DataType.STRING));
}
@EventHandler
public void onHarvest(CropHarvestEvent event) {
if (event.isCancelled()) return;
commonClue.handle(event.getPlayer(), 1, new ClueDataPair("crop_id", event.getCrop().getKey()));
}
}

View File

@@ -0,0 +1,113 @@
/*
* 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.customcrops.integrations.quest;
import net.momirealms.customcrops.api.event.CropHarvestEvent;
import net.momirealms.customcrops.utils.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 NewBetonQuestCCQuest extends CountingObjective implements Listener {
private final CompoundLocation playerLocation;
private final VariableNumber rangeVar;
private final HashSet<String> crop_ids;
public NewBetonQuestCCQuest(Instruction instruction) throws InstructionParseException {
super(instruction, "crop_to_harvest");
crop_ids = new HashSet<>();
Collections.addAll(crop_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("Crop amount cannot be less than 0");
}
}
public static void register() {
BetonQuest.getInstance().registerObjectives("customcrops", NewBetonQuestCCQuest.class);
}
@EventHandler
public void onHarvest(CropHarvestEvent event) {
OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer());
if (!containsPlayer(onlineProfile)) {
return;
}
if (isInvalidLocation(event, onlineProfile)) {
return;
}
if (this.crop_ids.contains(event.getCrop().getKey()) && this.checkConditions(onlineProfile)) {
getCountingData(onlineProfile).progress(1);
completeIfDoneOrNotify(onlineProfile);
}
}
private boolean isInvalidLocation(CropHarvestEvent 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

@@ -0,0 +1,156 @@
/*
* 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.customcrops.integrations.quest;
import net.momirealms.customcrops.api.event.CropHarvestEvent;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import pl.betoncraft.betonquest.BetonQuest;
import pl.betoncraft.betonquest.Instruction;
import pl.betoncraft.betonquest.api.Objective;
import pl.betoncraft.betonquest.config.Config;
import pl.betoncraft.betonquest.exceptions.InstructionParseException;
import pl.betoncraft.betonquest.exceptions.QuestRuntimeException;
import pl.betoncraft.betonquest.utils.LogUtils;
import pl.betoncraft.betonquest.utils.PlayerConverter;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.logging.Level;
public class OldBetonQuestCCQuest extends Objective implements Listener {
private final HashSet<String> crop_ids = new HashSet<>();
private final int amount;
private final boolean notify;
private final int notifyInterval;
public OldBetonQuestCCQuest(Instruction instruction) throws InstructionParseException {
super(instruction);
this.template = CropData.class;
this.notifyInterval = instruction.getInt(instruction.getOptional("notify"), 1);
this.notify = instruction.hasArgument("notify") || this.notifyInterval > 1;
this.amount = instruction.getInt(instruction.getOptional("amount"), 1);
Collections.addAll(this.crop_ids, instruction.getArray());
}
public static void register() {
BetonQuest.getInstance().registerObjectives("customfishing", OldBetonQuestCCQuest.class);
}
@Override
public void start() {
Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance());
}
@Override
public void stop() {
HandlerList.unregisterAll(this);
}
@Override
public String getDefaultDataInstruction() {
return Integer.toString(this.amount);
}
@Override
public String getProperty(String name, String playerID) {
return switch (name.toLowerCase(Locale.ROOT)) {
case "amount" ->
Integer.toString(this.amount - ((OldBetonQuestCCQuest.CropData) this.dataMap.get(playerID)).getAmount());
case "left" -> Integer.toString(((OldBetonQuestCCQuest.CropData) this.dataMap.get(playerID)).getAmount());
case "total" -> Integer.toString(this.amount);
default -> "";
};
}
private boolean isValidPlayer(Player player) {
if (player == null) {
return false;
} else {
return player.isOnline() && player.isValid();
}
}
@EventHandler
public void onHarvest(CropHarvestEvent event) {
String playerID = PlayerConverter.getID(event.getPlayer());
if (this.containsPlayer(playerID)) {
if (this.crop_ids.contains(event.getCrop().getKey())) {
if (this.checkConditions(playerID)) {
if (!isValidPlayer(event.getPlayer())) {
return;
}
CropData cropData = (CropData) this.dataMap.get(playerID);
cropData.harvest(1);
if (cropData.finished()) {
this.completeObjective(playerID);
}
else if (this.notify && cropData.getAmount() % this.notifyInterval == 0) {
try {
Config.sendNotify(this.instruction.getPackage().getName(), playerID, "crop_to_harvest", new String[]{String.valueOf(cropData.getAmount())}, "crop_to_harvest,info");
} catch (QuestRuntimeException e1) {
try {
LogUtils.getLogger().log(Level.WARNING, "The notify system was unable to play a sound for the 'crop_to_harvest' category in '" + this.instruction.getObjective().getFullID() + "'. Error was: '" + e1.getMessage() + "'");
} catch (InstructionParseException e2) {
LogUtils.logThrowableReport(e2);
}
}
}
}
}
}
}
public static class CropData extends Objective.ObjectiveData {
private int amount;
public CropData(String instruction, String playerID, String objID) {
super(instruction, playerID, objID);
try {
this.amount = Integer.parseInt(instruction);
}
catch (NumberFormatException e) {
AdventureUtil.consoleMessage("[CustomCrops] NumberFormatException");
this.amount = 1;
}
}
public void harvest(int caughtAmount) {
this.amount -= caughtAmount;
this.update();
}
public int getAmount() {
return this.amount;
}
public String toString() {
return String.valueOf(this.amount);
}
public boolean finished() {
return this.amount <= 0;
}
}
}

View File

@@ -29,23 +29,12 @@ public class RequirementWorld extends Requirement implements RequirementInterfac
@Override
public boolean isConditionMet(PlayerCondition playerCondition) {
String worldName = playerCondition.getLocation().getWorld().getName();
if (mode) {
for (String value : values) {
if (!value.equals(worldName)) {
notMetMessage(playerCondition.getPlayer());
return false;
}
for (String value : values) {
if (value.equals(worldName)) {
return true;
}
return true;
}
else {
for (String value : values) {
if (value.equals(worldName)) {
return true;
}
}
notMetMessage(playerCondition.getPlayer());
return false;
}
notMetMessage(playerCondition.getPlayer());
return false;
}
}

View File

@@ -28,6 +28,9 @@ softdepend:
- CrashClaim
- BentoBox
- EcoJobs
- BattlePass
- BetonQuest
- ClueScrolls
commands:
customcrops:
usage: /customcrops <args>