Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<codex.version>1.1.1-R0.11-SNAPSHOT</codex.version>
<fabled.version>1.0.4-R0.56-SNAPSHOT</fabled.version>
<fabled.version>1.0.4-R0.63-SNAPSHOT</fabled.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public EngineCfg(@NotNull Divinity plugin) throws InvalidConfigurationException
public static boolean ATTRIBUTES_ALLOW_HOLD_REQUIREMENTS;

public static boolean ATTRIBUTES_DURABILITY_BREAK_ITEMS;
public static boolean ATTRIBUTES_HIDE_FLAGS;
public static boolean ATTRIBUTES_DURABILITY_REDUCE_FOR_MOBS;
public static Set<String> ATTRIBUTES_DURABILITY_REDUCE_FOR_SKILL_API;

Expand All @@ -56,6 +57,7 @@ public EngineCfg(@NotNull Divinity plugin) throws InvalidConfigurationException
public static double COMBAT_SHIELD_BLOCK_BONUS_DAMAGE_MOD;
public static int COMBAT_SHIELD_BLOCK_COOLDOWN;
public static boolean LEGACY_COMBAT;
public static boolean FULL_LEGACY;
public static boolean COMBAT_DISABLE_VANILLA_SWEEP;
public static boolean COMBAT_REDUCE_PLAYER_HEALTH_BAR;
public static boolean COMBAT_FISHING_HOOK_DO_DAMAGE;
Expand Down Expand Up @@ -177,6 +179,7 @@ public void setup() {
EngineCfg.ATTRIBUTES_EFFECTIVE_FOR_MOBS = cfg.getBoolean(path + "effective-for-mobs");
EngineCfg.ATTRIBUTES_EFFECTIVE_IN_OFFHAND = cfg.getBoolean(path + "effective-in-offhand");
EngineCfg.ATTRIBUTES_ALLOW_HOLD_REQUIREMENTS = cfg.getBoolean(path + "allow-hold-items-you-cant-use");
EngineCfg.ATTRIBUTES_HIDE_FLAGS = cfg.getBoolean(path + "hide-flags");

path = "attributes.durability.";
EngineCfg.ATTRIBUTES_DURABILITY_BREAK_ITEMS = cfg.getBoolean(path + "break-items-on-zero");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import studio.magemonkey.divinity.api.event.DivinityDamageEvent;
import studio.magemonkey.divinity.api.event.EntityDivinityItemPickupEvent;
import studio.magemonkey.divinity.api.event.EntityEquipmentChangeEvent;
import studio.magemonkey.divinity.config.EngineCfg;
import studio.magemonkey.divinity.modules.api.QModuleDrop;
import studio.magemonkey.divinity.stats.EntityStats;
import studio.magemonkey.divinity.stats.EntityStatsTask;
Expand Down Expand Up @@ -90,6 +91,7 @@ public void shutdown() {

@EventHandler(priority = EventPriority.MONITOR)
public void onStatsDeath(EntityDeathEvent e) {
if(EngineCfg.FULL_LEGACY) return;
LivingEntity entity = e.getEntity();
previousEquipment.remove(e.getEntity().getUniqueId());
EntityStats.get(entity).handleDeath();
Expand All @@ -98,17 +100,20 @@ public void onStatsDeath(EntityDeathEvent e) {
// Clear stats on player exit
@EventHandler(priority = EventPriority.HIGHEST)
public void onStatsQuit(PlayerQuitEvent e) {
if(EngineCfg.FULL_LEGACY) return;
EntityStats.purge(e.getPlayer());
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onStatsJoin(PlayerJoinEvent e) {
if(EngineCfg.FULL_LEGACY) return;
EntityStats.get(e.getPlayer());
this.pushToUpdate(e.getPlayer(), 1D);
}

@EventHandler
public void quit(PlayerQuitEvent event) {
if(EngineCfg.FULL_LEGACY) return;
previousEquipment.remove(event.getPlayer().getUniqueId());
}

Expand All @@ -124,6 +129,7 @@ public void onStatsRegen(EntityRegainHealthEvent e) {

@EventHandler(ignoreCancelled = true)
public void onPickup(EntityPickupItemEvent e) {
if(EngineCfg.FULL_LEGACY) return;
if (!ProjectileStats.isPickable(e.getItem())) {
e.setCancelled(true);
}
Expand All @@ -138,6 +144,7 @@ public void onPickup(EntityPickupItemEvent e) {
}

private final void pushToUpdate(@NotNull LivingEntity entity, double time) {
if(EngineCfg.FULL_LEGACY) return;
EntityEquipment equip = new EntityEquipmentSnapshot(entity);
previousEquipment.put(entity.getUniqueId(), equip);
if (time <= 0D) {
Expand All @@ -153,6 +160,7 @@ public void run() {
}

private final void addDuplicatorFixer(@NotNull Entity entity) {
if(EngineCfg.FULL_LEGACY) return;
entity.setMetadata(PACKET_DUPLICATOR_FIXER, new FixedMetadataValue(plugin, "fixed"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.manager.api.Loadable;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.config.Config;
import studio.magemonkey.divinity.config.EngineCfg;
import studio.magemonkey.divinity.hooks.HookListener;
import studio.magemonkey.divinity.manager.listener.object.*;
import studio.magemonkey.divinity.stats.items.ItemStats;
Expand Down Expand Up @@ -45,8 +47,13 @@ public void setup() {
this.lisDynamic = new DynamicStatListener(this.plugin);
this.lisDynamic.registerListeners();

this.lisQuantum = new VanillaWrapperListener(this.plugin);
this.lisQuantum.registerListeners();
if(!EngineCfg.LEGACY_COMBAT) {
this.lisQuantum = new VanillaWrapperListener(this.plugin);
this.lisQuantum.registerListeners();
Divinity.getInstance().getLogger().info("Loaded " + this.lisQuantum.getClass().getSimpleName());
} else {
Divinity.getInstance().getLogger().info("Skipped " + VanillaWrapperListener.class.getSimpleName() + " due to legacy combat being enabled.");
}

this.updater = new ItemUpdaterListener(this.plugin);
this.updater.registerListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jetbrains.annotations.Nullable;
import studio.magemonkey.codex.manager.IListener;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.config.EngineCfg;
import studio.magemonkey.divinity.stats.items.ItemStats;
import studio.magemonkey.divinity.stats.items.api.DynamicStat;

Expand All @@ -27,19 +28,22 @@ public DynamicStatListener(@NotNull Divinity plugin) {
}

public static void updateItem(@Nullable Player p, @NotNull ItemStack item) {
if(EngineCfg.FULL_LEGACY) return;
for (DynamicStat<?> dynamicStat : ItemStats.getDynamicStats()) {
dynamicStat.updateItem(p, item);
}
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDrop(PlayerDropItemEvent e) {
if(EngineCfg.FULL_LEGACY) return;
ItemStack item = e.getItemDrop().getItemStack();
updateItem(null, item);
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPick(EntityPickupItemEvent e) {
if(EngineCfg.FULL_LEGACY) return;
LivingEntity entity = e.getEntity();
if (!(entity instanceof Player)) return;

Expand All @@ -50,6 +54,7 @@ public void onPick(EntityPickupItemEvent e) {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInvOpen(InventoryOpenEvent e) {
if(EngineCfg.FULL_LEGACY) return;
List<ItemStack> list = new ArrayList<>();
Player player = (Player) e.getPlayer();

Expand All @@ -64,6 +69,7 @@ public void onInvOpen(InventoryOpenEvent e) {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInvClose(InventoryCloseEvent e) {
if(EngineCfg.FULL_LEGACY) return;
Player player = (Player) e.getPlayer();

List<ItemStack> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import studio.magemonkey.codex.manager.IListener;
import studio.magemonkey.codex.util.DataUT;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.config.EngineCfg;
import studio.magemonkey.divinity.stats.items.ItemStats;

public class ItemUpdaterListener extends IListener<Divinity> {
Expand Down Expand Up @@ -93,6 +94,7 @@ public void join(PlayerJoinEvent event) {
}

public void update(ItemStack item, @Nullable Player player) {
if(EngineCfg.LEGACY_COMBAT ||EngineCfg.FULL_LEGACY) return;
if (item == null || item.getType() == Material.AIR) return;

ItemType itemType = CodexEngine.get().getItemManager().getMainItemType(item);
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/studio/magemonkey/divinity/modules/ModuleItem.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package studio.magemonkey.divinity.modules;

import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
Expand Down Expand Up @@ -135,16 +137,25 @@ public ModuleItem(@NotNull Divinity plugin, @NotNull JYML cfg, @NotNull QModuleD

this.attributes = new HashMap<>();
for (String attr : cfg.getSection("attributes")) {
String[] attrData = cfg.getString("attributes." + attr, "").split(":");
double value = Double.parseDouble(attrData[0]);
String operation = attrData.length > 1 ? attrData[1] : "ADD_NUMBER";
NBTAttribute nbtAttr = NBTAttribute.valueOf(attr.toUpperCase());
AttributeModifier attrModifier = VersionManager.getCompat()
.createAttributeModifier(nbtAttr, value, AttributeModifier.Operation.valueOf(operation));
String[] attrData = cfg.getString("attributes." + attr, "").split(":");
double value = Double.parseDouble(attrData[0]);
String operation = attrData.length > 1 ? attrData[1] : "ADD_NUMBER";
String equipmentSlot = attrData.length > 2 ? attrData[2] : null;
NBTAttribute nbtAttr = NBTAttribute.valueOf(attr.toUpperCase());

// Check attribute through compat support
AttributeModifier attrModifier = VersionManager.getCompat().createAttributeModifier(nbtAttr, value, AttributeModifier.Operation.valueOf(operation));
if (attrModifier == null) {
Codex.warn("Invalid attribute provided: " + attr + " (" + cfg.getFile().getName() + ")");
continue;
}
// If everything was fine and equipmentslot != null, recreate the modifier including the equipment slot
if(equipmentSlot != null) {
EquipmentSlot slot = EquipmentSlot.valueOf(equipmentSlot.toUpperCase());
attrModifier = new AttributeModifier(attrModifier.getUniqueId(), attrModifier.getName(), attrModifier.getAmount(), attrModifier.getOperation(), slot);
// Debug
Bukkit.getLogger().info("Registered attribute " + nbtAttr.name() + " with value " + value + ", operation " + operation + " and equipment slot " + equipmentSlot + " for item " + this.getId());
}
this.attributes.put(nbtAttr.getAttribute(), attrModifier);
}

Expand Down Expand Up @@ -277,6 +288,7 @@ protected ItemStack build(@NotNull ItemStack item) {

for (Map.Entry<Attribute, AttributeModifier> attribute : this.attributes.entrySet()) {
if (attribute != null) {
AttributeModifier mod = new AttributeModifier(attribute.getValue().getName(), attribute.getValue().getAmount(), attribute.getValue().getOperation());
meta.addAttributeModifier(attribute.getKey(), attribute.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ private void updateInventory() {
}

public void updateAll() {
if(EngineCfg.LEGACY_COMBAT) return;
if (!EngineCfg.ATTRIBUTES_EFFECTIVE_FOR_MOBS && !this.isPlayer()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import studio.magemonkey.codex.modules.IModule;
import studio.magemonkey.codex.util.DataUT;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.config.EngineCfg;
import studio.magemonkey.divinity.modules.api.QModuleDrop;
import studio.magemonkey.divinity.stats.items.api.DuplicableItemLoreStat;
import studio.magemonkey.divinity.stats.items.api.DynamicStat;
Expand Down Expand Up @@ -307,6 +308,8 @@ public static boolean hasStat(@NotNull ItemStack item, @Nullable Player player,
// ----------------------------------------------------------------- //

public static void updateVanillaAttributes(@NotNull ItemStack item, @Nullable Player player) {
if(EngineCfg.FULL_LEGACY || EngineCfg.LEGACY_COMBAT) return;

addAttribute(item, player, NBTAttribute.MAX_HEALTH, getStat(item, player, TypedStat.Type.MAX_HEALTH));
addAttribute(item, player, NBTAttribute.MOVEMENT_SPEED, getStat(item, player, TypedStat.Type.MOVEMENT_SPEED));
addAttribute(item, player, NBTAttribute.ATTACK_SPEED, getStat(item, player, TypedStat.Type.ATTACK_SPEED));
Expand Down Expand Up @@ -344,6 +347,7 @@ private static void addAttribute(@NotNull ItemStack item,
@Nullable Player player,
@NotNull NBTAttribute att,
double value) {
//if(EngineCfg.LEGACY_COMBAT) return;
ItemMeta meta = item.getItemMeta();
if (meta == null) return;

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ attributes:
# When enabled, allows to hold in hand items with requirements that player don't meet.
# Even when this is 'true', item attributes won't be applied to a player until he meet the requirements.
allow-hold-items-you-cant-use: false
# When enabled, hides attributes and enchantments by default on all custom items.
hide-flags: true

combat:
# Whether to use the old combat formula for calculating defenses
Expand Down