Added PlaceholderContext#copyWithItem

This commit is contained in:
Auxilor
2023-04-26 14:07:22 +01:00
parent 77754249ad
commit 80fa05da98
3 changed files with 26 additions and 13 deletions

View File

@@ -131,12 +131,8 @@ public final class PlaceholderManager {
getResult(
plugin,
identifier,
new PlaceholderContext(
player,
null,
EMPTY_INJECTABLE,
Collections.emptyList()
)
new PlaceholderContext()
.copyWithPlayer(player)
),
""
);

View File

@@ -50,6 +50,13 @@ public class PlaceholderContext {
@NotNull
private final Collection<AdditionalPlayer> additionalPlayers;
/**
* Create an empty PlaceholderContext.
*/
public PlaceholderContext() {
this(null, null, PlaceholderManager.EMPTY_INJECTABLE, Collections.emptyList());
}
/**
* Constructs a new PlaceholderContext with the given parameters.
*
@@ -135,6 +142,21 @@ public class PlaceholderContext {
);
}
/**
* Copy with an item.
*
* @param itemStack The ItemStack.
* @return The new context.
*/
public PlaceholderContext copyWithItem(@Nullable final ItemStack itemStack) {
return new PlaceholderContext(
this.getPlayer(),
itemStack,
this.getInjectableContext(),
this.getAdditionalPlayers()
);
}
/**
* Copy with an extra injectable context.
*

View File

@@ -22,7 +22,6 @@ import org.jetbrains.annotations.Nullable;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -346,12 +345,8 @@ public final class StringUtils {
if (option == FormatOption.WITH_PLACEHOLDERS) {
return format(
message,
new PlaceholderContext(
player,
null,
PlaceholderManager.EMPTY_INJECTABLE,
Collections.emptyList()
)
new PlaceholderContext()
.copyWithPlayer(player)
);
}