Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into issue/80
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/extendedclip/deluxemenus/action/ClickActionTask.java
  • Loading branch information
BlitzOffline committed Jun 18, 2024
2 parents b059663 + ac2700a commit d1b4f60
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ public class ClickActionTask extends BukkitRunnable {
// Ugly hack to get around the fact that arguments are not available at task execution time
private final Map<String, String> arguments;
private final boolean parsePlaceholdersInArguments;
private final boolean parsePlaceholdersAfterArguments;

public ClickActionTask(
@NotNull final DeluxeMenus plugin,
@NotNull final UUID uuid,
@NotNull final ActionType actionType,
@NotNull final String exec,
@NotNull final Map<String, String> arguments,
final boolean parsePlaceholdersInArguments
final boolean parsePlaceholdersInArguments,
final boolean parsePlaceholdersAfterArguments
) {
this.plugin = plugin;
this.uuid = uuid;
this.actionType = actionType;
this.exec = exec;
this.arguments = arguments;
this.parsePlaceholdersInArguments = parsePlaceholdersInArguments;
this.parsePlaceholdersAfterArguments = parsePlaceholdersAfterArguments;
}

@Override
Expand All @@ -58,12 +61,17 @@ public void run() {
}

final Optional<MenuHolder> holder = Menu.getMenuHolder(player);

final Player target = holder.isPresent() && holder.get().getPlaceholderPlayer() != null
? holder.get().getPlaceholderPlayer()
: player;

final String executable = StringUtils.replacePlaceholdersAndArguments(this.exec, this.arguments, target, this.parsePlaceholdersInArguments);

final String executable = StringUtils.replacePlaceholdersAndArguments(
this.exec,
this.arguments,
target,
this.parsePlaceholdersInArguments,
this.parsePlaceholdersAfterArguments);

switch (actionType) {
case META:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public boolean onCommand(
action.getType(),
action.getExecutable(),
holder.getTypedArgs(),
true,
true
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,8 @@ public void loadMenu(FileConfiguration c, String key, boolean mainConfig) {
return;
}

final boolean argumentsSupportPlaceholders = c.getBoolean(pre + "arguments_support_placeholders", false);

if (argumentsSupportPlaceholders) {
builder.parsePlaceholdersInArguments(argumentsSupportPlaceholders);
}
builder.parsePlaceholdersInArguments(c.getBoolean(pre + "arguments_support_placeholders", false));
builder.parsePlaceholdersAfterArguments(c.getBoolean(pre + "parse_placeholders_after_arguments", false));

// Don't need to register the menu since it's done in the constructor
new Menu(builder.build(), items);
Expand Down Expand Up @@ -1489,7 +1486,8 @@ public void onClick(@NotNull final MenuHolder holder) {
action.getType(),
action.getExecutable(),
holder.getTypedArgs(),
holder.parsePlaceholdersInArguments()
holder.parsePlaceholdersInArguments(),
holder.parsePlaceholdersAfterArguments()
);

if (action.hasDelay()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/extendedclip/deluxemenus/menu/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public void openMenu(final @NotNull Player viewer, final @Nullable Map<String, S
}
holder.setTypedArgs(args);
holder.parsePlaceholdersInArguments(this.options.parsePlaceholdersInArguments());
holder.parsePlaceholdersAfterArguments(this.options.parsePlaceholdersAfterArguments());

if (!this.handleArgRequirements(holder)) {
return;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/extendedclip/deluxemenus/menu/MenuHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MenuHolder implements InventoryHolder {
private Inventory inventory;
private boolean updating;
private boolean parsePlaceholdersInArguments;
private boolean parsePlaceholdersAfterArguments;
private Map<String, String> typedArgs;

public MenuHolder(Player viewer) {
Expand Down Expand Up @@ -91,6 +92,9 @@ public Optional<Menu> getMenu() {
}

public @NotNull String setPlaceholdersAndArguments(final @NotNull String string) {
if (parsePlaceholdersAfterArguments) {
return setPlaceholders(setArguments(string));
}
return setArguments(setPlaceholders(string));
}

Expand Down Expand Up @@ -318,10 +322,18 @@ public void parsePlaceholdersInArguments(final boolean parsePlaceholdersInArgume
this.parsePlaceholdersInArguments = parsePlaceholdersInArguments;
}

public void parsePlaceholdersAfterArguments(final boolean parsePlaceholdersAfterArguments) {
this.parsePlaceholdersAfterArguments = parsePlaceholdersAfterArguments;
}

public boolean parsePlaceholdersInArguments() {
return parsePlaceholdersInArguments;
}

public boolean parsePlaceholdersAfterArguments() {
return parsePlaceholdersAfterArguments;
}

public void setPlaceholderPlayer(Player placeholderPlayer) {
this.placeholderPlayer = placeholderPlayer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MenuOptions {
private final int size;
private final int updateInterval;
private final boolean parsePlaceholdersInArguments;
private final boolean parsePlaceholdersAfterArguments;

private final List<String> commands;
private final boolean registerCommands;
Expand All @@ -35,6 +36,7 @@ private MenuOptions(final @NotNull MenuOptionsBuilder builder) {
this.size = builder.size;
this.updateInterval = builder.updateInterval;
this.parsePlaceholdersInArguments = builder.parsePlaceholdersInArguments;
this.parsePlaceholdersAfterArguments = builder.parsePlaceholdersAfterArguments;

this.commands = builder.commands;
this.registerCommands = builder.registerCommands;
Expand Down Expand Up @@ -75,6 +77,10 @@ public boolean parsePlaceholdersInArguments() {
return this.parsePlaceholdersInArguments;
}

public boolean parsePlaceholdersAfterArguments() {
return this.parsePlaceholdersAfterArguments;
}

public @NotNull List<@NotNull String> commands() {
return this.commands;
}
Expand Down Expand Up @@ -113,6 +119,7 @@ public boolean registerCommands() {
.size(this.size)
.updateInterval(this.updateInterval)
.parsePlaceholdersInArguments(this.parsePlaceholdersInArguments)
.parsePlaceholdersAfterArguments(this.parsePlaceholdersAfterArguments)
.commands(this.commands)
.registerCommands(this.registerCommands)
.arguments(this.arguments)
Expand All @@ -131,6 +138,7 @@ public static class MenuOptionsBuilder {
private int size = 9;
private int updateInterval = 10;
private boolean parsePlaceholdersInArguments = false;
private boolean parsePlaceholdersAfterArguments = false;

private List<String> commands = List.of();
private boolean registerCommands = false;
Expand Down Expand Up @@ -177,6 +185,11 @@ public MenuOptionsBuilder parsePlaceholdersInArguments(final boolean parsePlaceh
return this;
}

public MenuOptionsBuilder parsePlaceholdersAfterArguments(final boolean parsePlaceholdersAfterArguments) {
this.parsePlaceholdersAfterArguments = parsePlaceholdersAfterArguments;
return this;
}

public MenuOptionsBuilder commands(final @NotNull List<@NotNull String> commands) {
this.commands = commands;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ public static String color(@NotNull String input) {

@NotNull
public static String replacePlaceholdersAndArguments(@NotNull String input, final @Nullable Map<String, String> arguments,
final @Nullable Player player, boolean parsePlaceholdersInsideArguments) {
final @Nullable Player player,
final boolean parsePlaceholdersInsideArguments,
final boolean parsePlaceholdersAfterArguments) {
if (player == null) {
return replaceArguments(input, arguments, null, parsePlaceholdersInsideArguments);
}

if (parsePlaceholdersAfterArguments) {
return replacePlaceholders(replaceArguments(input, arguments, player, parsePlaceholdersInsideArguments), player);
}

return replaceArguments(replacePlaceholders(input, player), arguments, player, parsePlaceholdersInsideArguments);
}

Expand Down

0 comments on commit d1b4f60

Please sign in to comment.