Skip to content

Commit

Permalink
More 1.20.6 tweaks and backward compatibility tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Travja committed Jun 1, 2024
1 parent a1807f4 commit 824234f
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 60 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<description>Custom items, combat, and more!</description>

<properties>
<codex.version>1.0.0-R0.9-SNAPSHOT</codex.version>
<codex.version>1.0.0-R0.14-SNAPSHOT</codex.version>
<fabled.version>1.0.0-R0.21-SNAPSHOT</fabled.version>
</properties>

Expand All @@ -38,6 +38,10 @@
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class DependencyRequirement {

public static final String MIN_CORE_VERSION = "1.0.0-R0.1-SNAPSHOT";
public static final String MIN_CORE_VERSION = "1.0.0-R0.14-SNAPSHOT";

public static boolean meetsVersion(String requiredVersion, String providedVersion) {
List<Integer> required = splitVersion(requiredVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void perform(CommandSender sender, String label, String[] args) {
}
} else if (args.length == 4 && args[1].equalsIgnoreCase(ARGS[4])) { // Enchant
String ench = args[2].toLowerCase();
Enchantment e = Enchantment.getByKey(NamespacedKey.minecraft(ench));
Enchantment e = Enchantment.getByName(ench);
if (e == null) {
plugin.lang().Error_InvalidArgument.replace("%arg%", ench).send(p);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import studio.magemonkey.codex.manager.IListener;
import studio.magemonkey.codex.registry.damage.DamageTypeProvider;
import studio.magemonkey.codex.util.LocUT;
import studio.magemonkey.codex.util.NamespaceResolver;
import studio.magemonkey.codex.util.random.Rnd;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.api.PartyAPI;
Expand Down Expand Up @@ -390,7 +391,8 @@ private void applyShieldDamage(Player player) {

ItemMeta shieldMeta = shield.getItemMeta();
int level =
shieldMeta.getEnchantLevel(Enchantment.getByKey(NamespacedKey.minecraft("unbreaking"))); // DURABILITY/UNBREAKING
shieldMeta.getEnchantLevel(NamespaceResolver.getEnchantment("UNBREAKING",
"DURABILITY")); // DURABILITY/UNBREAKING
if (Rnd.get(true) <= (100d / (level + 1))) {
if (shieldMeta instanceof Damageable) {
((Damageable) shieldMeta).setDamage(((Damageable) shieldMeta).getDamage() + 1);
Expand Down Expand Up @@ -472,23 +474,28 @@ private double getEnchantModifier(@NotNull LivingEntity zertva, @NotNull DamageC
EntityStats stats = EntityStats.get(zertva);

double epfAll =
stats.getEnchantProtectFactor(Enchantment.getByKey(NamespacedKey.minecraft("protection"))); // PROTECTION_ENVIRONMENTAL/PROTECTION
stats.getEnchantProtectFactor(NamespaceResolver.getEnchantment("PROTECTION",
"PROTECTION_ENVIRONMENTAL")); // PROTECTION_ENVIRONMENTAL/PROTECTION
double epfSpec = 0D;
double epfMod = 1D;

if (cause == DamageCause.FIRE || cause == DamageCause.FIRE_TICK
|| cause == DamageCause.LAVA) {
epfSpec =
stats.getEnchantProtectFactor(Enchantment.getByKey(NamespacedKey.minecraft("fire_protection"))); // PROTECTION_FIRE/FIRE_PROTECTION
stats.getEnchantProtectFactor(NamespaceResolver.getEnchantment("FIRE_PROTECTION",
"PROTECTION_FIRE")); // PROTECTION_FIRE/FIRE_PROTECTION
} else if (cause == DamageCause.FALL) {
epfSpec =
stats.getEnchantProtectFactor(Enchantment.getByKey(NamespacedKey.minecraft("feather_falling"))); // PROTECTION_FALL/FEATHER_FALLING
stats.getEnchantProtectFactor(NamespaceResolver.getEnchantment("FEATHER_FALLING",
"PROTECTION_FALL")); // PROTECTION_FALL/FEATHER_FALLING
} else if (cause == DamageCause.PROJECTILE) {
epfSpec =
stats.getEnchantProtectFactor(Enchantment.getByKey(NamespacedKey.minecraft("projectile_protection"))); // PROTECTION_PROJECTILE/PROJECTILE_PROTECTION
stats.getEnchantProtectFactor(NamespaceResolver.getEnchantment("PROJECTILE_PROTECTION",
"PROTECTION_PROJECTILE")); // PROTECTION_PROJECTILE/PROJECTILE_PROTECTION
} else if (cause == DamageCause.BLOCK_EXPLOSION || cause == DamageCause.ENTITY_EXPLOSION) {
epfSpec =
stats.getEnchantProtectFactor(Enchantment.getByKey(NamespacedKey.minecraft("blast_protection"))); // PROTECTION_EXPLOSION/BLAST_PROTECTION
stats.getEnchantProtectFactor(NamespaceResolver.getEnchantment("BLAST_PROTECTION",
"PROTECTION_EXPLOSION")); // PROTECTION_EXPLOSION/BLAST_PROTECTION
}
epfMod = Math.min(20D, (epfSpec + epfAll));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package studio.magemonkey.divinity.manager.effects.main;

import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.util.NamespaceResolver;
import studio.magemonkey.divinity.manager.effects.IEffectType;
import studio.magemonkey.divinity.manager.effects.IPeriodicEffect;

Expand Down Expand Up @@ -58,7 +57,7 @@ public static class Builder extends IPeriodicEffect.Builder<Builder> {

public Builder(double lifeTime) {
super(lifeTime, 1D / 20D);
this.addPotionEffects(new PotionEffect(PotionEffectType.getByKey(NamespacedKey.minecraft("slowness")),
this.addPotionEffects(new PotionEffect(NamespaceResolver.getPotion("SLOWNESS", "SLOW"),
(int) (lifeTime * 20),
127)); // SLOWNESS/SLOW
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package studio.magemonkey.divinity.manager.effects.main;

import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.util.NamespaceResolver;
import studio.magemonkey.divinity.manager.effects.IEffectType;
import studio.magemonkey.divinity.manager.effects.IPeriodicEffect;

Expand Down Expand Up @@ -56,10 +56,10 @@ public static class Builder extends IPeriodicEffect.Builder<Builder> {
public Builder(double lifeTime) {
super(lifeTime, 1D / 20D);

this.addPotionEffects(new PotionEffect(PotionEffectType.getByKey(NamespacedKey.minecraft("slowness")),
this.addPotionEffects(new PotionEffect(NamespaceResolver.getPotion("SLOWNESS", "SLOW"),
(int) (lifeTime * 20),
127)); // SLOW/SLOWNESS
this.addPotionEffects(new PotionEffect(PotionEffectType.getByKey(NamespacedKey.minecraft("mining_fatigue")),
this.addPotionEffects(new PotionEffect(NamespaceResolver.getPotion("SLOW_DIGGING", "MINING_FATIGUE"),
(int) (lifeTime * 20),
127)); // SLOW_DIGGING/MINING_FATIGUE
this.addPotionEffects(new PotionEffect(PotionEffectType.BLINDNESS, (int) lifeTime * 20, 127));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void setup() {

for (String sId : cfg.getSection(path + "by-enchant-level")) {
try {
Enchantment e = Enchantment.getByKey(NamespacedKey.minecraft(sId.toLowerCase()));
Enchantment e = Enchantment.getByName(sId.toLowerCase());
if (e == null) {
this.plugin.error("[Worth] Invalid Enchantment '" + sId + "' !");
continue;
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/studio/magemonkey/divinity/modules/ModuleItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package studio.magemonkey.divinity.modules;

import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.CodexEngine;
import studio.magemonkey.codex.config.api.JYML;
import studio.magemonkey.codex.items.ItemType;
Expand All @@ -8,6 +20,7 @@
import studio.magemonkey.codex.items.providers.VanillaProvider;
import studio.magemonkey.codex.manager.LoadableItem;
import studio.magemonkey.codex.util.ItemUT;
import studio.magemonkey.codex.util.NamespaceResolver;
import studio.magemonkey.codex.util.StringUT;
import studio.magemonkey.codex.util.constants.JStrings;
import studio.magemonkey.codex.util.random.Rnd;
Expand All @@ -20,25 +33,12 @@
import studio.magemonkey.divinity.stats.items.requirements.ItemRequirements;
import studio.magemonkey.divinity.stats.items.requirements.user.UntradeableRequirement;
import studio.magemonkey.divinity.utils.LoreUT;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;

import java.util.*;

public abstract class ModuleItem extends LoadableItem {
protected final QModuleDrop<?> module;
protected Divinity plugin;
protected final QModuleDrop<?> module;
protected Divinity plugin;
protected String name;
protected ItemType material;
protected List<String> lore;
Expand Down Expand Up @@ -116,7 +116,7 @@ public ModuleItem(@NotNull Divinity plugin, @NotNull JYML cfg, @NotNull QModuleD

this.enchants = new HashMap<>();
for (String sId : cfg.getSection("enchantments")) {
Enchantment en = Enchantment.getByKey(NamespacedKey.minecraft(sId.toLowerCase()));
Enchantment en = Enchantment.getByName(sId.toLowerCase());
if (en == null) {
plugin.error("Invalid enchantment provided: " + sId + " (" + cfg.getFile().getName() + ")");
continue;
Expand Down Expand Up @@ -234,7 +234,7 @@ protected ItemStack build(@NotNull ItemStack item) {
meta.addItemFlags(this.flags.toArray(new ItemFlag[this.flags.size()]));
meta.setUnbreakable(this.isUnbreakable);
if (this.enchanted) {
meta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft("punch")), 1, true); // ARROW_DAMAGE/PUNCH
meta.addEnchant(NamespaceResolver.getEnchantment("POWER", "ARROW_DAMAGE"), 1, true); // ARROW_DAMAGE/POWER
}

item.setItemMeta(meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
Expand All @@ -18,6 +16,7 @@
import studio.magemonkey.codex.config.api.JYML;
import studio.magemonkey.codex.manager.api.task.ITask;
import studio.magemonkey.codex.util.ItemUT;
import studio.magemonkey.codex.util.NamespaceResolver;
import studio.magemonkey.codex.util.StringUT;
import studio.magemonkey.codex.util.actions.ActionManipulator;
import studio.magemonkey.divinity.Divinity;
Expand Down Expand Up @@ -143,7 +142,8 @@ public void onQuantumArrowLaunch(DivinityProjectileLaunchEvent e) {

ItemStack bow = e.getWeapon();
if (e.isBowEvent() && !this.generalAllowInfinity && bow != null) {
if (bow.containsEnchantment(Enchantment.getByKey(NamespacedKey.minecraft("infinity")))) { // ARROW_INFINITE/INFINITY
if (bow.containsEnchantment(NamespaceResolver.getEnchantment("INFINITY",
"ARROW_INFINITE"))) { // ARROW_INFINITE/INFINITY
arrow.setAmount(arrow.getAmount() - 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
Expand All @@ -15,10 +14,7 @@
import studio.magemonkey.codex.config.api.JYML;
import studio.magemonkey.codex.hooks.external.VaultHK;
import studio.magemonkey.codex.manager.api.gui.*;
import studio.magemonkey.codex.util.DataUT;
import studio.magemonkey.codex.util.ItemUT;
import studio.magemonkey.codex.util.NumberUT;
import studio.magemonkey.codex.util.StringUT;
import studio.magemonkey.codex.util.*;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.api.DivinityAPI;
import studio.magemonkey.divinity.modules.api.socketing.ModuleSocket;
Expand Down Expand Up @@ -165,14 +161,16 @@ public void open(
for (int socketSlot : socketSlots) {
ItemStack socketItem = inv.getItem(socketSlot);
if (socketItem != null) {
socketItem.removeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft("punch"))); // ARROW_DAMAGE/PUNCH
socketItem.removeEnchantment(NamespaceResolver.getEnchantment("POWER",
"ARROW_DAMAGE")); // ARROW_DAMAGE/POWER
}
}

// Add glow to selected socket item
ItemStack item1 = e.getCurrentItem();
if (item1 != null) {
item1.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft("punch")), 1); // ARROW_DAMAGE/PUNCH
item1.addUnsafeEnchantment(NamespaceResolver.getEnchantment("POWER", "ARROW_DAMAGE"),
1); // ARROW_DAMAGE/POWER
}

ItemStack target1 = getItem(inv, itemSlot);
Expand Down Expand Up @@ -242,7 +240,8 @@ else if (e.isRightClick()) {
Enum<?> type2 = guiItem.getType();
if (type2 != null && type2 == type) {
ItemStack itemGlow = guiItem.getItem();
itemGlow.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft("punch")), 1); // ARROW_DAMAGE/PUNCH
itemGlow.addUnsafeEnchantment(NamespaceResolver.getEnchantment("POWER", "ARROW_DAMAGE"),
1); // ARROW_DAMAGE/POWER
DataUT.setData(itemGlow, META_KEY_SOCKET_SELECT, "true");
JIcon active = new JIcon(itemGlow);
active.setClick(guiItem.getClick());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public GeneratorItem(@NotNull Divinity plugin, @NotNull JYML cfg) {
this.enchantsSafeLevels = cfg.getBoolean(path + "safe-levels");
this.enchantsList = new HashMap<>();
for (String sId : cfg.getSection(path + "list")) {
Enchantment en = Enchantment.getByKey(NamespacedKey.minecraft(sId.toLowerCase()));
Enchantment en = Enchantment.getByName(sId.toLowerCase());
if (en == null) {
error("Invalid enchantment provided: " + sId + " (" + cfg.getFile().getName() + ")");
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
Expand All @@ -16,6 +15,7 @@
import studio.magemonkey.codex.manager.api.gui.*;
import studio.magemonkey.codex.util.DataUT;
import studio.magemonkey.codex.util.ItemUT;
import studio.magemonkey.codex.util.NamespaceResolver;
import studio.magemonkey.divinity.Divinity;

import java.util.HashSet;
Expand Down Expand Up @@ -146,8 +146,8 @@ public void open(
ItemStack itemGlow = guiItem.getItem();
this.replaceCostHave(player, target, itemGlow, repairType);
if (type2 == type) {
itemGlow.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft("punch")),
1); // ARROW_DAMAGE/PUNCH
itemGlow.addUnsafeEnchantment(NamespaceResolver.getEnchantment("POWER", "ARROW_DAMAGE"),
1); // ARROW_DAMAGE/POWER
DataUT.setData(itemGlow, META_KEY_REPAIR_SELECT, "true");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import studio.magemonkey.divinity.data.api.UserProfile;
import studio.magemonkey.divinity.manager.EntityManager;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -148,8 +149,11 @@ protected void managePlayerHelmet(@NotNull EnginePlayerPacketEvent e, @NotNull O

@Override
protected void manageDamageParticle(@NotNull EnginePlayerPacketEvent e, @NotNull Object packet) {
Class packetParticlesClass = Reflex.getClass(PACKET_LOCATION, "PacketPlayOutWorldParticles");
Class particleParamClass = Reflex.getClass("net.minecraft.core.particles", "ParticleParam");
Class<?> packetParticlesClass = Reflex.getClass(PACKET_LOCATION, "PacketPlayOutWorldParticles");
Class<?> particleParamClass = Reflex.getClass("net.minecraft.core.particles", "ParticleParam");

Class<?> registries = Reflex.getClass("net.minecraft.core.registries.BuiltInRegistries");
Object particleRegistry = Reflex.getFieldValue(registries, "j");

Object p = packetParticlesClass.cast(packet);

Expand All @@ -158,9 +162,21 @@ protected void manageDamageParticle(@NotNull EnginePlayerPacketEvent e, @NotNull

Method a = Reflex.getMethod(particleParamClass, "a"); //Get the namespace key of the particle being sent

String name = (String) Reflex.invokeMethod(a, particleParam);
if (name.contains("damage_indicator")) {
Reflex.setFieldValue(p, "i", 20);
try {
Object particleType = Reflex.invokeMethod(a, particleParam);
String mcKey = "minecraft:damage_indicator";
Class<?> keyClass = Reflex.getClass("net.minecraft.resources.MinecraftKey");
Object key = Reflex.getConstructor(keyClass, String.class).newInstance(mcKey);
Object damageIndicator = Reflex.invokeMethod(
Reflex.getMethod(particleRegistry.getClass(), "a", keyClass),
particleRegistry,
key
);
if (particleType.equals(damageIndicator)) {
Reflex.setFieldValue(p, "i", 20); // This is the count
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Loading

0 comments on commit 824234f

Please sign in to comment.