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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import javax.annotation.Nonnull;

import io.github.slimefunguguproject.bump.utils.Attributes;

import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -37,7 +39,7 @@ public ItemUseHandler getItemHandler() {
return e -> {
Player p = e.getPlayer();
double health = p.getHealth();
double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
double maxHealth = p.getAttribute(Attributes.get("max_health")).getBaseValue();
int foodLevel = p.getFoodLevel();

if (maxHealth <= health) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import javax.annotation.Nonnull;

import io.github.slimefunguguproject.bump.utils.Attributes;

import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -74,7 +76,7 @@ public static void setupTypes() {
.addValidSlimefunItemIds(validSlimefunItemIds);

for (String attr : attributes) {
Attribute attribute = Attribute.valueOf(attr);
Attribute attribute = Attributes.get(attr);
double min = attributesSection.getDouble(attr + ".min");
double max = attributesSection.getDouble(attr + ".max");
String weightStr = attributesSection.getString(attr + ".weight");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.slimefunguguproject.bump.utils;

import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.attribute.Attribute;

import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.Set;

public class Attributes {
@Nonnull
public static Attribute get(String key) {
key = key.toLowerCase();
key = key.replace("generic_", "generic.");
key = key.replace("player_", "player.");
key = key.replace("horse_", "horse.");
key = key.replace("zombie_", "zombie.");
Set<String> names = new HashSet<>();
String plain = key.contains(".") ? key.split("\\.")[1] : key;
names.add(key);
names.add(plain);
names.add("generic." + plain);
names.add("player." + plain);
names.add("horse." + plain);
names.add("zombie." + plain);
for (var s : names) {
var result = Registry.ATTRIBUTE.get(NamespacedKey.minecraft(s));
if (result != null) {
return result;
}
}

return null;
}
}
Loading