Skip to content
Open
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
6 changes: 6 additions & 0 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ repositories {
maven("https://repo.bg-software.com/repository/api/")
// ZNPCsPlus
maven("https://repo.pyr.lol/snapshots")
// WorldGuard / WorldEdit
maven("https://maven.enginehub.org/repo/")

// bungeecord-chat, HikariCP, hppc, JetBrains Annotations, slf4j
mavenCentral()
Expand Down Expand Up @@ -157,6 +159,10 @@ dependencies {
implementation("com.carrotsearch:hppc:0.10.0")
// bungeecord-chat
implementation("net.md-5:bungeecord-chat:1.21-R0.4") { isTransitive = false }

compileOnlyPlugin("com.sk89q.worldguard:worldguard-core:7.0.14")
compileOnlyPlugin("com.sk89q.worldedit:worldedit-bukkit:7.3.13")
compileOnlyPlugin("com.sk89q.worldedit:worldedit-core:7.3.13")
}

tasks.shadowJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public void onBlockPlace(BlockPlaceEvent event) {
// subtract if enabled
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (block.getType().isAir())
return;

Player player = event.getPlayer();
if (player.hasMetadata("NPC")) {
return;
Expand All @@ -83,7 +87,6 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}

Block block = event.getBlock();

for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) {
Quest quest = pendingTask.quest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public FarmingTaskType(BukkitQuestsPlugin plugin) {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (block.getType().isAir())
return;
Material type = block.getType();

List<Block> brokenBlocks = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void onReady() {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();

if (block.getType().isAir())
return;

Player player = event.getPlayer();
if (player.hasMetadata("NPC")) {
return;
Expand All @@ -61,7 +66,7 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}

Block block = event.getBlock();

ItemStack item = plugin.getVersionSpecificHandler().getItemInMainHand(player);
boolean silkTouchPresent = item != null && item.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
import com.leonardobishop.quests.common.quest.Quest;
import com.leonardobishop.quests.common.quest.Task;
import com.leonardobishop.quests.common.tasktype.TaskType;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.Biome;
Expand Down Expand Up @@ -61,9 +67,40 @@ public static boolean validateWorld(final Player player, final Task task) {
};
}

public static boolean validateRegion(@NotNull Player player, @NotNull Task task) {
final Object cfg = task.getConfigValue(
task.getConfigValues().containsKey("region") ? "region" : "regions");
if (cfg == null) return true;
if (!Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) return true;

try {
RegionContainer container = WorldGuard.getInstance()
.getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
ApplicableRegionSet set = query.getApplicableRegions(
BukkitAdapter.adapt(player.getLocation()));

if (set == null || set.size() == 0) return false;

java.util.Set<String> active = new java.util.HashSet<>();
set.getRegions().forEach(r -> active.add(r.getId()));

if (cfg instanceof java.util.List<?> list) {
for (Object o : list) if (active.contains(String.valueOf(o))) return true;
return false;
} else if (cfg instanceof String s) {
return active.contains(s);
} else {
return true;
}
} catch (NoClassDefFoundError ignored) {
return true;
}
}

public static boolean validateBiome(final String biomeKey, final @NotNull Object biomes) {
return switch (biomes) {
case final List<?> allowedBiomeKeys-> allowedBiomeKeys.contains(biomeKey);
case final List<?> allowedBiomeKeys -> allowedBiomeKeys.contains(biomeKey);
case final String allowedBiomeKey -> allowedBiomeKey.equals(biomeKey);
default -> true;
};
Expand All @@ -88,7 +125,7 @@ public static boolean doesConfigStringListExist(final @NotNull Task task, final
Object configObject = task.getConfigValue(key);
if (configObject instanceof List list) {
return List.copyOf(list);
} else if (configObject instanceof String s){
} else if (configObject instanceof String s) {
return List.of(s);
} else {
return null;
Expand All @@ -100,7 +137,7 @@ public static boolean doesConfigStringListExist(final @NotNull Task task, final
Object configObject = task.getConfigValue(key);
if (configObject instanceof List list) {
return List.copyOf(list);
} else if (configObject instanceof Integer i){
} else if (configObject instanceof Integer i) {
return List.of(i);
} else {
return null;
Expand Down Expand Up @@ -177,7 +214,7 @@ public static int decrementIntegerTaskProgress(TaskProgress taskProgress) {
return progress;
}

public static void sendTrackAdvancement(Player player, Quest quest, Task task, PendingTask pendingTask, Number amount) {
public static void sendTrackAdvancement(Player player, Quest quest, Task task, PendingTask pendingTask, Number amount) {
TaskProgress taskProgress = pendingTask.taskProgress();

boolean useActionBar = plugin.getConfig().getBoolean("options.actionbar.progress", false)
Expand Down Expand Up @@ -288,6 +325,12 @@ public static List<PendingTask> getApplicableTasks(Player player, QPlayer qPlaye
}
}

if (constraintSet.contains(TaskConstraint.REGION)) {
if (!TaskUtils.validateRegion(player, task)) {
continue;
}
}

BIOME_CHECK:
if (constraintSet.contains(TaskConstraint.BIOME)) {
final Object biomes = task.getConfigValue("biomes");
Expand Down Expand Up @@ -319,7 +362,8 @@ public static List<PendingTask> getApplicableTasks(Player player, QPlayer qPlaye
return tasks;
}

public record PendingTask(Quest quest, Task task, QuestProgress questProgress, TaskProgress taskProgress) { }
public record PendingTask(Quest quest, Task task, QuestProgress questProgress, TaskProgress taskProgress) {
}

public static boolean matchBlock(@NotNull BukkitTaskType type, @NotNull PendingTask pendingTask, @Nullable Block block, @NotNull UUID player) {
return matchBlock(type, pendingTask, block, player, "block", "blocks");
Expand Down Expand Up @@ -1059,7 +1103,7 @@ public static TaskType.ConfigValidator useEnchantmentListConfigValidator(TaskTyp
/**
* Returns a config validator which checks if at least one value in the given
* paths is present in the enum.
*
* <p>
* Should be used for small enums only as it lists possible values in config
* problem extended description.
*
Expand All @@ -1082,7 +1126,7 @@ public static <T extends Enum<T>> TaskType.ConfigValidator useEnumConfigValidato
* paths is a value in the list of accepted values.
*
* @param acceptedValues a list of accepted values
* @param paths a list of valid paths for task
* @param paths a list of valid paths for task
* @return config validator
*/
public static TaskType.ConfigValidator useAcceptedValuesConfigValidator(TaskType type, Collection<String> acceptedValues, String... paths) {
Expand All @@ -1101,9 +1145,9 @@ public static TaskType.ConfigValidator useAcceptedValuesConfigValidator(TaskType
extendedDescription += "<br> - " + value;
}
problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING,
ConfigProblemDescriptions.NOT_ACCEPTED_VALUE.getDescription(String.valueOf(configObject), type.getType()),
extendedDescription,
path));
ConfigProblemDescriptions.NOT_ACCEPTED_VALUE.getDescription(String.valueOf(configObject), type.getType()),
extendedDescription,
path));
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

public enum TaskConstraint {
WORLD(0b00000001),
BIOME(0x00000010);
BIOME(0x00000010),
REGION(0x00000100);

private final int value;

Expand Down
1 change: 1 addition & 0 deletions bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ softdepend:
- Votifier
- VotingPlugin
- WildStacker
- WorldGuard
- ZNPCsPlus
prefix: Quests
api-version: "1.13" # allows new API features but Quests will still work pre-1.13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ public void onDisable() {
* Returns the goal of a task.
*/
public Object getGoal(final Task task) {
return task.getConfigValue("amount", "-");
for (String key : List.of("amount", "distance", "minutes", "level", "worth", "value")) {
Object goal = task.getConfigValue(key);
if (goal != null) {
return goal;
}
}
return "-";
}

/**
Expand Down