This commit is contained in:
Ajneb97 2024-12-08 17:10:18 -03:00
parent c75d7196df
commit 70fccf26fb
9 changed files with 198 additions and 9 deletions

View file

@ -37,7 +37,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version> <version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -132,6 +132,9 @@ public class PlayerKits2 extends JavaPlugin {
case "1.21.3": case "1.21.3":
serverVersion = ServerVersion.v1_21_R2; serverVersion = ServerVersion.v1_21_R2;
break; break;
case "1.21.4":
serverVersion = ServerVersion.v1_21_R3;
break;
default: default:
serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", "")); serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
} }

View file

@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
import pk.ajneb97.PlayerKits2; import pk.ajneb97.PlayerKits2;
import pk.ajneb97.model.internal.KitVariable; import pk.ajneb97.model.internal.KitVariable;
import pk.ajneb97.model.item.*; import pk.ajneb97.model.item.*;
@ -19,6 +20,7 @@ import pk.ajneb97.utils.OtherUtils;
import pk.ajneb97.utils.ServerVersion; import pk.ajneb97.utils.ServerVersion;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class KitItemManager { public class KitItemManager {
@ -76,8 +78,40 @@ public class KitItemManager {
} }
if(OtherUtils.isNew() && meta.hasCustomModelData()) { if(OtherUtils.isNew() && meta.hasCustomModelData()) {
if(!serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R3)){
kitItem.setCustomModelData(meta.getCustomModelData()); kitItem.setCustomModelData(meta.getCustomModelData());
} }
}
if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R3)){
if(meta.hasCustomModelData()){
CustomModelDataComponent customModelDataComponent = meta.getCustomModelDataComponent();
List<String> customModelDataComponentFlagsList = customModelDataComponent.getFlags()
.stream()
.map(String::valueOf)
.collect(Collectors.toList());
List<String> customModelDataComponentColorsList = customModelDataComponent.getColors()
.stream()
.map(color -> String.valueOf(color.asRGB()))
.collect(Collectors.toList());
List<String> customModelDataComponentFloatsList = customModelDataComponent.getFloats()
.stream()
.map(String::valueOf)
.collect(Collectors.toList());
List<String> customModelDataComponentStringsList = new ArrayList<>(customModelDataComponent.getStrings());
kitItem.setCustomModelComponentData(new KitItemCustomModelComponentData(
customModelDataComponentFlagsList,
customModelDataComponentColorsList,
customModelDataComponentFloatsList,
customModelDataComponentStringsList
));
}
}
if(meta instanceof LeatherArmorMeta) { if(meta instanceof LeatherArmorMeta) {
LeatherArmorMeta meta2 = (LeatherArmorMeta) meta; LeatherArmorMeta meta2 = (LeatherArmorMeta) meta;
@ -159,6 +193,31 @@ public class KitItemManager {
meta.setCustomModelData(customModelData); meta.setCustomModelData(customModelData);
} }
ServerVersion serverVersion = PlayerKits2.serverVersion;
if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R3)){
KitItemCustomModelComponentData kitItemCustomModelComponentData = kitItem.getCustomModelComponentData();
if(kitItemCustomModelComponentData != null){
CustomModelDataComponent customModelDataComponent = meta.getCustomModelDataComponent();
List<String> cFloats = kitItemCustomModelComponentData.getFloats();
List<String> cColors = kitItemCustomModelComponentData.getColors();
List<String> cFlags = kitItemCustomModelComponentData.getFlags();
List<String> cStrings = kitItemCustomModelComponentData.getStrings();
customModelDataComponent.setFlags(cFlags.stream()
.map(Boolean::parseBoolean)
.collect(Collectors.toList()));
customModelDataComponent.setFloats(cFloats.stream()
.map(Float::parseFloat)
.collect(Collectors.toList()));
customModelDataComponent.setColors(cColors.stream()
.map(rgb -> Color.fromRGB(Integer.parseInt(rgb)))
.collect(Collectors.toList()));
customModelDataComponent.setStrings(new ArrayList<>(cStrings));
meta.setCustomModelDataComponent(customModelDataComponent);
}
}
List<String> enchants = kitItem.getEnchants(); List<String> enchants = kitItem.getEnchants();
if(enchants != null) { if(enchants != null) {
for(int i=0;i<enchants.size();i++) { for(int i=0;i<enchants.size();i++) {
@ -214,8 +273,6 @@ public class KitItemManager {
List<String> attributes = kitItem.getAttributes(); List<String> attributes = kitItem.getAttributes();
item = ItemUtils.setAttributes(plugin,item, attributes); item = ItemUtils.setAttributes(plugin,item, attributes);
ServerVersion serverVersion = PlayerKits2.serverVersion;
//Item Flags //Item Flags
meta = item.getItemMeta(); meta = item.getItemMeta();
List<String> flags = kitItem.getFlags(); List<String> flags = kitItem.getFlags();
@ -262,6 +319,15 @@ public class KitItemManager {
if(item.getCustomModelData() != 0) { if(item.getCustomModelData() != 0) {
config.set(path+".custom_model_data", item.getCustomModelData()); config.set(path+".custom_model_data", item.getCustomModelData());
} }
KitItemCustomModelComponentData customModelComponentData = item.getCustomModelComponentData();
if(customModelComponentData != null){
if(!customModelComponentData.getFlags().isEmpty()) config.set(path+".custom_model_component_data.flags",customModelComponentData.getFlags());
if(!customModelComponentData.getFloats().isEmpty()) config.set(path+".custom_model_component_data.floats",customModelComponentData.getFloats());
if(!customModelComponentData.getColors().isEmpty()) config.set(path+".custom_model_component_data.colors",customModelComponentData.getColors());
if(!customModelComponentData.getStrings().isEmpty()) config.set(path+".custom_model_component_data.strings",customModelComponentData.getStrings());
}
if(item.getColor() != 0) { if(item.getColor() != 0) {
config.set(path+".color", item.getColor()); config.set(path+".color", item.getColor());
} }
@ -365,6 +431,29 @@ public class KitItemManager {
List<String> canPlace = config.contains(path+".can_place") ? config.getStringList(path+".can_place") : null; List<String> canPlace = config.contains(path+".can_place") ? config.getStringList(path+".can_place") : null;
List<String> canDestroy = config.contains(path+".can_destroy") ? config.getStringList(path+".can_destroy") : null; List<String> canDestroy = config.contains(path+".can_destroy") ? config.getStringList(path+".can_destroy") : null;
KitItemCustomModelComponentData customModelComponentData = null;
if(config.contains(path+".custom_model_component_data")) {
List<String> cFlags = new ArrayList<>();
List<String> cFloats = new ArrayList<>();
List<String> cColors = new ArrayList<>();
List<String> cStrings = new ArrayList<>();
if(config.contains(path+".custom_model_component_data.flags")) {
cFlags = config.getStringList(path+".custom_model_component_data.flags");
}
if(config.contains(path+".custom_model_component_data.floats")) {
cFloats = config.getStringList(path+".custom_model_component_data.floats");
}
if(config.contains(path+".custom_model_component_data.colors")) {
cColors = config.getStringList(path+".custom_model_component_data.colors");
}
if(config.contains(path+".custom_model_component_data.strings")) {
cStrings = config.getStringList(path+".custom_model_component_data.strings");
}
customModelComponentData = new KitItemCustomModelComponentData(cFlags,cColors,cFloats,cStrings);
}
KitItemSkullData skullData = null; KitItemSkullData skullData = null;
if(config.contains(path+".skull_data")) { if(config.contains(path+".skull_data")) {
String skullTexture = null; String skullTexture = null;
@ -481,6 +570,7 @@ public class KitItemManager {
kitItem.setBannerData(bannerData); kitItem.setBannerData(bannerData);
kitItem.setBookData(bookData); kitItem.setBookData(bookData);
kitItem.setTrimData(trimData); kitItem.setTrimData(trimData);
kitItem.setCustomModelComponentData(customModelComponentData);
} }
kitItem.setOffhand(offhand); kitItem.setOffhand(offhand);

View file

@ -35,6 +35,7 @@ public class KitItem{
private KitItemBannerData bannerData; private KitItemBannerData bannerData;
private KitItemBookData bookData; private KitItemBookData bookData;
private KitItemTrimData trimData; private KitItemTrimData trimData;
private KitItemCustomModelComponentData customModelComponentData;
private boolean offhand; private boolean offhand;
private int previewSlot; private int previewSlot;
@ -223,6 +224,14 @@ public class KitItem{
this.trimData = trimData; this.trimData = trimData;
} }
public KitItemCustomModelComponentData getCustomModelComponentData() {
return customModelComponentData;
}
public void setCustomModelComponentData(KitItemCustomModelComponentData customModelComponentData) {
this.customModelComponentData = customModelComponentData;
}
public boolean isOffhand() { public boolean isOffhand() {
return offhand; return offhand;
} }
@ -283,6 +292,7 @@ public class KitItem{
kitItem.setBannerData(bannerData != null ? bannerData.clone() : null); kitItem.setBannerData(bannerData != null ? bannerData.clone() : null);
kitItem.setBookData(bookData != null ? bookData.clone() : null); kitItem.setBookData(bookData != null ? bookData.clone() : null);
kitItem.setTrimData(trimData != null ? trimData.clone() : null); kitItem.setTrimData(trimData != null ? trimData.clone() : null);
kitItem.setCustomModelComponentData(customModelComponentData != null ? customModelComponentData.clone() : null);
kitItem.setPreviewSlot(previewSlot); kitItem.setPreviewSlot(previewSlot);
kitItem.setOffhand(offhand); kitItem.setOffhand(offhand);

View file

@ -0,0 +1,54 @@
package pk.ajneb97.model.item;
import java.util.ArrayList;
import java.util.List;
public class KitItemCustomModelComponentData {
private List<String> flags;
private List<String> colors;
private List<String> floats;
private List<String> strings;
public KitItemCustomModelComponentData(List<String> flags, List<String> colors, List<String> floats, List<String> strings) {
this.flags = flags;
this.colors = colors;
this.floats = floats;
this.strings = strings;
}
public List<String> getFlags() {
return flags;
}
public void setFlags(List<String> flags) {
this.flags = flags;
}
public List<String> getColors() {
return colors;
}
public void setColors(List<String> colors) {
this.colors = colors;
}
public List<String> getFloats() {
return floats;
}
public void setFloats(List<String> floats) {
this.floats = floats;
}
public List<String> getStrings() {
return strings;
}
public void setStrings(List<String> strings) {
this.strings = strings;
}
public KitItemCustomModelComponentData clone(){
return new KitItemCustomModelComponentData(new ArrayList<>(flags),new ArrayList<>(colors),new ArrayList<>(floats),new ArrayList<>(strings));
}
}

View file

@ -12,6 +12,8 @@ import pk.ajneb97.libs.actionbar.ActionBarAPI;
import pk.ajneb97.libs.titles.TitleAPI; import pk.ajneb97.libs.titles.TitleAPI;
import pk.ajneb97.managers.MessagesManager; import pk.ajneb97.managers.MessagesManager;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
public class ActionUtils { public class ActionUtils {
@ -31,7 +33,7 @@ public class ActionUtils {
int volume = 0; int volume = 0;
float pitch = 0; float pitch = 0;
try { try {
sound = Sound.valueOf(sep[0]); sound = getSoundByName(sep[0]);
volume = Integer.valueOf(sep[1]); volume = Integer.valueOf(sep[1]);
pitch = Float.valueOf(sep[2]); pitch = Float.valueOf(sep[2]);
}catch(Exception e ) { }catch(Exception e ) {
@ -43,6 +45,16 @@ public class ActionUtils {
player.playSound(player.getLocation(), sound, volume, pitch); player.playSound(player.getLocation(), sound, volume, pitch);
} }
private static Sound getSoundByName(String name){
try {
Class<?> soundTypeClass = Class.forName("org.bukkit.Sound");
Method valueOf = soundTypeClass.getMethod("valueOf", String.class);
return (Sound) valueOf.invoke(null,name);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public static void actionbar(Player player, String actionLine, PlayerKits2 plugin){ public static void actionbar(Player player, String actionLine, PlayerKits2 plugin){
String[] sep = actionLine.split(";"); String[] sep = actionLine.split(";");
String text = sep[0]; String text = sep[0];

View file

@ -618,8 +618,17 @@ public class ItemUtils {
// 1.21+ only // 1.21+ only
public static void addDummyAttribute(ItemMeta meta,PlayerKits2 plugin){ public static void addDummyAttribute(ItemMeta meta,PlayerKits2 plugin){
try{
AttributeModifier modifier = new AttributeModifier(new NamespacedKey(plugin,"dummy_attribute"),0,AttributeModifier.Operation.ADD_NUMBER,EquipmentSlotGroup.FEET); AttributeModifier modifier = new AttributeModifier(new NamespacedKey(plugin,"dummy_attribute"),0,AttributeModifier.Operation.ADD_NUMBER,EquipmentSlotGroup.FEET);
meta.addAttributeModifier(Attribute.GENERIC_GRAVITY, modifier); ServerVersion serverVersion = PlayerKits2.serverVersion;
if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_21_R3)){
meta.addAttributeModifier(Attribute.GRAVITY, modifier);
}else{
meta.addAttributeModifier(getAttributeByName("GENERIC_GRAVITY"), modifier);
}
}catch(Exception ignored){
}
} }
public static KitItemBookData getBookData(ItemStack item){ public static KitItemBookData getBookData(ItemStack item){
@ -752,4 +761,14 @@ public class ItemUtils {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private static Attribute getAttributeByName(String name){
try {
Class<?> attributeTypeClass = Class.forName("org.bukkit.attribute");
Method valueOf = attributeTypeClass.getMethod("valueOf", String.class);
return (Attribute) valueOf.invoke(null,name);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
} }

View file

@ -27,7 +27,8 @@ public enum ServerVersion {
v1_20_R3, v1_20_R3,
v1_20_R4, v1_20_R4,
v1_21_R1, v1_21_R1,
v1_21_R2; v1_21_R2,
v1_21_R3;
public boolean serverVersionGreaterEqualThan(ServerVersion version1,ServerVersion version2){ public boolean serverVersionGreaterEqualThan(ServerVersion version1,ServerVersion version2){
return version1.ordinal() >= version2.ordinal(); return version1.ordinal() >= version2.ordinal();

View file

@ -1,5 +1,5 @@
main: pk.ajneb97.PlayerKits2 main: pk.ajneb97.PlayerKits2
version: 1.13.1 version: 1.14.1
name: PlayerKits2 name: PlayerKits2
api-version: 1.13 api-version: 1.13
softdepend: [Vault,PlaceholderAPI] softdepend: [Vault,PlaceholderAPI]