1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 22:13:25 +01:00

Now "jobs.petpay" can be denied to do not get income for killing mobs with mypet

Fixes #951
This commit is contained in:
montlikadani 2020-10-10 21:11:32 +02:00
parent ee21d95a43
commit 5abfc0bb55
4 changed files with 35 additions and 25 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
/**

View File

@ -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;