1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-07 00:38:42 +01:00

Fix for checking if the object is mypet

Fixes #930
This commit is contained in:
montlikadani 2020-10-02 12:14:09 +02:00
parent 0efedc0124
commit 3032802fad
4 changed files with 29 additions and 22 deletions

View File

@ -969,7 +969,7 @@ public class PlayerManager {
} }
} }
if (ent != null && HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(ent)) { if (ent != null && HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(ent, player.getPlayer())) {
if (petPay == null) if (petPay == null)
petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay"); petPay = Jobs.getPermissionManager().getMaxPermission(player, "jobs.petpay");
if (petPay != null) if (petPay != null)

View File

@ -144,6 +144,8 @@ public class ShopManager {
GUIitem.setAmount(item.getIconAmount()); GUIitem.setAmount(item.getIconAmount());
ItemMeta meta = GUIitem.getItemMeta(); ItemMeta meta = GUIitem.getItemMeta();
if (meta == null)
continue;
if (item.getIconName() != null) if (item.getIconName() != null)
meta.setDisplayName(item.getIconName()); meta.setDisplayName(item.getIconName());
@ -190,6 +192,9 @@ public class ShopManager {
GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack(); GUIitem = CMIMaterial.PLAYER_HEAD.newItemStack();
SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta(); SkullMeta skullMeta = (SkullMeta) GUIitem.getItemMeta();
if (skullMeta == null)
continue;
// Fix skull meta // Fix skull meta
skullMeta.setDisplayName(item.getIconName()); skullMeta.setDisplayName(item.getIconName());
skullMeta.setLore(Lore); skullMeta.setLore(Lore);
@ -262,8 +267,10 @@ public class ShopManager {
} }
ItemStack Item = new ItemStack(Material.ARROW); ItemStack Item = new ItemStack(Material.ARROW);
ItemMeta meta = Item.getItemMeta(); ItemMeta meta = Item.getItemMeta();
if (meta == null)
return false;
int prevSlot = getPrevButtonSlot(GuiSize.getFields(), page); int prevSlot = getPrevButtonSlot(GuiSize.getFields(), page);
if (prevSlot != -1 && page > 1) { if (prevSlot != -1 && page > 1) {
meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.prevPage")); meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.prevPage"));

View File

@ -2,29 +2,35 @@ package com.gamingmesh.jobs.hooks.MyPet;
import java.util.UUID; import java.util.UUID;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import de.Keyle.MyPet.MyPetApi; import de.Keyle.MyPet.MyPetApi;
import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.MyPet;
import de.Keyle.MyPet.api.entity.MyPetBukkitEntity; import de.Keyle.MyPet.api.entity.MyPetBukkitEntity;
import de.Keyle.MyPet.api.player.MyPetPlayer;
import de.Keyle.MyPet.api.repository.PlayerManager; import de.Keyle.MyPet.api.repository.PlayerManager;
public class MyPetManager { public class MyPetManager {
PlayerManager mp; private final PlayerManager mp = MyPetApi.getPlayerManager();
de.Keyle.MyPet.api.repository.MyPetManager mppm;
private boolean enabled = false;
public MyPetManager() { public boolean isMyPet(Entity entity, Player owner) {
mp = MyPetApi.getPlayerManager(); if (owner == null) {
mppm = MyPetApi.getMyPetManager(); return entity instanceof MyPetBukkitEntity;
enabled = true;
} }
public boolean isMyPet(Object ent) { if (!mp.isMyPetPlayer(owner)) {
return enabled && ent instanceof MyPetBukkitEntity; return false;
} }
public UUID getOwnerOfPet(Object ent) { MyPetPlayer myPetPlayer = mp.getMyPetPlayer(owner);
if (!enabled || !(ent instanceof MyPetBukkitEntity)) return myPetPlayer.hasMyPet() && myPetPlayer.getMyPet().getEntity().isPresent() &&
myPetPlayer.getMyPet().getEntity().get().getType() == entity.getType();
}
public UUID getOwnerOfPet(Entity ent) {
if (!(ent instanceof MyPetBukkitEntity))
return null; return null;
MyPet myPet = ((MyPetBukkitEntity) ent).getMyPet(); MyPet myPet = ((MyPetBukkitEntity) ent).getMyPet();

View File

@ -302,8 +302,6 @@ public class JobsPaymentListener implements Listener {
Jobs.action(jDamager, new CustomKillInfo(((Sheep) stacked.getLivingEntity()).getColor().name(), ActionType.SHEAR)); Jobs.action(jDamager, new CustomKillInfo(((Sheep) stacked.getLivingEntity()).getColor().name(), ActionType.SHEAR));
} }
} }
return;
} }
Jobs.action(jDamager, new CustomKillInfo(sheep.getColor().name(), ActionType.SHEAR)); Jobs.action(jDamager, new CustomKillInfo(sheep.getColor().name(), ActionType.SHEAR));
@ -546,8 +544,6 @@ public class JobsPaymentListener implements Listener {
Jobs.action(jDamager, new EntityActionInfo(stacked.getLivingEntity(), ActionType.TAME)); Jobs.action(jDamager, new EntityActionInfo(stacked.getLivingEntity(), ActionType.TAME));
} }
} }
return;
} }
Jobs.action(jDamager, new EntityActionInfo(animal, ActionType.TAME)); Jobs.action(jDamager, new EntityActionInfo(animal, ActionType.TAME));
@ -1190,7 +1186,7 @@ public class JobsPaymentListener implements Listener {
if (e.getDamager() instanceof Player) { if (e.getDamager() instanceof Player) {
pDamager = (Player) e.getDamager(); pDamager = (Player) e.getDamager();
// Checking if killer is MyPet animal // Checking if killer is MyPet animal
} else if (HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager())) { } else if (HookManager.getMyPetManager() != null && HookManager.getMyPetManager().isMyPet(e.getDamager(), null)) {
UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(e.getDamager()); UUID uuid = HookManager.getMyPetManager().getOwnerOfPet(e.getDamager());
if (uuid != null) if (uuid != null)
pDamager = Bukkit.getPlayer(uuid); pDamager = Bukkit.getPlayer(uuid);
@ -1248,8 +1244,6 @@ public class JobsPaymentListener implements Listener {
Jobs.action(jDamager, new EntityActionInfo(stacked.getLivingEntity(), ActionType.KILL), pDamager, stacked.getLivingEntity()); Jobs.action(jDamager, new EntityActionInfo(stacked.getLivingEntity(), ActionType.KILL), pDamager, stacked.getLivingEntity());
} }
} }
return;
} }
Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), pDamager, lVictim); Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), pDamager, lVictim);