From 5abfc0bb550996be56a22a505061013bcd551215 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 10 Oct 2020 21:11:32 +0200 Subject: [PATCH] Now "jobs.petpay" can be denied to do not get income for killing mobs with mypet Fixes #951 --- .../gamingmesh/jobs/config/TitleManager.java | 18 ++++++------- .../gamingmesh/jobs/container/JobsPlayer.java | 2 +- .../com/gamingmesh/jobs/container/Title.java | 13 +++++---- .../jobs/listeners/JobsPaymentListener.java | 27 +++++++++++++------ 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/config/TitleManager.java b/src/main/java/com/gamingmesh/jobs/config/TitleManager.java index a55b2ad4..22edb790 100644 --- a/src/main/java/com/gamingmesh/jobs/config/TitleManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/TitleManager.java @@ -24,10 +24,10 @@ public class TitleManager { Title title = null; for (Title t : titles) { if (title == null) { - if (t.getLevelReq() <= level && (t.getJobName() == null || t.getJobName().equalsIgnoreCase(jobName))) + if (t.getLevelReq() <= level && t.getJobName().equalsIgnoreCase(jobName)) title = t; } else { - if (t.getLevelReq() <= level && t.getLevelReq() > title.getLevelReq() && (t.getJobName() == null || t.getJobName().equalsIgnoreCase(jobName))) + if (t.getLevelReq() <= level && t.getLevelReq() > title.getLevelReq() && t.getJobName().equalsIgnoreCase(jobName)) title = t; } } @@ -45,11 +45,12 @@ public class TitleManager { ConfigReader c = null; try { c = new ConfigReader("titleConfig.yml"); - } catch (Throwable e) { + } catch (Exception e) { e.printStackTrace(); } if (c == null) return; + c.copyDefaults(true); c.header(Arrays.asList( @@ -126,21 +127,20 @@ public class TitleManager { c.save(); } else for (String titleKey : titleSection.getKeys(false)) { - String jobName = null; - String titleName = titleSection.getString(titleKey + ".Name"); - String titleShortName = titleSection.getString(titleKey + ".ShortName"); + String jobName = "", + titleName = titleSection.getString(titleKey + ".Name", ""), + titleShortName = titleSection.getString(titleKey + ".ShortName", ""); CMIChatColor titleColor = CMIChatColor.getColor(titleSection.getString(titleKey + ".ChatColour", "")); int levelReq = titleSection.getInt(titleKey + ".levelReq", -1); if (titleSection.isString(titleKey + ".JobName")) jobName = titleSection.getString(titleKey + ".JobName"); - if (titleName == null) { + if (titleName.isEmpty()) { Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid Name property. Skipping!"); continue; } - - if (titleShortName == null) { + if (titleShortName.isEmpty()) { Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ShortName property. Skipping!"); continue; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 4669786c..4656f241 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -688,7 +688,7 @@ public class JobsPlayer { if (method == DisplayMethod.FULL || method == DisplayMethod.JOB) { if (gotTitle) { - builder.append(" "); + builder.append(' '); } String honorificpart = prog.getJob().getNameWithColor() + CMIChatColor.WHITE; diff --git a/src/main/java/com/gamingmesh/jobs/container/Title.java b/src/main/java/com/gamingmesh/jobs/container/Title.java index afc6e391..20bea30c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Title.java +++ b/src/main/java/com/gamingmesh/jobs/container/Title.java @@ -28,11 +28,10 @@ import com.gamingmesh.jobs.CMILib.CMIChatColor; * */ public class Title { - private String name = null; - private String shortName = null; + + private String name = "", shortName = "", jobName = ""; private CMIChatColor color = CMIChatColor.WHITE; private int levelReq = 0; - private String jobName = null; /** * Constructor @@ -55,11 +54,11 @@ public class Title { * @param jobName Job this title is made for */ public Title(String name, String shortName, CMIChatColor color, int levelReq, String jobName) { - this.name = name; - this.color = color; + this.name = name == null ? "" : name; + this.color = color == null ? CMIChatColor.BLACK : color; this.levelReq = levelReq; - this.shortName = shortName; - this.jobName = jobName; + this.shortName = shortName == null ? "" : shortName; + this.jobName = jobName == null ? "" : jobName; } /** diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 3e5be6e7..00e45453 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -18,13 +18,7 @@ package com.gamingmesh.jobs.listeners; -import com.gamingmesh.jobs.CMILib.ActionBarManager; -import com.gamingmesh.jobs.CMILib.CMIChatColor; -import com.gamingmesh.jobs.CMILib.CMIEnchantment; -import com.gamingmesh.jobs.CMILib.CMIEntityType; -import com.gamingmesh.jobs.CMILib.CMIMaterial; -import com.gamingmesh.jobs.CMILib.ItemManager; -import com.gamingmesh.jobs.CMILib.Version; +import com.gamingmesh.jobs.CMILib.*; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.actions.*; import com.gamingmesh.jobs.api.JobsChunkChangeEvent; @@ -61,8 +55,15 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.entity.*; +import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityTameEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.SlimeSplitEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.BrewEvent; @@ -85,6 +86,7 @@ import org.bukkit.inventory.StonecutterInventory; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; +import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.projectiles.ProjectileSource; import java.util.ArrayList; @@ -1193,6 +1195,15 @@ public class JobsPaymentListener implements Listener { if (pDamager == null) return; + // Prevent payment for killing mobs with mypet by denying permission + if (HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager(), null)) { + for (PermissionAttachmentInfo perm : pDamager.getEffectivePermissions()) { + if (perm.getPermission().equals("jobs.petpay") && !perm.getValue()) { + return; + } + } + } + // check if in creative if (!payIfCreative(pDamager)) return;