mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-01-23 00:31:20 +01:00
Added 1.17 support and updated to Java 16
This commit is contained in:
parent
f12a2f7813
commit
bde29c9120
13
build.gradle
13
build.gradle
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'com.github.johnrengelman.shadow' version '5.2.0'
|
||||
id 'com.github.johnrengelman.shadow' version '7.0.0'
|
||||
id 'maven-publish'
|
||||
id 'java'
|
||||
}
|
||||
@ -16,7 +16,6 @@ allprojects {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
||||
@ -53,11 +52,11 @@ allprojects {
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.20'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.20'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
@ -96,7 +95,7 @@ jar {
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = findProperty("version")
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
java.sourceCompatibility = JavaVersion.VERSION_16
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
|
6
eco-core/core-nms/v1_17_R1/build.gradle
Normal file
6
eco-core/core-nms/v1_17_R1/build.gradle
Normal file
@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments;
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy;
|
||||
import com.willfp.ecoenchants.proxy.v1_17_R1.enchants.EcoCraftEnchantment;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class EcoCraftEnchantmentManager implements EcoCraftEnchantmentManagerProxy {
|
||||
@Override
|
||||
public void registerNewCraftEnchantments() {
|
||||
Map<org.bukkit.enchantments.Enchantment, VanillaEnchantmentMetadata> metadataMap = VanillaEnchantments.getMetadataMap();
|
||||
|
||||
for (Enchantment enchantment : IRegistry.X) {
|
||||
NamespacedKey key = CraftNamespacedKey.fromMinecraft(IRegistry.X.getKey(enchantment));
|
||||
VanillaEnchantmentMetadata metadata = metadataMap.get(org.bukkit.enchantments.Enchantment.getByKey(key));
|
||||
new EcoCraftEnchantment(enchantment, metadata).register();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.item.ItemEnchantedBook;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantmentsOnItem(@NotNull final ItemStack itemStack,
|
||||
final boolean checkStored) {
|
||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = checkStored && itemStack.getType() == Material.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments();
|
||||
HashMap<Enchantment, Integer> foundEnchantments = new HashMap<>();
|
||||
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
int level = '\uffff' & compound.getShort("lvl");
|
||||
|
||||
Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key));
|
||||
if (found != null) {
|
||||
foundEnchantments.put(found, level);
|
||||
}
|
||||
}
|
||||
return foundEnchantments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevelOnItem(@NotNull final ItemStack itemStack,
|
||||
@NotNull final Enchantment enchantment,
|
||||
final boolean checkStored) {
|
||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = checkStored && itemStack.getType() == Material.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments();
|
||||
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
if (!key.equals(enchantment.getKey().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return '\uffff' & compound.getShort("lvl");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class OpenInventory implements OpenInventoryProxy {
|
||||
@Override
|
||||
public Object getOpenInventory(@NotNull final Player player) {
|
||||
return ((CraftPlayer) player).getHandle().bV;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class RepairCost implements RepairCostProxy {
|
||||
@Override
|
||||
public ItemStack setRepairCost(@NotNull final ItemStack itemStack,
|
||||
final int cost) {
|
||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
nmsStack.setRepairCost(cost);
|
||||
return CraftItemStack.asBukkitCopy(nmsStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRepairCost(@NotNull final ItemStack itemStack) {
|
||||
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
return nmsStack.getRepairCost();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1.enchants;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.enchantments.CraftEnchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EcoCraftEnchantment extends CraftEnchantment {
|
||||
private final VanillaEnchantmentMetadata metadata;
|
||||
|
||||
public EcoCraftEnchantment(@NotNull final Enchantment target,
|
||||
@NotNull final VanillaEnchantmentMetadata metadata) {
|
||||
super(target);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return metadata.getMaxLevel() == null ? this.getHandle().getMaxLevel() : metadata.getMaxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
|
||||
return EcoEnchants.getFromEnchantment(other) == null ? super.conflictsWith(other) : other.conflictsWith(other);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey");
|
||||
Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName");
|
||||
byIdField.setAccessible(true);
|
||||
byNameField.setAccessible(true);
|
||||
Map<NamespacedKey, org.bukkit.enchantments.Enchantment> byKey = (Map<NamespacedKey, org.bukkit.enchantments.Enchantment>) byIdField.get(null);
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byName = (Map<String, org.bukkit.enchantments.Enchantment>) byNameField.get(null);
|
||||
byKey.remove(this.getKey());
|
||||
byName.remove(this.getName());
|
||||
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for (Map.Entry<String, org.bukkit.enchantments.Enchantment> entry : byNameClone.entrySet()) {
|
||||
if (entry.getValue().getKey().equals(this.getKey())) {
|
||||
byName.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew");
|
||||
f.setAccessible(true);
|
||||
f.set(null, true);
|
||||
f.setAccessible(false);
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(this);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -6,6 +6,7 @@ include ':eco-core:core-nms'
|
||||
include ':eco-core:core-nms:v1_16_R1'
|
||||
include ':eco-core:core-nms:v1_16_R2'
|
||||
include ':eco-core:core-nms:v1_16_R3'
|
||||
include ':eco-core:core-nms:v1_17_R1'
|
||||
include ':eco-core:core-proxy'
|
||||
include ':eco-core:core-plugin'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user