1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Merge pull request #1688 from DersWasTaken/master

Fix hunter job payouts not being applied
This commit is contained in:
Zrips 2023-12-19 12:15:08 +02:00 committed by GitHub
commit ddc9000f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 30 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
src/main/resources/locale/messages_en.yml
.classpath
.project
/build/

View File

@ -226,11 +226,6 @@
<!-- Temporary solution for replacing repository -->
<systemPath>${basedir}/libs/mypet-3.11-20210318.180552-1.jar</systemPath>
</dependency>
<dependency>
<groupId>CMILib</groupId>
<artifactId>CMILib</artifactId>
<version>1.4.3.1</version>
</dependency>
</dependencies>
<repositories>
<!-- MythicMobs -->
@ -293,7 +288,7 @@
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>D:\MC\Server 1.20\plugins\</outputDirectory>
<outputDirectory>build/jar</outputDirectory>
</configuration>
</plugin>
</plugins>

View File

@ -151,6 +151,11 @@ public final class JobsPaymentListener implements Listener {
.expireAfterWrite(10, TimeUnit.SECONDS)
.weakKeys()
.build();
private final Cache<UUID, Player> entityLastDamager = CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.MINUTES)
.weakKeys()
.build();
private Cache<UUID, Long> cowMilkingTimer;
public JobsPaymentListener(Jobs plugin) {
@ -1227,7 +1232,7 @@ public final class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDamageByPlayer(EntityDamageEvent event) {
if (!Jobs.getGCManager().MonsterDamageUse || !(event instanceof EntityDamageByEntityEvent)
if (!(event instanceof EntityDamageByEntityEvent)
|| !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
@ -1238,6 +1243,11 @@ public final class JobsPaymentListener implements Listener {
if (!(((EntityDamageByEntityEvent) event).getDamager() instanceof Player))
return;
//Gross but works
entityLastDamager.put(ent.getUniqueId(), (Player) ((EntityDamageByEntityEvent) event).getDamager());
if(!Jobs.getGCManager().MonsterDamageUse) return;
double damage = event.getFinalDamage();
double s = ((Damageable) ent).getHealth();
if (damage > s)
@ -1274,6 +1284,7 @@ public final class JobsPaymentListener implements Listener {
damage = s;
if (((Projectile) event.getDamager()).getShooter() instanceof Player) {
entityLastDamager.put(ent.getUniqueId(), (Player) ((Projectile) event.getDamager()).getShooter());
Double damageDealt = damageDealtByPlayers.getIfPresent(entUUID);
if (damageDealt != null) {
damageDealtByPlayers.put(entUUID, damageDealt + damage);
@ -1285,17 +1296,18 @@ public final class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) ||
!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
if(!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
LivingEntity lVictim = event.getEntity();
Entity killer;
// Entity that died must be living
if (!(e.getEntity() instanceof LivingEntity))
return;
LivingEntity lVictim = (LivingEntity) e.getEntity();
if(!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent)) {
if(entityLastDamager.getIfPresent(event.getEntity().getUniqueId()) == null) return;
killer = entityLastDamager.getIfPresent(event.getEntity().getUniqueId());
} else {
killer = ((EntityDamageByEntityEvent) event.getEntity().getLastDamageCause()).getDamager();
}
// mob spawner, no payment or experience
if (!Jobs.getGCManager().payNearSpawner() && lVictim.hasMetadata(Jobs.getPlayerManager().getMobSpawnerMetadata())) {
@ -1326,7 +1338,7 @@ public final class JobsPaymentListener implements Listener {
}
//extra check for Citizens 2 sentry kills
if (e.getDamager() instanceof Player && e.getDamager().hasMetadata("NPC"))
if (killer.hasMetadata("NPC"))
return;
if (Jobs.getGCManager().MythicMobsEnabled && HookManager.getMythicManager() != null
@ -1336,26 +1348,21 @@ public final class JobsPaymentListener implements Listener {
Player pDamager = null;
boolean isTameable = e.getDamager() instanceof Tameable;
boolean isMyPet = HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager(), null);
boolean isTameable = killer instanceof Tameable;
boolean isMyPet = HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(killer, null);
if (e.getDamager() instanceof Player) { // Checking if killer is player
pDamager = (Player) e.getDamager();
if (killer instanceof Player) { // Checking if killer is player
pDamager = (Player) killer;
} else if (isMyPet) { // Checking if killer is MyPet animal
UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(e.getDamager());
UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(killer);
if (uuid != null)
pDamager = Bukkit.getPlayer(uuid);
} else if (isTameable) { // Checking if killer is tamed animal
Tameable t = (Tameable) e.getDamager();
Tameable t = (Tameable) killer;
if (t.isTamed() && t.getOwner() instanceof Player)
pDamager = (Player) t.getOwner();
} else if (e.getDamager() instanceof Projectile) {
Projectile pr = (Projectile) e.getDamager();
if (pr.getShooter() instanceof Player)
pDamager = (Player) pr.getShooter();
}
if (pDamager == null)
@ -1396,18 +1403,18 @@ public final class JobsPaymentListener implements Listener {
if (Jobs.getGCManager().payForStackedEntities) {
if (JobsHook.WildStacker.isEnabled()) {
for (int i = 0; i < HookManager.getWildStackerHandler().getEntityAmount(lVictim) - 1; i++) {
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), e.getDamager(), lVictim);
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), killer, lVictim);
}
} else if (JobsHook.StackMob.isEnabled() && HookManager.getStackMobHandler().isStacked(lVictim)) {
for (uk.antiperson.stackmob.entity.StackEntity stacked : HookManager.getStackMobHandler().getStackEntities()) {
if (stacked.getEntity().getType() == lVictim.getType()) {
Jobs.action(jDamager, new EntityActionInfo(stacked.getEntity(), ActionType.KILL), e.getDamager(), stacked.getEntity());
Jobs.action(jDamager, new EntityActionInfo(stacked.getEntity(), ActionType.KILL), killer, stacked.getEntity());
}
}
}
}
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), e.getDamager(), lVictim);
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), killer, lVictim);
// Payment for killing player with particular job, except NPC's
if (notNpc) {