New option to hide item types from item browser

This commit is contained in:
Jules 2024-05-16 18:19:24 -07:00
parent e2e64cefbf
commit 354a5f9336
4 changed files with 68 additions and 54 deletions

View File

@ -97,7 +97,7 @@ public class Type implements CooldownObject, PreloadedObject {
public Script ent;
private boolean meleeAttacks;
private boolean meleeAttacks, hideInGame;
/**
* List of stats which can be applied onto an item which has this type. This
@ -112,14 +112,6 @@ public class Type implements CooldownObject, PreloadedObject {
onEntityInteract = config.contains("on-entity-interact") ? MythicLib.plugin.getSkills().loadSkillHandler(config.get("on-entity-interact")) : null;
});
/**
* @deprecated 'weapon' boolean is now automatically inferred from the modifierSource
*/
@Deprecated
public Type(@NotNull String id, boolean weapon, @NotNull ModifierSource modSource) {
this(id, modSource);
}
/**
* Hard-coded type with given parameters. Can be used by other plugins
* to create types using MMOItems API.
@ -147,12 +139,7 @@ public class Type implements CooldownObject, PreloadedObject {
loreFormat = config.getString("LoreFormat", (parent != null ? parent.loreFormat : null));
attackCooldownKey = config.getString("attack-cooldown-key", "default");
meleeAttacks = !config.getBoolean("disable-melee-attacks");
}
@Deprecated
public void postload(ConfigurationSection config) {
postLoadAction.cacheConfig(config);
postLoadAction.performAction();
hideInGame = config.getBoolean("hide-in-game");
}
@NotNull
@ -161,13 +148,8 @@ public class Type implements CooldownObject, PreloadedObject {
return postLoadAction;
}
/**
* @deprecated Type is no longer an enum so that external plugins
* can register their own types. Use getId() instead
*/
@Deprecated
public String name() {
return getId();
public boolean isDisplayed() {
return !hideInGame;
}
/**
@ -225,22 +207,6 @@ public class Type implements CooldownObject, PreloadedObject {
return onEntityInteract;
}
/**
* @deprecated Use {@link #getSupertype()}
*/
@Deprecated
public boolean isSubtype() {
return parent != null;
}
/**
* @deprecated Use {@link #getSupertype()}
*/
@Deprecated
public Type getParent() {
return parent;
}
/**
* @return Does it display as four rows in /mmoitems browse?
*/
@ -296,16 +262,6 @@ public class Type implements CooldownObject, PreloadedObject {
return unidentifiedTemplate;
}
/**
* @param stat The stat to check
* @return If the stat can be handled by this type of item
* @deprecated Use ItemStat.isCompatible(Type) instead
*/
@Deprecated
public boolean canHave(ItemStat stat) {
return stat.isCompatible(this);
}
private ItemStack read(String str) {
Validate.notNull(str, "Input must not be null");
@ -373,4 +329,57 @@ public class Type implements CooldownObject, PreloadedObject {
public static boolean isValid(@Nullable String id) {
return id != null && MMOItems.plugin.getTypes().has(id.toUpperCase().replace("-", "_").replace(" ", "_"));
}
//region Deprecated API
/**
* @param stat The stat to check
* @return If the stat can be handled by this type of item
* @deprecated Use ItemStat.isCompatible(Type) instead
*/
@Deprecated
public boolean canHave(ItemStat stat) {
return stat.isCompatible(this);
}
/**
* @deprecated Use {@link #getSupertype()}
*/
@Deprecated
public boolean isSubtype() {
return parent != null;
}
/**
* @deprecated Use {@link #getSupertype()}
*/
@Deprecated
public Type getParent() {
return parent;
}
/**
* @deprecated 'weapon' boolean is now automatically inferred from the modifierSource
*/
@Deprecated
public Type(@NotNull String id, boolean weapon, @NotNull ModifierSource modSource) {
this(id, modSource);
}
@Deprecated
public void postload(ConfigurationSection config) {
postLoadAction.cacheConfig(config);
postLoadAction.performAction();
}
/**
* @deprecated Type is no longer an enum so that external plugins
* can register their own types. Use getId() instead
*/
@Deprecated
public String name() {
return getId();
}
//endregion
}

View File

@ -28,9 +28,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.stream.Collectors;
public class ItemBrowser extends PluginInventory {
private final Map<String, ItemStack> cached = new LinkedHashMap<>();
private final List<Type> itemTypes;
private final Type type;
private boolean deleteMode;
@ -49,8 +51,9 @@ public class ItemBrowser extends PluginInventory {
super(player);
this.type = type;
}
this.itemTypes = MMOItems.plugin.getTypes().getAll().stream().filter(Type::isDisplayed).collect(Collectors.toList());
}
@NotNull
@Override
@ -61,7 +64,7 @@ public class ItemBrowser extends PluginInventory {
* TYPE BROWSER
*
* Displays all possible item types if no type was previously selected by the player.
* ------------------------------
* ------------------------------
*/
if (type == null) {
@ -74,11 +77,10 @@ public class ItemBrowser extends PluginInventory {
Inventory inv = Bukkit.createInventory(this, 54, "Item Explorer");
// Fetch the list of types
List<Type> types = new ArrayList<>(MMOItems.plugin.getTypes().getAll());
for (int j = min; j < Math.min(max, types.size()); j++) {
for (int j = min; j < Math.min(max, itemTypes.size()); j++) {
// Current type to display into the GUI
Type currentType = types.get(j);
Type currentType = itemTypes.get(j);
// Get number of items
int items = MMOItems.plugin.getTemplates().getTemplates(currentType).size();

View File

@ -50,7 +50,7 @@ public class TypeManager {
try {
ConfigurationSection section = config.getConfigurationSection(type.getId());
Validate.notNull(section, "Could not find config section for type '" + type.getId() + "'");
Validate.notNull(section, "Could not find config section");
type.load(section);
if (clearBefore) type.getPostLoadAction().performAction();
} catch (RuntimeException exception) {

View File

@ -19,6 +19,9 @@ SWORD:
# Name displayed in the item lore.
name: 'Sword'
# Should this type be displayed inside the item browser?
hide-in-game: false
# Template of an unidentified item.
unident-item: