Skip to content

Commit

Permalink
Work out some combat-log tweaks with SAPI fake damage events
Browse files Browse the repository at this point in the history
  • Loading branch information
Travja committed Feb 25, 2024
1 parent 6c66bbf commit 5c70f9e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<properties>
<promccore.version>1.2.0-R0.7-SNAPSHOT</promccore.version>
<promccore.version>1.2.0-R0.12-SNAPSHOT</promccore.version>
<proskillapi.version>1.3.0-R0.1-SNAPSHOT</proskillapi.version>
</properties>

Expand Down Expand Up @@ -70,6 +70,7 @@
<dependency>
<groupId>com.promcteam</groupId>
<artifactId>proskillapi</artifactId>
<version>1.3.0-R0.16-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package su.nightexpress.quantumrpg.manager.listener.object;

import com.sucy.skill.api.DefaultCombatProtection;
import mc.promcteam.engine.hooks.Hooks;
import mc.promcteam.engine.manager.IListener;
import mc.promcteam.engine.registry.attribute.AttributeRegistry;
Expand Down Expand Up @@ -129,6 +130,11 @@ public void onVanillaProjectLaunch(ProjectileLaunchEvent e) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVanillaDamage(EntityDamageEvent e) {
boolean isEde = e instanceof EntityDamageByEntityEvent;
if (isEde) {
EntityDamageByEntityEvent ede = (EntityDamageByEntityEvent) e;
if (DefaultCombatProtection.isFakeDamageEvent(ede)) return;
}
// long l1 = System.currentTimeMillis();

Entity eVictim = e.getEntity();
Expand All @@ -154,7 +160,6 @@ public void onVanillaDamage(EntityDamageEvent e) {
DamageMeta meta = new DamageMeta(victim, damager, weapon, cause);
statsVictim.setLastDamageMeta(meta);

boolean isEde = e instanceof EntityDamageByEntityEvent;
boolean isFullDamage = false;

SkillAPIHK skillApi = (SkillAPIHK) QuantumRPG.getInstance().getHook(EHook.SKILL_API);
Expand Down Expand Up @@ -221,7 +226,8 @@ public void onVanillaDamage(EntityDamageEvent e) {

// Anti-weapon damage bug, when shot was from a bow,
// but user swap his weapon to replace bow stats/damage.
if (weapon != null && weapon.getType() != Material.TRIDENT && !weapon.isSimilar(statsDamager.getItemInMainHand())) {
if (weapon != null && weapon.getType() != Material.TRIDENT
&& !weapon.isSimilar(statsDamager.getItemInMainHand())) {
damageStart = 1D;
break labelFullDamage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package su.nightexpress.quantumrpg.modules.list.combatlog;

import com.sucy.skill.api.DefaultCombatProtection;
import mc.promcteam.engine.hooks.Hooks;
import mc.promcteam.engine.manager.api.task.ITask;
import mc.promcteam.engine.utils.ClickText;
Expand All @@ -18,6 +19,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -84,18 +86,23 @@ public void setup() {

String path2 = "general.logging.format.";
this.genLogFormatTime = DateTimeFormatter.ofPattern(cfg.getString(path2 + "time", "HH:mm"));
this.genLogFormatText = StringUT.color(cfg.getString(path2 + "text", "&6[%time%] &r%message% %damage% %defense% %details% %weapon%"));
this.genLogFormatText = StringUT.color(cfg.getString(path2 + "text",
"&6[%time%] &r%message% %damage% %defense% %details% %weapon%"));

this.genLogFormatButtonDamageName = StringUT.color(cfg.getString(path2 + "buttons.damage.name", "&c&l[Damage]"));
this.genLogFormatButtonDamageName =
StringUT.color(cfg.getString(path2 + "buttons.damage.name", "&c&l[Damage]"));
this.genLogFormatButtonDamageText = StringUT.color(cfg.getStringList(path2 + "buttons.damage.text"));

this.genLogFormatButtonDefenseName = StringUT.color(cfg.getString(path2 + "buttons.defense.name", "&b&l[Defense]"));
this.genLogFormatButtonDefenseName =
StringUT.color(cfg.getString(path2 + "buttons.defense.name", "&b&l[Defense]"));
this.genLogFormatButtonDefenseText = StringUT.color(cfg.getStringList(path2 + "buttons.defense.text"));

this.genLogFormatButtonDetailsName = StringUT.color(cfg.getString(path2 + "buttons.details.name", "&e&l[Details]"));
this.genLogFormatButtonDetailsName =
StringUT.color(cfg.getString(path2 + "buttons.details.name", "&e&l[Details]"));
this.genLogFormatButtonDetailsText = StringUT.color(cfg.getStringList(path2 + "buttons.details.text"));

this.genLogFormatButtonWeaponName = StringUT.color(cfg.getString(path2 + "buttons.weapon.name", "&d&l[Weapon]"));
this.genLogFormatButtonWeaponName =
StringUT.color(cfg.getString(path2 + "buttons.weapon.name", "&d&l[Weapon]"));

this.moduleCommand.addSubCommand(new LogCommand(this));
}
Expand Down Expand Up @@ -269,7 +276,8 @@ public void format(@NotNull LivingEntity damager, @NotNull Player sender, @NotNu
List<String> damageDetails = new ArrayList<>(genLogFormatButtonDetailsText);
for (int i = 0; i < damageDetails.size(); i++) {
String line = damageDetails.get(i)
.replace("%enchantment_protection_factor%", NumberUT.format(meta.getEnchantProtectionModifier()))
.replace("%enchantment_protection_factor%",
NumberUT.format(meta.getEnchantProtectionModifier()))
.replace("%pvpe_modifier%", NumberUT.format(meta.getPvEDamageModifier()))
.replace("%penetrate_modifier%", NumberUT.format(meta.getPenetrateModifier()))
.replace("%block_modifier%", NumberUT.format(meta.getBlockModifier()))
Expand Down Expand Up @@ -391,7 +399,8 @@ public void onIndicatorRegen(EntityRegainHealthEvent e) {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamageIndicator(EntityDamageEvent ex) {
if (ex.isCancelled()) return;
if (ex.isCancelled() || (ex instanceof EntityDamageByEntityEvent
&& DefaultCombatProtection.isFakeDamageEvent((EntityDamageByEntityEvent) ex))) return;
if (!(ex.getEntity() instanceof LivingEntity)) return;
LivingEntity zertva = (LivingEntity) ex.getEntity();

Expand Down

0 comments on commit 5c70f9e

Please sign in to comment.