Skip to content

Commit

Permalink
chore(item): 更换物品的配置逻辑,支持跨版本的物品读取、保存。
Browse files Browse the repository at this point in the history
BREAKING-CHANGE: 旧的配置文件需要进行变更。
  • Loading branch information
CarmJos committed Oct 12, 2023
1 parent 7d62f68 commit 12489fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public ItemStack getItemWhenUsing(@Nullable Player player) {

@Contract("_,!null->!null")
protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) {
if (item == null) return null;
return PreparedItem.of(item).get(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;

public class PrefixSelectGUI extends AutoPagedGUI {

Expand Down Expand Up @@ -49,7 +50,10 @@ public void loadItems() {

for (PrefixConfig prefix : prefixList) {
if (prefix.getIdentifier().equals(usingPrefix.getIdentifier())) {
addItem(new GUIItem(prefix.getItemWhenUsing(player) != null ? prefix.getItemWhenUsing(player) : prefix.getItemHasPermission(player)));
addItem(new GUIItem(Optional
.ofNullable(prefix.getItemWhenUsing(player))
.orElse(prefix.getItemHasPermission(player))
));
} else if (prefix.checkPermission(player)) {
addItem(new GUIItem(prefix.getItemHasPermission(player)) {

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/ejemplo-prefijo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ item:
# itemHasPermission [Necesario]
# Este elemento se mostrará cuando el jugador tenga permiso
has-perm:
type: DIAMOND
material: DIAMOND
name: "&b&lVIP Prefix"
lore:
- ""
Expand All @@ -38,7 +38,7 @@ item:
# Este elemento se mostrará cuando se seleccione el prefijo.
# Si no existe tal configuración, se mostrará automáticamente "itemHasPermission".
using:
type: DIAMOND
material: DIAMOND
name: "&b&lVIP Prefix"
enchants:
PROTECTION_ENVIRONMENTAL: 1 #Añade un encantamiento para que parezca que está seleccionado
Expand All @@ -50,7 +50,7 @@ item:
# Si el jugador no tiene el permiso,este item sera mostrado.
# Si este elemento no está configurado, no se mostrará en la GUI cuando el jugador no tenga permiso para usarlo.
no-perm:
type: INK_SACK
material: INK_SACK
data: 8
name: "&b&lVIP &c(¡Cómpralo!)"
lore:
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/en_US/example-prefix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ item:
# itemHasPermission [Necessary]
# This Item will be displayed when player has permission
has-perm:
type: DIAMOND
material: DIAMOND
name: "&b&lVIP Prefix"
lore:
- ""
Expand All @@ -41,7 +41,7 @@ item:
# This Item will be displayed when the prefix is selected.
# If there is no such configuration, it will automatically display "itemHasPermission".
using:
type: DIAMOND
material: DIAMOND
name: "&b&lVIP Prefix"
enchants:
PROTECTION_ENVIRONMENTAL: 1 #Add an enchantment so it looks like it’s selected
Expand All @@ -53,7 +53,7 @@ item:
# If player doesn't have the permission,this item will be displayed.
# If this item is not configured, it will not be displayed in the GUI when the player does not have permission to use it.
no-perm:
type: INK_SACK
material: INK_SACK
data: 8
name: "&b&lVIP &c(Buy it!)"
lore:
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/prefixes/example-prefix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ item:
# 有权限时显示的物品 [必须]
# 当用户有权限且未选中时,会显示该物品
has-perm:
type: DIAMOND
material: DIAMOND
name: "&b&lPro &b会员前缀"
lore:
- "&7Pro会员专属称号"
Expand All @@ -48,7 +48,7 @@ item:
# 正在使用时显示的物品 [非必需]
# 当用户正在使用时会显示这个物品,不配置即自动加载“itemHasPermission”
using:
type: DIAMOND
material: DIAMOND
name: "&b&lPro &b会员前缀"
flags:
- HIDE_ENCHANTS # 隐藏附魔显示
Expand All @@ -65,7 +65,7 @@ item:
# 没有权限时显示的物品 [非必需]
# 如果没有权限就会显示这个item。如果不配置该物品,则玩家没有使用权限时不会显示在GUI里面。
no-perm:
type: INK_SACK
material: INK_SACK
data: 8
name: "&b&lPro+ &b会员前缀 &c(未拥有)"
lore:
Expand Down

0 comments on commit 12489fe

Please sign in to comment.