Skip to content

Commit

Permalink
Add main_hand as a valid item material; fix menu requirement api bein…
Browse files Browse the repository at this point in the history
…g dumb
  • Loading branch information
ErikSzabo committed Nov 29, 2024
1 parent 9efa756 commit c9f793b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plugins {
}

group = "gg.auroramc"
version = "2.0.5"
version = "2.0.6"

java {
sourceCompatibility = JavaVersion.VERSION_21
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gg/auroramc/aurora/api/AuroraAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

Expand Down Expand Up @@ -154,7 +155,7 @@ public static EntityManager getEntityManager() {
return Aurora.getExpansionManager().getExpansion(EntityExpansion.class).getEntityManager();
}

public static void registerRequirementHandler(String name, Function<String[], Boolean> resolver) {
public static void registerRequirementHandler(String name, BiFunction<Player, String[], Boolean> resolver) {
Requirement.register(name, resolver);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gg/auroramc/aurora/api/menu/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ public ItemStack toItemStack(Player player) {
} else if (config.getMaterial().equalsIgnoreCase("self_head")) {
setPlayerHead(player);
item = new ItemStack(Material.PLAYER_HEAD);
} else if (config.getMaterial().equalsIgnoreCase("main_hand")) {
item = player.getInventory().getItemInMainHand().clone();
} else {
item = new ItemStack(Material.valueOf(config.getMaterial().toUpperCase()));
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/gg/auroramc/aurora/api/menu/Requirement.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;

public class Requirement {
private static final Map<String, Function<String[], Boolean>> resolvers = Maps.newConcurrentMap();
private static final Map<String, BiFunction<Player, String[], Boolean>> resolvers = Maps.newConcurrentMap();

public static void register(String name, Function<String[], Boolean> resolver) {
public static void register(String name, BiFunction<Player, String[], Boolean> resolver) {
resolvers.put("[" + name + "]", resolver);
}

Expand Down Expand Up @@ -87,12 +88,12 @@ public static boolean isMet(Player player, String requirement, List<Placeholder<
if (args[0].equalsIgnoreCase("[placeholder]")) {
if (!DependencyManager.hasDep(Dep.PAPI)) return false;
var placeholderValue = PlaceholderAPI.setPlaceholders(player, args[1]);
return doPlaceholderCheck(args, placeholderValue);
return doPlaceholderCheck(player, args, placeholderValue);
}

if (args[0].equalsIgnoreCase("[arg]")) {
var placeholderValue = Placeholder.execute("{arg_" + args[1] + "}", placeholders);
return doPlaceholderCheck(args, placeholderValue);
return doPlaceholderCheck(player, args, placeholderValue);
}

if (args[0].equalsIgnoreCase("[has-items]")) {
Expand All @@ -113,14 +114,14 @@ public static boolean isMet(Player player, String requirement, List<Placeholder<
var customResolver = resolvers.get(args[0]);

if (customResolver != null) {
return customResolver.apply(args);
return customResolver.apply(player, args);
}

return false;
}

private static boolean doPlaceholderCheck(String[] args, String placeholderValue) {
var compareValue = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
private static boolean doPlaceholderCheck(Player player, String[] args, String placeholderValue) {
var compareValue = PlaceholderAPI.setPlaceholders(player, String.join(" ", Arrays.copyOfRange(args, 3, args.length)));

return switch (args[2]) {
case "==" -> placeholderValue.equals(compareValue);
Expand Down

0 comments on commit c9f793b

Please sign in to comment.