forked from Upstream/mmocore
Improved party target restriction
This commit is contained in:
parent
93377b6027
commit
1765b15707
@ -12,7 +12,6 @@ import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
import net.Indyuce.mmocore.api.util.debug.DebugMode;
|
||||
import net.Indyuce.mmocore.command.*;
|
||||
import net.Indyuce.mmocore.comp.MMOCoreTargetRestriction;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizenInteractEventListener;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizensMMOLoader;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicHook;
|
||||
@ -41,6 +40,7 @@ import net.Indyuce.mmocore.manager.profession.*;
|
||||
import net.Indyuce.mmocore.manager.social.BoosterManager;
|
||||
import net.Indyuce.mmocore.manager.social.PartyManager;
|
||||
import net.Indyuce.mmocore.manager.social.RequestManager;
|
||||
import net.Indyuce.mmocore.party.PartyMemberTargetRestriction;
|
||||
import net.Indyuce.mmocore.party.PartyModule;
|
||||
import net.Indyuce.mmocore.party.PartyModuleType;
|
||||
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
|
||||
@ -116,8 +116,8 @@ public class MMOCore extends LuminePlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
// Register target restrictions due to MMOCore in MythicLib
|
||||
MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction());
|
||||
// Register MMOCore-specific target restrictions
|
||||
MythicLib.plugin.getEntities().registerRestriction(new PartyMemberTargetRestriction());
|
||||
|
||||
// Register extra objective, drop items...
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
|
||||
|
@ -1,28 +0,0 @@
|
||||
package net.Indyuce.mmocore.comp;
|
||||
|
||||
import io.lumine.mythic.lib.comp.target.InteractionType;
|
||||
import io.lumine.mythic.lib.comp.target.TargetRestriction;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.party.AbstractParty;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MMOCoreTargetRestriction implements TargetRestriction {
|
||||
|
||||
@Override
|
||||
public boolean canTarget(Player player, LivingEntity target, InteractionType interaction) {
|
||||
|
||||
if (interaction.isOffense() && target instanceof Player && PlayerData.has(target.getUniqueId())) {
|
||||
PlayerData targetData = PlayerData.get(target.getUniqueId());
|
||||
|
||||
// Check for the same party
|
||||
AbstractParty party = targetData.getParty();
|
||||
if (party != null && party.hasMember(player))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.Indyuce.mmocore.party;
|
||||
|
||||
import io.lumine.mythic.lib.comp.target.InteractionType;
|
||||
import io.lumine.mythic.lib.comp.target.TargetRestriction;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PartyMemberTargetRestriction implements TargetRestriction {
|
||||
|
||||
@Override
|
||||
public boolean canTarget(Player player, LivingEntity livingEntity, InteractionType interactionType) {
|
||||
if (!interactionType.isOffense() || !(livingEntity instanceof Player) || livingEntity.hasMetadata("NPC"))
|
||||
return true;
|
||||
|
||||
AbstractParty party = MMOCore.plugin.partyModule.getParty(PlayerData.get(player));
|
||||
return party == null || !party.hasMember((Player) livingEntity);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package net.Indyuce.mmocore.party.provided;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.listener.PartyListener;
|
||||
import net.Indyuce.mmocore.party.PartyModule;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -1,16 +1,10 @@
|
||||
package net.Indyuce.mmocore.listener;
|
||||
package net.Indyuce.mmocore.party.provided;
|
||||
|
||||
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.social.PartyChatEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.ConfigManager.SimpleMessage;
|
||||
import net.Indyuce.mmocore.party.AbstractParty;
|
||||
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
|
||||
import net.Indyuce.mmocore.party.provided.Party;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -45,21 +39,4 @@ public class PartyListener implements Listener {
|
||||
party.getOnlineMembers().forEach(member -> format.send(member.getPlayer()));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel damage of players from the same party
|
||||
*
|
||||
* @deprecated This should be useful with the {@link io.lumine.mythic.lib.comp.target.TargetRestriction} update
|
||||
*/
|
||||
@Deprecated
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void b(PlayerAttackEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
if (entity instanceof Player && !entity.hasMetadata("NPC")) {
|
||||
PlayerData targetData = PlayerData.get((Player) event.getEntity());
|
||||
AbstractParty party = targetData.getParty();
|
||||
if (party != null && party.hasMember(event.getData().getPlayer()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user