Skip to content
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
14 changes: 8 additions & 6 deletions API/src/main/java/fr/maxlego08/menu/api/loader/NoneLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public NoneLoader(@NotNull Plugin plugin,@NotNull Class<? extends Button> clazz,
@Nullable
public Button load(@NonNull YamlConfiguration configuration, @NonNull String path, @NonNull DefaultButtonValue defaultButtonValue) {
try {
return this.clazz.getConstructor(Plugin.class).newInstance(this.plugin);
} catch (Exception exception) {
try {
return this.clazz.getDeclaredConstructor().newInstance();
} catch (Exception exception2) {
exception.printStackTrace();
for (var constructor : this.clazz.getConstructors()) {
var params = constructor.getParameterTypes();
if (params.length == 1 && params[0].isInstance(this.plugin)) {
return (Button) constructor.newInstance(this.plugin);
}
}
return this.clazz.getDeclaredConstructor().newInstance();
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class Action {
*/
protected abstract void execute(@NotNull Player player, @Nullable Button button, @NotNull InventoryEngine inventoryEngine, @NotNull Placeholders placeholders);

public void preExecute(@NotNull Player player,@Nullable Button button,@NotNull InventoryEngine inventoryEngine,@NotNull Placeholders placeholders) {
public void preExecute(@NotNull Player player, @Nullable Button button, @NotNull InventoryEngine inventoryEngine, @NotNull Placeholders placeholders) {
placeholders.register("player", player.getName());
if (chance < 100 && Math.random() > (chance / 100.0f)) {
for (Action denyChanceAction : denyChanceActions) {
Expand Down
6 changes: 3 additions & 3 deletions Common/src/main/java/fr/maxlego08/menu/ZMenuItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public static ZMenuItemStack fromMap(InventoryManager inventoryManager, File fil

@Override
public @NonNull ItemStack build(Player player) {
return build(new ZBuildContext.Builder().player(player).build());

return build(player, true);
}

@Override
Expand Down Expand Up @@ -405,7 +404,8 @@ private void applyDisplayNameLore(Player player, Placeholders placeholders, Item
if (this.displayName != null) {
try {
String displayName = locale == null ? this.displayName : this.translatedDisplayName.getOrDefault(locale, this.displayName);
itemName = fontImage.replace(papi(placeholders.parse(displayName), offlinePlayer == null ? player : offlinePlayer, useCache));
if (displayName != null)
itemName = fontImage.replace(papi(placeholders.parse(displayName), offlinePlayer == null ? player : offlinePlayer, useCache));
} catch (Exception exception) {
Logger.info("Error with update display name for item " + path + " in file " + filePath + " (" + player + ", " + this.displayName + ")", Logger.LogType.ERROR);
exception.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public OnlinePlayerArgumentValidator(Plugin plugin) {

@Override
public boolean isValid(String value) {
if (value.equalsIgnoreCase("%player%")) return true;
return plugin.getServer().getPlayerExact(value) != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public PlayerArgumentValidator(Plugin plugin) {

@Override
public boolean isValid(String value) {
if (value.equalsIgnoreCase("%player%")) return true;
return this.plugin.getServer().getOfflinePlayer(value).hasPlayedBefore();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ public MenuItemStack load(@NonNull YamlConfiguration configuration, @NonNull Str
}

if (!menuItemStack.isNeedPlaceholderAPI() && Configuration.enableCacheItemStack) {
menuItemStack.build(new ZBuildContext.Builder().build());
try {
menuItemStack.build(new ZBuildContext.Builder().build());
} catch (Exception ignored) { // Fail when a item requires a player to be built.
}
}

return menuItemStack;
Expand Down