#1393: Improve field rename handling and centralize conversion between bukkit and string more
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.craftbukkit.attribute;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
@@ -9,6 +10,8 @@ import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.legacy.FieldRename;
|
||||
import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
|
||||
public class CraftAttribute {
|
||||
@@ -28,10 +31,17 @@ public class CraftAttribute {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static Attribute stringToBukkit(String bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
public static Attribute stringToBukkit(String string) {
|
||||
Preconditions.checkArgument(string != null);
|
||||
|
||||
return Registry.ATTRIBUTE.get(NamespacedKey.fromString(bukkit));
|
||||
// We currently do not have any version-dependent remapping, so we can use current version
|
||||
// First convert from when only the names where saved
|
||||
string = FieldRename.convertAttributeName(ApiVersion.CURRENT, string);
|
||||
string = string.toLowerCase(Locale.ROOT);
|
||||
NamespacedKey key = NamespacedKey.fromString(string);
|
||||
|
||||
// Now also convert from when keys where saved
|
||||
return CraftRegistry.get(Registry.ATTRIBUTE, key, ApiVersion.CURRENT);
|
||||
}
|
||||
|
||||
public static AttributeBase bukkitToMinecraft(Attribute bukkit) {
|
||||
@@ -53,4 +63,10 @@ public class CraftAttribute {
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own sound effect with out properly registering it.");
|
||||
}
|
||||
|
||||
public static String bukkitToString(Attribute bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit.getKey().toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user