This commit is contained in:
Ajneb97 2024-03-06 18:56:20 -03:00
parent 2e4d073004
commit 5cb48102c2
8 changed files with 101 additions and 7 deletions

15
pom.xml
View file

@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@ -31,9 +31,19 @@
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
@ -74,6 +84,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<release>8</release>
</configuration>
</plugin>
<plugin>

View file

@ -1,6 +1,5 @@
package pk.ajneb97.configs;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import pk.ajneb97.PlayerKits2;
import pk.ajneb97.model.PlayerData;

View file

@ -11,6 +11,7 @@ public class DependencyManager {
private boolean isPlaceholderAPI;
private Economy vaultEconomy;
private boolean isPaper;
public DependencyManager(PlayerKits2 plugin){
this.plugin = plugin;
@ -24,6 +25,12 @@ public class DependencyManager {
vaultEconomy = rsp.getProvider();
}
}
try{
Class.forName("com.destroystokyo.paper.ParticleBuilder");
isPaper = true;
}catch(Exception e){
}
}
public boolean isPlaceholderAPI() {
@ -33,4 +40,8 @@ public class DependencyManager {
public Economy getVaultEconomy() {
return vaultEconomy;
}
public boolean isPaper() {
return isPaper;
}
}

View file

@ -1,6 +1,9 @@
package pk.ajneb97.managers;
import com.destroystokyo.paper.Namespaced;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -82,6 +85,23 @@ public class KitItemManager {
kitItem.setBookEnchants(enchantsList);
}
}
if(plugin.getDependencyManager().isPaper()){
List<String> canDestroy = new ArrayList<>();
for(Namespaced n : meta.getDestroyableKeys()){
canDestroy.add(n.getNamespace()+":"+n.getKey());
}
if(!canDestroy.isEmpty()){
kitItem.setCanDestroy(canDestroy);
}
List<String> canPlace = new ArrayList<>();
for(Namespaced n : meta.getPlaceableKeys()){
canPlace.add(n.getNamespace()+":"+n.getKey());
}
if(!canPlace.isEmpty()){
kitItem.setCanPlace(canPlace);
}
}
}
List<String> nbtList = ItemUtils.getNBT(plugin,item);
@ -147,6 +167,28 @@ public class KitItemManager {
meta.addItemFlags(ItemFlag.valueOf(flags.get(i)));
}
}
if(plugin.getDependencyManager().isPaper()){
List<String> canDestroy = kitItem.getCanDestroy();
if(canDestroy != null && !canDestroy.isEmpty()){
Collection<Namespaced> destroyableKeys = new ArrayList<>();
for(String line : canDestroy){
String[] sep = line.split(":");
destroyableKeys.add(new NamespacedKey(sep[0],sep[1]));
}
meta.setDestroyableKeys(destroyableKeys);
}
List<String> canPlace = kitItem.getCanPlace();
if(canPlace != null && !canPlace.isEmpty()){
Collection<Namespaced> placeableKeys = new ArrayList<>();
for(String line : canPlace){
String[] sep = line.split(":");
placeableKeys.add(new NamespacedKey(sep[0],sep[1]));
}
meta.setPlaceableKeys(placeableKeys);
}
}
item.setItemMeta(meta);
//OTHER META
@ -229,6 +271,12 @@ public class KitItemManager {
if(item.getBookEnchants() != null && !item.getBookEnchants().isEmpty()) {
config.set(path+".book_enchants", item.getBookEnchants());
}
if(item.getCanPlace() != null && !item.getCanPlace().isEmpty()) {
config.set(path+".can_place", item.getCanPlace());
}
if(item.getCanDestroy() != null && !item.getCanDestroy().isEmpty()) {
config.set(path+".can_destroy", item.getCanDestroy());
}
KitItemSkullData skullData = item.getSkullData();
if(skullData != null) {
@ -304,6 +352,8 @@ public class KitItemManager {
List<String> bookEnchants = config.contains(path+".book_enchants") ? config.getStringList(path+".book_enchants") : null;
List<String> nbtList = config.contains(path+".nbt") ? config.getStringList(path+".nbt") : null;
List<String> attributes = config.contains(path+".attributes") ? config.getStringList(path+".attributes") : 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;
boolean offhand = config.contains(path+".offhand") ? config.getBoolean(path+".offhand") : false;
int previewSlot = config.contains(path+".preview_slot") ? config.getInt(path+".preview_slot") : -1;
@ -416,6 +466,8 @@ public class KitItemManager {
kitItem.setBookEnchants(bookEnchants);
kitItem.setNbt(nbtList);
kitItem.setAttributes(attributes);
kitItem.setCanPlace(canPlace);
kitItem.setCanDestroy(canDestroy);
kitItem.setSkullData(skullData);
kitItem.setPotionData(potionData);
kitItem.setFireworkData(fireworkData);

View file

@ -20,6 +20,10 @@ public class KitItem{
//<name>;<operation>;<amount>;<uuid>;<slot>
private List<String> attributes;
//For Paper only
private List<String> canDestroy;
private List<String> canPlace;
private KitItemSkullData skullData;
private KitItemPotionData potionData;
private KitItemFireworkData fireworkData;
@ -151,6 +155,22 @@ public class KitItem{
this.attributes = attributes;
}
public List<String> getCanDestroy() {
return canDestroy;
}
public void setCanDestroy(List<String> canDestroy) {
this.canDestroy = canDestroy;
}
public List<String> getCanPlace() {
return canPlace;
}
public void setCanPlace(List<String> canPlace) {
this.canPlace = canPlace;
}
public KitItemFireworkData getFireworkData() {
return fireworkData;
}
@ -224,6 +244,8 @@ public class KitItem{
kitItem.setColor(color);
kitItem.setNbt(nbt != null ? new ArrayList<>(nbt) : null);
kitItem.setAttributes(attributes != null ? new ArrayList<>(attributes) : null);
kitItem.setCanDestroy(canDestroy != null ? new ArrayList<>(canDestroy) : null);
kitItem.setCanDestroy(canPlace != null ? new ArrayList<>(canPlace) : null);
kitItem.setSkullData(skullData != null ? skullData.clone() : null);
kitItem.setPotionData(potionData != null ? potionData.clone() : null);

View file

@ -34,7 +34,6 @@ import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;
import pk.ajneb97.PlayerKits2;
import pk.ajneb97.model.item.*;
import sun.misc.BASE64Decoder;
public class ItemUtils {

View file

@ -194,11 +194,11 @@ public class NMSManager {
"ench", "HideFlags", "display", "SkullOwner", "AttributeModifiers", "Enchantments",
"Damage", "CustomModelData", "Potion", "StoredEnchantments", "CustomPotionColor",
"CustomPotionEffects", "Fireworks", "Explosion", "pages", "title", "author", "resolved",
"generation", "Trim", "custom_potion_effects"
"generation", "Trim", "custom_potion_effects", "CanPlaceOn", "CanDestroy"
));
for(String t : tags) {
if(!notTags.contains(t)) {
if(t.equals("BlockEntityTag") && !item.getType().name().contains("SHULKER")){
if(t.equals("BlockEntityTag") && !item.getType().name().contains("SHULKER") && !item.getType().name().contains("CHEST")){
continue;
}
if((boolean)version.getMethodRef("hasKeyOfType").invoke(compound,t,1)) {

View file

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