Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bentobox_level update, minor remove-items-when-complete optimization and Gradle Wrapper upgrade #728

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
// Paper (adventure-bom snapshots)
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
// ASkyBlock, BentoBox, bStats, Citizens
maven("https://repo.codemc.org/repository/maven-public/")
maven("https://repo.codemc.io/repository/maven-public/")
// AuthLib
maven("https://libraries.minecraft.net/")
// CoreProtect
Expand All @@ -36,7 +36,7 @@ repositories {
// Oraxen
maven("https://repo.oraxen.com/releases")
// PlaceholderAPI
maven("https://repo.extendedclip.com/content/repositories/dev/")
maven("https://repo.extendedclip.com/releases")
// CustomFishing, ItemsAdder, SCore, ShopGUIPlus, Slimefun4, Vault
maven("https://jitpack.io/")
// PlayerPoints
Expand Down Expand Up @@ -68,7 +68,8 @@ dependencies {
// AuthLib
compileOnlyPlugin("com.mojang:authlib:1.5.21")
// BentoBox
compileOnlyPlugin("world.bentobox:bentobox:1.22.0-SNAPSHOT")
compileOnly("world.bentobox:bentobox:2.5.4-SNAPSHOT")
compileOnly("world.bentobox:level:2.16.1-SNAPSHOT")
// Citizens
compileOnlyPlugin("net.citizensnpcs:citizensapi:2.0.30-SNAPSHOT")
// CoreProtect
Expand Down Expand Up @@ -101,7 +102,7 @@ dependencies {
// Oraxen
compileOnlyPlugin("io.th0rgal:oraxen:1.175.0")
// PlaceholderAPI
compileOnlyPlugin("me.clip:placeholderapi:2.11.3-DEV-160")
compileOnlyPlugin("me.clip:placeholderapi:2.11.6")
// PlayerPoints
compileOnlyPlugin("org.black_ixx:playerpoints:3.2.5")
// SCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ public void onEnable() {

// Register task types with enabled plugin compatibility requirement
taskTypeManager.registerTaskType(() -> new ASkyBlockLevelTaskType(this), () -> CompatUtils.isPluginEnabled("ASkyBlock"));
taskTypeManager.registerTaskType(() -> new BentoBoxLevelTaskType(this), () -> CompatUtils.isPluginEnabled("BentoBox") && CompatUtils.classExists("world.bentobox.level.events.IslandLevelCalculatedEvent"));
taskTypeManager.registerTaskType(() -> new CitizensDeliverTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
taskTypeManager.registerTaskType(() -> new CitizensInteractTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
taskTypeManager.registerTaskType(() -> new CustomFishingFishingTaskType(this), () -> CompatUtils.isPluginEnabled("CustomFishing"));
Expand Down Expand Up @@ -511,11 +512,6 @@ public void onEnable() {
return pluginVersion != null && (pluginVersion.startsWith("4") || pluginVersion.startsWith("5"));
});

// Register task types with even more weird requirements
if (CompatUtils.isPluginEnabled("BentoBox")) {
BentoBoxLevelTaskType.register(this, taskTypeManager);
}

// Close task type registrations
taskTypeManager.closeRegistrations();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ private void checkInventory(Player player) {

super.debug("Inventory check triggered", quest.getId(), task.getId(), player.getUniqueId());

boolean remove = TaskUtils.getConfigBoolean(task, "remove-items-when-complete");
boolean allowPartial = TaskUtils.getConfigBoolean(task, "allow-partial-completion");

QuestItem qi;
Expand Down Expand Up @@ -167,6 +166,8 @@ private void checkInventory(Player player) {
taskProgress.setCompleted(true);
super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());

boolean remove = TaskUtils.getConfigBoolean(task, "remove-items-when-complete");

if (remove) {
TaskUtils.removeItemsInSlots(player, amountPerSlot, progress);
super.debug("Removing items from inventory", quest.getId(), task.getId(), player.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,78 @@
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
import com.leonardobishop.quests.bukkit.util.TaskUtils;
import com.leonardobishop.quests.bukkit.util.constraint.TaskConstraintSet;
import com.leonardobishop.quests.common.player.QPlayer;
import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
import com.leonardobishop.quests.common.quest.Quest;
import com.leonardobishop.quests.common.quest.Task;
import com.leonardobishop.quests.common.tasktype.TaskTypeManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import org.jetbrains.annotations.NotNull;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.level.events.IslandLevelCalculatedEvent;

import java.util.Set;
import java.util.UUID;

public final class BentoBoxLevelTaskType extends BukkitTaskType {

private final BukkitQuestsPlugin plugin;

public BentoBoxLevelTaskType(BukkitQuestsPlugin plugin) {
public BentoBoxLevelTaskType(final @NotNull BukkitQuestsPlugin plugin) {
super("bentobox_level", TaskUtils.TASK_ATTRIBUTION_STRING, "Reach a certain island level in the level addon for BentoBox.");
this.plugin = plugin;

super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "level"));
super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "level"));
this.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "level"));
this.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "level"));
}

public static void register(BukkitQuestsPlugin plugin, TaskTypeManager manager) {
if (BentoBox.getInstance().getAddonsManager().getAddonByName("Level").isPresent()) {
manager.registerTaskType(new BentoBoxLevelTaskType(plugin));
}
}

// https://github.com/BentoBoxWorld/bentobox/issues/352
@EventHandler
public void onBentoBoxIslandLevelCalculated(IslandBaseEvent event) {
if ("IslandLevelCalculatedEvent".equals(event.getEventName())) {
Island island = (Island) event.getKeyValues().get("island");
public void onIslandLevelCalculated(final @NotNull IslandLevelCalculatedEvent event) {
final Island island = event.getIsland();
final Set<UUID> memberIds = island.getMemberSet();
final long level = event.getLevel();

for (UUID member : island.getMemberSet()) {
QPlayer qPlayer = plugin.getPlayerManager().getPlayer(member);
if (qPlayer == null) {
continue;
}
for (final UUID memberId : memberIds) {
final Player player = Bukkit.getPlayer(memberId);

Player player = Bukkit.getPlayer(member);
if (player != null) {
this.handle(player, level);
}
}
}

if (player == null) {
continue;
}
private void handle(final @NotNull Player player, final long level) {
if (player.hasMetadata("NPC")) {
return;
}

for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
TaskProgress taskProgress = pendingTask.taskProgress();
final QPlayer qPlayer = this.plugin.getPlayerManager().getPlayer(player.getUniqueId());
if (qPlayer == null) {
return;
}

long islandLevelNeeded = (long) (int) task.getConfigValue("level");
long newLevel = (long) event.getKeyValues().get("level");
for (final TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) {
final Quest quest = pendingTask.quest();
final Task task = pendingTask.task();
final TaskProgress taskProgress = pendingTask.taskProgress();

super.debug("Player island level updated to " + newLevel, quest.getId(), task.getId(), member);
this.debug("Player island level updated to " + level, quest.getId(), task.getId(), player.getUniqueId());

taskProgress.setProgress(newLevel);
super.debug("Updating task progress (now " + newLevel + ")", quest.getId(), task.getId(), player.getUniqueId());
//noinspection DataFlowIssue // TODO quest data rework
final long levelNeeded = (long) task.getConfigValue("level");

if (newLevel >= islandLevelNeeded) {
super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
taskProgress.setProgress(newLevel);
taskProgress.setCompleted(true);
}
final long clampedLevel = Math.max(level, levelNeeded);
taskProgress.setProgress(clampedLevel);
this.debug("Updating task progress (now " + clampedLevel + ")", quest.getId(), task.getId(), player.getUniqueId());

TaskUtils.sendTrackAdvancement(player, quest, task, pendingTask, islandLevelNeeded);
}
if (level >= levelNeeded) {
this.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
taskProgress.setCompleted(true);
}

TaskUtils.sendTrackAdvancement(player, quest, task, pendingTask, levelNeeded);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void checkInventory(Player player, T npcId, String npcName, BukkitQuestsP
}
}

boolean remove = TaskUtils.getConfigBoolean(task, "remove-items-when-complete");
boolean allowPartial = TaskUtils.getConfigBoolean(task, "allow-partial-completion");

QuestItem qi;
Expand Down Expand Up @@ -143,6 +142,8 @@ public void checkInventory(Player player, T npcId, String npcName, BukkitQuestsP
taskProgress.setCompleted(true);
super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());

boolean remove = TaskUtils.getConfigBoolean(task, "remove-items-when-complete");

if (remove) {
TaskUtils.removeItemsInSlots(player, amountPerSlot, progress);
super.debug("Removing items from inventory", quest.getId(), task.getId(), player.getUniqueId());
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down